Skip to content

Commit

Permalink
test: add missing fields to e2e fixtures
Browse files Browse the repository at this point in the history
Signed-off-by: Flavio Castelli <[email protected]>
  • Loading branch information
flavio committed Nov 15, 2023
1 parent 2a8ea21 commit c70d834
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 218 deletions.
44 changes: 36 additions & 8 deletions e2e.bats
Original file line number Diff line number Diff line change
@@ -1,55 +1,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 ]
echo "$output"
[ $(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
echo "$output"

# 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 ]
echo "$output"
[ $(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 ]
echo "$output"
[ $(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 ]
echo "$output"
[ $(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 ]
echo "$output"
[ $(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
echo "$output"

# 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
echo "$output"

# 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 ]
}
78 changes: 42 additions & 36 deletions test_data/req_pod_with_allowed_capabilities_accept.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
{
"uid": "f0b8fba3-4f4f-465b-af8c-84d0326a2dc2",
"kind": {
"kind": "Pod",
"version": "v1"
"group": "",
"kind": "Pod",
"version": "v1"
},
"resource": {
"group": "",
"version": "v1",
"resource": "pods"
},
"object": {
"metadata": {
"name": "hello"
},
"spec": {
"containers": [
{
"command": [
"sh",
"-c",
"echo 'Hello!' && sleep 1h"
],
"image": "busybox",
"imagePullPolicy": "Always",
"name": "hello",
"resources": {},
"securityContext": {
"capabilities": {
"add": [
"CHOWN"
]
}
}

}
]
}
"metadata": {
"name": "hello"
},
"spec": {
"containers": [
{
"command": [
"sh",
"-c",
"echo 'Hello!' && sleep 1h"
],
"image": "busybox",
"imagePullPolicy": "Always",
"name": "hello",
"resources": {},
"securityContext": {
"capabilities": {
"add": [
"CHOWN"
]
}
}
}
]
}
},
"operation": "CREATE",
"requestKind": {
"kind": "Pod",
"version": "v1"
"group": "",
"kind": "Pod",
"version": "v1"
},
"userInfo": {
"groups": [
"system:masters",
"system:authenticated"
],
"username": "shiva"
"groups": [
"system:masters",
"system:authenticated"
],
"username": "shiva"
}
}
}
92 changes: 49 additions & 43 deletions test_data/req_pod_with_allowed_capabilities_reject.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
{
"uid": "f0b8fba3-4f4f-465b-af8c-84d0326a2dc2",
"kind": {
"kind": "Pod",
"version": "v1"
"uid": "f0b8fba3-4f4f-465b-af8c-84d0326a2dc2",
"kind": {
"group": "",
"kind": "Pod",
"version": "v1"
},
"resource": {
"group": "",
"version": "v1",
"resource": "pods"
},
"object": {
"metadata": {
"name": "hello"
},
"object": {
"metadata": {
"name": "hello"
},
"spec": {
"containers": [
{
"command": [
"sh",
"-c",
"echo 'Hello!' && sleep 1h"
],
"image": "busybox",
"imagePullPolicy": "Always",
"name": "hello",
"resources": {},
"securityContext": {
"capabilities": {
"add": [
"BPF"
]
}
}

}
]
"spec": {
"containers": [
{
"command": [
"sh",
"-c",
"echo 'Hello!' && sleep 1h"
],
"image": "busybox",
"imagePullPolicy": "Always",
"name": "hello",
"resources": {},
"securityContext": {
"capabilities": {
"add": [
"BPF"
]
}
}
}
},
"operation": "CREATE",
"requestKind": {
"kind": "Pod",
"version": "v1"
},
"userInfo": {
"groups": [
"system:masters",
"system:authenticated"
],
"username": "shiva"
]
}
}
},
"operation": "CREATE",
"requestKind": {
"group": "",
"kind": "Pod",
"version": "v1"
},
"userInfo": {
"groups": [
"system:masters",
"system:authenticated"
],
"username": "shiva"
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
{
"uid": "f0b8fba3-4f4f-465b-af8c-84d0326a2dc2",
"kind": {
"kind": "Pod",
"version": "v1"
"uid": "f0b8fba3-4f4f-465b-af8c-84d0326a2dc2",
"kind": {
"group": "",
"kind": "Pod",
"version": "v1"
},
"resource": {
"group": "",
"version": "v1",
"resource": "pods"
},
"object": {
"metadata": {
"name": "hello"
},
"object": {
"metadata": {
"name": "hello"
},
"spec": {
"containers": [
{
"command": [
"sh",
"-c",
"echo 'Hello!' && sleep 1h"
],
"image": "busybox",
"imagePullPolicy": "Always",
"name": "hello",
"resources": {},
"securityContext": {
"capabilities": {
"add": [
"NET_ADMIN"
]
}
}

}
]
"spec": {
"containers": [
{
"command": [
"sh",
"-c",
"echo 'Hello!' && sleep 1h"
],
"image": "busybox",
"imagePullPolicy": "Always",
"name": "hello",
"resources": {},
"securityContext": {
"capabilities": {
"add": [
"NET_ADMIN"
]
}
}
}
},
"operation": "CREATE",
"requestKind": {
"kind": "Pod",
"version": "v1"
},
"userInfo": {
"groups": [
"system:masters",
"system:authenticated"
],
"username": "shiva"
]
}
}
},
"operation": "CREATE",
"requestKind": {
"group": "",
"kind": "Pod",
"version": "v1"
},
"userInfo": {
"groups": [
"system:masters",
"system:authenticated"
],
"username": "shiva"
}
}
Loading

0 comments on commit c70d834

Please sign in to comment.