| 
									
										
										
										
											2016-04-27 10:48:22 +00:00
										 |  |  | package test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"io/ioutil" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/test" | 
					
						
							| 
									
										
										
										
											2016-04-27 10:48:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestLookupBalanceRewriteCacheDnssec(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-01-12 08:13:50 +00:00
										 |  |  | 	t.Parallel() | 
					
						
							| 
									
										
										
										
											2016-10-02 15:58:01 +01:00
										 |  |  | 	name, rm, err := test.TempFile(".", exampleOrg) | 
					
						
							| 
									
										
										
										
											2016-04-27 10:48:22 +00:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-06-01 15:12:49 +01:00
										 |  |  | 		t.Fatalf("Failed to create zone: %s", err) | 
					
						
							| 
									
										
										
										
											2016-04-27 10:48:22 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	defer rm() | 
					
						
							|  |  |  | 	rm1 := createKeyFile(t) | 
					
						
							|  |  |  | 	defer rm1() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	corefile := `example.org:0 { | 
					
						
							| 
									
										
										
										
											2020-04-25 14:08:36 +08:00
										 |  |  | 		file ` + name + ` | 
					
						
							|  |  |  | 		rewrite type ANY HINFO | 
					
						
							|  |  |  | 		dnssec { | 
					
						
							|  |  |  | 			key file ` + base + ` | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		loadbalance | 
					
						
							|  |  |  | 	}` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 11:35:14 +01:00
										 |  |  | 	ex, udp, _, err := CoreDNSServerAndPorts(corefile) | 
					
						
							| 
									
										
										
										
											2016-04-27 10:48:22 +00:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2016-10-02 08:31:44 +01:00
										 |  |  | 		t.Fatalf("Could not get CoreDNS serving instance: %s", err) | 
					
						
							| 
									
										
										
										
											2016-04-27 10:48:22 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	defer ex.Stop() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	c := new(dns.Client) | 
					
						
							|  |  |  | 	m := new(dns.Msg) | 
					
						
							|  |  |  | 	m.SetQuestion("example.org.", dns.TypeA) | 
					
						
							|  |  |  | 	m.SetEdns0(4096, true) | 
					
						
							|  |  |  | 	res, _, err := c.Exchange(m, udp) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Could not send query: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	sig := 0 | 
					
						
							|  |  |  | 	for _, a := range res.Answer { | 
					
						
							|  |  |  | 		if a.Header().Rrtype == dns.TypeRRSIG { | 
					
						
							|  |  |  | 			sig++ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if sig == 0 { | 
					
						
							| 
									
										
										
										
											2018-06-02 20:28:56 +01:00
										 |  |  | 		t.Errorf("Expected RRSIGs, got none") | 
					
						
							| 
									
										
										
										
											2016-04-27 10:48:22 +00:00
										 |  |  | 		t.Logf("%v\n", res) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func createKeyFile(t *testing.T) func() { | 
					
						
							|  |  |  | 	ioutil.WriteFile(base+".key", | 
					
						
							|  |  |  | 		[]byte(`example.org. IN DNSKEY 256 3 13 tDyI0uEIDO4SjhTJh1AVTFBLpKhY3He5BdAlKztewiZ7GecWj94DOodg ovpN73+oJs+UfZ+p9zOSN5usGAlHrw==`), | 
					
						
							|  |  |  | 		0644) | 
					
						
							|  |  |  | 	ioutil.WriteFile(base+".private", | 
					
						
							|  |  |  | 		[]byte(`Private-key-format: v1.3 | 
					
						
							|  |  |  | Algorithm: 13 (ECDSAP256SHA256) | 
					
						
							|  |  |  | PrivateKey: HPmldSNfrkj/aDdUMFwuk/lgzaC5KIsVEG3uoYvF4pQ= | 
					
						
							|  |  |  | Created: 20160426083115 | 
					
						
							|  |  |  | Publish: 20160426083115 | 
					
						
							|  |  |  | Activate: 20160426083115`), | 
					
						
							|  |  |  | 		0644) | 
					
						
							|  |  |  | 	return func() { | 
					
						
							|  |  |  | 		os.Remove(base + ".key") | 
					
						
							|  |  |  | 		os.Remove(base + ".private") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const base = "Kexample.org.+013+44563" |