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..f1a17fee 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 "../tests/fixtures/mock-session"; -/** 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/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/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. diff --git a/tests/audit-mock-credentials.test.ts b/tests/audit-mock-credentials.test.ts index 62b1413c..38c2fec7 100644 --- a/tests/audit-mock-credentials.test.ts +++ b/tests/audit-mock-credentials.test.ts @@ -9,6 +9,7 @@ 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"; 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"); }); }); });