Skip to content

Commit

Permalink
added integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ved Ratan <[email protected]>
  • Loading branch information
VedRatan committed Feb 15, 2024
1 parent db4df3d commit 6e4681f
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/controller/tests/np-creation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Description

This test ensures the creation of nimbus-policy.

# Expected Behaviour

Upon creation of SecurityIntent and SecurityIntentBinding the NimbusPolicy should get created.
29 changes: 29 additions & 0 deletions internal/controller/tests/np-creation/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: np-creation
spec:
timeouts:
assert: 10s
steps:
- try:
# first operation: create the config map
- apply:
# file is relative to the test folder
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
# second operation: verify the config map exists and contains the expected data
- assert:
# file is relative to the test folder
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
- assert:
file: nimbus-policy.yaml
# - try:
# - script:
# content: kubectl get si
# check:
# (contains($stdout, 'dns-manipulation')): true
# - try:
# - script:
# content: kubectl get sib
# check:
# (contains($stdout, 'dns-manipulation-binding')): true
21 changes: 21 additions & 0 deletions internal/controller/tests/np-creation/nimbus-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: intent.security.nimbus.com/v1
kind: NimbusPolicy
metadata:
name: dns-manipulation-binding
ownerReferences:
- apiVersion: intent.security.nimbus.com/v1
blockOwnerDeletion: true
controller: true
kind: SecurityIntentBinding
name: dns-manipulation-binding
spec:
rules:
- description: An adversary can manipulate DNS requests to redirect network traffic
and potentially reveal end user activity.
id: dnsManipulation
rule:
action: Block
mode: best-effort
selector:
matchLabels:
app: nginx
7 changes: 7 additions & 0 deletions internal/controller/tests/np-updation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Description

This test ensures the persistant nature of nimbus-policy.

# Expected Behaviour

On updation of NimbusPolicy the policy by modifying the value of the key in .spec.selector.matchLablels.app the policy should get reverted back to its original state.
27 changes: 27 additions & 0 deletions internal/controller/tests/np-updation/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: np-updation
spec:
timeouts:
assert: 10s
steps:

- name: step-01
try:
- apply:
# file is relative to the test folder
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
- assert:
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
- name: step-02
try:
- apply:
file: updated-nimbus-policy.yaml
- name: step-03
try:
- script:
content: kubectl get np -n $NAMESPACE dns-manipulation-binding -o=jsonpath='{.spec.selector.matchLabels.app}'
check:
(contains($stdout, 'frontend')): false

22 changes: 22 additions & 0 deletions internal/controller/tests/np-updation/updated-nimbus-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: intent.security.nimbus.com/v1
kind: NimbusPolicy
metadata:
name: dns-manipulation-binding
ownerReferences:
- apiVersion: intent.security.nimbus.com/v1
blockOwnerDeletion: true
controller: true
kind: SecurityIntentBinding
name: dns-manipulation-binding
uid: "123456789"
spec:
rules:
- description: An adversary can manipulate DNS requests to redirect network traffic
and potentially reveal end user activity.
id: dnsManipulation
rule:
action: Block
mode: best-effort
selector:
matchLabels:
app: frontend
7 changes: 7 additions & 0 deletions internal/controller/tests/sib-deletion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Description

This test ensures that NimbusPolicy is tightly coupled with SecurityIntentBinding.

# Expected Behaviour

On deletion of SecurityIntentBinding, NimbusPolicy should automatically get deleted.
28 changes: 28 additions & 0 deletions internal/controller/tests/sib-deletion/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: sib-deletion
spec:
timeouts:
assert: 10s
steps:

- name: step-01
try:
- apply:
# file is relative to the test folder
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
- assert:
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
- name: step-02
try:
- script:
content: kubectl delete sib -n $NAMESPACE dns-manipulation-binding
- name: step-03
try:
- script:
content: kubectl get np -n $NAMESPACE dns-manipulation-binding
check:
($error != null): true


21 changes: 21 additions & 0 deletions internal/controller/tests/sib-deletion/nimbus-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: intent.security.nimbus.com/v1
kind: NimbusPolicy
metadata:
name: dns-manipulation-binding
ownerReferences:
- apiVersion: intent.security.nimbus.com/v1
blockOwnerDeletion: true
controller: true
kind: SecurityIntentBinding
name: dns-manipulation-binding
spec:
rules:
- description: An adversary can manipulate DNS requests to redirect network traffic
and potentially reveal end user activity.
id: dnsManipulation
rule:
action: Block
mode: best-effort
selector:
matchLabels:
app: nginx
14 changes: 14 additions & 0 deletions internal/controller/tests/sib-deletion/sib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: intent.security.nimbus.com/v1
kind: SecurityIntentBinding
metadata:
name: dns-manipulation-binding
spec:
intents:
- name: dns-manipulation
selector:
any:
- resources:
kind: Pod
namespace: default
matchLabels:
app: frontend
7 changes: 7 additions & 0 deletions internal/controller/tests/sib-updation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Description

This test ensures that the change in SecurityIntentBinding by should get reflected in NimbusPolicy.

# Expected Behaviour

On updation of SecurityIntentBinding by updating the selector value, the corresponding selector in the NimbusPolicy should get updated.
28 changes: 28 additions & 0 deletions internal/controller/tests/sib-updation/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: np-updation
spec:
timeouts:
assert: 10s
steps:

- name: step-01
try:
- apply:
# file is relative to the test folder
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
- assert:
file: ../../../../examples/namespaced/dns-manipulation-si-sib.yaml
- name: step-02
try:
- apply:
file: updated-sib.yaml
- name: step-03
try:
- script:
content: kubectl get np -n $NAMESPACE dns-manipulation-binding -o=jsonpath='{.spec.selector.matchLabels.app}'
check:
(contains($stdout, 'frontend')): true


21 changes: 21 additions & 0 deletions internal/controller/tests/sib-updation/nimbus-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: intent.security.nimbus.com/v1
kind: NimbusPolicy
metadata:
name: dns-manipulation-binding
ownerReferences:
- apiVersion: intent.security.nimbus.com/v1
blockOwnerDeletion: true
controller: true
kind: SecurityIntentBinding
name: dns-manipulation-binding
spec:
rules:
- description: An adversary can manipulate DNS requests to redirect network traffic
and potentially reveal end user activity.
id: dnsManipulation
rule:
action: Block
mode: best-effort
selector:
matchLabels:
app: nginx
14 changes: 14 additions & 0 deletions internal/controller/tests/sib-updation/updated-sib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: intent.security.nimbus.com/v1
kind: SecurityIntentBinding
metadata:
name: dns-manipulation-binding
spec:
intents:
- name: dns-manipulation
selector:
any:
- resources:
kind: Pod
namespace: default
matchLabels:
app: frontend

0 comments on commit 6e4681f

Please sign in to comment.