Skip to content

Commit 69aa2e0

Browse files
sharon77242claude
andcommitted
fix: remove committed private key and generate EC key pair dynamically in tests
- Delete tests/fixtures/dev-private-key.pem (was accidentally committed in 2dba2e0) - Restore .gitignore to *.pem only (no negation exception) - diagnostic-agent-coverage.test.ts: replace readFileSync PEM load with generateKeyPairSync + BUNDLED_PUBLIC_KEYS["dev-k1"] override - license-validator.test.ts: same for the dev-k1 integration describe block; uses test.before/test.after to set and restore the overridden key - public-key.ts: update comment — no longer references the removed fixture BREAKING: git history still contains the key at commit 2dba2e0; a force-push with BFG/filter-branch is needed to fully purge it from history. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2dba2e0 commit 69aa2e0

4 files changed

Lines changed: 33 additions & 19 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ coverage/
77
.claude/
88
plans/
99
*.pem
10-
!packages/agent/tests/fixtures/dev-private-key.pem

packages/agent/src/licensing/public-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The 'kid' claim in the JWT header selects the correct key.
44
export const BUNDLED_PUBLIC_KEYS: Record<string, string> = {
55
// ── dev key (kid: 'dev-k1') ────────────────────────────────────────────────
6-
// Local-development only. The matching private key is in tests/fixtures/dev-private-key.pem.
6+
// Local-development only. Tests override this key dynamically via generateKeyPairSync.
77
// Replace with production keys via scripts/embed-pubkey.ts before release.
88
"dev-k1": [
99
"-----BEGIN PUBLIC KEY-----",

packages/agent/tests/diagnostic-agent-coverage.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
import { describe, it, afterEach } from "node:test";
2121
import assert from "node:assert/strict";
2222
import { once } from "node:events";
23-
import { createSign, createPrivateKey } from "node:crypto";
24-
import { readFileSync } from "node:fs";
25-
import { resolve } from "node:path";
23+
import { createSign, generateKeyPairSync } from "node:crypto";
2624
import { DiagnosticAgent } from "../src/diagnostic-agent.ts";
25+
import { BUNDLED_PUBLIC_KEYS } from "../src/licensing/public-key.ts";
2726
import http from "node:http";
2827
import { type AddressInfo } from "node:net";
2928
import fs from "node:fs";
@@ -33,9 +32,12 @@ import os from "node:os";
3332
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
3433

3534
// ── Dev-k1 license JWT builder ────────────────────────────────────────────────
36-
const _devPrivKey = createPrivateKey(
37-
readFileSync(resolve(import.meta.dirname, "fixtures/dev-private-key.pem"), "utf8"),
38-
);
35+
// Generate a fresh EC P-256 key pair and override the embedded dev-k1 public key so tests
36+
// are fully self-contained and never depend on a fixture file.
37+
const { privateKey: _devPrivKey, publicKey: _devPubKeyObj } = generateKeyPairSync("ec", {
38+
namedCurve: "P-256",
39+
});
40+
BUNDLED_PUBLIC_KEYS["dev-k1"] = _devPubKeyObj.export({ type: "spki", format: "pem" }) as string;
3941
function b64u(buf: Buffer) {
4042
return buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
4143
}

packages/agent/tests/licensing/license-validator.test.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { test, describe } from "node:test";
22
import assert from "node:assert/strict";
3-
import { createSign, generateKeyPairSync, createPrivateKey } from "node:crypto";
4-
import { readFileSync } from "node:fs";
5-
import { resolve } from "node:path";
3+
import { createSign, generateKeyPairSync } from "node:crypto";
64
import { validateLicense } from "../../src/licensing/license-validator.ts";
75
import { BUNDLED_PUBLIC_KEYS } from "../../src/licensing/public-key.ts";
86

@@ -146,15 +144,30 @@ describe("validateLicense", () => {
146144
});
147145
});
148146

149-
// ── Integration: embedded dev-k1 key ─────────────────────────────────────────
150-
// Exercises the full validateLicense() path using the key actually embedded in
151-
// public-key.ts (kid: 'dev-k1') and its matching private key fixture.
147+
// ── Integration: dev-k1 key round-trip ───────────────────────────────────────
148+
// Verifies that validateLicense() correctly resolves the 'dev-k1' key from
149+
// BUNDLED_PUBLIC_KEYS. We generate a fresh key pair so no fixture file is needed.
152150
describe("dev-k1 embedded key integration", () => {
153-
const devPrivateKeyPem = readFileSync(
154-
resolve(import.meta.dirname, "../fixtures/dev-private-key.pem"),
155-
"utf8",
156-
);
157-
const devPrivateKey = createPrivateKey(devPrivateKeyPem);
151+
const { privateKey: devPrivateKey, publicKey: devPublicKeyObj } = generateKeyPairSync("ec", {
152+
namedCurve: "P-256",
153+
});
154+
let originalDevK1: string | undefined;
155+
156+
test.before(() => {
157+
originalDevK1 = BUNDLED_PUBLIC_KEYS["dev-k1"];
158+
BUNDLED_PUBLIC_KEYS["dev-k1"] = devPublicKeyObj.export({
159+
type: "spki",
160+
format: "pem",
161+
}) as string;
162+
});
163+
164+
test.after(() => {
165+
if (originalDevK1 !== undefined) {
166+
BUNDLED_PUBLIC_KEYS["dev-k1"] = originalDevK1;
167+
} else {
168+
delete BUNDLED_PUBLIC_KEYS["dev-k1"];
169+
}
170+
});
158171

159172
function buildDevJwt(claims: Record<string, unknown>): string {
160173
const header = base64UrlEncode(

0 commit comments

Comments
 (0)