Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test(sdk): cover unreadable checked scan files (#1946)

Michael D'Angeloa638a6e3b1df
diff --git a/sdk/typescript/tests-ts/contract.test.ts b/sdk/typescript/tests-ts/contract.test.ts
index f8a33720b..43fe20d5b 100644
--- a/sdk/typescript/tests-ts/contract.test.ts
+++ b/sdk/typescript/tests-ts/contract.test.ts
@@ -375,6 +375,23 @@ describe("canonical scan contract", () => {
).resolves.toBe(false);
});
+ // macOS can reject the unreadable path before the checked open.
+ test.skipIf(process.platform !== "linux" || process.geteuid?.() === 0)(
+ "reports the permission error when opening an unreadable scan file",
+ async () => {
+ const scanDir = await realpath(await temporaryDirectory());
+ const path = join(scanDir, "report.md");
+ await writeFile(path, "Scan report", { mode: 0o000 });
+
+ const reading = readScanFile(scanDir, "report.md", "scan report");
+ await expect(reading).rejects.toBeInstanceOf(ContractValidationError);
+ await expect(reading).rejects.toMatchObject({
+ message: "scan report: unable to open the checked regular file.",
+ cause: expect.objectContaining({ code: "EACCES", path }),
+ });
+ },
+ );
+
test("rejects scan-file replacements whose numeric file IDs collide", async () => {
const title =
"rejects scan-file replacements whose numeric file IDs collide";