|
1 | | -import { rm } from "node:fs/promises"; |
| 1 | +import { mkdtemp, rm } from "node:fs/promises"; |
2 | 2 | import { Socket } from "node:net"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { join } from "node:path"; |
3 | 5 | import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
4 | 6 | import { assertDebugProxyDirectConnectAllowed, startDebugProxyServer } from "./proxy-server.js"; |
5 | 7 |
|
6 | | -const testBlobDir = ".tmp-debug-proxy-test-blobs"; |
7 | | -const testCertDir = ".tmp-debug-proxy-test-certs"; |
| 8 | +let testRoot: string | undefined; |
8 | 9 |
|
9 | 10 | async function cleanupTestDirs(): Promise<void> { |
10 | | - await Promise.all([ |
11 | | - rm(testBlobDir, { recursive: true, force: true }), |
12 | | - rm(testCertDir, { recursive: true, force: true }), |
13 | | - ]); |
| 11 | + if (!testRoot) { |
| 12 | + return; |
| 13 | + } |
| 14 | + const root = testRoot; |
| 15 | + testRoot = undefined; |
| 16 | + await rm(root, { recursive: true, force: true }); |
14 | 17 | } |
15 | 18 |
|
16 | | -function makeSettings() { |
| 19 | +async function makeSettings() { |
| 20 | + testRoot = await mkdtemp(join(tmpdir(), "openclaw-debug-proxy-managed-proxy-")); |
17 | 21 | return { |
18 | 22 | enabled: true, |
19 | 23 | required: false, |
20 | 24 | dbPath: ":memory:", |
21 | | - blobDir: testBlobDir, |
22 | | - certDir: testCertDir, |
| 25 | + blobDir: join(testRoot, "blobs"), |
| 26 | + certDir: join(testRoot, "certs"), |
23 | 27 | sessionId: "debug-proxy-managed-proxy-test", |
24 | 28 | sourceProcess: "test", |
25 | 29 | }; |
@@ -90,7 +94,7 @@ describe("debug proxy managed-proxy CONNECT policy", () => { |
90 | 94 |
|
91 | 95 | it("rejects CONNECT upstreams before opening direct sockets while managed proxy mode is active", async () => { |
92 | 96 | process.env["OPENCLAW_PROXY_ACTIVE"] = "1"; |
93 | | - const server = await startDebugProxyServer({ settings: makeSettings() }); |
| 97 | + const server = await startDebugProxyServer({ settings: await makeSettings() }); |
94 | 98 | try { |
95 | 99 | const response = await connectThroughProxy(server.proxyUrl); |
96 | 100 |
|
|
0 commit comments