From 2ba6ac63ee0089c1ab615219a5b08ad628d4ab56 Mon Sep 17 00:00:00 2001 From: Alexander Turinske <aturinske@gitlab.com> Date: Sat, 13 Jan 2024 15:30:17 -0800 Subject: [PATCH] Update integration tests - add tests for scan execution rules - update other tests --- .../policy_editor/mocks/rule_mocks.js | 24 ++++++ .../scan_execution/actions_spec.js | 39 ++------- .../scan_execution/rules_spec.js | 85 +++++++++++++++++++ .../policy_editor/scan_result/rules_spec.js | 16 +--- 4 files changed, 119 insertions(+), 45 deletions(-) create mode 100644 ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/rules_spec.js diff --git a/ee/spec/frontend_integration/security_orchestration/policy_editor/mocks/rule_mocks.js b/ee/spec/frontend_integration/security_orchestration/policy_editor/mocks/rule_mocks.js index fe11918e4a618..64c99f55cf6d3 100644 --- a/ee/spec/frontend_integration/security_orchestration/policy_editor/mocks/rule_mocks.js +++ b/ee/spec/frontend_integration/security_orchestration/policy_editor/mocks/rule_mocks.js @@ -48,3 +48,27 @@ approval_settings: remove_approvals_with_new_commit: true require_password_to_approve: false `; + +export const mockPipelineScanExecutionManifest = `type: scan_execution_policy +name: '' +description: '' +enabled: true +rules: + - type: pipeline + branches: + - '*' +actions: + - scan: secret_detection +`; + +export const mockScheduleScanExecutionManifest = `type: scan_execution_policy +name: '' +description: '' +enabled: true +rules: + - type: schedule + branches: [] + cadence: 0 0 * * * +actions: + - scan: secret_detection +`; diff --git a/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/actions_spec.js b/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/actions_spec.js index db10fe5249e1f..093c877591271 100644 --- a/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/actions_spec.js +++ b/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/actions_spec.js @@ -5,7 +5,7 @@ import GroupDastProfileSelector from 'ee/security_orchestration/components/polic import ProjectDastProfileSelector from 'ee/security_orchestration/components/policy_editor/scan_execution/action/scan_filters/project_dast_profile_selector.vue'; import RunnerTagsList from 'ee/security_orchestration/components/policy_editor/scan_execution/action/scan_filters/runner_tags_list.vue'; import ScanFilterSelector from 'ee/security_orchestration/components/policy_editor/scan_filter_selector.vue'; -import ScanAction from 'ee/security_orchestration/components/policy_editor/scan_execution/action/scan_action.vue'; +import CiVariablesSelectors from 'ee/security_orchestration/components/policy_editor/scan_execution/action/scan_filters/ci_variables_selectors.vue'; import { DEFAULT_ASSIGNED_POLICY_PROJECT, NAMESPACE_TYPES, @@ -25,7 +25,7 @@ import { mockDastActionScanExecutionManifest, mockActionsVariablesScanExecutionManifest, } from '../mocks/action_mocks'; -import { verify, findYamlPreview } from '../utils'; +import { verify } from '../utils'; describe('Scan execution policy actions', () => { let wrapper; @@ -54,24 +54,13 @@ describe('Scan execution policy actions', () => { window.gon = {}; }); + const findCiVariablesSelectors = () => wrapper.findComponent(CiVariablesSelectors); const findScanTypeSelector = () => wrapper.findByTestId('scan-type-selector'); const findGroupDastProfileSelector = () => wrapper.findComponent(GroupDastProfileSelector); const findProjectDastProfileSelector = () => wrapper.findComponent(ProjectDastProfileSelector); - const findScanAction = () => wrapper.findComponent(ScanAction); const findRunnerTagsList = () => wrapper.findComponent(RunnerTagsList); const findScanFilterSelector = () => wrapper.findComponent(ScanFilterSelector); - describe('initial state', () => { - beforeEach(() => { - createWrapper(); - }); - - it('should render action section', () => { - expect(findScanAction().exists()).toBe(true); - expect(findYamlPreview(wrapper).text()).toContain('actions:\n - scan: secret_detection'); - }); - }); - describe('secret detection', () => { beforeEach(() => { createWrapper(); @@ -79,11 +68,8 @@ describe('Scan execution policy actions', () => { it('selects secret detection scan as action', async () => { const verifyRuleMode = () => { - expect(findScanAction().exists()).toBe(true); + expect(findScanTypeSelector().exists()).toBe(true); expect(findRunnerTagsList().exists()).toBe(true); - expect(findScanAction().props('initAction')).toEqual({ - scan: REPORT_TYPE_SECRET_DETECTION, - }); }; await verify({ @@ -107,9 +93,8 @@ describe('Scan execution policy actions', () => { ${REPORT_TYPE_DEPENDENCY_SCANNING} `(`selects secret detection $scanType as action`, async ({ scanType }) => { const verifyRuleMode = () => { - expect(findScanAction().exists()).toBe(true); + expect(findScanTypeSelector().exists()).toBe(true); expect(findRunnerTagsList().exists()).toBe(true); - expect(findScanAction().props('initAction')).toEqual({ scan: scanType }); }; await findScanTypeSelector().vm.$emit('select', scanType); @@ -135,14 +120,9 @@ describe('Scan execution policy actions', () => { }); const verifyRuleMode = () => { - expect(findScanAction().exists()).toBe(true); + expect(findScanTypeSelector().exists()).toBe(true); expect(findDastSelector().exists()).toBe(true); expect(findRunnerTagsList().exists()).toBe(true); - expect(findScanAction().props('initAction')).toEqual({ - scan: REPORT_TYPE_DAST, - site_profile: '', - scanner_profile: '', - }); }; await findScanTypeSelector().vm.$emit('select', REPORT_TYPE_DAST); @@ -158,10 +138,9 @@ describe('Scan execution policy actions', () => { it('selects variables filter', async () => { const verifyRuleMode = () => { - expect(findScanAction().props('initAction')).toEqual({ - scan: REPORT_TYPE_SECRET_DETECTION, - variables: { '': '' }, - }); + expect(findScanTypeSelector().exists()).toBe(true); + expect(findRunnerTagsList().exists()).toBe(true); + expect(findCiVariablesSelectors().exists()).toBe(true); }; await findScanFilterSelector().vm.$emit('select', CI_VARIABLE); diff --git a/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/rules_spec.js b/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/rules_spec.js new file mode 100644 index 0000000000000..5a37d3ddce2d9 --- /dev/null +++ b/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_execution/rules_spec.js @@ -0,0 +1,85 @@ +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import * as urlUtils from '~/lib/utils/url_utility'; +import App from 'ee/security_orchestration/components/policy_editor/app.vue'; +import { DEFAULT_ASSIGNED_POLICY_PROJECT } from 'ee/security_orchestration/constants'; +import BaseRuleComponent from 'ee/security_orchestration/components/policy_editor/scan_execution/rule/base_rule_component.vue'; +import ScheduleRuleComponent from 'ee/security_orchestration/components/policy_editor/scan_execution/rule/schedule_rule_component.vue'; +import { SCAN_EXECUTION_SCHEDULE_RULE } from 'ee/security_orchestration/components/policy_editor/scan_execution/constants'; +import { DEFAULT_PROVIDE } from '../mocks/mocks'; +import { + mockPipelineScanExecutionManifest, + mockScheduleScanExecutionManifest, +} from '../mocks/rule_mocks'; +import { verify } from '../utils'; + +describe('Scan execution policy actions', () => { + let wrapper; + + const createWrapper = ({ propsData = {}, provide = {} } = {}) => { + wrapper = mountExtended(App, { + propsData: { + assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT, + ...propsData, + }, + provide: { + ...DEFAULT_PROVIDE, + ...provide, + }, + stubs: { + SourceEditor: true, + }, + }); + }; + + const findScheduleRuleTypeDropDown = () => wrapper.findByTestId('rule-component-type'); + + beforeEach(() => { + jest.spyOn(urlUtils, 'getParameterByName').mockReturnValue('scan_execution_policy'); + }); + + afterEach(() => { + window.gon = {}; + }); + + const findBaseRuleComponent = () => wrapper.findComponent(BaseRuleComponent); + const findScheduleRuleComponent = () => wrapper.findComponent(ScheduleRuleComponent); + + describe('pipeline', () => { + beforeEach(() => { + createWrapper(); + }); + + it('parses pipeline rule', async () => { + const verifyRuleMode = () => { + expect(findBaseRuleComponent().exists()).toBe(true); + expect(findScheduleRuleComponent().exists()).toBe(false); + }; + + await verify({ + manifest: mockPipelineScanExecutionManifest, + verifyRuleMode, + wrapper, + }); + }); + }); + + describe('schedule rule', () => { + beforeEach(() => { + createWrapper(); + }); + + it('parses schedule rule', async () => { + const verifyRuleMode = () => { + expect(findScheduleRuleComponent().exists()).toBe(true); + }; + + await findScheduleRuleTypeDropDown().vm.$emit('select', SCAN_EXECUTION_SCHEDULE_RULE); + + await verify({ + manifest: mockScheduleScanExecutionManifest, + verifyRuleMode, + wrapper, + }); + }); + }); +}); diff --git a/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_result/rules_spec.js b/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_result/rules_spec.js index 760c61184af88..04aedfacc080f 100644 --- a/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_result/rules_spec.js +++ b/ee/spec/frontend_integration/security_orchestration/policy_editor/scan_result/rules_spec.js @@ -7,7 +7,6 @@ import LicenseScanRuleBuilder from 'ee/security_orchestration/components/policy_ import SecurityScanRuleBuilder from 'ee/security_orchestration/components/policy_editor/scan_result/rule/security_scan_rule_builder.vue'; import SettingsItem from 'ee/security_orchestration/components/policy_editor/scan_result/settings/settings_item.vue'; import SettingsSection from 'ee/security_orchestration/components/policy_editor/scan_result/settings/settings_section.vue'; -import RuleSection from 'ee/security_orchestration/components/policy_editor/scan_result/rule/rule_section.vue'; import * as urlUtils from '~/lib/utils/url_utility'; import { DEFAULT_ASSIGNED_POLICY_PROJECT } from 'ee/security_orchestration/constants'; import { @@ -21,7 +20,7 @@ import { mockLicenseScanResultManifest, mockAnyMergeRequestScanResultManifest, } from '../mocks/rule_mocks'; -import { verify, findYamlPreview } from '../utils'; +import { verify } from '../utils'; describe('Scan result policy rules', () => { let wrapper; @@ -56,22 +55,9 @@ describe('Scan result policy rules', () => { const findDefaultRuleBuilder = () => wrapper.findComponent(DefaultRuleBuilder); const findScanTypeSelect = () => wrapper.findComponent(ScanTypeSelect); const findAnyMergeRequestRuleBuilder = () => wrapper.findComponent(AnyMergeRequestRuleBuilder); - const findRuleSection = () => wrapper.findComponent(RuleSection); const findSettingsSection = () => wrapper.findComponent(SettingsSection); const findAllSettingsItem = () => wrapper.findAllComponents(SettingsItem); - describe('initial state', () => { - beforeEach(() => { - createWrapper(); - }); - - it('should render rule section', () => { - expect(findRuleSection().exists()).toBe(true); - expect(findDefaultRuleBuilder().exists()).toBe(true); - expect(findYamlPreview(wrapper).text()).toContain("rules:\n - type: ''"); - }); - }); - describe('security scan', () => { beforeEach(() => { createWrapper(); -- GitLab