From 018a49dbc2297dfe1534b0816cf1f33fd0481bc7 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 19 May 2025 23:57:16 +0000 Subject: [PATCH] fix(tests): Update test mocks to include provisionAllCertificates methods in certificate manager stubs and related objects. --- changelog.md | 6 +++++ test/test.port80-management.node.ts | 30 ++++++++++++++++++++++++- test/test.route-callback-simple.ts | 1 + test/test.route-update-callback.node.ts | 6 +++++ test/test.simple-acme-mock.ts | 9 +++++++- ts/00_commitinfo_data.ts | 2 +- 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 07f9e21..1d87abe 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-05-19 - 19.3.12 - fix(tests) +Update test mocks to include provisionAllCertificates methods in certificate manager stubs and related objects. + +- Added async provisionAllCertificates functions to several test mocks (e.g. in test.port80-management.node.ts, test.route-callback-simple.ts, test.route-update-callback.node.ts, and test.simple-acme-mock.ts) to simulate ACME certificate provisioning. +- Enhanced logging and port-add history debugging for ACME challenge port addition. + ## 2025-05-19 - 19.3.11 - fix(logger) Replace raw console logging calls with structured logger usage across certificate management, connection handling, and route processing for improved observability. diff --git a/test/test.port80-management.node.ts b/test/test.port80-management.node.ts index 6eadb7a..fece240 100644 --- a/test/test.port80-management.node.ts +++ b/test/test.port80-management.node.ts @@ -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 diff --git a/test/test.route-callback-simple.ts b/test/test.route-callback-simple.ts index 015c38b..44437d1 100644 --- a/test/test.route-callback-simple.ts +++ b/test/test.route-callback-simple.ts @@ -49,6 +49,7 @@ tap.test('should set update routes callback on certificate manager', async () => setGlobalAcmeDefaults: function() {}, setAcmeStateManager: function() {}, initialize: async function() {}, + provisionAllCertificates: async function() {}, stop: async function() {}, getAcmeOptions: function() { return acmeOptions || {}; }, getState: function() { return initialState || { challengeRouteActive: false }; } diff --git a/test/test.route-update-callback.node.ts b/test/test.route-update-callback.node.ts index d9ebcf8..21cc591 100644 --- a/test/test.route-update-callback.node.ts +++ b/test/test.route-update-callback.node.ts @@ -60,6 +60,9 @@ tap.test('should preserve route update callback after updateRoutes', async () => // This is where the callback is actually set in the real implementation return Promise.resolve(); }, + provisionAllCertificates: async function() { + return Promise.resolve(); + }, stop: async function() {}, getAcmeOptions: function() { return { email: 'test@testdomain.test' }; @@ -114,6 +117,7 @@ tap.test('should preserve route update callback after updateRoutes', async () => setGlobalAcmeDefaults: function() {}, setAcmeStateManager: function() {}, initialize: async function() {}, + provisionAllCertificates: async function() {}, stop: async function() {}, getAcmeOptions: function() { return { email: 'test@testdomain.test' }; @@ -233,6 +237,7 @@ tap.test('should handle route updates when cert manager is not initialized', asy updateRoutesCallback: null, setHttpProxy: function() {}, initialize: async function() {}, + provisionAllCertificates: async function() {}, stop: async function() {}, getAcmeOptions: function() { return { email: 'test@testdomain.test' }; @@ -295,6 +300,7 @@ tap.test('real code integration test - verify fix is applied', async () => { setGlobalAcmeDefaults: function() {}, setAcmeStateManager: function() {}, initialize: async function() {}, + provisionAllCertificates: async function() {}, stop: async function() {}, getAcmeOptions: function() { return acmeOptions || { email: 'test@example.com', useProduction: false }; diff --git a/test/test.simple-acme-mock.ts b/test/test.simple-acme-mock.ts index 9d35172..ebd3f7a 100644 --- a/test/test.simple-acme-mock.ts +++ b/test/test.simple-acme-mock.ts @@ -45,8 +45,12 @@ tap.test('should properly initialize with ACME configuration', async (tools) => 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'); } @@ -55,7 +59,10 @@ tap.test('should properly initialize with ACME configuration', async (tools) => // Mock NFTables (proxy as any).nftablesManager = { - ensureNFTablesSetup: async () => {}, + provisionRoute: async () => {}, + deprovisionRoute: async () => {}, + updateRoute: async () => {}, + getStatus: async () => ({}), stop: async () => {} }; diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 17ec30f..80a197f 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartproxy', - version: '19.3.11', + version: '19.3.12', description: 'A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.' }