Issue 388 (#389)

* add extra test

* middleware/auto: fix crash when calling empty handler

Don't call the next middleware, we should be auth. for this zone
getitng into this path we should respond with ServFail.

Fixes #388
This commit is contained in:
Miek Gieben
2016-11-07 11:12:20 +00:00
committed by GitHub
parent 0f22d32191
commit 3d5be649a2
3 changed files with 41 additions and 8 deletions

View File

@@ -64,10 +64,7 @@ func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
z, ok := a.Zones.Z[zone] z, ok := a.Zones.Z[zone]
a.Zones.RUnlock() a.Zones.RUnlock()
if !ok { if !ok || z == nil {
return a.Next.ServeDNS(ctx, w, r)
}
if z == nil {
return dns.RcodeServerFailure, nil return dns.RcodeServerFailure, nil
} }

View File

@@ -43,11 +43,9 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
} }
return dns.RcodeServerFailure, errors.New("no next middleware found") return dns.RcodeServerFailure, errors.New("no next middleware found")
} }
z, ok := f.Zones.Z[zone] z, ok := f.Zones.Z[zone]
if !ok { if !ok || z == nil {
return f.Next.ServeDNS(ctx, w, r)
}
if z == nil {
return dns.RcodeServerFailure, nil return dns.RcodeServerFailure, nil
} }

View File

@@ -79,6 +79,44 @@ func TestAuto(t *testing.T) {
} }
} }
func TestAutoNonExistentZone(t *testing.T) {
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
if err != nil {
t.Fatal(err)
}
log.SetOutput(ioutil.Discard)
corefile := `.:0 {
auto {
directory ` + tmpdir + ` (.*) {1} 1
}
errors stdout
}
`
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()
p := proxy.New([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.org.", dns.TypeA)
if err != nil {
t.Fatal("Expected to receive reply, but didn't")
}
if resp.Rcode != dns.RcodeServerFailure {
t.Fatalf("Expected reply to be a SERVFAIL, got %d", resp.Rcode)
}
}
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.