fix(certificate-manager): Preserve certificate manager update callback in updateRoutes

This commit is contained in:
2025-05-19 19:17:48 +00:00
parent 6387b32d4b
commit da061292ae
3 changed files with 38 additions and 4 deletions

View File

@ -30,10 +30,16 @@ tap.test('should set update routes callback on certificate manager', async () =>
}]
});
// Mock createCertificateManager to track callback setting
// Track callback setting
let callbackSet = false;
(proxy as any).createCertificateManager = async function(...args: any[]) {
// Override createCertificateManager to track callback setting
(proxy as any).createCertificateManager = async function(
routes: any,
certStore: string,
acmeOptions?: any,
initialState?: any
) {
// Create a mock certificate manager
const mockCertManager = {
setUpdateRoutesCallback: function(callback: any) {
@ -43,9 +49,31 @@ tap.test('should set update routes callback on certificate manager', async () =>
setGlobalAcmeDefaults: function() {},
setAcmeStateManager: function() {},
initialize: async function() {},
stop: async function() {}
stop: async function() {},
getAcmeOptions: function() { return acmeOptions || {}; },
getState: function() { return initialState || { challengeRouteActive: false }; }
};
// Mimic the real createCertificateManager behavior
// Always set up the route update callback for ACME challenges
mockCertManager.setUpdateRoutesCallback(async (routes) => {
await this.updateRoutes(routes);
});
// Connect with HttpProxy if available (mimic real behavior)
if ((this as any).httpProxyBridge.getHttpProxy()) {
mockCertManager.setHttpProxy((this as any).httpProxyBridge.getHttpProxy());
}
// Set the ACME state manager
mockCertManager.setAcmeStateManager((this as any).acmeStateManager);
// Pass down the global ACME config if available
if ((this as any).settings.acme) {
mockCertManager.setGlobalAcmeDefaults((this as any).settings.acme);
}
await mockCertManager.initialize();
return mockCertManager;
};