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
848ec049
Commit
848ec049
authored
Aug 10, 2015
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ABAC tests
parent
11fcd3bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
abac_test.go
pkg/auth/authorizer/abac/abac_test.go
+14
-14
No files found.
pkg/auth/authorizer/abac/abac_test.go
View file @
848ec049
...
@@ -33,15 +33,15 @@ func TestEmptyFile(t *testing.T) {
...
@@ -33,15 +33,15 @@ func TestEmptyFile(t *testing.T) {
}
}
func
TestOneLineFileNoNewLine
(
t
*
testing
.
T
)
{
func
TestOneLineFileNoNewLine
(
t
*
testing
.
T
)
{
_
,
err
:=
newWithContents
(
t
,
`{"user":"scheduler", "readonly": true, "
kind
": "pods", "namespace":"ns1"}`
)
_
,
err
:=
newWithContents
(
t
,
`{"user":"scheduler", "readonly": true, "
resource
": "pods", "namespace":"ns1"}`
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unable to read policy file: %v"
,
err
)
t
.
Errorf
(
"unable to read policy file: %v"
,
err
)
}
}
}
}
func
TestTwoLineFile
(
t
*
testing
.
T
)
{
func
TestTwoLineFile
(
t
*
testing
.
T
)
{
_
,
err
:=
newWithContents
(
t
,
`{"user":"scheduler", "readonly": true, "
kind
": "pods"}
_
,
err
:=
newWithContents
(
t
,
`{"user":"scheduler", "readonly": true, "
resource
": "pods"}
{"user":"scheduler", "readonly": true, "
kind
": "services"}
{"user":"scheduler", "readonly": true, "
resource
": "services"}
`
)
`
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unable to read policy file: %v"
,
err
)
t
.
Errorf
(
"unable to read policy file: %v"
,
err
)
...
@@ -56,14 +56,14 @@ func TestExampleFile(t *testing.T) {
...
@@ -56,14 +56,14 @@ func TestExampleFile(t *testing.T) {
}
}
}
}
func
NotTestAuthorize
(
t
*
testing
.
T
)
{
func
TestNotAuthorized
(
t
*
testing
.
T
)
{
a
,
err
:=
newWithContents
(
t
,
`{
"readonly": true, "kind": "events"
}
a
,
err
:=
newWithContents
(
t
,
`{
"readonly": true, "resource": "events"
}
{"user":"scheduler",
"readonly": true, "kind": "pods"
}
{"user":"scheduler",
"readonly": true, "resource": "pods"
}
{"user":"scheduler",
"kind": "bindings"
}
{"user":"scheduler",
"resource": "bindings"
}
{"user":"kubelet",
"readonly": true, "kind": "bindings"
}
{"user":"kubelet",
"readonly": true, "resource": "bindings"
}
{"user":"kubelet",
"kind": "events"
}
{"user":"kubelet",
"resource": "events"
}
{"user":"alice",
"ns
": "projectCaribou"}
{"user":"alice",
"namespace
": "projectCaribou"}
{"user":"bob",
"readonly": true, "ns
": "projectCaribou"}
{"user":"bob",
"readonly": true, "namespace
": "projectCaribou"}
`
)
`
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"unable to read policy file: %v"
,
err
)
t
.
Fatalf
(
"unable to read policy file: %v"
,
err
)
...
@@ -114,7 +114,7 @@ func NotTestAuthorize(t *testing.T) {
...
@@ -114,7 +114,7 @@ func NotTestAuthorize(t *testing.T) {
// /healthz, /version, etc.
// /healthz, /version, etc.
{
User
:
uChuck
,
RO
:
true
,
Resource
:
""
,
NS
:
""
,
ExpectAllow
:
false
},
{
User
:
uChuck
,
RO
:
true
,
Resource
:
""
,
NS
:
""
,
ExpectAllow
:
false
},
}
}
for
_
,
tc
:=
range
testCases
{
for
i
,
tc
:=
range
testCases
{
attr
:=
authorizer
.
AttributesRecord
{
attr
:=
authorizer
.
AttributesRecord
{
User
:
&
tc
.
User
,
User
:
&
tc
.
User
,
ReadOnly
:
tc
.
RO
,
ReadOnly
:
tc
.
RO
,
...
@@ -125,8 +125,8 @@ func NotTestAuthorize(t *testing.T) {
...
@@ -125,8 +125,8 @@ func NotTestAuthorize(t *testing.T) {
err
:=
a
.
Authorize
(
attr
)
err
:=
a
.
Authorize
(
attr
)
actualAllow
:=
bool
(
err
==
nil
)
actualAllow
:=
bool
(
err
==
nil
)
if
tc
.
ExpectAllow
!=
actualAllow
{
if
tc
.
ExpectAllow
!=
actualAllow
{
t
.
Errorf
(
"
Expected allowed=%v but actually allowed=%v, for case
%v"
,
t
.
Errorf
(
"
%d: Expected allowed=%v but actually allowed=%v
\n\t
%v"
,
tc
.
ExpectAllow
,
actualAllow
,
tc
)
i
,
tc
.
ExpectAllow
,
actualAllow
,
tc
)
}
}
}
}
}
}
...
...
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