mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	Slowly adding all the tests from skydns
This commit is contained in:
		| @@ -44,12 +44,24 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i | |||||||
| 		return 0, nil | 		return 0, nil | ||||||
| 	} | 	} | ||||||
| 	if isEtcdNameError(err) { | 	if isEtcdNameError(err) { | ||||||
| 		NameError(zone, state) | 		m := new(dns.Msg) | ||||||
|  | 		m.SetRcode(state.Req, dns.RcodeNameError) | ||||||
|  | 		m.Ns = []dns.RR{e.SOA(zone, state)} | ||||||
|  | 		state.W.WriteMsg(m) | ||||||
| 		return dns.RcodeNameError, nil | 		return dns.RcodeNameError, nil | ||||||
| 	} | 	} | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return dns.RcodeServerFailure, err | 		return dns.RcodeServerFailure, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if len(records) == 0 { | ||||||
|  | 		m := new(dns.Msg) | ||||||
|  | 		m.SetReply(state.Req) | ||||||
|  | 		m.Ns = []dns.RR{e.SOA(zone, state)} | ||||||
|  | 		state.W.WriteMsg(m) | ||||||
|  | 		return dns.RcodeNameError, nil | ||||||
|  |  | ||||||
|  | 	} | ||||||
| 	if len(records) > 0 { | 	if len(records) > 0 { | ||||||
| 		m.Answer = append(m.Answer, records...) | 		m.Answer = append(m.Answer, records...) | ||||||
| 	} | 	} | ||||||
| @@ -60,15 +72,7 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i | |||||||
| 	return 0, nil | 	return 0, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // NameError writes a name error to the client. |  | ||||||
| func NameError(zone string, state middleware.State) { |  | ||||||
| 	m := new(dns.Msg) |  | ||||||
| 	m.SetRcode(state.Req, dns.RcodeNameError) |  | ||||||
| 	m.Ns = []dns.RR{SOA(zone)} |  | ||||||
| 	state.W.WriteMsg(m) |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // NoData write a nodata response to the client. | // NoData write a nodata response to the client. | ||||||
| func NoData(zone string, state middleware.State) { | func (e Etcd) NoData(zone string, state middleware.State) { | ||||||
| 	// TODO(miek): write it | 	// TODO(miek): write it | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,8 +10,6 @@ import ( | |||||||
| 	"github.com/miekg/dns" | 	"github.com/miekg/dns" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // TODO(miek): factor out common code a bit |  | ||||||
|  |  | ||||||
| func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) (records []dns.RR, err error) { | func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) (records []dns.RR, err error) { | ||||||
| 	services, err := e.Records(state.Name(), false) | 	services, err := e.Records(state.Name(), false) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -30,6 +28,7 @@ func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) ( | |||||||
| 				// x CNAME x is a direct loop, don't add those | 				// x CNAME x is a direct loop, don't add those | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
|  | 			println("TRYING TO ADD CNAME", len(previousRecords)) | ||||||
|  |  | ||||||
| 			newRecord := serv.NewCNAME(state.QName(), serv.Host) | 			newRecord := serv.NewCNAME(state.QName(), serv.Host) | ||||||
| 			if len(previousRecords) > 7 { | 			if len(previousRecords) > 7 { | ||||||
| @@ -46,7 +45,6 @@ func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) ( | |||||||
| 			if err == nil { | 			if err == nil { | ||||||
| 				// Not only have we found something we should add the CNAME and the IP addresses. | 				// Not only have we found something we should add the CNAME and the IP addresses. | ||||||
| 				if len(nextRecords) > 0 { | 				if len(nextRecords) > 0 { | ||||||
| 					// TODO(miek): sorting here? |  | ||||||
| 					records = append(records, newRecord) | 					records = append(records, newRecord) | ||||||
| 					records = append(records, nextRecords...) | 					records = append(records, nextRecords...) | ||||||
| 				} | 				} | ||||||
| @@ -56,6 +54,7 @@ func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) ( | |||||||
| 			target := newRecord.Target | 			target := newRecord.Target | ||||||
| 			if dns.IsSubDomain(zone, target) { | 			if dns.IsSubDomain(zone, target) { | ||||||
| 				// We should already have found it | 				// We should already have found it | ||||||
|  | 				println("DIDN'T FOUND IT") | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			m1, e1 := e.Proxy.Lookup(state, target, state.QType()) | 			m1, e1 := e.Proxy.Lookup(state, target, state.QType()) | ||||||
| @@ -322,8 +321,9 @@ func (e Etcd) TXT(zone string, state middleware.State) (records []dns.RR, err er | |||||||
| } | } | ||||||
|  |  | ||||||
| // synthesis a SOA Record. | // synthesis a SOA Record. | ||||||
| func SOA(zone string) *dns.SOA { | func (e Etcd) SOA(zone string, state middleware.State) *dns.SOA { | ||||||
| 	return &dns.SOA{} | 	header := dns.RR_Header{Name: zone, Rrtype: dns.TypeSOA, Ttl: 300, Class: dns.ClassINET} | ||||||
|  | 	return &dns.SOA{Hdr: header, Mbox: "hostmaster." + zone, Ns: "ns.dns." + zone} | ||||||
| } | } | ||||||
|  |  | ||||||
| func isDuplicateCNAME(r *dns.CNAME, records []dns.RR) bool { | func isDuplicateCNAME(r *dns.CNAME, records []dns.RR) bool { | ||||||
|   | |||||||
| @@ -83,19 +83,19 @@ func TestLookup(t *testing.T) { | |||||||
| 		m.SetQuestion(dns.Fqdn(tc.Qname), tc.Qtype) | 		m.SetQuestion(dns.Fqdn(tc.Qname), tc.Qtype) | ||||||
|  |  | ||||||
| 		rec := middleware.NewResponseRecorder(&middleware.TestResponseWriter{}) | 		rec := middleware.NewResponseRecorder(&middleware.TestResponseWriter{}) | ||||||
| 		code, err := etc.ServeDNS(ctx, rec, m) | 		_, err := etc.ServeDNS(ctx, rec, m) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			t.Errorf("expected no error, got %v\n", err) | 			t.Errorf("expected no error, got %v\n", err) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 		resp := rec.Reply() | 		resp := rec.Reply() | ||||||
| 		code = code // TODO(miek): test |  | ||||||
| 		// if nil then? |  | ||||||
|  |  | ||||||
| 		sort.Sort(rrSet(resp.Answer)) | 		sort.Sort(rrSet(resp.Answer)) | ||||||
| 		sort.Sort(rrSet(resp.Ns)) | 		sort.Sort(rrSet(resp.Ns)) | ||||||
| 		sort.Sort(rrSet(resp.Extra)) | 		sort.Sort(rrSet(resp.Extra)) | ||||||
|  |  | ||||||
|  | 		t.Logf("%v\n", resp) | ||||||
|  |  | ||||||
| 		if resp.Rcode != tc.Rcode { | 		if resp.Rcode != tc.Rcode { | ||||||
| 			t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode]) | 			t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode]) | ||||||
| 			continue | 			continue | ||||||
| @@ -139,6 +139,9 @@ var services = []*msg.Service{ | |||||||
| 	// CNAME dedup Test | 	// CNAME dedup Test | ||||||
| 	{Host: "www.miek.nl", Key: "a.miek.nl.skydns.test."}, | 	{Host: "www.miek.nl", Key: "a.miek.nl.skydns.test."}, | ||||||
| 	{Host: "www.miek.nl", Key: "b.miek.nl.skydns.test."}, | 	{Host: "www.miek.nl", Key: "b.miek.nl.skydns.test."}, | ||||||
|  |  | ||||||
|  | 	// Unresolvable internal name | ||||||
|  | 	{Host: "unresolvable.skydns.test", Key: "cname.prod.region1.skydns.test."}, | ||||||
| } | } | ||||||
|  |  | ||||||
| var dnsTestCases = []dnsTestCase{ | var dnsTestCases = []dnsTestCase{ | ||||||
| @@ -185,13 +188,12 @@ var dnsTestCases = []dnsTestCase{ | |||||||
| 			newCNAME("www.miek.nl. 303 IN CNAME a.miek.nl."), | 			newCNAME("www.miek.nl. 303 IN CNAME a.miek.nl."), | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	/* |  | ||||||
| 	// CNAME (unresolvable internal name) | 	// CNAME (unresolvable internal name) | ||||||
| 	{ | 	{ | ||||||
| 			Qname: "2.cname.skydns.test.", Qtype: dns.TypeA, | 		Qname: "cname.prod.region1.skydns.test.", Qtype: dns.TypeA, | ||||||
| 			Answer: []dns.RR{}, | 		Ns: []dns.RR{newSOA("skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 1407441600 28800 7200 604800 60")}, | ||||||
| 			Ns:     []dns.RR{newSOA("skydns.test. 60 SOA ns.dns.skydns.test. hostmaster.skydns.test. 1407441600 28800 7200 604800 60")}, |  | ||||||
| 	}, | 	}, | ||||||
|  | 	/* | ||||||
| 		// CNAME loop detection | 		// CNAME loop detection | ||||||
| 		{ | 		{ | ||||||
| 			Qname: "3.cname.skydns.test.", Qtype: dns.TypeA, | 			Qname: "3.cname.skydns.test.", Qtype: dns.TypeA, | ||||||
| @@ -330,7 +332,7 @@ func checkSection(t *testing.T, tc dnsTestCase, sect Section, rr []dns.RR) { | |||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		if a.Header().Rrtype != section[i].Header().Rrtype { | 		if a.Header().Rrtype != section[i].Header().Rrtype { | ||||||
| 			t.Errorf("answer %d should have a header rr type of %d, but has %dn", i, section[i].Header().Rrtype, a.Header().Rrtype) | 			t.Errorf("answer %d should have a header rr type of %d, but has %d", i, section[i].Header().Rrtype, a.Header().Rrtype) | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user