smartacme/test/test.ts

49 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-07-21 16:49:18 +00:00
import { tap, expect } from '@push.rocks/tapbundle';
import { Qenv } from '@push.rocks/qenv';
import * as cloudflare from '@apiclient.xyz/cloudflare';
2019-01-08 19:45:35 +00:00
const testQenv = new Qenv('./', './.nogit/');
2020-08-13 03:10:37 +00:00
const testCloudflare = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_TOKEN'));
2016-11-01 17:27:57 +00:00
2022-09-27 13:40:55 +00:00
import * as smartacme from '../ts/index.js';
2017-01-22 20:50:04 +00:00
let smartAcmeInstance: smartacme.SmartAcme;
2016-11-01 17:27:57 +00:00
2018-08-12 18:58:59 +00:00
tap.test('should create a valid instance of SmartAcme', async () => {
2019-01-08 19:45:35 +00:00
smartAcmeInstance = new smartacme.SmartAcme({
2019-01-06 19:41:21 +00:00
accountEmail: 'domains@lossless.org',
accountPrivateKey: null,
2019-01-08 23:01:01 +00:00
mongoDescriptor: {
2019-01-15 22:59:21 +00:00
mongoDbName: testQenv.getEnvVarRequired('MONGODB_DATABASE'),
mongoDbPass: testQenv.getEnvVarRequired('MONGODB_PASSWORD'),
2020-08-12 16:36:06 +00:00
mongoDbUrl: testQenv.getEnvVarRequired('MONGODB_URL'),
2019-01-08 23:01:01 +00:00
},
2020-08-12 16:36:06 +00:00
removeChallenge: async (dnsChallenge) => {
testCloudflare.convenience.acmeRemoveDnsChallenge(dnsChallenge);
2019-01-06 19:41:21 +00:00
},
2020-08-12 16:36:06 +00:00
setChallenge: async (dnsChallenge) => {
testCloudflare.convenience.acmeSetDnsChallenge(dnsChallenge);
2019-01-08 19:45:35 +00:00
},
2020-08-12 16:36:06 +00:00
environment: 'integration',
2019-01-06 19:41:21 +00:00
});
2019-01-08 19:45:35 +00:00
await smartAcmeInstance.init();
2020-02-10 11:15:47 +00:00
});
tap.test('should get a domain certificate', async () => {
2021-01-22 18:33:53 +00:00
const certificate = await smartAcmeInstance.getCertificateForDomain('bleu.de');
console.log(certificate);
2018-08-12 18:58:59 +00:00
});
2017-01-22 20:50:04 +00:00
2019-01-13 01:10:00 +00:00
tap.test('certmatcher should correctly match domains', async () => {
2022-09-27 13:40:55 +00:00
const certMatcherMod = await import('../ts/smartacme.classes.certmatcher.js');
2019-01-13 01:10:00 +00:00
const certMatcher = new certMatcherMod.CertMatcher();
const matchedCert = certMatcher.getCertificateDomainNameByDomainName('level3.level2.level1');
2022-09-27 13:40:55 +00:00
expect(matchedCert).toEqual('level2.level1');
2019-01-13 01:10:00 +00:00
});
2019-01-12 20:06:29 +00:00
tap.test('should stop correctly', async () => {
await smartAcmeInstance.stop();
});
2018-08-12 18:58:59 +00:00
tap.start();