plugin/hosts: fall through unsupported query types (#8193)

This commit is contained in:
houyuwushang
2026-06-24 17:28:20 +08:00
committed by GitHub
parent fc447d0658
commit faeb8ba699
2 changed files with 33 additions and 0 deletions

View File

@@ -57,6 +57,35 @@ 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(),
},
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{})
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)
}
}
var hostsTestCases = []test.Case{
{
Qname: "example.org.", Qtype: dns.TypeA,