]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache.clear: clearing root clears everything, not only the root zone
authorPetr Špaček <petr.spacek@nic.cz>
Fri, 17 Aug 2018 13:40:20 +0000 (15:40 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 17 Aug 2018 16:04:19 +0000 (18:04 +0200)
Problem was caused by our lookup format where only the root zone starts
with \0 and all other zones start differently. This caused
cache_match('.') to match only data from root zone.

.luacheckrc
daemon/cache.test/clear.test.lua
daemon/lua/sandbox.lua

index db1471c44caccdb6e78e86c529867a07c77f6edf..644f69aa24b55190ede1cb49f9093cd977da4240 100644 (file)
@@ -79,3 +79,4 @@ files['daemon/lua/kres-gen.lua'].ignore = {'631'} -- Allow overly long lines
 files['scripts'].ignore = {'111', '112', '113'}
 files['tests'].ignore = {'111', '112', '113'}
 files['modules/**/*.test.lua'].ignore = {'111', '112', '113', '121', '122'}
+files['daemon/**/*.test.lua'].ignore = {'111', '112', '113', '121', '122'}
index ff219d619981bb57f4f1696142e8674d6ca67de2..9a412d3e9dcd52b4e7a5efa7b8c54a417cc4b686 100644 (file)
@@ -26,9 +26,9 @@ assert(net.interfaces() ~= nil)
 -- Self-checks on loaded stuff
 assert(#modules.list() > 0)
 -- Self-check timers
-ev = event.recurrent(1 * sec, function (ev) return 1 end)
+ev = event.recurrent(1 * sec, function () return 1 end)
 event.cancel(ev)
-ev = event.after(0, function (ev) return 1 end)
+ev = event.after(0, function () return 1 end)
 
 
 -- import fake root zone
@@ -61,8 +61,8 @@ local function import_zone()
        worker.sleep(0.2)  -- zimport is delayed by 100 ms from function call
        -- sanity checks - cache must be filled in
        ok(cache.count() > 0, 'cache is not empty after import')
-       check_answer('root apex is cache',
-                    '.', kres.type.NS, kres.rcode.NOERROR)
+       check_answer('root apex is in cache',
+                     '.', kres.type.NS, kres.rcode.NOERROR)
        check_answer('deep subdomain is in cache',
                     'a.b.subtree1.', kres.type.AAAA, kres.rcode.NOERROR)
 
@@ -120,23 +120,22 @@ end
 
 local function test_callback()
        local test_name = '20r.subtree2.'
-       local test_maxcount = 1
        local test_exactname = true
        local test_rrtype = nil
-       local test_maxcount = 1
+       local test_chunksize = 1
        local test_prev_state = { works = true }
        local function check_callback(name, exact_name, rr_type, chunk_size, callback, prev_state, errors)
                is(errors.count, 1, 'callback received correct # of removed records')
                is(test_name, name, 'callback received subtree name')
                is(test_exactname, exact_name, 'callback received exact_name')
-               is(test_rrtype, rrtype, 'callback received rr_type')
-               is(test_chunksize, chunksize, 'callback received maxcount')
+               is(test_rrtype, rr_type, 'callback received rr_type')
+               is(test_chunksize, chunk_size, 'callback received chunk_size')
                is(check_callback, callback, 'callback received reference to itself')
                is(type(errors), 'table', 'callback received table of errors')
                same(test_prev_state, prev_state, 'callback received previous state')
                return 666
        end
-       same(cache.clear(test_name, test_exactname, test_rrtype, test_maxcount, check_callback, test_prev_state),
+       same(cache.clear(test_name, test_exactname, test_rrtype, test_chunksize, check_callback, test_prev_state),
             666, 'first callback return value is passed to cache.clear() caller')
        local cnt_before_wait = cache.count()
        worker.sleep(0.2)
@@ -173,6 +172,13 @@ local function test_apex()
                     'a.b.subtree1.', kres.type.NULL, kres.rcode.SERVFAIL)
 end
 
+local function test_root()
+       local prev_count = cache.count()
+       res = cache.clear('.')
+       is(res.count, prev_count, 'full clear reports correct number of entries')
+       is(cache.count(), 0, 'clearing root clears everything')
+end
+
 local function test_complete_flush()
        local prev_count = cache.count()
        res = cache.clear()
@@ -190,5 +196,7 @@ return {
        test_subtree_limit,
        test_apex,
        import_zone,
+       test_root,
+       import_zone,
        test_complete_flush,
 }
index e7990aafa497dc12ded0f77e9d9d7e499805bf52..22db6aac5ecc7abd920bea66c3571cdad8df6f9c 100644 (file)
@@ -159,7 +159,8 @@ setmetatable(modules, {
 
 
 cache.clear = function (name, exact_name, rr_type, chunk_size, callback, prev_state)
-       if name == nil then  -- keep same output format as for 'standard' clear
+       if name == nil or (name == '.' and not exact_name) then
+               -- keep same output format as for 'standard' clear
                local total_count = cache.count()
                if not cache.clear_everything() then
                        error('unable to clear everything')