Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b1ae1d67
Commit
b1ae1d67
authored
Nov 24, 2017
by
Slava Semushin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admission_test.go(TestAdmitPreferNonmutating): simplify test by replacing…
admission_test.go(TestAdmitPreferNonmutating): simplify test by replacing shouldPassAdmit by a constant value.
parent
2b95212a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
26 deletions
+16
-26
admission_test.go
...kg/admission/security/podsecuritypolicy/admission_test.go
+16
-26
No files found.
plugin/pkg/admission/security/podsecuritypolicy/admission_test.go
View file @
b1ae1d67
...
...
@@ -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
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment