BREAKING CHANGE(SmartAcme): Refactor challenge handling by removing legacy setChallenge/removeChallenge in favor of pluggable challengeHandlers and update documentation and tests accordingly
This commit is contained in:
38
test/test.handlers-dns01.ts
Normal file
38
test/test.handlers-dns01.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { Dns01Handler } from '../ts/handlers/Dns01Handler.js';
|
||||
|
||||
tap.test('Dns01Handler prepare and cleanup calls Cloudflare and DNS functions', async () => {
|
||||
let setCalled = false;
|
||||
let removeCalled = false;
|
||||
// fake Cloudflare API
|
||||
const fakeCF: any = {
|
||||
convenience: {
|
||||
acmeSetDnsChallenge: async (ch: any) => {
|
||||
setCalled = true;
|
||||
expect(ch).toHaveProperty('hostName');
|
||||
expect(ch).toHaveProperty('challenge');
|
||||
},
|
||||
acmeRemoveDnsChallenge: async (ch: any) => {
|
||||
removeCalled = true;
|
||||
expect(ch).toHaveProperty('hostName');
|
||||
expect(ch).toHaveProperty('challenge');
|
||||
},
|
||||
},
|
||||
};
|
||||
// fake DNS checker
|
||||
const fakeDNS: any = {
|
||||
checkUntilAvailable: async (host: string, rr: string, val: string, count: number, interval: number) => {
|
||||
expect(host).toEqual('test.host');
|
||||
expect(rr).toEqual('TXT');
|
||||
expect(val).toEqual('token');
|
||||
},
|
||||
};
|
||||
const handler = new Dns01Handler(fakeCF, fakeDNS);
|
||||
const input = { hostName: 'test.host', challenge: 'token' };
|
||||
await handler.prepare(input);
|
||||
expect(setCalled).toEqual(true);
|
||||
await handler.cleanup(input);
|
||||
expect(removeCalled).toEqual(true);
|
||||
});
|
||||
|
||||
export default tap.start();
|
Reference in New Issue
Block a user