mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 12:16:46 +00:00
test(cliproxy): stabilize tunnel localhost binding check
This commit is contained in:
@@ -116,17 +116,18 @@ describe('HttpsTunnelProxy', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const port = await tunnel.start();
|
const port = await tunnel.start();
|
||||||
|
const net = await import('net');
|
||||||
|
const socket = new net.Socket();
|
||||||
|
|
||||||
// Try to connect - should work on localhost
|
await new Promise<void>((resolve, reject) => {
|
||||||
const response = await new Promise<http.IncomingMessage>((resolve, reject) => {
|
socket.once('error', reject);
|
||||||
const req = http.get(`http://127.0.0.1:${port}/test`, resolve);
|
socket.connect(port, '127.0.0.1', () => {
|
||||||
req.on('error', reject);
|
socket.end();
|
||||||
req.setTimeout(1000);
|
resolve();
|
||||||
}).catch((err) => err);
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// We expect an error because there's no upstream, but connection should be accepted
|
expect(tunnel.getPort()).toBe(port);
|
||||||
// If binding failed, we'd get ECONNREFUSED before any response
|
|
||||||
expect(response).toBeDefined();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user