Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
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.
Diffstat (limited to 'tests/t0303-robustness.sh')
-rwxr-xr-xtests/t0303-robustness.sh219
1 file changed, 90 insertions, 129 deletions
diff --git a/tests/t0303-robustness.sh b/tests/t0303-robustness.sh
index 5348b43..f1ae9cd 100755
--- a/tests/t0303-robustness.sh
+++ b/tests/t0303-robustness.sh
@@ -10,17 +10,9 @@ test_description='Check the audit regressions'
test_expect_success 'set up a repository and a config to vary' '
mkrepo repos/rob 3 &&
sha=$(git -C repos/rob rev-parse HEAD~1) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "snapshots=tar.gz" &&
- echo "repo.url=rob" &&
- echo "repo.path=$PWD/repos/rob/.git"
- } >robrc
+ cgitrc_repo robrc rob snapshots=tar.gz
'
-robq() { CGIT_CONFIG="$PWD/robrc" QUERY_STRING="$1" cgit; }
-
test_expect_success 'a repository without a path answers 404' '
{
echo "virtual-root=/" &&
@@ -31,7 +23,7 @@ test_expect_success 'a repository without a path answers 404' '
} >nopathrc &&
for r in nopath emptypath
do
- CGIT_CONFIG="$PWD/nopathrc" QUERY_STRING="url=$r/log/" cgit >tmp &&
+ cgit_rc nopathrc "url=$r/log/" >tmp &&
grep "^Status: 404 Not Found" tmp &&
grep "Failed to open $r: Not a valid git repository" tmp || return 1
done
@@ -42,7 +34,7 @@ test_expect_success 'a repository without a path answers 404' '
test_expect_success 'a repository without a path has no age on the index' '
mkdir -p "(null)/refs/heads" &&
>"(null)/refs/heads/master" &&
- CGIT_CONFIG="$PWD/nopathrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc nopathrc "url=" >tmp &&
grep "</html>" tmp &&
! grep "<time " tmp
'
@@ -57,12 +49,12 @@ test_expect_success 'a repository with an empty url is skipped with a warning' '
echo "repo.url=rob" &&
echo "repo.path=$PWD/repos/rob/.git"
} >nourlrc &&
- CGIT_CONFIG="$PWD/nourlrc" QUERY_STRING="url=rob/" cgit >tmp 2>err &&
+ cgit_rc nourlrc "url=rob/" >tmp 2>err &&
grep "^Status: 200" tmp &&
grep "Ignoring repository with an empty url" err &&
- CGIT_CONFIG="$PWD/nourlrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc nourlrc "url=" >tmp &&
! grep nourl tmp &&
- CGIT_CONFIG="$PWD/nourlrc" QUERY_STRING="r=" cgit >tmp &&
+ cgit_rc nourlrc "r=" >tmp &&
! grep nourl tmp
'
@@ -73,7 +65,7 @@ test_expect_success 'a scan path that is itself a repository is named after it'
echo "remove-suffix=1" &&
echo "scan-path=$PWD/repos/rob"
} >rootrc &&
- CGIT_CONFIG="$PWD/rootrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc rootrc "url=" >tmp &&
grep "toplevel-repo.><a href=./rob/.>rob</a>" tmp
'
@@ -86,7 +78,7 @@ test_expect_success 'a repo key after scan-path is reported instead of applied'
echo "scan-path=$PWD/repos" &&
echo "repo.desc=misplaced"
} >stalerc &&
- CGIT_CONFIG="$PWD/stalerc" QUERY_STRING="url=" cgit >tmp 2>err &&
+ cgit_rc stalerc "url=" >tmp 2>err &&
! grep "misplaced" tmp &&
grep "Ignoring repo.desc before any repo.url" err
'
@@ -100,7 +92,7 @@ test_expect_success 'a valueless or broken git config in a scanned repository is
echo "enable-git-config=1" &&
echo "scan-path=$PWD/scan"
} >gitcfgrc &&
- CGIT_CONFIG="$PWD/gitcfgrc" QUERY_STRING="url=" cgit >tmp 2>err &&
+ cgit_rc gitcfgrc "url=" >tmp 2>err &&
grep "toplevel-repo.><a href=./a.git/.>" tmp &&
grep "Ignoring unreadable config in $PWD/scan/a.git/config" err
'
@@ -113,7 +105,7 @@ test_expect_success 'only descriptive keys are taken from a scanned repository'
echo "head-content=<script>alert(1)</script>" &&
echo "logo-link=javascript:alert(2)"
} >scan/b.git/cgitrc &&
- CGIT_CONFIG="$PWD/gitcfgrc" QUERY_STRING="url=b.git/about/" cgit >tmp 2>err &&
+ cgit_rc gitcfgrc "url=b.git/about/" >tmp 2>err &&
grep "from the repo" tmp &&
grep "pre class=.plaintext." tmp &&
! grep "alert(" tmp &&
@@ -123,7 +115,7 @@ test_expect_success 'only descriptive keys are taken from a scanned repository'
test_expect_success 'a filesystem readme from a scanned repository is refused' '
echo "readme=/etc/hosts" >scan/b.git/cgitrc &&
- CGIT_CONFIG="$PWD/gitcfgrc" QUERY_STRING="url=b.git/about/" cgit >tmp 2>err &&
+ cgit_rc gitcfgrc "url=b.git/about/" >tmp 2>err &&
grep "Ignoring readme in " err
'
@@ -132,7 +124,7 @@ test_expect_success 'a filesystem readme from a scanned repository is refused' '
test_expect_success 'a readme ending in a colon is refused like a path on disk' '
echo "outside the repository" >"scan/outside:" &&
echo "readme=../outside:" >scan/b.git/cgitrc &&
- CGIT_CONFIG="$PWD/gitcfgrc" QUERY_STRING="url=b.git/about/" cgit >tmp 2>err &&
+ cgit_rc gitcfgrc "url=b.git/about/" >tmp 2>err &&
grep "Ignoring readme in " err &&
! grep "outside the repository" tmp
'
@@ -143,7 +135,7 @@ test_expect_success 'a readme set after scan-path reaches a scanned repository'
rm scan/b.git/cgitrc &&
cat gitcfgrc >laterrc &&
echo "readme=master:file-1" >>laterrc &&
- CGIT_CONFIG="$PWD/laterrc" QUERY_STRING="url=b.git/about/" cgit >tmp &&
+ cgit_rc laterrc "url=b.git/about/" >tmp &&
grep "<pre class=.plaintext.>1$" tmp
'
@@ -167,7 +159,7 @@ test_expect_success 'html serving from a scanned repository waits on trust' '
echo "mimetype.html=text/html" &&
echo "scan-path=$PWD/scan2"
} >htmlrc &&
- CGIT_CONFIG="$PWD/htmlrc" QUERY_STRING="url=c.git/plain/page.html" cgit >tmp 2>err &&
+ cgit_rc htmlrc "url=c.git/plain/page.html" >tmp 2>err &&
grep "^Content-Type: text/plain" tmp &&
grep "^X-Content-Type-Options: nosniff" tmp &&
grep "Ignoring enable-html-serving in $PWD/scan2/c.git/: trust-scan-config is not set" err
@@ -178,19 +170,19 @@ test_expect_success 'with trust-scan-config the same repository serves html' '
echo "trust-scan-config=1" &&
cat htmlrc
} >htmltrustrc &&
- CGIT_CONFIG="$PWD/htmltrustrc" QUERY_STRING="url=c.git/plain/page.html" cgit >tmp &&
+ cgit_rc htmltrustrc "url=c.git/plain/page.html" >tmp &&
grep "^Content-Type: text/html" tmp &&
! grep "^X-Content-Type-Options" tmp
'
test_expect_success SYMLINKS 'a symlink cycle under the scan path is entered once' '
ln -s . scan/loop &&
- CGIT_CONFIG="$PWD/gitcfgrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc gitcfgrc "url=" >tmp &&
test $(grep -c "toplevel-repo" tmp) = 2
'
test_expect_success 'a bare query parameter does not swallow the next one' '
- robq "url=rob/commit/&x&id=$sha" >tmp &&
+ cgit_rc robrc "url=rob/commit/&x&id=$sha" >tmp &&
grep "<div class=.commit-subject.>commit 2" tmp
'
@@ -199,7 +191,7 @@ test_expect_success 'a filter that cannot run answers one error page' '
echo "commit-filter=exec:$PWD/no/such/filter" &&
cat robrc
} >badfilterrc &&
- CGIT_CONFIG="$PWD/badfilterrc" QUERY_STRING="url=rob/commit/" cgit >tmp 2>err &&
+ cgit_rc badfilterrc "url=rob/commit/" >tmp 2>err &&
test $(grep -c "^Status:" tmp) = 1 &&
grep "Unable to complete the request" tmp &&
grep "Unable to run filter $PWD/no/such/filter" err &&
@@ -211,7 +203,7 @@ test_expect_success 'a filter that exits without reading does not end cgit' '
echo "email-filter=exec:true" &&
cat robrc
} >truerc &&
- CGIT_CONFIG="$PWD/truerc" QUERY_STRING="url=rob/log/" cgit >tmp &&
+ cgit_rc truerc "url=rob/log/" >tmp &&
grep "^Status: 200" tmp &&
grep "</html>" tmp
'
@@ -223,7 +215,7 @@ test_expect_success 'a commit encoding header is read without its newline' '
git add file-1 &&
git -c i18n.commitEncoding=ISO-8859-1 commit -m "$(printf "caf\351")"
) &&
- robq "url=rob/commit/" >tmp &&
+ cgit_rc robrc "url=rob/commit/" >tmp &&
grep "<div class=.commit-subject.>caf$(printf "\303\251")<" tmp
'
@@ -242,43 +234,43 @@ test_expect_success 'a path below the about page answers 404' '
} >aboutrc &&
for path in sub sub/ missing.png file-1 ../robrc
do
- CGIT_CONFIG="$PWD/aboutrc" QUERY_STRING="url=rob/about/$path" cgit >tmp 2>err &&
+ cgit_rc aboutrc "url=rob/about/$path" >tmp 2>err &&
grep "^Status: 404" tmp &&
grep "^Content-Type: text/html" tmp &&
! grep fatal err || return 1
done &&
- CGIT_CONFIG="$PWD/aboutrc" QUERY_STRING="p=about&path=x" cgit >tmp &&
+ cgit_rc aboutrc "p=about&path=x" >tmp &&
grep "^Status: 404" tmp
'
test_expect_success 'a snapshot name holding a slash is refused' '
- robq "url=rob/snapshot/:/../../...tar.gz" >tmp &&
+ cgit_rc robrc "url=rob/snapshot/:/../../...tar.gz" >tmp &&
grep "^Status: 404" tmp &&
- robq "url=rob/snapshot/rob-master.tar.gz" >tmp &&
+ cgit_rc robrc "url=rob/snapshot/rob-master.tar.gz" >tmp &&
grep "^Status: 200" tmp
'
test_expect_success 'a path opening with a colon is refused on the log and patch pages' '
- robq "url=rob/log/:%25x" >tmp &&
+ cgit_rc robrc "url=rob/log/:%25x" >tmp &&
grep "^Status: 400" tmp &&
- robq "url=rob/patch/:%25x" >tmp &&
+ cgit_rc robrc "url=rob/patch/:%25x" >tmp &&
grep "^Status: 400" tmp &&
test $(grep -c "^Status:" tmp) = 1
'
test_expect_success 'a revision spelled like an option is refused' '
git -C repos/rob update-ref refs/heads/--stdin HEAD &&
- robq "url=rob/log/&h=--stdin" >tmp &&
+ cgit_rc robrc "url=rob/log/&h=--stdin" >tmp &&
grep "^Status: 404" tmp &&
- robq "url=rob/blame/file-1&id=--stdin" >tmp &&
+ cgit_rc robrc "url=rob/blame/file-1&id=--stdin" >tmp &&
grep "^Status: 400" tmp &&
- robq "url=rob/atom/&h=--stdin" >tmp &&
+ cgit_rc robrc "url=rob/atom/&h=--stdin" >tmp &&
grep "^Status: 404" tmp
'
test_expect_success 'the blob page reads a file through an annotated tag' '
git -C repos/rob -c tag.gpgsign=false tag -a -m note ann HEAD &&
- robq "url=rob/blob/&h=ann&path=file-1" >tmp &&
+ cgit_rc robrc "url=rob/blob/&h=ann&path=file-1" >tmp &&
strip_headers <tmp >body &&
printf "more\n" >want &&
test_cmp want body
@@ -288,14 +280,14 @@ test_expect_success 'the blob page reads a file through an annotated tag' '
# blob page used to answer such a request with the raw commit object.
test_expect_success 'the blob page walks a path out of the commit or tag the id names' '
tip=$(git -C repos/rob rev-parse HEAD) &&
- robq "url=rob/blob/file-1&id=$tip" >tmp &&
+ cgit_rc robrc "url=rob/blob/file-1&id=$tip" >tmp &&
strip_headers <tmp >body &&
test_cmp want body &&
tag=$(git -C repos/rob rev-parse ann) &&
- robq "url=rob/blob/file-1&id=$tag" >tmp &&
+ cgit_rc robrc "url=rob/blob/file-1&id=$tag" >tmp &&
strip_headers <tmp >body &&
test_cmp want body &&
- robq "url=rob/blob/missing&id=$tip" >tmp &&
+ cgit_rc robrc "url=rob/blob/missing&id=$tip" >tmp &&
grep "^Status: 404" tmp
'
@@ -319,21 +311,21 @@ test_expect_success 'the commit page shows a message whole when text follows its
echo "enable-commit-trailers=1" &&
cat robrc
} >trailrc &&
- CGIT_CONFIG="$PWD/trailrc" QUERY_STRING="url=rob/commit/" cgit >tmp &&
+ cgit_rc trailrc "url=rob/commit/" >tmp &&
! grep "commit-trailers" tmp &&
grep "Conflicts:" tmp
'
test_expect_success 'a revision expression that walks the history is refused' '
- robq "url=rob/log/&h=:/zzzz" >tmp &&
+ cgit_rc robrc "url=rob/log/&h=:/zzzz" >tmp &&
grep "^Status: 404" tmp &&
- robq "url=rob/commit/&id=HEAD^{/zzzz}" >tmp &&
+ cgit_rc robrc "url=rob/commit/&id=HEAD^{/zzzz}" >tmp &&
grep "^Status: 400" tmp &&
- robq "url=rob/log/&qt=range&q=:/zzzz" >tmp &&
+ cgit_rc robrc "url=rob/log/&qt=range&q=:/zzzz" >tmp &&
grep "^Status: 400" tmp &&
- robq "url=rob/log/&qt=range&q=master~1..master" >tmp &&
+ cgit_rc robrc "url=rob/log/&qt=range&q=master~1..master" >tmp &&
grep "^Status: 400" tmp &&
- robq "url=rob/log/&qt=range&q=$sha..master" >tmp &&
+ cgit_rc robrc "url=rob/log/&qt=range&q=$sha..master" >tmp &&
grep "^Status: 200" tmp
'
@@ -345,20 +337,14 @@ test_expect_success 'a commit with a broken tree line does not crash the blob pa
git hash-object -t commit -w --stdin --literally) &&
echo $bad >.git/refs/heads/bad
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=broken" &&
- echo "repo.path=$PWD/broken/.git" &&
- echo "repo.readme=:file-1"
- } >brokenrc &&
- CGIT_CONFIG="$PWD/brokenrc" QUERY_STRING="url=broken/blob/&h=bad&path=file-1" cgit >tmp &&
+ cgitrc_repo brokenrc broken "repo.path=$PWD/broken/.git" repo.readme=:file-1 &&
+ cgit_rc brokenrc "url=broken/blob/&h=bad&path=file-1" >tmp &&
grep "^Status: 404" tmp
'
test_expect_success 'a die inside git answers one 500 page and logs the reason' '
printf "[core\n" >>broken/.git/config &&
- CGIT_CONFIG="$PWD/brokenrc" QUERY_STRING="url=broken/log/" cgit >tmp 2>err &&
+ cgit_rc brokenrc "url=broken/log/" >tmp 2>err &&
grep "^Status: 500" tmp &&
test $(grep -c "^Status:" tmp) = 1 &&
grep "bad config line" err &&
@@ -370,17 +356,12 @@ test_expect_success 'a history with a missing parent renders up to the gap' '
older=$(git -C gap rev-parse HEAD~3) &&
parent=$(git -C gap rev-parse HEAD~2) &&
rm gap/.git/objects/$(echo $parent | cut -c1-2)/$(echo $parent | cut -c3-) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=gap" &&
- echo "repo.path=$PWD/gap/.git"
- } >gaprc &&
- CGIT_CONFIG="$PWD/gaprc" QUERY_STRING="url=gap/log/" cgit >tmp 2>err &&
+ cgitrc_repo gaprc gap "repo.path=$PWD/gap/.git" &&
+ cgit_rc gaprc "url=gap/log/" >tmp 2>err &&
test $(grep -c "^Status:" tmp) = 1 &&
grep "Unable to complete the request" tmp &&
grep "Failed to traverse parents" err &&
- CGIT_CONFIG="$PWD/gaprc" QUERY_STRING="url=gap/patch/&id2=$older" cgit >tmp &&
+ cgit_rc gaprc "url=gap/patch/&id2=$older" >tmp &&
test $(grep -c "^Status:" tmp) = 1 &&
grep "^Status: 500" tmp
'
@@ -403,13 +384,8 @@ test_expect_success 'a corrupt blob in a collected diff answers the error' '
test_copy_bytes $((size / 2)) <$obj >half &&
mv half $obj
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=corrupt" &&
- echo "repo.path=$PWD/corrupt/.git"
- } >corruptrc &&
- CGIT_CONFIG="$PWD/corruptrc" QUERY_STRING="url=corrupt/commit/" cgit >tmp 2>err &&
+ cgitrc_repo corruptrc corrupt "repo.path=$PWD/corrupt/.git" &&
+ cgit_rc corruptrc "url=corrupt/commit/" >tmp 2>err &&
grep "is corrupt" err &&
grep "Unable to complete the request" tmp
'
@@ -427,7 +403,7 @@ test_expect_success 'a filter pipeline sees the default SIGPIPE disposition' '
echo "source-filter=exec:$PWD/pipe.sh" &&
cat robrc
} >piperc &&
- CGIT_CONFIG="$PWD/piperc" QUERY_STRING="url=rob/tree/file-1" cgit >tmp 2>err &&
+ cgit_rc piperc "url=rob/tree/file-1" >tmp 2>err &&
grep "^Status: 200" tmp &&
! grep -i "broken pipe" err
'
@@ -435,7 +411,7 @@ test_expect_success 'a filter pipeline sees the default SIGPIPE disposition' '
test_expect_success 'the fallback branch skips a name spelled like an option' '
git -C repos/rob update-ref refs/heads/-first HEAD &&
git -C repos/rob symbolic-ref HEAD refs/heads/gone &&
- robq "url=rob/" >tmp &&
+ cgit_rc robrc "url=rob/" >tmp &&
git -C repos/rob symbolic-ref HEAD refs/heads/master &&
grep "^Status: 200" tmp
'
@@ -459,13 +435,13 @@ test_expect_success 'a blank line in the mimetype file is skipped' '
echo "mimetype-file=$PWD/mime.types" &&
cat robrc
} >mimerc &&
- CGIT_CONFIG="$PWD/mimerc" QUERY_STRING="url=rob/plain/note.cgt" cgit >tmp &&
+ cgit_rc mimerc "url=rob/plain/note.cgt" >tmp &&
grep "^Content-Type: image/x-cgit" tmp
'
test_expect_success 'an indented comment in the mimetype file is skipped' '
printf " # cgt used to be image/x-old\nimage/x-cgit cgt\n" >mime.types &&
- CGIT_CONFIG="$PWD/mimerc" QUERY_STRING="url=rob/plain/note.cgt" cgit >tmp &&
+ cgit_rc mimerc "url=rob/plain/note.cgt" >tmp &&
grep "^Content-Type: image/x-cgit" tmp
'
@@ -479,9 +455,9 @@ test_expect_success 'a refs page named with an id is not cached for ever' '
grep -v "^cache-size" robrc
} >ttlrc &&
full=$(git -C repos/rob rev-parse HEAD) &&
- CGIT_CONFIG="$PWD/ttlrc" QUERY_STRING="url=rob/refs/&id=$full" cgit >tmp &&
+ cgit_rc ttlrc "url=rob/refs/&id=$full" >tmp &&
git -C repos/rob tag later HEAD &&
- CGIT_CONFIG="$PWD/ttlrc" QUERY_STRING="url=rob/refs/&id=$full" cgit >tmp &&
+ cgit_rc ttlrc "url=rob/refs/&id=$full" >tmp &&
grep ">later<" tmp
'
@@ -500,15 +476,15 @@ test_expect_success 'the diff caps hold when the path names a directory' '
echo "max-diff-files=2" &&
cat robrc
} >caprc &&
- CGIT_CONFIG="$PWD/caprc" QUERY_STRING="url=rob/diff/dir" cgit >tmp &&
+ cgit_rc caprc "url=rob/diff/dir" >tmp &&
grep "too large to be rendered inline" tmp &&
- CGIT_CONFIG="$PWD/caprc" QUERY_STRING="url=rob/diff/dir/f1" cgit >tmp &&
+ cgit_rc caprc "url=rob/diff/dir/f1" >tmp &&
! grep "too large to be rendered inline" tmp
'
test_expect_success 'a snapshot of a tag spelled like an option is archived' '
git -C repos/rob update-ref refs/tags/-l HEAD &&
- robq "url=rob/snapshot/-l.tar.gz" >tmp &&
+ cgit_rc robrc "url=rob/snapshot/-l.tar.gz" >tmp &&
grep "^Status: 200" tmp &&
strip_headers <tmp | gzip -dc | tar -tf - >list &&
grep "file-1" list
@@ -535,9 +511,9 @@ test_expect_success 'a disk readme in the repository directory serves no sibling
cat robrc &&
echo "repo.readme=README"
} >diskrc &&
- CGIT_CONFIG="$PWD/diskrc" QUERY_STRING="url=rob/about/" cgit >tmp &&
+ cgit_rc diskrc "url=rob/about/" >tmp &&
grep "hello" tmp &&
- CGIT_CONFIG="$PWD/diskrc" QUERY_STRING="url=rob/about/config" cgit >tmp &&
+ cgit_rc diskrc "url=rob/about/config" >tmp &&
grep "^Status: 404" tmp &&
! grep "repositoryformatversion" tmp
'
@@ -545,23 +521,18 @@ test_expect_success 'a disk readme in the repository directory serves no sibling
test_expect_success 'a tag pointing at a tag links the inner tag by id' '
git -C repos/rob -c tag.gpgsign=false tag -a -m outer outer ann &&
inner=$(git -C repos/rob rev-parse ann) &&
- robq "url=rob/tag/&id=$inner" >tmp &&
+ cgit_rc robrc "url=rob/tag/&id=$inner" >tmp &&
grep "^Status: 200" tmp &&
grep "tagged object" tmp
'
test_expect_success 'the dumb transport serves an empty repository' '
git init -q --bare empty.git &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=empty" &&
- echo "repo.path=$PWD/empty.git"
- } >emptyrc &&
- CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=empty/info/refs" cgit >tmp &&
+ cgitrc_repo emptyrc empty "repo.path=$PWD/empty.git" &&
+ cgit_rc emptyrc "url=empty/info/refs" >tmp &&
grep "^Status: 200" tmp &&
grep "^Content-Type: text/plain" tmp &&
- CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=empty/objects/info" cgit >tmp &&
+ cgit_rc emptyrc "url=empty/objects/info" >tmp &&
grep "^Status: 404" tmp
'
@@ -569,10 +540,10 @@ test_expect_success 'the dumb transport serves an empty repository' '
# its size up front and compare what arrived against it.
test_expect_success 'the dumb transport sends a file with its size' '
git -C repos/rob repack -q -d &&
- robq "url=rob/objects/info/packs" >tmp &&
+ cgit_rc robrc "url=rob/objects/info/packs" >tmp &&
pack=$(strip_headers <tmp | sed -n "s/^P //p" | head -1) &&
test -n "$pack" &&
- robq "url=rob/objects/pack/$pack" >tmp &&
+ cgit_rc robrc "url=rob/objects/pack/$pack" >tmp &&
grep "^Status: 200" tmp &&
size=$(wc -c <repos/rob/.git/objects/pack/$pack | tr -d " ") &&
grep "^Content-Length: $size$" tmp &&
@@ -588,43 +559,38 @@ test_expect_success 'the dumb transport withholds the alternates file' '
for path in info/alternates info//alternates info/./alternates ./info/alternates \
info/Alternates /info/alternates
do
- robq "url=rob/objects/$path" >tmp &&
+ cgit_rc robrc "url=rob/objects/$path" >tmp &&
grep "^Status: 404" tmp &&
! grep "repos/foo" tmp || return 1
done &&
rm repos/rob/.git/objects/info/alternates &&
- robq "url=rob/objects/info/packs" >tmp &&
+ cgit_rc robrc "url=rob/objects/info/packs" >tmp &&
grep "^Status: 200" tmp
'
# A reftable repository keeps only a placeholder in its HEAD file, so the
# branch a client is to check out has to come from the refs instead.
test_expect_success 'the dumb transport answers HEAD from the refs' '
- robq "url=rob/HEAD" >tmp &&
+ cgit_rc robrc "url=rob/HEAD" >tmp &&
grep "^Status: 200" tmp &&
strip_headers <tmp >head &&
echo "ref: refs/heads/master" >expect &&
test_cmp expect head &&
git init -q --bare --ref-format=reftable -b trunk rt.git &&
git -C repos/rob push -q "$PWD/rt.git" master:trunk &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=rt" &&
- echo "repo.path=$PWD/rt.git"
- } >rtrc &&
- CGIT_CONFIG="$PWD/rtrc" QUERY_STRING="url=rt/HEAD" cgit >tmp &&
+ cgitrc_repo rtrc rt "repo.path=$PWD/rt.git" &&
+ cgit_rc rtrc "url=rt/HEAD" >tmp &&
strip_headers <tmp >head &&
echo "ref: refs/heads/trunk" >expect &&
test_cmp expect head &&
- CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=empty/HEAD" cgit >tmp &&
+ cgit_rc emptyrc "url=empty/HEAD" >tmp &&
strip_headers <tmp >head &&
echo "ref: refs/heads/master" >expect &&
test_cmp expect head
'
test_expect_success 'a reftable repository shows its age on the index' '
- CGIT_CONFIG="$PWD/rtrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc rtrc "url=" >tmp &&
grep "<td class=.col-idle.><time " tmp
'
@@ -638,7 +604,7 @@ test_expect_success 'a client that disconnects ends the request quietly' '
git add long.txt &&
git commit -m long
) &&
- { robq "url=rob/tree/long.txt" 2>err; echo $? >status; } | head -c 1 >/dev/null &&
+ { cgit_rc robrc "url=rob/tree/long.txt" 2>err; echo $? >status; } | head -c 1 >/dev/null &&
test "$(cat status)" = 0 &&
! grep -i "broken pipe" err &&
! grep "die()" err
@@ -655,11 +621,11 @@ test_expect_success 'pages behind an auth filter are marked private' '
echo "auth-filter=exec:$PWD/letin.sh" &&
cat robrc
} >letinrc &&
- CGIT_CONFIG="$PWD/letinrc" QUERY_STRING="url=rob/log/" cgit >tmp &&
+ cgit_rc letinrc "url=rob/log/" >tmp &&
grep "^Status: 200" tmp &&
grep "^Cache-Control: private$" tmp &&
grep "^Vary: Cookie$" tmp &&
- robq "url=rob/log/" >tmp &&
+ cgit_rc robrc "url=rob/log/" >tmp &&
! grep "^Cache-Control" tmp &&
! grep "^Vary" tmp
'
@@ -668,10 +634,10 @@ test_expect_success 'pages behind an auth filter are marked private' '
# the branch asked for has to survive that hop.
test_expect_success 'the about redirect keeps the query string' '
git -C repos/rob branch other HEAD &&
- robq "url=rob/about&h=other&x=1" >tmp &&
+ cgit_rc robrc "url=rob/about&h=other&x=1" >tmp &&
grep "^Status: 302" tmp &&
grep "^Location: /rob/?h=other&x=1$" tmp &&
- CGIT_CONFIG="$PWD/aboutrc" QUERY_STRING="url=rob/about&h=other" cgit >tmp &&
+ cgit_rc aboutrc "url=rob/about&h=other" >tmp &&
grep "^Status: 200" tmp
'
@@ -683,9 +649,9 @@ test_expect_success 'the readme follows an annotated tag as the head' '
cat robrc &&
echo "repo.readme=:file-1"
} >tagreadmerc &&
- CGIT_CONFIG="$PWD/tagreadmerc" QUERY_STRING="url=rob/about/&h=v1" cgit >tmp &&
+ cgit_rc tagreadmerc "url=rob/about/&h=v1" >tmp &&
grep "^Status: 200" tmp &&
- CGIT_CONFIG="$PWD/tagreadmerc" QUERY_STRING="url=rob/tree/&h=v1" cgit >tmp &&
+ cgit_rc tagreadmerc "url=rob/tree/&h=v1" >tmp &&
grep ">about<" tmp
'
@@ -702,7 +668,7 @@ test_expect_success 'a symlink whose target is a large blob is listed without it
git update-index --add --cacheinfo 120000,$big,biglink &&
git commit -m biglink
) &&
- robq "url=rob/tree/" >tmp &&
+ cgit_rc robrc "url=rob/tree/" >tmp &&
grep "biglink" tmp &&
! grep "aaaaaaaaaa" tmp
'
@@ -716,7 +682,7 @@ test_expect_success 'a chain of single directories is followed a bounded number
git add d &&
git commit -m deep
) &&
- robq "url=rob/tree/" >tmp &&
+ cgit_rc robrc "url=rob/tree/" >tmp &&
test $(grep -o "class=.ls-dir." tmp | wc -l) -le 17
'
@@ -731,7 +697,7 @@ test_expect_success 'an unreadable project list is named with its error' '
echo "project-list=$PWD/projdir" &&
echo "scan-path=$PWD/repos"
} >projrc &&
- CGIT_CONFIG="$PWD/projrc" QUERY_STRING="url=" cgit >tmp 2>err &&
+ cgit_rc projrc "url=" >tmp 2>err &&
grep "project list .*projdir: Is a directory" err
'
@@ -744,7 +710,7 @@ test_expect_success SANITY 'a scan entry that cannot be searched is named in ful
echo "cache-size=0" &&
echo "scan-path=$PWD/scanperm"
} >scanpermrc &&
- CGIT_CONFIG="$PWD/scanpermrc" QUERY_STRING="url=" cgit >tmp 2>err &&
+ cgit_rc scanpermrc "url=" >tmp 2>err &&
grep "Unable to stat .*scanperm/locked/objects: Permission denied" err
'
@@ -759,7 +725,7 @@ test_expect_success 'a readme past max-blob-size is reported on the about page'
cat robrc &&
echo "repo.readme=:big-readme"
} >bigreadmerc &&
- CGIT_CONFIG="$PWD/bigreadmerc" QUERY_STRING="url=rob/about/" cgit >tmp &&
+ cgit_rc bigreadmerc "url=rob/about/" >tmp &&
grep "The readme is larger than max-blob-size (1 KB)" tmp
'
@@ -767,9 +733,9 @@ test_expect_success 'a readme past max-blob-size is reported on the about page'
# that was just refused must not be looked up to get there, since the wider
# revision syntax walks the whole history for a match.
test_expect_success 'the error page does not resolve the id it refused' '
- robq "url=rob/log/&id=$sha" >tmp &&
+ cgit_rc robrc "url=rob/log/&id=$sha" >tmp &&
grep "<title>.* @ " tmp &&
- robq "url=rob/log/&id=%3A/commit" >tmp &&
+ cgit_rc robrc "url=rob/log/&id=%3A/commit" >tmp &&
grep "^Status: 400" tmp &&
! grep "<title>.* @ " tmp
'
@@ -794,22 +760,17 @@ test_expect_success 'odd dates and zones in pushed objects render' '
git hash-object -t commit -w --literally --stdin) &&
git update-ref refs/heads/zone $zone
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=dates" &&
- echo "repo.path=$PWD/repos/dates/.git"
- } >datesrc &&
+ cgitrc_repo datesrc dates &&
for q in "url=dates/" "url=dates/refs/" "url=dates/tag/&h=early" \
"url=dates/log/&h=far" "url=dates/commit/&h=far" "url=dates/commit/&h=zone" \
"url=dates/atom/&h=far"
do
- CGIT_CONFIG="$PWD/datesrc" QUERY_STRING="$q" cgit >tmp 2>err &&
+ cgit_rc datesrc "$q" >tmp 2>err &&
grep "^Status: 200" tmp &&
! grep "Unable to complete" tmp &&
! grep "Timestamp" err || return 1
done &&
- CGIT_CONFIG="$PWD/datesrc" QUERY_STRING="url=dates/commit/&h=far" cgit >tmp &&
+ cgit_rc datesrc "url=dates/commit/&h=far" >tmp &&
grep "1970-01-01" tmp
'
@@ -826,7 +787,7 @@ test_expect_success 'a notes ref that names no tree is passed over' '
for q in "url=dates/" "url=dates/log/" "url=dates/refs/" "url=dates/tree/" \
"url=dates/snapshot/dates-base.tar.asc"
do
- CGIT_CONFIG="$PWD/notesrc" QUERY_STRING="$q" cgit >tmp 2>err &&
+ cgit_rc notesrc "$q" >tmp 2>err &&
! grep "Unable to complete" tmp &&
! grep "notes tree" err || return 1
done &&
@@ -839,7 +800,7 @@ test_expect_success 'a scanned defbranch cannot name a path outside the reposito
mkdir -p secret &&
touch -t 200001010000 secret/file &&
echo "defbranch=../../../../secret/file" >scan/b.git/cgitrc &&
- CGIT_CONFIG="$PWD/gitcfgrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc gitcfgrc "url=" >tmp &&
grep ">b.git</a>" tmp &&
! grep "data-ut=.946" tmp
'