-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from auth0/explode-scopes-per-resource
Explode scopes per resource
- Loading branch information
Showing
2 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package auth | ||
|
||
import "testing" | ||
|
||
func TestRequiredScopes(t *testing.T) { | ||
t.Run("verify CRUD", func(t *testing.T) { | ||
crudResources := []string{ | ||
"actions", | ||
"clients", | ||
"connections", | ||
"hooks", | ||
"resource_servers", | ||
"rules", | ||
} | ||
crudPrefixes := []string{"create:", "delete:", "read:", "update:"} | ||
|
||
for _, resource := range crudResources { | ||
for _, prefix := range crudPrefixes { | ||
scope := prefix + resource | ||
|
||
if !strInArray(requiredScopes, scope) { | ||
t.Fatalf("wanted scope: %q, list: %+v", scope, requiredScopes) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
t.Run("verify special scopes", func(t *testing.T) { | ||
list := []string{ | ||
"read:client_keys", "read:logs", | ||
} | ||
|
||
for _, v := range list { | ||
if !strInArray(requiredScopes, v) { | ||
t.Fatalf("wanted scope: %q, list: %+v", v, requiredScopes) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func strInArray(haystack []string, needle string) bool { | ||
for _, v := range haystack { | ||
if v == needle { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |