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:
26
test/test.handlers-http01.ts
Normal file
26
test/test.handlers-http01.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { Http01Handler } from '../ts/handlers/Http01Handler.js';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import os from 'os';
|
||||
|
||||
tap.test('Http01Handler writes challenge file and removes it on cleanup', async () => {
|
||||
// create temporary webroot directory
|
||||
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'http01-'));
|
||||
const handler = new Http01Handler({ webroot: tmpDir });
|
||||
const token = 'testtoken';
|
||||
const keyAuth = 'keyAuthValue';
|
||||
const webPath = `/.well-known/acme-challenge/${token}`;
|
||||
const input = { type: 'http-01', token, keyAuthorization: keyAuth, webPath };
|
||||
// prepare should write the file
|
||||
await handler.prepare(input);
|
||||
const filePath = path.join(tmpDir, webPath);
|
||||
const content = await fs.readFile(filePath, 'utf8');
|
||||
expect(content).toEqual(keyAuth);
|
||||
// cleanup should remove the file
|
||||
await handler.cleanup(input);
|
||||
const exists = await fs.stat(filePath).then(() => true).catch(() => false);
|
||||
expect(exists).toEqual(false);
|
||||
});
|
||||
|
||||
export default tap.start();
|
Reference in New Issue
Block a user