Skip to content

Commit 169ce05

Browse files
committed
fix: test
1 parent d8bad3c commit 169ce05

5 files changed

Lines changed: 63 additions & 26 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v6
13+
- uses: oven-sh/setup-bun@v2
14+
with:
15+
bun-version: latest
16+
- run: bun install --frozen-lockfile
17+
- run: bun run test
18+
- run: bun run test:integration
19+
- run: bun run lint
20+
- run: bun run typecheck
21+
- run: bun run build

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727
run: bun install --frozen-lockfile
2828

2929
- name: Run tests
30-
run: bun test
30+
run: bun run test
31+
- name: Run integration tests
32+
run: bun run test:integration
3133

3234
build:
3335
needs: test

src/commands/cert/issue.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,31 @@ export default defineCommand({
111111

112112
const result = await client.certificates.issue(request);
113113

114-
if (args.json) {
115-
output(result, { json: true });
116-
} else if (args["out-cert"] || args["out-key"]) {
117-
// Write files if requested
118-
if (args["out-cert"]) {
119-
writeFileSync(args["out-cert"], result.certificate.certificate_pem);
120-
console.log(`Certificate written to ${args["out-cert"]}`);
121-
}
114+
// Write files if requested
115+
if (args["out-cert"]) {
116+
writeFileSync(args["out-cert"], result.certificate.certificate_pem);
117+
console.log(`Certificate written to ${args["out-cert"]}`);
118+
}
122119

123-
if (args["out-key"] && result.privateKey) {
124-
writeFileSync(args["out-key"], result.privateKey, { mode: 0o600 });
125-
console.log(`Private key written to ${args["out-key"]}`);
126-
}
127-
} else {
128-
// Print PEM to stdout
129-
console.log(result.certificate.certificate_pem);
130-
if (result.privateKey) {
131-
console.log(result.privateKey);
120+
if (args["out-key"] && result.privateKey) {
121+
writeFileSync(args["out-key"], result.privateKey, { mode: 0o600 });
122+
console.log(`Private key written to ${args["out-key"]}`);
123+
}
124+
125+
// Output result (unless files were written)
126+
if (!args["out-cert"] && !args["out-key"]) {
127+
if (args.json) {
128+
output(result, { json: true });
129+
} else {
130+
// Output formatted key-value pairs
131+
output({
132+
id: result.certificate.id,
133+
commonName: result.certificate.common_name,
134+
validFrom: result.certificate.valid_from,
135+
validTo: result.certificate.valid_to,
136+
certificate: result.certificate.certificate_pem,
137+
privateKey: result.privateKey ?? "",
138+
}, { json: false });
132139
}
133140
}
134141
} catch (error) {

src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ export function loadConfigFile(): Config {
2323
}
2424

2525
export function saveConfigFile(config: Config): void {
26-
mkdirSync(dirname(CONFIG_PATH), { recursive: true });
27-
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n");
26+
mkdirSync(dirname(CONFIG_PATH), { recursive: true, mode: 0o700 });
27+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n", {
28+
mode: 0o600,
29+
});
2830
}
2931

3032
export function getApiKey(cliFlag?: string): string | undefined {

tests/unit/commands/cert/issue.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,20 @@ describe("cert issue command", () => {
6262
vi.clearAllMocks();
6363
});
6464

65-
it("prints certificate and key PEM to stdout when no output files specified", async () => {
65+
it("outputs formatted key-value pairs when no output files specified", async () => {
6666
await runCommand(issueCommand, {
6767
rawArgs: ["--ca-id", "ca-123"],
6868
});
6969

70-
expect(consoleSpy).toHaveBeenCalledWith(mockCertificateResult.certificate.certificate_pem);
71-
expect(consoleSpy).toHaveBeenCalledWith(mockCertificateResult.privateKey);
70+
// Verify key-value formatted output
71+
const calls = consoleSpy.mock.calls.map(c => c[0]);
72+
expect(calls.some(c => c.includes("id") && c.includes("cert-123"))).toBe(true);
73+
expect(calls.some(c => c.includes("commonName") && c.includes("test.local"))).toBe(true);
74+
expect(calls.some(c => c.includes("certificate") && c.includes("BEGIN CERTIFICATE"))).toBe(true);
75+
expect(calls.some(c => c.includes("privateKey") && c.includes("BEGIN PRIVATE KEY"))).toBe(true);
7276
});
7377

74-
it("prints only certificate PEM when no private key returned (CSR mode)", async () => {
78+
it("outputs formatted key-value pairs with empty privateKey when no private key returned (CSR mode)", async () => {
7579
mockIssue.mockResolvedValue({
7680
certificate: mockCertificateResult.certificate,
7781
privateKey: undefined,
@@ -81,8 +85,9 @@ describe("cert issue command", () => {
8185
rawArgs: ["--ca-id", "ca-123"],
8286
});
8387

84-
expect(consoleSpy).toHaveBeenCalledWith(mockCertificateResult.certificate.certificate_pem);
85-
expect(consoleSpy).toHaveBeenCalledTimes(1);
88+
const calls = consoleSpy.mock.calls.map(c => c[0]);
89+
expect(calls.some(c => c.includes("id") && c.includes("cert-123"))).toBe(true);
90+
expect(calls.some(c => c.includes("certificate") && c.includes("BEGIN CERTIFICATE"))).toBe(true);
8691
});
8792

8893
it("outputs JSON when --json flag is provided", async () => {

0 commit comments

Comments
 (0)