Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b481209b
Commit
b481209b
authored
Jun 13, 2021
by
Alexander Turinske
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up tests
- add translation
parent
38873a13
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
46 deletions
+57
-46
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_editor.vue
...or/scan_execution_policy/scan_execution_policy_editor.vue
+0
-12
ee/spec/frontend/threat_monitoring/components/policy_editor/network_policy/network_policy_editor_spec.js
...olicy_editor/network_policy/network_policy_editor_spec.js
+15
-30
ee/spec/frontend/threat_monitoring/components/policy_editor/policy_editor_layout_spec.js
...ing/components/policy_editor/policy_editor_layout_spec.js
+2
-4
ee/spec/frontend/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_editor_spec.js
...can_execution_policy/scan_execution_policy_editor_spec.js
+37
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
No files found.
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_editor.vue
View file @
b481209b
...
...
@@ -32,8 +32,6 @@ export default {
:
DEFAULT_SCAN_EXECUTION_POLICY
;
return
{
isRemovingPolicy
:
false
,
isUpdatingPolicy
:
false
,
policy
,
yamlEditorValue
,
};
...
...
@@ -44,12 +42,6 @@ export default {
},
},
methods
:
{
removePolicy
()
{
// TODO call graphql mutation and redirect to merge request after #329422 is closed
},
savePolicy
()
{
// TODO call graphql mutation and redirect to merge request after #329422 is closed
},
updateYaml
(
manifest
)
{
this
.
yamlEditorValue
=
manifest
;
},
...
...
@@ -62,12 +54,8 @@ export default {
:default-editor-mode=
"$options.DEFAULT_EDITOR_MODE"
:editor-modes=
"$options.EDITOR_MODES"
:is-editing=
"isEditing"
:is-removing-policy=
"isRemovingPolicy"
:is-updating-policy=
"isUpdatingPolicy"
:policy-name=
"policy.name"
:yaml-editor-value=
"yamlEditorValue"
@
remove-policy=
"removePolicy"
@
save-policy=
"savePolicy"
@
update-yaml=
"updateYaml"
>
<template
#save-button-text
>
...
...
ee/spec/frontend/threat_monitoring/components/policy_editor/network_policy/network_policy_editor_spec.js
View file @
b481209b
...
...
@@ -63,11 +63,9 @@ describe('NetworkPolicyEditor component', () => {
const
modifyPolicyAlert
=
async
({
isAlertEnabled
})
=>
{
const
policyAlertPicker
=
findPolicyAlertPicker
();
policyAlertPicker
.
vm
.
$emit
(
'
update-alert
'
,
isAlertEnabled
);
await
wrapper
.
vm
.
$nextTick
();
await
policyAlertPicker
.
vm
.
$emit
(
'
update-alert
'
,
isAlertEnabled
);
expect
(
policyAlertPicker
.
props
(
'
policyAlert
'
)).
toBe
(
isAlertEnabled
);
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
};
beforeEach
(()
=>
{
...
...
@@ -140,8 +138,7 @@ describe('NetworkPolicyEditor component', () => {
}),
});
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
,
EDITOR_MODE_YAML
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
,
EDITOR_MODE_YAML
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
networkPolicies/createPolicy
'
,
{
environmentId
:
-
1
,
policy
:
{
manifest
:
mockL7Manifest
},
...
...
@@ -152,24 +149,21 @@ describe('NetworkPolicyEditor component', () => {
it
(
'
given there is a name change, updates policy yaml preview
'
,
async
()
=>
{
const
initialValue
=
findPreview
().
props
(
'
policyYaml
'
);
findPolicyName
().
vm
.
$emit
(
'
input
'
,
'
new
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyName
().
vm
.
$emit
(
'
input
'
,
'
new
'
);
expect
(
findPreview
().
props
(
'
policyYaml
'
)).
not
.
toEqual
(
initialValue
);
});
it
(
'
given there is a rule change, updates policy description preview
'
,
async
()
=>
{
const
initialValue
=
findPreview
().
props
(
'
policyDescription
'
);
findAddRuleButton
().
vm
.
$emit
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findAddRuleButton
().
vm
.
$emit
(
'
click
'
);
expect
(
findPreview
().
props
(
'
policyDescription
'
)).
not
.
toEqual
(
initialValue
);
});
it
(
'
adds a new rule
'
,
async
()
=>
{
expect
(
wrapper
.
findAllComponents
(
PolicyRuleBuilder
)).
toHaveLength
(
1
);
const
button
=
findAddRuleButton
();
button
.
vm
.
$emit
(
'
click
'
);
button
.
vm
.
$emit
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
await
button
.
vm
.
$emit
(
'
click
'
);
await
button
.
vm
.
$emit
(
'
click
'
);
const
elements
=
wrapper
.
findAllComponents
(
PolicyRuleBuilder
);
expect
(
elements
).
toHaveLength
(
3
);
...
...
@@ -186,20 +180,17 @@ describe('NetworkPolicyEditor component', () => {
});
it
(
'
removes a new rule
'
,
async
()
=>
{
findAddRuleButton
().
vm
.
$emit
(
'
click
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findAddRuleButton
().
vm
.
$emit
(
'
click
'
);
expect
(
wrapper
.
findAllComponents
(
PolicyRuleBuilder
)).
toHaveLength
(
2
);
findPolicyRuleBuilder
().
vm
.
$emit
(
'
remove
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyRuleBuilder
().
vm
.
$emit
(
'
remove
'
);
expect
(
wrapper
.
findAllComponents
(
PolicyRuleBuilder
)).
toHaveLength
(
1
);
});
it
(
'
updates yaml editor value on switch to yaml editor
'
,
async
()
=>
{
const
policyEditorLayout
=
findPolicyEditorLayout
();
findPolicyName
().
vm
.
$emit
(
'
input
'
,
'
test-policy
'
);
policyEditorLayout
.
vm
.
$emit
(
'
update-editor-mode
'
,
EDITOR_MODE_YAML
);
await
wrapper
.
vm
.
$nextTick
();
await
policyEditorLayout
.
vm
.
$emit
(
'
update-editor-mode
'
,
EDITOR_MODE_YAML
);
expect
(
fromYaml
(
policyEditorLayout
.
attributes
(
'
yamleditorvalue
'
))).
toMatchObject
({
name
:
'
test-policy
'
,
});
...
...
@@ -245,16 +236,13 @@ describe('NetworkPolicyEditor component', () => {
it
(
'
does not update yaml editor value on switch to yaml editor
'
,
async
()
=>
{
findPolicyName
().
vm
.
$emit
(
'
input
'
,
'
test-policy
'
);
const
policyEditorLayout
=
findPolicyEditorLayout
();
policyEditorLayout
.
vm
.
$emit
(
'
update-editor-mode
'
,
EDITOR_MODE_YAML
);
await
wrapper
.
vm
.
$nextTick
();
await
policyEditorLayout
.
vm
.
$emit
(
'
update-editor-mode
'
,
EDITOR_MODE_YAML
);
expect
(
policyEditorLayout
.
attributes
(
'
yamleditorvalue
'
)).
toEqual
(
''
);
});
});
it
(
'
creates policy and redirects to a threat monitoring path
'
,
async
()
=>
{
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
networkPolicies/createPolicy
'
,
{
environmentId
:
-
1
,
policy
:
{
manifest
:
toYaml
(
wrapper
.
vm
.
policy
)
},
...
...
@@ -272,8 +260,7 @@ describe('NetworkPolicyEditor component', () => {
});
it
(
'
it does not redirect
'
,
async
()
=>
{
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
expect
(
redirectTo
).
not
.
toHaveBeenCalledWith
(
'
/threat-monitoring
'
);
});
});
...
...
@@ -299,8 +286,7 @@ describe('NetworkPolicyEditor component', () => {
});
it
(
'
updates existing policy and redirects to a threat monitoring path
'
,
async
()
=>
{
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
networkPolicies/updatePolicy
'
,
{
environmentId
:
-
1
,
policy
:
{
name
:
'
policy
'
,
manifest
:
toYaml
(
wrapper
.
vm
.
policy
)
},
...
...
@@ -328,8 +314,7 @@ describe('NetworkPolicyEditor component', () => {
});
it
(
'
removes policy and redirects to a threat monitoring path on secondary modal button click
'
,
async
()
=>
{
findPolicyEditorLayout
().
vm
.
$emit
(
'
remove-policy
'
);
await
wrapper
.
vm
.
$nextTick
();
await
findPolicyEditorLayout
().
vm
.
$emit
(
'
remove-policy
'
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
networkPolicies/deletePolicy
'
,
{
environmentId
:
-
1
,
...
...
ee/spec/frontend/threat_monitoring/components/policy_editor/policy_editor_layout_spec.js
View file @
b481209b
...
...
@@ -58,15 +58,13 @@ describe('PolicyEditorLayout component', () => {
it
(
'
mode changes appropriately when new mode is selected
'
,
async
()
=>
{
expect
(
findRuleModeSection
().
exists
()).
toBe
(
true
);
expect
(
findYamlModeSection
().
exists
()).
toBe
(
false
);
findEditorModeToggle
().
vm
.
$emit
(
'
input
'
,
EDITOR_MODE_YAML
);
await
wrapper
.
vm
.
$nextTick
();
await
findEditorModeToggle
().
vm
.
$emit
(
'
input
'
,
EDITOR_MODE_YAML
);
expect
(
findRuleModeSection
().
exists
()).
toBe
(
false
);
expect
(
findYamlModeSection
().
exists
()).
toBe
(
true
);
expect
(
wrapper
.
emitted
(
'
update-editor-mode
'
)).
toStrictEqual
([[
EDITOR_MODE_YAML
]]);
});
it
(
'
does display custom save button text
'
,
()
=>
{
// custom save button text works
const
saveButton
=
findSavePolicyButton
();
expect
(
saveButton
.
exists
()).
toBe
(
true
);
expect
(
saveButton
.
text
()).
toBe
(
'
Create policy
'
);
...
...
@@ -118,7 +116,7 @@ describe('PolicyEditorLayout component', () => {
expect
(
findComponent
().
exists
()).
toBe
(
state
);
});
it
(
'
emits proper
t
ly when yaml is updated
'
,
()
=>
{
it
(
'
emits properly when yaml is updated
'
,
()
=>
{
const
newManifest
=
'
new yaml!
'
;
findYamlModeSection
().
vm
.
$emit
(
'
input
'
,
newManifest
);
expect
(
wrapper
.
emitted
(
'
update-yaml
'
)).
toStrictEqual
([[
newManifest
]]);
...
...
ee/spec/frontend/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_spec.js
→
ee/spec/frontend/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_
editor_
spec.js
View file @
b481209b
...
...
@@ -2,7 +2,6 @@ import { shallowMount } from '@vue/test-utils';
import
PolicyEditorLayout
from
'
ee/threat_monitoring/components/policy_editor/policy_editor_layout.vue
'
;
import
{
DEFAULT_SCAN_EXECUTION_POLICY
}
from
'
ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib
'
;
import
ScanExecutionPolicyEditor
from
'
ee/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_editor.vue
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
describe
(
'
ScanExecutionPolicyEditor
'
,
()
=>
{
let
wrapper
;
...
...
@@ -27,36 +26,12 @@ describe('ScanExecutionPolicyEditor', () => {
wrapper
.
destroy
();
});
it
(
'
calls the save policy funtion when "save-policy" is emitted
'
,
async
()
=>
{
const
savePolicySpy
=
jest
.
spyOn
(
wrapper
.
vm
,
'
savePolicy
'
);
expect
(
wrapper
.
vm
.
savePolicy
).
toHaveBeenCalledTimes
(
0
);
findPolicyEditorLayout
().
vm
.
$emit
(
'
save-policy
'
);
await
waitForPromises
();
expect
(
wrapper
.
vm
.
savePolicy
).
toHaveBeenCalledTimes
(
1
);
savePolicySpy
.
mockRestore
();
});
it
(
'
calls the remove policy funtion when "remove-policy" is emitted
'
,
async
()
=>
{
const
removePolicySpy
=
jest
.
spyOn
(
wrapper
.
vm
,
'
removePolicy
'
);
expect
(
wrapper
.
vm
.
removePolicy
).
toHaveBeenCalledTimes
(
0
);
findPolicyEditorLayout
().
vm
.
$emit
(
'
remove-policy
'
);
await
waitForPromises
();
expect
(
wrapper
.
vm
.
removePolicy
).
toHaveBeenCalledTimes
(
1
);
removePolicySpy
.
mockRestore
();
});
it
(
'
updates the policy yaml when "update-yaml" is emitted
'
,
async
()
=>
{
const
updateYamlSpy
=
jest
.
spyOn
(
wrapper
.
vm
,
'
updateYaml
'
);
const
newManifest
=
'
new yaml!
'
;
expect
(
wrapper
.
vm
.
updateYaml
).
toHaveBeenCalledTimes
(
0
);
expect
(
findPolicyEditorLayout
().
attributes
(
'
yamleditorvalue
'
)).
toBe
(
DEFAULT_SCAN_EXECUTION_POLICY
,
);
findPolicyEditorLayout
().
vm
.
$emit
(
'
update-yaml
'
,
newManifest
);
await
waitForPromises
();
expect
(
wrapper
.
vm
.
updateYaml
).
toHaveBeenCalledTimes
(
1
);
expect
(
wrapper
.
vm
.
updateYaml
).
toHaveBeenCalledWith
(
newManifest
);
expect
(
findPolicyEditorLayout
().
attributes
(
'
yaml-editor-value
'
)).
toBe
(
newManifest
);
updateYamlSpy
.
mockRestore
();
await
findPolicyEditorLayout
().
vm
.
$emit
(
'
update-yaml
'
,
newManifest
);
expect
(
findPolicyEditorLayout
().
attributes
(
'
yamleditorvalue
'
)).
toBe
(
newManifest
);
});
});
locale/gitlab.pot
View file @
b481209b
...
...
@@ -21755,6 +21755,9 @@ msgstr ""
msgid "NetworkPolicies|Save changes"
msgstr ""
msgid "NetworkPolicies|Scan Execution"
msgstr ""
msgid "NetworkPolicies|Something went wrong, failed to update policy"
msgstr ""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment