Files
scrabble-game/loadtest/internal/seed/token.go
T
Ilia Denisov 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
R2: load-test harness + contour resource observability
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.
2026-06-09 23:45:24 +02:00

34 lines
1.2 KiB
Go

// Package seed creates accounts, identities and sessions directly in the backend
// Postgres schema so the load driver can authenticate as many pre-provisioned
// players without paying the per-IP cost of the auth edge operations. It owns the
// inverse operation too (cleanup of everything it created).
package seed
import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
)
// GenerateToken mints an opaque bearer token and its stored hash. token is the
// plaintext handed to the client; hash is what the seeder writes to
// sessions.token_hash. The transformation matches backend/internal/session so a
// resolve of token recomputes the same hash and finds the seeded row.
func GenerateToken() (token, hash string, err error) {
buf := make([]byte, 32)
if _, err := rand.Read(buf); err != nil {
return "", "", err
}
token = base64.RawURLEncoding.EncodeToString(buf)
return token, HashToken(token), nil
}
// HashToken returns the hex-encoded SHA-256 of token. It is the exact hash the
// backend session resolver computes (backend/internal/session/token.go), kept in
// lockstep so seeded sessions validate.
func HashToken(token string) string {
sum := sha256.Sum256([]byte(token))
return hex.EncodeToString(sum[:])
}