diff options
author | 2021-01-15 19:26:04 +0100 | |
---|---|---|
committer | 2021-01-15 18:26:04 +0000 | |
commit | 342eae9b4b1791da8fb92d36b3968839f3f38b94 (patch) | |
tree | 8ed2b47ecb8005fe68e007254dbfc355f1d2e83f /test/file_loop_test.go | |
parent | f5f977f4c8c6e77a8908ebd9fce781a74c26374e (diff) | |
download | coredns-342eae9b4b1791da8fb92d36b3968839f3f38b94.tar.gz coredns-342eae9b4b1791da8fb92d36b3968839f3f38b94.tar.zst coredns-342eae9b4b1791da8fb92d36b3968839f3f38b94.zip |
plugin/file: guard against cname loops (#4387)
Automatically submitted.
Diffstat (limited to '')
-rw-r--r-- | test/file_loop_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/file_loop_test.go b/test/file_loop_test.go new file mode 100644 index 000000000..daebb7088 --- /dev/null +++ b/test/file_loop_test.go @@ -0,0 +1,49 @@ +package test + +import ( + "testing" + + "github.com/coredns/coredns/plugin/test" + + "github.com/miekg/dns" +) + +const loopDB = `example.com. 500 IN SOA ns1.outside.com. root.example.com. 3 604800 86400 2419200 604800 +example.com. 500 IN NS ns1.outside.com. +a.example.com. 500 IN CNAME b.example.com. +*.foo.example.com. 500 IN CNAME bar.foo.example.com.` + +func TestFileLoop(t *testing.T) { + name, rm, err := test.TempFile(".", loopDB) + if err != nil { + t.Fatalf("Failed to create zone: %s", err) + } + defer rm() + + // Corefile with for example without proxy section. + corefile := `example.com:0 { + file ` + name + ` + }` + + i, udp, _, err := CoreDNSServerAndPorts(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + defer i.Stop() + + m := new(dns.Msg) + m.SetQuestion("something.foo.example.com.", dns.TypeA) + + r, err := dns.Exchange(m, udp) + if err != nil { + t.Fatalf("Could not exchange msg: %s", err) + } + + // This should not loop, don't really care about the correctness of the answer. + // Currently we return servfail in the file lookup.go file. + // For now: document current behavior in this test. + if r.Rcode != dns.RcodeServerFailure { + t.Errorf("Rcode should be dns.RcodeServerFailure: %d", r.Rcode) + + } +} |