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

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
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();