test(01-03): add passkey enrollment security contracts

- require fresh existing-factor proof on both cookie-only legs
- bind registration challenges to user, purpose, session, expiry and one use
- cover bearer, ambient-cookie, stale, foreign and replay attacks
This commit is contained in:
Marc-André Bombeck committed 2026-07-29 13:38:53 +02:00
1 parent 6c0f47acad
commit 9f6cd86c0d
2 files changed
+457 -173

No files matched your search

@@ -11,6 +11,8 @@
* The write half (the stamp on a verified assertion) is pinned in
* `src/lib/auth/__tests__/passkey.test.ts`.
*/
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, it, expect, vi, beforeEach } from "vitest";
vi.mock("@/lib/api-handler", () => ({
@@ -80,3 +82,32 @@ describe("GET /api/auth/passkeys", () => {
expect(body.data[0].lastUsedAt).toBeNull();
});
});
describe("primary-passkey enrollment route guards", () => {
const optionsSource = readFileSync(
resolve(__dirname, "../../passkey/register-options/route.ts"),
"utf8",
);
const verifySource = readFileSync(
resolve(__dirname, "../../passkey/register-verify/route.ts"),
"utf8",
);
it("keeps both registration legs cookie-only", () => {
for (const source of [optionsSource, verifySource]) {
expect(source).toContain("requireCookieAuth");
expect(source).not.toMatch(/\brequireAuth\b/);
expect(source).not.toContain("requireMfaManagementAuth");
expect(source).not.toContain("requireBearerAuth");
}
});
it("requires existing-factor proof before options and repeats freshness on verify", () => {
expect(optionsSource).toMatch(
/password|totp|webauthn|passkey-registration/,
);
expect(optionsSource).toMatch(/session\.id/);
expect(verifySource).toMatch(/session\.id/);
expect(verifySource).toMatch(/fresh|reauth|proof/i);
});
});