diff options
author | 2017-06-21 23:46:20 -0700 | |
---|---|---|
committer | 2017-06-21 23:46:20 -0700 | |
commit | 9fb266aebeabf626d9b34659cd96b31e4111a600 (patch) | |
tree | 431f688b56add4c9f498283e607cbe8a3a957c7f /test | |
parent | 9e463e0bca3f7c4275150dd36d1d4a020293ff90 (diff) | |
download | coredns-9fb266aebeabf626d9b34659cd96b31e4111a600.tar.gz coredns-9fb266aebeabf626d9b34659cd96b31e4111a600.tar.zst coredns-9fb266aebeabf626d9b34659cd96b31e4111a600.zip |
middleware/secondary: multiple fixes (#745)
Fix transferring the zone from a master and the matching of notifies
to source and dst IP addresses.
Add `upstream` keyword as well, because it is needed for the same
reasons as in the *file* middlware.
Add some dire warning about upstream in the readme of both middlewares.
Out of band testing, hidden by net build tag was added. Integration
testing still needs to be setup.
Diffstat (limited to 'test')
-rw-r--r-- | test/secondary_net_test.go | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/test/secondary_net_test.go b/test/secondary_net_test.go new file mode 100644 index 000000000..451195442 --- /dev/null +++ b/test/secondary_net_test.go @@ -0,0 +1,126 @@ +// +build net + +package test + +import ( + "testing" + + "github.com/miekg/dns" +) + +func TestSecondaryZoneTransfer(t *testing.T) { + /* + Test will only work when there is a CoreDNS running on part 32054 + with example.com and willing to transfer + coredns -conf Corefile -dns.port 32054 + Corefile: + example.com { + file example.com { + transfer to 127.0.0.1:32053 + } + } + example.com: + example.com. 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042730 7200 3600 1209600 3600 + + example.com. 65118 IN NS a.iana-servers.net. + example.com. 65118 IN NS b.iana-servers.net. + cname.example.com. 434334 IN CNAME a.miek.nl. + */ + + corefile := `example.com:32053 { + secondary { + transfer from 127.0.0.1:32054 + } + } + ` + + sec, err := CoreDNSServer(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + + defer sec.Stop() + + m := new(dns.Msg) + m.SetQuestion("cname.example.com.", dns.TypeCNAME) + + r, err := dns.Exchange(m, "127.0.0.1:32053") + if err != nil { + t.Fatalf("Expected to receive reply, but didn't: %s", err) + } + + if len(r.Answer) == 0 { + t.Fatalf("Expected answer section") + } + + if r.Answer[0].(*dns.CNAME).Target != "a.miek.nl." { + t.Fatalf("Expected target of %s, got %s", "a.miek.nl.", r.Answer[0].(*dns.CNAME).Target) + } + + m = new(dns.Msg) + m.SetQuestion("example.com.", dns.TypeSOA) + r, err = dns.Exchange(m, "127.0.0.1:32053") + if err != nil { + t.Fatalf("Expected to receive reply, but didn't: %s", err) + } + if len(r.Answer) == 0 { + t.Fatalf("Expected answer section") + } + if r.Answer[0].(*dns.SOA).Serial != 2017042730 { + t.Fatalf("Expected serial of %d, got %d", 2017042730, r.Answer[0].(*dns.SOA).Serial) + } +} + +func TestSecondaryZoneTransferUpstream(t *testing.T) { + /* + Test will only work when there is a CoreDNS running on part 32054 + with example.com and willing to transfer + coredns -conf Corefile -dns.port 32054 + Corefile: + example.com { + file example.com { + transfer to 127.0.0.1:32053 + } + } + example.com: + example.com. 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042730 7200 3600 1209600 3600 + + example.com. 65118 IN NS a.iana-servers.net. + example.com. 65118 IN NS b.iana-servers.net. + cname.example.com. 434334 IN CNAME a.miek.nl. + */ + + corefile := `example.com:32053 { + secondary { + transfer from 127.0.0.1:32054 + upstream 8.8.8.8 + } + } + ` + + sec, err := CoreDNSServer(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + + defer sec.Stop() + + m := new(dns.Msg) + m.SetQuestion("cname.example.com.", dns.TypeA) + + r, err := dns.Exchange(m, "127.0.0.1:32053") + if err != nil { + t.Fatalf("Expected to receive reply, but didn't: %s", err) + } + + if len(r.Answer) != 2 { + t.Fatalf("Expected answer section, with 2 records, got %d", len(r.Answer)) + } + + if r.Answer[0].(*dns.CNAME).Target != "a.miek.nl." { + t.Fatalf("Expected target of %s, got %s", "a.miek.nl.", r.Answer[0].(*dns.CNAME).Target) + } + if r.Answer[1].Header().Name != "a.miek.nl." { + t.Fatalf("Expected name of %s, got %s", "a.miek.nl.", r.Answer[1].Header().Name) + } +} |