mw/file: wildcard at apex fix
* mw/file: wildcard at apex fix
This adds a test case (that does passes!)
* completer test
@@ -212,6 +212,60 @@ func TestReplaceWithAsteriskLabel(t *testing.T) {
}
}
+var apexWildcardTestCases = []test.Case{
+ {
+ Qname: "foo.example.org.", Qtype: dns.TypeA,
+ Answer: []dns.RR{test.A(`foo.example.org. 3600 IN A 127.0.0.54`)},
+ Ns: []dns.RR{test.NS(`example.org. 3600 IN NS b.iana-servers.net.`)},
+ },
+ {
+ Qname: "bar.example.org.", Qtype: dns.TypeA,
+ Answer: []dns.RR{test.A(`bar.example.org. 3600 IN A 127.0.0.53`)},
+ Ns: []dns.RR{test.NS(`example.org. 3600 IN NS b.iana-servers.net.`)},
+ },
+}
+
+func TestLookupApexWildcard(t *testing.T) {
+ const name = "example.org."
+ zone, err := Parse(strings.NewReader(apexWildcard), name, "stdin", 0)
+ if err != nil {
+ t.Fatalf("Expect no error when reading zone, got %q", err)
+ }
+
+ fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{name: zone}, Names: []string{name}}}
+ ctx := context.TODO()
+
+ for _, tc := range apexWildcardTestCases {
+ 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)
+ }
+ }
+}
+
const exampleOrg = `; example.org test file
example.org. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600
example.org. IN NS b.iana-servers.net.
@@ -224,3 +278,10 @@ a.b.c.w.example.org. IN TXT "Not a wildcard"
*.d.example.org. IN CNAME alias.example.org.
alias.example.org. IN TXT "Wildcard CNAME expansion"
`
+
+const apexWildcard = `; example.org test file with wildcard at apex
+example.org. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600
+example.org. IN NS b.iana-servers.net.
+*.example.org. IN A 127.0.0.53
+foo.example.org. IN A 127.0.0.54
+`
