82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
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;
|
|
}
|
|
},
|
|
setHttpProxy: () => {},
|
|
setGlobalAcmeDefaults: () => {},
|
|
setAcmeStateManager: () => {},
|
|
initialize: async () => {},
|
|
provisionAllCertificates: 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(); |