mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
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:
@@ -64,10 +64,7 @@ func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||
z, ok := a.Zones.Z[zone]
|
||||
a.Zones.RUnlock()
|
||||
|
||||
if !ok {
|
||||
return a.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
if z == nil {
|
||||
if !ok || z == nil {
|
||||
return dns.RcodeServerFailure, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
z, ok := f.Zones.Z[zone]
|
||||
if !ok {
|
||||
return f.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
if z == nil {
|
||||
if !ok || z == nil {
|
||||
return dns.RcodeServerFailure, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@ IN SOA sns.dns.icann.org. noc.dns.icann.org. 2016082534 7200 3600 1209600 3600
|
||||
NS a.iana-servers.net.
|
||||
|
||||
Reference in New Issue
Block a user