import { describe, expect, it } from "vitest"; import { catalogSpec, isAutomatic, isIdentifier, isNotSecret, parseRotationSpec, planRotations, baseKeyName, EMPTY_FINGERPRINT } from "./rotation-catalog.js"; import { checkSpecForKey, rotationTargets, scheduledBlock } from "./rotate-keys.js"; const method = (k: string) => catalogSpec(k)?.method; describe("catalog coverage (2026-10-29 plan)", () => { it("never automates money, signing, the personal vault, Stripe, npm or GitHub App keys", () => { for (const k of [ "SYSTEM_MNEMONIC_SOL__1", "TREASURY_MNEMONIC_ETH", "PRIVATE_KEY", "LN_HSM_SECRET_HEX", "LNBITS_ADMIN_KEY", "KRAKEN_API_SECRET", "COINBASE_API_PRIVATE_KEY_B64", "STRIPE_SECRET_KEY", "STRIPE_WEBHOOK_SECRET", "NPM_TOKEN", "GITHUB_APP_PRIVATE_KEY", "OPENCREDS_MASTER_PASSWORD", "OPENCREDS_RECOVERY_KEY", "W3BS_TUF_ROOT_KEY_PK8_B64", "DID_PRIVATE_KEY_BASE64", "MOSHPIT_CA_ROOT_KEY", "FTB_BUSINESS_PASSWORD" ]) { const s = catalogSpec(k); expect(s?.never, k).toBe(true); expect(s?.owner, k).toBe("anthony"); expect(isAutomatic(s), k).toBe(false); } }); it("never mints random bytes for provider secrets that look like ours", () => { for (const k of ["SLACK_SIGNING_SECRET", "JWT_SECRET", "SUPABASE_JWT_SECRET", "FIREFOX_JWT_SECRET", "META_APP_SECRET", "GITHUB_WEBHOOK_SECRET"]) { expect(method(k), k).not.toBe("random"); } }); it("routes keys with clean APIs to provider rotators", () => { expect(catalogSpec("RESEND_API_KEY")?.provider).toBe("resend"); expect(catalogSpec("RESEND_PITWORLD_ADMIN_KEY")?.provider).toBe("resend"); expect(catalogSpec("CLOUDFLARE_API_TOKEN")?.provider).toBe("cloudflare-token"); expect(catalogSpec("COINPAY_API_KEY")?.provider).toBe("coinpay-api-key"); expect(catalogSpec("COINPAYPORTAL_WEBHOOK_SECRET")?.provider).toBe("coinpay-webhook-secret"); expect(catalogSpec("VAPID_PRIVATE_KEY")?.provider).toBe("vapid"); expect(catalogSpec("VAPID_PRIVATE")?.provider).toBe("vapid"); expect(catalogSpec("SUPABASE_DB_PASSWORD")?.provider).toBe("postgres-role"); }); it("classifies public config as not-secret", () => { for (const k of [ "COINPAY_OAUTH_CLIENT_ID", "COINPAY_OAUTH_REDIRECT_URI", "COINPAY_OAUTH_SCOPES", "COINPAY_OAUTH_ISSUER", "STRIPE_PUBLISHABLE_KEY", "SUPABASE_PUBLISHABLE_KEY", "HCAPTCHA_SITE_KEY", "SENTRY_DSN", "EXPO_PUBLIC_SENTRY_DSN", "WEBAUTHN_RP_ID", "SESSION_COOKIE_SECURE", "TURSO_DATABASE_URL", "AUTHOR_BATCH_SIZE", "SYSTEM_KEY_GENERATION", "JWT_PUBLIC_KEY_JWK", "R2_ACCESS_KEY_ID", "__ARCHIVE__SUPABASE_SERVICE_ROLE_KEY" ]) { expect(isNotSecret(k), k).toBe(true); } // ...but a connection string can hold a password. expect(isNotSecret("DATABASE_URL")).toBe(false); expect(catalogSpec("DATABASE_URL")?.family).toBe("postgres"); expect(isNotSecret("NEXT_PUBLIC_SUPABASE_ANON_KEY")).toBe(false); }); it("gives every secret-looking name from the 2026-10-29 unknown list some instructions", () => { const unknownBefore = [ "ADMIN_KEY", "ADNETWORK_KEY", "ANON_KEY", "API_KEY_SALT", "BITTORRENTED_SUPABASE_KEY", "BUILTINDIE_KEY", "CRAWLPROOF_ACTOR_TOKEN_ANTHONY", "CRYPTO_APIS_KEY", "DB_PASS", "DEALDASH_COOKIE", "FAL_KEY", "GROUPCALL_AGENT_WORKER_KEY", "IMAP_PASS", "IP_HASH_SALT", "OPENACCESS_KEY_UGIG_NET", "PAYAGENT_KEY", "PG_META_CRYPTO_KEY", "SALAD_AI_GATEWAY_KEY", "SECRET_KEY_BASE", "SEEDBOX_HTTP_AUTH", "SERVICE_ROLE_KEY", "SMTP_PASS", "SOCIAL_VAULT_KEY", "SUPABASE_SECRETMAT_KEY", "TOKEN_ENC_KEY", "TURN_SERVER_CREDENTIAL", "VOTE_SALT", "SP_TOKEN_PEPPER", "AUR_SSH_KEY__1" ]; for (const k of unknownBefore) expect(catalogSpec(k), k).not.toBeNull(); }); it("strips __n duplicate suffixes before matching", () => { expect(baseKeyName("SYSTEM_MNEMONIC_BTC__2")).toBe("SYSTEM_MNEMONIC_BTC"); expect(method("CRON_SECRET__1")).toBe("random"); }); it("marks session signers disruptive so the weekly job leaves them", () => { expect(catalogSpec("SESSION_SECRET")?.disruptive).toBeTruthy(); expect(catalogSpec("CRON_SECRET")?.disruptive).toBeUndefined(); }); }); describe("planRotations", () => { const row = (vault: string, key: string, fingerprint: string) => ({ vault, key, fingerprint, updatedAt: "2026-10-01T00:00:00Z" }); it("drops not-secret, archive and empty values; an entry can declare not-secret", () => { const plan = planRotations( [row("a--prod", "COINPAY_OAUTH_CLIENT_ID", "f1"), row("a--prod", "__ARCHIVE__X", "f2"), row("a--prod", "CRON_SECRET", EMPTY_FINGERPRINT), row("a--prod", "WEIRD_TOKEN", "f3"), row("a--prod", "CRON_SECRET", "f4")], new Map([["a--prod\u0000WEIRD_TOKEN", { method: "not-secret" as const }]]) ); expect(plan.map((p) => p.key)).toEqual(["CRON_SECRET"]); }); }); describe("entry specs", () => { it("cannot make a wallet key automatic", () => { const plan = planRotations([{ vault: "c--prod", key: "TREASURY_MNEMONIC_SOL", fingerprint: "f", updatedAt: "" }], new Map([["c--prod\u0000TREASURY_MNEMONIC_SOL", { method: "random" as const }]])); expect(plan[0]!.automatic).toBe(false); expect(plan[0]!.spec?.never).toBe(true); }); it("TURN secrets are manual (coturn config holds a copy)", () => { expect(catalogSpec("TURN_SERVER_CREDENTIAL")?.method).toBe("manual"); }); }); describe("scheduledBlock", () => { const p = (spec: any) => ({ key: "K", vaults: ["a--prod"], fingerprint: "f", oldestUpdate: "", method: spec.method, source: "catalog" as const, automatic: isAutomatic(spec), spec }); it("lets plain random secrets and overlapping provider rotators through, nothing else", () => { expect(scheduledBlock(p(catalogSpec("CRON_SECRET")))).toBeNull(); expect(scheduledBlock(p(catalogSpec("RESEND_API_KEY")))).toBeNull(); expect(scheduledBlock(p(catalogSpec("CLOUDFLARE_API_TOKEN")))).toBeNull(); expect(scheduledBlock(p(catalogSpec("COINPAY_API_KEY")))).toBeNull(); expect(scheduledBlock(p(catalogSpec("SESSION_SECRET")))).toMatch(/disruptive/); expect(scheduledBlock(p(catalogSpec("COINPAY_WEBHOOK_SECRET")))).toMatch(/disruptive/); expect(scheduledBlock(p(catalogSpec("SUPABASE_DB_PASSWORD")))).toMatch(/disruptive/); expect(scheduledBlock(p(catalogSpec("SSH_ID_ED25519")))).toMatch(/person/); expect(scheduledBlock(p(catalogSpec("SYSTEM_MNEMONIC_SOL")))).toMatch(/person|never/); }); }); describe("OAuth client ids are identifiers, never rotated (c0upons invalid_client, 2026-11-22)", () => { const row = (vault: string, key: string, fingerprint: string) => ({ vault, key, fingerprint, updatedAt: "2026-11-22T00:00:00Z" }); it("classifies every *_CLIENT_ID as an identifier that is never automatic", () => { for (const k of ["COINPAY_CLIENT_ID", "COINPAY_OAUTH_CLIENT_ID", "GOOGLE_CLIENT_ID", "GITHUB_OAUTH_CLIENT_ID", "CLIENT_ID", "COINPAY_CLIENT_ID__1"]) { expect(isIdentifier(k)).toBe(true); const spec = catalogSpec(k); expect(spec?.method).toBe("identifier"); expect(spec?.never).toBe(true); expect(isAutomatic(spec)).toBe(false); expect(spec?.note).toMatch(/not a secret/); } for (const k of ["COINPAY_CLIENT_SECRET", "COINPAY_API_KEY", "CLIENT_IDS_URL"]) expect(isIdentifier(k)).toBe(false); expect(catalogSpec("COINPAY_API_KEY")?.provider).toBe("coinpay-api-key"); expect(isAutomatic(catalogSpec("COINPAY_API_KEY"))).toBe(true); }); it("a __ROTATE__ entry claiming provider rotation is overridden and reported, not automatic", () => { const entries = new Map([["c0upons--prod\u0000COINPAY_CLIENT_ID", parseRotationSpec(JSON.stringify({ method: "provider", provider: "coinpay-api-key", family: "coinpay" }))]]); const plan = planRotations([row("c0upons--prod", "COINPAY_CLIENT_ID", "f1"), row("other--prod", "COINPAY_CLIENT_ID", "f2")], entries); expect(plan).toHaveLength(1); expect(plan[0]).toMatchObject({ key: "COINPAY_CLIENT_ID", method: "identifier", automatic: false, source: "entry" }); expect(plan[0]!.spec?.note).toMatch(/is ignored/); expect(scheduledBlock(plan[0]!)).toBe("needs a person"); }); it("an identifier entry drops the key from the plan again", () => { const entries = new Map([["a--prod\u0000COINPAY_CLIENT_ID", parseRotationSpec(JSON.stringify({ method: "identifier" }))]]); expect(planRotations([row("a--prod", "COINPAY_CLIENT_ID", "f1")], entries)).toEqual([]); }); it("rotation-set refuses an automatic method for a client id", () => { for (const method of ["random", "provider", "command", "ssh-keygen"]) { const spec = parseRotationSpec(JSON.stringify({ method, provider: "coinpay-api-key", command: "x" })); expect(() => checkSpecForKey("COINPAY_CLIENT_ID", spec)).toThrow(/OAuth client id/); } expect(checkSpecForKey("COINPAY_CLIENT_ID", { method: "identifier" })).toMatchObject({ method: "identifier", never: true }); expect(checkSpecForKey("COINPAY_CLIENT_ID", { method: "manual", steps: ["x"] })).toMatchObject({ method: "manual", never: true }); expect(checkSpecForKey("COINPAY_API_KEY", { method: "provider", provider: "coinpay-api-key" }).method).toBe("provider"); }); it("a rotation never writes into a client id that shares the value, and the plan's key comes first", () => { const all = [ { vault: "a", key: "COINPAY_CLIENT_ID" }, { vault: "b", key: "COINPAY_API_KEY" }, { vault: "c", key: "CP_KEY" } ]; const { targets, skipped } = rotationTargets(all, "COINPAY_API_KEY"); expect(targets.map((t) => t.key)).toEqual(["COINPAY_API_KEY", "CP_KEY"]); expect(skipped.map((t) => t.vault)).toEqual(["a"]); }); });