diff options
author | 2018-04-27 02:05:44 -0400 | |
---|---|---|
committer | 2018-04-27 07:05:44 +0100 | |
commit | 47b2b102091db3ca3fb67761d7952a9723da08ff (patch) | |
tree | c4c927df9aa41617e17484eabb5cf2c505fe5c25 /plugin/rewrite/reverter_test.go | |
parent | 3236464223d64bfb8c3b98504226582c9884a0d6 (diff) | |
download | coredns-47b2b102091db3ca3fb67761d7952a9723da08ff.tar.gz coredns-47b2b102091db3ca3fb67761d7952a9723da08ff.tar.zst coredns-47b2b102091db3ca3fb67761d7952a9723da08ff.zip |
plugin/rewrite: handle continue in response rewrite (#1740)
* handle continue in response rewrite
* add test
Diffstat (limited to 'plugin/rewrite/reverter_test.go')
-rw-r--r-- | plugin/rewrite/reverter_test.go | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/plugin/rewrite/reverter_test.go b/plugin/rewrite/reverter_test.go index 685cecac1..d46180af4 100644 --- a/plugin/rewrite/reverter_test.go +++ b/plugin/rewrite/reverter_test.go @@ -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) |