fix: close record repair and verification gaps

This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 9251c85fd8
commit adff599e08
27 files changed
+787 -153

No files matched your search

+65 -13
View File
@@ -9,7 +9,7 @@ import { waitForZone, waitForZoneGone } from '../harness/dig';
import { runnerAddress, SESSION_COOKIE } from '../harness/env';
import { bulkDeleteBody, expectCheckErrorRowsCarryRaw, expectZoneCreateWarnings, importApplyBody, UNKNOWN_API_OPERATION, ZONE_CREATE_DELEGATIONS_IN } from '../harness/decisions';
import { READ_OPERATIONS } from '../harness/ledger';
import type { AuditRow, RecordRow } from '../harness/mysql';
import type { AuditRow } from '../harness/mysql';
import { newZoneSerial, uiValue, utcDay } from '../harness/records';
import type { RecordInput, Ui } from '../harness/ui';
import { expectServed } from '../harness/served';
@@ -297,26 +297,31 @@ test.describe('core flow', () => {
test('5a. bulk deletion removes the selected records in one transaction', async ({ world }) => {
await adminUi.openZone(zone);
const recs: Rec[] = [1, 2, 3].map((i) => ({ name: `bulk${i}`, type: 'TXT', ttl: 300, data: { text: `bulk ${i}` } }));
const remaining: Rec = { name: 'bulk4', type: 'TXT', ttl: 300, data: { text: 'x'.repeat(256) } };
for (const r of recs) {
const res = await adminApi.post(`${zp(zone)}/records`, { name: r.name, type: r.type, ttl: r.ttl, data: r.data });
expect(res.status, res.text).toBe(201);
}
const added = await adminApi.post(`${zp(zone)}/records`, remaining);
expect(added.status, added.text).toBe(201);
const survivor = added.json.record;
await adminUi.openZone(zone);
const rows = await Promise.all(recs.map((r) => storedRow(world, zone, r)));
const change = await begin(world, zone);
const mark = await world.db.auditMaxId();
const res = await adminUi.bulkDelete(recs.map((r) => ({ name: r.name, type: r.type })), { expectStatus: 200 });
expect(res.json).toEqual(bulkDeleteBody(3));
expect(res.json.warnings).toContainEqual(expect.objectContaining({ code: 'txt_split' }));
await adminUi.expectToast('TXT is served in strings of at most 255 bytes');
await expectBumped(world, zone, change, 'bulk delete');
for (const r of recs) await threeWayGone(world, adminUi, zone, r, null, `bulk deleted ${r.name}`);
const audit = findAudit(await auditSince(world, mark), 'record_bulk_delete', 200);
expect(audit.zone).toBe(zone);
await expectAuditChange(world, zone, audit, change, 'bulk delete');
const survivor = await adminApi.post(`${zp(zone)}/records`, { name: 'bulk4', type: 'TXT', ttl: 300, data: { text: 'bulk 4' } });
const stale = await adminApi.post(`${zp(zone)}/records/delete`, { records: [{ id: survivor.json.record.id, etag: survivor.json.record.etag }, { id: rows[0].id, etag: '"0000"' }] });
const stale = await adminApi.post(`${zp(zone)}/records/delete`, { records: [{ id: survivor.id, etag: survivor.etag }, { id: rows[0].id, etag: '"0000"' }] });
expect(stale.status, 'a stale or missing ETag fails the whole bulk delete').toBe(412);
await storedRow(world, zone, { name: 'bulk4', type: 'TXT', ttl: 300, data: { text: 'bulk 4' } });
const done = await adminApi.post(`${zp(zone)}/records/delete`, { records: [{ id: survivor.json.record.id, etag: survivor.json.record.etag }] });
await storedRow(world, zone, remaining);
const done = await adminApi.post(`${zp(zone)}/records/delete`, { records: [{ id: survivor.id, etag: survivor.etag }] });
expect(done.status).toBe(200);
});
@@ -373,7 +378,9 @@ test.describe('core flow', () => {
const applied = await adminUi.importApply();
expect(applied.status).toBe(200);
expect(applied.json).toEqual(importApplyBody(3, 1, 0));
expect(applied.json.warnings).toContainEqual(expect.objectContaining({ message: 'TXT strings were joined and the plugin will re-split them at 255 bytes' }));
await expect(adminUi.page).toHaveURL(new RegExp(`/zones/${zone.replace(/\./g, '\\.')}$`));
await adminUi.expectToast('TXT strings were joined and the plugin will re-split them at 255 bytes');
await expectBumped(world, zone, change, 'merge import');
const imported: Rec[] = [
{ name: 'imp1', type: 'A', ttl: 600, data: { ip: '192.0.2.40' } },
@@ -426,7 +433,9 @@ test.describe('core flow', () => {
expect(created.status, created.text).toBe(201);
await adminApi.post(`${zp(zoneC)}/records`, { name: 'ns1', type: 'A', ttl: 3600, data: { ip: '192.0.2.1' } });
await waitForZone(world.g, zoneC, { recorder: world.recorder });
const soa = (await world.db.records(zoneC)).find((r) => r.record_type === 'SOA') as RecordRow;
const original = await begin(world, zoneC);
const soa = original.rows.find((r) => r.record_type === 'SOA')!;
const duplicateSOA = JSON.stringify({ ...JSON.parse(soa.content!), ns: 'duplicate.example.net.' });
const id = async (name: string, type: string, ttl: number | null, content: string | null, z = zoneC) => world.db.insertRaw({ zone: z, name, ttl, content, record_type: type });
const broken: Record<string, number> = {
ttl_null: await id('tnull', 'A', null, '{"ip":"192.0.2.60"}'),
@@ -438,12 +447,12 @@ test.describe('core flow', () => {
name_not_fqdn: await id('nfq', 'CNAME', 3600, '{"host":"target.example.net"}'),
mx_priority_key: await id('mxp', 'MX', 3600, '{"host":"mail.example.net.","priority":10}'),
soa_not_apex: await id('soasub', 'SOA', 3600, soa.content),
soa_multiple: await id('', 'SOA', 3600, soa.content),
soa_multiple: await id('', 'SOA', 3600, duplicateSOA),
cname_apex: await id('', 'CNAME', 3600, '{"host":"target.example.net."}'),
cname_conflict: await id('both', 'CNAME', 3600, '{"host":"target.example.net."}'),
pack_failed: await id('cut', 'NS', 3600, '{"host":"ns.example.net"}'),
};
await id('both', 'A', 3600, '{"ip":"192.0.2.63"}');
const conflictAddress = await id('both', 'A', 3600, '{"ip":"192.0.2.63"}');
const codes = Object.keys(broken);
const brokenRows = await world.db.records(zoneC);
for (const [name, type, rcode] of [
@@ -464,6 +473,8 @@ test.describe('core flow', () => {
zone_case: await id('upper', 'A', 3600, '{"ip":"192.0.2.65"}', upper),
};
await id('', 'NS', 3600, `{"host":"ns1.${nosoa}"}`, nosoa);
await id('ns1', 'A', 3600, '{"ip":"192.0.2.67"}', nosoa);
const noSOARows = await world.db.records(nosoa);
const check = await adminApi.get(`${zp(zoneC)}/check`);
expect(check.status).toBe(200);
@@ -508,15 +519,31 @@ test.describe('core flow', () => {
expect(zonesTable.find((z) => z.zone === zoneC)?.problems).toMatch(/\d+ errors?/);
expect(zonesTable.find((z) => z.zone === zone)?.problems).not.toMatch(/error/);
await world.db.exec(`DELETE FROM ${world.db.t.records} WHERE id IN (?, ?)`, [broken.soa_not_apex, broken.soa_multiple]);
await world.db.deleteZoneRaw(nodot);
await world.db.deleteZoneRaw(upper);
await world.db.deleteZoneRaw(nosoa);
await adminUi.openZone(zoneC);
await adminUi.deleteRecord({ name: 'soasub', type: 'SOA' }, { expectStatus: 200 });
expect(await world.db.recordById(broken.soa_not_apex)).toBeUndefined();
await adminUi.openZone(zoneC);
expect((await adminUi.problems()).map((p) => p.code)).toEqual(expect.arrayContaining(['soa_multiple', 'cname_apex', 'cname_conflict']));
await adminUi.deleteRecord({ name: '@', type: 'SOA', value: duplicateSOA }, { expectStatus: 200 });
expect(await world.db.recordById(broken.soa_multiple)).toBeUndefined();
const soaSerial = await expectBumped(world, zoneC, original, 'repair leaves one managed SOA');
expect((await world.db.records(zoneC)).filter((row) => row.record_type === 'SOA')).toEqual([
{ ...soa, content: JSON.stringify({ ...JSON.parse(soa.content!), serial: soaSerial }) },
]);
await adminUi.openZone(zoneC);
await adminUi.expectRow({ name: '@', type: 'SOA' });
const beforeCNAMERepair = await begin(world, zoneC);
await adminUi.bulkDelete([{ name: 'both', type: 'CNAME' }, { name: '@', type: 'CNAME' }], { expectStatus: 200 });
expect(await world.db.recordById(broken.cname_apex)).toBeUndefined();
expect(await world.db.recordById(broken.cname_conflict)).toBeUndefined();
await adminUi.expectNoRow({ name: 'both', type: 'CNAME' });
await adminUi.expectNoRow({ name: '@', type: 'CNAME' });
const preservedAddress = await threeWay(world, adminUi, zoneC, { name: 'both', type: 'A', ttl: 3600, data: { ip: '192.0.2.63' } }, beforeCNAMERepair, 'repair conflicting CNAMEs');
expect(preservedAddress.id).toBe(conflictAddress);
const listed = (await adminApi.get(`${zp(zoneC)}/records`)).json.records as Array<{ id: number; name: string; type: string; data: unknown; raw: string | null; problems: Array<{ severity: string }> }>;
for (const r of listed.filter((x) => x.problems.length > 0 && x.data === null)) expect(r.raw === null || typeof r.raw === 'string').toBe(true);
const storedContent = new Map((await world.db.records(zoneC)).map((r) => [r.id, r.content]));
const storedContent = new Map((await world.db.records()).map((r) => [r.id, r.content]));
expectCheckErrorRowsCarryRaw(listed, (i) => storedContent.get(listed[i].id) ?? null);
const repair = async (what: string, match: { name: string; type: string }, inp: RecordInput & { selectType?: string }, rec: Rec) => {
const apiRow = listed.find((x) => x.name === match.name && x.type === match.type);
@@ -550,12 +577,37 @@ test.describe('core flow', () => {
await repair('name_not_fqdn', { name: 'nfq', type: 'CNAME' }, { name: 'nfq', type: 'CNAME', ttl: '3600', fields: { host: 'target.example.net' } }, { name: 'nfq', type: 'CNAME', ttl: 3600, data: { host: 'target.example.net.' } });
await repair('mx_priority_key', { name: 'mxp', type: 'MX' }, { name: 'mxp', type: 'MX', ttl: '3600', fields: { preference: '10', host: 'mail.example.net' } }, { name: 'mxp', type: 'MX', ttl: 3600, data: { host: 'mail.example.net.', preference: 10 } });
await repair('pack_failed', { name: 'cut', type: 'NS' }, { name: 'cut', type: 'NS', ttl: '3600', fields: { host: 'ns.example.net' } }, { name: 'cut', type: 'NS', ttl: 3600, data: { host: 'ns.example.net.' } });
for (const [name, code, ip] of [['nodot', 'zone_not_fqdn', '192.0.2.64'], ['upper', 'zone_case', '192.0.2.65']]) {
await repair(code, { name, type: 'A' }, { name, type: 'A', ttl: '3600', fields: { ip } }, { name, type: 'A', ttl: 3600, data: { ip } });
expect((await world.db.recordById(other[code]))?.zone).toBe(zoneC);
}
const after = await adminApi.get(`${zp(zoneC)}/check`);
expect((after.json.problems as Array<{ severity: string; code: string }>).filter((p) => p.severity === 'error')).toEqual([]);
expect((await adminUi.problems()).filter((p) => p.severity === 'error')).toEqual([]);
const cliAfter = await world.cli.check(zoneC);
expect(cliAfter.code).toBe(after.json.problems.length === 0 ? 0 : 3);
expect(cliAfter.stdout).not.toMatch(/\berror\b/);
for (const row of original.rows.filter((r) => r.id !== soa.id)) expect(await world.db.recordById(row.id)).toEqual(row);
await servedZone(world, zoneC);
await adminUi.openZone(nosoa);
expect((await adminUi.problems()).some((p) => p.code === 'soa_missing')).toBe(true);
const started = new Date();
const preview = await adminUi.importPreview(nosoa, `@ 3600 IN SOA ns1.${nosoa} hostmaster.${nosoa} 1980010100 3600 600 604800 300`, 'merge');
expect(preview.status, JSON.stringify(preview.json)).toBe(200);
expect(preview.json).toMatchObject({ added: [expect.objectContaining({ name: '', type: 'SOA', ttl: 3600 })], updated: [], deleted: [] });
const applied = await adminUi.importApply();
expect(applied.status).toBe(200);
expect(applied.json).toEqual(importApplyBody(1, 0, 0));
await adminUi.openZone(nosoa);
await waitForZone(world.g, nosoa, { recorder: world.recorder });
const restoredSerial = (await world.db.soaSerial(nosoa))!;
expect([utcDay(started), utcDay(new Date())]).toContain(restoredSerial);
await threeWay(world, adminUi, nosoa, { name: '', type: 'SOA', ttl: 3600, data: { ns: `ns1.${nosoa}`, MBox: `hostmaster.${nosoa}`, serial: restoredSerial, refresh: 3600, retry: 600, expire: 604800, minttl: 300 } }, null, 'merge-import restores missing SOA');
expect((await world.db.records(nosoa)).filter((row) => row.record_type !== 'SOA')).toEqual(noSOARows);
expect((await adminApi.get(`${zp(nosoa)}/check`)).json.problems).toEqual([]);
expect(await adminUi.problems()).toEqual([]);
await servedZone(world, nosoa);
});
test('noncanonical zones and selected SOA rows can be repaired through the UI', async ({ world }) => {
+18 -8
View File
@@ -211,15 +211,25 @@ test.describe('harness self-checks', () => {
test('the leak detection finds and removes resources of the run', async () => {
const name = `${project()}-leakprobe`;
const sentinel = `${project()}-unlabeled`;
const image = process.env.E2E_RUNNER_IMAGE as string;
const started = await docker(['run', '--detach', '--name', name, '--label', `${RUN_LABEL}=${project()}`, '--network', 'none', '--entrypoint', 'node', image, '-e', 'setTimeout(() => {}, 120000)']);
expect(started.code, started.stderr).toBe(0);
const allowed = new Set(STACK_SERVICES.map((s) => containerName(s)));
const leaks = await detectLeaks(allowed);
expect(leaks.join('\n')).toContain(name);
const gone = await docker(['inspect', name]);
expect(gone.code).not.toBe(0);
expect(await detectLeaks(allowed)).toEqual([]);
const volume = await docker(['volume', 'create', sentinel]);
expect(volume.code, volume.stderr).toBe(0);
try {
const started = await docker(['run', '--detach', '--name', name, '--label', `${RUN_LABEL}=${project()}`, '--network', 'none', '--entrypoint', 'node', image, '-e', 'setTimeout(() => {}, 120000)']);
expect(started.code, started.stderr).toBe(0);
const allowed = new Set(STACK_SERVICES.map((s) => containerName(s)));
const leaks = await detectLeaks(allowed);
expect(leaks.join('\n')).toContain(name);
const gone = await docker(['inspect', name]);
expect(gone.code).not.toBe(0);
expect(await detectLeaks(allowed)).toEqual([]);
const preserved = await docker(['volume', 'inspect', sentinel]);
expect(preserved.code, preserved.stderr).toBe(0);
} finally {
const removed = await docker(['volume', 'rm', sentinel]);
expect(removed.code, removed.stderr).toBe(0);
}
const ps = await run('docker', ['ps', '--format', '{{.Names}}', '--filter', `label=com.docker.compose.project=${project()}`]);
for (const service of STACK_SERVICES) expect(ps.stdout).toContain(containerName(service));
expect(Object.keys(GROUPS)).toHaveLength(9);
+34 -14
View File
@@ -7,8 +7,8 @@ import { importApplyBody } from '../harness/decisions';
import { parseRR, waitForZone } from '../harness/dig';
import { COREDNS_HOST } from '../harness/env';
import { run } from '../harness/proc';
import { address, addAddress, createZone, restartWithSessions, zoneInput } from '../harness/personas';
import { begin, servedZone, threeWay } from '../harness/verify';
import { address, createZone, restartWithSessions, zoneInput } from '../harness/personas';
import { begin, expectBumped, servedZone, storedRow, threeWay, type Rec } from '../harness/verify';
test.use({ group: 'power' });
@@ -69,7 +69,8 @@ test('a power user operates a large installation, with restart and edit conflict
expect(await world.db.delegations()).toHaveLength(48);
const ip = '198.51.100.40';
const file = Array.from({ length: 1200 }, (_, i) => `load-${i} 300 IN A ${ip}`).join('\n') + '\n';
const names = Array.from({ length: 1200 }, (_, i) => `load-${i}`);
const file = names.map((name) => `${name} 300 IN A ${ip}`).join('\n') + '\n';
expect((await first.importPreview(imports, file, 'merge')).json.added).toHaveLength(1200);
const importChange = await begin(world, imports);
expect((await first.importApply()).json).toEqual(importApplyBody(1200, 0, 0));
@@ -78,13 +79,15 @@ test('a power user operates a large installation, with restart and edit conflict
await threeWay(world, first, imports, { ...address('load-0', ip), type: 'A' }, importChange, 'large import');
expect(await world.db.records(imports)).toHaveLength(1202);
const imported = (await world.db.records(imports)).filter((row) => row.name.startsWith('load-'));
expect(imported).toHaveLength(1200);
const queries = imported.map((row) => `${row.name}.${imports} A`).join('\n') + '\n';
const batch = await run('dig', [`@${COREDNS_HOST}`, '-p', String(world.g.dnsPort), '+norecurse', '+nocookie', '+time=3', '+tries=2', '+noall', '+answer', '-f', '-'], { input: queries, timeoutMs: 120_000 });
expect(imported.map((row) => row.name).sort()).toEqual([...names].sort());
const queries = names.map((name) => `${name}.${imports} A`).join('\n') + '\n';
const batch = await run('dig', [`@${COREDNS_HOST}`, '-p', String(world.g.dnsPort), '+norecurse', '+nocookie', '+time=3', '+tries=2', '+noall', '+comments', '+answer', '-f', '-'], { input: queries, timeoutMs: 120_000 });
expect(batch.code, batch.stderr).toBe(0);
const rcodes = Array.from(batch.stdout.matchAll(/->>HEADER<<-\s+opcode:\s*\S+,\s*status:\s*([A-Z]+),/g), (match) => match[1]);
expect(rcodes).toEqual(names.map(() => 'NOERROR'));
const answers = batch.stdout.split('\n').filter((line) => line.trim() && !line.startsWith(';')).map(parseRR);
expect(answers.map((rr) => `${rr.name} ${rr.ttl} ${rr.type} ${rr.data}`).sort()).toEqual(
imported.map((row) => `${row.name}.${imports} 300 A ${ip}`).sort(),
expect(answers.map((rr) => `${rr.name} ${rr.ttl} ${rr.class} ${rr.type} ${rr.data}`).sort()).toEqual(
names.map((name) => `${name}.${imports} 300 IN A ${ip}`).sort(),
);
for (const row of imported) expect(row).toMatchObject({ zone: imports, ttl: 300, record_type: 'A', content: JSON.stringify({ ip }) });
expect((await api.get(`${zp(imports)}/check`)).json.problems).toEqual([]);
@@ -94,22 +97,39 @@ test('a power user imports the supported types in one transaction', async ({ wor
const admin = await world.bootstrapAdmin();
const api = await world.apiAs(admin);
const zone = world.zoneName();
const zonePath = await createZone(api, zone);
await addAddress(api, zonePath, 'www', '192.0.2.5');
await createZone(api, zone);
const ui = await world.uiAs(admin);
const soa = zoneInput(zone);
const replacementNS = 'ns3.example.net.';
const entries = [
['@', 'SOA', `${soa.ns} ${soa.mbox} 0 3600 600 604800 300`],
['@', 'SOA', `${replacementNS} ${soa.mbox} 0 3600 600 604800 300`],
['@', 'NS', 'ns2.example.net.'],
['www', 'A', '192.0.2.5'],
['www', 'AAAA', '2001:db8::50'],
['*.alias', 'CNAME', `www.${zone}`],
['@', 'MX', '0 .'],
['@', 'MX', '17 mail.example.net.'],
['@', 'TXT', '"test"'],
['_tcp._svc', 'SRV', '0 0 0 .'],
['@', 'CAA', '0 issue "ca.example.net"'],
['_tcp._svc', 'SRV', '5 9 8443 svc.example.net.'],
['@', 'CAA', '128 issue "ca.example.net"'],
];
const before = await begin(world, zone);
expect((await ui.importPreview(zone, entries.map(([n, t, v]) => `${n} 300 IN ${t} ${v}\n`).join(''), 'merge')).status).toBe(200);
expect((await ui.importApply()).status).toBe(200);
expect((await world.db.records(zone)).map((row) => row.record_type).sort()).toEqual(['A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NS', 'NS', 'SOA', 'SRV', 'TXT']);
const serial = await expectBumped(world, zone, before, 'all-types import');
await storedRow(world, zone, { name: '', type: 'SOA', ttl: 300, data: { ns: replacementNS, MBox: soa.mbox, refresh: 3600, retry: 600, expire: 604800, minttl: 300, serial } });
const imported: Rec[] = [
{ name: '', type: 'NS', ttl: 300, data: { host: 'ns2.example.net.' } },
{ name: 'www', type: 'A', ttl: 300, data: { ip: '192.0.2.5' } },
{ name: 'www', type: 'AAAA', ttl: 300, data: { ip: '2001:db8::50' } },
{ name: '*.alias', type: 'CNAME', ttl: 300, data: { host: `www.${zone}` } },
{ name: '', type: 'MX', ttl: 300, data: { host: 'mail.example.net.', preference: 17 } },
{ name: '', type: 'TXT', ttl: 300, data: { text: 'test' } },
{ name: '_tcp._svc', type: 'SRV', ttl: 300, data: { priority: 5, weight: 9, port: 8443, target: 'svc.example.net.' } },
{ name: '', type: 'CAA', ttl: 300, data: { flag: 128, tag: 'issue', value: 'ca.example.net' } },
];
await ui.openZone(zone);
await waitForZone(world.g, zone, { recorder: world.recorder });
for (const record of imported) await threeWay(world, ui, zone, record, null, 'all-types import');
await servedZone(world, zone);
});