rbac authorizer: support non-resource urls with stars ("/apis/*")

This commit is contained in:
Eric Chiang
2016-06-30 13:34:22 -07:00
parent 411922f66c
commit addc4b166c
4 changed files with 99 additions and 6 deletions

View File

@@ -219,3 +219,28 @@ func TestValidateRole(t *testing.T) {
}
}
}
func TestNonResourceURLCovers(t *testing.T) {
tests := []struct {
owner string
requested string
want bool
}{
{"*", "/api", true},
{"/api", "/api", true},
{"/apis", "/api", false},
{"/api/v1", "/api", false},
{"/api/v1", "/api/v1", true},
{"/api/*", "/api/v1", true},
{"/api/*", "/api", false},
{"/api/*/*", "/api/v1", false},
{"/*/v1/*", "/api/v1", false},
}
for _, tc := range tests {
got := nonResourceURLCovers(tc.owner, tc.requested)
if got != tc.want {
t.Errorf("nonResourceURLCovers(%q, %q): want=(%t), got=(%t)", tc.owner, tc.requested, tc.want, got)
}
}
}