feat(PortProxy): Add feature to preserve original client IP through chained proxies

This commit is contained in:
2025-02-21 19:39:52 +00:00
parent 8cb8fa1a52
commit c77b31b72c
4 changed files with 40 additions and 1 deletions

View File

@ -175,6 +175,37 @@ tap.test('should stop port proxy', async () => {
});
// Cleanup
tap.test('should preserve client IP through chained proxies', async () => {
// Create two proxies in chain
const firstProxy = new PortProxy({
fromPort: PROXY_PORT + 4,
toPort: PROXY_PORT + 5, // Point to second proxy
toHost: 'localhost',
domains: [],
sniEnabled: false,
defaultAllowedIPs: ['127.0.0.1']
});
const secondProxy = new PortProxy({
fromPort: PROXY_PORT + 5,
toPort: TEST_SERVER_PORT,
toHost: 'localhost',
domains: [],
sniEnabled: false,
defaultAllowedIPs: ['127.0.0.1']
});
await secondProxy.start();
await firstProxy.start();
// Connect through the chain
const response = await createTestClient(PROXY_PORT + 4, TEST_DATA);
expect(response).toEqual(`Echo: ${TEST_DATA}`);
await firstProxy.stop();
await secondProxy.stop();
});
tap.test('cleanup port proxy test environment', async () => {
await new Promise<void>((resolve) => testServer.close(() => resolve()));
});