86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
|
import { SmartProxy } from '../ts/index.js';
|
|
|
|
tap.test('should set update routes callback on certificate manager', async () => {
|
|
// Create a simple proxy with a route requiring certificates
|
|
const proxy = new SmartProxy({
|
|
acme: {
|
|
email: 'test@local.dev',
|
|
useProduction: false,
|
|
port: 8080 // Use non-privileged port for ACME challenges globally
|
|
},
|
|
routes: [{
|
|
name: 'test-route',
|
|
match: {
|
|
ports: [8443],
|
|
domains: ['test.local']
|
|
},
|
|
action: {
|
|
type: 'forward',
|
|
target: { host: 'localhost', port: 3000 },
|
|
tls: {
|
|
mode: 'terminate',
|
|
certificate: 'auto',
|
|
acme: {
|
|
email: 'test@local.dev',
|
|
useProduction: false
|
|
}
|
|
}
|
|
}
|
|
}]
|
|
});
|
|
|
|
// Mock createCertificateManager to track callback setting
|
|
let callbackSet = false;
|
|
const originalCreate = (proxy as any).createCertificateManager;
|
|
|
|
(proxy as any).createCertificateManager = async function(...args: any[]) {
|
|
// Create the actual certificate manager
|
|
const certManager = await originalCreate.apply(this, args);
|
|
|
|
// Track if setUpdateRoutesCallback was called
|
|
const originalSet = certManager.setUpdateRoutesCallback;
|
|
certManager.setUpdateRoutesCallback = function(callback: any) {
|
|
callbackSet = true;
|
|
return originalSet.call(this, callback);
|
|
};
|
|
|
|
return certManager;
|
|
};
|
|
|
|
await proxy.start();
|
|
|
|
// The callback should have been set during initialization
|
|
expect(callbackSet).toEqual(true);
|
|
|
|
// Reset tracking
|
|
callbackSet = false;
|
|
|
|
// Update routes - this should recreate the certificate manager
|
|
await proxy.updateRoutes([{
|
|
name: 'new-route',
|
|
match: {
|
|
ports: [8444],
|
|
domains: ['new.local']
|
|
},
|
|
action: {
|
|
type: 'forward',
|
|
target: { host: 'localhost', port: 3001 },
|
|
tls: {
|
|
mode: 'terminate',
|
|
certificate: 'auto',
|
|
acme: {
|
|
email: 'test@local.dev',
|
|
useProduction: false
|
|
}
|
|
}
|
|
}
|
|
}]);
|
|
|
|
// The callback should have been set again after update
|
|
expect(callbackSet).toEqual(true);
|
|
|
|
await proxy.stop();
|
|
});
|
|
|
|
tap.start(); |