test: require review fix assertions

- test: require review fix assertions
- test: cover zone repair and imported dns records
- test: wait for dns and tighten assertions
- fix(api): drop the record id of a rolled back record creation
- test(audit): run every api route through the real handlers in an audit matrix
- test(api): run the authorization matrix through the real zone handlers
- test: repair duplicate apex soa through ui
This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent a884219512
commit 9251c85fd8
14 files changed
+1631 -123

No files matched your search

+53 -3
View File
@@ -7,7 +7,7 @@ import { zp, up } from '../harness/api';
import { parseTable, USAGE_TEXT } from '../harness/cli';
import { waitForZone, waitForZoneGone } from '../harness/dig';
import { runnerAddress, SESSION_COOKIE } from '../harness/env';
import { bulkDeleteBody, expectCheckErrorRowsCarryRaw, expectZoneCreateWarnings, importApplyBody, REVIEW_FIXES, UNKNOWN_API_OPERATION, ZONE_CREATE_DELEGATIONS_IN } from '../harness/decisions';
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 { newZoneSerial, uiValue, utcDay } from '../harness/records';
@@ -207,7 +207,7 @@ test.describe('core flow', () => {
const change = await begin(world, zone);
const mark = await world.db.auditMaxId();
const deleted = await adminUi.deleteRecord({ name: rec.name === '' ? '@' : rec.name, type: rec.type, value: uiValue(rec.type, rec.data) });
expect([200, 204]).toContain(deleted.status);
expect(deleted.status).toBe(200);
if (deleted.status === 200) expect(deleted.json).toMatchObject({ warnings: expect.any(Array) });
await threeWayGone(world, adminUi, zone, rec, change, what);
expect(await world.db.recordById(before.id)).toBeUndefined();
@@ -558,6 +558,56 @@ test.describe('core flow', () => {
await servedZone(world, zoneC);
});
test('noncanonical zones and selected SOA rows can be repaired through the UI', async ({ world }) => {
test.setTimeout(180_000);
const api = adminApi;
const zone = world.zoneName('repair-');
expect((await api.post('/zones', { name: zone, ns: `ns1.${zone}`, mbox: `hostmaster@${zone}`, extra_ns: [], refresh: 3600, retry: 600, expire: 604800, minttl: 300, ttl: 3600 })).status).toBe(201);
const ui = adminUi;
await waitForZone(world.g, zone, { recorder: world.recorder });
const baseline = await world.db.records(zone);
for (const [name, storedZone, code, ip] of [
['nodot', zone.slice(0, -1), 'zone_not_fqdn', '192.0.2.71'],
['upper', zone.toUpperCase(), 'zone_case', '192.0.2.72'],
]) {
const id = await world.db.insertRaw({ zone: storedZone, name, ttl: 300, content: JSON.stringify({ ip }), record_type: 'A' });
await ui.openZone(zone);
expect((await ui.problems()).some((p) => p.code === code)).toBe(true);
await ui.editRecord({ name, type: 'A' }, { name, type: 'A', ttl: '300', fields: { ip } }, { expectStatus: 200 });
expect((await world.db.recordById(id))?.zone).toBe(zone);
await threeWay(world, ui, zone, { name, type: 'A', ttl: 300, data: { ip } }, null, code);
}
const soa = baseline.find((row) => row.record_type === 'SOA')!;
const duplicateContent = JSON.stringify({ ...JSON.parse(soa.content!), ns: 'duplicate.example.net.' });
const duplicateId = await world.db.insertRaw({ zone, name: '', ttl: soa.ttl, content: duplicateContent, record_type: 'SOA' });
await ui.openZone(zone);
expect((await ui.problems()).some((p) => p.code === 'soa_multiple')).toBe(true);
await ui.deleteRecord({ name: '@', type: 'SOA', value: duplicateContent }, { expectStatus: 200 });
expect(await world.db.recordById(duplicateId)).toBeUndefined();
expect(await world.db.recordById(soa.id)).toBeDefined();
await ui.expectRow({ name: '@', type: 'SOA' });
await servedZone(world, zone);
const subId = await world.db.insertRaw({ zone, name: 'sub', ttl: soa.ttl, content: soa.content, record_type: 'SOA' });
await ui.openZone(zone);
expect((await ui.problems()).some((p) => p.code === 'soa_not_apex')).toBe(true);
expect((await ui.problems()).some((p) => p.code === 'soa_multiple')).toBe(true);
await ui.deleteRecord({ name: '@', type: 'SOA' }, { expectStatus: 200 });
expect(await world.db.recordById(soa.id)).toBeUndefined();
const row = await ui.row({ name: 'sub', type: 'SOA' });
await row.getByRole('button', { name: /^Edit / }).click();
await expect(ui.page.locator('#soa-dialog')).toBeVisible();
for (const [key, value] of Object.entries({ ns: `ns1.${zone}`, mbox: `hostmaster.${zone}`, ttl: '3600', refresh: '3600', retry: '600', expire: '604800', minttl: '300' })) await ui.page.fill(`#soa-${key}`, value);
const response = ui.page.waitForResponse((r) => r.request().method() === 'PUT' && new URL(r.url()).pathname.endsWith('/soa'));
await ui.page.locator('#soa-form button[type=submit]').click();
expect((await response).status()).toBe(200);
await ui.settle();
expect((await world.db.recordById(subId))?.name).toBe('');
await ui.expectRow({ name: '@', type: 'SOA' });
expect((await api.get(`${zp(zone)}/check`)).json.problems.filter((p: { severity: string }) => p.severity === 'error')).toEqual([]);
for (const original of baseline.filter((r) => r.id !== soa.id)) expect(await world.db.recordById(original.id)).toEqual(original);
await servedZone(world, zone);
});
test('7. users and delegation: roles, zone visibility, revocation, promotion, deletion and the last active admin', async ({ world }) => {
test.setTimeout(600_000);
zoneB = `${world.unique('second-')}.core.test.`;
@@ -990,7 +1040,7 @@ test.describe('core flow', () => {
const zc = findAudit(await auditSince(world, cmark), 'zone_create', 201);
const removed = JSON.stringify(parsedJson(ZONE_CREATE_DELEGATIONS_IN === 'before' ? zc.before_value : [zc.before_value, zc.after_value]));
expect(removed, 'the creation audit row lists the removed delegations').toContain(user2.username);
if (REVIEW_FIXES) expect(JSON.stringify(parsedJson(zc.after_value)), 'removed delegations are not in after').not.toContain(`"username":"${user2.username}"`);
expect(JSON.stringify(parsedJson(zc.after_value)), 'removed delegations are not in after').not.toContain(`"username":"${user2.username}"`);
await waitForZone(world.g, zoneD, { recorder: world.recorder });
await servedZone(world, zoneD);
});