diff options
author | 2018-06-12 14:54:37 +0100 | |
---|---|---|
committer | 2018-06-12 14:54:37 +0100 | |
commit | 26c41a0c177fbe89f1f81214634aed49790581f4 (patch) | |
tree | 7e957105a4256d875c4985a75a3c9fb92b49234d /test | |
parent | 6e466d509281953fdf0209a5b50611e89b4689ae (diff) | |
download | coredns-26c41a0c177fbe89f1f81214634aed49790581f4.tar.gz coredns-26c41a0c177fbe89f1f81214634aed49790581f4.tar.zst coredns-26c41a0c177fbe89f1f81214634aed49790581f4.zip |
plugin/file: fix local CNAME lookup (#1866)
* plugin/file: fix local CNAME lookup
Issue #1864 explains it will, when we serve the child zone as well we
should just recursive into ourself (upstream self). Thus relax the
IsSubDomain check in file/lookup.go and just query (even if the query
will hit a remote server).
I've looped over all other plugins that do something similar (CNAME
resolving) and they didn't do the IsSubDomain check; therefor I've
removed it from *file* as well.
Added test in file_upstream_test that shows this failed before but now
results in a reply.
Fixes #1864
* self does not need to be exported
* Fix test
We don't know if we had a valid reply. Check this.
Diffstat (limited to 'test')
-rw-r--r-- | test/file_upstream_test.go | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/test/file_upstream_test.go b/test/file_upstream_test.go index dc4cbc45f..36f2bbc56 100644 --- a/test/file_upstream_test.go +++ b/test/file_upstream_test.go @@ -6,8 +6,6 @@ import ( "github.com/miekg/dns" ) -// TODO(miek): this test needs to be fleshed out. - func TestFileUpstream(t *testing.T) { name, rm, err := TempFile(".", `$ORIGIN example.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. ( @@ -59,3 +57,63 @@ www 3600 IN CNAME www.example.net. t.Errorf("Failed to get address for CNAME, expected 10.0.0.1 got %s", x) } } + +// TestFileUpstreamAdditional runs two CoreDNS servers that serve example.org and foo.example.org. +// example.org contains a cname to foo.example.org; this should be resolved via upstream.Self. +func TestFileUpstreamAdditional(t *testing.T) { + name, rm, err := TempFile(".", `$ORIGIN example.org. +@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600 + + 3600 IN NS b.iana-servers.net. + +www 3600 IN CNAME www.foo +`) + if err != nil { + t.Fatalf("Failed to create zone: %s", err) + } + defer rm() + + name2, rm2, err2 := TempFile(".", `$ORIGIN foo.example.org. +@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600 + + 3600 IN NS b.iana-servers.net. + +www 3600 IN A 127.0.0.53 +`) + if err2 != nil { + t.Fatalf("Failed to create zone: %s", err2) + } + defer rm2() + + corefile := `.:0 { + file ` + name + ` example.org { + upstream + } + file ` + name2 + ` foo.example.org { + upstream + } +} +` + 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("www.example.org.", dns.TypeA) + + r, err := dns.Exchange(m, udp) + if err != nil { + t.Fatalf("Could not exchange msg: %s", err) + } + if r.Rcode == dns.RcodeServerFailure { + t.Fatalf("Rcode should not be dns.RcodeServerFailure") + } + if x := len(r.Answer); x != 2 { + t.Errorf("Expected 2 RR in reply, got %d", x) + } + if x := r.Answer[1].(*dns.A).A.String(); x != "127.0.0.53" { + t.Errorf("Failed to get address for CNAME, expected 127.0.0.53, got %s", x) + } +} |