fix(tests): test

This commit is contained in:
2025-05-19 17:59:12 +00:00
parent 70448af5b4
commit 1b4d215cd4
4 changed files with 42 additions and 17 deletions

View File

@ -24,7 +24,7 @@ tap.test('NFTables forwarding should not terminate connections', async () => {
// Create SmartProxy with NFTables route
const smartProxy = new SmartProxy({
enableDetailedLogging: true,
acceptedRoutes: [
routes: [
{
id: 'nftables-test',
name: 'NFTables Test Route',

View File

@ -1,24 +1,30 @@
import { expect, tap } from '@git.zone/tapbundle';
import { expect, tap } from '@git.zone/tstest/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 () => {
let echoServer: net.Server;
let proxy: SmartProxy;
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}`);
echoServer = await new Promise<net.Server>((resolve) => {
const server = net.createServer((socket) => {
socket.on('data', (data) => {
socket.write(`ECHO: ${data}`);
});
});
server.listen(8888, () => {
console.log('Echo server listening on port 8888');
resolve(server);
});
});
await new Promise<void>((resolve) => {
echoServer.listen(8888, () => resolve());
});
// Create proxy with forwarding route
const proxy = new SmartProxy({
proxy = new SmartProxy({
routes: [{
id: 'test',
match: { port: 9999 },
match: { ports: 9999 },
action: {
type: 'forward',
target: { host: 'localhost', port: 8888 }
@ -44,16 +50,14 @@ tap.test('Port forwarding should not immediately close connections', async () =>
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({
proxy = new SmartProxy({
routes: [{
id: 'tls-test',
match: { port: 8443, domain: 'test.example.com' },
match: { ports: 8443, domains: 'test.example.com' },
action: {
type: 'forward',
tls: { mode: 'passthrough' },
@ -70,4 +74,13 @@ tap.test('TLS passthrough should work correctly', async () => {
await proxy.stop();
});
tap.test('cleanup', async () => {
if (echoServer) {
echoServer.close();
}
if (proxy) {
await proxy.stop();
}
});
export default tap.start();