Skip to content

Commit

Permalink
Test xfr via TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Kuroiwa committed Jan 31, 2024
1 parent 9a65062 commit 852eb25
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions xfr_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dns

import (
"crypto/tls"
"testing"
"time"
)
Expand Down Expand Up @@ -87,6 +88,27 @@ func TestSingleEnvelopeXfr(t *testing.T) {
axfrTestingSuite(t, addrstr)
}

func TestSingleEnvelopeXfrTLS(t *testing.T) {
HandleFunc("miek.nl.", SingleEnvelopeXfrServer)
defer HandleRemove("miek.nl.")

cert, err := tls.X509KeyPair(CertPEMBlock, KeyPEMBlock)
if err != nil {
t.Fatalf("unable to build certificate: %v", err)
}

tlsConfig := tls.Config{
Certificates: []tls.Certificate{cert},
}
s, addrstr, _, err := RunLocalTLSServer(":0", &tlsConfig)
if err != nil {
t.Fatalf("unable to run test server: %s", err)
}
defer s.Shutdown()

axfrTestingSuiteTLS(t, addrstr)
}

func TestMultiEnvelopeXfr(t *testing.T) {
HandleFunc("miek.nl.", MultipleEnvelopeXfrServer)
defer HandleRemove("miek.nl.")
Expand Down Expand Up @@ -131,6 +153,38 @@ func axfrTestingSuite(t *testing.T, addrstr string) {
}
}

func axfrTestingSuiteTLS(t *testing.T, addrstr string) {
tr := new(Transfer)
m := new(Msg)
m.SetAxfr("miek.nl.")

tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
c, err := tr.InTLS(m, addrstr, tlsConfig)
if err != nil {
t.Fatal("failed to zone transfer in", err)
}

var records []RR
for msg := range c {
if msg.Error != nil {
t.Fatal(msg.Error)
}
records = append(records, msg.RR...)
}

if len(records) != len(xfrTestData) {
t.Fatalf("bad axfr: expected %v, got %v", records, xfrTestData)
}

for i, rr := range records {
if !IsDuplicate(rr, xfrTestData[i]) {
t.Fatalf("bad axfr: expected %v, got %v", records, xfrTestData)
}
}
}

func axfrTestingSuiteWithCustomTsig(t *testing.T, addrstr string, provider TsigProvider) {
tr := new(Transfer)
m := new(Msg)
Expand Down

0 comments on commit 852eb25

Please sign in to comment.