| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | package file | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2018-04-22 08:34:35 +01:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/pkg/dnstest" | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/test" | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 12:26:22 +01:00
										 |  |  | // these examples don't have an additional opt RR set, because that's gets added by the server. | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | var wildcardTestCases = []test.Case{ | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 		Qname: "wild.dnssex.nl.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | 			test.TXT(`wild.dnssex.nl.	1800	IN	TXT	"Doing It Safe Is Better"`), | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: dnssexAuth[:len(dnssexAuth)-1], // remove RRSIG on the end | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "a.wild.dnssex.nl.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.TXT(`a.wild.dnssex.nl.	1800	IN	TXT	"Doing It Safe Is Better"`), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: dnssexAuth[:len(dnssexAuth)-1], // remove RRSIG on the end | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "wild.dnssex.nl.", Qtype: dns.TypeTXT, Do: true, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | 			test.RRSIG("wild.dnssex.nl.	1800	IN	RRSIG	TXT 8 2 1800 20160428190224 20160329190224 14460 dnssex.nl. FUZSTyvZfeuuOpCm"), | 
					
						
							|  |  |  | 			test.TXT(`wild.dnssex.nl.	1800	IN	TXT	"Doing It Safe Is Better"`), | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: append([]dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-11-06 08:32:07 +00:00
										 |  |  | 			test.NSEC("a.dnssex.nl.	14400	IN	NSEC	www.dnssex.nl. A AAAA RRSIG NSEC"), | 
					
						
							|  |  |  | 			test.RRSIG("a.dnssex.nl.	14400	IN	RRSIG	NSEC 8 3 14400 20160428190224 20160329190224 14460 dnssex.nl. S+UMs2ySgRaaRY"), | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		}, dnssexAuth...), | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "a.wild.dnssex.nl.", Qtype: dns.TypeTXT, Do: true, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.RRSIG("a.wild.dnssex.nl.	1800	IN	RRSIG	TXT 8 2 1800 20160428190224 20160329190224 14460 dnssex.nl. FUZSTyvZfeuuOpCm"), | 
					
						
							|  |  |  | 			test.TXT(`a.wild.dnssex.nl.	1800	IN	TXT	"Doing It Safe Is Better"`), | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: append([]dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-11-06 08:32:07 +00:00
										 |  |  | 			test.NSEC("a.dnssex.nl.	14400	IN	NSEC	www.dnssex.nl. A AAAA RRSIG NSEC"), | 
					
						
							|  |  |  | 			test.RRSIG("a.dnssex.nl.	14400	IN	RRSIG	NSEC 8 3 14400 20160428190224 20160329190224 14460 dnssex.nl. S+UMs2ySgRaaRY"), | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		}, dnssexAuth...), | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	// nodata responses | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "wild.dnssex.nl.", Qtype: dns.TypeSRV, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA(`dnssex.nl.	1800	IN	SOA	linode.atoom.net. miek.miek.nl. 1459281744 14400 3600 604800 14400`), | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "wild.dnssex.nl.", Qtype: dns.TypeSRV, Do: true, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-11-05 14:39:49 +00:00
										 |  |  | 			// TODO(miek): needs closest encloser proof as well? This is the wrong answer | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 			test.NSEC(`*.dnssex.nl.	14400	IN	NSEC	a.dnssex.nl. TXT RRSIG NSEC`), | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 			test.RRSIG(`*.dnssex.nl.	14400	IN	RRSIG	NSEC 8 2 14400 20160428190224 20160329190224 14460 dnssex.nl. os6INm6q2eXknD5z8TaaDOV+Ge/Ko+2dXnKP+J1fqJzafXJVH1F0nDrcXmMlR6jlBHA=`), | 
					
						
							|  |  |  | 			test.RRSIG(`dnssex.nl.	1800	IN	RRSIG	SOA 8 2 1800 20160428190224 20160329190224 14460 dnssex.nl. CA/Y3m9hCOiKC/8ieSOv8SeP964Bq++lyH8BZJcTaabAsERs4xj5PRtcxicwQXZiF8fYUCpROlUS0YR8Cdw=`), | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 			test.SOA(`dnssex.nl.	1800	IN	SOA	linode.atoom.net. miek.miek.nl. 1459281744 14400 3600 604800 14400`), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | var dnssexAuth = []dns.RR{ | 
					
						
							|  |  |  | 	test.NS("dnssex.nl.	1800	IN	NS	linode.atoom.net."), | 
					
						
							|  |  |  | 	test.NS("dnssex.nl.	1800	IN	NS	ns-ext.nlnetlabs.nl."), | 
					
						
							|  |  |  | 	test.NS("dnssex.nl.	1800	IN	NS	omval.tednet.nl."), | 
					
						
							|  |  |  | 	test.RRSIG("dnssex.nl.	1800	IN	RRSIG	NS 8 2 1800 20160428190224 20160329190224 14460 dnssex.nl. dLIeEvP86jj5ndkcLzhgvWixTABjWAGRTGQsPsVDFXsGMf9TGGC9FEomgkCVeNC0="), | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | func TestLookupWildcard(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-06-08 18:43:11 +01:00
										 |  |  | 	zone, err := Parse(strings.NewReader(dbDnssexNLSigned), testzone1, "stdin", 0) | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2016-11-05 14:39:49 +00:00
										 |  |  | 		t.Fatalf("Expect no error when reading zone, got %q", err) | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | 	fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{testzone1: zone}, Names: []string{testzone1}}} | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 	ctx := context.TODO() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-31 09:25:22 +00:00
										 |  |  | 	for _, tc := range wildcardTestCases { | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 		m := tc.Msg() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 		rec := dnstest.NewRecorder(&test.ResponseWriter{}) | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 		_, err := fm.ServeDNS(ctx, rec, m) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 			t.Errorf("Expected no error, got %v", err) | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 11:10:16 +01:00
										 |  |  | 		resp := rec.Msg | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 		if err := test.SortAndCheck(resp, tc); err != nil { | 
					
						
							|  |  |  | 			t.Error(err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-29 21:25:06 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | var wildcardDoubleTestCases = []test.Case{ | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "wild.w.example.org.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.TXT(`wild.w.example.org. IN	TXT	"Wildcard"`), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: exampleAuth, | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "wild.c.example.org.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.TXT(`wild.c.example.org. IN	TXT	"c Wildcard"`), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: exampleAuth, | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "wild.d.example.org.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.TXT(`alias.example.org. IN	TXT	"Wildcard CNAME expansion"`), | 
					
						
							|  |  |  | 			test.CNAME(`wild.d.example.org. IN	CNAME	alias.example.org`), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: exampleAuth, | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "alias.example.org.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.TXT(`alias.example.org. IN	TXT	"Wildcard CNAME expansion"`), | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | 		Ns: exampleAuth, | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-07 20:37:29 +00:00
										 |  |  | var exampleAuth = []dns.RR{ | 
					
						
							|  |  |  | 	test.NS("example.org.	3600	IN	NS	a.iana-servers.net."), | 
					
						
							|  |  |  | 	test.NS("example.org.	3600	IN	NS	b.iana-servers.net."), | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | func TestLookupDoubleWildcard(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-06-08 18:43:11 +01:00
										 |  |  | 	zone, err := Parse(strings.NewReader(exampleOrg), "example.org.", "stdin", 0) | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2016-11-05 14:39:49 +00:00
										 |  |  | 		t.Fatalf("Expect no error when reading zone, got %q", err) | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fm := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{"example.org.": zone}, Names: []string{"example.org."}}} | 
					
						
							|  |  |  | 	ctx := context.TODO() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, tc := range wildcardDoubleTestCases { | 
					
						
							|  |  |  | 		m := tc.Msg() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 		rec := dnstest.NewRecorder(&test.ResponseWriter{}) | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 		_, err := fm.ServeDNS(ctx, rec, m) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 			t.Errorf("Expected no error, got %v", err) | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		resp := rec.Msg | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 		if err := test.SortAndCheck(resp, tc); err != nil { | 
					
						
							|  |  |  | 			t.Error(err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 14:39:49 +00:00
										 |  |  | func TestReplaceWithAsteriskLabel(t *testing.T) { | 
					
						
							|  |  |  | 	tests := []struct { | 
					
						
							|  |  |  | 		in, out string | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		{".", ""}, | 
					
						
							|  |  |  | 		{"miek.nl.", "*.nl."}, | 
					
						
							|  |  |  | 		{"www.miek.nl.", "*.miek.nl."}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, tc := range tests { | 
					
						
							|  |  |  | 		got := replaceWithAsteriskLabel(tc.in) | 
					
						
							|  |  |  | 		if got != tc.out { | 
					
						
							|  |  |  | 			t.Errorf("Expected to be %s, got %s", tc.out, got) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-21 03:44:36 -07:00
										 |  |  | 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() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 		rec := dnstest.NewRecorder(&test.ResponseWriter{}) | 
					
						
							| 
									
										
										
										
											2017-07-21 03:44:36 -07:00
										 |  |  | 		_, err := fm.ServeDNS(ctx, rec, m) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 			t.Errorf("Expected no error, got %v", err) | 
					
						
							| 
									
										
										
										
											2017-07-21 03:44:36 -07:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		resp := rec.Msg | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 		if err := test.SortAndCheck(resp, tc); err != nil { | 
					
						
							|  |  |  | 			t.Error(err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-21 03:44:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-24 14:21:40 -07:00
										 |  |  | var multiWildcardTestCases = []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.`)}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "bar.intern.example.org.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Answer: []dns.RR{test.A(`bar.intern.example.org. 3600	IN	A 127.0.1.52`)}, | 
					
						
							|  |  |  | 		Ns: []dns.RR{test.NS(`example.org. 3600 IN NS b.iana-servers.net.`)}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestLookupMultiWildcard(t *testing.T) { | 
					
						
							|  |  |  | 	const name = "example.org." | 
					
						
							|  |  |  | 	zone, err := Parse(strings.NewReader(doubleWildcard), 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 multiWildcardTestCases { | 
					
						
							|  |  |  | 		m := tc.Msg() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 		rec := dnstest.NewRecorder(&test.ResponseWriter{}) | 
					
						
							| 
									
										
										
										
											2017-07-24 14:21:40 -07:00
										 |  |  | 		_, err := fm.ServeDNS(ctx, rec, m) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 			t.Errorf("Expected no error, got %v", err) | 
					
						
							| 
									
										
										
										
											2017-07-24 14:21:40 -07:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		resp := rec.Msg | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 		if err := test.SortAndCheck(resp, tc); err != nil { | 
					
						
							|  |  |  | 			t.Error(err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-24 14:21:40 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | const exampleOrg = `; example.org test file | 
					
						
							| 
									
										
										
										
											2017-09-26 19:41:49 +01:00
										 |  |  | $TTL 3600 | 
					
						
							| 
									
										
										
										
											2016-10-08 15:22:31 +01:00
										 |  |  | 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	NS	a.iana-servers.net. | 
					
						
							|  |  |  | example.org.		IN	A	127.0.0.1 | 
					
						
							|  |  |  | example.org.		IN	A	127.0.0.2 | 
					
						
							|  |  |  | *.w.example.org.        IN      TXT     "Wildcard" | 
					
						
							|  |  |  | a.b.c.w.example.org.    IN      TXT     "Not a wildcard" | 
					
						
							|  |  |  | *.c.example.org.        IN      TXT     "c Wildcard" | 
					
						
							|  |  |  | *.d.example.org.        IN      CNAME   alias.example.org. | 
					
						
							|  |  |  | alias.example.org.      IN      TXT     "Wildcard CNAME expansion" | 
					
						
							|  |  |  | ` | 
					
						
							| 
									
										
										
										
											2017-07-21 03:44:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const apexWildcard = `; example.org test file with wildcard at apex | 
					
						
							| 
									
										
										
										
											2017-09-26 19:41:49 +01:00
										 |  |  | $TTL 3600 | 
					
						
							| 
									
										
										
										
											2017-07-21 03:44:36 -07:00
										 |  |  | 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 | 
					
						
							|  |  |  | ` | 
					
						
							| 
									
										
										
										
											2017-07-24 14:21:40 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const doubleWildcard = `; example.org test file with wildcard at apex | 
					
						
							| 
									
										
										
										
											2017-09-26 19:41:49 +01:00
										 |  |  | $TTL 3600 | 
					
						
							| 
									
										
										
										
											2017-07-24 14:21:40 -07:00
										 |  |  | 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 | 
					
						
							|  |  |  | *.intern.example.org.   IN      A       127.0.1.52 | 
					
						
							|  |  |  | foo.example.org.        IN      A       127.0.0.54 | 
					
						
							|  |  |  | ` |