Commit 683fa3d2 authored by Mark Florian's avatar Mark Florian

Align Secret Detection module with SAST

The existing SAST Vuex module was only superficially different from the
new Secret Detection module. The only real difference is the passing of
the relevant report type to the `fetchDiffData` function.

I've intentionally made these two modules nearly identical to aid future
refactoring to de-duplicate these via a factory pattern, or similar.
parent 65c792cf
import { fetchDiffData } from '../../utils';
import * as types from './mutation_types';
export const setSecretScanningDiffEndpoint = ({ commit }, path) =>
commit(types.SET_SECRET_SCANNING_DIFF_ENDPOINT, path);
export const setDiffEndpoint = ({ commit }, path) => commit(types.SET_DIFF_ENDPOINT, path);
export const requestSecretScanningDiff = ({ commit }) => commit(types.REQUEST_SECRET_SCANNING_DIFF);
export const requestDiff = ({ commit }) => commit(types.REQUEST_DIFF);
export const receiveSecretScanningDiffSuccess = ({ commit }, response) =>
commit(types.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS, response);
export const receiveDiffSuccess = ({ commit }, response) =>
commit(types.RECEIVE_DIFF_SUCCESS, response);
export const receiveSecretScanningDiffError = ({ commit }, error) =>
commit(types.RECEIVE_SECRET_SCANNING_DIFF_ERROR, error);
export const receiveDiffError = ({ commit }, response) =>
commit(types.RECEIVE_DIFF_ERROR, response);
export const fetchSecretScanningDiff = ({ state, rootState, dispatch }) => {
dispatch('requestSecretScanningDiff');
export const fetchDiff = ({ state, rootState, dispatch }) => {
dispatch('requestDiff');
return fetchDiffData(rootState, state.paths.diffEndpoint, 'secret_detection')
.then(data => {
dispatch('receiveSecretScanningDiffSuccess', data);
dispatch('receiveDiffSuccess', data);
})
.catch(() => {
dispatch('receiveSecretScanningDiffError');
dispatch('receiveDiffError');
});
};
export const RECEIVE_SECRET_SCANNING_DIFF_SUCCESS = 'RECEIVE_SECRET_SCANNING_DIFF_SUCCESS';
export const RECEIVE_SECRET_SCANNING_DIFF_ERROR = 'RECEIVE_SECRET_SCANNING_DIFF_ERROR';
export const REQUEST_SECRET_SCANNING_DIFF = 'REQUEST_SECRET_SCANNING_DIFF';
export const SET_SECRET_SCANNING_DIFF_ENDPOINT = 'SET_SECRET_SCANNING_DIFF_ENDPOINT';
export const RECEIVE_DIFF_SUCCESS = 'RECEIVE_DIFF_SUCCESS';
export const RECEIVE_DIFF_ERROR = 'RECEIVE_DIFF_ERROR';
export const REQUEST_DIFF = 'REQUEST_DIFF';
export const SET_DIFF_ENDPOINT = 'SET_DIFF_ENDPOINT';
......@@ -3,29 +3,29 @@ import { parseDiff } from '~/vue_shared/security_reports/store/utils';
import * as types from './mutation_types';
export default {
[types.SET_SECRET_SCANNING_DIFF_ENDPOINT](state, path) {
[types.SET_DIFF_ENDPOINT](state, path) {
Vue.set(state.paths, 'diffEndpoint', path);
},
[types.REQUEST_SECRET_SCANNING_DIFF](state) {
Vue.set(state, 'isLoading', true);
[types.REQUEST_DIFF](state) {
state.isLoading = true;
},
[types.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS](state, { diff, enrichData }) {
[types.RECEIVE_DIFF_SUCCESS](state, { diff, enrichData }) {
const { added, fixed, existing } = parseDiff(diff, enrichData);
const baseReportOutofDate = diff.base_report_out_of_date || false;
const hasBaseReport = Boolean(diff.base_report_created_at);
Vue.set(state, 'isLoading', false);
Vue.set(state, 'newIssues', added);
Vue.set(state, 'resolvedIssues', fixed);
Vue.set(state, 'allIssues', existing);
Vue.set(state, 'baseReportOutofDate', baseReportOutofDate);
Vue.set(state, 'hasBaseReport', hasBaseReport);
state.isLoading = false;
state.newIssues = added;
state.resolvedIssues = fixed;
state.allIssues = existing;
state.baseReportOutofDate = baseReportOutofDate;
state.hasBaseReport = hasBaseReport;
},
[types.RECEIVE_SECRET_SCANNING_DIFF_ERROR](state) {
Vue.set(state, 'isLoading', false);
Vue.set(state, 'hasError', true);
[types.RECEIVE_DIFF_ERROR](state) {
state.isLoading = false;
state.hasError = true;
},
};
......@@ -309,8 +309,8 @@ export default {
const secretScanningDiffEndpoint = gl?.mrWidgetData?.secret_scanning_comparison_path;
if (secretScanningDiffEndpoint && this.hasSecretScanningReports) {
this.setSecretScanningDiffEndpoint(secretScanningDiffEndpoint);
this.fetchSecretScanningDiff();
this.setSecretDetectionDiffEndpoint(secretScanningDiffEndpoint);
this.fetchSecretDetectionDiff();
}
const coverageFuzzingDiffEndpoint = gl?.mrWidgetData?.coverage_fuzzing_comparison_path;
......@@ -359,8 +359,8 @@ export default {
fetchSastDiff: 'fetchDiff',
}),
...mapActions('secretScanning', {
setSecretScanningDiffEndpoint: 'setSecretScanningDiffEndpoint',
fetchSecretScanningDiff: 'fetchSecretScanningDiff',
setSecretDetectionDiffEndpoint: 'setDiffEndpoint',
fetchSecretDetectionDiff: 'fetchDiff',
}),
...mapActions('pipelineJobs', ['fetchPipelineJobs', 'setPipelineJobsPath', 'setProjectId']),
...mapActions('pipelineJobs', {
......
......@@ -5,7 +5,7 @@ export const updateIssueActionsMap = {
dependency_scanning: 'updateDependencyScanningIssue',
container_scanning: 'updateContainerScanningIssue',
dast: 'updateDastIssue',
secret_detection: 'secretScanning/updateSecretScanningIssue',
secret_detection: 'secretScanning/updateVulnerability',
coverage_fuzzing: 'updateCoverageFuzzingIssue',
};
......
......@@ -2,5 +2,5 @@ import * as types from './mutation_types';
export * from '~/vue_shared/security_reports/store/modules/secret_detection/actions';
export const updateSecretScanningIssue = ({ commit }, issue) =>
commit(types.UPDATE_SECRET_SCANNING_ISSUE, issue);
export const updateVulnerability = ({ commit }, vulnerability) =>
commit(types.UPDATE_VULNERABILITY, vulnerability);
export * from '~/vue_shared/security_reports/store/modules/secret_detection/mutation_types';
export const UPDATE_SECRET_SCANNING_ISSUE = 'UPDATE_SECRET_SCANNING_ISSUE';
export const UPDATE_VULNERABILITY = 'UPDATE_VULNERABILITY';
......@@ -5,9 +5,7 @@ import * as types from './mutation_types';
export default {
...ceMutations,
[types.UPDATE_SECRET_SCANNING_ISSUE](state, issue) {
// Find issue in the correct list and update it
[types.UPDATE_VULNERABILITY](state, issue) {
const newIssuesIndex = findIssueIndex(state.newIssues, issue);
if (newIssuesIndex !== -1) {
state.newIssues.splice(newIssuesIndex, 1, issue);
......@@ -17,6 +15,7 @@ export default {
const resolvedIssuesIndex = findIssueIndex(state.resolvedIssues, issue);
if (resolvedIssuesIndex !== -1) {
state.resolvedIssues.splice(resolvedIssuesIndex, 1, issue);
return;
}
const allIssuesIndex = findIssueIndex(state.allIssues, issue);
......
......@@ -140,7 +140,7 @@ describe('Grouped security reports app', () => {
waitForMutation(wrapper.vm.$store, types.RECEIVE_DEPENDENCY_SCANNING_DIFF_ERROR),
waitForMutation(
wrapper.vm.$store,
`secretScanning/${secretScanningTypes.RECEIVE_SECRET_SCANNING_DIFF_ERROR}`,
`secretScanning/${secretScanningTypes.RECEIVE_DIFF_ERROR}`,
),
waitForMutation(wrapper.vm.$store, types.RECEIVE_COVERAGE_FUZZING_DIFF_ERROR),
]);
......@@ -228,7 +228,7 @@ describe('Grouped security reports app', () => {
waitForMutation(wrapper.vm.$store, types.RECEIVE_DEPENDENCY_SCANNING_DIFF_SUCCESS),
waitForMutation(
wrapper.vm.$store,
`secretScanning/${secretScanningTypes.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS}`,
`secretScanning/${secretScanningTypes.RECEIVE_DIFF_SUCCESS}`,
),
waitForMutation(wrapper.vm.$store, types.RECEIVE_COVERAGE_FUZZING_DIFF_SUCCESS),
]);
......@@ -281,7 +281,7 @@ describe('Grouped security reports app', () => {
waitForMutation(wrapper.vm.$store, types.RECEIVE_DEPENDENCY_SCANNING_DIFF_SUCCESS),
waitForMutation(
wrapper.vm.$store,
`secretScanning/${secretScanningTypes.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS}`,
`secretScanning/${secretScanningTypes.RECEIVE_DIFF_SUCCESS}`,
),
waitForMutation(wrapper.vm.$store, types.RECEIVE_COVERAGE_FUZZING_DIFF_SUCCESS),
]);
......@@ -576,7 +576,7 @@ describe('Grouped security reports app', () => {
return waitForMutation(
wrapper.vm.$store,
`secretScanning/${secretScanningTypes.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS}`,
`secretScanning/${secretScanningTypes.RECEIVE_DIFF_SUCCESS}`,
);
};
......@@ -589,7 +589,7 @@ describe('Grouped security reports app', () => {
expect(wrapper.find('[data-qa-selector="secret_scan_report"]').exists()).toBe(true);
});
it('should set setSecretScanningDiffEndpoint', () => {
it('should set setDiffEndpoint', () => {
expect(wrapper.vm.secretScanning.paths.diffEndpoint).toEqual(SECRET_SCANNING_DIFF_ENDPOINT);
});
......
......@@ -13,15 +13,15 @@ describe('EE secret detection report actions', () => {
state = createState();
});
describe('updateSecretScanningIssue', () => {
it(`should commit ${types.UPDATE_SECRET_SCANNING_ISSUE} with the correct response`, done => {
describe('updateVulnerability', () => {
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, done => {
testAction(
actions.updateSecretScanningIssue,
actions.updateVulnerability,
issue,
state,
[
{
type: types.UPDATE_SECRET_SCANNING_ISSUE,
type: types.UPDATE_VULNERABILITY,
payload: issue,
},
],
......
......@@ -13,7 +13,7 @@ describe('EE secret detection module mutations', () => {
state = createState();
});
describe(types.UPDATE_SECRET_SCANNING_ISSUE, () => {
describe(types.UPDATE_VULNERABILITY, () => {
let newIssue;
let resolvedIssue;
let allIssue;
......@@ -30,7 +30,7 @@ describe('EE secret detection module mutations', () => {
describe('with a `new` issue', () => {
beforeEach(() => {
mutations[types.UPDATE_SECRET_SCANNING_ISSUE](state, { ...newIssue, changed: true });
mutations[types.UPDATE_VULNERABILITY](state, { ...newIssue, changed: true });
});
it('should update the correct issue', () => {
......@@ -40,7 +40,7 @@ describe('EE secret detection module mutations', () => {
describe('with a `resolved` issue', () => {
beforeEach(() => {
mutations[types.UPDATE_SECRET_SCANNING_ISSUE](state, { ...resolvedIssue, changed: true });
mutations[types.UPDATE_VULNERABILITY](state, { ...resolvedIssue, changed: true });
});
it('should update the correct issue', () => {
......@@ -50,7 +50,7 @@ describe('EE secret detection module mutations', () => {
describe('with an `all` issue', () => {
beforeEach(() => {
mutations[types.UPDATE_SECRET_SCANNING_ISSUE](state, { ...allIssue, changed: true });
mutations[types.UPDATE_VULNERABILITY](state, { ...allIssue, changed: true });
});
it('should update the correct issue', () => {
......@@ -60,7 +60,7 @@ describe('EE secret detection module mutations', () => {
describe('with an invalid issue', () => {
beforeEach(() => {
mutations[types.UPDATE_SECRET_SCANNING_ISSUE](
mutations[types.UPDATE_VULNERABILITY](
state,
createIssue({ project_fingerprint: 'invalid', changed: true }),
);
......
......@@ -25,15 +25,15 @@ describe('secret detection report actions', () => {
state = createState();
});
describe('setSecretScanningDiffEndpoint', () => {
it(`should commit ${types.SET_SECRET_SCANNING_DIFF_ENDPOINT} with the correct path`, done => {
describe('setDiffEndpoint', () => {
it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, done => {
testAction(
actions.setSecretScanningDiffEndpoint,
actions.setDiffEndpoint,
diffEndpoint,
state,
[
{
type: types.SET_SECRET_SCANNING_DIFF_ENDPOINT,
type: types.SET_DIFF_ENDPOINT,
payload: diffEndpoint,
},
],
......@@ -43,28 +43,21 @@ describe('secret detection report actions', () => {
});
});
describe('requestSecretScanningDiff', () => {
it(`should commit ${types.REQUEST_SECRET_SCANNING_DIFF}`, done => {
testAction(
actions.requestSecretScanningDiff,
{},
state,
[{ type: types.REQUEST_SECRET_SCANNING_DIFF }],
[],
done,
);
describe('requestDiff', () => {
it(`should commit ${types.REQUEST_DIFF}`, done => {
testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], [], done);
});
});
describe('receiveSecretScanningDiffSuccess', () => {
it(`should commit ${types.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS} with the correct response`, done => {
describe('receiveDiffSuccess', () => {
it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, done => {
testAction(
actions.receiveSecretScanningDiffSuccess,
actions.receiveDiffSuccess,
reports,
state,
[
{
type: types.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS,
type: types.RECEIVE_DIFF_SUCCESS,
payload: reports,
},
],
......@@ -74,15 +67,15 @@ describe('secret detection report actions', () => {
});
});
describe('receiveSecretScanningDiffError', () => {
it(`should commit ${types.RECEIVE_SECRET_SCANNING_DIFF_ERROR} with the correct response`, done => {
describe('receiveDiffError', () => {
it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, done => {
testAction(
actions.receiveSecretScanningDiffError,
actions.receiveDiffError,
error,
state,
[
{
type: types.RECEIVE_SECRET_SCANNING_DIFF_ERROR,
type: types.RECEIVE_DIFF_ERROR,
payload: error,
},
],
......@@ -92,7 +85,7 @@ describe('secret detection report actions', () => {
});
});
describe('fetchSecretScanningDiff', () => {
describe('fetchDiff', () => {
let mock;
beforeEach(() => {
......@@ -117,14 +110,14 @@ describe('secret detection report actions', () => {
it('should dispatch the `receiveDiffSuccess` action', done => {
const { diff, enrichData } = reports;
testAction(
actions.fetchSecretScanningDiff,
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[
{ type: 'requestSecretScanningDiff' },
{ type: 'requestDiff' },
{
type: 'receiveSecretScanningDiffSuccess',
type: 'receiveDiffSuccess',
payload: {
diff,
enrichData,
......@@ -142,18 +135,18 @@ describe('secret detection report actions', () => {
mock.onGet(diffEndpoint).replyOnce(200, reports.diff);
});
it('should dispatch the `receiveSecretScanningDiffSuccess` action with empty enrich data', done => {
it('should dispatch the `receiveDiffSuccess` action with empty enrich data', done => {
const { diff } = reports;
const enrichData = [];
testAction(
actions.fetchSecretScanningDiff,
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[
{ type: 'requestSecretScanningDiff' },
{ type: 'requestDiff' },
{
type: 'receiveSecretScanningDiffSuccess',
type: 'receiveDiffSuccess',
payload: {
diff,
enrichData,
......@@ -174,13 +167,13 @@ describe('secret detection report actions', () => {
.replyOnce(404);
});
it('should dispatch the `receiveSecretScanningDiffError` action', done => {
it('should dispatch the `receiveDiffError` action', done => {
testAction(
actions.fetchSecretScanningDiff,
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[{ type: 'requestSecretScanningDiff' }, { type: 'receiveSecretScanningDiffError' }],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
);
});
......@@ -195,13 +188,13 @@ describe('secret detection report actions', () => {
.replyOnce(200, reports.enrichData);
});
it('should dispatch the `receiveSecretScanningDiffError` action', done => {
it('should dispatch the `receiveDiffError` action', done => {
testAction(
actions.fetchSecretScanningDiff,
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[{ type: 'requestSecretScanningDiff' }, { type: 'receiveSecretScanningDiffError' }],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
);
});
......
......@@ -12,23 +12,23 @@ describe('secret detection module mutations', () => {
state = createState();
});
describe(types.SET_SECRET_SCANNING_DIFF_ENDPOINT, () => {
describe(types.SET_DIFF_ENDPOINT, () => {
it('should set the secret detection diff endpoint', () => {
mutations[types.SET_SECRET_SCANNING_DIFF_ENDPOINT](state, path);
mutations[types.SET_DIFF_ENDPOINT](state, path);
expect(state.paths.diffEndpoint).toBe(path);
});
});
describe(types.REQUEST_SECRET_SCANNING_DIFF, () => {
describe(types.REQUEST_DIFF, () => {
it('should set the `isLoading` status to `true`', () => {
mutations[types.REQUEST_SECRET_SCANNING_DIFF](state);
mutations[types.REQUEST_DIFF](state);
expect(state.isLoading).toBe(true);
});
});
describe(types.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS, () => {
describe(types.RECEIVE_DIFF_SUCCESS, () => {
beforeEach(() => {
const reports = {
diff: {
......@@ -43,7 +43,7 @@ describe('secret detection module mutations', () => {
},
};
state.isLoading = true;
mutations[types.RECEIVE_SECRET_SCANNING_DIFF_SUCCESS](state, reports);
mutations[types.RECEIVE_DIFF_SUCCESS](state, reports);
});
it('should set the `isLoading` status to `false`', () => {
......@@ -67,10 +67,10 @@ describe('secret detection module mutations', () => {
});
});
describe(types.RECEIVE_SECRET_SCANNING_DIFF_ERROR, () => {
describe(types.RECEIVE_DIFF_ERROR, () => {
beforeEach(() => {
state.isLoading = true;
mutations[types.RECEIVE_SECRET_SCANNING_DIFF_ERROR](state);
mutations[types.RECEIVE_DIFF_ERROR](state);
});
it('should set the `isLoading` status to `false`', () => {
......
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