Commit 5fd9f9c9 authored by Daniel Tian's avatar Daniel Tian

Fix vuln scanner filter not working when report type has no scanner IDs

Changelog: fixed
parent 9091eaf7
......@@ -70,8 +70,17 @@ export default {
return groups;
},
filterObject() {
const ids = this.selectedOptions.flatMap((x) => x.scannerIds);
return { scannerId: ids.map((x) => `${SCANNER_ID_PREFIX}${x}`) };
if (this.isNoOptionsSelected) {
return { scannerId: [] };
}
const ids = this.selectedOptions.flatMap(({ scannerIds, reportType }) => {
return scannerIds.length
? scannerIds.map((id) => `${SCANNER_ID_PREFIX}${id}`)
: [`${SCANNER_ID_PREFIX}${reportType}:null`];
});
return { scannerId: ids };
},
},
methods: {
......
......@@ -24,12 +24,11 @@ const scanners = [
createScannerConfig(DEFAULT_SCANNER, 'SAST', 4),
createScannerConfig(DEFAULT_SCANNER, 'SECRET_DETECTION', 5),
createScannerConfig(DEFAULT_SCANNER, 'CONTAINER_SCANNING', 6),
createScannerConfig(DEFAULT_SCANNER, 'COVERAGE_FUZZING', 7),
createScannerConfig(DEFAULT_SCANNER, 'DAST', 7),
createScannerConfig(DEFAULT_SCANNER, 'DAST', 8),
createScannerConfig(DEFAULT_SCANNER, 'DAST', 9),
createScannerConfig('Custom', 'SAST', 9),
createScannerConfig('Custom', 'SAST', 10),
createScannerConfig('Custom', 'SAST', 11),
createScannerConfig('Custom', 'DAST', 12),
createScannerConfig('Custom', 'DAST', 11),
];
describe('Scanner Filter component', () => {
......@@ -104,14 +103,18 @@ describe('Scanner Filter component', () => {
});
it('emits filter-changed event with expected data for selected options', async () => {
const ids = ['GitLab.SAST', 'Custom.SAST'];
const ids = ['GitLab.SAST', 'Custom.SAST', 'GitLab.API_FUZZING', 'GitLab.COVERAGE_FUZZING'];
router.replace({ query: { [scannerFilter.id]: ids } });
const selectedScanners = scanners.filter((x) => ids.includes(`${x.vendor}.${x.report_type}`));
createWrapper();
await wrapper.vm.$nextTick();
expect(wrapper.emitted('filter-changed')[0][0]).toEqual({
scannerId: selectedScanners.map((x) => `${SCANNER_ID_PREFIX}${x.id}`),
scannerId: expect.arrayContaining([
...selectedScanners.map((x) => `${SCANNER_ID_PREFIX}${x.id}`),
`${SCANNER_ID_PREFIX}COVERAGE_FUZZING:null`,
`${SCANNER_ID_PREFIX}API_FUZZING:null`,
]),
});
});
});
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