From eac6075a120ad1cf5c4992cb8363d985fed97abc Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sun, 13 Jul 2025 00:41:44 +0000 Subject: [PATCH] fix(cert): fix tsclass ICert usage --- test/test.certificate-provision.ts | 42 ++++++++++++------- ts/proxies/smart-proxy/certificate-manager.ts | 8 ++-- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/test/test.certificate-provision.ts b/test/test.certificate-provision.ts index 33fec90..74c46c3 100644 --- a/test/test.certificate-provision.ts +++ b/test/test.certificate-provision.ts @@ -15,12 +15,15 @@ const testCert = fs.readFileSync(path.join(__dirname, 'helpers/test-cert.pem'), const testKey = fs.readFileSync(path.join(__dirname, 'helpers/test-key.pem'), 'utf8'); tap.test('SmartProxy should support custom certificate provision function', async () => { - // Create test certificate object - the type is from plugins.tsclass.network.ICert - // but we return a simple object with the required properties + // Create test certificate object matching ICert interface const testCertObject = { - cert: testCert, - key: testKey, - ca: '' + id: 'test-cert-1', + domainName: 'test.example.com', + created: Date.now(), + validUntil: Date.now() + 90 * 24 * 60 * 60 * 1000, // 90 days + privateKey: testKey, + publicKey: testCert, + csr: '' }; // Custom certificate store for testing @@ -35,7 +38,7 @@ tap.test('SmartProxy should support custom certificate provision function', asyn // Return custom cert for known domains if (customCerts.has(domain)) { console.log(`Returning custom certificate for ${domain}`); - return customCerts.get(domain)! as unknown as TSmartProxyCertProvisionObject; + return customCerts.get(domain)!; } // Fallback to Let's Encrypt for other domains @@ -81,13 +84,16 @@ tap.test('Custom certificate provision function should be called', async () => { provisionCalled = true; provisionedDomains.push(domain); - // Return a test certificate using the loaded files - // We need to return a proper cert object that satisfies the type + // Return a test certificate matching ICert interface return { - cert: testCert, - key: testKey, - ca: '' - } as unknown as TSmartProxyCertProvisionObject; + id: `test-cert-${domain}`, + domainName: domain, + created: Date.now(), + validUntil: Date.now() + 90 * 24 * 60 * 60 * 1000, + privateKey: testKey, + publicKey: testCert, + csr: '' + }; }, acme: { email: 'test@example.com', @@ -278,10 +284,14 @@ tap.test('Should return http01 for unknown domains', async () => { certProvisionFunction: async (domain: string): Promise => { if (domain === 'known.example.com') { return { - cert: testCert, - key: testKey, - ca: '' - } as unknown as TSmartProxyCertProvisionObject; + id: `test-cert-${domain}`, + domainName: domain, + created: Date.now(), + validUntil: Date.now() + 90 * 24 * 60 * 60 * 1000, + privateKey: testKey, + publicKey: testCert, + csr: '' + }; } returnedHttp01 = true; return 'http01'; diff --git a/ts/proxies/smart-proxy/certificate-manager.ts b/ts/proxies/smart-proxy/certificate-manager.ts index 3eac595..9d80ff0 100644 --- a/ts/proxies/smart-proxy/certificate-manager.ts +++ b/ts/proxies/smart-proxy/certificate-manager.ts @@ -260,11 +260,11 @@ export class SmartCertManager { // Convert to internal certificate format const certData: ICertificateData = { - cert: customCert.cert, - key: customCert.key, - ca: customCert.ca || '', + cert: customCert.publicKey, + key: customCert.privateKey, + ca: '', issueDate: new Date(), - expiryDate: this.extractExpiryDate(customCert.cert), + expiryDate: this.extractExpiryDate(customCert.publicKey), source: 'custom' };