- 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
98 lines
4.3 KiB
TypeScript
98 lines
4.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 } from '../harness/api';
|
|
import { intEnv, ORIGIN2_URL } from '../harness/env';
|
|
import { address, checkZone, createZone, restartWithSessions } from '../harness/personas';
|
|
import { begin, expectBumped, storedRow, threeWay, threeWayGone } from '../harness/verify';
|
|
import { waitForZone } from '../harness/dig';
|
|
|
|
test.use({ group: 'operator' });
|
|
|
|
test('a long operator session preserves state and audit invariants through mixed actions', async ({ world }) => {
|
|
test.setTimeout(300_000);
|
|
const admin = await world.bootstrapAdmin();
|
|
const api = await world.apiAs(admin);
|
|
const ui = await world.uiAs(admin);
|
|
const member = await world.createUser(api, 'user');
|
|
const outsider = await world.apiAs(member);
|
|
const zone = world.zoneName();
|
|
const z = await createZone(api, zone);
|
|
const recordsPath = `${z}/records`;
|
|
await waitForZone(world.g, zone, { recorder: world.recorder });
|
|
await ui.openZone(zone);
|
|
const model = new Map<string, ReturnType<typeof address>>();
|
|
const initialMark = await world.db.auditMaxId();
|
|
const operations = ['browser-add', 'create', 'edit', 'delete', 'typo', 'cross-origin', 'random', 'private'] as const;
|
|
const rounds = Math.max(operations.length, intEnv('E2E_OPERATOR_ACTIONS', 64));
|
|
for (let i = 0; i < rounds; i++) {
|
|
const operation = i < operations.length ? operations[i] : world.rng.pick(operations);
|
|
const name = `node-${i}`;
|
|
const ip = `192.0.2.${world.rng.int(1, 254)}`;
|
|
const item = address(name, ip);
|
|
world.recorder.fuzzCases.push({ operation, item });
|
|
switch (operation) {
|
|
case 'browser-add': {
|
|
const change = await begin(world, zone);
|
|
await ui.addRecord({ ...item, ttl: '300', fields: { ip } }, { expectStatus: 201 });
|
|
await threeWay(world, ui, zone, item, change, operation);
|
|
model.set(name, item);
|
|
break;
|
|
}
|
|
case 'create': {
|
|
const change = await begin(world, zone);
|
|
expect((await api.post(recordsPath, item)).status).toBe(201);
|
|
await expectBumped(world, zone, change, operation);
|
|
model.set(name, item);
|
|
await ui.openZone(zone);
|
|
break;
|
|
}
|
|
case 'edit':
|
|
case 'delete': {
|
|
if (model.size === 0) break;
|
|
const current = world.rng.pick([...model.values()]);
|
|
const match = { name: current.name, type: current.type, value: current.data.ip };
|
|
const change = await begin(world, zone);
|
|
if (operation === 'edit') {
|
|
await ui.editRecord(match, { name: current.name, type: 'A', ttl: '301', fields: { ip } }, { expectStatus: 200 });
|
|
const replacement = address(current.name, ip, 301);
|
|
await threeWay(world, ui, zone, replacement, change, operation);
|
|
model.set(current.name, replacement);
|
|
} else {
|
|
expect((await ui.deleteRecord(match)).status).toBe(200);
|
|
await threeWayGone(world, ui, zone, current, change, operation);
|
|
model.delete(current.name);
|
|
}
|
|
break;
|
|
}
|
|
case 'typo':
|
|
expect((await api.post(recordsPath, address(name, '2001:db8::1'))).status).toBe(422);
|
|
break;
|
|
case 'cross-origin':
|
|
expect((await api.post(recordsPath, item, { origin: ORIGIN2_URL })).status).toBe(403);
|
|
break;
|
|
case 'random':
|
|
expect((await api.post(recordsPath, { ...item, ttl: world.rng.pick([-1, '0', 'NaN', 2 ** 31]) })).status).toBe(422);
|
|
break;
|
|
case 'private':
|
|
expect((await outsider.get(recordsPath)).status).toBe(404);
|
|
expect((await outsider.put(z + up(member.username))).status).toBe(403);
|
|
break;
|
|
}
|
|
if ((i + 1) % 8 === 0 || i + 1 === rounds) {
|
|
await world.ledger.settle();
|
|
await world.ledger.verify(`audit after ${i + 1} actions`);
|
|
const rows = await world.db.records(zone);
|
|
expect(rows).toHaveLength(model.size + 2);
|
|
for (const current of model.values()) await storedRow(world, zone, current);
|
|
await checkZone(world, api, zone);
|
|
expect((await world.db.auditSince(initialMark)).length).toBeGreaterThan(i / 2);
|
|
}
|
|
}
|
|
await restartWithSessions(world, ui);
|
|
expect((await api.get('/account')).status).toBe(200);
|
|
await ui.openZone(zone);
|
|
expect((await ui.rows()).filter(({ type }) => type === 'A')).toHaveLength(model.size);
|
|
});
|