Validate PSP allowedProcMountTypes

This commit is contained in:
Jordan Liggitt
2018-12-29 00:18:01 -05:00
parent 7c112762b0
commit cb76da9fd7
3 changed files with 34 additions and 8 deletions

View File

@@ -384,6 +384,9 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
nonEmptyFlexVolumes := validPSP()
nonEmptyFlexVolumes.Spec.AllowedFlexVolumes = []policy.AllowedFlexVolume{{Driver: "example/driver"}}
invalidProcMount := validPSP()
invalidProcMount.Spec.AllowedProcMountTypes = []api.ProcMountType{api.ProcMountType("bogus")}
type testCase struct {
psp *policy.PodSecurityPolicy
errorType field.ErrorType
@@ -550,6 +553,11 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
errorType: field.ErrorTypeRequired,
errorDetail: "must specify a driver",
},
"invalid allowedProcMountTypes": {
psp: invalidProcMount,
errorType: field.ErrorTypeNotSupported,
errorDetail: `supported values: "Default", "Unmasked"`,
},
}
for k, v := range errorCases {
@@ -643,6 +651,10 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
flexvolumeWhenAllVolumesAllowed.Spec.AllowedFlexVolumes = []policy.AllowedFlexVolume{
{Driver: "example/driver2"},
}
validProcMount := validPSP()
validProcMount.Spec.AllowedProcMountTypes = []api.ProcMountType{api.DefaultProcMount, api.UnmaskedProcMount}
successCases := map[string]struct {
psp *policy.PodSecurityPolicy
}{
@@ -682,6 +694,9 @@ func TestValidatePodSecurityPolicy(t *testing.T) {
"allow white-listed flexVolume when all volumes are allowed": {
psp: flexvolumeWhenAllVolumesAllowed,
},
"valid allowedProcMountTypes": {
psp: validProcMount,
},
}
for k, v := range successCases {