Files
streamline/satellite/test/security_cursor_diagnostics.test.ts
T
2026-11-16 17:26:44 -08:00

34 lines
1.8 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { CursorCliDiagnosticBuffer, redactCursorCliDiagnostic } from "../src/security_telemetry/cursor_cli_diagnostics";
import { classifySecurityAgentResult } from "../src/security_run_policy";
describe("security Cursor CLI diagnostics", () => {
test("strips terminal controls and redacts credentials, including split chunks", () => {
const buffer = new CursorCliDiagnosticBuffer();
buffer.append("\u001b[33mError: keychain is locked.\u001b[0m\nCURSOR_API_KEY=abc");
buffer.append("def123456\nAuthorization: Bearer private-auth-token\n");
buffer.append('"access_token": "secret value"\nJWT=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.private-signature\n');
const text = buffer.text();
expect(text).toContain("keychain is locked");
expect(text).toContain("[REDACTED]");
for (const secret of ["abcdef123456", "private-auth-token", "secret value", "private-signature", "\u001b"]) {
expect(text).not.toContain(secret);
}
expect(redactCursorCliDiagnostic("OPENAI_API_KEY=sk-testsecret12345")).not.toContain("sk-testsecret12345");
});
test("bounds long output without retaining clipped credential fragments", () => {
const buffer = new CursorCliDiagnosticBuffer();
buffer.append("CURSOR_API_KEY=" + "s".repeat(20_000) + "\n");
buffer.append("Error: Your macOS login keychain is locked.\n");
expect(buffer.text()).toContain("keychain is locked");
expect(buffer.text()).not.toContain("sss");
expect(buffer.text().length).toBeLessThanOrEqual(4_000);
});
test("does not classify successful agent prose about a keychain as auth failure", () => {
expect(classifySecurityAgentResult(JSON.stringify({ type: "result", subtype: "success", is_error: false,
result: "I documented what happens when the macOS login keychain is locked." }), "cursor")).toBeNull();
});
});