Auth scope tests
This commit is contained in:
parent
95cbac71ed
commit
e9dafa7ab9
3 changed files with 21 additions and 8 deletions
|
@ -61,10 +61,10 @@ func (a *Auth) NewToken(userId UserId, deviceId DeviceId, scope AuthScope) (*Aut
|
|||
|
||||
// NOTE - not stubbing methods of structs like this. more convoluted than it's worth right now
|
||||
func (at *AuthToken) ScopeValid(required AuthScope) bool {
|
||||
// So far the only scope issued. Used to have more, didn't want to delete
|
||||
// this feature yet in case we add more again. We'll delete it if it's of
|
||||
// no use and ends up complicating anything.
|
||||
return at.Scope == ScopeFull
|
||||
// So far * is the only scope issued. Used to have more, didn't want to
|
||||
// delete this feature yet in case we add more again. We'll delete it if it's
|
||||
// of no use and ends up complicating anything.
|
||||
return at.Scope == ScopeFull || at.Scope == required
|
||||
}
|
||||
|
||||
func (p Password) Obfuscate() string {
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
// Test stubs for now
|
||||
|
||||
|
||||
func TestAuthNewTokenSuccess(t *testing.T) {
|
||||
t.Fatalf("Test me: New token passes. Different scopes etc.")
|
||||
}
|
||||
|
@ -16,9 +15,24 @@ func TestAuthNewTokenFail(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAuthScopeValid(t *testing.T) {
|
||||
t.Fatalf("Test me: Scope Valid tests")
|
||||
fullAuthToken := AuthToken{Scope: "*"}
|
||||
if !fullAuthToken.ScopeValid("*") {
|
||||
t.Fatalf("Expected * to be a valid scope for *")
|
||||
}
|
||||
if !fullAuthToken.ScopeValid("banana") {
|
||||
t.Fatalf("Expected * to be a valid scope for banana")
|
||||
}
|
||||
|
||||
bananaAuthToken := AuthToken{Scope: "banana"}
|
||||
if !bananaAuthToken.ScopeValid("banana") {
|
||||
t.Fatalf("Expected banana to be a valid scope for banana")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthScopeInvalid(t *testing.T) {
|
||||
t.Fatalf("Test me: Scope Invalid tests")
|
||||
bananaAuthToken := AuthToken{Scope: "banana"}
|
||||
|
||||
if bananaAuthToken.ScopeValid("*") {
|
||||
t.Fatalf("Expected banana to be an invalid scope for *")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,4 +156,3 @@ func TestServerAuthHandlerErrors(t *testing.T) {
|
|||
func TestServerValidateAuthRequest(t *testing.T) {
|
||||
t.Fatalf("Test me: Implement and test AuthRequest.validate()")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue