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
42c41a07
Commit
42c41a07
authored
Jun 07, 2017
by
xilabao
Committed by
Chen Rong
Aug 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validate nonResourceURL in create clusterrole
parent
2820b45c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
create_clusterrole.go
pkg/kubectl/cmd/create_clusterrole.go
+15
-0
create_clusterrole_test.go
pkg/kubectl/cmd/create_clusterrole_test.go
+41
-1
No files found.
pkg/kubectl/cmd/create_clusterrole.go
View file @
42c41a07
...
...
@@ -19,6 +19,7 @@ package cmd
import
(
"fmt"
"io"
"strings"
"github.com/spf13/cobra"
...
...
@@ -133,6 +134,20 @@ func (c *CreateClusterRoleOptions) Validate() error {
return
fmt
.
Errorf
(
"invalid verb: '%s' for nonResourceURL"
,
v
)
}
}
for
_
,
nonResourceURL
:=
range
c
.
NonResourceURLs
{
if
nonResourceURL
==
"*"
{
continue
}
if
nonResourceURL
==
""
||
!
strings
.
HasPrefix
(
nonResourceURL
,
"/"
)
{
return
fmt
.
Errorf
(
"nonResourceURL should start with /"
)
}
if
strings
.
ContainsRune
(
nonResourceURL
[
:
len
(
nonResourceURL
)
-
1
],
'*'
)
{
return
fmt
.
Errorf
(
"nonResourceURL only supports wildcard matches when '*' is at the end"
)
}
}
}
return
nil
...
...
pkg/kubectl/cmd/create_clusterrole_test.go
View file @
42c41a07
...
...
@@ -375,6 +375,46 @@ func TestClusterRoleValidate(t *testing.T) {
},
expectErr
:
false
,
},
"test-invalid-empty-non-resource-url"
:
{
clusterRoleOptions
:
&
CreateClusterRoleOptions
{
CreateRoleOptions
:
&
CreateRoleOptions
{
Name
:
"my-clusterrole"
,
Verbs
:
[]
string
{
"create"
},
},
NonResourceURLs
:
[]
string
{
""
},
},
expectErr
:
true
,
},
"test-invalid-non-resource-url"
:
{
clusterRoleOptions
:
&
CreateClusterRoleOptions
{
CreateRoleOptions
:
&
CreateRoleOptions
{
Name
:
"my-clusterrole"
,
Verbs
:
[]
string
{
"create"
},
},
NonResourceURLs
:
[]
string
{
"logs"
},
},
expectErr
:
true
,
},
"test-invalid-non-resource-url-with-*"
:
{
clusterRoleOptions
:
&
CreateClusterRoleOptions
{
CreateRoleOptions
:
&
CreateRoleOptions
{
Name
:
"my-clusterrole"
,
Verbs
:
[]
string
{
"create"
},
},
NonResourceURLs
:
[]
string
{
"/logs/*/"
},
},
expectErr
:
true
,
},
"test-invalid-non-resource-url-with-multiple-*"
:
{
clusterRoleOptions
:
&
CreateClusterRoleOptions
{
CreateRoleOptions
:
&
CreateRoleOptions
{
Name
:
"my-clusterrole"
,
Verbs
:
[]
string
{
"create"
},
},
NonResourceURLs
:
[]
string
{
"/logs*/*"
},
},
expectErr
:
true
,
},
"test-invalid-verb-for-non-resource-url"
:
{
clusterRoleOptions
:
&
CreateClusterRoleOptions
{
CreateRoleOptions
:
&
CreateRoleOptions
{
...
...
@@ -397,7 +437,7 @@ func TestClusterRoleValidate(t *testing.T) {
},
},
},
NonResourceURLs
:
[]
string
{
"/logs/"
},
NonResourceURLs
:
[]
string
{
"/logs/"
,
"/logs/*"
},
},
expectErr
:
false
,
},
...
...
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