Skip to content
Open
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
5 changes: 5 additions & 0 deletions sdk/typescript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,11 @@ export function scanAuthentication(
environment: ProcessEnvironment,
auth: ScanAuthMode = "auto",
): ScanAuthentication {
if (auth !== "auto" && auth !== "chatgpt" && auth !== "api-key") {
throw new TypeError(
"Scan authentication mode must be auto, chatgpt, or api-key.",
);
}
if (auth === "chatgpt") {
return { method: "stored_credentials", verified: false };
}
Expand Down
29 changes: 29 additions & 0 deletions sdk/typescript/tests-ts/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,35 @@ describe("CodexSecurity orchestration", () => {
await client.close();
});

test("rejects unsupported authentication modes before runtime initialization", async () => {
const root = await temporaryDirectory();
const repository = join(root, "repository");
await mkdir(repository);
let runtimeStarted = false;
const client = new TestClient(
{},
{
environment: { OPENAI_API_KEY: "synthetic-openai-key" },
prepareRuntime: async () => {
runtimeStarted = true;
throw new Error("runtime should not initialize");
},
},
);
const options = {
auth: "unsupported",
} as unknown as ScanOptions;

await expect(client.preflight(repository, options)).rejects.toThrow(
"Scan authentication mode must be auto, chatgpt, or api-key.",
);
await expect(client.run(repository, options)).rejects.toThrow(
"Scan authentication mode must be auto, chatgpt, or api-key.",
);
expect(runtimeStarted).toBe(false);
await client.close();
});

test("rejects explicit API-key authentication without a configured key before runtime initialization", async () => {
const root = await temporaryDirectory();
const repository = join(root, "repository");
Expand Down