From a997161e7e840580aea8ff80df0982fe60e5df68 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 18:59:09 -1000 Subject: Test the cache key length a slot can take The over-long key was 6000 bytes and the ordinary one about 30, so the limit could move by kilobytes either way and pass, and the warning went to /dev/null. --- tests/t0003-cache.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'tests/t0003-cache.sh') diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index 8f72a6c..618fb7d 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -157,23 +157,27 @@ test_expect_success 'a page larger than the buffer is kept and replayed whole' ' test_cmp big.nocache.body big.second.body ' -# A slot stores its key ahead of the content and only the first few kilobytes of -# it are read back, so a key longer than that could never match. A request -# carrying one used to leave a slot behind on every visit that nothing could -# ever go on to use. -test_expect_success 'an over-long cache key leaves no slot behind' ' +# A slot is read back in one read of 4096 bytes, which has to take in the key +# and its NUL, so a longer key could never match. A request carrying one used +# to leave a slot behind on every visit that nothing could ever go on to use. +# The key is the scheme, host, path and query, each behind its length, so with +# no host or path a query of 4077 bytes makes a key of 4095. +test_expect_success 'a cache key past 4095 bytes leaves no slot behind' ' rm -rf cache3 && mkdir cache3 && - long=$(awk "BEGIN{s=\"\";for(i=0;i<6000;i++)s=s \"k\"; print s}") && - cgit_rc bigkeyrc "url=bigpage/&q=$long" >key.out 2>/dev/null && - grep "" key.out && + cgit_rc bigkeyrc "url=bigpage/&q=$(printf "%04063d" 0)" >key.out 2>key.err && + test_grep "" key.out && + test_grep "Cache key too long for a slot" key.err && test_dir_is_empty cache3 ' -test_expect_success 'an ordinary key still fills a slot' ' +test_expect_success 'a cache key of 4095 bytes fills a slot' ' rm -rf cache3 && mkdir cache3 && - cgit_rc bigkeyrc "url=bigpage/" >/dev/null && + cgit_ok bigkeyrc "url=bigpage/&q=$(printf "%04062d" 0)" >/dev/null && ls cache3 >key.slots && - test_line_count = 1 key.slots + test_line_count = 1 key.slots && + tr "\000" "\n" <"cache3/$(cat key.slots)" | awk "{ print length; exit }" >key.length && + echo 4095 >expect && + test_cmp expect key.length ' # An error page fired after rendering began abandons the fill with part of -- cgit 2.12.1