generated from kubewarden/go-policy-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
e2e.bats
115 lines (90 loc) · 3.94 KB
/
e2e.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bats
@test "accept when no settings are provided" {
run kwctl run annotated-policy.wasm -r test_data/ingress.json
# this prints the output when one the checks below fails
echo "output = ${output}"
# request accepted
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
}
@test "accept user defined constraint is respected" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json \
--settings-json '{"constrained_labels": {"owner": "^team-"}}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request accepted
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
}
@test "accept labels are not on deny list" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json \
--settings-json '{"denied_labels": ["foo", "bar"]}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request accepted
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
}
@test "reject because label is on deny list" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json --settings-json '{"denied_labels": ["foo", "owner"]}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request rejected
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*false') -ne 0 ]
[ $(expr "$output" : '.*The following labels are denied: owner".*') -ne 0 ]
}
@test "reject because label doesn't pass validation constraint" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json \
--settings-json '{"constrained_labels": {"cc-center": "^cc-\\d+$"}}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request rejected
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*false') -ne 0 ]
[ $(expr "$output" : ".*The following labels are violating user constraints: cc-center.*") -ne 0 ]
}
@test "reject because a required label does not exist" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json --settings-json '{"mandatory_labels": ["required"], "constrained_labels": {"foo": ".*"}}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request rejected
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*false') -ne 0 ]
[ $(expr "$output" : '.*The following mandatory labels are missing: required.*') -ne 0 ]
}
@test "fail settings validation because constrained labels are also denied" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json \
--settings-json '{"denied_labels": ["foo", "cc-center"], "constrained_labels": {"cc-center": "^cc-\\d+$"}}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# settings validation fails
[ "$status" -eq 1 ]
[ $(expr "$output" : ".*Provided settings are not valid: These labels cannot be constrained and denied at the same time: cc-center.*") -ne 0 ]
}
@test "fail settings validation because mandatory labels are also denied" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json \
--settings-json '{"denied_labels": ["foo", "cc-center"], "mandatory_labels": ["cc-center"]}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# settings validation fails
[ "$status" -eq 1 ]
[ $(expr "$output" : ".*Provided settings are not valid: These labels cannot be mandatory and denied at the same time: cc-center.*") -ne 0 ]
}
@test "fail settings validation because of invalid constraint" {
run kwctl run annotated-policy.wasm \
-r test_data/ingress.json \
--settings-json '{"constrained_labels": {"cc-center": "^cc-[12$"}}'
# this prints the output when one the checks below fails
echo "output = ${output}"
# settings validation fails
[ "$status" -eq 1 ]
[ $(expr "$output" : ".*Provided settings are not valid: error parsing regexp: missing closing ]: `[12$`.*") -ne 0 ]
}