73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
|
import { expect, tap } from '@git.zone/tapbundle';
|
||
|
import * as net from 'net';
|
||
|
import { SmartProxy } from '../ts/proxies/smart-proxy/smart-proxy.js';
|
||
|
|
||
|
tap.test('Port forwarding should not immediately close connections', async () => {
|
||
|
// Create an echo server
|
||
|
const echoServer = net.createServer((socket) => {
|
||
|
socket.on('data', (data) => {
|
||
|
socket.write(`ECHO: ${data}`);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
await new Promise<void>((resolve) => {
|
||
|
echoServer.listen(8888, () => resolve());
|
||
|
});
|
||
|
|
||
|
// Create proxy with forwarding route
|
||
|
const proxy = new SmartProxy({
|
||
|
routes: [{
|
||
|
id: 'test',
|
||
|
match: { port: 9999 },
|
||
|
action: {
|
||
|
type: 'forward',
|
||
|
target: { host: 'localhost', port: 8888 }
|
||
|
}
|
||
|
}]
|
||
|
});
|
||
|
|
||
|
await proxy.start();
|
||
|
|
||
|
// Test connection through proxy
|
||
|
const client = net.createConnection(9999, 'localhost');
|
||
|
|
||
|
const result = await new Promise<string>((resolve, reject) => {
|
||
|
client.on('data', (data) => {
|
||
|
resolve(data.toString());
|
||
|
});
|
||
|
|
||
|
client.on('error', reject);
|
||
|
|
||
|
client.write('Hello');
|
||
|
});
|
||
|
|
||
|
expect(result).toEqual('ECHO: Hello');
|
||
|
|
||
|
client.end();
|
||
|
await proxy.stop();
|
||
|
echoServer.close();
|
||
|
});
|
||
|
|
||
|
tap.test('TLS passthrough should work correctly', async () => {
|
||
|
// Create proxy with TLS passthrough
|
||
|
const proxy = new SmartProxy({
|
||
|
routes: [{
|
||
|
id: 'tls-test',
|
||
|
match: { port: 8443, domain: 'test.example.com' },
|
||
|
action: {
|
||
|
type: 'forward',
|
||
|
tls: { mode: 'passthrough' },
|
||
|
target: { host: 'localhost', port: 443 }
|
||
|
}
|
||
|
}]
|
||
|
});
|
||
|
|
||
|
await proxy.start();
|
||
|
|
||
|
// For now just verify the proxy starts correctly with TLS passthrough route
|
||
|
expect(proxy).toBeDefined();
|
||
|
|
||
|
await proxy.stop();
|
||
|
});
|
||
|
|
||
|
export default tap.start();
|