From 1b4d215cd4263651553a4d17fe33c6649819fafa Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 19 May 2025 17:59:12 +0000 Subject: [PATCH] fix(tests): test --- changelog.md | 12 +++++++++ test/test.nftables-forwarding.ts | 2 +- test/test.port-forwarding-fix.ts | 43 +++++++++++++++++++++----------- ts/00_commitinfo_data.ts | 2 +- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index 2f72c18..06854b8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,17 @@ # Changelog +## 2025-05-19 - 19.3.6 - fix(tests) +Fix route configuration property names in tests: replace 'acceptedRoutes' with 'routes' in nftables tests and update 'match: { port: ... }' to 'match: { ports: ... }' in port forwarding tests. + +- Renamed 'acceptedRoutes' to 'routes' in test/nftables-forwarding.ts for alignment with the current SmartProxy API. +- Changed port matching in test/port-forwarding-fix.ts from 'match: { port: ... }' to 'match: { ports: ... }' for consistency. + +## 2025-05-19 - 19.3.6 - fix(tests) +Update test route config properties: replace 'acceptedRoutes' with 'routes' in nftables tests and change 'match: { port: ... }' to 'match: { ports: ... }' in port forwarding tests + +- In test/nftables-forwarding.ts, renamed property 'acceptedRoutes' to 'routes' to align with current SmartProxy API. +- In test/port-forwarding-fix.ts, updated 'match: { port: 9999 }' to 'match: { ports: 9999 }' for consistency. + ## 2025-05-19 - 19.3.5 - fix(smartproxy) Correct NFTables forwarding handling to avoid premature connection termination and add comprehensive tests diff --git a/test/test.nftables-forwarding.ts b/test/test.nftables-forwarding.ts index 7e1284a..4d3c96e 100644 --- a/test/test.nftables-forwarding.ts +++ b/test/test.nftables-forwarding.ts @@ -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', diff --git a/test/test.port-forwarding-fix.ts b/test/test.port-forwarding-fix.ts index c67e210..235e631 100644 --- a/test/test.port-forwarding-fix.ts +++ b/test/test.port-forwarding-fix.ts @@ -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((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((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(); \ No newline at end of file diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 7078345..4266701 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartproxy', - version: '19.3.5', + version: '19.3.6', description: 'A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.' }