desloppify: code health overhaul plus abuse hardening (140 green, strict 87.2)
Honest baseline after removing 45 gaming suppressions. Structural: lib/game plus root hooks extraction, CORS origin echo, DEV_ORIGINS layering. Fixes: error-cause binding, discord 5xx split, null-cache guard, co-located tests, rejecting-fetch coverage, naming and typing cleanup, socket controller, cache bound, cascade helpers, latch resets. Hardening: per-IP rate limit on API routes, deterministic-miss UX, retry cooldown plus cap. Suite 140 green, build plus lint clean.
This commit is contained in:
78 files changed
+4908
-1430
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { GET } from "@/app/api/game/[id]/route";
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
function contextWith(id: string) {
|
||||
return { params: Promise.resolve({ id }) };
|
||||
}
|
||||
|
||||
function requestWith(url: string) {
|
||||
return new Request(url);
|
||||
}
|
||||
|
||||
describe("GET /api/game/[id]", () => {
|
||||
it("returns 400 for non-numeric ids", async () => {
|
||||
const response = await GET(
|
||||
requestWith("https://fristy.net/api/game/abc"),
|
||||
contextWith("abc"),
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("https://fristy.net");
|
||||
});
|
||||
|
||||
it("returns 404 when no profile resolves", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () => ({ ok: false, status: 404 })),
|
||||
);
|
||||
const response = await GET(
|
||||
requestWith("https://fristy.net/api/game/123"),
|
||||
contextWith("123"),
|
||||
);
|
||||
expect(response.status).toBe(404);
|
||||
});
|
||||
|
||||
it("returns 502 when upstream networking fails", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(async () => {
|
||||
throw new Error("down");
|
||||
}),
|
||||
);
|
||||
const response = await GET(
|
||||
requestWith("https://fristy.net/api/game/123"),
|
||||
contextWith("123"),
|
||||
);
|
||||
expect(response.status).toBe(502);
|
||||
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("https://fristy.net");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user