mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
admission_test.go(TestAdmitPreferNonmutating): simplify test by replacing shouldPassAdmit by a constant value.
This commit is contained in:
parent
2b95212ad3
commit
b1ae1d67b2
@ -349,7 +349,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
pod *kapi.Pod
|
||||
podBeforeUpdate *kapi.Pod
|
||||
psps []*extensions.PodSecurityPolicy
|
||||
shouldPassAdmit bool
|
||||
shouldPassValidate bool
|
||||
expectMutation bool
|
||||
expectedContainerUser *int64
|
||||
@ -359,7 +358,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
operation: kadmission.Create,
|
||||
pod: unprivilegedRunAsAnyPod.DeepCopy(),
|
||||
psps: []*extensions.PodSecurityPolicy{privilegedPSP},
|
||||
shouldPassAdmit: true,
|
||||
shouldPassValidate: true,
|
||||
expectMutation: false,
|
||||
expectedContainerUser: nil,
|
||||
@ -369,7 +367,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
operation: kadmission.Create,
|
||||
pod: unprivilegedRunAsAnyPod.DeepCopy(),
|
||||
psps: []*extensions.PodSecurityPolicy{mutating2, mutating1, privilegedPSP},
|
||||
shouldPassAdmit: true,
|
||||
shouldPassValidate: true,
|
||||
expectMutation: false,
|
||||
expectedContainerUser: nil,
|
||||
@ -379,7 +376,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
operation: kadmission.Create,
|
||||
pod: unprivilegedRunAsAnyPod.DeepCopy(),
|
||||
psps: []*extensions.PodSecurityPolicy{mutating2, mutating1},
|
||||
shouldPassAdmit: true,
|
||||
shouldPassValidate: true,
|
||||
expectMutation: true,
|
||||
expectedContainerUser: &mutating1.Spec.RunAsUser.Ranges[0].Min,
|
||||
@ -390,7 +386,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
pod: changedPodWithSC.DeepCopy(),
|
||||
podBeforeUpdate: podWithSC.DeepCopy(),
|
||||
psps: []*extensions.PodSecurityPolicy{mutating2, mutating1, privilegedPSP},
|
||||
shouldPassAdmit: true,
|
||||
shouldPassValidate: true,
|
||||
expectMutation: false,
|
||||
expectedContainerUser: nil,
|
||||
@ -401,7 +396,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
pod: changedPod.DeepCopy(),
|
||||
podBeforeUpdate: unprivilegedRunAsAnyPod.DeepCopy(),
|
||||
psps: []*extensions.PodSecurityPolicy{mutating2, mutating1},
|
||||
shouldPassAdmit: true,
|
||||
shouldPassValidate: false,
|
||||
expectMutation: false,
|
||||
expectedContainerUser: nil,
|
||||
@ -412,7 +406,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
pod: unprivilegedRunAsAnyPod.DeepCopy(),
|
||||
podBeforeUpdate: unprivilegedRunAsAnyPod.DeepCopy(),
|
||||
psps: []*extensions.PodSecurityPolicy{mutating2, mutating1},
|
||||
shouldPassAdmit: true,
|
||||
shouldPassValidate: true,
|
||||
expectMutation: false,
|
||||
expectedContainerUser: nil,
|
||||
@ -423,7 +416,6 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
pod: gcChangedPod.DeepCopy(),
|
||||
podBeforeUpdate: unprivilegedRunAsAnyPod.DeepCopy(),
|
||||
psps: []*extensions.PodSecurityPolicy{mutating2, mutating1},
|
||||
shouldPassAdmit: true,
|
||||
shouldPassValidate: true,
|
||||
expectMutation: false,
|
||||
expectedContainerUser: nil,
|
||||
@ -432,26 +424,24 @@ func TestAdmitPreferNonmutating(t *testing.T) {
|
||||
}
|
||||
|
||||
for k, v := range tests {
|
||||
testPSPAdmitAdvanced(k, v.operation, v.psps, nil, &user.DefaultInfo{}, v.pod, v.podBeforeUpdate, v.shouldPassAdmit, v.shouldPassValidate, v.expectMutation, v.expectedPSP, t)
|
||||
testPSPAdmitAdvanced(k, v.operation, v.psps, nil, &user.DefaultInfo{}, v.pod, v.podBeforeUpdate, true, v.shouldPassValidate, v.expectMutation, v.expectedPSP, t)
|
||||
|
||||
if v.shouldPassAdmit {
|
||||
actualPodUser := (*int64)(nil)
|
||||
if v.pod.Spec.SecurityContext != nil {
|
||||
actualPodUser = v.pod.Spec.SecurityContext.RunAsUser
|
||||
}
|
||||
if actualPodUser != nil {
|
||||
t.Errorf("%s expected pod user nil, got %v", k, *actualPodUser)
|
||||
}
|
||||
actualPodUser := (*int64)(nil)
|
||||
if v.pod.Spec.SecurityContext != nil {
|
||||
actualPodUser = v.pod.Spec.SecurityContext.RunAsUser
|
||||
}
|
||||
if actualPodUser != nil {
|
||||
t.Errorf("%s expected pod user nil, got %v", k, *actualPodUser)
|
||||
}
|
||||
|
||||
actualContainerUser := (*int64)(nil)
|
||||
if v.pod.Spec.Containers[0].SecurityContext != nil {
|
||||
actualContainerUser = v.pod.Spec.Containers[0].SecurityContext.RunAsUser
|
||||
}
|
||||
if (actualContainerUser == nil) != (v.expectedContainerUser == nil) {
|
||||
t.Errorf("%s expected container user %v, got %v", k, v.expectedContainerUser, actualContainerUser)
|
||||
} else if actualContainerUser != nil && *actualContainerUser != *v.expectedContainerUser {
|
||||
t.Errorf("%s expected container user %v, got %v", k, *v.expectedContainerUser, *actualContainerUser)
|
||||
}
|
||||
actualContainerUser := (*int64)(nil)
|
||||
if v.pod.Spec.Containers[0].SecurityContext != nil {
|
||||
actualContainerUser = v.pod.Spec.Containers[0].SecurityContext.RunAsUser
|
||||
}
|
||||
if (actualContainerUser == nil) != (v.expectedContainerUser == nil) {
|
||||
t.Errorf("%s expected container user %v, got %v", k, v.expectedContainerUser, actualContainerUser)
|
||||
} else if actualContainerUser != nil && *actualContainerUser != *v.expectedContainerUser {
|
||||
t.Errorf("%s expected container user %v, got %v", k, *v.expectedContainerUser, *actualContainerUser)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user