|
1 | 1 | import { afterAll, expect, test } from "bun:test"; |
2 | | -import { connect, createServer, type Socket } from "node:net"; |
| 2 | +import { connect, createServer, Socket } from "node:net"; |
3 | 3 | import { CLAUDE_INTERCEPT_HOSTS, isLoopbackTarget, parseConnectRequestLine, startConnectProxy, type ConnectProxyHandle } from "../../src/claude/intercept/connect-proxy"; |
4 | 4 | import { startClaudeInterceptListener, rewriteInterceptedRequest } from "../../src/claude/intercept/listener"; |
5 | 5 | import { createLocalInterceptCa, issueLocalInterceptLeaf } from "../../src/claude/intercept/local-ca"; |
@@ -326,12 +326,12 @@ test("isLoopbackTarget covers mapped, unspecified and shorthand loopback literal |
326 | 326 | }); |
327 | 327 |
|
328 | 328 | test("a dead upstream yields 502 instead of a hung tunnel", async () => { |
329 | | - const dead = await startEchoUpstream(); |
330 | | - await dead.close(); |
331 | 329 | const proxy = await startConnectProxy(0, { |
332 | 330 | interceptPort: 1, |
333 | 331 | authToken: AUTH_TOKEN, |
334 | | - dialUpstream: () => connect({ host: "127.0.0.1", port: dead.port }), |
| 332 | + // A closed listener's port can be reassigned, even to this proxy. Fail a real socket |
| 333 | + // asynchronously instead, so this always exercises dial failure before establishment. |
| 334 | + dialUpstream: () => new Socket().destroy(new Error("connect ECONNREFUSED")), |
335 | 335 | }); |
336 | 336 | cleanups.push(proxy.close); |
337 | 337 | expect(await rawRequest(proxy.port, `CONNECT gone.example:443 HTTP/1.1\r\n${AUTH_HEADER}\r\n`)).toStartWith("HTTP/1.1 502"); |
|
0 commit comments