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
@@ -4,7 +4,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -102,7 +104,7 @@ func checkRecord(row recordRow, now time.Time) []zoneProblem {
|
||||
if soa, ok := decoded.data.(soaData); ok && soa.Serial == 0 && fields["serial"] == "" {
|
||||
warn("soa_dynamic_serial", "SOA uses a dynamic Unix time serial")
|
||||
}
|
||||
if canonical, _ := encodeRecord(normalized); len(fields) == 0 && canonical != row.Content.String {
|
||||
if canonical, _ := encodeRecord(normalized); len(fields) == 0 && !canonicalContent(row.Content.String, canonical) {
|
||||
warn("content_not_canonical", "stored content differs from its canonical form")
|
||||
}
|
||||
if decoded.decodeErr == nil && row.TTL.Valid && row.TTL.Int64 >= 0 && row.TTL.Int64 <= int64(^uint32(0)) {
|
||||
@@ -114,6 +116,60 @@ func checkRecord(row recordRow, now time.Time) []zoneProblem {
|
||||
return problems
|
||||
}
|
||||
|
||||
type contentMember struct {
|
||||
key string
|
||||
value any
|
||||
}
|
||||
|
||||
func contentMembers(content string) ([]contentMember, bool) {
|
||||
decoder := json.NewDecoder(strings.NewReader(content))
|
||||
decoder.UseNumber()
|
||||
if token, err := decoder.Token(); err != nil || token != json.Delim('{') {
|
||||
return nil, false
|
||||
}
|
||||
var members []contentMember
|
||||
for decoder.More() {
|
||||
key, err := decoder.Token()
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
value, err := decoder.Token()
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
if _, nested := value.(json.Delim); nested {
|
||||
return nil, false
|
||||
}
|
||||
members = append(members, contentMember{key.(string), value})
|
||||
}
|
||||
if _, err := decoder.Token(); err != nil {
|
||||
return nil, false
|
||||
}
|
||||
if _, err := decoder.Token(); err != io.EOF {
|
||||
return nil, false
|
||||
}
|
||||
return members, true
|
||||
}
|
||||
|
||||
func canonicalContent(stored, canonical string) bool {
|
||||
if stored == canonical {
|
||||
return true
|
||||
}
|
||||
have, ok := contentMembers(stored)
|
||||
want, _ := contentMembers(canonical)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if last := len(want) - 1; last >= 0 && want[last].key == "serial" && want[last].value == json.Number("0") &&
|
||||
!slices.ContainsFunc(have, func(m contentMember) bool { return m.key == "serial" }) {
|
||||
want = want[:last]
|
||||
}
|
||||
mysqlOrder := slices.SortedStableFunc(slices.Values(want), func(a, b contentMember) int {
|
||||
return cmp.Or(cmp.Compare(len(a.key), len(b.key)), strings.Compare(a.key, b.key))
|
||||
})
|
||||
return slices.Equal(have, want) || slices.Equal(have, mysqlOrder)
|
||||
}
|
||||
|
||||
func hasContentKey(object map[string]json.RawMessage, key string) bool {
|
||||
for name := range object {
|
||||
if strings.EqualFold(name, key) {
|
||||
|
||||
Reference in new issue
Block a user