plugin/rewrite: Write failures with ResponseReverter (#5150)

* write failures with ResponseReverter instead of letting server write them

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* fix comment

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver 2022-02-01 16:54:06 -05:00 committed by GitHub
parent 49ee97994e
commit 911891f485
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View file

@ -7,6 +7,34 @@ import (
"github.com/miekg/dns"
)
func TestRewriteFailure(t *testing.T) {
t.Parallel()
i, udp, _, err := CoreDNSServerAndPorts(`.:0 {
rewrite name regex (.*)\.test\.$ {1}. answer auto
# no next plugin to induce SERVFAIL
}`)
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
defer i.Stop()
m := new(dns.Msg)
m.SetQuestion("example.test.", dns.TypeMX)
r, err := dns.Exchange(m, udp)
if err != nil {
t.Fatalf("Expected to receive reply, but didn't: %s", err)
}
if len(r.Question) == 0 {
t.Error("Invalid empty question section")
}
if r.Question[0].Name != "example.test." {
t.Errorf("Question section mismatch. expected \"example.test.\" got %q", r.Question[0].Name)
}
}
func TestRewrite(t *testing.T) {
t.Parallel()
corefile := `.:0 {