plugin/rewrite: handle continue in response rewrite (#1740)

* handle continue in response rewrite

* add test
This commit is contained in:
Chris O'Haver
2018-04-27 02:05:44 -04:00
committed by Miek Gieben
parent 3236464223
commit 47b2b10209
2 changed files with 33 additions and 19 deletions

View File

@@ -11,30 +11,41 @@ import (
"github.com/miekg/dns"
)
var tests = []struct {
from string
fromType uint16
answer []dns.RR
to string
toType uint16
noRevert bool
}{
{"core.dns.rocks", dns.TypeA, []dns.RR{test.A("dns.core.rocks. 5 IN A 10.0.0.1")}, "core.dns.rocks", dns.TypeA, false},
{"core.dns.rocks", dns.TypeSRV, []dns.RR{test.SRV("dns.core.rocks. 5 IN SRV 0 100 100 srv1.dns.core.rocks.")}, "core.dns.rocks", dns.TypeSRV, false},
{"core.dns.rocks", dns.TypeA, []dns.RR{test.A("core.dns.rocks. 5 IN A 10.0.0.1")}, "dns.core.rocks.", dns.TypeA, true},
{"core.dns.rocks", dns.TypeSRV, []dns.RR{test.SRV("core.dns.rocks. 5 IN SRV 0 100 100 srv1.dns.core.rocks.")}, "dns.core.rocks.", dns.TypeSRV, true},
{"core.dns.rocks", dns.TypeHINFO, []dns.RR{test.HINFO("core.dns.rocks. 5 HINFO INTEL-64 \"RHEL 7.4\"")}, "core.dns.rocks", dns.TypeHINFO, false},
{"core.dns.rocks", dns.TypeA, []dns.RR{
test.A("dns.core.rocks. 5 IN A 10.0.0.1"),
test.A("dns.core.rocks. 5 IN A 10.0.0.2"),
}, "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)
tests := []struct {
from string
fromType uint16
answer []dns.RR
to string
toType uint16
noRevert bool
}{
{"core.dns.rocks", dns.TypeA, []dns.RR{test.A("dns.core.rocks. 5 IN A 10.0.0.1")}, "core.dns.rocks", dns.TypeA, false},
{"core.dns.rocks", dns.TypeSRV, []dns.RR{test.SRV("dns.core.rocks. 5 IN SRV 0 100 100 srv1.dns.core.rocks.")}, "core.dns.rocks", dns.TypeSRV, false},
{"core.dns.rocks", dns.TypeA, []dns.RR{test.A("core.dns.rocks. 5 IN A 10.0.0.1")}, "dns.core.rocks.", dns.TypeA, true},
{"core.dns.rocks", dns.TypeSRV, []dns.RR{test.SRV("core.dns.rocks. 5 IN SRV 0 100 100 srv1.dns.core.rocks.")}, "dns.core.rocks.", dns.TypeSRV, true},
{"core.dns.rocks", dns.TypeHINFO, []dns.RR{test.HINFO("core.dns.rocks. 5 HINFO INTEL-64 \"RHEL 7.4\"")}, "core.dns.rocks", dns.TypeHINFO, false},
{"core.dns.rocks", dns.TypeA, []dns.RR{
test.A("dns.core.rocks. 5 IN A 10.0.0.1"),
test.A("dns.core.rocks. 5 IN A 10.0.0.2"),
}, "core.dns.rocks", dns.TypeA, false},
}
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()
for i, tc := range tests {
m := new(dns.Msg)