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:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 53444bec7a
commit a7ba01fc77
21 files changed
+1315 -170

No files matched your search

+83 -2
View File
@@ -165,7 +165,7 @@ func TestIntegrationZoneAPIHandlers(t *testing.T) {
t.Fatalf("update audit values: %s, %s", audit.Before, audit.After)
}
it.call(t, user, "record_delete", id, updated.Header.Get("ETag"), "", 204)
it.call(t, user, "record_delete", id, updated.Header.Get("ETag"), "", 200)
it.serial(t, serial+3)
var deletes []map[string]any
for _, name := range []string{"one", "two"} {
@@ -312,7 +312,88 @@ func TestIntegrationZoneAPIJSONColumnETags(t *testing.T) {
}
it.audit(t, "record_update", 1)
it.serial(t, newSOASerial(modelNow)+2)
it.call(t, admin, "record_delete", id, newTag, "", 204)
it.call(t, admin, "record_delete", id, newTag, "", 200)
if check := zoneAPITestJSON(t, it.call(t, admin, "zone_check", "", "", "", 200).Body); check != `{"problems":[]}` {
t.Fatalf("JSON column rows reported as not canonical: %s", check)
}
soa := zoneAPIFindSOA(it.rows(t))
if !strings.Contains(soa.Content.String, `"retry": 600, "expire"`) {
t.Fatalf("MySQL did not reformat the SOA content: %s", soa.Content.String)
}
}
func TestIntegrationZoneAPIRepairs(t *testing.T) {
it := newITZoneAPI(t)
admin := it.admin
it.call(t, admin, "zone_create", "", "", zoneAPITestCreate, 201)
tables := it.server.tables
insert := func(zone, name, recordType, content string) int64 {
id, err := it.db.rootExec(t, tables.sql("INSERT INTO {records} (`zone`, `name`, `ttl`, `content`, `record_type`) VALUES (?, ?, 60, ?, ?)"),
zone, name, content, recordType).LastInsertId()
if err != nil {
t.Fatal(err)
}
return id
}
undotted := insert("example.org", "undotted", "A", `{"ip":"192.0.2.1"}`)
upper := insert("EXAMPLE.ORG.", "upper", "A", `{"ip":"192.0.2.2"}`)
insert("ex\u00e4mple.org.", "accent", "A", `{"ip":"192.0.2.3"}`)
insert("example.org..", "dots", "A", `{"ip":"192.0.2.4"}`)
insert("sub.example.org.", "", "A", `{"ip":"192.0.2.5"}`)
zones, err := it.records.ListZones(t.Context())
if err != nil || len(zones) != 4 || zones[0].Zone != zoneAPITestName || zones[0].RecordCount != 5 || !zones[0].SOAContent.Valid ||
zones[1].Zone != "example.org.." || zones[2].Zone != "ex\u00e4mple.org." || zones[3].Zone != "sub.example.org." {
t.Fatalf("zones = %+v, %v", zones, err)
}
it.grant(t, zoneAPITestName)
mine, err := it.records.ListZonesOfUser(t.Context(), it.user.ID)
if err != nil || len(mine) != 1 || mine[0].Zone != zoneAPITestName || mine[0].RecordCount != 5 {
t.Fatalf("delegated zones = %+v, %v", mine, err)
}
if exists, err := it.records.ZoneExists(t.Context(), "example.org."); !exists || err != nil {
t.Fatal(exists, err)
}
rows := it.rows(t)
if len(rows) != 5 {
t.Fatalf("zone rows = %+v", rows)
}
for _, id := range []int64{undotted, upper} {
current, err := it.records.RecordByID(t.Context(), id)
if err != nil {
t.Fatal(err)
}
body := zoneAPITestJSON(t, map[string]any{"name": current.Name, "type": "A", "ttl": 60, "data": json.RawMessage(current.Content.String)})
it.call(t, it.user, "record_update", strconv.FormatInt(id, 10), recordETag(current), body, 200)
repaired, err := it.records.RecordByID(t.Context(), id)
if err != nil || repaired.Zone != zoneAPITestName {
t.Fatalf("record %d not repaired: %+v, %v", id, repaired, err)
}
}
it.serial(t, newSOASerial(modelNow)+2)
soa := zoneAPIFindSOA(it.rows(t))
extra := insert(zoneAPITestName, "below", "SOA", strings.Replace(soa.Content.String, "ns.example.net.", "other.example.net.", 1))
it.call(t, admin, "record_create", "", "", zoneAPITestRecord, 422)
stored, err := it.records.RecordByID(t.Context(), extra)
if err != nil {
t.Fatal(err)
}
it.call(t, admin, "soa_update", "", recordETag(stored), strings.Replace(zoneAPITestSOA, "ns.example.net", "other.example.net", 1), 200)
it.call(t, admin, "record_delete", strconv.FormatInt(soa.ID, 10), recordETag(soa), "", 200)
rows = it.rows(t)
final := zoneAPIFindSOA(rows)
if len(rows) != 5 || final.ID != extra || final.Name != "" {
t.Fatalf("SOA set not repaired: %+v", rows)
}
it.serial(t, newSOASerial(modelNow)+3)
if check := zoneAPITestJSON(t, it.call(t, admin, "zone_check", "", "", "", 200).Body); strings.Contains(check, `"severity":"error"`) {
t.Fatalf("errors after the repairs: %s", check)
}
it.call(t, admin, "zone_delete", "", "", `{"confirm":"example.org"}`, 204)
if n := it.db.count(t, tables.sql("SELECT COUNT(*) FROM {records}")); n != 3 {
t.Fatalf("zone delete left %d rows in total, want the 3 rows of other zones", n)
}
}
func TestIntegrationZoneAPIAuditRollback(t *testing.T) {