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 {
isEnabled: false,
endpointMatchMode: EndpointMatchModeAny,
endpointLabels: '',
rules: [],
rules: [buildRule(RuleTypeEndpoint)],
annotations: '',
labels: '',
};
......
---
title: New policy starts out with a rule by default
merge_request: 60464
author:
type: changed
......@@ -155,7 +155,14 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
<dim-disable-container-stub
data-testid="rule-builder-container"
>
<policy-rule-builder-stub
class="gl-mb-4"
endpointlabels=""
endpointmatchmode="any"
rule="[object Object]"
/>
<div
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`] = `
<policy-preview-stub
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
kind: CiliumNetworkPolicy
metadata:
......@@ -202,6 +209,9 @@ spec:
endpointSelector:
matchLabels:
network-policy.gitlab.com/disabled_by: gitlab
ingress:
- fromEndpoints:
- matchLabels: {}
"
/>
</dim-disable-container-stub>
......
......@@ -82,6 +82,7 @@ spec:
const findPolicyDescription = () => wrapper.find("[id='policyDescription']");
const findPolicyEnableContainer = () => wrapper.findByTestId('policy-enable');
const findPolicyName = () => wrapper.find("[id='policyName']");
const findPolicyRuleBuilder = () => wrapper.findComponent(PolicyRuleBuilder);
const findSavePolicy = () => wrapper.findByTestId('save-policy');
const findDeletePolicy = () => wrapper.findByTestId('delete-policy');
const findEditorModeToggle = () => wrapper.findByTestId('editor-mode');
......@@ -112,6 +113,14 @@ spec:
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', () => {
expect(findYamlEditor().exists()).toBe(false);
});
......@@ -227,13 +236,13 @@ spec:
});
it('adds a new rule', async () => {
expect(wrapper.findAll(PolicyRuleBuilder).length).toEqual(0);
expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1);
const button = findAddRuleButton();
button.vm.$emit('click');
button.vm.$emit('click');
await wrapper.vm.$nextTick();
const elements = wrapper.findAll(PolicyRuleBuilder);
expect(elements.length).toEqual(2);
const elements = wrapper.findAllComponents(PolicyRuleBuilder);
expect(elements).toHaveLength(3);
elements.wrappers.forEach((builder, idx) => {
expect(builder.props().rule).toMatchObject({
......@@ -250,11 +259,11 @@ spec:
it('removes a new rule', async () => {
findAddRuleButton().vm.$emit('click');
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();
expect(wrapper.findAll(PolicyRuleBuilder).length).toEqual(0);
expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1);
});
it('updates yaml editor value on switch to yaml editor', async () => {
......@@ -362,7 +371,7 @@ spec:
it('presents existing 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 () => {
......
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