repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/leaks/__tests__/false-positives.test.ts

Raw
File outline
import { describe, expect, it } from "vitest";
import { __test } from "../index.ts";

function redacted(text: string, engine = new __test.LeaksEngine()) {
	return engine.redactText(text, "provider").text;
}

describe("leaks false-positive policy", () => {
	it("keeps metadata and references visible", () => {
		const negatives = [
			"feature/Project-Raven-auth-cleanup",
			"@scope/internal-package-name",
			"https://example.test/callback/path?user=me",
			"change host db.internal.test/path and preserve scheme",
			"username=alice",
			"CN=Alice Example,OU=People,DC=example,DC=test",
			"550e8400-e29b-41d4-a716-446655440000",
			"deadbeef",
			"4f9c2a7b8d1e3f604a9c2a7b8d1e3f604f9c2a7b8d1e3f60",
			"# default token placeholder goes here",
			"endpoint=prod-api",
			"10.0.0.0/24",
			"$API_KEY ${API_KEY} ${{ secrets.PROD_TOKEN }} process.env.API_KEY",
			"customer Acme Project Nightingale",
			"service.internal.corp",
			"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQMetadataOnly user@example",
			"-----BEGIN CERTIFICATE-----\nbody\n-----END CERTIFICATE-----",
		];

		for (const value of negatives) expect(redacted(value)).toBe(value);
	});

	it("keeps source code and complete-name near misses visible", () => {
		const ordinary = "ordinary-metadata-value-123456";
		const negatives = [
			"agendaFlick.visibleArea.yPosition",
			"application/vnd.openxmlformats-officedocument.sheet",
			`const STATUS_KEY = "${ordinary}";`,
			`const COOKIE = "${ordinary}";`,
			`const result = { session: runtimeSession };`,
			'function sum(key: "additions" | "deletions") {}',
			`https://example.test/?monkey=${ordinary}`,
			`Cookie: keyboard=${ordinary}`,
			`<session>${ordinary}</session>`,
		];

		for (const value of negatives) expect(redacted(value), value).toBe(value);
	});

	it("still redacts high-confidence provider-specific patterns", () => {
		const value = "ghp_" + "A".repeat(36);
		expect(redacted(value)).not.toBe(value);
	});

	it("lets custom regex override negative metadata policy", () => {
		const engine = new __test.LeaksEngine({
			settings: {
				regex: [{ pattern: "Project Nightingale", label: "CODENAME" }],
			},
		});
		const text = "customer Acme Project Nightingale";
		expect(redacted(text, engine)).not.toBe(text);
	});
});