From 592f739205813aac906c21f3232d10e39cee0565 Mon Sep 17 00:00:00 2001 From: qalvinahmad Date: Mon, 16 Nov 2026 14:16:26 +0700 Subject: [PATCH 1/3] docs: specify auth mock fixture design Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../specs/2026-11-16-auth-mock-fixtures-design.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs/superpowers/specs/2026-11-16-auth-mock-fixtures-design.md diff --git a/docs/superpowers/specs/2026-11-16-auth-mock-fixtures-design.md b/docs/superpowers/specs/2026-11-16-auth-mock-fixtures-design.md new file mode 100644 index 00000000..fb9709de --- /dev/null +++ b/docs/superpowers/specs/2026-11-16-auth-mock-fixtures-design.md @@ -0,0 +1,15 @@ +# Auth Mock Fixtures Design + +## Goal + +Provide one canonical safe session fixture for Auth.js mocks, standardize synthetic credential and token values in `__mocks__/`, and verify auth and admin route tests without introducing route-specific session overrides. + +## Design + +`__mocks__/next-auth/index.ts` will define and export a frozen `SAFE_MOCK_SESSION`. `__mocks__/auth.ts` will import and re-export that object, use it for the default auth result, and retain `SAFE_MOCK_AUTH_SESSION` as an alias for compatibility. Credential and token placeholders in `__mocks__/` will use exact low-entropy placeholder forms already recognized by the CLI's entropy checks. Provider-specific prefixes will not be preserved when they are unnecessary to mock behavior. + +No route behavior or CLI detection rules will change. Existing route tests will remain responsible for explicit authorization cases; validation will run the requested auth and admin route tests, together with focused mock credential and CLI scanner/entropy tests. + +## Scope and validation + +Changes are limited to the canonical fixture, directly related mock placeholder strings, and focused regression assertions if needed. No dependencies, production authentication behavior, or scanner heuristics are in scope. Validation will run the auth route test, all `src/app/api/admin/**` route tests, and focused fixture/scanner/entropy tests. From 19ba6a09384e4614e4366edf885d919281b1da8b Mon Sep 17 00:00:00 2001 From: qalvinahmad Date: Mon, 16 Nov 2026 14:51:35 +0700 Subject: [PATCH 2/3] test(mocks): standardize auth mock fixtures Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- __mocks__/@armoriq/sdk.ts | 12 +++---- __mocks__/auth.ts | 15 +++----- __mocks__/groq-sdk.ts | 2 +- __mocks__/next-auth/index.ts | 12 +++++-- __mocks__/next-auth/providers/github.ts | 4 +-- cli/src/scanner.test.ts | 1 + tests/audit-mock-credentials.test.ts | 46 +++++++++++++++++++++---- tests/fixtures/mock-session.ts | 10 +----- vitest.setup.ts | 22 +++++++----- 9 files changed, 79 insertions(+), 45 deletions(-) diff --git a/__mocks__/@armoriq/sdk.ts b/__mocks__/@armoriq/sdk.ts index 12ced74d..6c4dd108 100644 --- a/__mocks__/@armoriq/sdk.ts +++ b/__mocks__/@armoriq/sdk.ts @@ -8,8 +8,8 @@ import { vi } from "vitest"; /** Safe synthetic API key placeholder for ArmorIQ tests. */ -export const SAFE_MOCK_ARMORIQ_API_KEY = "armoriq_mock_test_key_safe"; -export const SAFE_MOCK_INTENT_TOKEN = "intent_mock_token_safe_never_leak"; +export const SAFE_MOCK_ARMORIQ_API_KEY = "mock_api_key"; +export const SAFE_MOCK_INTENT_TOKEN = "mock_token"; /** * Custom Error thrown when upstream ArmorIQ service times out. @@ -155,8 +155,8 @@ export const mockVerifyIntentToken = vi.fn().mockImplementation(async (token: st decision: mockArmorIQState.decision, ruleMatched: mockArmorIQState.ruleMatched, justification: mockArmorIQState.justification, - proofHash: mockArmorIQState.validProof ? "mock_proof_hash_abc123" : null, - signature: mockArmorIQState.validSignature ? "mock_sig_xyz789" : null, + proofHash: mockArmorIQState.validProof ? "mock_secret" : null, + signature: mockArmorIQState.validSignature ? "mock_token" : null, token, }; }); @@ -173,7 +173,7 @@ export const mockSignIntent = vi return { signed: true, intentId: "intent_mock_12345", - signature: "mock_signature_hash_67890", + signature: "mock_token", intent, }; }); @@ -231,7 +231,7 @@ export const mockGetIntentToken = vi throw new ArmorIQUnreachableError(); } return { - tokenId: `intent_token_${Date.now()}`, + tokenId: "mock_token", token: SAFE_MOCK_INTENT_TOKEN, plan, policy, diff --git a/__mocks__/auth.ts b/__mocks__/auth.ts index 2a1b28e1..4e83c934 100644 --- a/__mocks__/auth.ts +++ b/__mocks__/auth.ts @@ -5,17 +5,10 @@ * without any hardcoded production secrets, session keys, or private credentials. */ import { vi } from "vitest"; +import { SAFE_MOCK_SESSION } from "./next-auth/index.js"; -/** Safe synthetic session fixture for test suites. */ -export const SAFE_MOCK_AUTH_SESSION = Object.freeze({ - user: { - id: "mock-test-user-id", - name: "Mock Security Engineer", - email: "mock-user@secureflow.internal.test", - image: null, - }, - expires: "2099-01-01T00:00:00.000Z", -}); +export { SAFE_MOCK_SESSION }; +export const SAFE_MOCK_AUTH_SESSION = SAFE_MOCK_SESSION; export const auth = (handler?: any) => @@ -23,7 +16,7 @@ export const auth = if (typeof handler === "function") { return handler(req, ...args); } - return SAFE_MOCK_AUTH_SESSION; + return SAFE_MOCK_SESSION; }; export const signIn = vi.fn(); diff --git a/__mocks__/groq-sdk.ts b/__mocks__/groq-sdk.ts index 64379312..3db60e7f 100644 --- a/__mocks__/groq-sdk.ts +++ b/__mocks__/groq-sdk.ts @@ -7,7 +7,7 @@ import { vi } from "vitest"; /** Safe synthetic placeholder API key for test suites. */ -export const SAFE_MOCK_GROQ_API_KEY = "gsk_mock_test_token_never_expose"; +export const SAFE_MOCK_GROQ_API_KEY = "mock_api_key"; /** * Asserts that a provided API key is purely a synthetic mock token diff --git a/__mocks__/next-auth/index.ts b/__mocks__/next-auth/index.ts index 3e560500..c56c3ac0 100644 --- a/__mocks__/next-auth/index.ts +++ b/__mocks__/next-auth/index.ts @@ -5,8 +5,16 @@ * without requiring or storing hardcoded OAuth tokens, client secrets, or user credentials. */ import { vi } from "vitest"; -import { SAFE_MOCK_SESSION } from "../../tests/fixtures/mock-session"; -export { SAFE_MOCK_SESSION }; + +export const SAFE_MOCK_SESSION = Object.freeze({ + user: { + id: "mock_test_user_id", + name: "Mock Security Engineer", + email: "mock-user@secureflow.internal.test", + image: null, + }, + expires: "2099-01-01T00:00:00.000Z", +}); export const auth = vi.fn(async () => SAFE_MOCK_SESSION); export const signIn = vi.fn(); diff --git a/__mocks__/next-auth/providers/github.ts b/__mocks__/next-auth/providers/github.ts index cd2ab43d..2eaf8ca3 100644 --- a/__mocks__/next-auth/providers/github.ts +++ b/__mocks__/next-auth/providers/github.ts @@ -11,8 +11,8 @@ export default vi.fn((config: Record = {}) => ({ type: "oauth", name: "GitHub", config: { - clientId: "mock-github-client-id", - clientSecret: "mock-github-client-secret-do-not-use", + clientId: "mock_key", + clientSecret: "mock_secret", ...config, }, })); diff --git a/cli/src/scanner.test.ts b/cli/src/scanner.test.ts index d73d5491..ffe99ee0 100644 --- a/cli/src/scanner.test.ts +++ b/cli/src/scanner.test.ts @@ -534,6 +534,7 @@ describe("entropy and benign secret false positive suppression (#1512)", () => { it("does not flag benign placeholder tokens and mock keys", () => { const benignCases = [ "console.log(your_api_key_here);", + "console.log(mock_api_key);", "console.info(mock_token);", "console.warn(placeholder_token);", "console.error(dummy_secret);", diff --git a/tests/audit-mock-credentials.test.ts b/tests/audit-mock-credentials.test.ts index 62b1413c..23943145 100644 --- a/tests/audit-mock-credentials.test.ts +++ b/tests/audit-mock-credentials.test.ts @@ -5,10 +5,11 @@ import MockGroq, { mockCreate, mockStream, } from "../__mocks__/groq-sdk"; -import NextAuth from "../__mocks__/next-auth"; -import { SAFE_MOCK_SESSION } from "./fixtures/mock-session"; +import NextAuth from "../__mocks__/next-auth/index.js"; +import { SAFE_MOCK_SESSION } from "../__mocks__/next-auth/index.js"; import githubProvider from "../__mocks__/next-auth/providers/github"; import { auth, SAFE_MOCK_AUTH_SESSION } from "../__mocks__/auth"; +import { hasHighEntropy, isBenignSecretCandidate } from "../cli/src/entropy.js"; describe("Mock Data Credentials Security Audit (#1303, #1354)", () => { describe("groq-sdk mock audit", () => { @@ -39,6 +40,7 @@ describe("Mock Data Credentials Security Audit (#1303, #1354)", () => { expect(SAFE_MOCK_SESSION.user.email).toContain("secureflow.internal.test"); expect(SAFE_MOCK_SESSION).not.toHaveProperty("accessToken"); expect(SAFE_MOCK_SESSION).not.toHaveProperty("secret"); + expect(Object.isFrozen(SAFE_MOCK_SESSION)).toBe(true); }); it("creates next-auth instance mock with safe handlers", async () => { @@ -53,15 +55,16 @@ describe("Mock Data Credentials Security Audit (#1303, #1354)", () => { it("mocks github provider with dummy non-functional secrets", () => { const provider = githubProvider(); expect(provider.id).toBe("github"); - expect(provider.config.clientId).toBe("mock-github-client-id"); - expect(provider.config.clientSecret).toBe("mock-github-client-secret-do-not-use"); + expect(provider.config.clientId).toBe("mock_key"); + expect(provider.config.clientSecret).toBe("mock_secret"); }); }); describe("auth mock audit", () => { it("returns safe mock session when invoked directly", async () => { const session = await auth()(); - expect(session).toEqual(SAFE_MOCK_AUTH_SESSION); + expect(session).toBe(SAFE_MOCK_SESSION); + expect(SAFE_MOCK_AUTH_SESSION).toBe(SAFE_MOCK_SESSION); }); it("passes through handler functions as middleware wrapper", async () => { @@ -82,6 +85,37 @@ describe("Mock Data Credentials Security Audit (#1303, #1354)", () => { expect(client.apiKey).toBe(SAFE_MOCK_ARMORIQ_API_KEY); }); + it("uses entropy-safe forms for mock credentials and token-like outputs", async () => { + const { + ArmorIQClient, + SAFE_MOCK_ARMORIQ_API_KEY, + SAFE_MOCK_INTENT_TOKEN, + mockVerifyIntentToken, + mockSignIntent, + } = await import("../__mocks__/@armoriq/sdk"); + const provider = githubProvider(); + const client = new ArmorIQClient(); + const verified = await mockVerifyIntentToken("mock_token"); + const signed = await mockSignIntent({}); + const generated = await client.getIntentToken({}, {}); + const values = [ + SAFE_MOCK_GROQ_API_KEY, + SAFE_MOCK_ARMORIQ_API_KEY, + SAFE_MOCK_INTENT_TOKEN, + provider.config.clientId, + provider.config.clientSecret, + verified.proofHash, + verified.signature, + signed.signature, + generated.token, + generated.tokenId, + ].filter((value): value is string => typeof value === "string"); + + expect(values.every(isBenignSecretCandidate)).toBe(true); + expect(values.every((value) => !hasHighEntropy(value))).toBe(true); + expect(client.apiKey).toBe(SAFE_MOCK_ARMORIQ_API_KEY); + }); + it("supports standardized blocked intent, policy violation, and degraded helpers (#1355)", async () => { const { setMockArmorIQBlockedIntent, @@ -130,7 +164,7 @@ describe("Mock Data Credentials Security Audit (#1303, #1354)", () => { const tokenResult = await client.getIntentToken({ plan: "test" }, { policy: "strict" }); expect(tokenResult.token).toBeDefined(); - expect(tokenResult.tokenId).toContain("intent_token_"); + expect(tokenResult.tokenId).toBe("mock_token"); }); }); }); diff --git a/tests/fixtures/mock-session.ts b/tests/fixtures/mock-session.ts index d066de45..0714b4ed 100644 --- a/tests/fixtures/mock-session.ts +++ b/tests/fixtures/mock-session.ts @@ -1,9 +1 @@ -export const SAFE_MOCK_SESSION = Object.freeze({ - user: { - id: "mock_test_user_id", - name: "Mock Security Engineer", - email: "mock-user@secureflow.internal.test", - image: null, - }, - expires: "2099-01-01T00:00:00.000Z", -}); +export { SAFE_MOCK_SESSION } from "../../__mocks__/next-auth/index.js"; diff --git a/vitest.setup.ts b/vitest.setup.ts index b3e80f4c..c177cffe 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -53,14 +53,20 @@ vi.mock("ioredis", () => { }); // Stub next-auth so importing @/auth never tries to read next.config.js. -vi.mock("next-auth", () => ({ - default: vi.fn(() => ({ - handlers: {}, - signIn: vi.fn(), - signOut: vi.fn(), - auth: vi.fn(async () => null), - })), -})); +vi.mock("next-auth", async (importOriginal) => { + const { SAFE_MOCK_SESSION } = + await importOriginal(); + + return { + SAFE_MOCK_SESSION, + default: vi.fn(() => ({ + handlers: {}, + signIn: vi.fn(), + signOut: vi.fn(), + auth: vi.fn(async () => null), + })), + }; +}); // Stub @/auth directly so test files that import it get a simple mock. vi.mock("@/auth", () => ({ From 6df5f63eef8c4c8c1173c082c50f95c2cf12e00f Mon Sep 17 00:00:00 2001 From: qalvinahmad Date: Mon, 16 Nov 2026 17:59:12 +0700 Subject: [PATCH 3/3] fix(mocks): keep session fixture in tests Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- __mocks__/auth.ts | 2 +- __mocks__/next-auth/index.ts | 12 ++---------- tests/audit-mock-credentials.test.ts | 4 ++-- tests/fixtures/mock-session.ts | 10 +++++++++- vitest.setup.ts | 22 ++++++++-------------- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/__mocks__/auth.ts b/__mocks__/auth.ts index 4e83c934..f1a17fee 100644 --- a/__mocks__/auth.ts +++ b/__mocks__/auth.ts @@ -5,7 +5,7 @@ * without any hardcoded production secrets, session keys, or private credentials. */ import { vi } from "vitest"; -import { SAFE_MOCK_SESSION } from "./next-auth/index.js"; +import { SAFE_MOCK_SESSION } from "../tests/fixtures/mock-session"; export { SAFE_MOCK_SESSION }; export const SAFE_MOCK_AUTH_SESSION = SAFE_MOCK_SESSION; diff --git a/__mocks__/next-auth/index.ts b/__mocks__/next-auth/index.ts index c56c3ac0..3e560500 100644 --- a/__mocks__/next-auth/index.ts +++ b/__mocks__/next-auth/index.ts @@ -5,16 +5,8 @@ * without requiring or storing hardcoded OAuth tokens, client secrets, or user credentials. */ import { vi } from "vitest"; - -export const SAFE_MOCK_SESSION = Object.freeze({ - user: { - id: "mock_test_user_id", - name: "Mock Security Engineer", - email: "mock-user@secureflow.internal.test", - image: null, - }, - expires: "2099-01-01T00:00:00.000Z", -}); +import { SAFE_MOCK_SESSION } from "../../tests/fixtures/mock-session"; +export { SAFE_MOCK_SESSION }; export const auth = vi.fn(async () => SAFE_MOCK_SESSION); export const signIn = vi.fn(); diff --git a/tests/audit-mock-credentials.test.ts b/tests/audit-mock-credentials.test.ts index 23943145..38c2fec7 100644 --- a/tests/audit-mock-credentials.test.ts +++ b/tests/audit-mock-credentials.test.ts @@ -5,8 +5,8 @@ import MockGroq, { mockCreate, mockStream, } from "../__mocks__/groq-sdk"; -import NextAuth from "../__mocks__/next-auth/index.js"; -import { SAFE_MOCK_SESSION } from "../__mocks__/next-auth/index.js"; +import NextAuth from "../__mocks__/next-auth"; +import { SAFE_MOCK_SESSION } from "./fixtures/mock-session"; import githubProvider from "../__mocks__/next-auth/providers/github"; import { auth, SAFE_MOCK_AUTH_SESSION } from "../__mocks__/auth"; import { hasHighEntropy, isBenignSecretCandidate } from "../cli/src/entropy.js"; diff --git a/tests/fixtures/mock-session.ts b/tests/fixtures/mock-session.ts index 0714b4ed..d066de45 100644 --- a/tests/fixtures/mock-session.ts +++ b/tests/fixtures/mock-session.ts @@ -1 +1,9 @@ -export { SAFE_MOCK_SESSION } from "../../__mocks__/next-auth/index.js"; +export const SAFE_MOCK_SESSION = Object.freeze({ + user: { + id: "mock_test_user_id", + name: "Mock Security Engineer", + email: "mock-user@secureflow.internal.test", + image: null, + }, + expires: "2099-01-01T00:00:00.000Z", +}); diff --git a/vitest.setup.ts b/vitest.setup.ts index c177cffe..b3e80f4c 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -53,20 +53,14 @@ vi.mock("ioredis", () => { }); // Stub next-auth so importing @/auth never tries to read next.config.js. -vi.mock("next-auth", async (importOriginal) => { - const { SAFE_MOCK_SESSION } = - await importOriginal(); - - return { - SAFE_MOCK_SESSION, - default: vi.fn(() => ({ - handlers: {}, - signIn: vi.fn(), - signOut: vi.fn(), - auth: vi.fn(async () => null), - })), - }; -}); +vi.mock("next-auth", () => ({ + default: vi.fn(() => ({ + handlers: {}, + signIn: vi.fn(), + signOut: vi.fn(), + auth: vi.fn(async () => null), + })), +})); // Stub @/auth directly so test files that import it get a simple mock. vi.mock("@/auth", () => ({