# Tests for the policy itself. Run: conftest verify --policy policy package main import rego.v1 good := {"kind": "Deployment", "spec": {"template": {"spec": {"containers": [{ "name": "app", "image": "registry.example/app@sha256:0123", "securityContext": {"runAsNonRoot": true, "allowPrivilegeEscalation": false, "readOnlyRootFilesystem": true, "capabilities": {"drop": ["ALL"]}}, "resources": {"limits": {"cpu": "500m", "memory": "128Mi"}}, }]}}}} test_good_deployment_passes if { count(deny) == 0 with input as good } test_tag_instead_of_digest_is_denied if { bad := json.patch(good, [{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "app:latest"}]) count(deny) == 1 with input as bad } test_privileged_root_container_is_denied if { bad := json.patch(good, [{"op": "replace", "path": "/spec/template/spec/containers/0/securityContext", "value": {"privileged": true}}]) count(deny) == 5 with input as bad } test_missing_limits_are_denied if { bad := json.patch(good, [{"op": "remove", "path": "/spec/template/spec/containers/0/resources"}]) count(deny) == 2 with input as bad } test_other_kinds_are_ignored if { count(deny) == 0 with input as {"kind": "Service"} }