|
| 1 | +// Proxy CA installer tests keep macOS trust changes behind explicit CLI args. |
| 2 | +import { existsSync } from "node:fs"; |
| 3 | +import { join } from "node:path"; |
| 4 | +import { spawnSync } from "node:child_process"; |
| 5 | +import { afterEach, describe, expect, it } from "vitest"; |
| 6 | +import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js"; |
| 7 | + |
| 8 | +const SCRIPT = "scripts/proxy-install-ca.mjs"; |
| 9 | +const tempDirs = new Set<string>(); |
| 10 | + |
| 11 | +afterEach(() => { |
| 12 | +cleanupTempDirs(tempDirs); |
| 13 | +}); |
| 14 | + |
| 15 | +function runProxyInstallCa(args: string[], certDir: string) { |
| 16 | +return spawnSync(process.execPath, ["--import", "tsx", SCRIPT, ...args], { |
| 17 | +cwd: process.cwd(), |
| 18 | +encoding: "utf8", |
| 19 | +env: { |
| 20 | + ...process.env, |
| 21 | +OPENCLAW_DEBUG_PROXY_CERT_DIR: certDir, |
| 22 | +}, |
| 23 | +}); |
| 24 | +} |
| 25 | + |
| 26 | +describe("scripts/proxy-install-ca.mjs", () => { |
| 27 | +it("rejects unknown arguments before creating the debug proxy CA", () => { |
| 28 | +const root = makeTempDir(tempDirs, "openclaw-proxy-install-ca-"); |
| 29 | +const certDir = join(root, "certs"); |
| 30 | +const result = runProxyInstallCa(["--print-onli"], certDir); |
| 31 | + |
| 32 | +expect(result.status).toBe(1); |
| 33 | +expect(result.stderr).toContain("Unknown proxy install CA argument: --print-onli"); |
| 34 | +expect(result.stderr).toContain( |
| 35 | +"Usage: node --import tsx scripts/proxy-install-ca.mjs [--print-only]", |
| 36 | +); |
| 37 | +expect(result.stdout).toBe(""); |
| 38 | +expect(existsSync(certDir)).toBe(false); |
| 39 | +}); |
| 40 | + |
| 41 | +it("prints usage without creating the debug proxy CA", () => { |
| 42 | +const root = makeTempDir(tempDirs, "openclaw-proxy-install-ca-"); |
| 43 | +const certDir = join(root, "certs"); |
| 44 | +const result = runProxyInstallCa(["--help"], certDir); |
| 45 | + |
| 46 | +expect(result.status).toBe(0); |
| 47 | +expect(result.stdout).toContain( |
| 48 | +"Usage: node --import tsx scripts/proxy-install-ca.mjs [--print-only]", |
| 49 | +); |
| 50 | +expect(result.stderr).toBe(""); |
| 51 | +expect(existsSync(certDir)).toBe(false); |
| 52 | +}); |
| 53 | +}); |