aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-02-20 21:00:00 +0000
committerGravatar GitHub <noreply@github.com> 2017-02-20 21:00:00 +0000
commit26242cef1bac4a4d807a49981e47c4e67b612311 (patch)
tree80930ed68de5813b2e5f8f4917c0a68ae83cd9df /test
parent3e26398e086d68da94aa6aaebee24705ce91b6a9 (diff)
downloadcoredns-26242cef1bac4a4d807a49981e47c4e67b612311.tar.gz
coredns-26242cef1bac4a4d807a49981e47c4e67b612311.tar.zst
coredns-26242cef1bac4a4d807a49981e47c4e67b612311.zip
Document fallthrough and fix rewrite (#537)
* Document fallthrough and fix *reverse* While documenting the fallthrough behavior and testing it I noticed the did not properly work. This PR does a tiny bit too much as it - Documents fallthrough - Fixes fallthrough in reverse - Makes directives_generate complain on duplicate priorities - Moved reverse *before* file in middleware.cfg - Add a test that tests the reverse fallthrough behavior with a file backend Fixes #515 * ....and fix the tests
Diffstat (limited to 'test')
-rw-r--r--test/reverse_test.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/test/reverse_test.go b/test/reverse_test.go
new file mode 100644
index 000000000..f1acb0a65
--- /dev/null
+++ b/test/reverse_test.go
@@ -0,0 +1,95 @@
+package test
+
+import (
+ "io/ioutil"
+ "log"
+ "testing"
+
+ "github.com/miekg/coredns/middleware/proxy"
+ "github.com/miekg/coredns/middleware/test"
+ "github.com/miekg/coredns/request"
+
+ "github.com/miekg/dns"
+)
+
+func TestReverseFallthrough(t *testing.T) {
+ t.Parallel()
+ name, rm, err := test.TempFile(".", exampleOrg)
+ if err != nil {
+ t.Fatalf("failed to created zone: %s", err)
+ }
+ defer rm()
+
+ corefile := `arpa:0 example.org:0 {
+ reverse 10.32.0.0/16 {
+ hostname ip-{ip}.{zone[2]}
+ #fallthrough
+ }
+ file ` + name + ` example.org
+}
+`
+
+ i, err := CoreDNSServer(corefile)
+ if err != nil {
+ t.Fatalf("Could not get CoreDNS serving instance: %s", err)
+ }
+
+ udp, _ := CoreDNSServerPorts(i, 0)
+ if udp == "" {
+ t.Fatalf("Could not get UDP listening port")
+ }
+
+ log.SetOutput(ioutil.Discard)
+
+ p := proxy.NewLookup([]string{udp})
+ state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
+ resp, err := p.Lookup(state, "example.org.", dns.TypeA)
+ if err != nil {
+ t.Fatal("Expected to receive reply, but didn't")
+ }
+ // Reply should be SERVFAIL because of no fallthrough
+ if resp.Rcode != dns.RcodeServerFailure {
+ t.Fatalf("Expected SERVFAIL, but got: %d", resp.Rcode)
+ }
+
+ // Stop the server.
+ i.Stop()
+
+ // And redo with fallthrough enabled
+
+ corefile = `arpa:0 example.org:0 {
+ reverse 10.32.0.0/16 {
+ hostname ip-{ip}.{zone[2]}
+ fallthrough
+ }
+ file ` + name + ` example.org
+}
+`
+
+ i, err = CoreDNSServer(corefile)
+ if err != nil {
+ t.Fatalf("Could not get CoreDNS serving instance: %s", err)
+ }
+
+ udp, _ = CoreDNSServerPorts(i, 0)
+ if udp == "" {
+ t.Fatalf("Could not get UDP listening port")
+ }
+ defer i.Stop()
+
+ p = proxy.NewLookup([]string{udp})
+ resp, err = p.Lookup(state, "example.org.", dns.TypeA)
+ if err != nil {
+ t.Fatal("Expected to receive reply, but didn't")
+ }
+
+ if len(resp.Answer) == 0 {
+ t.Error("Expected to at least one RR in the answer section, got none")
+ }
+ if resp.Answer[0].Header().Rrtype != dns.TypeA {
+ t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
+ }
+ if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" {
+ t.Errorf("Expected 127.0.0.1, got: %s", resp.Answer[0].(*dns.A).A.String())
+ }
+}