import { tap, expect } from '@push.rocks/tapbundle'; import { Qenv } from '@push.rocks/qenv'; import * as cloudflare from '@apiclient.xyz/cloudflare'; import { SmartAcme, certmanagers } from '../ts/index.js'; import { Dns01Handler } from '../ts/handlers/Dns01Handler.js'; // Load environment variables for credentials (stored under .nogit/) const testQenv = new Qenv('./', './.nogit/'); // Cloudflare API token for DNS-01 challenge (must be set in .nogit/ or env) const cfToken = (await testQenv.getEnvVarOnDemand('CF_TOKEN'))!; const cfAccount = new cloudflare.CloudflareAccount(cfToken); // MongoDB connection settings for certificate storage (must be set in .nogit/ or env) const mongoDbName = (await testQenv.getEnvVarOnDemand('MONGODB_DATABASE'))!; const mongoDbPass = (await testQenv.getEnvVarOnDemand('MONGODB_PASSWORD'))!; const mongoDbUrl = (await testQenv.getEnvVarOnDemand('MONGODB_URL'))!; let smartAcmeInstance: SmartAcme; tap.test('create SmartAcme instance with DNS-01 handler and start', async () => { smartAcmeInstance = new SmartAcme({ accountEmail: 'domains@lossless.org', // certManager: new MongoCertManager({ mongoDbName, mongoDbPass, mongoDbUrl }), certManager: new certmanagers.MemoryCertManager(), environment: 'integration', retryOptions: {}, challengeHandlers: [new Dns01Handler(cfAccount)], challengePriority: ['dns-01'], }); await smartAcmeInstance.start(); expect(smartAcmeInstance).toBeInstanceOf(SmartAcme); }); tap.test('should wipe the certmanager for this test', async () => { await smartAcmeInstance.certmanager.wipe(); }); tap.test('get a domain certificate via DNS-01 challenge', async () => { // Replace 'bleu.de' with your test domain if different const domain = 'bleu.de'; const cert = await smartAcmeInstance.getCertificateForDomain(domain); expect(cert).toHaveProperty('domainName'); expect(cert.domainName).toEqual(domain); expect(cert).toHaveProperty('publicKey'); expect(typeof cert.publicKey).toEqual('string'); expect(cert.publicKey.length).toBeGreaterThan(0); }); tap.test('stop SmartAcme instance', async () => { await smartAcmeInstance.stop(); }); export default tap.start();