fix(cert): fix tsclass ICert usage

This commit is contained in:
Juergen Kunz
2025-07-13 00:41:44 +00:00
parent 2d2e9e9475
commit eac6075a12
2 changed files with 30 additions and 20 deletions

View File

@ -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<TSmartProxyCertProvisionObject> => {
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';

View File

@ -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'
};