aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-05-09 12:35:42 +0100
committerGravatar GitHub <noreply@github.com> 2018-05-09 12:35:42 +0100
commit0e5e59c327387472c60fb5f2f2c7d84a89b879c9 (patch)
tree48a0c7a1fcb6e94fc889e1cd4fd57632414f3e16 /plugin
parent68b45f5377ff0c8661f987398e316f3acae4835d (diff)
downloadcoredns-0e5e59c327387472c60fb5f2f2c7d84a89b879c9.tar.gz
coredns-0e5e59c327387472c60fb5f2f2c7d84a89b879c9.tar.zst
coredns-0e5e59c327387472c60fb5f2f2c7d84a89b879c9.zip
request.Match check Response bit as well (#1775)
* request.Match check Response bit as well We should check this bit and reject them as invalid. * Fix test
Diffstat (limited to 'plugin')
-rw-r--r--plugin/cache/cache.go1
-rw-r--r--plugin/cache/spoof_test.go22
2 files changed, 19 insertions, 4 deletions
diff --git a/plugin/cache/cache.go b/plugin/cache/cache.go
index 972c2b5e1..4e64fa733 100644
--- a/plugin/cache/cache.go
+++ b/plugin/cache/cache.go
@@ -130,7 +130,6 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
}
if key != -1 && duration > 0 {
-
if w.state.Match(res) {
w.set(res, key, mt, duration)
cacheSize.WithLabelValues(w.server, Success).Set(float64(w.pcache.Len()))
diff --git a/plugin/cache/spoof_test.go b/plugin/cache/spoof_test.go
index e9c618f03..71930f4dc 100644
--- a/plugin/cache/spoof_test.go
+++ b/plugin/cache/spoof_test.go
@@ -14,7 +14,7 @@ import (
func TestSpoof(t *testing.T) {
// Send query for example.org, get reply for example.net; should not be cached.
c := New()
- c.Next = spoofHandler()
+ c.Next = spoofHandler(true)
req := new(dns.Msg)
req.SetQuestion("example.org.", dns.TypeA)
@@ -39,13 +39,29 @@ func TestSpoof(t *testing.T) {
}
}
+func TestResponse(t *testing.T) {
+ // Send query for example.org, get reply for example.net; should not be cached.
+ c := New()
+ c.Next = spoofHandler(false)
+
+ req := new(dns.Msg)
+ req.SetQuestion("example.net.", dns.TypeA)
+ rec := dnstest.NewRecorder(&test.ResponseWriter{})
+
+ c.ServeDNS(context.TODO(), rec, req)
+
+ if c.pcache.Len() != 0 {
+ t.Errorf("cached %s, while reply had response set to %t", "example.net.", rec.Msg.Response)
+ }
+}
+
// spoofHandler is a fake plugin implementation which returns a single A records for example.org. The qname in the
// question section is set to example.NET (i.e. they *don't* match).
-func spoofHandler() plugin.Handler {
+func spoofHandler(response bool) plugin.Handler {
return plugin.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
m := new(dns.Msg)
m.SetQuestion("example.net.", dns.TypeA)
- m.Response = true
+ m.Response = response
m.Answer = []dns.RR{test.A("example.org. IN A 127.0.0.53")}
w.WriteMsg(m)
return dns.RcodeSuccess, nil