-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathe2e.bats
83 lines (59 loc) · 3.68 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
@test "Accept all capabilities when star in allowed capabilities" {
run kwctl run --request-path test_data/req_pod_with_allowed_capabilities_accept.json --settings-json '{"allowed_capabilities": ["*"]}' 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 ]
run kwctl run --request-path test_data/req_pod_with_allowed_capabilities_reject.json --settings-json '{"allowed_capabilities": ["*"]}' 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 "Reject when star in allowed capabilities and capabilities in required_drop_capabilities" {
run kwctl run --request-path test_data/req_pod_with_allowed_capabilities_reject.json --settings-json '{"allowed_capabilities": ["*"], "required_drop_capabilities": ["BPF"]}' annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*"message":"PSP capabilities policies doesn'\''t allow these capabilities to be added*') -ne 0 ]
}
@test "Reject capabilities in required_drop_capabilities" {
run kwctl run --request-path test_data/req_pod_with_capabilities_in_required_drop_capabilities.json --settings-json '{"required_drop_capabilities": ["NET_ADMIN"]}' annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*"message":"PSP capabilities policies doesn'\''t allow these capabilities to be added*') -ne 0 ]
}
@test "Accept capabilities in allowed capabilities" {
run kwctl run --request-path test_data/req_pod_with_allowed_capabilities_accept.json --settings-json '{"allowed_capabilities": ["CHOWN", "KILL"]}' 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 "Reject capabilities not in allowed capabilities" {
run kwctl run --request-path test_data/req_pod_with_allowed_capabilities_reject.json --settings-json '{"allowed_capabilities": ["CHOWN", "KILL"]}' annotated-policy.wasm
# this prints the output when one the checks below fails
echo "output = ${output}"
[ "$status" -eq 0 ]
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*"message":"PSP capabilities policies doesn'\''t allow these capabilities to be added*') -ne 0 ]
}
@test "Mutate pods" {
run kwctl run --request-path test_data/req_pod_with_mutate_capabilities.json --settings-json '{"allowed_capabilities": ["CHOWN", "KILL"], "required_drop_capabilities":["NET_ADMIN"], "default_add_capabilities":["CHOWN"]}' 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 ]
}
@test "Mutate deployments" {
run kwctl run --request-path test_data/req_pod_with_mutate_capabilities_for_deployment.json --settings-json '{"allowed_capabilities": ["CHOWN", "KILL"], "required_drop_capabilities":["NET_ADMIN"], "default_add_capabilities":["CHOWN"]}' 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 ]
}