88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
|
import { SmartProxy } from '../ts/index.js';
|
|
|
|
/**
|
|
* Simple test to check route manager initialization with ACME
|
|
*/
|
|
tap.test('should properly initialize with ACME configuration', async (tools) => {
|
|
const settings = {
|
|
routes: [
|
|
{
|
|
name: 'secure-route',
|
|
match: {
|
|
ports: [8443],
|
|
domains: 'test.example.com'
|
|
},
|
|
action: {
|
|
type: 'forward' as const,
|
|
target: { host: 'localhost', port: 8080 },
|
|
tls: {
|
|
mode: 'terminate' as const,
|
|
certificate: 'auto' as const,
|
|
acme: {
|
|
email: 'ssl@bleu.de',
|
|
challengePort: 8080
|
|
}
|
|
}
|
|
}
|
|
}
|
|
],
|
|
acme: {
|
|
email: 'ssl@bleu.de',
|
|
port: 8080,
|
|
useProduction: false,
|
|
enabled: true
|
|
}
|
|
};
|
|
|
|
const proxy = new SmartProxy(settings);
|
|
|
|
// Replace the certificate manager creation to avoid real ACME requests
|
|
(proxy as any).createCertificateManager = async () => {
|
|
return {
|
|
setUpdateRoutesCallback: () => {},
|
|
setHttpProxy: () => {},
|
|
setGlobalAcmeDefaults: () => {},
|
|
setAcmeStateManager: () => {},
|
|
initialize: async () => {
|
|
// Using logger would be better but in test we'll keep console.log
|
|
console.log('Mock certificate manager initialized');
|
|
},
|
|
provisionAllCertificates: async () => {
|
|
console.log('Mock certificate provisioning');
|
|
},
|
|
stop: async () => {
|
|
console.log('Mock certificate manager stopped');
|
|
}
|
|
};
|
|
};
|
|
|
|
// Mock NFTables
|
|
(proxy as any).nftablesManager = {
|
|
provisionRoute: async () => {},
|
|
deprovisionRoute: async () => {},
|
|
updateRoute: async () => {},
|
|
getStatus: async () => ({}),
|
|
stop: async () => {}
|
|
};
|
|
|
|
await proxy.start();
|
|
|
|
// Verify proxy started successfully
|
|
expect(proxy).toBeDefined();
|
|
|
|
// Verify route manager has routes
|
|
const routeManager = (proxy as any).routeManager;
|
|
expect(routeManager).toBeDefined();
|
|
expect(routeManager.getAllRoutes().length).toBeGreaterThan(0);
|
|
|
|
// Verify the route exists with correct domain
|
|
const routes = routeManager.getAllRoutes();
|
|
const secureRoute = routes.find((r: any) => r.name === 'secure-route');
|
|
expect(secureRoute).toBeDefined();
|
|
expect(secureRoute.match.domains).toEqual('test.example.com');
|
|
|
|
await proxy.stop();
|
|
});
|
|
|
|
tap.start(); |