on master help sign in
Add Rego syntax test file
commita0a5e30c3961273b16609c566bddb5f802d8279b authorMohamed Abdelnour <mohamed.k.abdelnour@gmail.com> dateSun 30 May 2021, 08:49 (5 years ago) parent4126bbe
3 files changed+387
tests/syntax-tests/highlighted/Rego/src_test.rego+181 tests/syntax-tests/source/Rego/LICENSE.md+25 tests/syntax-tests/source/Rego/src_test.rego+181
tests/syntax-tests/highlighted/Rego/src_test.regonew file+181
@@ -0,0 +1,181 @@
1+package k8sazureprocmount
2+
3+test_input_container_not_proc_mount_allowed {
4+ input := { "review": input_review, "parameters": input_parameters_default}
5+ results := violation with input as input
6+ count(results) == 0
7+}
8+test_input_container_proc_mount_not_allowed {
9+ input := { "review": input_review_unmasked, "parameters": input_parameters_default}
10+ results := violation with input as input
11+ count(results) == 1
12+}
13+test_input_container_proc_mount_not_allowed_null_param {
14+ input := { "review": input_review_unmasked, "parameters": null }
15+ results := violation with input as input
16+ count(results) == 1
17+}
18+test_input_container_proc_mount_not_allowed_missing_param {
19+ input := { "review": input_review_unmasked }
20+ results := violation with input as input
21+ count(results) == 1
22+}
23+test_input_container_many_not_proc_mount_allowed {
24+ input := { "review": input_review_many, "parameters": input_parameters_default}
25+ results := violation with input as input
26+ count(results) == 0
27+}
28+test_input_container_many_mixed_proc_mount_not_allowed {
29+ input := { "review": input_review_many_mixed, "parameters": input_parameters_default}
30+ results := violation with input as input
31+ count(results) == 1
32+}
33+test_input_container_many_mixed_proc_mount_not_allowed_two {
34+ input := { "review": input_review_many_mixed_two, "parameters": input_parameters_default}
35+ results := violation with input as input
36+ count(results) == 2
37+}
38+test_input_container_proc_mount_case_insensitive {
39+ input := { "review": input_review, "parameters": input_parameters_default_lower}
40+ results := violation with input as input
41+ count(results) == 0
42+}
43+test_input_container_not_proc_mount_unmasked {
44+ input := { "review": input_review, "parameters": input_parameters_unmasked}
45+ results := violation with input as input
46+ count(results) == 0
47+}
48+test_input_container_proc_mount_unmasked {
49+ input := { "review": input_review_unmasked, "parameters": input_parameters_unmasked}
50+ results := violation with input as input
51+ count(results) == 0
52+}
53+test_input_container_many_mixed_proc_mount_allowed_two {
54+ input := { "review": input_review_many_mixed_two, "parameters": input_parameters_unmasked}
55+ results := violation with input as input
56+ count(results) == 0
57+}
58+
59+input_review = {
60+ "object": {
61+ "metadata": {
62+ "name": "nginx"
63+ },
64+ "spec": {
65+ "containers": input_containers_one
66+ }
67+ }
68+}
69+
70+input_review_unmasked = {
71+ "object": {
72+ "metadata": {
73+ "name": "nginx"
74+ },
75+ "spec": {
76+ "containers": input_containers_one_unmasked
77+ }
78+ }
79+}
80+
81+input_review_many = {
82+ "object": {
83+ "metadata": {
84+ "name": "nginx"
85+ },
86+ "spec": {
87+ "containers": input_containers_many,
88+ "initContainers": input_containers_one
89+ }
90+ }
91+}
92+
93+input_review_many_mixed = {
94+ "object": {
95+ "metadata": {
96+ "name": "nginx"
97+ },
98+ "spec": {
99+ "containers": input_containers_many,
100+ "initContainers": input_containers_one_unmasked
101+ }
102+ }
103+}
104+
105+input_review_many_mixed_two = {
106+ "object": {
107+ "metadata": {
108+ "name": "nginx"
109+ },
110+ "spec": {
111+ "containers": input_containers_many_mixed,
112+ "initContainers": input_containers_one_unmasked
113+ }
114+ }
115+}
116+
117+input_containers_one = [
118+{
119+ "name": "nginx",
120+ "image": "nginx",
121+ "securityContext": {
122+ "procMount": "Default"
123+ }
124+}]
125+
126+input_containers_one_unmasked = [
127+{
128+ "name": "nginx",
129+ "image": "nginx",
130+ "securityContext": {
131+ "procMount": "Unmasked"
132+ }
133+}]
134+
135+input_containers_many = [
136+{
137+ "name": "nginx",
138+ "image": "nginx",
139+ "securityContext": {
140+ "procMount": "Default"
141+ }
142+},
143+{
144+ "name": "nginx1",
145+ "image": "nginx"
146+},
147+{
148+ "name": "nginx2",
149+ "image": "nginx",
150+ "securityContext": {
151+ "runAsUser": "1000"
152+ }
153+}]
154+
155+input_containers_many_mixed = [
156+{
157+ "name": "nginx",
158+ "image": "nginx",
159+ "securityContext": {
160+ "procMount": "Default"
161+ }
162+},
163+{
164+ "name": "nginx1",
165+ "image": "nginx",
166+ "securityContext": {
167+ "procMount": "Unmasked"
168+ }
169+}]
170+
171+input_parameters_default = {
172+ "procMount": "Default"
173+}
174+
175+input_parameters_default_lower = {
176+ "procMount": "default"
177+}
178+
179+input_parameters_unmasked = {
180+ "procMount": "Unmasked"
181+}
tests/syntax-tests/source/Rego/LICENSE.mdnew file+25
@@ -0,0 +1,25 @@
1+The `src_test.rego` file has been added from https://github.com/Azure/Community-Policy under the following license:
2+
3+```text
4+ MIT License
5+
6+ Copyright (c) Microsoft Corporation.
7+
8+ Permission is hereby granted, free of charge, to any person obtaining a copy
9+ of this software and associated documentation files (the "Software"), to deal
10+ in the Software without restriction, including without limitation the rights
11+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+ copies of the Software, and to permit persons to whom the Software is
13+ furnished to do so, subject to the following conditions:
14+
15+ The above copyright notice and this permission notice shall be included in all
16+ copies or substantial portions of the Software.
17+
18+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+ SOFTWARE
25+```
tests/syntax-tests/source/Rego/src_test.regonew file+181
@@ -0,0 +1,181 @@
1+package k8sazureprocmount
2+
3+test_input_container_not_proc_mount_allowed {
4+ input := { "review": input_review, "parameters": input_parameters_default}
5+ results := violation with input as input
6+ count(results) == 0
7+}
8+test_input_container_proc_mount_not_allowed {
9+ input := { "review": input_review_unmasked, "parameters": input_parameters_default}
10+ results := violation with input as input
11+ count(results) == 1
12+}
13+test_input_container_proc_mount_not_allowed_null_param {
14+ input := { "review": input_review_unmasked, "parameters": null }
15+ results := violation with input as input
16+ count(results) == 1
17+}
18+test_input_container_proc_mount_not_allowed_missing_param {
19+ input := { "review": input_review_unmasked }
20+ results := violation with input as input
21+ count(results) == 1
22+}
23+test_input_container_many_not_proc_mount_allowed {
24+ input := { "review": input_review_many, "parameters": input_parameters_default}
25+ results := violation with input as input
26+ count(results) == 0
27+}
28+test_input_container_many_mixed_proc_mount_not_allowed {
29+ input := { "review": input_review_many_mixed, "parameters": input_parameters_default}
30+ results := violation with input as input
31+ count(results) == 1
32+}
33+test_input_container_many_mixed_proc_mount_not_allowed_two {
34+ input := { "review": input_review_many_mixed_two, "parameters": input_parameters_default}
35+ results := violation with input as input
36+ count(results) == 2
37+}
38+test_input_container_proc_mount_case_insensitive {
39+ input := { "review": input_review, "parameters": input_parameters_default_lower}
40+ results := violation with input as input
41+ count(results) == 0
42+}
43+test_input_container_not_proc_mount_unmasked {
44+ input := { "review": input_review, "parameters": input_parameters_unmasked}
45+ results := violation with input as input
46+ count(results) == 0
47+}
48+test_input_container_proc_mount_unmasked {
49+ input := { "review": input_review_unmasked, "parameters": input_parameters_unmasked}
50+ results := violation with input as input
51+ count(results) == 0
52+}
53+test_input_container_many_mixed_proc_mount_allowed_two {
54+ input := { "review": input_review_many_mixed_two, "parameters": input_parameters_unmasked}
55+ results := violation with input as input
56+ count(results) == 0
57+}
58+
59+input_review = {
60+ "object": {
61+ "metadata": {
62+ "name": "nginx"
63+ },
64+ "spec": {
65+ "containers": input_containers_one
66+ }
67+ }
68+}
69+
70+input_review_unmasked = {
71+ "object": {
72+ "metadata": {
73+ "name": "nginx"
74+ },
75+ "spec": {
76+ "containers": input_containers_one_unmasked
77+ }
78+ }
79+}
80+
81+input_review_many = {
82+ "object": {
83+ "metadata": {
84+ "name": "nginx"
85+ },
86+ "spec": {
87+ "containers": input_containers_many,
88+ "initContainers": input_containers_one
89+ }
90+ }
91+}
92+
93+input_review_many_mixed = {
94+ "object": {
95+ "metadata": {
96+ "name": "nginx"
97+ },
98+ "spec": {
99+ "containers": input_containers_many,
100+ "initContainers": input_containers_one_unmasked
101+ }
102+ }
103+}
104+
105+input_review_many_mixed_two = {
106+ "object": {
107+ "metadata": {
108+ "name": "nginx"
109+ },
110+ "spec": {
111+ "containers": input_containers_many_mixed,
112+ "initContainers": input_containers_one_unmasked
113+ }
114+ }
115+}
116+
117+input_containers_one = [
118+{
119+ "name": "nginx",
120+ "image": "nginx",
121+ "securityContext": {
122+ "procMount": "Default"
123+ }
124+}]
125+
126+input_containers_one_unmasked = [
127+{
128+ "name": "nginx",
129+ "image": "nginx",
130+ "securityContext": {
131+ "procMount": "Unmasked"
132+ }
133+}]
134+
135+input_containers_many = [
136+{
137+ "name": "nginx",
138+ "image": "nginx",
139+ "securityContext": {
140+ "procMount": "Default"
141+ }
142+},
143+{
144+ "name": "nginx1",
145+ "image": "nginx"
146+},
147+{
148+ "name": "nginx2",
149+ "image": "nginx",
150+ "securityContext": {
151+ "runAsUser": "1000"
152+ }
153+}]
154+
155+input_containers_many_mixed = [
156+{
157+ "name": "nginx",
158+ "image": "nginx",
159+ "securityContext": {
160+ "procMount": "Default"
161+ }
162+},
163+{
164+ "name": "nginx1",
165+ "image": "nginx",
166+ "securityContext": {
167+ "procMount": "Unmasked"
168+ }
169+}]
170+
171+input_parameters_default = {
172+ "procMount": "Default"
173+}
174+
175+input_parameters_default_lower = {
176+ "procMount": "default"
177+}
178+
179+input_parameters_unmasked = {
180+ "procMount": "Unmasked"
181+}