oops forget to checkin (#111)

This commit is contained in:
Miek Gieben 2016-04-12 21:50:01 +01:00
parent 9ee41a399a
commit 842953f179
2 changed files with 8 additions and 29 deletions

View file

@ -3,7 +3,6 @@
package etcd
import (
"sort"
"testing"
"github.com/miekg/coredns/middleware"
@ -11,7 +10,7 @@ import (
"github.com/miekg/dns"
)
func TestStubLookup(t *testing.T) {
func TestStubCycle(t *testing.T) {
// reuse servics from stub_test.go
for _, serv := range servicesStub {
set(t, etc, serv.Key, 0, serv)
@ -28,34 +27,13 @@ func TestStubLookup(t *testing.T) {
rec := middleware.NewResponseRecorder(&test.ResponseWriter{})
_, err := etc.ServeDNS(ctx, rec, m)
if err != nil {
t.Errorf("expected no error, got %v\n", err)
if err == nil {
t.Errorf("expected error, got none")
continue
}
resp := rec.Msg()
sort.Sort(test.RRSet(resp.Answer))
sort.Sort(test.RRSet(resp.Ns))
sort.Sort(test.RRSet(resp.Extra))
if !test.Header(t, tc, resp) {
t.Logf("%v\n", resp)
continue
}
if !test.Section(t, tc, test.Answer, resp.Answer) {
t.Logf("%v\n", resp)
}
if !test.Section(t, tc, test.Ns, resp.Ns) {
t.Logf("%v\n", resp)
}
if !test.Section(t, tc, test.Extra, resp.Extra) {
t.Logf("%v\n", resp)
}
// err should have been, set msg is nil, CoreDNS middlware handling takes
// care of proper error to client.
}
}
var dnsTestCasesCycleStub = []test.Case{
{
Qname: "example.org.", Qtype: dns.TypeA, Rcode: dns.RcodeRefused, Do: true,
},
}
var dnsTestCasesCycleStub = []test.Case{{Qname: "example.org.", Qtype: dns.TypeA, Rcode: dns.RcodeRefused, Do: true}}

View file

@ -1,6 +1,7 @@
package etcd
import (
"errors"
"log"
"github.com/miekg/coredns/middleware"
@ -18,7 +19,7 @@ type Stub struct {
func (s Stub) ServeDNS(ctx context.Context, w dns.ResponseWriter, req *dns.Msg) (int, error) {
if hasStubEdns0(req) {
log.Printf("[WARNING] Forwarding cycle detected, refusing msg: %s", req.Question[0].Name)
return dns.RcodeRefused, nil
return dns.RcodeRefused, errors.New("stub forward cycle")
}
req = addStubEdns0(req)
proxy, ok := (*s.Etcd.Stubmap)[s.Zone]