diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-16 20:05:39 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-16 20:13:47 +0900 |
| commit | 071e7cc78d3f13fa782dbc6ca5fcec3a37263a4d (patch) | |
| tree | d0174928c0d320bb76e0cdb899beee0476643d55 /backend/auth/session_test.go | |
| parent | 5ed369a6c70707543fd5ec9a13c79851fdfc5d6c (diff) | |
| download | phperkaigi-2026-albatross-071e7cc78d3f13fa782dbc6ca5fcec3a37263a4d.tar.gz phperkaigi-2026-albatross-071e7cc78d3f13fa782dbc6ca5fcec3a37263a4d.tar.zst phperkaigi-2026-albatross-071e7cc78d3f13fa782dbc6ca5fcec3a37263a4d.zip | |
test(backend): add unit tests for auth, config, ratelimit, game, and api
Cover previously untested logic: session ID generation/hashing,
password authentication, IP rate limiting, game state helpers,
handler endpoints, task enqueue/result processing, and config loading.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'backend/auth/session_test.go')
| -rw-r--r-- | backend/auth/session_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/backend/auth/session_test.go b/backend/auth/session_test.go new file mode 100644 index 0000000..2a47739 --- /dev/null +++ b/backend/auth/session_test.go @@ -0,0 +1,47 @@ +package auth + +import ( + "testing" +) + +func TestGenerateSessionID(t *testing.T) { + id, err := GenerateSessionID() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + // 32 bytes → 64 hex characters + if len(id) != 64 { + t.Errorf("expected session ID length 64, got %d", len(id)) + } +} + +func TestGenerateSessionID_Unique(t *testing.T) { + id1, err := GenerateSessionID() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + id2, err := GenerateSessionID() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if id1 == id2 { + t.Error("expected unique session IDs, got identical values") + } +} + +func TestHashSessionID(t *testing.T) { + raw := "abc123" + hashed := HashSessionID(raw) + // SHA-256 produces 32 bytes → 64 hex characters + if len(hashed) != 64 { + t.Errorf("expected hash length 64, got %d", len(hashed)) + } + // Same input should produce same hash + if hashed != HashSessionID(raw) { + t.Error("expected deterministic hash") + } + // Different input should produce different hash + if hashed == HashSessionID("different") { + t.Error("expected different hashes for different inputs") + } +} |
