mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
plugin/rewrite: prevent illegal names (#1972)
Log and returns an error when the name rewrite creates a name that is illegal. Add test in name_test.go to see if an error is returned. Possible followup could be the only check this if a name-rewrite is done. Fixes: #1638 Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
committed by
Paul Greenberg
parent
8d9cf95ee8
commit
d9b9a955ba
33
plugin/rewrite/name_test.go
Normal file
33
plugin/rewrite/name_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package rewrite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func TestRewriteIllegalName(t *testing.T) {
|
||||
r, _ := newNameRule("stop", "example.org.", "example..org.")
|
||||
|
||||
rw := Rewrite{
|
||||
Next: plugin.HandlerFunc(msgPrinter),
|
||||
Rules: []Rule{r},
|
||||
noRevert: true,
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("example.org.", dns.TypeA)
|
||||
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
_, err := rw.ServeDNS(ctx, rec, m)
|
||||
if !strings.Contains(err.Error(), "invalid name") {
|
||||
t.Errorf("Expected invalid name, got %s", err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user