Diff options
Diffstat (limited to '')
-rwxr-xr-xtests/t0110-snapshot.sh133
1 file changed, 68 insertions, 65 deletions
diff --git a/tests/t0110-snapshot.sh b/tests/t0110-snapshot.sh
index bec0e3d..faebf5e 100755
--- a/tests/t0110-snapshot.sh
+++ b/tests/t0110-snapshot.sh
@@ -1,38 +1,43 @@
#!/bin/sh
# The snapshot page hands a branch back as an archive. One function below
-# registers the same checks for every tar based format, and each format
+# registers the same checks for every compressed tar format, and each format
# needs the same compressor cgit pipes through on the server, so one missing
-# tool skips that format on both grounds at once. zip follows at the end,
-# since unzip shares no flags with the rest.
+# tool skips that format on both grounds at once. Plain tar and zip get checks
+# of their own, since cgit runs no compressor for either and unzip shares no
+# flags with the rest.
test_description='Verify snapshot'
. ./setup.sh
-# Registers the checks for one tar based format. Takes the archive suffix,
-# the content type the response must carry, the compressor to unpack with and
-# the name of the prerequisite guarding the checks.
+check_snapshot_headers() {
+ head -n 1 tmp | grep "Status: 200 OK" &&
+ head -n 2 tmp | grep "^Content-Type: $2$" &&
+ head -n 3 tmp | grep "Content-Disposition: inline; filename=.master.$1."
+}
+
+check_snapshot_content() {
+ ls master/ >output &&
+ test_line_count = 5 output &&
+ grep "^5$" master/file-5 &&
+ test_line_count = 1 master/file-5
+}
+
+# Registers the checks for one compressed tar format.
test_tar_snapshot() {
ext=$1
type=$2
tool=$3
prereq=$4
- if command -v "$tool" >/dev/null 2>&1
- then
- test_set_prereq $prereq
- else
- say "Skipping $ext validation tests: $tool not found"
- fi
+ test_lazy_prereq $prereq "command -v $tool"
test_expect_success $prereq "get foo/snapshot/master.$ext" "
cgit_url 'foo/snapshot/master.$ext' >tmp
"
test_expect_success $prereq "check $ext response headers" "
- head -n 1 tmp | grep 'Status: 200 OK' &&
- head -n 2 tmp | grep '^Content-Type: $type\$' &&
- head -n 3 tmp | grep 'Content-Disposition: inline; filename=.master.$ext.'
+ check_snapshot_headers $ext $type
"
test_expect_success $prereq "verify $ext format" "
@@ -43,10 +48,7 @@ test_tar_snapshot() {
test_expect_success $prereq "untar $ext and verify the content" "
rm -rf master &&
'$tool' -dc 'master.$ext' | tar -xf - &&
- ls master/ >output &&
- test_line_count = 5 output &&
- grep '^5\$' master/file-5 &&
- test_line_count = 1 master/file-5
+ check_snapshot_content
"
}
@@ -57,19 +59,14 @@ test_expect_success 'get foo/snapshot/master.tar' '
'
test_expect_success 'check tar response headers' '
- head -n 1 tmp | grep "Status: 200 OK" &&
- head -n 2 tmp | grep "^Content-Type: application/x-tar$" &&
- head -n 3 tmp | grep "Content-Disposition: inline; filename=.master.tar."
+ check_snapshot_headers tar application/x-tar
'
test_expect_success 'untar and verify the content' '
strip_headers <tmp >master.tar &&
rm -rf master &&
tar -xf master.tar &&
- ls master/ >output &&
- test_line_count = 5 output &&
- grep "^5$" master/file-5 &&
- test_line_count = 1 master/file-5
+ check_snapshot_content
'
test_tar_snapshot tar.gz application/gzip gzip GZIP
@@ -78,21 +75,12 @@ test_tar_snapshot tar.lz application/x-lzip lzip LZIP
test_tar_snapshot tar.xz application/x-xz xz XZ
test_tar_snapshot tar.zst application/zstd zstd ZSTD
-if command -v unzip >/dev/null 2>&1
-then
- test_set_prereq UNZIP
-else
- say 'Skipping zip validation tests: unzip not found'
-fi
-
test_expect_success 'get foo/snapshot/master.zip' '
cgit_url "foo/snapshot/master.zip" >tmp
'
test_expect_success 'check zip response headers' '
- head -n 1 tmp | grep "Status: 200 OK" &&
- head -n 2 tmp | grep "^Content-Type: application/zip$" &&
- head -n 3 tmp | grep "Content-Disposition: inline; filename=.master.zip."
+ check_snapshot_headers zip application/zip
'
test_expect_success 'strip off the header lines' '
@@ -100,16 +88,13 @@ test_expect_success 'strip off the header lines' '
'
test_expect_success UNZIP 'verify zip format' '
- unzip -t master.zip
+ "$GIT_UNZIP" -t master.zip
'
test_expect_success UNZIP 'unzip and verify the content' '
rm -rf master &&
- unzip master.zip &&
- ls master/ >output &&
- test_line_count = 5 output &&
- grep "^5$" master/file-5 &&
- test_line_count = 1 master/file-5
+ "$GIT_UNZIP" master.zip &&
+ check_snapshot_content
'
# A tag named v1.0 sheds its v in the snapshot name unless dropping it would
@@ -120,17 +105,11 @@ test_expect_success UNZIP 'unzip and verify the content' '
test_expect_success 'set up a repo with a versioned tag' '
mkrepo repos/vtags 2 &&
git -C repos/vtags update-ref refs/tags/v1.0 HEAD &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "snapshots=tar.gz" &&
- echo "repo.url=vtags" &&
- echo "repo.path=$PWD/repos/vtags/.git"
- } >vtagsrc
+ cgitrc_repo vtagsrc vtags snapshots=tar.gz
'
test_expect_success 'a loose v tag still sheds its v in the snapshot name' '
- CGIT_CONFIG="$PWD/vtagsrc" QUERY_STRING="url=vtags/refs/" cgit >tmp &&
+ cgit_rc vtagsrc "url=vtags/refs/" >tmp &&
grep "vtags-1.0.tar.gz" tmp &&
! grep "vtags-v1.0.tar.gz" tmp
'
@@ -140,7 +119,7 @@ test_expect_success 'a loose v tag still sheds its v in the snapshot name' '
test_expect_success 'a real case collision keeps the v on both tags' '
git -C repos/vtags pack-refs --all &&
git -C repos/vtags update-ref refs/tags/V1.0 HEAD~1 &&
- CGIT_CONFIG="$PWD/vtagsrc" QUERY_STRING="url=vtags/refs/" cgit >tmp &&
+ cgit_rc vtagsrc "url=vtags/refs/" >tmp &&
grep "vtags-v1.0.tar.gz" tmp &&
grep "vtags-V1.0.tar.gz" tmp &&
! grep "vtags-1.0.tar.gz" tmp
@@ -151,7 +130,7 @@ test_expect_success 'a real case collision keeps the v on both tags' '
test_expect_success 'a snapshot name with nothing before its suffix is refused' '
git -C repos/vtags branch v HEAD &&
sed "s/^snapshots=tar.gz$/snapshots=tar/" vtagsrc >vtagstarrc &&
- CGIT_CONFIG="$PWD/vtagstarrc" QUERY_STRING="url=vtags/snapshot/.tar" cgit >tmp &&
+ cgit_rc vtagstarrc "url=vtags/snapshot/.tar" >tmp &&
grep "^Status: 404" tmp
'
@@ -160,17 +139,47 @@ test_expect_success 'an empty snapshot-prefix puts no slash ahead of the members
cat vtagstarrc &&
echo "repo.snapshot-prefix="
} >noprefixrc &&
- CGIT_CONFIG="$PWD/noprefixrc" QUERY_STRING="url=vtags/snapshot/vtags.tar&id=master" cgit >tmp &&
+ cgit_rc noprefixrc "url=vtags/snapshot/vtags.tar&id=master" >tmp &&
strip_headers <tmp >noprefix.tar &&
tar -tf noprefix.tar >members &&
grep "^file-1$" members &&
! grep "^/" members
'
+# A snapshot is named after the last component of the url once its .git
+# suffix is gone, so a url of .git alone leaves the ref as the whole name.
+test_expect_success 'set up repositories whose urls end in .git' '
+ mkrepo repos/dotgit 1 &&
+ git -C repos/dotgit tag v1.0 &&
+ {
+ echo "virtual-root=/" &&
+ echo "cache-size=0" &&
+ echo "snapshots=tar" &&
+ echo "repo.url=.git" &&
+ echo "repo.path=$PWD/repos/dotgit/.git" &&
+ echo "repo.url=sub/.git" &&
+ echo "repo.path=$PWD/repos/dotgit/.git"
+ } >dotgitrc
+'
+
+test_expect_success 'a url of .git names a snapshot after the ref alone' '
+ cgit_rc dotgitrc "url=.git/refs/" >tmp &&
+ grep ">v1.0.tar<" tmp &&
+ cgit_rc dotgitrc "url=.git/snapshot/v1.0.tar" >tmp &&
+ strip_headers <tmp >dotgit.tar &&
+ tar -tf dotgit.tar >members &&
+ grep "^v1.0/file-1$" members
+'
+
+test_expect_success 'a url ending in /.git names a snapshot after its directory' '
+ cgit_rc dotgitrc "url=sub/.git/refs/" >tmp &&
+ grep ">sub-1.0.tar<" tmp
+'
+
# A server may run cgit with no PATH at all, and the compressor is then looked
# for on the default path execvp searches.
test_expect_success GZIP 'a compressed snapshot is made without a PATH' '
- sed "s/^cache-size=.*/cache-size=0/" cgitrc >nopathrc &&
+ cgitrc_copy nopathrc &&
cgit_bin=$(command -v cgit) &&
(
unset PATH &&
@@ -183,9 +192,9 @@ test_expect_success GZIP 'a compressed snapshot is made without a PATH' '
# A link offers the snapshot of a tag, and the name on it has to lead back to
# that tag even when a branch is spelled like the tag's stem.
-test_expect_success 'a snapshot name leads to the tag ahead of a branch' '
+test_expect_success GZIP 'a snapshot name leads to the tag ahead of a branch' '
git -C repos/vtags update-ref refs/heads/1.0 $(git -C repos/vtags commit-tree -m shadow HEAD^{tree}) &&
- CGIT_CONFIG="$PWD/vtagsrc" QUERY_STRING="url=vtags/snapshot/vtags-1.0.tar.gz" cgit >tmp &&
+ cgit_rc vtagsrc "url=vtags/snapshot/vtags-1.0.tar.gz" >tmp &&
strip_headers <tmp >tag.tar.gz &&
test "$(gzip -dc tag.tar.gz | git -C repos/vtags get-tar-commit-id)" = "$(git -C repos/vtags rev-parse refs/tags/v1.0^{commit})"
'
@@ -198,7 +207,7 @@ test_expect_success 'a signature past max-blob-size is refused' '
echo "max-blob-size=1" &&
cat vtagsrc
} >sigrc &&
- CGIT_CONFIG="$PWD/sigrc" QUERY_STRING="url=vtags/snapshot/vtags-1.0.tar.gz.asc" cgit >tmp &&
+ cgit_rc sigrc "url=vtags/snapshot/vtags-1.0.tar.gz.asc" >tmp &&
grep "^Status: 413" tmp
'
@@ -213,14 +222,8 @@ test_expect_success 'a snapshot and its signature are linked as one unit' '
sig=$(echo signature | git hash-object -w --stdin) &&
git notes --ref signatures/tar.gz add -C $sig one
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "snapshots=tar.gz" &&
- echo "repo.url=signed" &&
- echo "repo.path=$PWD/repos/signed/.git"
- } >signedrc &&
- CGIT_CONFIG="$PWD/signedrc" QUERY_STRING="url=signed/refs/" cgit >tmp &&
+ cgitrc_repo signedrc signed snapshots=tar.gz &&
+ cgit_rc signedrc "url=signed/refs/" >tmp &&
grep "<span class=.snapshot.><a href=./signed/snapshot/signed-one.tar.gz.>signed-one.tar.gz</a> (<a href=./signed/snapshot/signed-one.tar.gz.asc.>sig</a>)</span>" tmp
'