Commit 3690691b authored by Filipa Lacerda's avatar Filipa Lacerda

[ci skip] Changes after review

parent 38cf8d53
...@@ -3,9 +3,7 @@ import * as types from './mutation_types'; ...@@ -3,9 +3,7 @@ import * as types from './mutation_types';
export const setHeadBlobPath = ({ commit }, blobPath) => commit(types.SET_HEAD_BLOB_PATH, blobPath); export const setHeadBlobPath = ({ commit }, blobPath) => commit(types.SET_HEAD_BLOB_PATH, blobPath);
export const setBaseBlobPath = ({ commit }, blobPath) => { export const setBaseBlobPath = ({ commit }, blobPath) => commit(types.SET_BASE_BLOB_PATH, blobPath);
commit(types.SET_BASE_BLOB_PATH, blobPath);
};
/** /**
* SAST * SAST
...@@ -28,29 +26,19 @@ export const fetchSastReports = ({ state, dispatch }) => { ...@@ -28,29 +26,19 @@ export const fetchSastReports = ({ state, dispatch }) => {
dispatch('requestSastReports'); dispatch('requestSastReports');
if (head && base) { Promise.all([
Promise.all([axios.get(head), axios.get(base)]) head ? axios.get(head) : Promise.resolve(),
.then(values => { base ? axios.get(base) : Promise.resolve(),
dispatch('receiveSastReports', { ])
head: values[0].data, .then(values => {
base: values[1].data, dispatch('receiveSastReports', {
}); head: values[0] ? values[0].data : null,
}) base: values[1] ? values[1].data : null,
.catch(() => { });
dispatch('receiveSastError'); })
}); .catch(() => {
} else if (head && !base) { dispatch('receiveSastError');
axios });
.get(head)
.then(response => {
dispatch('receiveSastReports', {
head: response.data,
});
})
.catch(() => {
dispatch('receiveSastError');
});
}
}; };
/** /**
...@@ -77,29 +65,19 @@ export const fetchSastContainerReports = ({ state, dispatch }) => { ...@@ -77,29 +65,19 @@ export const fetchSastContainerReports = ({ state, dispatch }) => {
dispatch('requestSastContainerReports'); dispatch('requestSastContainerReports');
if (head && base) { Promise.all([
Promise.all([axios.get(head), axios.get(base)]) head ? axios.get(head) : Promise.resolve(),
.then(values => { base ? axios.get(base) : Promise.resolve(),
dispatch('receiveSastContainerReports', { ])
head: values[0].data, .then(values => {
base: values[1].data, dispatch('receiveSastContainerReports', {
}); head: values[0] ? values[0].data : null,
}) base: values[1] ? values[1].data : null,
.catch(() => { });
dispatch('receiveSastContainerError'); })
}); .catch(() => {
} else { dispatch('receiveSastContainerError');
axios });
.get(head)
.then(response => {
dispatch('receiveSastContainerReports', {
head: response.data,
});
})
.catch(() => {
dispatch('receiveSastContainerError');
});
}
}; };
/** /**
...@@ -122,29 +100,19 @@ export const fetchDastReports = ({ state, dispatch }) => { ...@@ -122,29 +100,19 @@ export const fetchDastReports = ({ state, dispatch }) => {
dispatch('requestDastReports'); dispatch('requestDastReports');
if (head && base) { Promise.all([
Promise.all([axios.get(head), axios.get(base)]) head ? axios.get(head) : Promise.resolve(),
.then(values => { base ? axios.get(base) : Promise.resolve(),
dispatch('receiveDastReports', { ])
head: values[0].data, .then(values => {
base: values[1].data, dispatch('receiveDastReports', {
}); head: values[0] ? values[0].data : null,
}) base: values[1] ? values[1].data : null,
.catch(() => { });
dispatch('receiveDastError'); })
}); .catch(() => {
} else { dispatch('receiveDastError');
axios });
.get(head)
.then(response => {
dispatch('receiveDastReports', {
head: response.data,
});
})
.catch(() => {
dispatch('receiveDastError');
});
}
}; };
/** /**
...@@ -171,27 +139,17 @@ export const fetchDependencyScanningReports = ({ state, dispatch }) => { ...@@ -171,27 +139,17 @@ export const fetchDependencyScanningReports = ({ state, dispatch }) => {
dispatch('requestDependencyScanningReports'); dispatch('requestDependencyScanningReports');
if (head && base) { Promise.all([
Promise.all([axios.get(head), axios.get(base)]) head ? axios.get(head) : Promise.resolve(),
.then(values => { base ? axios.get(base) : Promise.resolve(),
dispatch('receiveDependencyScanningReports', { ])
head: values[0].data, .then(values => {
base: values[1].data, dispatch('receiveDependencyScanningReports', {
}); head: values[0] ? values[0].data : null,
}) base: values[1] ? values[1].data : null,
.catch(() => { });
dispatch('receiveDependencyScanningError'); })
}); .catch(() => {
} else { dispatch('receiveDependencyScanningError');
axios });
.get(head)
.then(response => {
dispatch('receiveDependencyScanningReports', {
head: response.data,
});
})
.catch(() => {
dispatch('receiveDependencyScanningError');
});
}
}; };
import { n__, s__ } from '~/locale'; import { n__, s__ } from '~/locale';
import { textBuilder, statusIcon } from './utils'; import { textBuilder, statusIcon } from './utils';
export const groupedSastText = state => { export const groupedSastText = ({ sast }) =>
const { sast } = state; textBuilder(
return textBuilder(
'SAST', 'SAST',
sast.paths, sast.paths,
sast.newIssues.length, sast.newIssues.length,
sast.resolvedIssues.length, sast.resolvedIssues.length,
sast.allIssues.length, sast.allIssues.length,
); );
};
export const groupedSastContainerText = state => {
const { sastContainer } = state;
return textBuilder( export const groupedSastContainerText = ({ sastContainer }) =>
textBuilder(
'Container scanning', 'Container scanning',
sastContainer.paths, sastContainer.paths,
sastContainer.newIssues.length, sastContainer.newIssues.length,
sastContainer.resolvedIssues.length, sastContainer.resolvedIssues.length,
); );
};
export const groupedDastText = state => { export const groupedDastText = ({ dast }) =>
const { dast } = state; textBuilder('DAST', dast.paths, dast.newIssues.length, dast.resolvedIssues.length);
return textBuilder('DAST', dast.paths, dast.newIssues.length, dast.resolvedIssues.length);
};
export const groupedDependencyText = state => { export const groupedDependencyText = ({ dependencyScanning }) =>
const { dependencyScanning } = state; textBuilder(
return textBuilder(
'Dependency scanning', 'Dependency scanning',
dependencyScanning.paths, dependencyScanning.paths,
dependencyScanning.newIssues.length, dependencyScanning.newIssues.length,
dependencyScanning.resolvedIssues.length, dependencyScanning.resolvedIssues.length,
); );
};
export const groupedSummaryText = (state, getters) => {
const { added, fixed } = state.summaryCounts;
export const groupedSummaryText = ({ added, fixed }, getters) => {
// All reports returned error // All reports returned error
if (getters.allReportsHaveError) { if (getters.allReportsHaveError) {
return s__('ciReport|Security scanning failed loading any results'); return s__('ciReport|Security scanning failed loading any results');
...@@ -91,15 +80,15 @@ export const groupedSummaryText = (state, getters) => { ...@@ -91,15 +80,15 @@ export const groupedSummaryText = (state, getters) => {
return text.join(' '); return text.join(' ');
}; };
export const sastStatusIcon = state => statusIcon(state.sast.hasError, state.sast.newIssues.length); export const sastStatusIcon = ({ sast }) => statusIcon(sast.hasError, sast.newIssues.length);
export const sastContainerStatusIcon = state => export const sastContainerStatusIcon = ({ sastContainer }) =>
statusIcon(state.sastContainer.hasError, state.sastContainer.newIssues.length); statusIcon(sastContainer.hasError, sastContainer.newIssues.length);
export const dastStatusIcon = state => statusIcon(state.dast.hasError, state.dast.newIssues.length); export const dastStatusIcon = ({ dast }) => statusIcon(dast.hasError, dast.newIssues.length);
export const dependencyScanningStatusIcon = state => export const dependencyScanningStatusIcon = ({ dependencyScanning }) =>
statusIcon(state.dependencyScanning.hasError, state.dependencyScanning.newIssues.length); statusIcon(dependencyScanning.hasError, dependencyScanning.newIssues.length);
export const areReportsLoading = state => export const areReportsLoading = state =>
state.sast.isLoading || state.sast.isLoading ||
......
...@@ -55,16 +55,18 @@ export default { ...@@ -55,16 +55,18 @@ export default {
const allIssues = filterByKey(parsedHead, newIssues.concat(resolvedIssues), filterKey); const allIssues = filterByKey(parsedHead, newIssues.concat(resolvedIssues), filterKey);
Object.assign(state.sast, { Object.assign(state, {
newIssues, sast: {
resolvedIssues, ...state.sast,
allIssues, newIssues,
isLoading: false, resolvedIssues,
}); allIssues,
isLoading: false,
Object.assign(state.summaryCounts, { },
added: state.summaryCounts.added + newIssues.length, summaryCounts: {
fixed: state.summaryCounts.fixed + resolvedIssues.length, added: state.summaryCounts.added + newIssues.length,
fixed: state.summaryCounts.fixed + resolvedIssues.length,
},
}); });
} else if (reports.head && !reports.base) { } else if (reports.head && !reports.base) {
const newIssues = parseSastIssues(reports.head, state.blobPath.head); const newIssues = parseSastIssues(reports.head, state.blobPath.head);
...@@ -114,15 +116,17 @@ export default { ...@@ -114,15 +116,17 @@ export default {
const newIssues = filterByKey(headIssues, baseIssues, filterKey); const newIssues = filterByKey(headIssues, baseIssues, filterKey);
const resolvedIssues = filterByKey(baseIssues, headIssues, filterKey); const resolvedIssues = filterByKey(baseIssues, headIssues, filterKey);
Object.assign(state.sastContainer, { Object.assign(state, {
isLoading: false, sastContainer: {
newIssues, ...state.sastContainer,
resolvedIssues, isLoading: false,
}); newIssues,
resolvedIssues,
Object.assign(state.summaryCounts, { },
added: state.summaryCounts.added + newIssues.length, summaryCounts: {
fixed: state.summaryCounts.fixed + resolvedIssues.length, added: state.summaryCounts.added + newIssues.length,
fixed: state.summaryCounts.fixed + resolvedIssues.length,
},
}); });
} else if (reports.head && !reports.base) { } else if (reports.head && !reports.base) {
Object.assign(state.sastContainer, { Object.assign(state.sastContainer, {
...@@ -164,15 +168,17 @@ export default { ...@@ -164,15 +168,17 @@ export default {
const newIssues = filterByKey(headIssues, baseIssues, filterKey); const newIssues = filterByKey(headIssues, baseIssues, filterKey);
const resolvedIssues = filterByKey(baseIssues, headIssues, filterKey); const resolvedIssues = filterByKey(baseIssues, headIssues, filterKey);
Object.assign(state.dast, { Object.assign(state, {
isLoading: false, dast: {
newIssues, ...state.dast,
resolvedIssues, isLoading: false,
}); newIssues,
resolvedIssues,
Object.assign(state.summaryCounts, { },
added: state.summaryCounts.added + newIssues.length, summaryCounts: {
fixed: state.summaryCounts.fixed + resolvedIssues.length, added: state.summaryCounts.added + newIssues.length,
fixed: state.summaryCounts.fixed + resolvedIssues.length,
},
}); });
} else if (reports.head && !reports.base) { } else if (reports.head && !reports.base) {
Object.assign(state.dast, { Object.assign(state.dast, {
...@@ -228,16 +234,18 @@ export default { ...@@ -228,16 +234,18 @@ export default {
const resolvedIssues = filterByKey(parsedBase, parsedHead, filterKey); const resolvedIssues = filterByKey(parsedBase, parsedHead, filterKey);
const allIssues = filterByKey(parsedHead, newIssues.concat(resolvedIssues), filterKey); const allIssues = filterByKey(parsedHead, newIssues.concat(resolvedIssues), filterKey);
Object.assign(state.dependencyScanning, { Object.assign(state, {
newIssues, dependencyScanning: {
resolvedIssues, ...state.dependencyScanning,
allIssues, newIssues,
isLoading: false, resolvedIssues,
}); allIssues,
isLoading: false,
Object.assign(state.summaryCounts, { },
added: state.summaryCounts.added + newIssues.length, summaryCounts: {
fixed: state.summaryCounts.fixed + resolvedIssues.length, added: state.summaryCounts.added + newIssues.length,
fixed: state.summaryCounts.fixed + resolvedIssues.length,
},
}); });
} else { } else {
Object.assign(state.dependencyScanning, { Object.assign(state.dependencyScanning, {
......
...@@ -11,13 +11,13 @@ import { n__, s__, sprintf } from '~/locale'; ...@@ -11,13 +11,13 @@ import { n__, s__, sprintf } from '~/locale';
* @param {String} path * @param {String} path
*/ */
export const parseSastIssues = (issues = [], path = '') => export const parseSastIssues = (issues = [], path = '') =>
issues.map(issue => issues.map(issue => ({
Object.assign({}, issue, { ...issue,
name: issue.message, name: issue.message,
path: issue.file, path: issue.file,
urlPath: issue.line ? `${path}/${issue.file}#L${issue.line}` : `${path}/${issue.file}`, urlPath: issue.line ? `${path}/${issue.file}#L${issue.line}` : `${path}/${issue.file}`,
}), }),
); );
/** /**
* Parses Sast Container results into a common format to allow to use the same Vue component * Parses Sast Container results into a common format to allow to use the same Vue component
...@@ -27,13 +27,13 @@ export const parseSastIssues = (issues = [], path = '') => ...@@ -27,13 +27,13 @@ export const parseSastIssues = (issues = [], path = '') =>
* @returns {Array} * @returns {Array}
*/ */
export const parseSastContainer = (data = []) => export const parseSastContainer = (data = []) =>
data.map(el => ({ data.map(element => ({
name: el.vulnerability, ...element,
priority: el.severity, name: element.vulnerability,
path: el.namespace, priority: element.severity,
path: element.namespace,
// external link to provide better description // external link to provide better description
nameLink: `https://cve.mitre.org/cgi-bin/cvename.cgi?name=${el.vulnerability}`, nameLink: `https://cve.mitre.org/cgi-bin/cvename.cgi?name=${element.vulnerability}`,
...el,
})); }));
export const parseDastIssues = (issues = []) => export const parseDastIssues = (issues = []) =>
......
/* eslint-disable */
/** /**
* helper for testing action with expected mutations * helper for testing action with expected mutations inspired in
* https://vuex.vuejs.org/en/testing.html * https://vuex.vuejs.org/en/testing.html
*
* @example
* testAction(
* actions.actionName, // action
* { }, // mocked response
* state, // state
* [
* { type: types.MUTATION}
* { type: types.MUTATION_1, payload: {}}
* ], // mutations
* [
* { type: 'actionName', payload: {}},
* { type: 'actionName1', payload: {}}
* ] //actions
* done,
* );
*/ */
export default (action, payload, state, expectedMutations, done) => { export default (action, payload, state, expectedMutations, expectedActions, done) => {
let count = 0; let mutationsCount = 0;
let actionsCount = 0;
// mock commit // mock commit
const commit = (type, payload) => { const commit = (type, mutationPayload) => {
const mutation = expectedMutations[count]; const mutation = expectedMutations[mutationsCount];
try { expect(mutation.type).toEqual(type);
expect(mutation.type).to.equal(type);
if (payload) { if (mutation.payload) {
expect(mutation.payload).to.deep.equal(payload); expect(mutation.payload).toEqual(mutationPayload);
}
} catch (error) {
done(error);
} }
count++; mutationsCount += 1;
if (count >= expectedMutations.length) { if (mutationsCount >= expectedMutations.length) {
done(); done();
} }
}; };
// mock dispatch // mock dispatch
const dispatch = (type, dispatchPayload) => { const dispatch = (type, actionPayload) => {
const mutation = expectedMutations[count]; const actionExpected = expectedActions[actionsCount];
try { expect(actionExpected.type).toEqual(type);
expect(mutation.type).to.equal(type);
if (dispatchPayload) { if (actionExpected.payload) {
expect(mutation.payload).to.deep.equal(dispatchPayload); expect(actionExpected.payload).toEqual(actionPayload);
}
} catch (error) {
done(error);
} }
count++; actionsCount += 1;
if (actionsCount >= expectedActions.length) {
if (count >= expectedMutations.length) {
done(); done();
} }
}; };
...@@ -52,7 +59,13 @@ export default (action, payload, state, expectedMutations, done) => { ...@@ -52,7 +59,13 @@ export default (action, payload, state, expectedMutations, done) => {
// check if no mutations should have been dispatched // check if no mutations should have been dispatched
if (expectedMutations.length === 0) { if (expectedMutations.length === 0) {
expect(count).to.equal(0); expect(mutationsCount).toEqual(0);
done();
}
// check if no mutations should have been dispatched
if (expectedActions.length === 0) {
expect(actionsCount).toEqual(0);
done(); done();
} }
}; };
...@@ -305,7 +305,7 @@ describe('Security reports getters', () => { ...@@ -305,7 +305,7 @@ describe('Security reports getters', () => {
}); });
it('returns added and fixed text', () => { it('returns added and fixed text', () => {
const newState = Object.assign({}, state()); const newState = state();
newState.summaryCounts = { newState.summaryCounts = {
added: 2, added: 2,
fixed: 4, fixed: 4,
...@@ -321,7 +321,7 @@ describe('Security reports getters', () => { ...@@ -321,7 +321,7 @@ describe('Security reports getters', () => {
}); });
it('returns added text', () => { it('returns added text', () => {
const newState = Object.assign({}, state()); const newState = state();
newState.summaryCounts = { newState.summaryCounts = {
added: 2, added: 2,
fixed: 0, fixed: 0,
......
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