fix(SmartCertManager): Preserve certificate manager update callback during route updates
This commit is contained in:
81
test/test.fix-verification.ts
Normal file
81
test/test.fix-verification.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartProxy } from '../ts/index.js';
|
||||
|
||||
tap.test('should verify certificate manager callback is preserved on updateRoutes', async () => {
|
||||
// Create proxy with initial cert routes
|
||||
const proxy = new SmartProxy({
|
||||
routes: [{
|
||||
name: 'cert-route',
|
||||
match: { ports: [18443], domains: ['test.local'] },
|
||||
action: {
|
||||
type: 'forward',
|
||||
target: { host: 'localhost', port: 3000 },
|
||||
tls: {
|
||||
mode: 'terminate',
|
||||
certificate: 'auto',
|
||||
acme: { email: 'test@local.test' }
|
||||
}
|
||||
}
|
||||
}],
|
||||
acme: { email: 'test@local.test', port: 18080 }
|
||||
});
|
||||
|
||||
// Track callback preservation
|
||||
let initialCallbackSet = false;
|
||||
let updateCallbackSet = false;
|
||||
|
||||
// Mock certificate manager creation
|
||||
(proxy as any).createCertificateManager = async function(...args: any[]) {
|
||||
const certManager = {
|
||||
updateRoutesCallback: null as any,
|
||||
setUpdateRoutesCallback: function(callback: any) {
|
||||
this.updateRoutesCallback = callback;
|
||||
if (!initialCallbackSet) {
|
||||
initialCallbackSet = true;
|
||||
} else {
|
||||
updateCallbackSet = true;
|
||||
}
|
||||
},
|
||||
setNetworkProxy: () => {},
|
||||
setGlobalAcmeDefaults: () => {},
|
||||
setAcmeStateManager: () => {},
|
||||
initialize: async () => {},
|
||||
stop: async () => {},
|
||||
getAcmeOptions: () => ({ email: 'test@local.test' }),
|
||||
getState: () => ({ challengeRouteActive: false })
|
||||
};
|
||||
|
||||
// Set callback as in real implementation
|
||||
certManager.setUpdateRoutesCallback(async (routes) => {
|
||||
await this.updateRoutes(routes);
|
||||
});
|
||||
|
||||
return certManager;
|
||||
};
|
||||
|
||||
await proxy.start();
|
||||
expect(initialCallbackSet).toEqual(true);
|
||||
|
||||
// Update routes - this should preserve the callback
|
||||
await proxy.updateRoutes([{
|
||||
name: 'updated-route',
|
||||
match: { ports: [18444], domains: ['test2.local'] },
|
||||
action: {
|
||||
type: 'forward',
|
||||
target: { host: 'localhost', port: 3001 },
|
||||
tls: {
|
||||
mode: 'terminate',
|
||||
certificate: 'auto',
|
||||
acme: { email: 'test@local.test' }
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
expect(updateCallbackSet).toEqual(true);
|
||||
|
||||
await proxy.stop();
|
||||
|
||||
console.log('Fix verified: Certificate manager callback is preserved on updateRoutes');
|
||||
});
|
||||
|
||||
tap.start();
|
Reference in New Issue
Block a user