From 2be91842938c083096ce8c95042ea6f250666adf Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:26:05 -1000 Subject: Compare each snapshot format with git archive Only the entry count and one file were checked, never the archive itself. git's own writer at the same commit gives the same bytes, so each format is held to it, which also proves the commit served. That leaves unzip -t unused, which busybox may not have. --- tests/t0110-snapshot.sh | 105 ++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 58 deletions(-) diff --git a/tests/t0110-snapshot.sh b/tests/t0110-snapshot.sh index 0f1ca21..2078a71 100755 --- a/tests/t0110-snapshot.sh +++ b/tests/t0110-snapshot.sh @@ -1,19 +1,19 @@ #!/bin/sh -# The snapshot page hands a branch back as an archive. One function below -# 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. Plain tar and zip get checks -# of their own, since cgit runs no compressor for either and unzip shares no -# flags with the rest. +# The snapshot page hands a revision back as an archive. Every format is held +# byte for byte to the archive git itself writes, once decompressed where cgit +# pipes through a compressor, and each compressed format needs the same tool +# on the server and here, so one missing tool skips that format on both +# grounds at once. The tags after them check how a snapshot is named. test_description='Verify snapshot' . ./setup.sh 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." + sed "/^$/q" tmp >headers && + grep "^Status: 200 OK$" headers && + grep "^Content-Type: $2$" headers && + grep "^Content-Disposition: inline; filename=\"master.$1\"$" headers } check_snapshot_content() { @@ -23,7 +23,30 @@ check_snapshot_content() { test_line_count = 1 master/file-5 } -# Registers the checks for one compressed tar format. +# Lists the members of the archive in the response held in tmp. +snapshot_members() { + strip_headers snapshot.tar && + tar -tf snapshot.tar >members +} + +# The format checks below compare against these, which git's own writer makes +# from the commit the snapshots are taken of. +test_expect_success 'set up the archives git writes' ' + git -C repos/foo archive --format=tar --prefix=master/ master >expect.tar && + git -C repos/foo archive --format=zip --prefix=master/ master >expect.zip +' + +test_expect_success 'a tar snapshot is the archive git writes' ' + cgit_ok_url "foo/snapshot/master.tar" >tmp && + check_snapshot_headers tar application/x-tar && + strip_headers master.tar && + test_cmp_bin expect.tar master.tar && + rm -rf master && + tar -xf master.tar && + check_snapshot_content +' + +# Registers the check for one compressed tar format. test_tar_snapshot() { ext=$1 type=$2 @@ -32,66 +55,32 @@ test_tar_snapshot() { 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" " - check_snapshot_headers $ext $type - " - - test_expect_success $prereq "verify $ext format" " + test_expect_success $prereq "a $ext snapshot unpacks to the tar git writes" " + cgit_ok_url 'foo/snapshot/master.$ext' >tmp && + check_snapshot_headers $ext $type && strip_headers master.$ext && - '$tool' -t 'master.$ext' - " - - test_expect_success $prereq "untar $ext and verify the content" " - rm -rf master && - '$tool' -dc 'master.$ext' | tar -xf - && - check_snapshot_content + '$tool' -t 'master.$ext' && + '$tool' -dc 'master.$ext' >master.tar && + test_cmp_bin expect.tar master.tar " } -# The uncompressed tar comes straight out of git's archive writer, so tar -# itself both proves the format and unpacks it. -test_expect_success 'get foo/snapshot/master.tar' ' - cgit_url "foo/snapshot/master.tar" >tmp -' - -test_expect_success 'check tar response headers' ' - check_snapshot_headers tar application/x-tar -' - -test_expect_success 'untar and verify the content' ' - strip_headers master.tar && - rm -rf master && - tar -xf master.tar && - check_snapshot_content -' - test_tar_snapshot tar.gz application/gzip gzip GZIP test_tar_snapshot tar.bz2 application/x-bzip2 bzip2 BZIP2 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 -test_expect_success 'get foo/snapshot/master.zip' ' - cgit_url "foo/snapshot/master.zip" >tmp -' - -test_expect_success 'check zip response headers' ' - check_snapshot_headers zip application/zip -' - -test_expect_success 'strip off the header lines' ' - strip_headers master.zip -' - -test_expect_success UNZIP 'verify zip format' ' - "$GIT_UNZIP" -t master.zip +test_expect_success 'a zip snapshot is the archive git writes' ' + cgit_ok_url "foo/snapshot/master.zip" >tmp && + check_snapshot_headers zip application/zip && + strip_headers master.zip && + test_cmp_bin expect.zip master.zip ' -test_expect_success UNZIP 'unzip and verify the content' ' +test_expect_success UNZIP 'a zip snapshot unzips' ' + cgit_ok_url "foo/snapshot/master.zip" >tmp && + strip_headers master.zip && rm -rf master && "$GIT_UNZIP" master.zip && check_snapshot_content -- cgit 2.12.1