generated from kubewarden/go-policy-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathe2e.bats
86 lines (66 loc) · 3.23 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
#!/usr/bin/env bats
@test "Accept resource with labels already set" {
run kwctl run --allow-context-aware -r test_data/pod.json \
--replay-host-capabilities-interactions test_data/session_replay.yml \
--settings-path test_data/settings.json annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
[ $(expr "$output" : '.*"patchType":"JSONPatch".*') -eq 0 ]
}
@test "Mutate resource with no labels" {
run kwctl run --allow-context-aware -r test_data/pod_with_no_labels.json \
--replay-host-capabilities-interactions test_data/session_replay.yml \
--settings-path test_data/settings.json annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
[ $(expr "$output" : '.*"patchType":"JSONPatch".*') -ne 0 ]
# check if patch operation
patch=$(echo "${output}" | grep '{.*\"patch\".*}'| jq -r ".patch" | base64 --decode)
echo "patch=$patch"
echo ${patch} | jq -e "[.[].op == \"add\" and .[].value.cccenter? == \"zpto\"] | any"
}
@test "Mutate resource with wrong labels value" {
run kwctl run --allow-context-aware -r test_data/pod_with_wrong_label_value.json \
--replay-host-capabilities-interactions test_data/session_replay.yml \
--settings-path test_data/settings.json annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
[ $(expr "$output" : '.*"patchType":"JSONPatch".*') -ne 0 ]
# check if patch operation
patch=$(echo "${output}" | grep '{.*\"patch\".*}'| jq -r ".patch" | base64 --decode)
echo "patch=$patch"
echo ${patch} | jq -e "[.[].op == \"replace\" and .[].value == \"zpto\"] | any"
}
@test "Accept resource with labels already set when namespace misses the labels" {
run kwctl run --allow-context-aware -r test_data/pod.json \
--replay-host-capabilities-interactions test_data/session_replay_no_labels.yml \
--settings-path test_data/settings.json annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
}
@test "Accept resource with no labels when namespace misses the labels" {
run kwctl run --allow-context-aware -r test_data/pod_with_no_labels.json \
--replay-host-capabilities-interactions test_data/session_replay_no_labels.yml \
--settings-path test_data/settings.json annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
}
@test "Accept resource with wrong labels value when namespace misses the labels" {
run kwctl run --allow-context-aware -r test_data/pod_with_wrong_label_value.json \
--replay-host-capabilities-interactions test_data/session_replay_no_labels.yml \
--settings-path test_data/settings.json annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*allowed.*true') -ne 0 ]
}