Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jaydip Gabani <[email protected]>
  • Loading branch information
JaydipGabani committed Apr 16, 2024
1 parent 3fe14b6 commit abdfc90
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/bats/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ teardown_file() {
kubectl delete --ignore-not-found -f ${BATS_TESTS_DIR}/good/good_ns.yaml
kubectl delete --ignore-not-found -f ${BATS_TESTS_DIR}/bad/bad_ns.yaml

wait_for_process ${WAIT_TIME} ${SLEEP_TIME} "kubectl delete --ignore-not-found -f ${BATS_TESTS_DIR}/constraints/all_ns_must_have_label_provided_vapbinding.yaml"

wait_for_process ${WAIT_TIME} ${SLEEP_TIME} "kubectl delete --ignore-not-found ValidatingAdmissionPolicyBinding gatekeeper-all-must-have-label"

wait_for_process ${WAIT_TIME} ${SLEEP_TIME} "kubectl apply -f ${BATS_TESTS_DIR}/constraints/all_ns_must_have_label_provided_vapbinding_scoped.yaml"

wait_for_process ${WAIT_TIME} ${SLEEP_TIME} "kubectl get ValidatingAdmissionPolicyBinding gatekeeper-all-must-have-label"

run kubectl apply -f ${BATS_TESTS_DIR}/bad/bad_ns.yaml
assert_match 'denied' "${output}"
assert_failure
kubectl apply -f ${BATS_TESTS_DIR}/good/good_ns.yaml
kubectl delete --ignore-not-found -f ${BATS_TESTS_DIR}/good/good_ns.yaml
kubectl delete --ignore-not-found -f ${BATS_TESTS_DIR}/bad/bad_ns.yaml

wait_for_process ${WAIT_TIME} ${SLEEP_TIME} "kubectl delete --ignore-not-found -f ${BATS_TESTS_DIR}/templates/k8srequiredlabels_template_vap.yaml"
fi
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabelsVap
metadata:
name: all-must-have-label
labels:
"gatekeeper.sh/use-vap": "yes"
spec:
enforcementAction: scoped
scopedEnforcementActions:
- action: deny
enforcementPoints:
- name: vap.k8s.io
match:
kinds:
- apiGroups: [""]
kinds: ["Namespace"]
parameters:
message: "All namespaces must have an `owner` label that points to your company username"
labels:
- key: owner
allowedRegex: "^[a-zA-Z]+.agilebank.demo$"
19 changes: 19 additions & 0 deletions test/gator/verify/constraint_with_scopedEA.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sFooIs
metadata:
name: foo-is-bar
spec:
enforcementAction: scoped
scopedEnforcementActions:
- action: deny
enforcementPoints:
- name: gator.gatekeeper.sh
- action: warn
enforcementPoints:
- name: validation.k8s.io
match:
kinds:
- apiGroups: [""]
kinds: ["FooIsBar"]
parameters:
foo: "bar"
12 changes: 12 additions & 0 deletions test/gator/verify/suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ tests:
object: deny.yaml
assertions:
- violations: yes
- name: foo-is-bar-with-scopedEA
template: template.yaml
constraint: constraint_with_scopedEA.yaml
cases:
- name: foo-bar
object: allow.yaml
assertions:
- violations: no
- name: foo-not-bar
object: deny.yaml
assertions:
- violations: yes

0 comments on commit abdfc90

Please sign in to comment.