2021-12-25 02:16:58 +01:00
|
|
|
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")
|
|
|
|
}
|
2021-12-25 02:16:58 +01:00
|
|
|
|
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")
|
|
|
|
}
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 *")
|
|
|
|
}
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|