60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package auth
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestNewSessionValidator(t *testing.T) {
|
|
validator := NewSessionValidator()
|
|
if validator == nil {
|
|
t.Fatal("Expected non-nil validator")
|
|
}
|
|
|
|
if validator.httpClient == nil {
|
|
t.Error("Expected httpClient to be initialized")
|
|
}
|
|
|
|
if validator.cache == nil {
|
|
t.Error("Expected cache to be initialized")
|
|
}
|
|
}
|
|
|
|
func TestGetCacheKey(t *testing.T) {
|
|
// Cache key should be deterministic
|
|
key1 := getCacheKey("alice.bsky.social", "password123")
|
|
key2 := getCacheKey("alice.bsky.social", "password123")
|
|
|
|
if key1 != key2 {
|
|
t.Error("Expected same cache key for same credentials")
|
|
}
|
|
|
|
// Different credentials should produce different keys
|
|
key3 := getCacheKey("bob.bsky.social", "password123")
|
|
if key1 == key3 {
|
|
t.Error("Expected different cache keys for different users")
|
|
}
|
|
|
|
key4 := getCacheKey("alice.bsky.social", "different_password")
|
|
if key1 == key4 {
|
|
t.Error("Expected different cache keys for different passwords")
|
|
}
|
|
|
|
// Cache key should be hex-encoded SHA256 (64 characters)
|
|
if len(key1) != 64 {
|
|
t.Errorf("Expected cache key length 64, got %d", len(key1))
|
|
}
|
|
}
|
|
|
|
func TestSessionValidator_GetCachedSession_Miss(t *testing.T) {
|
|
validator := NewSessionValidator()
|
|
cacheKey := "nonexistent_key"
|
|
|
|
session, ok := validator.getCachedSession(cacheKey)
|
|
if ok {
|
|
t.Error("Expected cache miss for nonexistent key")
|
|
}
|
|
if session != nil {
|
|
t.Error("Expected nil session for cache miss")
|
|
}
|
|
}
|