From 4fbff714736c1bdcd392dd904e007dd10e5a7ee3 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 14:39:02 -1000 Subject: Check the cache the hook tests start from The checks that pages went had nothing proving they were there to begin with, so they would pass with nothing removed if the scan list stopped being written or two keys shared a slot. Nor did anything check that the copy of the hook was pointed at the trash directory, and a renamed line would have left it wiping the system's cache wherever the test user can write it. cached_requests read the lock and the scan list as if they were pages and hid a failing dd. The test without access could not fail, since nothing can be removed there and the scan list alone names a.git, so it now compares the slots with the pristine copy. --- tests/t0507-hooks.sh | 68 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/t0507-hooks.sh b/tests/t0507-hooks.sh index f30bd94..9e5dfce 100755 --- a/tests/t0507-hooks.sh +++ b/tests/t0507-hooks.sh @@ -11,8 +11,32 @@ CGIT_TEST_NO_CREATE_REPOS=YesPlease HOOK_DIRECTORY="$TEST_OUTPUT_DIRECTORY/../custom/hooks" +# The request each page slot in a directory answers, read off its head the +# way the hook reads it, leaving out the locks and the cached repository +# scan. +cached_requests() { + test -d "$1" || return 1 + for slot in "$1"/* + do + case $slot in + *.lock | */rc-*) + continue + ;; + esac + dd if="$slot" bs=4096 count=1 2>/dev/null >slot-head && + tr "\0" "\n" /dev/null && echo writer >slots/0123abcd.lock && cp -R slots pristine && + sort >expect-keys <<-\EOF && + 7|http://0|1|/0| + 7|http://0|7|/a.git/0| + 7|http://0|11|/a.git/log/0| + 7|http://0|7|/b.git/0| + 7|http://0|11|/b.git/log/0| + 7|http://0|0|15|url=a.git/refs/ + 7|http://0|0|15|url=b.git/refs/ + EOF + cached_requests pristine >keys && + sort keys >sorted-keys && + test_cmp expect-keys sorted-keys && + ls pristine >pristine-slots && + grep "^rc-" pristine-slots && sed -e "s|^cache_root=.*|cache_root='\''$PWD/slots'\''|" \ -e "s|^scan_path=.*|scan_path='\''$PWD/scan'\''|" \ - "$HOOK_DIRECTORY/post-receive.cgit-cache" >cache-hook + "$HOOK_DIRECTORY/post-receive.cgit-cache" >cache-hook && + grep -Fx "cache_root='\''$PWD/slots'\''" cache-hook && + grep -Fx "scan_path='\''$PWD/scan'\''" cache-hook ' -# The request each slot answers, read off its head the way the hook reads it. -cached_requests() { - for slot in slots/* - do - dd if="$slot" bs=4096 count=1 2>/dev/null | tr "\0" "\n" | sed -n 1p - done -} - # The hooks are POSIX sh, so each runs under every such shell that is here. shells= for shell in sh dash ksh bash @@ -59,9 +91,9 @@ done for shell in $shells do test_expect_success "a push drops its own pages and the index under $shell" " - rm -rf slots && cp -R pristine slots && + fresh_slots && (cd scan/a.git && $shell ../../cache-hook) && - cached_requests >left && + cached_requests slots >left && grep '|/b.git/log/' left && grep 'url=b.git/refs/' left && ! grep 'a.git' left && @@ -72,27 +104,29 @@ do done test_expect_success 'a repository named in cgitrc gives the hook its url' ' - rm -rf slots && cp -R pristine slots && + fresh_slots && git -C scan/b.git config hooks.cgiturl b.git && sed "s|^scan_path=.*|scan_path=/nonexistent|" cache-hook >named-hook && + grep -Fx "scan_path=/nonexistent" named-hook && (cd scan/b.git && sh ../../named-hook) && - cached_requests >left && + cached_requests slots >left && grep "|/a.git/log/" left && ! grep "b.git" left ' test_expect_success 'with no url to go on the whole cache goes' ' - rm -rf slots && cp -R pristine slots && + fresh_slots && (cd scan/a.git && sh ../../named-hook) && test "$(ls slots)" = 0123abcd.lock ' test_expect_success SANITY 'the cache hook shows a pusher no error' ' - rm -rf slots && cp -R pristine slots && + fresh_slots && test_when_finished "chmod 755 slots" && chmod 555 slots && (cd scan/a.git && sh ../../cache-hook 2>../../err) && - cached_requests | grep "a.git" && + ls slots >left && + test_cmp pristine-slots left && test_must_be_empty err ' -- cgit 2.12.1