Skip to content
代码片段 群组 项目
未验证 提交 e97b6ded 编辑于 作者: Lorenz van Herwaarden's avatar Lorenz van Herwaarden 提交者: GitLab
浏览文件

Allow to save and update vulnerability management policy

Provide save and update capabilities for vulnerability management
policy type in the editor component.
上级 4788ca1b
No related branches found
No related tags found
无相关合并请求
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
EDITOR_MODE_RULE, EDITOR_MODE_RULE,
EDITOR_MODE_YAML, EDITOR_MODE_YAML,
PARSING_ERROR_MESSAGE, PARSING_ERROR_MESSAGE,
SECURITY_POLICY_ACTIONS,
} from '../constants'; } from '../constants';
import EditorLayout from '../editor_layout.vue'; import EditorLayout from '../editor_layout.vue';
import DimDisableContainer from '../dim_disable_container.vue'; import DimDisableContainer from '../dim_disable_container.vue';
...@@ -16,6 +17,7 @@ import RuleSection from './rule/rule_section.vue'; ...@@ -16,6 +17,7 @@ import RuleSection from './rule/rule_section.vue';
import ActionSection from './action/action_section.vue'; import ActionSection from './action/action_section.vue';
export default { export default {
SECURITY_POLICY_ACTIONS,
EDITOR_MODE_RULE, EDITOR_MODE_RULE,
EDITOR_MODE_YAML, EDITOR_MODE_YAML,
i18n: { i18n: {
...@@ -41,6 +43,14 @@ export default { ...@@ -41,6 +43,14 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
isCreating: {
type: Boolean,
required: true,
},
isDeleting: {
type: Boolean,
required: true,
},
isEditing: { isEditing: {
type: Boolean, type: Boolean,
required: true, required: true,
...@@ -62,16 +72,28 @@ export default { ...@@ -62,16 +72,28 @@ export default {
mode: EDITOR_MODE_RULE, mode: EDITOR_MODE_RULE,
policy, policy,
yamlEditorValue, yamlEditorValue,
isUpdatingPolicy: false,
isRemovingPolicy: false,
hasParsingError, hasParsingError,
parsingError, parsingError,
}; };
}, },
computed: {
policyActionName() {
return this.isEditing
? this.$options.SECURITY_POLICY_ACTIONS.REPLACE
: this.$options.SECURITY_POLICY_ACTIONS.APPEND;
},
},
methods: { methods: {
changeEditorMode(mode) { changeEditorMode(mode) {
this.mode = mode; this.mode = mode;
}, },
async handleModifyPolicy(act) {
// Assumes feature flag securityPoliciesProjectBackgroundWorker is enabled
this.$emit('save', {
action: act || this.policyActionName,
policy: this.yamlEditorValue,
});
},
handleUpdateProperty(property, value) { handleUpdateProperty(property, value) {
this.policy[property] = value; this.policy[property] = value;
this.updateYamlEditorValue(this.policy); this.updateYamlEditorValue(this.policy);
...@@ -107,10 +129,12 @@ export default { ...@@ -107,10 +129,12 @@ export default {
:policy="policy" :policy="policy"
:yaml-editor-value="yamlEditorValue" :yaml-editor-value="yamlEditorValue"
:is-editing="isEditing" :is-editing="isEditing"
:is-removing-policy="isRemovingPolicy" :is-removing-policy="isDeleting"
:is-updating-policy="isUpdatingPolicy" :is-updating-policy="isCreating"
:has-parsing-error="hasParsingError" :has-parsing-error="hasParsingError"
:parsing-error="parsingError" :parsing-error="parsingError"
@remove-policy="handleModifyPolicy($options.SECURITY_POLICY_ACTIONS.REMOVE)"
@save-policy="handleModifyPolicy()"
@update-editor-mode="changeEditorMode" @update-editor-mode="changeEditorMode"
@update-property="handleUpdateProperty" @update-property="handleUpdateProperty"
@update-yaml="handleUpdateYaml" @update-yaml="handleUpdateYaml"
......
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import waitForPromises from 'helpers/wait_for_promises';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { DEFAULT_ASSIGNED_POLICY_PROJECT } from 'ee/security_orchestration/constants'; import { DEFAULT_ASSIGNED_POLICY_PROJECT } from 'ee/security_orchestration/constants';
import EditorComponent from 'ee/security_orchestration/components/policy_editor/vulnerability_management/editor_component.vue'; import EditorComponent from 'ee/security_orchestration/components/policy_editor/vulnerability_management/editor_component.vue';
...@@ -6,6 +7,9 @@ import EditorLayout from 'ee/security_orchestration/components/policy_editor/edi ...@@ -6,6 +7,9 @@ import EditorLayout from 'ee/security_orchestration/components/policy_editor/edi
import RuleSection from 'ee/security_orchestration/components/policy_editor/vulnerability_management/rule/rule_section.vue'; import RuleSection from 'ee/security_orchestration/components/policy_editor/vulnerability_management/rule/rule_section.vue';
import ActionSection from 'ee/security_orchestration/components/policy_editor/vulnerability_management/action/action_section.vue'; import ActionSection from 'ee/security_orchestration/components/policy_editor/vulnerability_management/action/action_section.vue';
import { DEFAULT_VULNERABILITY_MANAGEMENT_POLICY } from 'ee/security_orchestration/components/policy_editor/vulnerability_management/constants'; import { DEFAULT_VULNERABILITY_MANAGEMENT_POLICY } from 'ee/security_orchestration/components/policy_editor/vulnerability_management/constants';
import { SECURITY_POLICY_ACTIONS } from 'ee/security_orchestration/components/policy_editor/constants';
import { ASSIGNED_POLICY_PROJECT } from 'ee_jest/security_orchestration/mocks/mock_data';
import { import {
mockVulnerabilityManagementManifest, mockVulnerabilityManagementManifest,
mockVulnerabilityManagementObject, mockVulnerabilityManagementObject,
...@@ -19,6 +23,8 @@ describe('EditorComponent', () => { ...@@ -19,6 +23,8 @@ describe('EditorComponent', () => {
wrapper = shallowMountExtended(EditorComponent, { wrapper = shallowMountExtended(EditorComponent, {
propsData: { propsData: {
assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT, assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT,
isCreating: false,
isDeleting: false,
isEditing: false, isEditing: false,
...propsData, ...propsData,
}, },
...@@ -29,6 +35,16 @@ describe('EditorComponent', () => { ...@@ -29,6 +35,16 @@ describe('EditorComponent', () => {
}); });
}; };
const factoryWithExistingPolicy = () => {
return factory({
propsData: {
assignedPolicyProject: ASSIGNED_POLICY_PROJECT,
existingPolicy: mockVulnerabilityManagementObject,
isEditing: true,
},
});
};
const findPolicyEditorLayout = () => wrapper.findComponent(EditorLayout); const findPolicyEditorLayout = () => wrapper.findComponent(EditorLayout);
const findRuleSection = () => wrapper.findComponent(RuleSection); const findRuleSection = () => wrapper.findComponent(RuleSection);
const findAllRuleSections = () => wrapper.findAllComponents(RuleSection); const findAllRuleSections = () => wrapper.findAllComponents(RuleSection);
...@@ -124,4 +140,18 @@ describe('EditorComponent', () => { ...@@ -124,4 +140,18 @@ describe('EditorComponent', () => {
); );
}); });
}); });
describe('modifying a policy', () => {
it.each`
status | action | event | factoryFn | yamlEditorValue
${'creating a new policy'} | ${SECURITY_POLICY_ACTIONS.APPEND} | ${'save-policy'} | ${factory} | ${DEFAULT_VULNERABILITY_MANAGEMENT_POLICY}
${'updating an existing policy'} | ${SECURITY_POLICY_ACTIONS.REPLACE} | ${'save-policy'} | ${factoryWithExistingPolicy} | ${mockVulnerabilityManagementManifest}
${'deleting an existing policy'} | ${SECURITY_POLICY_ACTIONS.REMOVE} | ${'remove-policy'} | ${factoryWithExistingPolicy} | ${mockVulnerabilityManagementManifest}
`('emits "save" when $status', async ({ action, event, factoryFn, yamlEditorValue }) => {
factoryFn();
findPolicyEditorLayout().vm.$emit(event);
await waitForPromises();
expect(wrapper.emitted('save')).toEqual([[{ action, policy: yamlEditorValue }]]);
});
});
}); });
...@@ -24,11 +24,16 @@ actions: ...@@ -24,11 +24,16 @@ actions:
- type: auto_resolve - type: auto_resolve
rules: rules:
- type: no_longer_detected - type: no_longer_detected
scanners: ["sast", "dependency_scanning"] scanners:
severity_levels: ["high", "medium"] - sast
- dependency_scanning
severity_levels:
- high
- medium
- type: no_longer_detected - type: no_longer_detected
scanners: [] scanners: []
severity_levels: ["low"] severity_levels:
- low
`; `;
export const mockVulnerabilityManagementObject = fromYaml({ export const mockVulnerabilityManagementObject = fromYaml({
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册