Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit 560cfdf

Browse files
aneeshkpryandgoulding
authored andcommitted
Fixed check for null value for array type when key/value is not set
1 parent e1dee79 commit 560cfdf

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ run-generic-cnf-tests:
4949
cd ./test-network-function && ./test-network-function.test -ginkgo.focus="generic" ${COMMON_GINKGO_ARGS}
5050

5151
run-cnf-tests:
52-
cd ./test-network-function && ./test-network-function.test $COMMON_GINKGO_ARGS
52+
cd ./test-network-function && ./test-network-function.test ${COMMON_GINKGO_ARGS}
5353

5454
run-operator-tests:
55-
cd ./test-network-function/operator-test && ./operator-test.test $COMMON_GINKGO_ARGS
55+
cd ./test-network-function/operator-test && ./operator-test.test ${COMMON_GINKGO_ARGS}
5656

5757
run-container-tests:
58-
cd ./test-network-function/container-test && ./container-test.test $COMMON_GINKGO_ARGS
58+
cd ./test-network-function/container-test && ./container-test.test ${COMMON_GINKGO_ARGS}
5959

6060
deps-update:
6161
go mod tidy && \
@@ -80,7 +80,7 @@ clean:
8080
rm -f ./test-network-function/operator-test/operator-test.test
8181
rm -f ./test-network-function/operator-test/cnf-operator-certification-tests_junit.xml
8282
rm -f ./test-network-function/container-test/container-test.test
83-
rm -f ./test-network-function/container-test/cnf-container-certification-tests_junit.xml
83+
rm -f ./test-network-function/container-test/cnf-container-tests_junit.xml
8484

8585
dependencies:
8686
go get github.com/onsi/ginkgo/ginkgo

pkg/tnf/handlers/container/pod.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ func (p *Pod) ReelMatch(_ string, _ string, match string) *reel.Step {
6565
//for type: array ,should match for any expected status or fail on any expected status
6666
//based on the action type allow (default)|deny
6767
if p.ResultType == "array" {
68-
68+
re := regexp.MustCompile(testcases.GetOutRegExp("NULL")) //Not having capabilities is positive
69+
matched := re.MatchString(match)
70+
if matched {
71+
p.result = tnf.SUCCESS
72+
return nil
73+
}
6974
replacer := strings.NewReplacer(`[`, ``, "\"", ``, `]`, ``, `, `, `,`)
7075
match = replacer.Replace(match)
7176
matchSlice := strings.Split(match, ",")

pkg/tnf/handlers/container/pod_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ func TestPodTest_ReelMatchStringNoFound(t *testing.T) {
6464
assert.Equal(t, tnf.ERROR, c.Result())
6565
}
6666

67+
func TestPodTest_ReelMatchArray_Allow_Dendy_ISNULL(t *testing.T) {
68+
c := container.NewPod(command, name, namespace, sliceExpectedStatus, "array", actionAllow, testTimeoutDuration)
69+
step := c.ReelMatch("", "", `null`)
70+
assert.Nil(t, step)
71+
assert.Equal(t, tnf.SUCCESS, c.Result())
72+
}
73+
6774
func TestPodTest_ReelMatchArray_Allow_Match(t *testing.T) {
6875
c := container.NewPod(command, name, namespace, sliceExpectedStatus, "array", actionAllow, testTimeoutDuration)
6976
step := c.ReelMatch("", "", `["NET_ADMIN", "SYS_TIME"]`)

pkg/tnf/handlers/container/testcases/data/privilegedpod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var PrivilegedPodJSON = string(`{
6363
"name": "ROOT_CHECK",
6464
"skiptest": true,
6565
"command": "oc get pod %s -n %s -o json | jq -r '.spec.containers[0].securityContext.runAsUser'",
66-
"resultType": "string",
66+
"resulttype": "string",
6767
"action": "allow",
6868
"expectedstatus": [
6969
"NON_ROOT_USER"

test-network-function/container-test/container_cnf_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var _ = ginkgo.Describe("container_test", func() {
5757
gomega.Expect(context.GetExpecter()).ToNot(gomega.BeNil())
5858
})
5959
// add pdo is running check later
60-
ginkgo.When("When Pod is in running state", func() {
60+
ginkgo.When("pod is in running state", func() {
6161
for _, pod := range podsInTest.Pod {
6262
for _, testType := range pod.Tests {
6363
testFile := loadConfiguredTestFile(testType)
@@ -78,9 +78,9 @@ var _ = ginkgo.Describe("container_test", func() {
7878
})
7979

8080
func runTestsOnPod(name, namespace string, testCmd testcases.BaseTestCase) {
81-
ginkgo.When("Pod Test ", func() {
82-
ginkgo.It("Checks for "+testCmd.Name, func() {
83-
podInTest := container.NewPod(testCmd.Command, name, namespace, testCmd.ExptectedStatus, testCmd.Action, testCmd.ResultType, defaultTimeout)
81+
ginkgo.When("pod test ", func() {
82+
ginkgo.It("checks for "+testCmd.Name, func() {
83+
podInTest := container.NewPod(testCmd.Command, name, namespace, testCmd.ExptectedStatus, testCmd.ResultType, testCmd.Action, defaultTimeout)
8484
gomega.Expect(podInTest).ToNot(gomega.BeNil())
8585
test, err := tnf.NewTest(context.GetExpecter(), podInTest, []reel.Handler{podInTest}, context.GetErrorChannel())
8686
gomega.Expect(err).To(gomega.BeNil())

0 commit comments

Comments
 (0)