From b4a1a4054b96b8cbba04f332541ca8396c48a988 Mon Sep 17 00:00:00 2001 From: Artur Fedorov <afedorov@gitlab.com> Date: Wed, 31 Jan 2024 19:32:18 +0000 Subject: [PATCH] This MR changes schema for external file path Yaml structure is changed and now using include structure for pipeline execution policy ci action Changelog: changed EE: true --- .../action/code_block_action.vue | 40 ++++-- .../scan_execution/lib/from_yaml.js | 1 - .../action/code_block_action_spec.js | 126 ++++++++++++------ .../mocks/mock_scan_execution_policy_data.js | 12 +- 4 files changed, 113 insertions(+), 66 deletions(-) diff --git a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/action/code_block_action.vue b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/action/code_block_action.vue index adacffeb23527..29fc715d1357a 100644 --- a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/action/code_block_action.vue +++ b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/action/code_block_action.vue @@ -9,7 +9,11 @@ import { THOUSAND } from '~/lib/utils/constants'; import CodeBlockSourceSelector from 'ee/security_orchestration/components/policy_editor/scan_execution/action/code_block_source_selector.vue'; import PolicyPopover from 'ee/security_orchestration/components/policy_popover.vue'; import { parseCustomFileConfiguration } from 'ee/security_orchestration/components/policy_editor/utils'; -import { buildCustomCodeAction } from 'ee/security_orchestration/components/policy_editor/scan_execution/lib'; +import { + buildCustomCodeAction, + fromYaml, + toYaml, +} from 'ee/security_orchestration/components/policy_editor/scan_execution/lib'; import SectionLayout from '../../section_layout.vue'; import { ACTION_AND_LABEL } from '../../constants'; import { @@ -65,7 +69,7 @@ export default { }, data() { const { project: selectedProject, showLinkedFile } = parseCustomFileConfiguration( - this.initAction?.ci_configuration_path, + fromYaml({ manifest: this.initAction?.ci_configuration || '' })?.include, ); const yamlEditorValue = (this.initAction?.ci_configuration || '').trim(); @@ -79,7 +83,10 @@ export default { }, computed: { ciConfigurationPath() { - return this.initAction?.ci_configuration_path || {}; + return this.ciConfigurationParsed?.include || {}; + }, + ciConfigurationParsed() { + return fromYaml({ manifest: this.initAction?.ci_configuration || '' }); }, filePath() { return this.ciConfigurationPath.file; @@ -143,11 +150,9 @@ export default { }); }, setSelectedRef(ref) { - this.triggerChanged({ - ci_configuration_path: { - ...this.ciConfigurationPath, - ref, - }, + this.setCiConfigurationPath({ + ...this.ciConfigurationPath, + ref, }); }, setSelectedProject(project) { @@ -167,15 +172,13 @@ export default { delete config.id; } - this.triggerChanged({ ci_configuration_path: config }); + this.setCiConfigurationPath({ ...config }); }); }, updatedFilePath(path) { - this.triggerChanged({ - ci_configuration_path: { - ...this.ciConfigurationPath, - file: path, - }, + this.setCiConfigurationPath({ + ...this.ciConfigurationPath, + file: path, }); }, async validateFilePath() { @@ -197,6 +200,15 @@ export default { this.doesFileExist = false; } }, + setCiConfigurationPath(pathConfig) { + this.triggerChanged({ + ci_configuration: toYaml({ + include: { + ...pathConfig, + }, + }), + }); + }, triggerChanged(value) { this.$emit('changed', { ...this.initAction, ...value }); }, diff --git a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/lib/from_yaml.js b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/lib/from_yaml.js index 20a95add96a9f..9d226d9643b79 100644 --- a/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/lib/from_yaml.js +++ b/ee/app/assets/javascripts/security_orchestration/components/policy_editor/scan_execution/lib/from_yaml.js @@ -74,7 +74,6 @@ export const fromYaml = ({ manifest, validateRuleMode = false }) => { const actionsKeys = ['scan', 'site_profile', 'scanner_profile', 'variables', 'tags', 'id']; if (gon?.features?.compliancePipelineInPolicies) { - actionsKeys.push('ci_configuration_path'); actionsKeys.push('ci_configuration'); } diff --git a/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/action/code_block_action_spec.js b/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/action/code_block_action_spec.js index e84aa4df605ba..b7eca312270e8 100644 --- a/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/action/code_block_action_spec.js +++ b/ee/spec/frontend/security_orchestration/components/policy_editor/scan_execution/action/code_block_action_spec.js @@ -2,7 +2,10 @@ import { GlSprintf } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import waitForPromises from 'helpers/wait_for_promises'; import Api from 'ee/api'; -import { buildCustomCodeAction } from 'ee/security_orchestration/components/policy_editor/scan_execution/lib'; +import { + buildCustomCodeAction, + toYaml, +} from 'ee/security_orchestration/components/policy_editor/scan_execution/lib'; import CodeBlockSourceSelector from 'ee/security_orchestration/components/policy_editor/scan_execution/action/code_block_source_selector.vue'; import CodeBlockAction from 'ee/security_orchestration/components/policy_editor/scan_execution/action/code_block_action.vue'; import CodeBlockFilePath from 'ee/security_orchestration/components/policy_editor/scan_execution/action/code_block_file_path.vue'; @@ -178,7 +181,12 @@ describe('CodeBlockAction', () => { expect(wrapper.emitted('changed')).toEqual([ [buildCustomCodeAction()], - [{ ...buildCustomCodeAction(), ci_configuration_path: { file: 'file/path' } }], + [ + { + ...buildCustomCodeAction(), + ci_configuration: toYaml({ include: { file: 'file/path' } }), + }, + ], ]); }); @@ -198,9 +206,11 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - file: 'file', - }, + ci_configuration: toYaml({ + include: { + file: 'file', + }, + }), }, }, }); @@ -213,9 +223,11 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - project: 'file', - }, + ci_configuration: toYaml({ + include: { + project: 'file', + }, + }), }, }, }); @@ -228,9 +240,11 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - id: 1, - }, + ci_configuration: toYaml({ + include: { + id: 1, + }, + }), }, }, }); @@ -245,9 +259,11 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - ref: 'ref', - }, + ci_configuration: toYaml({ + include: { + ref: 'ref', + }, + }), }, }, }); @@ -269,7 +285,7 @@ describe('CodeBlockAction', () => { findCodeBlockFilePath().vm.$emit('select-ref', 'ref'); expect(wrapper.emitted('changed')[1]).toEqual([ - { ...buildCustomCodeAction(), ci_configuration_path: { ref: 'ref' } }, + { ...buildCustomCodeAction(), ci_configuration: toYaml({ include: { ref: 'ref' } }) }, ]); }); @@ -288,17 +304,21 @@ describe('CodeBlockAction', () => { findCodeBlockFilePath().vm.$emit('update-file-path', 'file-path'); expect(wrapper.emitted('changed')[1]).toEqual([ - { ...buildCustomCodeAction(), ci_configuration_path: { file: 'file-path' } }, + { + ...buildCustomCodeAction(), + ci_configuration: toYaml({ include: { file: 'file-path' } }), + }, ]); }); it('updates project', async () => { await findCodeBlockSourceSelector().vm.$emit('select', LINKED_EXISTING_FILE); await findCodeBlockFilePath().vm.$emit('select-project', project); + expect(wrapper.emitted('changed')[1]).toEqual([ { ...buildCustomCodeAction(), - ci_configuration_path: { id: 29, project: project.fullPath }, + ci_configuration: toYaml({ include: { project: project.fullPath, id: 29 } }), }, ]); }); @@ -309,7 +329,7 @@ describe('CodeBlockAction', () => { await findCodeBlockFilePath().vm.$emit('select-project', undefined); expect(wrapper.emitted('changed')[1]).toEqual([ - { ...buildCustomCodeAction(), ci_configuration_path: {} }, + { ...buildCustomCodeAction(), ci_configuration: toYaml({ include: {} }) }, ]); }); @@ -333,9 +353,11 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - id: 1, - }, + ci_configuration: toYaml({ + include: { + id: 1, + }, + }), }, }, }); @@ -350,10 +372,12 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - id: 1, - ref: 'main', - }, + ci_configuration: toYaml({ + include: { + id: 1, + ref: 'main', + }, + }), }, }, }); @@ -367,10 +391,12 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - id: 1, - ref: 'not-main', - }, + ci_configuration: toYaml({ + include: { + id: 1, + ref: 'not-main', + }, + }), }, }, }); @@ -385,10 +411,12 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - id: 1, - ref: 'main', - }, + ci_configuration: toYaml({ + include: { + id: 1, + ref: 'main', + }, + }), }, }, }); @@ -396,7 +424,9 @@ describe('CodeBlockAction', () => { it('verifies on file path change', async () => { await wrapper.setProps({ - initAction: { ci_configuration_path: { ref: 'main', file: 'new-path' } }, + initAction: { + ci_configuration: toYaml({ include: { ref: 'main', file: 'new-path' } }), + }, }); await waitForPromises(); expect(Api.getFile).toHaveBeenCalledTimes(2); @@ -411,7 +441,9 @@ describe('CodeBlockAction', () => { }); it('verifies on ref change', async () => { - await wrapper.setProps({ initAction: { ci_configuration_path: { ref: 'new-ref' } } }); + await wrapper.setProps({ + initAction: { ci_configuration: toYaml({ include: { ref: 'new-ref' } }) }, + }); await waitForPromises(); expect(Api.getFile).toHaveBeenCalledTimes(2); expect(findCodeBlockFilePath().props('doesFileExist')).toBe(true); @@ -424,14 +456,18 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - id: 1, - ref: 'not-main', - }, + ci_configuration: toYaml({ + include: { + id: 1, + ref: 'not-main', + }, + }), }, }, }); - await wrapper.setProps({ initAction: { ci_configuration_path: { ref: 'new-ref' } } }); + await wrapper.setProps({ + initAction: { ci_configuration: toYaml({ include: { ref: 'new-ref' } }) }, + }); await waitForPromises(); expect(Api.getFile).toHaveBeenCalledTimes(2); expect(findCodeBlockFilePath().props('doesFileExist')).toBe(false); @@ -450,10 +486,12 @@ describe('CodeBlockAction', () => { createComponent({ propsData: { initAction: { - ci_configuration_path: { - id: 1, - ref: 'main', - }, + ci_configuration: toYaml({ + include: { + id: 1, + ref: 'main', + }, + }), }, }, }); diff --git a/ee/spec/frontend/security_orchestration/mocks/mock_scan_execution_policy_data.js b/ee/spec/frontend/security_orchestration/mocks/mock_scan_execution_policy_data.js index 3aed9fdecccb8..99215698c0037 100644 --- a/ee/spec/frontend/security_orchestration/mocks/mock_scan_execution_policy_data.js +++ b/ee/spec/frontend/security_orchestration/mocks/mock_scan_execution_policy_data.js @@ -256,10 +256,9 @@ rules: actions: - scan: sast - scan: custom - ci_configuration_path: - file: file ci_configuration: - file: file + include: + file: file `; export const mockCodeBlockFilePathScanExecutionObject = { @@ -271,11 +270,10 @@ export const mockCodeBlockFilePathScanExecutionObject = { { scan: 'sast', id: actionId }, { scan: 'custom', - ci_configuration_path: { - file: 'file', - }, ci_configuration: { - file: 'file', + include: { + file: 'file', + }, }, id: actionId, }, -- GitLab