Backend (services/): make the app testable and fill real gaps. - Extract buildApp() factory; index.ts owns listen()/matcher tick - Real Apple/Google identity verification via jose JWKS (iss/aud/sub) - Guest -> OAuth account linking (POST /auth/link), rebind in place - POST /matches/:id/complete: record match + participants, update leaderboard, idempotent, guarded by server-to-server secret - Extract pure matchmaking pairing (computePairings); fix ticket deckId loss on match; map ZodError -> 400; @fastify/cors - vitest suite (40 tests), initial Prisma migration, prisma schema path Web (web/): new Vite + React + TS client. - Typed API client with one-shot 401 refresh/retry, localStorage auth - Login (guest), deck builder (slot-0 hero rule), queue polling, leaderboard; 11 tests, clean build Game (Assets/, Unity C#): champion-select layout now fits the roster size; add Golem and Bandit champions. Docs: root DEVELOPMENT.md tying game + services + web together. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import jwt from "jsonwebtoken";
|
|
import {
|
|
signAccessToken,
|
|
signRefreshToken,
|
|
verifyAccessToken,
|
|
verifyRefreshToken,
|
|
} from "../src/lib/jwt";
|
|
|
|
describe("jwt", () => {
|
|
it("round-trips an access token, preserving the playerId", () => {
|
|
const token = signAccessToken("player-123");
|
|
expect(verifyAccessToken(token).playerId).toBe("player-123");
|
|
});
|
|
|
|
it("round-trips a refresh token, preserving playerId and tokenVersion", () => {
|
|
const token = signRefreshToken("player-123", 7);
|
|
const payload = verifyRefreshToken(token);
|
|
expect(payload.playerId).toBe("player-123");
|
|
expect(payload.tokenVersion).toBe(7);
|
|
});
|
|
|
|
it("rejects a token signed with a different secret", () => {
|
|
const forged = jwt.sign({ playerId: "attacker" }, "wrong-secret");
|
|
expect(() => verifyAccessToken(forged)).toThrow();
|
|
});
|
|
|
|
it("rejects a tampered token", () => {
|
|
const token = signAccessToken("player-123");
|
|
const tampered = token.slice(0, -4) + "aaaa";
|
|
expect(() => verifyAccessToken(tampered)).toThrow();
|
|
});
|
|
|
|
it("rejects an expired token", () => {
|
|
const expired = jwt.sign({ playerId: "player-123" }, "test-secret-do-not-use-in-prod", {
|
|
expiresIn: "-1s",
|
|
});
|
|
expect(() => verifyAccessToken(expired)).toThrow();
|
|
});
|
|
});
|