diff --git a/changelog.md b/changelog.md index 54c8c9b..30e74a5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2026-02-21 - 25.7.9 - fix(tests) +use high non-privileged ports in tests to avoid conflicts and CI failures + +- Updated multiple test files to use high-range, non-privileged ports instead of well-known or conflicting ports. +- Files changed: test/test.acme-http01-challenge.ts, test/test.connection-forwarding.ts, test/test.forwarding-regression.ts, test/test.http-port8080-forwarding.ts, test/test.port-mapping.ts, test/test.smartproxy.ts, test/test.socket-handler.ts. +- Notable port remappings: 8080/8081 -> 47730/47731 (and other proxy ports like 47710), 8443 -> 47711, 7001/7002 -> 47712/47713, 9090 -> 47721, 8181/8182 -> 47732/47733, 9999 -> 47780, TEST_PORT_START/PROXY_PORT_START -> 47750/48750, and TEST_SERVER_PORT/PROXY_PORT -> 47770/47771. + ## 2026-02-19 - 25.7.8 - fix(no-changes) no changes detected; nothing to release diff --git a/test/test.acme-http01-challenge.ts b/test/test.acme-http01-challenge.ts index a70a256..94fa897 100644 --- a/test/test.acme-http01-challenge.ts +++ b/test/test.acme-http01-challenge.ts @@ -37,7 +37,7 @@ tap.test('should correctly handle HTTP-01 challenge requests with initial data c routes: [{ name: 'acme-challenge-route', match: { - ports: 8080, + ports: 47700, path: '/.well-known/acme-challenge/*' }, action: { @@ -60,7 +60,7 @@ tap.test('should correctly handle HTTP-01 challenge requests with initial data c // Connect to the proxy and send the HTTP-01 challenge request await new Promise((resolve, reject) => { - testClient.connect(8080, 'localhost', () => { + testClient.connect(47700, 'localhost', () => { // Send HTTP request for the challenge token testClient.write( `GET ${challengePath} HTTP/1.1\r\n` + @@ -113,7 +113,7 @@ tap.test('should return 404 for non-existent challenge tokens', async (tapTest) routes: [{ name: 'acme-challenge-route', match: { - ports: 8081, + ports: 47701, path: '/.well-known/acme-challenge/*' }, action: { @@ -135,7 +135,7 @@ tap.test('should return 404 for non-existent challenge tokens', async (tapTest) // Connect and send a request for a non-existent token await new Promise((resolve, reject) => { - testClient.connect(8081, 'localhost', () => { + testClient.connect(47701, 'localhost', () => { testClient.write( 'GET /.well-known/acme-challenge/invalid-token HTTP/1.1\r\n' + 'Host: test.example.com\r\n' + diff --git a/test/test.connection-forwarding.ts b/test/test.connection-forwarding.ts index d29b84d..c56bce5 100644 --- a/test/test.connection-forwarding.ts +++ b/test/test.connection-forwarding.ts @@ -24,8 +24,8 @@ tap.test('setup test servers', async () => { }); await new Promise((resolve) => { - testServer.listen(7001, '127.0.0.1', () => { - console.log('TCP test server listening on port 7001'); + testServer.listen(47712, '127.0.0.1', () => { + console.log('TCP test server listening on port 47712'); resolve(); }); }); @@ -45,8 +45,8 @@ tap.test('setup test servers', async () => { ); await new Promise((resolve) => { - tlsTestServer.listen(7002, '127.0.0.1', () => { - console.log('TLS test server listening on port 7002'); + tlsTestServer.listen(47713, '127.0.0.1', () => { + console.log('TLS test server listening on port 47713'); resolve(); }); }); @@ -60,13 +60,13 @@ tap.test('should forward TCP connections correctly', async () => { { name: 'tcp-forward', match: { - ports: 8080, + ports: 47710, }, action: { type: 'forward', targets: [{ host: '127.0.0.1', - port: 7001, + port: 47712, }], }, }, @@ -77,7 +77,7 @@ tap.test('should forward TCP connections correctly', async () => { // Test TCP forwarding const client = await new Promise((resolve, reject) => { - const socket = net.connect(8080, '127.0.0.1', () => { + const socket = net.connect(47710, '127.0.0.1', () => { console.log('Connected to proxy'); resolve(socket); }); @@ -106,7 +106,7 @@ tap.test('should handle TLS passthrough correctly', async () => { { name: 'tls-passthrough', match: { - ports: 8443, + ports: 47711, domains: 'test.example.com', }, action: { @@ -116,7 +116,7 @@ tap.test('should handle TLS passthrough correctly', async () => { }, targets: [{ host: '127.0.0.1', - port: 7002, + port: 47713, }], }, }, @@ -129,7 +129,7 @@ tap.test('should handle TLS passthrough correctly', async () => { const client = await new Promise((resolve, reject) => { const socket = tls.connect( { - port: 8443, + port: 47711, host: '127.0.0.1', servername: 'test.example.com', rejectUnauthorized: false, @@ -164,7 +164,7 @@ tap.test('should handle SNI-based forwarding', async () => { { name: 'domain-a', match: { - ports: 8443, + ports: 47711, domains: 'a.example.com', }, action: { @@ -174,14 +174,14 @@ tap.test('should handle SNI-based forwarding', async () => { }, targets: [{ host: '127.0.0.1', - port: 7002, + port: 47713, }], }, }, { name: 'domain-b', match: { - ports: 8443, + ports: 47711, domains: 'b.example.com', }, action: { @@ -191,7 +191,7 @@ tap.test('should handle SNI-based forwarding', async () => { }, targets: [{ host: '127.0.0.1', - port: 7002, + port: 47713, }], }, }, @@ -204,7 +204,7 @@ tap.test('should handle SNI-based forwarding', async () => { const clientA = await new Promise((resolve, reject) => { const socket = tls.connect( { - port: 8443, + port: 47711, host: '127.0.0.1', servername: 'a.example.com', rejectUnauthorized: false, @@ -231,7 +231,7 @@ tap.test('should handle SNI-based forwarding', async () => { const clientB = await new Promise((resolve, reject) => { const socket = tls.connect( { - port: 8443, + port: 47711, host: '127.0.0.1', servername: 'b.example.com', rejectUnauthorized: false, diff --git a/test/test.forwarding-regression.ts b/test/test.forwarding-regression.ts index 4e5ea8e..5556c1b 100644 --- a/test/test.forwarding-regression.ts +++ b/test/test.forwarding-regression.ts @@ -21,8 +21,8 @@ tap.test('forward connections should not be immediately closed', async (t) => { // Listen on a non-privileged port await new Promise((resolve) => { - testServer.listen(9090, '127.0.0.1', () => { - console.log('Test server listening on port 9090'); + testServer.listen(47721, '127.0.0.1', () => { + console.log('Test server listening on port 47721'); resolve(); }); }); @@ -34,13 +34,13 @@ tap.test('forward connections should not be immediately closed', async (t) => { { name: 'forward-test', match: { - ports: 8080, + ports: 47720, }, action: { type: 'forward', targets: [{ host: '127.0.0.1', - port: 9090, + port: 47721, }], }, }, @@ -51,7 +51,7 @@ tap.test('forward connections should not be immediately closed', async (t) => { // Create a client connection through the proxy const client = net.createConnection({ - port: 8080, + port: 47720, host: '127.0.0.1', }); diff --git a/test/test.http-port8080-forwarding.ts b/test/test.http-port8080-forwarding.ts index 8116e2b..c6ae61b 100644 --- a/test/test.http-port8080-forwarding.ts +++ b/test/test.http-port8080-forwarding.ts @@ -4,7 +4,7 @@ import * as http from 'http'; tap.test('should forward HTTP connections on port 8080', async (tapTest) => { // Create a mock HTTP server to act as our target - const targetPort = 8181; + const targetPort = 47732; let receivedRequest = false; let receivedPath = ''; @@ -36,7 +36,7 @@ tap.test('should forward HTTP connections on port 8080', async (tapTest) => { routes: [{ name: 'test-route', match: { - ports: 8080 + ports: 47730 // Remove domain restriction for HTTP connections // Domain matching happens after HTTP headers are received }, @@ -55,7 +55,7 @@ tap.test('should forward HTTP connections on port 8080', async (tapTest) => { // Make an HTTP request to port 8080 const options = { hostname: 'localhost', - port: 8080, + port: 47730, path: '/.well-known/acme-challenge/test-token', method: 'GET', headers: { @@ -104,7 +104,7 @@ tap.test('should forward HTTP connections on port 8080', async (tapTest) => { tap.test('should handle basic HTTP request forwarding', async (tapTest) => { // Create a simple target server - const targetPort = 8182; + const targetPort = 47733; let receivedRequest = false; const targetServer = http.createServer((req, res) => { @@ -126,7 +126,7 @@ tap.test('should handle basic HTTP request forwarding', async (tapTest) => { routes: [{ name: 'simple-forward', match: { - ports: 8081 + ports: 47731 // Remove domain restriction for HTTP connections }, action: { @@ -142,7 +142,7 @@ tap.test('should handle basic HTTP request forwarding', async (tapTest) => { // Make request const options = { hostname: 'localhost', - port: 8081, + port: 47731, path: '/test', method: 'GET', headers: { diff --git a/test/test.port-mapping.ts b/test/test.port-mapping.ts index 5ecd748..07d7a94 100644 --- a/test/test.port-mapping.ts +++ b/test/test.port-mapping.ts @@ -14,8 +14,8 @@ import type { IRouteConfig, IRouteContext } from '../ts/proxies/smart-proxy/mode let testServers: Array<{ server: net.Server; port: number }> = []; let smartProxy: SmartProxy; -const TEST_PORT_START = 4000; -const PROXY_PORT_START = 5000; +const TEST_PORT_START = 47750; +const PROXY_PORT_START = 48750; const TEST_DATA = 'Hello through dynamic port mapper!'; // Cleanup function to close all servers and proxies @@ -103,9 +103,9 @@ function createTestClient(port: number, data: string): Promise { tap.test('setup port mapping test environment', async () => { // Create multiple test servers on different ports await Promise.all([ - createTestServer(TEST_PORT_START), // Server on port 4000 - createTestServer(TEST_PORT_START + 1), // Server on port 4001 - createTestServer(TEST_PORT_START + 2), // Server on port 4002 + createTestServer(TEST_PORT_START), // Server on port 47750 + createTestServer(TEST_PORT_START + 1), // Server on port 47751 + createTestServer(TEST_PORT_START + 2), // Server on port 47752 ]); // Create a SmartProxy with dynamic port mapping routes @@ -119,7 +119,7 @@ tap.test('setup port mapping test environment', async () => { name: 'Identity Port Mapping' }), - // Offset port mapping from 5001 to 4001 (offset -1000) + // Offset port mapping from 48751 to 47751 (offset -1000) createOffsetPortMappingRoute({ ports: PROXY_PORT_START + 1, targetHost: 'localhost', @@ -170,13 +170,13 @@ tap.test('setup port mapping test environment', async () => { await smartProxy.start(); }); -// Test 1: Simple identity port mapping (5000 -> 4000) +// Test 1: Simple identity port mapping (48750 -> 47750) tap.test('should map port using identity function', async () => { const response = await createTestClient(PROXY_PORT_START, TEST_DATA); expect(response).toEqual(`Server ${TEST_PORT_START} says: ${TEST_DATA}`); }); -// Test 2: Offset port mapping (5001 -> 4001) +// Test 2: Offset port mapping (48751 -> 47751) tap.test('should map port using offset function', async () => { const response = await createTestClient(PROXY_PORT_START + 1, TEST_DATA); expect(response).toEqual(`Server ${TEST_PORT_START + 1} says: ${TEST_DATA}`); diff --git a/test/test.smartproxy.ts b/test/test.smartproxy.ts index 02f0ff9..17ae3d2 100644 --- a/test/test.smartproxy.ts +++ b/test/test.smartproxy.ts @@ -4,8 +4,8 @@ import { SmartProxy } from '../ts/proxies/smart-proxy/index.js'; let testServer: net.Server; let smartProxy: SmartProxy; -const TEST_SERVER_PORT = 4000; -const PROXY_PORT = 4001; +const TEST_SERVER_PORT = 47770; +const PROXY_PORT = 47771; const TEST_DATA = 'Hello through port proxy!'; // Track all created servers and proxies for proper cleanup diff --git a/test/test.socket-handler.ts b/test/test.socket-handler.ts index 4041d25..45d59ce 100644 --- a/test/test.socket-handler.ts +++ b/test/test.socket-handler.ts @@ -10,7 +10,7 @@ tap.test('setup socket handler test', async () => { const routes: IRouteConfig[] = [{ name: 'echo-handler', match: { - ports: 9999 + ports: 47780 // No domains restriction - matches all connections }, action: { @@ -43,7 +43,7 @@ tap.test('should handle socket with custom function', async () => { let response = ''; await new Promise((resolve, reject) => { - client.connect(9999, 'localhost', () => { + client.connect(47780, 'localhost', () => { console.log('Client connected to proxy'); resolve(); }); @@ -78,7 +78,7 @@ tap.test('should handle async socket handler', async () => { // Update route with async handler await proxy.updateRoutes([{ name: 'async-handler', - match: { ports: 9999 }, + match: { ports: 47780 }, action: { type: 'socket-handler', socketHandler: async (socket, context) => { @@ -108,7 +108,7 @@ tap.test('should handle async socket handler', async () => { }); await new Promise((resolve, reject) => { - client.connect(9999, 'localhost', () => { + client.connect(47780, 'localhost', () => { // Send initial data to trigger the handler client.write('test data\n'); resolve(); @@ -131,7 +131,7 @@ tap.test('should handle errors in socket handler', async () => { // Update route with error-throwing handler await proxy.updateRoutes([{ name: 'error-handler', - match: { ports: 9999 }, + match: { ports: 47780 }, action: { type: 'socket-handler', socketHandler: (socket, context) => { @@ -148,7 +148,7 @@ tap.test('should handle errors in socket handler', async () => { }); await new Promise((resolve, reject) => { - client.connect(9999, 'localhost', () => { + client.connect(47780, 'localhost', () => { // Connection established - send data to trigger handler client.write('trigger\n'); resolve(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 863e618..ca4c79e 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: '25.7.8', + version: '25.7.9', 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.' }