Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions __mocks__/@armoriq/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
};
});
Expand All @@ -173,7 +173,7 @@ export const mockSignIntent = vi
return {
signed: true,
intentId: "intent_mock_12345",
signature: "mock_signature_hash_67890",
signature: "mock_token",
intent,
};
});
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 4 additions & 11 deletions __mocks__/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@
* 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) =>
async (req?: any, ...args: any[]) => {
if (typeof handler === "function") {
return handler(req, ...args);
}
return SAFE_MOCK_AUTH_SESSION;
return SAFE_MOCK_SESSION;
};

export const signIn = vi.fn();
Expand Down
2 changes: 1 addition & 1 deletion __mocks__/groq-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions __mocks__/next-auth/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default vi.fn((config: Record<string, any> = {}) => ({
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,
},
}));
1 change: 1 addition & 0 deletions cli/src/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);",
Expand Down
15 changes: 15 additions & 0 deletions docs/superpowers/specs/2026-11-16-auth-mock-fixtures-design.md
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 38 additions & 4 deletions tests/audit-mock-credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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,
Expand Down Expand Up @@ -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");
});
});
});