fix(tests): Update test mocks to include provisionAllCertificates methods in certificate manager stubs and related objects.

This commit is contained in:
2025-05-19 23:57:16 +00:00
parent b30464a612
commit 018a49dbc2
6 changed files with 51 additions and 3 deletions

View File

@ -98,6 +98,13 @@ tap.test('should not double-register port 80 when user route and ACME use same p
};
// This would trigger route update in real implementation
},
provisionAllCertificates: async function() {
// Mock implementation to satisfy the call in SmartProxy.start()
// Add the ACME challenge port here too in case initialize was skipped
const challengePort = acmeOptions?.port || 80;
await mockPortManager.addPort(challengePort);
console.log(`Added ACME challenge port from provisionAllCertificates: ${challengePort}`);
},
getAcmeOptions: () => acmeOptions,
getState: () => ({ challengeRouteActive: false }),
stop: async () => {}
@ -175,9 +182,13 @@ tap.test('should handle ACME on different port than user routes', async (tools)
// Mock the port manager
const mockPortManager = {
addPort: async (port: number) => {
console.log(`Attempting to add port: ${port}`);
if (!activePorts.has(port)) {
activePorts.add(port);
portAddHistory.push(port);
console.log(`Port ${port} added to history`);
} else {
console.log(`Port ${port} already active, not adding to history`);
}
},
addPorts: async (ports: number[]) => {
@ -207,17 +218,31 @@ tap.test('should handle ACME on different port than user routes', async (tools)
setAcmeStateManager: function() {},
initialize: async function() {
// Simulate ACME route addition on different port
const challengePort = acmeOptions?.port || 80;
const challengeRoute = {
name: 'acme-challenge',
priority: 1000,
match: {
ports: acmeOptions?.port || 80,
ports: challengePort,
path: '/.well-known/acme-challenge/*'
},
action: {
type: 'static'
}
};
// Add the ACME port to our port tracking
await mockPortManager.addPort(challengePort);
// For debugging
console.log(`Added ACME challenge port: ${challengePort}`);
},
provisionAllCertificates: async function() {
// Mock implementation to satisfy the call in SmartProxy.start()
// Add the ACME challenge port here too in case initialize was skipped
const challengePort = acmeOptions?.port || 80;
await mockPortManager.addPort(challengePort);
console.log(`Added ACME challenge port from provisionAllCertificates: ${challengePort}`);
},
getAcmeOptions: () => acmeOptions,
getState: () => ({ challengeRouteActive: false }),
@ -242,6 +267,9 @@ tap.test('should handle ACME on different port than user routes', async (tools)
await proxy.start();
// Log the port history for debugging
console.log('Port add history:', portAddHistory);
// Verify that all expected ports were added
expect(portAddHistory.includes(80)).toBeTrue(); // User route
expect(portAddHistory.includes(443)).toBeTrue(); // TLS route