From 3eada575b37080f5d3995dd6b9a1ad44c95c5243 Mon Sep 17 00:00:00 2001 From: mourya007 Date: Wed, 20 Feb 2019 11:33:59 +0530 Subject: [PATCH] Adding Selinux test in validation --- pkg/apis/policy/validation/validation_test.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/apis/policy/validation/validation_test.go b/pkg/apis/policy/validation/validation_test.go index b36f03d01a..c17d24b5c1 100644 --- a/pkg/apis/policy/validation/validation_test.go +++ b/pkg/apis/policy/validation/validation_test.go @@ -906,3 +906,34 @@ func TestValidatePSPRunAsGroup(t *testing.T) { }) } } + +func TestValidatePSPSELinux(t *testing.T) { + var testCases = []struct { + name string + selinux policy.SELinuxStrategyOptions + fail bool + }{ + {"SELinuxStrategyMustRunAs", + policy.SELinuxStrategyOptions{ + Rule: policy.SELinuxStrategyMustRunAs, + SELinuxOptions: &api.SELinuxOptions{Level: "s9:z0,z1"}}, false}, + {"SELinuxStrategyMustRunAs", + policy.SELinuxStrategyOptions{ + Rule: policy.SELinuxStrategyMustRunAs, + SELinuxOptions: &api.SELinuxOptions{Level: "s0"}}, false}, + } + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + errList := validatePSPSELinux(field.NewPath("Status"), &testCase.selinux) + actualErrors := len(errList) + expectedErrors := 1 + if !testCase.fail { + expectedErrors = 0 + } + if actualErrors != expectedErrors { + t.Errorf("In testCase %v, expected %v errors, got %v errors", testCase.name, expectedErrors, actualErrors) + } + }) + } + +}