diff options
author | 2016-11-09 21:26:49 +0000 | |
---|---|---|
committer | 2016-11-09 21:26:49 +0000 | |
commit | 0919216d3ca513d6ae18ffb0ed35b6a89fd393c6 (patch) | |
tree | 4dc5882a582b17778869428c707d6ab671c26065 /middleware/file/cname_test.go | |
parent | a8287bb04dc7861f349c96ba790e4a007dc7657c (diff) | |
download | coredns-0919216d3ca513d6ae18ffb0ed35b6a89fd393c6.tar.gz coredns-0919216d3ca513d6ae18ffb0ed35b6a89fd393c6.tar.zst coredns-0919216d3ca513d6ae18ffb0ed35b6a89fd393c6.zip |
middleware/{file, auto}: resolve external CNAMEs
Do the same thing as in etcd and give the option of externally resolving
CNAME. This is needed when CoreDNS is a proxy as well is serving zones.
Diffstat (limited to 'middleware/file/cname_test.go')
-rw-r--r-- | middleware/file/cname_test.go | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/middleware/file/cname_test.go b/middleware/file/cname_test.go index 800020068..2388aef33 100644 --- a/middleware/file/cname_test.go +++ b/middleware/file/cname_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/miekg/coredns/middleware/pkg/dnsrecorder" + "github.com/miekg/coredns/middleware/proxy" "github.com/miekg/coredns/middleware/test" "github.com/miekg/dns" @@ -69,6 +70,12 @@ var cnameTestCases = []test.Case{ }, }, { + Qname: "dangling.example.org.", Qtype: dns.TypeA, + Answer: []dns.RR{ + test.CNAME("dangling.example.org. 1800 IN CNAME foo.example.org."), + }, + }, + { Qname: "www3.example.org.", Qtype: dns.TypeA, Answer: []dns.RR{ test.A("a.example.org. 1800 IN A 127.0.0.1"), @@ -80,6 +87,59 @@ var cnameTestCases = []test.Case{ }, } +func TestLookupCNAMEExternal(t *testing.T) { + name := "example.org." + zone, err := Parse(strings.NewReader(dbExampleCNAME), name, "stdin") + if err != nil { + t.Fatalf("Expected no error when reading zone, got %q", err) + } + zone.Proxy = proxy.New([]string{"8.8.8.8:53"}) // TODO(point to local instance) + + fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{name: zone}, Names: []string{name}}} + ctx := context.TODO() + + for _, tc := range exernalTestCases { + m := tc.Msg() + + rec := dnsrecorder.New(&test.ResponseWriter{}) + _, err := fm.ServeDNS(ctx, rec, m) + if err != nil { + t.Errorf("Expected no error, got %v\n", err) + return + } + + resp := rec.Msg + sort.Sort(test.RRSet(resp.Answer)) + sort.Sort(test.RRSet(resp.Ns)) + sort.Sort(test.RRSet(resp.Extra)) + + if !test.Header(t, tc, resp) { + t.Logf("%v\n", resp) + continue + } + + if !test.Section(t, tc, test.Answer, resp.Answer) { + t.Logf("%v\n", resp) + } + if !test.Section(t, tc, test.Ns, resp.Ns) { + t.Logf("%v\n", resp) + + } + if !test.Section(t, tc, test.Extra, resp.Extra) { + t.Logf("%v\n", resp) + } + } +} + +var exernalTestCases = []test.Case{ + { + Qname: "external.example.org.", Qtype: dns.TypeA, + Answer: []dns.RR{ + test.CNAME("external.example.org. 1800 CNAME www.example.net."), + }, + }, +} + const dbExampleCNAME = ` $TTL 30M $ORIGIN example.org. @@ -95,4 +155,5 @@ www3 IN CNAME www2 www2 IN CNAME www1 www1 IN CNAME www www IN CNAME a -dangling IN CNAME foo` +dangling IN CNAME foo +external IN CNAME www.example.net.` |