mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
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
This commit is contained in:
95
test/reverse_test.go
Normal file
95
test/reverse_test.go
Normal file
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user