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
This commit is contained in:
parent
a2affcd93e
commit
c7c325a7d8
@ -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'
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user