diff --git a/test/test.acme-timing.ts b/test/test.acme-timing.ts index dace98b..e424151 100644 --- a/test/test.acme-timing.ts +++ b/test/test.acme-timing.ts @@ -188,6 +188,8 @@ tap.test('should have ACME challenge route ready before certificate provisioning expect(challengeRouteActive).toEqual(true); } }; + // Call initialize like the real createCertificateManager does + await mockCertManager.initialize(); return mockCertManager; }; diff --git a/test/test.http-fix-verification.ts b/test/test.http-fix-verification.ts index cfd8cf6..49c6563 100644 --- a/test/test.http-fix-verification.ts +++ b/test/test.http-fix-verification.ts @@ -48,7 +48,8 @@ tap.test('should detect and forward non-TLS connections on useHttpProxy ports', const mockRouteManager = { findMatchingRoute: (criteria: any) => ({ route: mockSettings.routes[0] - }) + }), + getAllRoutes: () => mockSettings.routes }; // Mock security manager @@ -141,7 +142,8 @@ tap.test('should handle TLS connections normally', async (tapTest) => { const mockRouteManager = { findMatchingRoute: (criteria: any) => ({ route: mockSettings.routes[0] - }) + }), + getAllRoutes: () => mockSettings.routes }; const mockSecurityManager = { diff --git a/test/test.http-forwarding-fix.ts b/test/test.http-forwarding-fix.ts index 01f28b7..3f32256 100644 --- a/test/test.http-forwarding-fix.ts +++ b/test/test.http-forwarding-fix.ts @@ -22,27 +22,36 @@ tap.test('should detect and forward non-TLS connections on HttpProxy ports', asy }] }); - // Mock the HttpProxy forwarding on the instance - const originalForward = (proxy as any).httpProxyBridge.forwardToHttpProxy; - (proxy as any).httpProxyBridge.forwardToHttpProxy = async function(...args: any[]) { - forwardedToHttpProxy = true; - connectionPath = 'httpproxy'; - console.log('Mock: Connection forwarded to HttpProxy'); - // Just close the connection for the test - args[1].end(); // socket.end() - }; - // Add detailed logging to the existing proxy instance proxy.settings.enableDetailedLogging = true; // Override the HttpProxy initialization to avoid actual HttpProxy setup - proxy['httpProxyBridge'].getHttpProxy = () => null; + const mockHttpProxy = { available: true }; proxy['httpProxyBridge'].initialize = async () => { console.log('Mock: HttpProxyBridge initialized'); }; + proxy['httpProxyBridge'].start = async () => { + console.log('Mock: HttpProxyBridge started'); + }; await proxy.start(); + // Mock the HttpProxy forwarding AFTER start to ensure it's not overridden + const originalForward = (proxy as any).httpProxyBridge.forwardToHttpProxy; + (proxy as any).httpProxyBridge.forwardToHttpProxy = async function(...args: any[]) { + forwardedToHttpProxy = true; + connectionPath = 'httpproxy'; + console.log('Mock: Connection forwarded to HttpProxy with args:', args[0], 'on port:', args[2]?.localPort); + // Just close the connection for the test + args[1].end(); // socket.end() + }; + + const originalGetHttpProxy = proxy['httpProxyBridge'].getHttpProxy; + proxy['httpProxyBridge'].getHttpProxy = () => { + console.log('Mock: getHttpProxy called, returning:', mockHttpProxy); + return mockHttpProxy; + }; + // Make a connection to port 8080 const client = new net.Socket(); diff --git a/ts/proxies/smart-proxy/route-connection-handler.ts b/ts/proxies/smart-proxy/route-connection-handler.ts index 0da16cd..c84799d 100644 --- a/ts/proxies/smart-proxy/route-connection-handler.ts +++ b/ts/proxies/smart-proxy/route-connection-handler.ts @@ -708,6 +708,18 @@ export class RouteConnectionHandler { // No TLS settings - check if this port should use HttpProxy const isHttpProxyPort = this.settings.useHttpProxy?.includes(record.localPort); + // Debug logging + if (this.settings.enableDetailedLogging) { + logger.log('debug', `Checking HttpProxy forwarding: port=${record.localPort}, useHttpProxy=${JSON.stringify(this.settings.useHttpProxy)}, isHttpProxyPort=${isHttpProxyPort}, hasHttpProxy=${!!this.httpProxyBridge.getHttpProxy()}`, { + connectionId, + localPort: record.localPort, + useHttpProxy: this.settings.useHttpProxy, + isHttpProxyPort, + hasHttpProxy: !!this.httpProxyBridge.getHttpProxy(), + component: 'route-handler' + }); + } + if (isHttpProxyPort && this.httpProxyBridge.getHttpProxy()) { // Forward non-TLS connections to HttpProxy if configured if (this.settings.enableDetailedLogging) {