Commit 1171f6fb authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch '346188-cluster-image-scanning-drawer' into 'master'

Update scan execution policy drawer

See merge request gitlab-org/gitlab!74949
parents bf71f9fe 53098c16
...@@ -47,6 +47,12 @@ const humanizePipelineRule = (rule) => { ...@@ -47,6 +47,12 @@ const humanizePipelineRule = (rule) => {
}; };
const humanizeScheduleRule = (rule) => { const humanizeScheduleRule = (rule) => {
if (rule.clusters) {
return sprintf(s__('SecurityOrchestration|Scan to be performed %{cadence}'), {
cadence: humanizeCadence(rule.cadence),
});
}
return sprintf(s__('SecurityOrchestration|Scan to be performed %{cadence} on the %{branches}'), { return sprintf(s__('SecurityOrchestration|Scan to be performed %{cadence} on the %{branches}'), {
cadence: humanizeCadence(rule.cadence), cadence: humanizeCadence(rule.cadence),
branches: humanizeBranches(rule.branches), branches: humanizeBranches(rule.branches),
...@@ -74,7 +80,7 @@ export const humanizeActions = (actions) => { ...@@ -74,7 +80,7 @@ export const humanizeActions = (actions) => {
*/ */
export const humanizeRules = (rules) => { export const humanizeRules = (rules) => {
const humanizedRules = rules.reduce((acc, curr) => { const humanizedRules = rules.reduce((acc, curr) => {
return curr.branches ? [...acc, HUMANIZE_RULES_METHODS[curr.type](curr)] : acc; return curr.branches || curr.clusters ? [...acc, HUMANIZE_RULES_METHODS[curr.type](curr)] : acc;
}, []); }, []);
return humanizedRules.length ? humanizedRules : [NO_RULE_MESSAGE]; return humanizedRules.length ? humanizedRules : [NO_RULE_MESSAGE];
......
...@@ -4,6 +4,13 @@ import { ...@@ -4,6 +4,13 @@ import {
NO_RULE_MESSAGE, NO_RULE_MESSAGE,
} from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib'; } from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib';
jest.mock('~/locale', () => ({
getPreferredLocales: jest.fn().mockReturnValue(['en']),
sprintf: jest.requireActual('~/locale').sprintf,
s__: jest.requireActual('~/locale').s__, // eslint-disable-line no-underscore-dangle
n__: jest.requireActual('~/locale').n__, // eslint-disable-line no-underscore-dangle
}));
const mockActions = [ const mockActions = [
{ scan: 'dast', scanner_profile: 'Scanner Profile', site_profile: 'Site Profile' }, { scan: 'dast', scanner_profile: 'Scanner Profile', site_profile: 'Site Profile' },
{ scan: 'dast', scanner_profile: 'Scanner Profile 01', site_profile: 'Site Profile 01' }, { scan: 'dast', scanner_profile: 'Scanner Profile 01', site_profile: 'Site Profile 01' },
...@@ -14,6 +21,11 @@ const mockRules = [ ...@@ -14,6 +21,11 @@ const mockRules = [
{ type: 'schedule', cadence: '*/10 * * * *', branches: ['main'] }, { type: 'schedule', cadence: '*/10 * * * *', branches: ['main'] },
{ type: 'pipeline', branches: ['release/*', 'staging'] }, { type: 'pipeline', branches: ['release/*', 'staging'] },
{ type: 'pipeline', branches: ['release/1.*', 'canary', 'staging'] }, { type: 'pipeline', branches: ['release/1.*', 'canary', 'staging'] },
{
type: 'schedule',
cadence: '* */20 4 * *',
clusters: { protect: { namespaces: ['default-cluster'] } },
},
{ type: 'pipeline' }, { type: 'pipeline' },
]; ];
...@@ -34,17 +46,12 @@ describe('humanizeActions', () => { ...@@ -34,17 +46,12 @@ describe('humanizeActions', () => {
}); });
describe('humanizeRules', () => { describe('humanizeRules', () => {
beforeEach(() => {
// Need to spy on window.navigator.languages as it is read-only
jest.spyOn(window.navigator, 'languages', 'get').mockReturnValueOnce(['en']);
});
it('returns the empty rules message in an Array if no rules are specified', () => { it('returns the empty rules message in an Array if no rules are specified', () => {
expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]); expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]);
}); });
it('returns the empty rules message in an Array if a single rule is passed in without a branch', () => { it('returns the empty rules message in an Array if a single rule is passed in without a branch or cluster', () => {
expect(humanizeRules([])).toStrictEqual([NO_RULE_MESSAGE]); expect(humanizeRules([mockRules[4]])).toStrictEqual([NO_RULE_MESSAGE]);
}); });
it('returns a single rule as a human-readable string', () => { it('returns a single rule as a human-readable string', () => {
...@@ -58,6 +65,7 @@ describe('humanizeRules', () => { ...@@ -58,6 +65,7 @@ describe('humanizeRules', () => {
'Scan to be performed every 10 minutes, every hour, every day on the main branch', 'Scan to be performed every 10 minutes, every hour, every day on the main branch',
'Scan to be performed on every pipeline on the release/* and staging branches', 'Scan to be performed on every pipeline on the release/* and staging branches',
'Scan to be performed on every pipeline on the release/1.*, canary and staging branches', 'Scan to be performed on every pipeline on the release/1.*, canary and staging branches',
'Scan to be performed every minute, every 20 hours, on day 4 of the month',
]); ]);
}); });
}); });
...@@ -31037,6 +31037,9 @@ msgstr "" ...@@ -31037,6 +31037,9 @@ msgstr ""
msgid "SecurityOrchestration|Scan execution policies can only be created by project owners." msgid "SecurityOrchestration|Scan execution policies can only be created by project owners."
msgstr "" msgstr ""
msgid "SecurityOrchestration|Scan to be performed %{cadence}"
msgstr ""
msgid "SecurityOrchestration|Scan to be performed %{cadence} on the %{branches}" msgid "SecurityOrchestration|Scan to be performed %{cadence} on the %{branches}"
msgstr "" msgstr ""
......
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