This commit is contained in:
Philipp Kunz 2025-05-29 13:24:27 +00:00
parent 30ff3b7d8a
commit af13d3af10
4 changed files with 38 additions and 13 deletions

View File

@ -188,6 +188,8 @@ tap.test('should have ACME challenge route ready before certificate provisioning
expect(challengeRouteActive).toEqual(true); expect(challengeRouteActive).toEqual(true);
} }
}; };
// Call initialize like the real createCertificateManager does
await mockCertManager.initialize();
return mockCertManager; return mockCertManager;
}; };

View File

@ -48,7 +48,8 @@ tap.test('should detect and forward non-TLS connections on useHttpProxy ports',
const mockRouteManager = { const mockRouteManager = {
findMatchingRoute: (criteria: any) => ({ findMatchingRoute: (criteria: any) => ({
route: mockSettings.routes[0] route: mockSettings.routes[0]
}) }),
getAllRoutes: () => mockSettings.routes
}; };
// Mock security manager // Mock security manager
@ -141,7 +142,8 @@ tap.test('should handle TLS connections normally', async (tapTest) => {
const mockRouteManager = { const mockRouteManager = {
findMatchingRoute: (criteria: any) => ({ findMatchingRoute: (criteria: any) => ({
route: mockSettings.routes[0] route: mockSettings.routes[0]
}) }),
getAllRoutes: () => mockSettings.routes
}; };
const mockSecurityManager = { const mockSecurityManager = {

View File

@ -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 // Add detailed logging to the existing proxy instance
proxy.settings.enableDetailedLogging = true; proxy.settings.enableDetailedLogging = true;
// Override the HttpProxy initialization to avoid actual HttpProxy setup // Override the HttpProxy initialization to avoid actual HttpProxy setup
proxy['httpProxyBridge'].getHttpProxy = () => null; const mockHttpProxy = { available: true };
proxy['httpProxyBridge'].initialize = async () => { proxy['httpProxyBridge'].initialize = async () => {
console.log('Mock: HttpProxyBridge initialized'); console.log('Mock: HttpProxyBridge initialized');
}; };
proxy['httpProxyBridge'].start = async () => {
console.log('Mock: HttpProxyBridge started');
};
await proxy.start(); 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 // Make a connection to port 8080
const client = new net.Socket(); const client = new net.Socket();

View File

@ -708,6 +708,18 @@ export class RouteConnectionHandler {
// No TLS settings - check if this port should use HttpProxy // No TLS settings - check if this port should use HttpProxy
const isHttpProxyPort = this.settings.useHttpProxy?.includes(record.localPort); 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()) { if (isHttpProxyPort && this.httpProxyBridge.getHttpProxy()) {
// Forward non-TLS connections to HttpProxy if configured // Forward non-TLS connections to HttpProxy if configured
if (this.settings.enableDetailedLogging) { if (this.settings.enableDetailedLogging) {