aboutsummaryrefslogtreecommitdiff
path: root/plugin/cache/do_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2020-09-28 16:53:00 +0200
committerGravatar GitHub <noreply@github.com> 2020-09-28 07:53:00 -0700
commit35b40a84f212223b6da8bae103471f67e3eedac5 (patch)
tree9b9773c21cd214c37dce3936e9ff20ca0186713d /plugin/cache/do_test.go
parent1a1ce9a9c8eadd0e6154dd473a6e22b1f9e37ca2 (diff)
downloadcoredns-35b40a84f212223b6da8bae103471f67e3eedac5.tar.gz
coredns-35b40a84f212223b6da8bae103471f67e3eedac5.tar.zst
coredns-35b40a84f212223b6da8bae103471f67e3eedac5.zip
plugin/cache: Fix filtering (#4148)
The filtering of DNSSEC records in the cache plugin was not done correctly. Also the change to introduced this bug didn't take into account that the cache - by virtue of differentiating between DNSSEC and no-DNSSEC - relied on not copying the data from the cache. This change copies and then filters the data and factors the filtering into a function that is used in two places (albeit with on ugly boolean parameters to prevent copying things twice). Add tests, do_test.go is moved to test/cache_test.go because the OPT handing is done outside of the cache plugin. The core server re-attaches the correct OPT when replying, so that makes for a better e2e test. Added small unit test for filterRRslice and an explicit test that asks for DNSSEC first and then plain, and vice versa to test cache behavior. Fixes: #4146 Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/cache/do_test.go')
-rw-r--r--plugin/cache/do_test.go75
1 files changed, 0 insertions, 75 deletions
diff --git a/plugin/cache/do_test.go b/plugin/cache/do_test.go
deleted file mode 100644
index 3cf87cabe..000000000
--- a/plugin/cache/do_test.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package cache
-
-import (
- "context"
- "testing"
-
- "github.com/coredns/coredns/plugin"
- "github.com/coredns/coredns/plugin/pkg/dnstest"
- "github.com/coredns/coredns/plugin/test"
-
- "github.com/miekg/dns"
-)
-
-func TestDo(t *testing.T) {
- // cache sets Do and requests that don't have them.
- c := New()
- c.Next = echoHandler()
- req := new(dns.Msg)
- req.SetQuestion("example.org.", dns.TypeA)
- rec := dnstest.NewRecorder(&test.ResponseWriter{})
-
- // No DO set.
- c.ServeDNS(context.TODO(), rec, req)
- reply := rec.Msg
- opt := reply.Extra[len(reply.Extra)-1]
- if x, ok := opt.(*dns.OPT); !ok {
- t.Fatalf("Expected OPT RR, got %T", x)
- }
- if !opt.(*dns.OPT).Do() {
- t.Errorf("Expected DO bit to be set, got false")
- }
- if x := opt.(*dns.OPT).UDPSize(); x != defaultUDPBufSize {
- t.Errorf("Expected %d bufsize, got %d", defaultUDPBufSize, x)
- }
-
- // Do set - so left alone.
- const mysize = defaultUDPBufSize * 2
- setDo(req)
- // set bufsize to something else than default to see cache doesn't touch it
- req.Extra[len(req.Extra)-1].(*dns.OPT).SetUDPSize(mysize)
- c.ServeDNS(context.TODO(), rec, req)
- reply = rec.Msg
- opt = reply.Extra[len(reply.Extra)-1]
- if x, ok := opt.(*dns.OPT); !ok {
- t.Fatalf("Expected OPT RR, got %T", x)
- }
- if !opt.(*dns.OPT).Do() {
- t.Errorf("Expected DO bit to be set, got false")
- }
- if x := opt.(*dns.OPT).UDPSize(); x != mysize {
- t.Errorf("Expected %d bufsize, got %d", mysize, x)
- }
-
- // edns0 set, but not DO, so _not_ left alone.
- req.Extra[len(req.Extra)-1].(*dns.OPT).SetDo(false)
- c.ServeDNS(context.TODO(), rec, req)
- reply = rec.Msg
- opt = reply.Extra[len(reply.Extra)-1]
- if x, ok := opt.(*dns.OPT); !ok {
- t.Fatalf("Expected OPT RR, got %T", x)
- }
- if !opt.(*dns.OPT).Do() {
- t.Errorf("Expected DO bit to be set, got false")
- }
- if x := opt.(*dns.OPT).UDPSize(); x != defaultUDPBufSize {
- t.Errorf("Expected %d bufsize, got %d", defaultUDPBufSize, x)
- }
-}
-
-func echoHandler() plugin.Handler {
- return plugin.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
- w.WriteMsg(r)
- return dns.RcodeSuccess, nil
- })
-}