mirror of
https://github.com/coredns/coredns.git
synced 2026-07-22 23:50:10 -04:00
plugin/hosts: make unsupported type fallthrough opt-in (#8282)
This commit is contained in:
@@ -58,31 +58,81 @@ func TestLookupA(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFallthroughUnsupportedType(t *testing.T) {
|
||||
h := Hosts{
|
||||
Next: test.NextHandler(dns.RcodeRefused, nil),
|
||||
Hostsfile: &Hostsfile{
|
||||
Origins: []string{"."},
|
||||
hmap: newMap(),
|
||||
inline: newMap(),
|
||||
options: newOptions(),
|
||||
tests := []struct {
|
||||
name string
|
||||
qname string
|
||||
fall fall.F
|
||||
unsupported bool
|
||||
expectFallthrough bool
|
||||
}{
|
||||
{
|
||||
name: "existing name returns nodata by default",
|
||||
qname: "example.org.",
|
||||
fall: fall.Root,
|
||||
},
|
||||
{
|
||||
name: "existing name falls through with opt-in",
|
||||
qname: "example.org.",
|
||||
fall: fall.Root,
|
||||
unsupported: true,
|
||||
expectFallthrough: true,
|
||||
},
|
||||
{
|
||||
name: "opt-in respects fallthrough zones",
|
||||
qname: "example.org.",
|
||||
fall: fall.F{Zones: []string{"example.net."}},
|
||||
unsupported: true,
|
||||
},
|
||||
{
|
||||
name: "missing name still falls through",
|
||||
qname: "missing.example.org.",
|
||||
fall: fall.Root,
|
||||
expectFallthrough: true,
|
||||
},
|
||||
Fall: fall.Root,
|
||||
}
|
||||
h.hmap = h.parse(strings.NewReader(hostsExample))
|
||||
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("example.org.", dns.TypeTXT)
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
h := Hosts{
|
||||
Next: test.NextHandler(dns.RcodeRefused, nil),
|
||||
Hostsfile: &Hostsfile{
|
||||
Origins: []string{"."},
|
||||
hmap: newMap(),
|
||||
inline: newMap(),
|
||||
options: newOptions(),
|
||||
},
|
||||
Fall: tc.fall,
|
||||
fallthroughUnsupported: tc.unsupported,
|
||||
}
|
||||
h.hmap = h.parse(strings.NewReader(hostsExample))
|
||||
|
||||
rcode, err := h.ServeDNS(context.Background(), rec, m)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no error, got %v", err)
|
||||
}
|
||||
if rcode != dns.RcodeRefused {
|
||||
t.Fatalf("Expected fallthrough rcode %d, got %d", dns.RcodeRefused, rcode)
|
||||
}
|
||||
if rec.Msg != nil {
|
||||
t.Fatalf("Expected no response from hosts after fallthrough, got %#v", rec.Msg)
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion(tc.qname, dns.TypeTXT)
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
|
||||
rcode, err := h.ServeDNS(context.Background(), rec, m)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no error, got %v", err)
|
||||
}
|
||||
if tc.expectFallthrough {
|
||||
if rcode != dns.RcodeRefused {
|
||||
t.Fatalf("Expected fallthrough rcode %d, got %d", dns.RcodeRefused, rcode)
|
||||
}
|
||||
if rec.Msg != nil {
|
||||
t.Fatalf("Expected no response from hosts after fallthrough, got %#v", rec.Msg)
|
||||
}
|
||||
return
|
||||
}
|
||||
if rcode != dns.RcodeSuccess {
|
||||
t.Fatalf("Expected authoritative NODATA rcode %d, got %d", dns.RcodeSuccess, rcode)
|
||||
}
|
||||
if rec.Msg == nil {
|
||||
t.Fatal("Expected authoritative NODATA response from hosts, got no response")
|
||||
}
|
||||
if !rec.Msg.Authoritative || len(rec.Msg.Answer) != 0 {
|
||||
t.Fatalf("Expected authoritative NODATA response, got %#v", rec.Msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user