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
62c170fc
Commit
62c170fc
authored
Nov 10, 2017
by
hzxuzhonghu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
verify token file
parent
9c904d6b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
1 deletion
+17
-1
tokenfile.go
...apiserver/pkg/authentication/token/tokenfile/tokenfile.go
+7
-1
tokenfile_test.go
...rver/pkg/authentication/token/tokenfile/tokenfile_test.go
+10
-0
No files found.
staging/src/k8s.io/apiserver/pkg/authentication/token/tokenfile/tokenfile.go
View file @
62c170fc
...
@@ -62,11 +62,17 @@ func NewCSV(path string) (*TokenAuthenticator, error) {
...
@@ -62,11 +62,17 @@ func NewCSV(path string) (*TokenAuthenticator, error) {
if
len
(
record
)
<
3
{
if
len
(
record
)
<
3
{
return
nil
,
fmt
.
Errorf
(
"token file '%s' must have at least 3 columns (token, user name, user uid), found %d"
,
path
,
len
(
record
))
return
nil
,
fmt
.
Errorf
(
"token file '%s' must have at least 3 columns (token, user name, user uid), found %d"
,
path
,
len
(
record
))
}
}
recordNum
++
if
record
[
0
]
==
""
{
glog
.
Warningf
(
"empty token has been found in token file '%s', record number '%d'"
,
path
,
recordNum
)
continue
}
obj
:=
&
user
.
DefaultInfo
{
obj
:=
&
user
.
DefaultInfo
{
Name
:
record
[
1
],
Name
:
record
[
1
],
UID
:
record
[
2
],
UID
:
record
[
2
],
}
}
recordNum
++
if
_
,
exist
:=
tokens
[
record
[
0
]];
exist
{
if
_
,
exist
:=
tokens
[
record
[
0
]];
exist
{
glog
.
Warningf
(
"duplicate token has been found in token file '%s', record number '%d'"
,
path
,
recordNum
)
glog
.
Warningf
(
"duplicate token has been found in token file '%s', record number '%d'"
,
path
,
recordNum
)
}
}
...
...
staging/src/k8s.io/apiserver/pkg/authentication/token/tokenfile/tokenfile_test.go
View file @
62c170fc
...
@@ -125,6 +125,16 @@ func TestInsufficientColumnsTokenFile(t *testing.T) {
...
@@ -125,6 +125,16 @@ func TestInsufficientColumnsTokenFile(t *testing.T) {
}
}
}
}
func
TestEmptyTokenTokenFile
(
t
*
testing
.
T
)
{
auth
,
err
:=
newWithContents
(
t
,
",user5,uid5
\n
"
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error %v"
,
err
)
}
if
len
(
auth
.
tokens
)
!=
0
{
t
.
Fatalf
(
"empty token should not be recorded"
)
}
}
func
newWithContents
(
t
*
testing
.
T
,
contents
string
)
(
auth
*
TokenAuthenticator
,
err
error
)
{
func
newWithContents
(
t
*
testing
.
T
,
contents
string
)
(
auth
*
TokenAuthenticator
,
err
error
)
{
f
,
err
:=
ioutil
.
TempFile
(
""
,
"tokenfile_test"
)
f
,
err
:=
ioutil
.
TempFile
(
""
,
"tokenfile_test"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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