fix(tests): use high non-privileged ports in tests to avoid conflicts and CI failures
This commit is contained in:
@@ -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<void>((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<void>((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' +
|
||||
|
||||
@@ -24,8 +24,8 @@ tap.test('setup test servers', async () => {
|
||||
});
|
||||
|
||||
await new Promise<void>((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<void>((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<net.Socket>((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<tls.TLSSocket>((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<tls.TLSSocket>((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<tls.TLSSocket>((resolve, reject) => {
|
||||
const socket = tls.connect(
|
||||
{
|
||||
port: 8443,
|
||||
port: 47711,
|
||||
host: '127.0.0.1',
|
||||
servername: 'b.example.com',
|
||||
rejectUnauthorized: false,
|
||||
|
||||
@@ -21,8 +21,8 @@ tap.test('forward connections should not be immediately closed', async (t) => {
|
||||
|
||||
// Listen on a non-privileged port
|
||||
await new Promise<void>((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',
|
||||
});
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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<string> {
|
||||
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}`);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<void>((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<void>((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<void>((resolve, reject) => {
|
||||
client.connect(9999, 'localhost', () => {
|
||||
client.connect(47780, 'localhost', () => {
|
||||
// Connection established - send data to trigger handler
|
||||
client.write('trigger\n');
|
||||
resolve();
|
||||
|
||||
Reference in New Issue
Block a user