| 
									
										
										
										
											2016-10-19 17:46:03 +01:00
										 |  |  | package test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/proxy" | 
					
						
							|  |  |  | 	mtest "github.com/coredns/coredns/plugin/test" | 
					
						
							| 
									
										
										
										
											2017-02-21 22:51:47 -08:00
										 |  |  | 	"github.com/coredns/coredns/request" | 
					
						
							| 
									
										
										
										
											2016-10-19 17:46:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Using miek.nl here because this is the easiest zone to get access to and it's masters | 
					
						
							|  |  |  | // run both NSD and BIND9, making checks like "what should we actually return" super easy. | 
					
						
							|  |  |  | var dsTestCases = []mtest.Case{ | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "_udp.miek.nl.", Qtype: dns.TypeDS, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeNameError, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			mtest.SOA("miek.nl.	1800	IN	SOA	linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "miek.nl.", Qtype: dns.TypeDS, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			mtest.SOA("miek.nl.	1800	IN	SOA	linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestLookupDS(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-01-12 08:13:50 +00:00
										 |  |  | 	t.Parallel() | 
					
						
							| 
									
										
										
										
											2016-10-19 17:46:03 +01:00
										 |  |  | 	name, rm, err := TempFile(".", miekNL) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-06-01 15:12:49 +01:00
										 |  |  | 		t.Fatalf("Failed to create zone: %s", err) | 
					
						
							| 
									
										
										
										
											2016-10-19 17:46:03 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	defer rm() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	corefile := `miek.nl:0 { | 
					
						
							|  |  |  |        file ` + name + ` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 11:35:14 +01:00
										 |  |  | 	i, udp, _, err := CoreDNSServerAndPorts(corefile) | 
					
						
							| 
									
										
										
										
											2016-10-19 17:46:03 +01:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Could not get CoreDNS serving instance: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer i.Stop() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-15 08:12:58 +00:00
										 |  |  | 	p := proxy.NewLookup([]string{udp}) | 
					
						
							| 
									
										
										
										
											2016-10-19 17:46:03 +01:00
										 |  |  | 	state := request.Request{W: &mtest.ResponseWriter{}, Req: new(dns.Msg)} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, tc := range dsTestCases { | 
					
						
							|  |  |  | 		resp, err := p.Lookup(state, tc.Qname, tc.Qtype) | 
					
						
							|  |  |  | 		if err != nil || resp == nil { | 
					
						
							|  |  |  | 			t.Fatalf("Expected to receive reply, but didn't for %s %d", tc.Qname, tc.Qtype) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-16 15:30:58 +01:00
										 |  |  | 		mtest.SortAndCheck(t, resp, tc) | 
					
						
							| 
									
										
										
										
											2016-10-19 17:46:03 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |