wallet-sync-server/auth/auth_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

package auth
import (
"testing"
)
// Test stubs for now
2022-06-08 02:08:41 +02:00
func TestAuthNewToken(t *testing.T) {
2022-06-08 01:30:18 +02:00
auth := Auth{}
authToken, err := auth.NewToken(234, "dId", "my-scope")
if err != nil {
t.Fatalf("Error creating new token")
}
2022-06-08 01:30:18 +02:00
if authToken.UserId != 234 ||
authToken.DeviceId != "dId" ||
authToken.Scope != "my-scope" {
t.Fatalf("authToken fields don't match expected values")
}
// result.Token is in hex, AuthTokenLength is bytes in the original
expectedTokenLength := AuthTokenLength * 2
if len(authToken.Token) != expectedTokenLength {
t.Fatalf("authToken token string length isn't the expected length")
}
}
func TestAuthScopeValid(t *testing.T) {
2022-06-08 00:41:32 +02:00
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) {
2022-06-08 00:41:32 +02:00
bananaAuthToken := AuthToken{Scope: "banana"}
if bananaAuthToken.ScopeValid("*") {
t.Fatalf("Expected banana to be an invalid scope for *")
}
2022-06-22 17:04:26 +02:00
if bananaAuthToken.ScopeValid("carrot") {
t.Fatalf("Expected banana to be an invalid scope for carrot")
}
}