// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 2026 Bryan Joshua Pedini import { test, expect } from '../harness/fixtures'; import { up } from '../harness/api'; import { intEnv } from '../harness/env'; import { addAddress, checkZone, createZone, zoneInput } from '../harness/personas'; test.use({ group: 'fuzzer' }); test('seeded requests cover every API operation and DNS record type', async ({ world }) => { test.setTimeout(240_000); const admin = await world.bootstrapAdmin(); const api = await world.apiAs(admin); const member = await world.createUser(api, 'user'); const u = up(member.username); const zone = world.zoneName(); const z = await createZone(api, zone); const r = await addAddress(api, z, 'initial', '192.0.2.30'); const rr = `${z}/records`; const cases = [ ['GET', '/account'], ['PUT', '/account/password'], ['GET', '/zones'], ['POST', '/zones'], ['GET', z], ['DELETE', z], ['GET', rr], ['POST', rr], ['PUT', `${rr}/${r.id}`], ['DELETE', `${rr}/${r.id}`], ['POST', `${rr}/delete`], ['PUT', `${z}/soa`], ['GET', `${z}/check`], ['GET', '/check'], ['GET', `${z}/export`], ['POST', `${z}/import/preview`], ['POST', `${z}/import/apply`], ['GET', `${z}/users`], ['PUT', z + u], ['DELETE', z + u], ['GET', '/users'], ['POST', '/users'], ['GET', u], ['PUT', `${u}/role`], ['PUT', `${u}/password`], ['DELETE', u], ['GET', '/audit'], ] as const; const denied = new Set([400, 404, 409, 412, 413, 415, 422, 428]); const values: unknown[] = [null, {}, [], 2 ** 40, 'bad value', '', '\u0000', '\u200b']; const mark = await world.db.auditMaxId(); const count = Math.max(cases.length, intEnv('E2E_FUZZ_CASES', 81)); for (let i = 0; i < count; i++) { const [method, route] = cases[i < cases.length ? i : world.rng.int(0, cases.length - 1)]; const key = world.rng.pick(['name', 'type', 'ttl', 'confirm', 'role', 'password', 'data', 'content']); const value = world.rng.pick(values); const typo = world.rng.string(5); const mutation = { [key]: value, [`unknown_${typo}`]: value }; const raw = world.rng.pick([JSON.stringify(mutation), JSON.stringify(value), '{"unfinished":', '[false]']); const body = method === 'GET' || route === z + u || (method === 'DELETE' && route.startsWith(rr)) ? undefined : raw; const query = method === 'GET' ? { [world.rng.pick(['limit', 'before_id', 'kind', 'actor', 'filter', 'deleted'])]: String(value) } : undefined; const options = { raw: body, contentType: world.rng.pick(['text/plain', 'application/json', 'application/json']), query }; world.recorder.fuzzCases.push({ method, route, ...options }); const result = await api.raw(method, '/api/v1' + route, options); const maySucceed = method === 'GET' || route === z + u; expect((maySucceed && result.status < 300) || denied.has(result.status), `${method} ${route}: ${result.status} ${result.text.slice(0, 250)}`).toBe(true); if (result.status >= 400) { expect(result.text.length).toBeLessThan(4096); expect(result.json.error).toEqual(expect.any(String)); } expect(world.secrets.findIn(result.text)).toEqual([]); expect(result.text).not.toMatch(/\$argon2id\$|runtime error:|SQLSTATE/); } expect(await world.db.auditSince(mark)).toHaveLength(count); expect(await world.db.records(zone)).toHaveLength(3); const types = { A: { ip: '192.0.2.42' }, AAAA: { ip: '2001:db8::42' }, CNAME: { host: `initial.${zone}` }, NS: { host: 'ns2.example.net.' }, MX: { host: '.', preference: 0 }, TXT: { text: 'random fixture' }, SRV: { priority: 0, weight: 0, port: 0, target: '.' }, CAA: { flag: 0, tag: 'issue', value: 'ca.example.net' }, SOA: { ns: 'ns.example.net.', MBox: 'hostmaster.example.net.', refresh: 3600, retry: 600, expire: 604800, minttl: 300 }, }; for (const [type, data] of Object.entries(types)) { const owner = type === 'SOA' ? '@' : type === 'SRV' ? '_service._tcp' : world.rng.string(8).toLowerCase(); const ttl = world.rng.int(1, 86400); const wrong = { name: owner, type, ttl: -ttl, data }; world.recorder.fuzzCases.push(wrong); expect((await api.post(rr, wrong)).status).toBe(422); if (type !== 'SOA') expect((await api.post(rr, { ...wrong, ttl })).status).toBe(201); } const { name, extra_ns, ...updatedSoa } = zoneInput(zone); expect((await api.put(`${z}/soa`, { ...updatedSoa, ttl: world.rng.int(1, 600) }, { ifMatch: (await api.get(z)).etag! })).status).toBe(200); await checkZone(world, api, zone); });