This commit is contained in:
2025-05-29 12:54:31 +00:00
parent ab1ea95070
commit 30ff3b7d8a
7 changed files with 36 additions and 180 deletions

View File

@ -10,11 +10,11 @@ tap.test('should detect and forward non-TLS connections on HttpProxy ports', asy
// Create a SmartProxy instance first
const proxy = new SmartProxy({
useHttpProxy: [8080],
httpProxyPort: 8844,
useHttpProxy: [8081], // Use different port to avoid conflicts
httpProxyPort: 8847, // Use different port to avoid conflicts
routes: [{
name: 'test-http-forward',
match: { ports: 8080 },
match: { ports: 8081 },
action: {
type: 'forward',
target: { host: 'localhost', port: 8181 }
@ -47,8 +47,8 @@ tap.test('should detect and forward non-TLS connections on HttpProxy ports', asy
const client = new net.Socket();
await new Promise<void>((resolve, reject) => {
client.connect(8080, 'localhost', () => {
console.log('Client connected to proxy on port 8080');
client.connect(8081, 'localhost', () => {
console.log('Client connected to proxy on port 8081');
// Send a non-TLS HTTP request
client.write('GET / HTTP/1.1\r\nHost: test.local\r\n\r\n');
resolve();
@ -67,7 +67,9 @@ tap.test('should detect and forward non-TLS connections on HttpProxy ports', asy
client.destroy();
await proxy.stop();
// Restore original method
// Wait a bit to ensure port is released
await new Promise(resolve => setTimeout(resolve, 100));
// Restore original method
(proxy as any).httpProxyBridge.forwardToHttpProxy = originalForward;
});
@ -94,12 +96,12 @@ tap.test('should properly detect non-TLS connections on HttpProxy ports', async
let httpProxyForwardCalled = false;
const proxy = new SmartProxy({
useHttpProxy: [8080],
httpProxyPort: 8844,
useHttpProxy: [8082], // Use different port to avoid conflicts
httpProxyPort: 8848, // Use different port to avoid conflicts
routes: [{
name: 'test-route',
match: {
ports: 8080
ports: 8082
},
action: {
type: 'forward',
@ -126,7 +128,7 @@ tap.test('should properly detect non-TLS connections on HttpProxy ports', async
const client = new net.Socket();
await new Promise<void>((resolve, reject) => {
client.connect(8080, 'localhost', () => {
client.connect(8082, 'localhost', () => {
console.log('Connected to proxy');
client.write('GET / HTTP/1.1\r\nHost: test.local\r\n\r\n');
resolve();
@ -147,8 +149,11 @@ tap.test('should properly detect non-TLS connections on HttpProxy ports', async
targetServer.close(() => resolve());
});
// Wait a bit to ensure port is released
await new Promise(resolve => setTimeout(resolve, 100));
// Restore original method
proxy['httpProxyBridge'].forwardToHttpProxy = originalForward;
});
tap.start();
export default tap.start();