From 852eb25558c61e65e367b5811edf6084e494ff9c Mon Sep 17 00:00:00 2001 From: Cesar Kuroiwa Date: Wed, 31 Jan 2024 11:15:12 -0300 Subject: [PATCH] Test xfr via TLS --- xfr_test.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/xfr_test.go b/xfr_test.go index f6c5e98cc..7574329ba 100644 --- a/xfr_test.go +++ b/xfr_test.go @@ -1,6 +1,7 @@ package dns import ( + "crypto/tls" "testing" "time" ) @@ -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.") @@ -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)