Files
coredns-web-ui/e2e/tests/power.spec.ts
T
bryanpedini 9251c85fd8 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
2026-11-19 15:46:12 +01:00

116 lines
6.3 KiB
TypeScript

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 Bryan Joshua Pedini
import { test, expect } from '../harness/fixtures';
import { up, zp } from '../harness/api';
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';
test.use({ group: 'power' });
test('a power user operates a large installation, with restart and edit conflicts', async ({ world }, info) => {
test.setTimeout(240_000);
const admin = await world.bootstrapAdmin();
const api = await world.apiAs(admin);
const zones = Array.from({ length: 24 }, (_, i) => world.zoneName(`z${i}-`));
for (const zone of zones) await createZone(api, zone);
for (let i = 0; i < 24; i++) {
const account = await world.createUser(api, 'user');
for (const zone of [zones[i], zones[(i + 1) % zones.length]]) {
expect((await api.put(`${zp(zone)}${up(account.username)}`)).status).toBe(204);
}
}
const [large, imports] = zones;
await world.db.insertMany(Array.from({ length: 9998 }, (_, i) => ({
zone: large, name: `seed-${String(i).padStart(4, '0')}`, ttl: 300, record_type: 'A',
content: JSON.stringify({ ip: `192.0.2.${i % 254 + 1}` }),
})));
const first = await world.uiAs(admin);
const second = await world.uiAs(admin);
const startZones = performance.now();
await first.page.goto('/');
await expect(first.page.getByRole('link', { name: large, exact: true })).toBeVisible();
const zonesMs = performance.now() - startZones;
const startZone = performance.now();
await first.page.getByRole('link', { name: large, exact: true }).click();
await expect(first.page.getByRole('rowheader', { name: 'seed-0000', exact: true })).toBeVisible();
const editButton = first.page.getByRole('row', { name: /seed-0000/ }).getByRole('button', { name: /^Edit / });
await editButton.click();
await expect(first.page.locator('#rec-f-ip')).toHaveValue('192.0.2.1');
const editMs = performance.now() - startZone;
await info.attach('performance.json', {
body: JSON.stringify({ zones: zones.length, records: 10000, zonesMs, editMs, budgetMs: 2000 }),
contentType: 'application/json',
});
expect(zonesMs, 'zones page renders its links within 2 seconds').toBeLessThan(2000);
expect(editMs, '10,000-record zone is interactive within 2 seconds').toBeLessThan(2000);
await second.openZone(large);
await second.openEdit({ name: 'seed-0000', type: 'A' });
await restartWithSessions(world, first, second);
expect((await api.get('/account')).json.username).toBe(admin.username);
const submit = async (ui: typeof first, ip: string) => {
await ui.page.fill('#rec-f-ip', ip);
const response = ui.page.waitForResponse((res) => res.request().method() === 'PUT' && /\/records\/\d+$/.test(new URL(res.url()).pathname));
await ui.page.click('#rec-submit');
return (await response).status();
};
const change = await begin(world, large);
expect(await submit(first, '192.0.2.240')).toBe(200);
expect(await submit(second, '192.0.2.241')).toBe(412);
await second.page.getByRole('button', { name: 'Reload', exact: true }).click();
await waitForZone(world.g, large, { recorder: world.recorder });
await threeWay(world, first, large, address('seed-0000', '192.0.2.240'), change, 'first editor wins');
await second.expectRow({ name: 'seed-0000', type: 'A', value: '192.0.2.240' });
expect(await world.db.recordCount()).toBe(10000 + 23 * 2);
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';
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));
await first.openZone(imports);
await waitForZone(world.g, imports, { recorder: world.recorder });
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(batch.code, batch.stderr).toBe(0);
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(),
);
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([]);
});
test('a power user imports the supported types in one transaction', async ({ world }) => {
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');
const ui = await world.uiAs(admin);
const soa = zoneInput(zone);
const entries = [
['@', 'SOA', `${soa.ns} ${soa.mbox} 0 3600 600 604800 300`],
['@', 'NS', 'ns2.example.net.'],
['www', 'AAAA', '2001:db8::50'],
['*.alias', 'CNAME', `www.${zone}`],
['@', 'MX', '0 .'],
['@', 'TXT', '"test"'],
['_tcp._svc', 'SRV', '0 0 0 .'],
['@', 'CAA', '0 issue "ca.example.net"'],
];
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']);
await servedZone(world, zone);
});