Commit 269efbd6 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '321419-new-policy-gets-rule-by-default' into 'master'

New policy starts out with a rule by default

See merge request gitlab-org/gitlab!60464
parents cbe78223 953f690e
...@@ -84,7 +84,7 @@ export default { ...@@ -84,7 +84,7 @@ export default {
isEnabled: false, isEnabled: false,
endpointMatchMode: EndpointMatchModeAny, endpointMatchMode: EndpointMatchModeAny,
endpointLabels: '', endpointLabels: '',
rules: [], rules: [buildRule(RuleTypeEndpoint)],
annotations: '', annotations: '',
labels: '', labels: '',
}; };
......
---
title: New policy starts out with a rule by default
merge_request: 60464
author:
type: changed
...@@ -156,6 +156,13 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = ` ...@@ -156,6 +156,13 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
data-testid="rule-builder-container" data-testid="rule-builder-container"
> >
<policy-rule-builder-stub
class="gl-mb-4"
endpointlabels=""
endpointmatchmode="any"
rule="[object Object]"
/>
<div <div
class="gl-p-3 gl-rounded-base gl-border-1 gl-border-solid gl-border-gray-100 gl-mb-5" class="gl-p-3 gl-rounded-base gl-border-1 gl-border-solid gl-border-gray-100 gl-mb-5"
> >
...@@ -191,7 +198,7 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = ` ...@@ -191,7 +198,7 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
<policy-preview-stub <policy-preview-stub
initialtab="0" initialtab="0"
policydescription="Deny all traffic" policydescription="Allow all inbound traffic to <strong>all</strong> pods from <strong>all</strong> pods on <strong>any</strong> port"
policyyaml="apiVersion: cilium.io/v2 policyyaml="apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy kind: CiliumNetworkPolicy
metadata: metadata:
...@@ -202,6 +209,9 @@ spec: ...@@ -202,6 +209,9 @@ spec:
endpointSelector: endpointSelector:
matchLabels: matchLabels:
network-policy.gitlab.com/disabled_by: gitlab network-policy.gitlab.com/disabled_by: gitlab
ingress:
- fromEndpoints:
- matchLabels: {}
" "
/> />
</dim-disable-container-stub> </dim-disable-container-stub>
......
...@@ -82,6 +82,7 @@ spec: ...@@ -82,6 +82,7 @@ spec:
const findPolicyDescription = () => wrapper.find("[id='policyDescription']"); const findPolicyDescription = () => wrapper.find("[id='policyDescription']");
const findPolicyEnableContainer = () => wrapper.findByTestId('policy-enable'); const findPolicyEnableContainer = () => wrapper.findByTestId('policy-enable');
const findPolicyName = () => wrapper.find("[id='policyName']"); const findPolicyName = () => wrapper.find("[id='policyName']");
const findPolicyRuleBuilder = () => wrapper.findComponent(PolicyRuleBuilder);
const findSavePolicy = () => wrapper.findByTestId('save-policy'); const findSavePolicy = () => wrapper.findByTestId('save-policy');
const findDeletePolicy = () => wrapper.findByTestId('delete-policy'); const findDeletePolicy = () => wrapper.findByTestId('delete-policy');
const findEditorModeToggle = () => wrapper.findByTestId('editor-mode'); const findEditorModeToggle = () => wrapper.findByTestId('editor-mode');
...@@ -112,6 +113,14 @@ spec: ...@@ -112,6 +113,14 @@ spec:
expect(wrapper.findComponent(GlToggle).props('label')).toBe(PolicyEditorApp.i18n.toggleLabel); expect(wrapper.findComponent(GlToggle).props('label')).toBe(PolicyEditorApp.i18n.toggleLabel);
}); });
it('renders a default rule with label', () => {
expect(findPolicyRuleBuilder().exists()).toBe(true);
expect(findPolicyRuleBuilder().attributes()).toMatchObject({
endpointlabels: '',
endpointmatchmode: 'any',
});
});
it('does not render yaml editor', () => { it('does not render yaml editor', () => {
expect(findYamlEditor().exists()).toBe(false); expect(findYamlEditor().exists()).toBe(false);
}); });
...@@ -227,13 +236,13 @@ spec: ...@@ -227,13 +236,13 @@ spec:
}); });
it('adds a new rule', async () => { it('adds a new rule', async () => {
expect(wrapper.findAll(PolicyRuleBuilder).length).toEqual(0); expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1);
const button = findAddRuleButton(); const button = findAddRuleButton();
button.vm.$emit('click'); button.vm.$emit('click');
button.vm.$emit('click'); button.vm.$emit('click');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
const elements = wrapper.findAll(PolicyRuleBuilder); const elements = wrapper.findAllComponents(PolicyRuleBuilder);
expect(elements.length).toEqual(2); expect(elements).toHaveLength(3);
elements.wrappers.forEach((builder, idx) => { elements.wrappers.forEach((builder, idx) => {
expect(builder.props().rule).toMatchObject({ expect(builder.props().rule).toMatchObject({
...@@ -250,11 +259,11 @@ spec: ...@@ -250,11 +259,11 @@ spec:
it('removes a new rule', async () => { it('removes a new rule', async () => {
findAddRuleButton().vm.$emit('click'); findAddRuleButton().vm.$emit('click');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.findAll(PolicyRuleBuilder).length).toEqual(1); expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(2);
wrapper.find(PolicyRuleBuilder).vm.$emit('remove'); findPolicyRuleBuilder().vm.$emit('remove');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.findAll(PolicyRuleBuilder).length).toEqual(0); expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1);
}); });
it('updates yaml editor value on switch to yaml editor', async () => { it('updates yaml editor value on switch to yaml editor', async () => {
...@@ -362,7 +371,7 @@ spec: ...@@ -362,7 +371,7 @@ spec:
it('presents existing policy', () => { it('presents existing policy', () => {
expect(findPolicyName().attributes().value).toEqual('policy'); expect(findPolicyName().attributes().value).toEqual('policy');
expect(wrapper.findAll(PolicyRuleBuilder).length).toEqual(1); expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1);
}); });
it('updates existing policy and redirects to a threat monitoring path', async () => { it('updates existing policy and redirects to a threat monitoring path', async () => {
......
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