aboutsummaryrefslogtreecommitdiff
path: root/plugin/cache/cache_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-09-28 14:22:23 +0100
committerGravatar GitHub <noreply@github.com> 2017-09-28 14:22:23 +0100
commit1e71d0e2c14161ab57c3af44c1a69414335f7ca1 (patch)
treec836f1689a7db0b1dff99bd347ef72244c34a175 /plugin/cache/cache_test.go
parent9d736fd754dfdfbf56a972d1889e6defecc922c4 (diff)
downloadcoredns-1e71d0e2c14161ab57c3af44c1a69414335f7ca1.tar.gz
coredns-1e71d0e2c14161ab57c3af44c1a69414335f7ca1.tar.zst
coredns-1e71d0e2c14161ab57c3af44c1a69414335f7ca1.zip
plugin/cache: don't cache msg with TTL=0 in them (#1116)
Don't cache these - may be lead to weird side effects. Fixes #1113
Diffstat (limited to 'plugin/cache/cache_test.go')
-rw-r--r--plugin/cache/cache_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/plugin/cache/cache_test.go b/plugin/cache/cache_test.go
index ad23f4d5a..7b7c2c6f2 100644
--- a/plugin/cache/cache_test.go
+++ b/plugin/cache/cache_test.go
@@ -208,6 +208,25 @@ func TestCache(t *testing.T) {
}
}
+func TestCacheZeroTTL(t *testing.T) {
+ c := &Cache{Zones: []string{"."}, pcap: defaultCap, ncap: defaultCap, pttl: maxTTL, nttl: maxTTL}
+ c.pcache = cache.New(c.pcap)
+ c.ncache = cache.New(c.ncap)
+ c.Next = zeroTTLBackend()
+
+ req := new(dns.Msg)
+ req.SetQuestion("example.org.", dns.TypeA)
+ ctx := context.TODO()
+
+ c.ServeDNS(ctx, &test.ResponseWriter{}, req)
+ if c.pcache.Len() != 0 {
+ t.Errorf("Msg with 0 TTL should not have been cached")
+ }
+ if c.ncache.Len() != 0 {
+ t.Errorf("Msg with 0 TTL should not have been cached")
+ }
+}
+
func BenchmarkCacheResponse(b *testing.B) {
c := &Cache{Zones: []string{"."}, pcap: defaultCap, ncap: defaultCap, pttl: maxTTL, nttl: maxTTL}
c.pcache = cache.New(c.pcap)
@@ -249,3 +268,15 @@ func BackendHandler() plugin.Handler {
return dns.RcodeSuccess, nil
})
}
+
+func zeroTTLBackend() plugin.Handler {
+ return plugin.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
+ m := new(dns.Msg)
+ m.SetReply(r)
+ m.Response, m.RecursionAvailable = true, true
+
+ m.Answer = []dns.RR{test.A("example.org. 0 IN A 127.0.0.53")}
+ w.WriteMsg(m)
+ return dns.RcodeSuccess, nil
+ })
+}