From 7a08b450b80e8efb81b980a87e06ae65bb62f753 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 14:56:59 -0700 Subject: Move the later tests to the config writers The one-line request wrappers go with them. Configs with several repositories, a key out of place on purpose, the cache on or no repository of their own stay written out. --- tests/t0201-filters.sh | 31 +++--- tests/t0202-submodule-links.sh | 4 +- tests/t0203-dates.sh | 26 +++-- tests/t0204-limits.sh | 54 +++------- tests/t0205-config.sh | 23 ++--- tests/t0206-trailers.sh | 2 +- tests/t0208-mailmap.sh | 2 +- tests/t0301-security.sh | 135 +++++++------------------ tests/t0303-robustness.sh | 219 +++++++++++++++++------------------------ tests/t0505-auth.sh | 2 +- tests/t0507-hooks.sh | 4 +- 11 files changed, 182 insertions(+), 320 deletions(-) (limited to 'tests') diff --git a/tests/t0201-filters.sh b/tests/t0201-filters.sh index 2e59a1d..8d8743a 100755 --- a/tests/t0201-filters.sh +++ b/tests/t0201-filters.sh @@ -57,9 +57,8 @@ do done test_expect_success 'the blame page goes through the source filter too' ' - echo "enable-blame=1" >blamerc && - sed "s/^cache-size=.*/cache-size=0/" cgitrc >>blamerc && - CGIT_CONFIG="$PWD/blamerc" QUERY_STRING="url=filter-exec/blame/a%2bb" cgit >tmp && + cgitrc_copy blamerc enable-blame=1 && + cgit_rc blamerc "url=filter-exec/blame/a%2bb" >tmp && grep "" tmp && grep "a+b HELLO$" tmp ' @@ -67,22 +66,14 @@ test_expect_success 'the blame page goes through the source filter too' ' # A readme read at another branch links into the tree at that branch, which # the filter is told as the query to follow a path with. test_expect_success 'the about filter gets the tree url at the readme branch' ' - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "readme=:a+b" && - echo "about-filter=exec:$FILTER_DIRECTORY/dump.sh" && - echo "root-readme=$PWD/root.txt" && - echo "repo.url=filtered" && - echo "repo.path=$PWD/repos/filter/.git" - } >aboutargsrc && - CGIT_CONFIG="$PWD/aboutargsrc" QUERY_STRING="url=filtered/about/&h=1%2b2" cgit >tmp && + cgitrc_repo aboutargsrc filtered readme=:a+b "about-filter=exec:$FILTER_DIRECTORY/dump.sh" "root-readme=$PWD/root.txt" "repo.path=$PWD/repos/filter/.git" && + cgit_rc aboutargsrc "url=filtered/about/&h=1%2b2" >tmp && grep "
a+b /filtered/tree/ ?h=1%2B2 HELLO" tmp ' test_expect_success 'the site readme leaves the tree url empty' ' echo site >root.txt && - CGIT_CONFIG="$PWD/aboutargsrc" QUERY_STRING="p=about" cgit >tmp && + cgit_rc aboutargsrc "p=about" >tmp && grep "root.txt SITE" tmp ' @@ -92,9 +83,9 @@ test_expect_success 'only a repository page hands filters its variables' ' echo "repo url: $CGIT_REPO_URL." EOF sed "s|^about-filter=.*|about-filter=exec:$PWD/env.sh|" aboutargsrc >envrc && - CGIT_CONFIG="$PWD/envrc" QUERY_STRING="url=filtered/about/" cgit >tmp && + cgit_rc envrc "url=filtered/about/" >tmp && grep "repo url: filtered\." tmp && - CGIT_CONFIG="$PWD/envrc" QUERY_STRING="p=about" cgit >tmp && + cgit_rc envrc "p=about" >tmp && grep "repo url: \." tmp ' @@ -113,7 +104,7 @@ test_expect_success CGIT_LUA 'a failing lua filter still renders an error page' echo "repo.path=$PWD/repos/foo/.git" && echo "auth-filter=lua:$PWD/broken.lua" } >brokenrc && - CGIT_CONFIG="$PWD/brokenrc" QUERY_STRING="url=foo/commit" cgit >tmp 2>err && + cgit_rc brokenrc "url=foo/commit" >tmp 2>err && grep "Status: 500" tmp && grep "Lua error in" err ' @@ -126,7 +117,7 @@ test_expect_success CGIT_LUA 'a lua filter raising a table is named by type' ' function filter_close() return 0 end EOF sed "s|broken.lua|tabled.lua|" brokenrc >tabledrc && - CGIT_CONFIG="$PWD/tabledrc" QUERY_STRING="url=foo/commit" cgit >tmp 2>err && + cgit_rc tabledrc "url=foo/commit" >tmp 2>err && grep "Status: 500" tmp && grep "Lua error in .*tabled.lua: (error object is a table value)" err ' @@ -146,7 +137,7 @@ test_expect_success CGIT_LUA 'a lua filter that writes while loading still rende echo "repo.path=$PWD/repos/foo/.git" && echo "repo.commit-filter=lua:$PWD/loud.lua" } >loudrc && - CGIT_CONFIG="$PWD/loudrc" QUERY_STRING="url=foo/commit" cgit >tmp && + cgit_rc loudrc "url=foo/commit" >tmp && grep "written while loading" tmp && grep "" tmp ' @@ -173,7 +164,7 @@ test_expect_success CGIT_LUA 'a lua filter can encode an argument and include a function filter_close() return 0 end EOF sed "s|loud.lua|apis.lua|" loudrc >apisrc && - CGIT_CONFIG="$PWD/apisrc" QUERY_STRING="url=foo/commit" cgit >tmp && + cgit_rc apisrc "url=foo/commit" >tmp && grep "a+b%26c|included bold" tmp ' diff --git a/tests/t0202-submodule-links.sh b/tests/t0202-submodule-links.sh index 2cbbba7..a5810a0 100755 --- a/tests/t0202-submodule-links.sh +++ b/tests/t0202-submodule-links.sh @@ -55,7 +55,7 @@ test_expect_success 'set up a parent repo with submodules' ' ' test_expect_success 'generate subparent/tree' ' - CGIT_CONFIG="$PWD/subrc" QUERY_STRING="url=subparent/tree/" cgit >tmp + cgit_rc subrc "url=subparent/tree/" >tmp ' test_expect_success 'an ssh url served here links to the local repo' ' @@ -93,7 +93,7 @@ test_expect_success 'an unresolvable url stays unlinked with a tooltip' ' test_expect_success 'the links stay off without the flag' ' sed "/enable-gitmodules-links/d" subrc >subrcoff && - CGIT_CONFIG="$PWD/subrcoff" QUERY_STRING="url=subparent/tree/" cgit >tmp && + cgit_rc subrcoff "url=subparent/tree/" >tmp && ! grep "subtarget/tree" tmp && grep "class=.ls-mod.>local-ssh" tmp ' diff --git a/tests/t0203-dates.sh b/tests/t0203-dates.sh index 60a4e5a..5c3567f 100755 --- a/tests/t0203-dates.sh +++ b/tests/t0203-dates.sh @@ -34,66 +34,64 @@ daterc() { } >daterc } -dateq() { CGIT_CONFIG="$PWD/daterc" QUERY_STRING="$1" cgit; } - test_expect_success 'relative dates are on by default' ' daterc && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && grep "class=.age-" tmp ' test_expect_success 'enable-relative-dates=0 shows a calendar date' ' daterc "enable-relative-dates=0" && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && ! grep "class=.age-" tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' test_expect_success 'the index and log columns follow the same flag' ' daterc "enable-relative-dates=0" && - dateq "" >tmp && + cgit_rc daterc "" >tmp && ! grep "class=.age-" tmp && - dateq "url=dated/log/" >tmp && + cgit_rc daterc "url=dated/log/" >tmp && ! grep "class=.age-" tmp ' test_expect_success 'date-format selects the calendar format' ' daterc "enable-relative-dates=0" "date-format=iso8601" && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && grep ">[0-9-]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] +0000<" tmp ' test_expect_success 'date-format accepts a strftime format' ' daterc "enable-relative-dates=0" "date-format=format:%Y/%m/%d" && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && grep ">[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]<" tmp ' test_expect_success 'an unknown date-format falls back to short' ' daterc "enable-relative-dates=0" "date-format=nonsense" && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp && daterc "enable-relative-dates=0" "date-format=format:" && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' test_expect_success 'a date-format git would refuse falls back to short' ' daterc "enable-relative-dates=0" "date-format=local-local" && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && grep "^Status: 200" tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' test_expect_success 'date-format=local is the default format in local time' ' daterc "enable-relative-dates=0" "date-format=local" && - dateq "url=dated/refs/" >tmp && + cgit_rc daterc "url=dated/refs/" >tmp && grep ">[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9:]* [0-9]*<" tmp ' test_expect_success 'date-format still formats the log fallback' ' daterc "date-format=rfc2822" && - dateq "url=dated/log/" >tmp && + cgit_rc daterc "url=dated/log/" >tmp && grep "class=.age-" tmp && grep ">[A-Z][a-z][a-z], [0-9]* Apr 2005 " tmp ' @@ -101,7 +99,7 @@ test_expect_success 'date-format still formats the log fallback' ' test_expect_success 'date-format leaves the commit page on ISO 8601' ' daterc "date-format=rfc2822" && sha=$(git -C repos/dated rev-parse HEAD~1) && - dateq "url=dated/commit/&id=$sha" >tmp && + cgit_rc daterc "url=dated/commit/&id=$sha" >tmp && grep "2005-04-07 [0-9:]* +0000" tmp && ! grep "Apr 2005" tmp ' diff --git a/tests/t0204-limits.sh b/tests/t0204-limits.sh index 1a1d7ad..ecc33bf 100755 --- a/tests/t0204-limits.sh +++ b/tests/t0204-limits.sh @@ -29,26 +29,10 @@ 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 @@ -71,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 ' @@ -82,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 @@ -107,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 && @@ -122,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 ' @@ -132,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 ' @@ -141,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 ' @@ -164,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 ' @@ -184,7 +162,7 @@ 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 @@ -202,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 diff --git a/tests/t0205-config.sh b/tests/t0205-config.sh index dbc73e9..f13b2ec 100755 --- a/tests/t0205-config.sh +++ b/tests/t0205-config.sh @@ -6,14 +6,7 @@ test_description='Check configuration diagnostics' . ./setup.sh test_expect_success 'set up configs' ' - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "no-such-key=1" && - echo "repo.url=diag" && - echo "repo.path=$PWD/repos/foo/.git" && - echo "repo.no-such-repo-key=1" - } >diagrc && + cgitrc_repo diagrc diag no-such-key=1 "repo.path=$PWD/repos/foo/.git" repo.no-such-repo-key=1 && { echo "virtual-root=/" && echo "cache-size=0" && @@ -26,14 +19,14 @@ test_expect_success 'set up configs' ' ' test_expect_success 'unknown keys are reported and the page still renders' ' - CGIT_CONFIG="$PWD/diagrc" QUERY_STRING="url=diag/" cgit >tmp 2>err && + cgit_rc diagrc "url=diag/" >tmp 2>err && grep "Status: 200" tmp && grep "Unknown config key: no-such-key" err && grep "Unknown repo config key: no-such-repo-key" err ' test_expect_success 'a repo key before any repo.url is reported' ' - CGIT_CONFIG="$PWD/earlyrc" QUERY_STRING="url=diag/" cgit >tmp 2>err && + cgit_rc earlyrc "url=diag/" >tmp 2>err && grep "Status: 200" tmp && grep "Ignoring repo.desc before any repo.url" err ' @@ -46,7 +39,7 @@ test_expect_success 'a filter in a scanned repository is reported without its fl echo "cache-size=0" && echo "scan-path=$PWD/scan" } >scanrc && - CGIT_CONFIG="$PWD/scanrc" QUERY_STRING="url=foo.git/commit/" cgit >tmp 2>err && + cgit_rc scanrc "url=foo.git/commit/" >tmp 2>err && grep "
commit 5" tmp && grep "Ignoring commit-filter in $PWD/scan/foo.git/: trust-scan-config is not set" err ' @@ -56,7 +49,7 @@ test_expect_success 'the flag lets a scanned repository set its filters' ' echo "trust-scan-config=1" && cat scanrc } >scanrc-on && - CGIT_CONFIG="$PWD/scanrc-on" QUERY_STRING="url=foo.git/commit/" cgit >tmp 2>err && + cgit_rc scanrc-on "url=foo.git/commit/" >tmp 2>err && grep "
COMMIT 5" tmp && ! grep "Ignoring" err ' @@ -64,7 +57,7 @@ test_expect_success 'the flag lets a scanned repository set its filters' ' # The filter prints nothing, so an empty about div shows that it ran in place # of the readme. test_expect_success 'a repo filter in the main cgitrc needs no flag' ' - CGIT_CONFIG="$PWD/earlyrc" QUERY_STRING="url=diag/about/" cgit >tmp 2>err && + cgit_rc earlyrc "url=diag/about/" >tmp 2>err && grep "
" tmp && ! grep "about-filter" err ' @@ -80,7 +73,7 @@ test_expect_success 'a repository whose path is missing answers 404' ' mkdir -p gone-cache && for page in "" log/ commit/ "tag/&h=x" atom/ plain/f do - CGIT_CONFIG="$PWD/gonerc" QUERY_STRING="url=gone/$page" cgit >tmp 2>err && + cgit_rc gonerc "url=gone/$page" >tmp 2>err && grep "^Status: 404 Not Found" tmp && grep "Failed to open gone: No such file or directory" tmp || return 1 done && @@ -104,7 +97,7 @@ test_expect_success 'a NUL inside a comment does not end it' ' echo "repo.path=$PWD/repos/foo/.git" } >nulrc && grep -c Smuggled nulrc && - CGIT_CONFIG="$PWD/nulrc" QUERY_STRING="url=" cgit >tmp && + cgit_rc nulrc "url=" >tmp && grep "" tmp && ! grep Smuggled tmp ' diff --git a/tests/t0206-trailers.sh b/tests/t0206-trailers.sh index 61fba94..15c3600 100755 --- a/tests/t0206-trailers.sh +++ b/tests/t0206-trailers.sh @@ -87,7 +87,7 @@ test_expect_success 'a message with no block gets no table' ' test_expect_success 'with the flag off the message stays whole' ' sed "s/^enable-commit-trailers=1/enable-commit-trailers=0/" cgitrc >cgitrc-off && - CGIT_CONFIG="$PWD/cgitrc-off" QUERY_STRING="url=trailers/commit/" cgit >tmp && + cgit_rc cgitrc-off "url=trailers/commit/" >tmp && ! grep "commit-trailers" tmp && grep "Signed-off-by: A U Thor" tmp ' diff --git a/tests/t0208-mailmap.sh b/tests/t0208-mailmap.sh index 86f6d50..ec33cd9 100755 --- a/tests/t0208-mailmap.sh +++ b/tests/t0208-mailmap.sh @@ -73,7 +73,7 @@ test_expect_success 'with the flag off the old ident shows' ' echo "enable-mailmap=0" && cat cgitrc } >cgitrc-off && - CGIT_CONFIG="$PWD/cgitrc-off" QUERY_STRING="url=mapped/log/" cgit >tmp && + cgit_rc cgitrc-off "url=mapped/log/" >tmp && grep "Old Name" tmp ' diff --git a/tests/t0301-security.sh b/tests/t0301-security.sh index 453d521..3fc491f 100755 --- a/tests/t0301-security.sh +++ b/tests/t0301-security.sh @@ -23,18 +23,9 @@ test_expect_success 'set up security fixtures' ' git add -A && git commit -m fixtures ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "max-blob-size=1" && - echo "enable-tree-group-dirs=1" && - echo "repo.url=sec" && - echo "repo.path=$PWD/repos/sec/.git" - } >seccgitrc + cgitrc_repo seccgitrc sec max-blob-size=1 enable-tree-group-dirs=1 ' -secq() { CGIT_CONFIG="$PWD/seccgitrc" QUERY_STRING="$1" cgit; } - # A revision beginning with a dash reaches git as an option rather than as a # tip, so a request for id=--output= could create or truncate any file # the server is able to write. @@ -54,7 +45,7 @@ test_expect_success 'a valid id= still renders the log' ' ' test_expect_success 'a small blob is still served' ' - secq "url=sec/plain/afile" >tmp && + cgit_rc seccgitrc "url=sec/plain/afile" >tmp && grep -F top tmp ' @@ -72,14 +63,14 @@ test_expect_success 'markdown readme without a filter is escaped as plain text' echo "repo.path=$PWD/repos/sec/.git" && echo "repo.readme=master:readme.txt" } >secreadmerc && - CGIT_CONFIG="$PWD/secreadmerc" QUERY_STRING="url=md/about/" cgit >tmp && + cgit_rc secreadmerc "url=md/about/" >tmp && grep "pre class=.plaintext." tmp && grep "<script>" tmp && ! grep "" tmp ' test_expect_success 'non-markdown readme without a filter is escaped as plain text' ' - CGIT_CONFIG="$PWD/secreadmerc" QUERY_STRING="url=txt/about/" cgit >tmp && + cgit_rc secreadmerc "url=txt/about/" >tmp && grep "pre class=.plaintext." tmp && grep "<script>" tmp && ! grep "" tmp @@ -94,10 +85,10 @@ test_expect_success 'root-readme without a filter is its own page, as written' ' echo "cache-size=0" && echo "root-readme=$PWD/root.html" } >secrootrc && - CGIT_CONFIG="$PWD/secrootrc" QUERY_STRING="url=" cgit >tmp && + cgit_rc secrootrc "url=" >tmp && grep "
  • about" tmp && ! grep "site" tmp && - CGIT_CONFIG="$PWD/secrootrc" QUERY_STRING="p=about" cgit >tmp && + cgit_rc secrootrc "p=about" >tmp && grep "^site$" tmp ' @@ -114,7 +105,7 @@ test_expect_success 'diff options submit through a button' ' # Grouping directories ahead of files is behaviour this fork adds, so nothing # upstream covers it. test_expect_success 'tree groups directories before files' ' - secq "url=sec/tree/" >tmp && + cgit_rc seccgitrc "url=sec/tree/" >tmp && dirline=$(grep -n "tree/zsub" tmp | head -1 | cut -d: -f1) && fileline=$(grep -n "tree/afile" tmp | head -1 | cut -d: -f1) && test -n "$dirline" && @@ -136,14 +127,9 @@ test_expect_success 'ssdiff percent-encodes a quoted file path' ' printf "a\nc\n" >"$name" && git commit -am change ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=xss" && - echo "repo.path=$PWD/repos/xss/.git" - } >xssrc && + cgitrc_repo xssrc xss && sha=$(git -C repos/xss rev-parse HEAD) && - CGIT_CONFIG="$PWD/xssrc" QUERY_STRING="url=xss/diff/&id=$sha&ss=1" cgit >tmp && + cgit_rc xssrc "url=xss/diff/&id=$sha&ss=1" >tmp && grep "tree/x%27y.txt" tmp && ! grep "href=.[^>]*x.y.txt.[^>]*>" tmp ' @@ -159,15 +145,10 @@ test_expect_success 'a message-less commit renders without crashing' ' cid=$(git hash-object -t commit -w raw) && git update-ref refs/heads/master "$cid" ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=nomsg" && - echo "repo.path=$PWD/repos/nomsg/.git" - } >nomsgrc && - CGIT_CONFIG="$PWD/nomsgrc" QUERY_STRING="url=nomsg/log/&showmsg=1" cgit >tmp && + cgitrc_repo nomsgrc nomsg && + cgit_rc nomsgrc "url=nomsg/log/&showmsg=1" >tmp && grep "no commit message" tmp && - CGIT_CONFIG="$PWD/nomsgrc" QUERY_STRING="url=nomsg/" cgit >tmp && + cgit_rc nomsgrc "url=nomsg/" >tmp && grep "no commit message" tmp ' @@ -188,19 +169,13 @@ test_expect_success 'set up a repo whose branches point at odd objects' ' grep -q "tree.refs/heads/points-at-tree" refs.out && grep -q "tag.refs/heads/points-at-tag" refs.out ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "branch-sort=age" && - echo "repo.url=oddref" && - echo "repo.path=$PWD/repos/oddref/.git" - } >oddrefrc + cgitrc_repo oddrefrc oddref branch-sort=age ' test_expect_success 'the refs, branch and summary pages sort such branches' ' for page in refs/ refs/heads/ "" do - CGIT_CONFIG="$PWD/oddrefrc" QUERY_STRING="url=oddref/$page" cgit >tmp && + cgit_rc oddrefrc "url=oddref/$page" >tmp && grep "points-at-tree" tmp && grep "" tmp || return 1 done @@ -208,7 +183,7 @@ test_expect_success 'the refs, branch and summary pages sort such branches' ' test_expect_success 'name-sorted branches are unaffected' ' sed "s/^branch-sort=age$/branch-sort=name/" oddrefrc >oddrefnamerc && - CGIT_CONFIG="$PWD/oddrefnamerc" QUERY_STRING="url=oddref/refs/heads/" cgit >tmp && + cgit_rc oddrefnamerc "url=oddref/refs/heads/" >tmp && grep "points-at-tree" tmp && grep "" tmp ' @@ -239,7 +214,7 @@ test_expect_success 'set up a submodule fixture with a hostile module-link' ' ' test_expect_success 'a surplus conversion does not crash the tree view' ' - CGIT_CONFIG="$PWD/modlinkrc" QUERY_STRING="url=modlink/tree/" cgit >tmp && + cgit_rc modlinkrc "url=modlink/tree/" >tmp && grep "ls-mod" tmp ' @@ -248,38 +223,20 @@ test_expect_success 'a surplus conversion is shown literally, not filled' ' ' test_expect_success 'a well-formed module-link still takes name and sha1' ' - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "module-link=/mod/%s/commit/?id=%s" && - echo "repo.url=modlink" && - echo "repo.path=$PWD/repos/modlink/.git" - } >modlinkokrc && - CGIT_CONFIG="$PWD/modlinkokrc" QUERY_STRING="url=modlink/tree/" cgit >tmp && + cgitrc_repo modlinkokrc modlink "module-link=/mod/%s/commit/?id=%s" && + cgit_rc modlinkokrc "url=modlink/tree/" >tmp && grep "href=./mod/submod/commit/?id=$sub." tmp ' test_expect_success 'a per-path module-link takes only the sha1' ' - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=modlink" && - echo "repo.path=$PWD/repos/modlink/.git" && - echo "repo.module-link.submod=https://example.com/s/?id=%s" - } >modlinkpathrc && - CGIT_CONFIG="$PWD/modlinkpathrc" QUERY_STRING="url=modlink/tree/" cgit >tmp && + cgitrc_repo modlinkpathrc modlink "repo.module-link.submod=https://example.com/s/?id=%s" && + cgit_rc modlinkpathrc "url=modlink/tree/" >tmp && grep "href=.https://example.com/s/?id=$sub." tmp ' test_expect_success 'a doubled percent in a module-link renders as one' ' - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "module-link=/m/%s/%%/%s" && - echo "repo.url=modlink" && - echo "repo.path=$PWD/repos/modlink/.git" - } >modlinkpctrc && - CGIT_CONFIG="$PWD/modlinkpctrc" QUERY_STRING="url=modlink/tree/" cgit >tmp && + cgitrc_repo modlinkpctrc modlink "module-link=/m/%s/%%/%s" && + cgit_rc modlinkpctrc "url=modlink/tree/" >tmp && grep "href=./m/submod/%/$sub." tmp ' @@ -297,7 +254,7 @@ test_expect_success 'a clone endpoint with http clone off answers the same way' echo "enable-http-clone=0" && cat cgitrc } >noclonerc && - CGIT_CONFIG="$PWD/noclonerc" QUERY_STRING="url=foo/info/refs" cgit >tmp && + cgit_rc noclonerc "url=foo/info/refs" >tmp && grep "^Status: 404 Not Found" tmp && grep "