87 lines
2.1 KiB
TypeScript
87 lines
2.1 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;
|
|
|
|
(proxy as any).createCertificateManager = async function(...args: any[]) {
|
|
// Create a mock certificate manager
|
|
const mockCertManager = {
|
|
setUpdateRoutesCallback: function(callback: any) {
|
|
callbackSet = true;
|
|
},
|
|
setHttpProxy: function() {},
|
|
setGlobalAcmeDefaults: function() {},
|
|
setAcmeStateManager: function() {},
|
|
initialize: async function() {},
|
|
stop: async function() {}
|
|
};
|
|
|
|
return mockCertManager;
|
|
};
|
|
|
|
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(); |