2020-05-11 13:34:22 +03:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2020-05-19 20:17:17 +03:00
|
|
|
func TestHasScope(t *testing.T) {
|
2020-05-20 18:11:34 +03:00
|
|
|
if new(Account).HasScope("namespace", "foo") {
|
2020-05-19 20:17:17 +03:00
|
|
|
t.Errorf("Expected the blank account to not have a role")
|
|
|
|
}
|
|
|
|
|
|
|
|
acc := Account{Scopes: []string{"namespace.foo"}}
|
2020-05-20 18:11:34 +03:00
|
|
|
if !acc.HasScope("namespace", "foo") {
|
2020-05-19 20:17:17 +03:00
|
|
|
t.Errorf("Expected the account to have the namespace.foo role")
|
|
|
|
}
|
2020-05-20 18:11:34 +03:00
|
|
|
if acc.HasScope("namespace", "bar") {
|
2020-05-19 20:17:17 +03:00
|
|
|
t.Errorf("Expected the account to not have the namespace.bar role")
|
|
|
|
}
|
|
|
|
}
|
2020-05-11 13:34:22 +03:00
|
|
|
func TestHasRole(t *testing.T) {
|
|
|
|
if new(Account).HasRole("foo") {
|
|
|
|
t.Errorf("Expected the blank account to not have a role")
|
|
|
|
}
|
|
|
|
|
|
|
|
acc := Account{Roles: []string{"foo"}}
|
|
|
|
if !acc.HasRole("foo") {
|
|
|
|
t.Errorf("Expected the account to have the foo role")
|
|
|
|
}
|
|
|
|
if acc.HasRole("bar") {
|
|
|
|
t.Errorf("Expected the account to not have the bar role")
|
|
|
|
}
|
|
|
|
}
|