fix(certificates): Update static-route certificate metadata for ACME challenges
This commit is contained in:
104
test/test.simple-acme-mock.ts
Normal file
104
test/test.simple-acme-mock.ts
Normal file
@ -0,0 +1,104 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import { SmartProxy } from '../ts/index.js';
|
||||
|
||||
/**
|
||||
* Simple test to check that ACME challenge routes are created
|
||||
*/
|
||||
tap.test('should create ACME challenge route', async (tools) => {
|
||||
tools.timeout(5000);
|
||||
|
||||
const mockRouteUpdates: any[] = [];
|
||||
|
||||
const settings = {
|
||||
routes: [
|
||||
{
|
||||
name: 'secure-route',
|
||||
match: {
|
||||
ports: [443],
|
||||
domains: 'test.example.com'
|
||||
},
|
||||
action: {
|
||||
type: 'forward' as const,
|
||||
target: { host: 'localhost', port: 8080 },
|
||||
tls: {
|
||||
mode: 'terminate' as const,
|
||||
certificate: 'auto',
|
||||
acme: {
|
||||
email: 'test@test.local' // Use non-example.com domain
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const proxy = new SmartProxy(settings);
|
||||
|
||||
// Mock certificate manager
|
||||
let updateRoutesCallback: any;
|
||||
|
||||
(proxy as any).createCertificateManager = async function(routes: any[], certDir: string, acmeOptions: any) {
|
||||
const mockCertManager = {
|
||||
setUpdateRoutesCallback: function(callback: any) {
|
||||
updateRoutesCallback = callback;
|
||||
},
|
||||
setNetworkProxy: function() {},
|
||||
setGlobalAcmeDefaults: function() {},
|
||||
setAcmeStateManager: function() {},
|
||||
initialize: async function() {
|
||||
// Simulate adding ACME challenge route
|
||||
if (updateRoutesCallback) {
|
||||
const challengeRoute = {
|
||||
name: 'acme-challenge',
|
||||
priority: 1000,
|
||||
match: {
|
||||
ports: 80,
|
||||
path: '/.well-known/acme-challenge/*'
|
||||
},
|
||||
action: {
|
||||
type: 'static',
|
||||
handler: async (context: any) => {
|
||||
const token = context.path?.split('/').pop() || '';
|
||||
return {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
body: `mock-challenge-response-${token}`
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const updatedRoutes = [...routes, challengeRoute];
|
||||
mockRouteUpdates.push(updatedRoutes);
|
||||
await updateRoutesCallback(updatedRoutes);
|
||||
}
|
||||
},
|
||||
getAcmeOptions: () => acmeOptions,
|
||||
getState: () => ({ challengeRouteActive: false }),
|
||||
stop: async () => {}
|
||||
};
|
||||
return mockCertManager;
|
||||
};
|
||||
|
||||
// Mock NFTables
|
||||
(proxy as any).nftablesManager = {
|
||||
ensureNFTablesSetup: async () => {},
|
||||
stop: async () => {}
|
||||
};
|
||||
|
||||
await proxy.start();
|
||||
|
||||
// Verify that routes were updated with challenge route
|
||||
expect(mockRouteUpdates.length).toBeGreaterThan(0);
|
||||
|
||||
const lastUpdate = mockRouteUpdates[mockRouteUpdates.length - 1];
|
||||
const challengeRoute = lastUpdate.find((r: any) => r.name === 'acme-challenge');
|
||||
|
||||
expect(challengeRoute).toBeDefined();
|
||||
expect(challengeRoute.match.path).toEqual('/.well-known/acme-challenge/*');
|
||||
expect(challengeRoute.match.ports).toEqual(80);
|
||||
|
||||
await proxy.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
Reference in New Issue
Block a user