From c7c325a7d8b585930fdecd2199d6a4ad8c1fea0f Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 1 Jun 2025 07:06:11 +0000 Subject: [PATCH] fix(tests): update AcmeStateManager tests to use socket-handler for challenge routes fix(tests): enhance non-TLS connection detection with range support in HttpProxy tests --- test/test.acme-state-manager.node.ts | 21 ++++++++++++--------- test/test.http-fix-verification.ts | 22 ++++++++++++++++++++-- test/test.http-forwarding-fix.ts | 7 +------ 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/test/test.acme-state-manager.node.ts b/test/test.acme-state-manager.node.ts index 1e433b1..d0969c8 100644 --- a/test/test.acme-state-manager.node.ts +++ b/test/test.acme-state-manager.node.ts @@ -13,8 +13,11 @@ tap.test('AcmeStateManager should track challenge routes correctly', async (tool path: '/.well-known/acme-challenge/*' }, action: { - type: 'static', - handler: async () => ({ status: 200, body: 'challenge' }) + type: 'socket-handler', + socketHandler: async (socket, context) => { + // Mock handler that would write the challenge response + socket.end('challenge response'); + } } }; @@ -46,7 +49,7 @@ tap.test('AcmeStateManager should track port allocations', async (tools) => { path: '/.well-known/acme-challenge/*' }, action: { - type: 'static' + type: 'socket-handler' } }; @@ -58,7 +61,7 @@ tap.test('AcmeStateManager should track port allocations', async (tools) => { path: '/.well-known/acme-challenge/*' }, action: { - type: 'static' + type: 'socket-handler' } }; @@ -97,7 +100,7 @@ tap.test('AcmeStateManager should select primary route by priority', async (tool ports: 80 }, action: { - type: 'static' + type: 'socket-handler' } }; @@ -108,7 +111,7 @@ tap.test('AcmeStateManager should select primary route by priority', async (tool ports: 80 }, action: { - type: 'static' + type: 'socket-handler' } }; @@ -119,7 +122,7 @@ tap.test('AcmeStateManager should select primary route by priority', async (tool ports: 80 }, action: { - type: 'static' + type: 'socket-handler' } }; @@ -149,7 +152,7 @@ tap.test('AcmeStateManager should handle clear operation', async (tools) => { ports: [80, 443] }, action: { - type: 'static' + type: 'socket-handler' } }; @@ -159,7 +162,7 @@ tap.test('AcmeStateManager should handle clear operation', async (tools) => { ports: 8080 }, action: { - type: 'static' + type: 'socket-handler' } }; diff --git a/test/test.http-fix-verification.ts b/test/test.http-fix-verification.ts index 2fe4738..65dd7ef 100644 --- a/test/test.http-fix-verification.ts +++ b/test/test.http-fix-verification.ts @@ -57,7 +57,14 @@ tap.test('should detect and forward non-TLS connections on useHttpProxy ports', getAllRoutes: () => mockSettings.routes, getRoutesForPort: (port: number) => mockSettings.routes.filter(r => { const ports = Array.isArray(r.match.ports) ? r.match.ports : [r.match.ports]; - return ports.includes(port); + return ports.some(p => { + if (typeof p === 'number') { + return p === port; + } else if (p && typeof p === 'object' && 'from' in p && 'to' in p) { + return port >= p.from && port <= p.to; + } + return false; + }); }) }; @@ -101,6 +108,8 @@ tap.test('should detect and forward non-TLS connections on useHttpProxy ports', resume: () => {}, removeListener: function() { return this; }, emit: () => {}, + setNoDelay: () => {}, + setKeepAlive: () => {}, _dataHandler: null as any } as any; @@ -176,7 +185,14 @@ tap.test('should handle TLS connections normally', async (tapTest) => { getAllRoutes: () => mockSettings.routes, getRoutesForPort: (port: number) => mockSettings.routes.filter(r => { const ports = Array.isArray(r.match.ports) ? r.match.ports : [r.match.ports]; - return ports.includes(port); + return ports.some(p => { + if (typeof p === 'number') { + return p === port; + } else if (p && typeof p === 'object' && 'from' in p && 'to' in p) { + return port >= p.from && port <= p.to; + } + return false; + }); }) }; @@ -211,6 +227,8 @@ tap.test('should handle TLS connections normally', async (tapTest) => { resume: () => {}, removeListener: function() { return this; }, emit: () => {}, + setNoDelay: () => {}, + setKeepAlive: () => {}, _dataHandler: null as any } as any; diff --git a/test/test.http-forwarding-fix.ts b/test/test.http-forwarding-fix.ts index 83b106e..1c024df 100644 --- a/test/test.http-forwarding-fix.ts +++ b/test/test.http-forwarding-fix.ts @@ -26,7 +26,6 @@ tap.test('should detect and forward non-TLS connections on HttpProxy ports', asy proxy.settings.enableDetailedLogging = true; // Override the HttpProxy initialization to avoid actual HttpProxy setup - const mockHttpProxy = { available: true }; proxy['httpProxyBridge'].initialize = async () => { console.log('Mock: HttpProxyBridge initialized'); }; @@ -49,11 +48,7 @@ tap.test('should detect and forward non-TLS connections on HttpProxy ports', asy args[1].end(); // socket.end() }; - const originalGetHttpProxy = proxy['httpProxyBridge'].getHttpProxy; - proxy['httpProxyBridge'].getHttpProxy = () => { - console.log('Mock: getHttpProxy called, returning:', mockHttpProxy); - return mockHttpProxy; - }; + // No need to mock getHttpProxy - the bridge already handles HttpProxy availability // Make a connection to port 8080 const client = new net.Socket();