Fix nil account bug
This commit is contained in:
@@ -4,6 +4,7 @@ package auth
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -60,13 +61,13 @@ type Account struct {
|
||||
}
|
||||
|
||||
// HasScope returns a boolean indicating if the account has the given scope
|
||||
func (a *Account) HasScope(scope string) bool {
|
||||
func (a *Account) HasScope(scopes ...string) bool {
|
||||
if a.Scopes == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, s := range a.Scopes {
|
||||
if s == scope {
|
||||
if s == strings.Join(scopes, ".") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@@ -3,15 +3,15 @@ package auth
|
||||
import "testing"
|
||||
|
||||
func TestHasScope(t *testing.T) {
|
||||
if new(Account).HasScope("namespace.foo") {
|
||||
if new(Account).HasScope("namespace", "foo") {
|
||||
t.Errorf("Expected the blank account to not have a role")
|
||||
}
|
||||
|
||||
acc := Account{Scopes: []string{"namespace.foo"}}
|
||||
if !acc.HasScope("namespace.foo") {
|
||||
if !acc.HasScope("namespace", "foo") {
|
||||
t.Errorf("Expected the account to have the namespace.foo role")
|
||||
}
|
||||
if acc.HasScope("namespace.bar") {
|
||||
if acc.HasScope("namespace", "bar") {
|
||||
t.Errorf("Expected the account to not have the namespace.bar role")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user