refactor(api): use audit operation constants and the shared zone not found error in zone handlers
- refactor(api): use audit operation constants and the shared zone not found error in zone handlers - fix(api): return the stored content of rows with check errors - fix(api): return warnings from record deletes, zone creation and import apply - fix(api): allow repairing rows stored with a non canonical zone and invalid SOA sets - fix(check): accept JSON column formatting and an absent SOA serial as canonical content - fix(ui): match audit diff items by identity instead of array index - fix(ui): count the SOA change once, report import warnings and check the request size - fix(ui): edit the selected SOA row, keep the server order, show error rows raw and report write warnings - test(check): cover triggering and clean pairs with exact codes and record ids - test(records): cover SRV port, SOA timer and CAA value boundaries - test(cli): check the exact check output and the exit code of warning-only zones - refactor(import): order current rows with cmp.Compare - test(check): cover malformed stored content and a mailbox stored as an address - test(api): cover zone write failure paths, ambiguous SOA updates and unchanged record detection
This commit is contained in:
1 parent
53444bec7a
commit
a7ba01fc77
21 files changed
+1315
-170
No files matched your search
+27
-5
@@ -6,6 +6,15 @@ import { $, ApiError, api, appData, busy, clear, clearErrors, flash, formatTTL,
|
||||
const { zone } = appData();
|
||||
const base = zonePath(zone);
|
||||
const state = { fingerprint: null, mode: "merge", content: "" };
|
||||
const MAX_REQUEST_BYTES = 2 * 1024 * 1024;
|
||||
|
||||
function requestBytes(mode, content) {
|
||||
return new TextEncoder().encode(JSON.stringify({ mode, content, fingerprint: "0".repeat(64) })).length;
|
||||
}
|
||||
|
||||
function tooLarge(mode, content) {
|
||||
return requestBytes(mode, content) > MAX_REQUEST_BYTES;
|
||||
}
|
||||
|
||||
function entryTable(title, entries, withOld) {
|
||||
if (!entries || entries.length === 0) return null;
|
||||
@@ -56,7 +65,7 @@ function showPreview(data) {
|
||||
const skipped = data.skipped || [];
|
||||
summary.append(h("p", { text: plural(added.length, "addition", "additions") + ", " + plural(updated.length, "update", "updates") + ", " + plural(deleted.length, "deletion", "deletions") + ", " + (data.unchanged || 0) + " unchanged, " + plural(skipped.length, "skipped entry", "skipped entries") + "." }));
|
||||
if (data.soa) {
|
||||
summary.append(h("p", { text: "The SOA record is replaced: " + data.soa.ns + " " + data.soa.mbox + " refresh " + data.soa.refresh + " retry " + data.soa.retry + " expire " + data.soa.expire + " minimum " + data.soa.minttl + " TTL " + formatTTL(data.soa.ttl) + "." }));
|
||||
summary.append(h("p", { text: "One of the updates replaces the SOA record: " + data.soa.ns + " " + data.soa.mbox + " refresh " + data.soa.refresh + " retry " + data.soa.retry + " expire " + data.soa.expire + " minimum " + data.soa.minttl + " TTL " + formatTTL(data.soa.ttl) + "." }));
|
||||
}
|
||||
for (const warning of data.warnings || []) {
|
||||
summary.append(h("p", { class: "alert alert-warn", text: (warning.line ? "Line " + warning.line + ": " : "") + warning.message }));
|
||||
@@ -67,7 +76,7 @@ function showPreview(data) {
|
||||
if (node) tables.append(node);
|
||||
}
|
||||
state.fingerprint = data.fingerprint;
|
||||
const total = added.length + updated.length + deleted.length + (data.soa ? 1 : 0);
|
||||
const total = added.length + updated.length + deleted.length;
|
||||
$("#import-apply").hidden = total === 0;
|
||||
if (total === 0) summary.append(h("p", { class: "muted", text: "Nothing to apply." }));
|
||||
}
|
||||
@@ -86,6 +95,10 @@ async function preview(event) {
|
||||
showFieldErrors(form, { content: "Paste a zone file or load one." });
|
||||
return;
|
||||
}
|
||||
if (tooLarge(input.mode, input.content)) {
|
||||
showFieldErrors(form, { content: "The zone file is too large: an import request is limited to 2 MiB." });
|
||||
return;
|
||||
}
|
||||
await busy($("#import-preview"), async () => {
|
||||
try {
|
||||
const { data } = await api("POST", base + "/import/preview", { body: input });
|
||||
@@ -112,7 +125,9 @@ async function apply() {
|
||||
await busy($("#import-apply"), async () => {
|
||||
try {
|
||||
const { data } = await api("POST", base + "/import/apply", { body: { mode: state.mode, content: state.content, fingerprint: state.fingerprint } });
|
||||
flash("Import applied: " + plural(data.added || 0, "addition", "additions") + ", " + plural(data.updated || 0, "update", "updates") + ", " + plural(data.deleted || 0, "deletion", "deletions") + ".");
|
||||
const warnings = Array.isArray(data.warnings) ? data.warnings : [];
|
||||
const notes = warnings.map((warning) => (warning.line ? "line " + warning.line + ": " : "") + warning.message);
|
||||
flash("Import applied: " + plural(data.added || 0, "addition", "additions") + ", " + plural(data.updated || 0, "update", "updates") + ", " + plural(data.deleted || 0, "deletion", "deletions") + "." + (notes.length ? " Warnings: " + notes.join("; ") + "." : ""));
|
||||
location.assign("/zones/" + encodeURIComponent(zone));
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.status === 409) {
|
||||
@@ -136,11 +151,18 @@ $("#import-form").addEventListener("input", () => {
|
||||
$("#import-file").addEventListener("change", async (event) => {
|
||||
const file = event.target.files[0];
|
||||
if (!file) return;
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
if (file.size > MAX_REQUEST_BYTES) {
|
||||
toast("The file is larger than 2 MiB.", { kind: "error" });
|
||||
event.target.value = "";
|
||||
return;
|
||||
}
|
||||
$("#import-content").value = await file.text();
|
||||
const content = await file.text();
|
||||
if (tooLarge($("#import-form").elements.mode.value, content)) {
|
||||
toast("The file is too large: an import request, which encodes the file as JSON, is limited to 2 MiB.", { kind: "error" });
|
||||
event.target.value = "";
|
||||
return;
|
||||
}
|
||||
$("#import-content").value = content;
|
||||
$("#import-apply").hidden = true;
|
||||
state.fingerprint = null;
|
||||
});
|
||||
Reference in new issue
Block a user