generated from kubewarden/go-policy-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
e2e.bats
81 lines (63 loc) · 2.41 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
#!/usr/bin/env bats
@test "reject because allowedTypes is empty" {
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": [] }'
# 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" : ".*No volume type is allowed.*") -ne 0 ]
}
@test "reject because types not present" {
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": ["foo", "hostPath"] }'
# 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" : ".*volume 'kube-api-access-kplj9' of type 'projected' is not in the AllowedTypes list.*") -ne 0 ]
}
@test "reject because mix of '*' and other types" {
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": ["projected", "hostPath", "*"] }'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request rejected by settings error
[ "$status" -eq 1 ]
[ $(expr "$output" : ".*Provided settings are not valid.*") -ne 0 ]
}
@test "accept all types" {
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": [ "*" ] }'
# 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 pods with no volumes" {
run kwctl run annotated-policy.wasm -r test_data/request-pod-no-volumes.json \
--settings-json \
'{ "allowedTypes": [ "foo" ] }'
# 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 pods with correct types" {
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": [ "hostPath", "projected", "foo" ] }'
# this prints the output when one the checks below fails
echo "output = ${output}"
# request accepted
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
}