mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	middleware/auto: add axfr test. (#396)
This commit is contained in:
		| @@ -58,6 +58,7 @@ func TestAuto(t *testing.T) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	time.Sleep(1100 * time.Millisecond) // wait for it to be picked up | 	time.Sleep(1100 * time.Millisecond) // wait for it to be picked up | ||||||
|  |  | ||||||
| 	resp, err = p.Lookup(state, "www.example.org.", dns.TypeA) | 	resp, err = p.Lookup(state, "www.example.org.", dns.TypeA) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Fatal("Expected to receive reply, but didn't") | 		t.Fatal("Expected to receive reply, but didn't") | ||||||
| @@ -117,6 +118,54 @@ func TestAutoNonExistentZone(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestAutoAXFR(t *testing.T) { | ||||||
|  | 	log.SetOutput(ioutil.Discard) | ||||||
|  |  | ||||||
|  | 	tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns") | ||||||
|  | 	if err != nil { | ||||||
|  | 		t.Fatal(err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	corefile := `org:0 { | ||||||
|  | 		auto { | ||||||
|  | 			directory ` + tmpdir + ` db\.(.*) {1} 1 | ||||||
|  | 			transfer to * | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | ` | ||||||
|  |  | ||||||
|  | 	i, err := CoreDNSServer(corefile) | ||||||
|  | 	if err != nil { | ||||||
|  | 		t.Fatalf("Could not get CoreDNS serving instance: %s", err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	udp, _ := CoreDNSServerPorts(i, 0) | ||||||
|  | 	if udp == "" { | ||||||
|  | 		t.Fatalf("Could not get UDP listening port") | ||||||
|  | 	} | ||||||
|  | 	defer i.Stop() | ||||||
|  |  | ||||||
|  | 	// Write db.example.org to get example.org. | ||||||
|  | 	if err = ioutil.WriteFile(path.Join(tmpdir, "db.example.org"), []byte(zoneContent), 0644); err != nil { | ||||||
|  | 		t.Fatal(err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	time.Sleep(1100 * time.Millisecond) // wait for it to be picked up | ||||||
|  |  | ||||||
|  | 	p := proxy.New([]string{udp}) | ||||||
|  | 	m := new(dns.Msg) | ||||||
|  | 	m.SetAxfr("example.org.") | ||||||
|  | 	state := request.Request{W: &test.ResponseWriter{}, Req: m} | ||||||
|  |  | ||||||
|  | 	resp, err := p.Lookup(state, "example.org.", dns.TypeAXFR) | ||||||
|  | 	if err != nil { | ||||||
|  | 		t.Fatal("Expected to receive reply, but didn't") | ||||||
|  | 	} | ||||||
|  | 	if len(resp.Answer) != 5 { | ||||||
|  | 		t.Fatal("Expected response with %d RRs, got %d", 5, len(resp.Answer)) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| const zoneContent = `; testzone | const zoneContent = `; testzone | ||||||
| @	IN	SOA	sns.dns.icann.org. noc.dns.icann.org. 2016082534 7200 3600 1209600 3600 | @	IN	SOA	sns.dns.icann.org. noc.dns.icann.org. 2016082534 7200 3600 1209600 3600 | ||||||
| 		NS	a.iana-servers.net. | 		NS	a.iana-servers.net. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user