import { tap, expect } from '@push.rocks/tapbundle'; import { Http01Webroot } from '../ts/handlers/Http01Handler.js'; import { promises as fs } from 'fs'; import * as path from 'path'; import os from 'os'; tap.test('Http01Webroot 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 Http01Webroot({ 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();