aa137e3558
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 11s
CI / ui (pull_request) Successful in 38s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Failing after 3s
New scrabble/loadtest module (the pre-release stress harness): seeds 1000 guest + 10000 durable accounts with pre-created sessions directly in Postgres (token hash matches backend/internal/session), drives virtual players through the edge protocol (real 2-4p games assembled via invitations, mid-ranked legal moves generated locally by the embedded scrabble-solver — the edge carries no board, so the client replays history), plus nudge/chat/check-word/draft/profile/stats and a gateway-hammer that verifies the rate limiter. Prints a trip-report summary (per-op latency percentiles, result codes, live-event tally). Go unit tests cover the pure pieces; the DAWG-backed move test runs under BACKEND_DICT_DIR. Contour: add cAdvisor + postgres_exporter + a 'Scrabble - Resources' Grafana dashboard and the two Prometheus scrape jobs, for the R2/R7 stress-run resource baseline. CI: gate ./loadtest/... (path filter + vet/build/test). Docs: TESTING, ARCHITECTURE, project CLAUDE repo layout.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package seed
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
// TestHashTokenMatchesSHA256Hex pins HashToken to the exact transformation the
|
|
// backend session resolver uses (hex-encoded SHA-256), the invariant that makes a
|
|
// seeded session resolve.
|
|
func TestHashTokenMatchesSHA256Hex(t *testing.T) {
|
|
const token = "an-example-bearer-token"
|
|
sum := sha256.Sum256([]byte(token))
|
|
want := hex.EncodeToString(sum[:])
|
|
if got := HashToken(token); got != want {
|
|
t.Fatalf("HashToken(%q) = %s, want %s", token, got, want)
|
|
}
|
|
}
|
|
|
|
// TestGenerateTokenRoundTrip checks that a minted token hashes to the stored hash and
|
|
// that tokens are unique.
|
|
func TestGenerateTokenRoundTrip(t *testing.T) {
|
|
token, hash, err := GenerateToken()
|
|
if err != nil {
|
|
t.Fatalf("GenerateToken: %v", err)
|
|
}
|
|
if token == "" || hash == "" {
|
|
t.Fatal("empty token or hash")
|
|
}
|
|
if len(hash) != 64 {
|
|
t.Fatalf("hash length = %d, want 64 hex chars", len(hash))
|
|
}
|
|
if got := HashToken(token); got != hash {
|
|
t.Fatalf("hash mismatch: GenerateToken returned %s, HashToken(token) = %s", hash, got)
|
|
}
|
|
token2, _, err := GenerateToken()
|
|
if err != nil {
|
|
t.Fatalf("GenerateToken (2nd): %v", err)
|
|
}
|
|
if token2 == token {
|
|
t.Fatal("two generated tokens are identical")
|
|
}
|
|
}
|