mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-25 03:34:14 +00:00
unit tests
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user