Diff options
Diffstat (limited to '')
-rwxr-xr-xtests/t0204-limits.sh80
1 file changed, 17 insertions, 63 deletions
diff --git a/tests/t0204-limits.sh b/tests/t0204-limits.sh
index 2d33368..ecc33bf 100755
--- a/tests/t0204-limits.sh
+++ b/tests/t0204-limits.sh
@@ -4,17 +4,10 @@
# on the lines and files a diff renders inline, on the size of a blob any
# view will inflate, and the clamp on index query length. Crossing one has
# to trim the page or point somewhere better suited, never drop the request.
-# The last case is the same idea applied to a filter, which degrades to
-# escaped text when its highlighting library is absent.
test_description='Check the ref listing and diff size limits'
. ./setup.sh
-if test "$CGIT_HAS_LUA" -eq 1
-then
- test_set_prereq LUA
-fi
-
# The limits only show themselves against content that crosses them, so the
# fixture carries more branches and tags than max-ref-count allows and a
# commit whose oversized file diff sits beside a small one, which is what
@@ -36,33 +29,16 @@ test_expect_success 'set up limit fixtures' '
git tag tag-$i || exit 1
done
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-ref-count=2" &&
- echo "max-diff-lines=20" &&
- echo "max-diff-files=0" &&
- echo "repo.url=limits" &&
- echo "repo.path=$PWD/repos/limits/.git"
- } >limitrc &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-diff-files=1" &&
- echo "repo.url=limits" &&
- echo "repo.path=$PWD/repos/limits/.git"
- } >limitfilesrc
+ cgitrc_repo limitrc limits max-ref-count=2 max-diff-lines=20 max-diff-files=0 &&
+ cgitrc_repo limitfilesrc limits max-diff-files=1
'
-limitq() { CGIT_CONFIG="$PWD/limitrc" QUERY_STRING="$1" cgit; }
-
# An index query is compared against every repository the listing holds, so
# an enormous one multiplies out across the whole index. Clamping it rather
# than refusing it keeps the cost bounded without making an ordinary search
# behave any differently.
test_expect_success 'an enormous query is clamped, not rejected' '
long=$(awk "BEGIN{s=\"\";for(i=0;i<4000;i++)s=s \"a\"; print s}") &&
- test ${#long} -eq 4000 &&
cgit_query "q=$long" >tmp &&
grep "</html>" tmp &&
longest=$(grep -o "aaaa*" tmp | awk "{print length}" | sort -n | tail -1) &&
@@ -71,7 +47,7 @@ test_expect_success 'an enormous query is clamped, not rejected' '
test_expect_success 'an ordinary query still filters the index' '
cgit_query "q=foo" >tmp &&
- grep "foo" tmp &&
+ grep ">foo</a>" tmp &&
! grep ">bar<" tmp
'
@@ -79,7 +55,7 @@ test_expect_success 'an ordinary query still filters the index' '
# hands the overflow to page on their own, so a limit that leaked between the
# two sections would show up as the wrong link or the wrong count here.
test_expect_success 'refs page lists max-ref-count branches and tags' '
- limitq "url=limits/refs/" >tmp &&
+ cgit_rc limitrc "url=limits/refs/" >tmp &&
test $(grep -c "log/?h=" tmp) -eq 2 &&
test $(grep -c "/tag/?h=tag-" tmp) -eq 2
'
@@ -90,16 +66,16 @@ test_expect_success 'refs page links each overflow to its own category' '
'
test_expect_success 'branch page paginates independently' '
- limitq "url=limits/refs/heads/" >tmp &&
+ cgit_rc limitrc "url=limits/refs/heads/" >tmp &&
test $(grep -c "log/?h=" tmp) -eq 2 &&
grep "\[next\]" tmp &&
- limitq "url=limits/refs/heads/&ofs=2" >tmp &&
+ cgit_rc limitrc "url=limits/refs/heads/&ofs=2" >tmp &&
grep "\[prev\]" tmp &&
! grep "/tag/?h=tag-" tmp
'
test_expect_success 'tag page paginates independently' '
- limitq "url=limits/refs/tags/&ofs=2" >tmp &&
+ cgit_rc limitrc "url=limits/refs/tags/&ofs=2" >tmp &&
grep "/tag/?h=tag-" tmp &&
grep "\[prev\]" tmp &&
! grep "log/?h=" tmp
@@ -115,8 +91,8 @@ test_expect_success 'a negative ref count lists every ref' '
echo "summary-tags=$n" &&
sed "s/^max-ref-count=2$/max-ref-count=$n/" limitrc
} >count$n.rc &&
- CGIT_CONFIG="$PWD/count$n.rc" QUERY_STRING="url=limits/refs/" cgit >refs$n &&
- CGIT_CONFIG="$PWD/count$n.rc" QUERY_STRING="url=limits/" cgit >summary$n ||
+ cgit_rc count$n.rc "url=limits/refs/" >refs$n &&
+ cgit_rc count$n.rc "url=limits/" >summary$n ||
return 1
done &&
grep "log/?h=branch-3" refs0 &&
@@ -130,7 +106,7 @@ test_expect_success 'a negative ref count lists every ref' '
# The rest of the commit still renders, so one huge file cannot hide the
# small change beside it.
test_expect_success 'oversized file diff is replaced by a link' '
- limitq "url=limits/commit/" >tmp &&
+ cgit_rc limitrc "url=limits/commit/" >tmp &&
grep "too large to be rendered inline" tmp &&
grep "View it on its own page" tmp
'
@@ -140,7 +116,7 @@ test_expect_success 'small file in the same commit still renders inline' '
'
test_expect_success 'the single-file diff page always renders in full' '
- limitq "url=limits/diff/big.c" >tmp &&
+ cgit_rc limitrc "url=limits/diff/big.c" >tmp &&
grep "class=.hunk." tmp &&
! grep "too large to be rendered inline" tmp
'
@@ -149,13 +125,13 @@ test_expect_success 'the single-file diff page always renders in full' '
# so it drops the whole body back to the diffstat while a request naming a
# single file stays unaffected.
test_expect_success 'a commit changing too many files shows stat only' '
- CGIT_CONFIG="$PWD/limitfilesrc" QUERY_STRING="url=limits/commit/" cgit >tmp &&
+ cgit_rc limitfilesrc "url=limits/commit/" >tmp &&
grep "too large to be rendered inline" tmp &&
! grep "class=.hunk." tmp
'
test_expect_success 'the single-file page is not limited by max-diff-files' '
- CGIT_CONFIG="$PWD/limitfilesrc" QUERY_STRING="url=limits/diff/small.c" cgit >tmp &&
+ cgit_rc limitfilesrc "url=limits/diff/small.c" >tmp &&
grep "class=.hunk." tmp
'
@@ -172,15 +148,9 @@ test_expect_success 'a diff of an oversized blob is not inlined' '
awk "BEGIN{for(i=0;i<401;i++)print \"aaaaaaaa\"}" >big.txt &&
git commit -am change
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-blob-size=1" &&
- echo "repo.url=blobdiff" &&
- echo "repo.path=$PWD/repos/blobdiff/.git"
- } >blobdiffrc &&
+ cgitrc_repo blobdiffrc blobdiff max-blob-size=1 &&
sha=$(git -C repos/blobdiff rev-parse HEAD) &&
- CGIT_CONFIG="$PWD/blobdiffrc" QUERY_STRING="url=blobdiff/commit/&id=$sha" cgit >tmp &&
+ cgit_rc blobdiffrc "url=blobdiff/commit/&id=$sha" >tmp &&
grep "Binary files differ" tmp &&
! grep "aaaaaaaa" tmp
'
@@ -192,28 +162,12 @@ test_expect_success 'every page showing a blob refuses an oversized one alike' '
} >blobpagesrc &&
for page in tree plain blob blame
do
- CGIT_CONFIG="$PWD/blobpagesrc" QUERY_STRING="url=blobdiff/$page/big.txt" cgit >tmp &&
+ cgit_rc blobpagesrc "url=blobdiff/$page/big.txt" >tmp &&
grep "^Status: 413 Content Too Large" tmp &&
grep "Blob size (3 KB) exceeds the limit (1 KB)" tmp || return 1
done
'
-# A missing scintillua leaves the shipped filter with nothing to highlight
-# with, and a filter that failed there would take the whole page down with
-# it, so it has to hand the source back escaped instead.
-test_expect_success LUA 'highlight filter passes text through without scintillua' '
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "source-filter=lua:$(cd "$TEST_OUTPUT_DIRECTORY/../custom/extensions" && pwd)/syntax-highlight.lua" &&
- echo "repo.url=limits" &&
- echo "repo.path=$PWD/repos/limits/.git"
- } >hlrc &&
- CGIT_SCINTILLUA_PATH=/nonexistent CGIT_CONFIG="$PWD/hlrc" \
- QUERY_STRING="url=limits/tree/small.c" cgit >tmp &&
- grep "int y;" tmp
-'
-
# The patch and rawdiff pages hand the work to git, whose own limit on an
# inlined blob is far past max-blob-size, so the cap is passed through to it.
test_expect_success 'patch and rawdiff show an oversized blob as binary' '
@@ -226,7 +180,7 @@ test_expect_success 'patch and rawdiff show an oversized blob as binary' '
} >blobrc &&
for p in patch rawdiff
do
- CGIT_CONFIG="$PWD/blobrc" QUERY_STRING="url=limits/$p/" cgit >tmp &&
+ cgit_rc blobrc "url=limits/$p/" >tmp &&
grep "^Binary files" tmp &&
! grep "^+1999$" tmp || return 1
done