136 lines
7.8 KiB
TypeScript
136 lines
7.8 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, createZone, restartWithSessions, zoneInput } from '../harness/personas';
|
|
import { begin, expectBumped, servedZone, storedRow, threeWay, type Rec } 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 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));
|
|
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.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.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([]);
|
|
});
|
|
|
|
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();
|
|
await createZone(api, zone);
|
|
const ui = await world.uiAs(admin);
|
|
const soa = zoneInput(zone);
|
|
const replacementNS = 'ns3.example.net.';
|
|
const entries = [
|
|
['@', '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', '17 mail.example.net.'],
|
|
['@', 'TXT', '"test"'],
|
|
['_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);
|
|
});
|