diff options
author | 2022-05-01 08:57:03 -0400 | |
---|---|---|
committer | 2022-05-01 05:57:03 -0700 | |
commit | c4bc1a5471e8829fab317b4693e476c6b416a09c (patch) | |
tree | 2af847dfe0b9c800f1efb95e89a67db4f7753864 /plugin/cache/cache_test.go | |
parent | 5a4437bb23e383ebb7c8fce6c8fbce802831d986 (diff) | |
download | coredns-c4bc1a5471e8829fab317b4693e476c6b416a09c.tar.gz coredns-c4bc1a5471e8829fab317b4693e476c6b416a09c.tar.zst coredns-c4bc1a5471e8829fab317b4693e476c6b416a09c.zip |
plugin/cache: Fix cache poisoning exploit (#5174)
Diffstat (limited to 'plugin/cache/cache_test.go')
-rw-r--r-- | plugin/cache/cache_test.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/plugin/cache/cache_test.go b/plugin/cache/cache_test.go index 9417a59f6..d839ea1a3 100644 --- a/plugin/cache/cache_test.go +++ b/plugin/cache/cache_test.go @@ -191,7 +191,7 @@ func TestCache(t *testing.T) { c, crr := newTestCache(maxTTL) - for _, tc := range cacheTestCases { + for n, tc := range cacheTestCases { m := tc.in.Msg() m = cacheMsg(m, tc) @@ -204,11 +204,15 @@ func TestCache(t *testing.T) { crr.set(m, k, mt, c.pttl) } - i, _ := c.get(time.Now().UTC(), state, "dns://:53") + i := c.getIgnoreTTL(time.Now().UTC(), state, "dns://:53") ok := i != nil - if ok != tc.shouldCache { - t.Errorf("Cached message that should not have been cached: %s", state.Name()) + if !tc.shouldCache && ok { + t.Errorf("Test %d: Cached message that should not have been cached: %s", n, state.Name()) + continue + } + if tc.shouldCache && !ok { + t.Errorf("Test %d: Did not cache message that should have been cached: %s", n, state.Name()) continue } |