Slowly adding all the tests from skydns
This commit is contained in:
parent
c1d5b5d0db
commit
a655a5735b
3 changed files with 31 additions and 25 deletions
|
@ -44,12 +44,24 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
|||
return 0, nil
|
||||
}
|
||||
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
|
||||
}
|
||||
if err != nil {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
// 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.
|
||||
func NoData(zone string, state middleware.State) {
|
||||
func (e Etcd) NoData(zone string, state middleware.State) {
|
||||
// TODO(miek): write it
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import (
|
|||
"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) {
|
||||
services, err := e.Records(state.Name(), false)
|
||||
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
|
||||
continue
|
||||
}
|
||||
println("TRYING TO ADD CNAME", len(previousRecords))
|
||||
|
||||
newRecord := serv.NewCNAME(state.QName(), serv.Host)
|
||||
if len(previousRecords) > 7 {
|
||||
|
@ -46,7 +45,6 @@ func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) (
|
|||
if err == nil {
|
||||
// Not only have we found something we should add the CNAME and the IP addresses.
|
||||
if len(nextRecords) > 0 {
|
||||
// TODO(miek): sorting here?
|
||||
records = append(records, newRecord)
|
||||
records = append(records, nextRecords...)
|
||||
}
|
||||
|
@ -56,6 +54,7 @@ func (e Etcd) A(zone string, state middleware.State, previousRecords []dns.RR) (
|
|||
target := newRecord.Target
|
||||
if dns.IsSubDomain(zone, target) {
|
||||
// We should already have found it
|
||||
println("DIDN'T FOUND IT")
|
||||
continue
|
||||
}
|
||||
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.
|
||||
func SOA(zone string) *dns.SOA {
|
||||
return &dns.SOA{}
|
||||
func (e Etcd) SOA(zone string, state middleware.State) *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 {
|
||||
|
|
|
@ -83,19 +83,19 @@ func TestLookup(t *testing.T) {
|
|||
m.SetQuestion(dns.Fqdn(tc.Qname), tc.Qtype)
|
||||
|
||||
rec := middleware.NewResponseRecorder(&middleware.TestResponseWriter{})
|
||||
code, err := etc.ServeDNS(ctx, rec, m)
|
||||
_, err := etc.ServeDNS(ctx, rec, m)
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v\n", err)
|
||||
return
|
||||
}
|
||||
resp := rec.Reply()
|
||||
code = code // TODO(miek): test
|
||||
// if nil then?
|
||||
|
||||
sort.Sort(rrSet(resp.Answer))
|
||||
sort.Sort(rrSet(resp.Ns))
|
||||
sort.Sort(rrSet(resp.Extra))
|
||||
|
||||
t.Logf("%v\n", resp)
|
||||
|
||||
if resp.Rcode != tc.Rcode {
|
||||
t.Errorf("rcode is %q, expected %q", dns.RcodeToString[resp.Rcode], dns.RcodeToString[tc.Rcode])
|
||||
continue
|
||||
|
@ -139,6 +139,9 @@ var services = []*msg.Service{
|
|||
// CNAME dedup Test
|
||||
{Host: "www.miek.nl", Key: "a.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{
|
||||
|
@ -185,13 +188,12 @@ var dnsTestCases = []dnsTestCase{
|
|||
newCNAME("www.miek.nl. 303 IN CNAME a.miek.nl."),
|
||||
},
|
||||
},
|
||||
// CNAME (unresolvable internal name)
|
||||
{
|
||||
Qname: "cname.prod.region1.skydns.test.", Qtype: dns.TypeA,
|
||||
Ns: []dns.RR{newSOA("skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 1407441600 28800 7200 604800 60")},
|
||||
},
|
||||
/*
|
||||
// CNAME (unresolvable internal name)
|
||||
{
|
||||
Qname: "2.cname.skydns.test.", Qtype: dns.TypeA,
|
||||
Answer: []dns.RR{},
|
||||
Ns: []dns.RR{newSOA("skydns.test. 60 SOA ns.dns.skydns.test. hostmaster.skydns.test. 1407441600 28800 7200 604800 60")},
|
||||
},
|
||||
// CNAME loop detection
|
||||
{
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue