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

+57
View File
@@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"slices"
"strings"
"testing"
"time"
@@ -255,3 +256,59 @@ func TestNewZoneRows(t *testing.T) {
}
}
}
func TestRecordFieldBoundaries(t *testing.T) {
soa := func(key string, value int64) string {
timers := map[string]int64{"refresh": 3600, "retry": 600, "expire": 604800, "minttl": 300}
timers[key] = value
return fmt.Sprintf(`{"ns":"ns.example.net.","MBox":"hostmaster.example.org.","refresh":%d,"retry":%d,"expire":%d,"minttl":%d}`,
timers["refresh"], timers["retry"], timers["expire"], timers["minttl"])
}
caa := func(value string) string {
encoded, _ := json.Marshal(value)
return `{"flag":0,"tag":"issue","value":` + string(encoded) + `}`
}
type boundary struct {
typ, name, content, field string
}
cases := []boundary{
{"SRV", "_sip._tcp", `{"priority":65535,"weight":65535,"port":65535,"target":"."}`, ""},
{"SRV", "_sip._tcp", `{"priority":0,"weight":0,"port":65536,"target":"."}`, "port"},
{"SRV", "_sip._tcp", `{"priority":0,"weight":0,"port":-1,"target":"."}`, "port"},
{"CAA", "", caa(" "), ""},
{"CAA", "", caa("~"), ""},
{"CAA", "", caa(" !\"#$%&'()*+,-./0123456789:;<=>?@AZ[]^_`az{|}~"), ""},
{"CAA", "", caa("\x1f"), "value"},
{"CAA", "", caa("\x7f"), "value"},
{"CAA", "", caa("a\\b"), "value"},
{"CAA", "", caa("a\tb"), "value"},
{"CAA", "", caa("é"), "value"},
}
for _, key := range []string{"refresh", "retry", "expire", "minttl"} {
cases = append(cases, boundary{"SOA", "", soa(key, 2147483647), ""}, boundary{"SOA", "", soa(key, 2147483648), key})
}
for _, tc := range cases {
t.Run(tc.typ+"/"+tc.content, func(t *testing.T) {
row, fields := validateRecord("example.org.", tc.name, tc.typ, 3600, json.RawMessage(tc.content), modelNow)
if tc.field == "" {
if len(fields) != 0 {
t.Fatalf("refused: %v", fields)
}
var want []modelFinding
if tc.typ == "SOA" {
want = []modelFinding{{0, "warning", "soa_dynamic_serial"}}
}
if got := modelFindings(checkRecord(row, modelNow)); !slices.Equal(got, want) {
t.Fatalf("check of an accepted record: %v, want %v", got, want)
}
if rr, err := recordRR(row, modelNow); err != nil || packRecordRR(rr) != nil {
t.Fatalf("accepted record does not pack: %v, %v", rr, err)
}
return
}
if len(fields) != 1 || fields[tc.field] == "" {
t.Fatalf("fields = %v, want only %q", fields, tc.field)
}
})
}
}