Commit a3c1f34d authored by Mark Florian's avatar Mark Florian

Use props instead of gl global for diff endpoints

Rather than the GroupedSecurityReportsApp digging into the global
`gl.mrWidgetData` for the security report comparison paths, it's more
elegant to expose the paths on the MR widget store and provide them as
props to the component.
parent 4c4345a4
...@@ -349,6 +349,12 @@ export default { ...@@ -349,6 +349,12 @@ export default {
:mr-state="mr.state" :mr-state="mr.state"
:target-branch-tree-path="mr.targetBranchTreePath" :target-branch-tree-path="mr.targetBranchTreePath"
:new-pipeline-path="mr.newPipelinePath" :new-pipeline-path="mr.newPipelinePath"
:container-scanning-comparison-path="mr.containerScanningComparisonPath"
:coverage-fuzzing-comparison-path="mr.coverageFuzzingComparisonPath"
:dast-comparison-path="mr.dastComparisonPath"
:dependency-scanning-comparison-path="mr.dependencyScanningComparisonPath"
:sast-comparison-path="mr.sastComparisonPath"
:secret-scanning-comparison-path="mr.secretScanningComparisonPath"
class="js-security-widget" class="js-security-widget"
/> />
<mr-widget-licenses <mr-widget-licenses
......
...@@ -50,6 +50,19 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -50,6 +50,19 @@ export default class MergeRequestStore extends CEMergeRequestStore {
super.setData(data, isRebased); super.setData(data, isRebased);
} }
setPaths(data) {
// Paths are set on the first load of the page and not auto-refreshed
super.setPaths(data);
// Security scan diff paths
this.containerScanningComparisonPath = data.container_scanning_comparison_path;
this.coverageFuzzingComparisonPath = data.coverage_fuzzing_comparison_path;
this.dastComparisonPath = data.dast_comparison_path;
this.dependencyScanningComparisonPath = data.dependency_scanning_comparison_path;
this.sastComparisonPath = data.sast_comparison_path;
this.secretScanningComparisonPath = data.secret_scanning_comparison_path;
}
initGeo(data) { initGeo(data) {
this.isGeoSecondaryNode = this.isGeoSecondaryNode || data.is_geo_secondary_node; this.isGeoSecondaryNode = this.isGeoSecondaryNode || data.is_geo_secondary_node;
this.geoSecondaryHelpPath = this.geoSecondaryHelpPath || data.geo_secondary_help_path; this.geoSecondaryHelpPath = this.geoSecondaryHelpPath || data.geo_secondary_help_path;
......
...@@ -190,6 +190,36 @@ export default { ...@@ -190,6 +190,36 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
containerScanningComparisonPath: {
type: String,
required: false,
default: '',
},
coverageFuzzingComparisonPath: {
type: String,
required: false,
default: '',
},
dastComparisonPath: {
type: String,
required: false,
default: '',
},
dependencyScanningComparisonPath: {
type: String,
required: false,
default: '',
},
sastComparisonPath: {
type: String,
required: false,
default: '',
},
secretScanningComparisonPath: {
type: String,
required: false,
default: '',
},
}, },
componentNames, componentNames,
computed: { computed: {
...@@ -305,44 +335,33 @@ export default { ...@@ -305,44 +335,33 @@ export default {
this.setPipelineId(this.pipelineId); this.setPipelineId(this.pipelineId);
this.setPipelineJobsId(this.pipelineId); this.setPipelineJobsId(this.pipelineId);
const sastDiffEndpoint = gl?.mrWidgetData?.sast_comparison_path; if (this.sastComparisonPath && this.hasSastReports) {
this.setSastDiffEndpoint(this.sastComparisonPath);
if (sastDiffEndpoint && this.hasSastReports) {
this.setSastDiffEndpoint(sastDiffEndpoint);
this.fetchSastDiff(); this.fetchSastDiff();
} }
const containerScanningDiffEndpoint = gl?.mrWidgetData?.container_scanning_comparison_path; if (this.containerScanningComparisonPath && this.hasContainerScanningReports) {
this.setContainerScanningDiffEndpoint(this.containerScanningComparisonPath);
if (containerScanningDiffEndpoint && this.hasContainerScanningReports) {
this.setContainerScanningDiffEndpoint(containerScanningDiffEndpoint);
this.fetchContainerScanningDiff(); this.fetchContainerScanningDiff();
} }
const dastDiffEndpoint = gl?.mrWidgetData?.dast_comparison_path; if (this.dastComparisonPath && this.hasDastReports) {
this.setDastDiffEndpoint(this.dastComparisonPath);
if (dastDiffEndpoint && this.hasDastReports) {
this.setDastDiffEndpoint(dastDiffEndpoint);
this.fetchDastDiff(); this.fetchDastDiff();
} }
const dependencyScanningDiffEndpoint = gl?.mrWidgetData?.dependency_scanning_comparison_path; if (this.dependencyScanningComparisonPath && this.hasDependencyScanningReports) {
this.setDependencyScanningDiffEndpoint(this.dependencyScanningComparisonPath);
if (dependencyScanningDiffEndpoint && this.hasDependencyScanningReports) {
this.setDependencyScanningDiffEndpoint(dependencyScanningDiffEndpoint);
this.fetchDependencyScanningDiff(); this.fetchDependencyScanningDiff();
} }
const secretDetectionDiffEndpoint = gl?.mrWidgetData?.secret_scanning_comparison_path; if (this.secretScanningComparisonPath && this.hasSecretDetectionReports) {
if (secretDetectionDiffEndpoint && this.hasSecretDetectionReports) { this.setSecretDetectionDiffEndpoint(this.secretScanningComparisonPath);
this.setSecretDetectionDiffEndpoint(secretDetectionDiffEndpoint);
this.fetchSecretDetectionDiff(); this.fetchSecretDetectionDiff();
} }
const coverageFuzzingDiffEndpoint = gl?.mrWidgetData?.coverage_fuzzing_comparison_path; if (this.coverageFuzzingComparisonPath && this.hasCoverageFuzzingReports) {
this.setCoverageFuzzingDiffEndpoint(this.coverageFuzzingComparisonPath);
if (coverageFuzzingDiffEndpoint && this.hasCoverageFuzzingReports) {
this.setCoverageFuzzingDiffEndpoint(coverageFuzzingDiffEndpoint);
this.fetchCoverageFuzzingDiff(); this.fetchCoverageFuzzingDiff();
this.fetchPipelineJobs(); this.fetchPipelineJobs();
} }
......
...@@ -54,6 +54,12 @@ describe('Grouped security reports app', () => { ...@@ -54,6 +54,12 @@ describe('Grouped security reports app', () => {
pipelineId: 123, pipelineId: 123,
projectId: 321, projectId: 321,
projectFullPath: 'path', projectFullPath: 'path',
containerScanningComparisonPath: CONTAINER_SCANNING_DIFF_ENDPOINT,
coverageFuzzingComparisonPath: COVERAGE_FUZZING_DIFF_ENDPOINT,
dastComparisonPath: DAST_DIFF_ENDPOINT,
dependencyScanningComparisonPath: DEPENDENCY_SCANNING_DIFF_ENDPOINT,
sastComparisonPath: SAST_DIFF_ENDPOINT,
secretScanningComparisonPath: SECRET_DETECTION_DIFF_ENDPOINT,
}; };
const defaultDastSummary = { const defaultDastSummary = {
...@@ -112,16 +118,6 @@ describe('Grouped security reports app', () => { ...@@ -112,16 +118,6 @@ describe('Grouped security reports app', () => {
}, },
}; };
beforeEach(() => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.container_scanning_comparison_path = CONTAINER_SCANNING_DIFF_ENDPOINT;
gl.mrWidgetData.dependency_scanning_comparison_path = DEPENDENCY_SCANNING_DIFF_ENDPOINT;
gl.mrWidgetData.dast_comparison_path = DAST_DIFF_ENDPOINT;
gl.mrWidgetData.sast_comparison_path = SAST_DIFF_ENDPOINT;
gl.mrWidgetData.secret_scanning_comparison_path = SECRET_DETECTION_DIFF_ENDPOINT;
gl.mrWidgetData.coverage_fuzzing_comparison_path = COVERAGE_FUZZING_DIFF_ENDPOINT;
});
describe('with error', () => { describe('with error', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(CONTAINER_SCANNING_DIFF_ENDPOINT).reply(500); mock.onGet(CONTAINER_SCANNING_DIFF_ENDPOINT).reply(500);
...@@ -394,41 +390,32 @@ describe('Grouped security reports app', () => { ...@@ -394,41 +390,32 @@ describe('Grouped security reports app', () => {
}); });
describe('coverage fuzzing reports', () => { describe('coverage fuzzing reports', () => {
describe.each([true, false])( describe.each([true, false])('given featureEnabled is %s', shouldShowFuzzing => {
'given coverage fuzzing comparison endpoint is /fuzzing and featureEnabled is %s', beforeEach(() => {
shouldShowFuzzing => { createWrapper(
beforeEach(() => { {
gl.mrWidgetData = gl.mrWidgetData || {}; ...props,
gl.mrWidgetData.coverage_fuzzing_comparison_path = '/fuzzing'; enabledReports: {
coverageFuzzing: true,
createWrapper(
{
...props,
enabledReports: {
coverageFuzzing: true,
},
},
{},
{
glFeatures: { coverageFuzzingMrWidget: shouldShowFuzzing },
}, },
); },
}); {},
{
glFeatures: { coverageFuzzingMrWidget: shouldShowFuzzing },
},
);
});
it(`${shouldShowFuzzing ? 'renders' : 'does not render'}`, () => { it(`${shouldShowFuzzing ? 'renders' : 'does not render'}`, () => {
expect(wrapper.find('[data-qa-selector="coverage_fuzzing_report"]').exists()).toBe( expect(wrapper.find('[data-qa-selector="coverage_fuzzing_report"]').exists()).toBe(
shouldShowFuzzing, shouldShowFuzzing,
); );
}); });
}, });
);
}); });
describe('container scanning reports', () => { describe('container scanning reports', () => {
beforeEach(() => { beforeEach(() => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.container_scanning_comparison_path = CONTAINER_SCANNING_DIFF_ENDPOINT;
mock.onGet(CONTAINER_SCANNING_DIFF_ENDPOINT).reply(200, containerScanningDiffSuccessMock); mock.onGet(CONTAINER_SCANNING_DIFF_ENDPOINT).reply(200, containerScanningDiffSuccessMock);
createWrapper({ createWrapper({
...@@ -456,9 +443,6 @@ describe('Grouped security reports app', () => { ...@@ -456,9 +443,6 @@ describe('Grouped security reports app', () => {
describe('dependency scanning reports', () => { describe('dependency scanning reports', () => {
beforeEach(() => { beforeEach(() => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.dependency_scanning_comparison_path = DEPENDENCY_SCANNING_DIFF_ENDPOINT;
mock.onGet(DEPENDENCY_SCANNING_DIFF_ENDPOINT).reply(200, dependencyScanningDiffSuccessMock); mock.onGet(DEPENDENCY_SCANNING_DIFF_ENDPOINT).reply(200, dependencyScanningDiffSuccessMock);
createWrapper({ createWrapper({
...@@ -486,9 +470,6 @@ describe('Grouped security reports app', () => { ...@@ -486,9 +470,6 @@ describe('Grouped security reports app', () => {
describe('dast reports', () => { describe('dast reports', () => {
beforeEach(() => { beforeEach(() => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.dast_comparison_path = DAST_DIFF_ENDPOINT;
mock.onGet(DAST_DIFF_ENDPOINT).reply(200, { mock.onGet(DAST_DIFF_ENDPOINT).reply(200, {
...dastDiffSuccessMock, ...dastDiffSuccessMock,
base_report_out_of_date: true, base_report_out_of_date: true,
...@@ -562,9 +543,6 @@ describe('Grouped security reports app', () => { ...@@ -562,9 +543,6 @@ describe('Grouped security reports app', () => {
describe('secret scanning reports', () => { describe('secret scanning reports', () => {
const initSecretScan = (isEnabled = true) => { const initSecretScan = (isEnabled = true) => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.secret_scanning_comparison_path = SECRET_DETECTION_DIFF_ENDPOINT;
mock.onGet(SECRET_DETECTION_DIFF_ENDPOINT).reply(200, secretScanningDiffSuccessMock); mock.onGet(SECRET_DETECTION_DIFF_ENDPOINT).reply(200, secretScanningDiffSuccessMock);
createWrapper({ createWrapper({
...@@ -615,9 +593,6 @@ describe('Grouped security reports app', () => { ...@@ -615,9 +593,6 @@ describe('Grouped security reports app', () => {
describe('sast reports', () => { describe('sast reports', () => {
beforeEach(() => { beforeEach(() => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.sast_comparison_path = SAST_DIFF_ENDPOINT;
mock.onGet(SAST_DIFF_ENDPOINT).reply(200, { ...sastDiffSuccessMock }); mock.onGet(SAST_DIFF_ENDPOINT).reply(200, { ...sastDiffSuccessMock });
createWrapper({ createWrapper({
...@@ -643,9 +618,6 @@ describe('Grouped security reports app', () => { ...@@ -643,9 +618,6 @@ describe('Grouped security reports app', () => {
describe('Out of date report', () => { describe('Out of date report', () => {
const createComponent = (extraProp, done) => { const createComponent = (extraProp, done) => {
gl.mrWidgetData = gl.mrWidgetData || {};
gl.mrWidgetData.sast_comparison_path = SAST_DIFF_ENDPOINT;
mock mock
.onGet(SAST_DIFF_ENDPOINT) .onGet(SAST_DIFF_ENDPOINT)
.reply(200, { ...sastDiffSuccessMock, base_report_out_of_date: true }); .reply(200, { ...sastDiffSuccessMock, base_report_out_of_date: true });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment