RBAC: use scope reduction for user permission listing (#61583)

use scope reduction for user permission listing
This commit is contained in:
Ieva
2023-01-17 09:58:40 +00:00
committed by GitHub
parent b5383b7d05
commit f44bc0dd6b
2 changed files with 23 additions and 2 deletions
@@ -42,6 +42,17 @@ func TestReduce(t *testing.T) {
"teams:write": {"teams:id:1"},
},
},
{
name: "specific permissions with repeated scope",
ps: []Permission{
{Action: "teams:read", Scope: "teams:id:1"},
{Action: "teams:read", Scope: "teams:id:2"},
{Action: "teams:read", Scope: "teams:id:1"},
},
want: map[string][]string{
"teams:read": {"teams:id:1", "teams:id:2"},
},
},
{
name: "wildcard permission",
ps: []Permission{
@@ -88,6 +99,16 @@ func TestReduce(t *testing.T) {
"dashboards:read": {"*"},
},
},
{
name: "non-wilcard scopes with * in them",
ps: []Permission{
{Action: "dashboards:read", Scope: "dashboards:uid:123"},
{Action: "dashboards:read", Scope: "dashboards:uid:1*"},
},
want: map[string][]string{
"dashboards:read": {"dashboards:uid:123", "dashboards:uid:1*"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {