Align DNS zone projection order
This commit is contained in:
parent
fc3d05c557
commit
0832a0c396
2 changed files with 33 additions and 2 deletions
|
|
@ -461,8 +461,8 @@ func (r *Resource) GetToTXT(name string) []TXTRecord {
|
|||
|
||||
// ToZone projects the resource into zone-order records.
|
||||
//
|
||||
// Authority-like records are emitted first in original order, with duplicate NS
|
||||
// targets collapsed. Glue records for in-zone hosts are appended last.
|
||||
// Records are emitted in their original order, with duplicate NS targets
|
||||
// collapsed. Glue records for in-zone hosts are appended last.
|
||||
func (r *Resource) ToZone(name string) []ResourceRecord {
|
||||
if r == nil {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -507,6 +507,37 @@ func TestResourceProjectionHelpers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResourceToZonePreservesOriginalOrder(t *testing.T) {
|
||||
resource := NewResource()
|
||||
resource.Records = []ResourceRecord{
|
||||
TXTRecord{Entries: []string{"first"}},
|
||||
DSRecord{KeyTag: 7, Algorithm: 8, DigestType: 9, Digest: []byte{0xaa}},
|
||||
NSRecord{NS: "ns1.example."},
|
||||
GLUE4Record{NS: "ns1.example.", Address: netip.MustParseAddr("192.0.2.10")},
|
||||
}
|
||||
|
||||
zone := resource.ToZone("example.")
|
||||
if len(zone) != 4 {
|
||||
t.Fatalf("ToZone returned %d records, want 4", len(zone))
|
||||
}
|
||||
|
||||
if rr, ok := zone[0].(TXTRecord); !ok || len(rr.Entries) != 1 || rr.Entries[0] != "first" {
|
||||
t.Fatalf("ToZone[0] = %#v, want TXT first", zone[0])
|
||||
}
|
||||
|
||||
if rr, ok := zone[1].(DSRecord); !ok || rr.KeyTag != 7 {
|
||||
t.Fatalf("ToZone[1] = %#v, want DS record", zone[1])
|
||||
}
|
||||
|
||||
if rr, ok := zone[2].(NSRecord); !ok || rr.NS != "ns1.example." {
|
||||
t.Fatalf("ToZone[2] = %#v, want NS ns1.example.", zone[2])
|
||||
}
|
||||
|
||||
if rr, ok := zone[3].(GLUE4Record); !ok || rr.NS != "ns1.example." || rr.Address.String() != "192.0.2.10" {
|
||||
t.Fatalf("ToZone[3] = %#v, want GLUE4 ns1.example./192.0.2.10", zone[3])
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceToDNSAndReferral(t *testing.T) {
|
||||
resource := NewResource()
|
||||
resource.Records = []ResourceRecord{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue