aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2021-05-11 09:50:18 +0200
committerGravatar GitHub <noreply@github.com> 2021-05-11 09:50:18 +0200
commite42614edc5e69c923177bac00868e7336abca8ba (patch)
tree013ec331f53b4316a2a6ffbea3b6739256bc3ddd /test
parentfdfc9bcdd24f6861353a41b0cd630c7d82e1f868 (diff)
downloadcoredns-e42614edc5e69c923177bac00868e7336abca8ba.tar.gz
coredns-e42614edc5e69c923177bac00868e7336abca8ba.tar.zst
coredns-e42614edc5e69c923177bac00868e7336abca8ba.zip
reverse zones (#4538)
* core: fix v4 non-octet reverse zones This fixes the reverse zones handling. Add expanstion of the reverse notation to all octet boundary subnets and add those to the config - just as if they were directly typed in the config. This takes inspiration from #4501, but that (even with DCO!!) seems to be just using https://github.com/apparentlymart/go-cidr/ so use that instead - I think a minor function is still needed that one is copied from #4501. Also sort the zones we are listing on startup - caught in this PR because of the expanded zones being not listed next to each other. This also removes the need for FilterFunc from the config, so this is now gone as well, making the whole thing slightly more efficient. Add couple of reverse unit tests and a e2e test that queries for the correct (and incorrect) reverse zones and checks the reply. Closes: #4501 Fixes: #2779 Signed-off-by: Miek Gieben <miek@miek.nl> * Add more test cases Add test from origin bug report: #2779 Signed-off-by: Miek Gieben <miek@miek.nl> * Rebase and fix conflicts Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'test')
-rw-r--r--test/server_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/server_test.go b/test/server_test.go
index f03a27749..c58915ee7 100644
--- a/test/server_test.go
+++ b/test/server_test.go
@@ -53,3 +53,57 @@ func chaosTest(t *testing.T, server string) {
t.Fatalf("Expected version.bind. reply, got %s", r.Answer[0].String())
}
}
+
+func TestReverseExpansion(t *testing.T) {
+ // this test needs a fixed port, because with :0 the expanded reverse zone will listen on different
+ // addresses and we can't check which ones...
+ corefile := `10.0.0.0/15:5053 {
+ whoami
+ }`
+
+ server, udp, _, err := CoreDNSServerAndPorts(corefile)
+ if err != nil {
+ t.Fatalf("Could not get CoreDNS serving instance: %s", err)
+ }
+
+ defer server.Stop()
+
+ m := new(dns.Msg)
+ m.SetQuestion("whoami.0.10.in-addr.arpa.", dns.TypeA)
+
+ r, err := dns.Exchange(m, udp)
+ if err != nil {
+ t.Fatalf("Could not send message: %s", err)
+ }
+ if r.Rcode != dns.RcodeSuccess {
+ t.Errorf("Expected NOERROR, got %d", r.Rcode)
+ }
+ if len(r.Extra) != 2 {
+ t.Errorf("Expected 2 RRs in additional section, got %d", len(r.Extra))
+ }
+
+ m.SetQuestion("whoami.1.10.in-addr.arpa.", dns.TypeA)
+ r, err = dns.Exchange(m, udp)
+ if err != nil {
+ t.Fatalf("Could not send message: %s", err)
+ }
+ if r.Rcode != dns.RcodeSuccess {
+ t.Errorf("Expected NOERROR, got %d", r.Rcode)
+ }
+ if len(r.Extra) != 2 {
+ t.Errorf("Expected 2 RRs in additional section, got %d", len(r.Extra))
+ }
+
+ // should be refused
+ m.SetQuestion("whoami.2.10.in-addr.arpa.", dns.TypeA)
+ r, err = dns.Exchange(m, udp)
+ if err != nil {
+ t.Fatalf("Could not send message: %s", err)
+ }
+ if r.Rcode != dns.RcodeRefused {
+ t.Errorf("Expected REFUSED, got %d", r.Rcode)
+ }
+ if len(r.Extra) != 0 {
+ t.Errorf("Expected 0 RRs in additional section, got %d", len(r.Extra))
+ }
+}