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,6 +4,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -74,3 +76,69 @@ func TestZoneRuleWarnings(t *testing.T) {
|
||||
t.Fatalf("clean zone reported %+v %+v", problems, warnings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateZoneChangePairs(t *testing.T) {
|
||||
a := func(id int64, name string, ttl int64, ip string) recordRow {
|
||||
return modelRawRow(id, name, "A", ttl, `{"ip":"`+ip+`"}`)
|
||||
}
|
||||
txt := func(size int) recordRow {
|
||||
return modelRawRow(5, "text", "TXT", 3600, `{"text":"`+strings.Repeat("x", size)+`"}`)
|
||||
}
|
||||
cut := modelRawRow(4, "sub", "NS", 3600, `{"host":"ns.example.net."}`)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
current []recordRow
|
||||
triggered, control zoneChanges
|
||||
problems, warnings []modelFinding
|
||||
}{
|
||||
{"same canonical identity", append(modelBaseZone(), a(3, "www", 3600, "192.0.2.1")),
|
||||
zoneChanges{Creates: []recordRow{modelRawRow(5, "www", "A", 3600, `{"ip": "192.0.2.1"}`)}},
|
||||
zoneChanges{Creates: []recordRow{a(5, "www", 3600, "192.0.2.2")}},
|
||||
[]modelFinding{{3, "error", "duplicate"}, {5, "error", "duplicate"}}, nil},
|
||||
{"different TTL in an RRset", append(modelBaseZone(), a(3, "www", 3600, "192.0.2.1")),
|
||||
zoneChanges{Creates: []recordRow{a(5, "www", 60, "192.0.2.2")}},
|
||||
zoneChanges{Creates: []recordRow{a(5, "www", 3600, "192.0.2.2")}},
|
||||
nil, []modelFinding{{3, "warning", "rrset_ttl_mismatch"}, {5, "warning", "rrset_ttl_mismatch"}}},
|
||||
{"below a zone cut", append(modelBaseZone(), cut),
|
||||
zoneChanges{Creates: []recordRow{a(5, "host.sub", 3600, "192.0.2.1")}},
|
||||
zoneChanges{Creates: []recordRow{a(5, "sub", 3600, "192.0.2.1")}},
|
||||
nil, []modelFinding{{5, "warning", "below_zone_cut"}}},
|
||||
{"TXT of 256 bytes", modelBaseZone(),
|
||||
zoneChanges{Creates: []recordRow{txt(256)}}, zoneChanges{Creates: []recordRow{txt(255)}},
|
||||
nil, []modelFinding{{5, "warning", "txt_split"}}},
|
||||
{"in-zone CNAME target", append(modelBaseZone(), modelRawRow(3, "alias", "CNAME", 3600, `{"host":"www.example.net."}`)),
|
||||
zoneChanges{Creates: []recordRow{modelRawRow(5, "", "MX", 3600, `{"host":"alias.example.org.","preference":10}`)}},
|
||||
zoneChanges{Creates: []recordRow{modelRawRow(5, "", "MX", 3600, `{"host":"mail.example.net.","preference":10}`)}},
|
||||
nil, []modelFinding{{5, "warning", "target_is_cname"}, {5, "warning", "target_no_address"}}},
|
||||
{"SOA moved below the apex", modelBaseZone(),
|
||||
zoneChanges{SOAUpdate: &recordRow{ID: 1, Name: "sub", RecordType: "SOA"}},
|
||||
zoneChanges{SOAUpdate: &recordRow{ID: 1, RecordType: "SOA"}},
|
||||
[]modelFinding{{1, "error", "soa_not_apex"}}, nil},
|
||||
{"extra SOA deleted", append(modelBaseZone(), modelRawRow(3, "", "SOA", 3600, strings.Replace(modelSOAContent, "ns.example.net.", "ns2.example.net.", 1))),
|
||||
zoneChanges{Creates: []recordRow{a(5, "www", 3600, "192.0.2.1")}},
|
||||
zoneChanges{Deletes: []int64{3}},
|
||||
[]modelFinding{{1, "error", "soa_multiple"}, {3, "error", "soa_multiple"}}, nil},
|
||||
{"non-apex SOA moved to the apex", []recordRow{modelRawRow(1, "sub", "SOA", 3600, modelSOAContent), modelBaseZone()[1]},
|
||||
zoneChanges{Creates: []recordRow{a(5, "www", 3600, "192.0.2.1")}},
|
||||
zoneChanges{SOAUpdate: &recordRow{ID: 1, RecordType: "SOA", Content: sql.NullString{String: modelSOAContent, Valid: true}}},
|
||||
[]modelFinding{{1, "error", "soa_not_apex"}}, nil},
|
||||
{"last SOA deleted", []recordRow{modelRawRow(1, "sub", "SOA", 3600, modelSOAContent), modelBaseZone()[1]},
|
||||
zoneChanges{Deletes: []int64{1}},
|
||||
zoneChanges{SOAUpdate: &recordRow{ID: 1, RecordType: "SOA", Content: sql.NullString{String: modelSOAContent, Valid: true}}},
|
||||
[]modelFinding{{0, "error", "soa_missing"}, {1, "error", "soa_delete"}}, nil},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
problems, warnings := validateZoneChanges("example.org.", tc.current, tc.triggered)
|
||||
if got := modelFindings(problems); !slices.Equal(got, tc.problems) {
|
||||
t.Errorf("problems: got %v, want %v", got, tc.problems)
|
||||
}
|
||||
if got := modelFindings(warnings); !slices.Equal(got, tc.warnings) {
|
||||
t.Errorf("warnings: got %v, want %v", got, tc.warnings)
|
||||
}
|
||||
problems, warnings = validateZoneChanges("example.org.", tc.current, tc.control)
|
||||
if len(problems)+len(warnings) != 0 {
|
||||
t.Errorf("control: problems %v, warnings %v", modelFindings(problems), modelFindings(warnings))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user