Skip to content

Commit

Permalink
core: Adds ExactScopeStrategy (#260)
Browse files Browse the repository at this point in the history
The ExactScopeStrategy performs a simple string match (case sensitive)
of scopes.
  • Loading branch information
arekkas authored Apr 22, 2018
1 parent 018b5c1 commit 0fcdf33
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scope_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ func HierarchicScopeStrategy(haystack []string, needle string) bool {
return false
}

func ExactScopeStrategy(haystack []string, needle string) bool {
for _, this := range haystack {
if needle == this {
return true
}
}

return false
}

func WildcardScopeStrategy(matchers []string, needle string) bool {
needleParts := strings.Split(needle, ".")
for _, matcher := range matchers {
Expand Down
16 changes: 16 additions & 0 deletions scope_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,19 @@ func TestWildcardScopeStrategy(t *testing.T) {
assert.True(t, strategy(scopes, "offline"))
assert.True(t, strategy(scopes, "openid"))
}

func TestExactScopeStrategy2ScopeStrategy(t *testing.T) {
var strategy ScopeStrategy = ExactScopeStrategy

scopes := []string{"foo.bar.baz", "foo.bar"}
assert.True(t, strategy(scopes, "foo.bar.baz"))
assert.True(t, strategy(scopes, "foo.bar"))

assert.False(t, strategy(scopes, "foo.bar.baz.baz"))
assert.False(t, strategy(scopes, "foo.bar.bar"))

assert.False(t, strategy(scopes, "foo.bar.baz1"))
assert.False(t, strategy(scopes, "foo.bar1"))

assert.False(t, strategy([]string{}, "foo"))
}

0 comments on commit 0fcdf33

Please sign in to comment.