mirror of
https://github.com/coredns/coredns.git
synced 2025-11-06 12:06:37 -05:00
plugin/rewrite: handle continue in response rewrite (#1740)
* handle continue in response rewrite * add test
This commit is contained in:
committed by
Miek Gieben
parent
3236464223
commit
47b2b10209
@@ -11,12 +11,7 @@ import (
|
|||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResponseReverter(t *testing.T) {
|
var tests = []struct {
|
||||||
rules := []Rule{}
|
|
||||||
r, _ := newNameRule("stop", "regex", `(core)\.(dns)\.(rocks)`, "{2}.{1}.{3}", "answer", "name", `(dns)\.(core)\.(rocks)`, "{2}.{1}.{3}")
|
|
||||||
rules = append(rules, r)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
from string
|
from string
|
||||||
fromType uint16
|
fromType uint16
|
||||||
answer []dns.RR
|
answer []dns.RR
|
||||||
@@ -35,6 +30,22 @@ func TestResponseReverter(t *testing.T) {
|
|||||||
}, "core.dns.rocks", dns.TypeA, false},
|
}, "core.dns.rocks", dns.TypeA, false},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResponseReverter(t *testing.T) {
|
||||||
|
|
||||||
|
rules := []Rule{}
|
||||||
|
r, _ := newNameRule("stop", "regex", `(core)\.(dns)\.(rocks)`, "{2}.{1}.{3}", "answer", "name", `(dns)\.(core)\.(rocks)`, "{2}.{1}.{3}")
|
||||||
|
rules = append(rules, r)
|
||||||
|
|
||||||
|
doReverterTests(rules, t)
|
||||||
|
|
||||||
|
rules = []Rule{}
|
||||||
|
r, _ = newNameRule("continue", "regex", `(core)\.(dns)\.(rocks)`, "{2}.{1}.{3}", "answer", "name", `(dns)\.(core)\.(rocks)`, "{2}.{1}.{3}")
|
||||||
|
rules = append(rules, r)
|
||||||
|
|
||||||
|
doReverterTests(rules, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func doReverterTests(rules []Rule, t *testing.T) {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
|
|||||||
@@ -64,8 +64,11 @@ func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if rw.noRevert || len(wr.ResponseRules) == 0 {
|
||||||
return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, w, r)
|
return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, w, r)
|
||||||
}
|
}
|
||||||
|
return plugin.NextOrFailure(rw.Name(), rw.Next, ctx, wr, r)
|
||||||
|
}
|
||||||
|
|
||||||
// Name implements the Handler interface.
|
// Name implements the Handler interface.
|
||||||
func (rw Rewrite) Name() string { return "rewrite" }
|
func (rw Rewrite) Name() string { return "rewrite" }
|
||||||
|
|||||||
Reference in New Issue
Block a user