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
a91e2dc4
Commit
a91e2dc4
authored
Dec 20, 2017
by
Slava Semushin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
security_context_test.go(TestVerifyRunAsNonRoot): add more test cases.
parent
51fbd6e6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
5 deletions
+36
-5
security_context_test.go
pkg/kubelet/kuberuntime/security_context_test.go
+36
-5
No files found.
pkg/kubelet/kuberuntime/security_context_test.go
View file @
a91e2dc4
...
...
@@ -45,16 +45,20 @@ func TestVerifyRunAsNonRoot(t *testing.T) {
}
rootUser
:=
int64
(
0
)
anyUser
:=
int64
(
1000
)
runAsNonRootTrue
:=
true
runAsNonRootFalse
:=
false
for
_
,
test
:=
range
[]
struct
{
desc
string
sc
*
v1
.
SecurityContext
fail
bool
desc
string
sc
*
v1
.
SecurityContext
uid
*
int64
username
string
fail
bool
}{
{
desc
:
"Pass if SecurityContext is not set"
,
sc
:
nil
,
uid
:
&
rootUser
,
fail
:
false
,
},
{
...
...
@@ -62,6 +66,7 @@ func TestVerifyRunAsNonRoot(t *testing.T) {
sc
:
&
v1
.
SecurityContext
{
RunAsUser
:
&
rootUser
,
},
uid
:
&
rootUser
,
fail
:
false
,
},
{
...
...
@@ -69,6 +74,7 @@ func TestVerifyRunAsNonRoot(t *testing.T) {
sc
:
&
v1
.
SecurityContext
{
RunAsNonRoot
:
&
runAsNonRootFalse
,
},
uid
:
&
rootUser
,
fail
:
false
,
},
{
...
...
@@ -77,6 +83,7 @@ func TestVerifyRunAsNonRoot(t *testing.T) {
RunAsNonRoot
:
&
runAsNonRootFalse
,
RunAsUser
:
&
rootUser
,
},
uid
:
&
rootUser
,
fail
:
false
,
},
{
...
...
@@ -85,6 +92,7 @@ func TestVerifyRunAsNonRoot(t *testing.T) {
RunAsNonRoot
:
&
runAsNonRootTrue
,
RunAsUser
:
&
rootUser
,
},
uid
:
&
rootUser
,
fail
:
true
,
},
{
...
...
@@ -92,12 +100,35 @@ func TestVerifyRunAsNonRoot(t *testing.T) {
sc
:
&
v1
.
SecurityContext
{
RunAsNonRoot
:
&
runAsNonRootTrue
,
},
uid
:
&
rootUser
,
fail
:
true
,
},
{
desc
:
"Fail if image's username is set and RunAsNonRoot is true"
,
sc
:
&
v1
.
SecurityContext
{
RunAsNonRoot
:
&
runAsNonRootTrue
,
},
username
:
"test"
,
fail
:
true
,
},
{
desc
:
"Pass if image's user is non-root and RunAsNonRoot is true"
,
sc
:
&
v1
.
SecurityContext
{
RunAsNonRoot
:
&
runAsNonRootTrue
,
},
uid
:
&
anyUser
,
fail
:
false
,
},
{
desc
:
"Pass if container's user and image's user aren't set and RunAsNonRoot is true"
,
sc
:
&
v1
.
SecurityContext
{
RunAsNonRoot
:
&
runAsNonRootTrue
,
},
fail
:
false
,
},
}
{
pod
.
Spec
.
Containers
[
0
]
.
SecurityContext
=
test
.
sc
uid
:=
int64
(
0
)
err
:=
verifyRunAsNonRoot
(
pod
,
&
pod
.
Spec
.
Containers
[
0
],
&
uid
,
""
)
err
:=
verifyRunAsNonRoot
(
pod
,
&
pod
.
Spec
.
Containers
[
0
],
test
.
uid
,
test
.
username
)
if
test
.
fail
{
assert
.
Error
(
t
,
err
,
test
.
desc
)
}
else
{
...
...
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