test(auth): retarget the MFA route mocks at the shared gate

The three unit suites that stubbed `requireCookieAuth` / `requireFreshMfa`
directly now stub `requireMfaManagementAuth`, and the password-change suite
stubs the elevation revocation the route gained. Adds the unit checks that need
no database: the elevation TTL is pinned to the cookie path's step-up window so
the two cannot drift apart, the minted value is a prefixed CSPRNG secret whose
plaintext never reaches the row, and a value carrying another credential's
prefix is refused without costing a query.
This commit is contained in:
Marc-André Bombeck committed 2026-07-19 13:14:38 +02:00
1 parent 433d983e60
commit ba45a25cb0
5 files changed
+132 -8

No files matched your search

+9 -2
View File
@@ -129,10 +129,17 @@ async function mintElevation(
return { status: res.status, body: (await res.json()) as never };
}
/**
* Some handlers in the set declare no request parameter (`apiHandler(async () =>
* …)`), so their wrapped type takes none. The runtime always passes one; this
* keeps the call sites honest without loosening the handlers themselves.
*/
type RouteFn = (request: NextRequest) => Promise<Response>;
/** GET /api/auth/me/mfa — the cheapest route in the elevation-accepting set. */
async function callMfaStatus(): Promise<Response> {
const { GET } = await import("@/app/api/auth/me/mfa/route");
return await GET(req("/api/auth/me/mfa"));
return await (GET as unknown as RouteFn)(req("/api/auth/me/mfa"));
}
async function auditReasons(action: string): Promise<string[]> {
@@ -338,7 +345,7 @@ describe("E5 — an elevation does not satisfy requireAdmin", () => {
useElevation(elevation);
const { GET } = await import("@/app/api/admin/users/route");
const res = await GET(req("/api/admin/users"));
const res = await (GET as unknown as RouteFn)(req("/api/admin/users"));
// Cookie-only, and the elevation is not a cookie. The account being a
// genuine admin is what makes this test worth having: the refusal is the