validate nonResourceURL in create clusterrole

This commit is contained in:
xilabao
2017-06-07 14:04:17 +08:00
committed by Chen Rong
parent 2820b45caa
commit 42c41a07c8
2 changed files with 56 additions and 1 deletions

View File

@@ -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,
},