mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Merge pull request #3033 from ywk253100/170811_scope
Fix bug in parsing scope
This commit is contained in:
commit
c878a4df06
@ -53,16 +53,21 @@ func GetResourceActions(scopes []string) []*token.ResourceActions {
|
||||
items := strings.Split(s, ":")
|
||||
length := len(items)
|
||||
|
||||
typee := items[0]
|
||||
|
||||
typee := ""
|
||||
name := ""
|
||||
if length > 1 {
|
||||
name = items[1]
|
||||
}
|
||||
|
||||
actions := []string{}
|
||||
if length > 2 {
|
||||
actions = strings.Split(items[2], ",")
|
||||
|
||||
if length == 1 {
|
||||
typee = items[0]
|
||||
} else if length == 2 {
|
||||
typee = items[0]
|
||||
name = items[1]
|
||||
} else {
|
||||
typee = items[0]
|
||||
name = strings.Join(items[1:length-1], ":")
|
||||
if len(items[length-1]) > 0 {
|
||||
actions = strings.Split(items[length-1], ",")
|
||||
}
|
||||
}
|
||||
|
||||
res = append(res, &token.ResourceActions{
|
||||
|
@ -55,22 +55,53 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestGetResourceActions(t *testing.T) {
|
||||
s := []string{"registry:catalog:*", "repository:10.117.4.142/notary-test/hello-world-2:pull,push"}
|
||||
expectedRA := [2]token.ResourceActions{
|
||||
token.ResourceActions{
|
||||
cases := map[string]*token.ResourceActions{
|
||||
"::": &token.ResourceActions{
|
||||
Type: "",
|
||||
Name: "",
|
||||
Actions: []string{},
|
||||
},
|
||||
"repository": &token.ResourceActions{
|
||||
Type: "repository",
|
||||
Name: "",
|
||||
Actions: []string{},
|
||||
},
|
||||
"repository:": &token.ResourceActions{
|
||||
Type: "repository",
|
||||
Name: "",
|
||||
Actions: []string{},
|
||||
},
|
||||
"repository:library/hello-world": &token.ResourceActions{
|
||||
Type: "repository",
|
||||
Name: "library/hello-world",
|
||||
Actions: []string{},
|
||||
},
|
||||
"repository:library/hello-world:": &token.ResourceActions{
|
||||
Type: "repository",
|
||||
Name: "library/hello-world",
|
||||
Actions: []string{},
|
||||
},
|
||||
"repository:library/hello-world:pull,push": &token.ResourceActions{
|
||||
Type: "repository",
|
||||
Name: "library/hello-world",
|
||||
Actions: []string{"pull", "push"},
|
||||
},
|
||||
"registry:catalog:*": &token.ResourceActions{
|
||||
Type: "registry",
|
||||
Name: "catalog",
|
||||
Actions: []string{"*"},
|
||||
},
|
||||
token.ResourceActions{
|
||||
"repository:192.168.0.1:443/library/hello-world:pull,push": &token.ResourceActions{
|
||||
Type: "repository",
|
||||
Name: "10.117.4.142/notary-test/hello-world-2",
|
||||
Name: "192.168.0.1:443/library/hello-world",
|
||||
Actions: []string{"pull", "push"},
|
||||
},
|
||||
}
|
||||
ra := GetResourceActions(s)
|
||||
assert.Equal(t, *ra[0], expectedRA[0], "The Resource Action mismatch")
|
||||
assert.Equal(t, *ra[1], expectedRA[1], "The Resource Action mismatch")
|
||||
|
||||
for k, v := range cases {
|
||||
r := GetResourceActions([]string{k})[0]
|
||||
assert.EqualValues(t, v, r)
|
||||
}
|
||||
}
|
||||
|
||||
func getKeyAndCertPath() (string, string) {
|
||||
|
Loading…
Reference in New Issue
Block a user