A container registry that uses the AT Protocol for manifest storage and S3 for blob storage.
1package auth
2
3import (
4 "testing"
5)
6
7func TestNewSessionValidator(t *testing.T) {
8 validator := NewSessionValidator()
9 if validator == nil {
10 t.Fatal("Expected non-nil validator")
11 }
12
13 if validator.httpClient == nil {
14 t.Error("Expected httpClient to be initialized")
15 }
16
17 if validator.cache == nil {
18 t.Error("Expected cache to be initialized")
19 }
20}
21
22func TestGetCacheKey(t *testing.T) {
23 // Cache key should be deterministic
24 key1 := getCacheKey("alice.bsky.social", "password123")
25 key2 := getCacheKey("alice.bsky.social", "password123")
26
27 if key1 != key2 {
28 t.Error("Expected same cache key for same credentials")
29 }
30
31 // Different credentials should produce different keys
32 key3 := getCacheKey("bob.bsky.social", "password123")
33 if key1 == key3 {
34 t.Error("Expected different cache keys for different users")
35 }
36
37 key4 := getCacheKey("alice.bsky.social", "different_password")
38 if key1 == key4 {
39 t.Error("Expected different cache keys for different passwords")
40 }
41
42 // Cache key should be hex-encoded SHA256 (64 characters)
43 if len(key1) != 64 {
44 t.Errorf("Expected cache key length 64, got %d", len(key1))
45 }
46}
47
48func TestSessionValidator_GetCachedSession_Miss(t *testing.T) {
49 validator := NewSessionValidator()
50 cacheKey := "nonexistent_key"
51
52 session, ok := validator.getCachedSession(cacheKey)
53 if ok {
54 t.Error("Expected cache miss for nonexistent key")
55 }
56 if session != nil {
57 t.Error("Expected nil session for cache miss")
58 }
59}