- test(e2e): add playwright harness and test stack - test(e2e): add core flow - fix(ui): preserve same-origin browser form submissions - fix(ui): offer reload inside stale edit dialogs - test(e2e): add persona session and accessibility suites - test(e2e): preserve per-run artifacts and clean pulled images - test(e2e): verify import and audit state across navigation - test(e2e): tighten verification helpers and persona checks - test(e2e): bound response body reads of the browser observer - test: recover review compatibility assertions - test: stabilize audit and user flow assertions
73 lines
3.7 KiB
TypeScript
73 lines
3.7 KiB
TypeScript
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
|
|
|
import { test, expect } from '../harness/fixtures';
|
|
import type { RecordInput } from '../harness/ui';
|
|
import { up } from '../harness/api';
|
|
import { addAddress, checkZone, createZone } from '../harness/personas';
|
|
|
|
test.use({ group: 'stupid' });
|
|
|
|
test('operator mistakes preserve DNS, user records and delegations', async ({ world }) => {
|
|
const admin = await world.bootstrapAdmin();
|
|
const api = await world.apiAs(admin);
|
|
const ui = await world.uiAs(admin);
|
|
const zone = world.zoneName();
|
|
const zonePath = await createZone(api, zone);
|
|
await addAddress(api, zonePath, 'www', '192.0.2.10');
|
|
await ui.openZone(zone);
|
|
const before = await world.db.records(zone);
|
|
const wrongRecords: RecordInput[] = [
|
|
{ name: 'v6', type: 'A', fields: { ip: '2001:db8::1' } },
|
|
{ name: 'www..', type: 'A', fields: { ip: '192.0.2.8' } },
|
|
{ name: '@', type: 'CNAME', fields: { host: 'elsewhere.example.net' } },
|
|
{ name: 'www', type: 'CNAME', fields: { host: 'elsewhere.example.net.' } },
|
|
];
|
|
for (const entry of wrongRecords) {
|
|
await ui.addRecord({ ...entry, ttl: '300' }, { expectStatus: 422 });
|
|
await expect(ui.page.locator('#record-dialog')).toBeVisible();
|
|
await ui.page.keyboard.press('Escape');
|
|
}
|
|
const soa = (await api.get(zonePath)).json.soa;
|
|
expect((await api.delete(`${zonePath}/records/${soa.id}`, undefined, { ifMatch: soa.etag })).status).toBe(422);
|
|
const ns = (await api.get(`${zonePath}/records`)).json.records.find((r: { type: string }) => r.type === 'NS');
|
|
expect((await api.delete(`${zonePath}/records/${ns.id}`, undefined, { ifMatch: ns.etag })).status).toBe(422);
|
|
expect(await world.db.records(zone)).toEqual(before);
|
|
|
|
await ui.page.click('#record-add');
|
|
await ui.page.fill('#rec-name', `www.${zone.slice(0, -1)}`);
|
|
await expect(ui.page.locator('#rec-fqdn')).toContainText(`www.${zone}${zone}`);
|
|
await ui.page.fill('#rec-name', 'double');
|
|
await ui.page.fill('#rec-f-ip', '192.0.2.20');
|
|
const mark = await world.db.auditMaxId();
|
|
const response = ui.page.waitForResponse((res) => res.url().endsWith(`/api/v1${zonePath}/records`) && res.request().method() === 'POST');
|
|
await ui.page.locator('#rec-submit').evaluate((button: HTMLButtonElement) => {
|
|
button.click();
|
|
button.click();
|
|
});
|
|
expect((await response).status()).toBe(201);
|
|
await ui.settle();
|
|
expect((await world.db.auditSince(mark)).filter((row) => row.operation === 'record_create')).toHaveLength(1);
|
|
await checkZone(world, api, zone);
|
|
|
|
const member = await world.createUser(api, 'user');
|
|
expect((await api.post('/users', { username: 'short-password', role: 'user', password: world.secrets.register('tiny', 'short password') })).status).toBe(422);
|
|
await ui.openUser(member.username);
|
|
expect(await ui.deleteUserUi(member.username, 'another-user')).toBeNull();
|
|
expect((await ui.deleteUserUi(member.username))?.status).toBe(204);
|
|
await ui.page.goBack();
|
|
await ui.settle();
|
|
expect((await world.db.user(member.username))?.deleted_at).not.toBeNull();
|
|
expect((await api.post('/users', { ...member })).status).toBe(409);
|
|
expect((await api.put(`${up(admin.username)}/role`, { role: 'user' })).status).toBe(403);
|
|
expect((await api.delete(up(admin.username), { confirm: admin.username })).status).toBe(403);
|
|
expect((await api.put(`${zonePath}${up(admin.username)}`)).status).toBe(422);
|
|
await ui.openZone(zone);
|
|
expect(await ui.deleteZoneUi('wrong.example.net.')).toBeNull();
|
|
expect((await ui.deleteZoneUi(zone))?.status).toBe(204);
|
|
await ui.page.goBack();
|
|
await expect(ui.page.locator('#records-body tr')).toHaveCount(0);
|
|
expect((await api.get(zonePath)).status).toBe(404);
|
|
expect(await world.db.records(zone)).toEqual([]);
|
|
});
|