git/t/t9501-gitweb-standalone-http-status.sh

222 lines
7 KiB
Bash
Raw Normal View History

#!/bin/sh
#
# Copyright (c) 2009 Mark Rada
#
test_description='gitweb as standalone script (http status tests).
This test runs gitweb (git web interface) as a CGI script from the
commandline, and checks that it returns the expected HTTP status
code and message.'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
tests: mark tests relying on the current default for `init.defaultBranch` In addition to the manual adjustment to let the `linux-gcc` CI job run the test suite with `master` and then with `main`, this patch makes sure that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts that currently rely on the initial branch name being `master by default. To determine which test scripts to mark up, the first step was to force-set the default branch name to `master` in - all test scripts that contain the keyword `master`, - t4211, which expects `t/t4211/history.export` with a hard-coded ref to initialize the default branch, - t5560 because it sources `t/t556x_common` which uses `master`, - t8002 and t8012 because both source `t/annotate-tests.sh` which also uses `master`) This trick was performed by this command: $ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\ ' $(git grep -l master t/t[0-9]*.sh) \ t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh After that, careful, manual inspection revealed that some of the test scripts containing the needle `master` do not actually rely on a specific default branch name: either they mention `master` only in a comment, or they initialize that branch specificially, or they do not actually refer to the current default branch. Therefore, the aforementioned modification was undone in those test scripts thusly: $ git checkout HEAD -- \ t/t0027-auto-crlf.sh t/t0060-path-utils.sh \ t/t1011-read-tree-sparse-checkout.sh \ t/t1305-config-include.sh t/t1309-early-config.sh \ t/t1402-check-ref-format.sh t/t1450-fsck.sh \ t/t2024-checkout-dwim.sh \ t/t2106-update-index-assume-unchanged.sh \ t/t3040-subprojects-basic.sh t/t3301-notes.sh \ t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \ t/t3436-rebase-more-options.sh \ t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \ t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \ t/t5511-refspec.sh t/t5526-fetch-submodules.sh \ t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \ t/t5548-push-porcelain.sh \ t/t5552-skipping-fetch-negotiator.sh \ t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \ t/t5614-clone-submodules-shallow.sh \ t/t7508-status.sh t/t7606-merge-custom.sh \ t/t9302-fast-import-unpack-limit.sh We excluded one set of test scripts in these commands, though: the range of `git p4` tests. The reason? `git p4` stores the (foreign) remote branch in the branch called `p4/master`, which is obviously not the default branch. Manual analysis revealed that only five of these tests actually require a specific default branch name to pass; They were modified thusly: $ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\ ' t/t980[0167]*.sh t/t9811*.sh Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 23:44:19 +00:00
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
revisions API: have release_revisions() release "cmdline" Extend the the release_revisions() function so that it frees the "cmdline" in the "struct rev_info". This in combination with a preceding change to free "commits" and "mailmap" means that we can whitelist another test under "TEST_PASSES_SANITIZE_LEAK=true". There was a proposal in [1] to do away with xstrdup()-ing this add_rev_cmdline(), perhaps that would be worthwhile, but for now let's just free() it. We could also make that a "char *" in "struct rev_cmdline_entry" itself, but since we own it let's expose it as a constant to outside callers. I proposed that in [2] but have since changed my mind. See 14d30cdfc04 (ref-filter: fix memory leak in `free_array_item()`, 2019-07-10), c514c62a4fd (checkout: fix leak of non-existent branch names, 2020-08-14) and other log history hits for "free((char *)" for prior art. This includes the tests we had false-positive passes on before my 6798b08e848 (perl Git.pm: don't ignore signalled failure in _cmd_close(), 2022-02-01), now they pass for real. Since there are 66 tests matching t/t[0-9]*git-svn*.sh it's easier to list those that don't pass than to touch most of those 66. So let's introduce a "TEST_FAILS_SANITIZE_LEAK=true", which if set in the tests won't cause lib-git-svn.sh to set "TEST_PASSES_SANITIZE_LEAK=true. This change also marks all the tests that we removed "TEST_FAILS_SANITIZE_LEAK=true" from in an earlier commit due to removing the UNLEAK() from cmd_format_patch(), we can now assert that its API use doesn't leak any "struct rev_info" memory. This change also made commit "t5503-tagfollow.sh" pass on current master, but that would regress when combined with ps/fetch-atomic-fixup's de004e848a9 (t5503: simplify setup of test which exercises failure of backfill, 2022-03-03) (through no fault of that topic, that change started using "git clone" in the test, which has an outstanding leak). Let's leave that test out for now to avoid in-flight semantic conflicts. 1. https://lore.kernel.org/git/YUj%2FgFRh6pwrZalY@carlos-mbp.lan/ 2. https://lore.kernel.org/git/87o88obkb1.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-04-13 20:01:47 +00:00
TEST_PASSES_SANITIZE_LEAK=true
. ./lib-gitweb.sh
#
# Gitweb only provides the functionality tested by the 'modification times'
# tests if it can access a date parser from one of these modules:
#
perl -MHTTP::Date -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
perl -MTime::ParseDate -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
# ----------------------------------------------------------------------
# snapshot settings
test_expect_success 'setup' "
test_commit 'SnapshotTests' 'i can has snapshot'
"
cat >>gitweb_config.perl <<\EOF
$feature{'snapshot'}{'override'} = 0;
EOF
test_expect_success \
'snapshots: tgz only default format enabled' \
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
grep "Status: 200 OK" gitweb.output &&
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
grep "403 - Unsupported snapshot format" gitweb.output &&
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
grep "403 - Snapshot format not allowed" gitweb.output &&
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
grep "403 - Unsupported snapshot format" gitweb.output'
cat >>gitweb_config.perl <<\EOF
$feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
EOF
test_expect_success \
'snapshots: all enabled in default, use default disabled value' \
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
grep "Status: 200 OK" gitweb.output &&
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
grep "Status: 200 OK" gitweb.output &&
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
grep "403 - Snapshot format not allowed" gitweb.output &&
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
grep "Status: 200 OK" gitweb.output'
cat >>gitweb_config.perl <<\EOF
$known_snapshot_formats{'zip'}{'disabled'} = 1;
EOF
test_expect_success \
'snapshots: zip explicitly disabled' \
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
grep "403 - Snapshot format not allowed" gitweb.output'
test_debug 'cat gitweb.output'
cat >>gitweb_config.perl <<\EOF
$known_snapshot_formats{'tgz'}{'disabled'} = 0;
EOF
test_expect_success \
'snapshots: tgz explicitly enabled' \
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
grep "Status: 200 OK" gitweb.output'
test_debug 'cat gitweb.headers'
# ----------------------------------------------------------------------
# snapshot hash ids
test_expect_success 'snapshots: good tree-ish id' '
gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
grep "Status: 200 OK" gitweb.output
'
test_debug 'cat gitweb.headers'
test_expect_success 'snapshots: bad tree-ish id' '
gitweb_run "p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz" &&
grep "404 - Object does not exist" gitweb.output
'
test_debug 'cat gitweb.output'
test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
echo object > tag-object &&
git add tag-object &&
test_tick && git commit -m "Object to be tagged" &&
git tag tagged-object $(git hash-object tag-object) &&
gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
grep "400 - Object is not a tree-ish" gitweb.output
'
test_debug 'cat gitweb.output'
test_expect_success 'snapshots: good object id' '
ID=$(git rev-parse --verify HEAD) &&
gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
grep "Status: 200 OK" gitweb.output
'
test_debug 'cat gitweb.headers'
test_expect_success 'snapshots: bad object id' '
gitweb_run "p=.git;a=snapshot;h=abcdef01234;sf=tgz" &&
grep "404 - Object does not exist" gitweb.output
'
test_debug 'cat gitweb.output'
# ----------------------------------------------------------------------
# modification times (Last-Modified and If-Modified-Since)
test_expect_success DATE_PARSER 'modification: feed last-modified' '
gitweb_run "p=.git;a=atom;h=main" &&
grep "Status: 200 OK" gitweb.headers &&
grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
'
test_debug 'cat gitweb.headers'
test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' '
HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
export HTTP_IF_MODIFIED_SINCE &&
test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
gitweb_run "p=.git;a=atom;h=main" &&
grep "Status: 200 OK" gitweb.headers
'
test_debug 'cat gitweb.headers'
test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' '
HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
export HTTP_IF_MODIFIED_SINCE &&
test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
gitweb_run "p=.git;a=atom;h=main" &&
grep "Status: 304 Not Modified" gitweb.headers
'
test_debug 'cat gitweb.headers'
test_expect_success DATE_PARSER 'modification: snapshot last-modified' '
gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
grep "Status: 200 OK" gitweb.headers &&
grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
'
test_debug 'cat gitweb.headers'
test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' '
HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
export HTTP_IF_MODIFIED_SINCE &&
test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
grep "Status: 200 OK" gitweb.headers
'
test_debug 'cat gitweb.headers'
test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' '
HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
export HTTP_IF_MODIFIED_SINCE &&
test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
grep "Status: 304 Not Modified" gitweb.headers
'
test_debug 'cat gitweb.headers'
test_expect_success DATE_PARSER 'modification: tree snapshot' '
ID=$(git rev-parse --verify HEAD^{tree}) &&
HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
export HTTP_IF_MODIFIED_SINCE &&
test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
grep "Status: 200 OK" gitweb.headers &&
! grep -i "last-modified" gitweb.headers
'
test_debug 'cat gitweb.headers'
# ----------------------------------------------------------------------
# load checking
# always hit the load limit
cat >>gitweb_config.perl <<\EOF
our $maxload = -1;
EOF
test_expect_success 'load checking: load too high (default action)' '
gitweb_run "p=.git" &&
grep "Status: 503 Service Unavailable" gitweb.headers &&
grep "503 - The load average on the server is too high" gitweb.body
'
test_debug 'cat gitweb.headers'
# turn off load checking
cat >>gitweb_config.perl <<\EOF
our $maxload = undef;
EOF
# ----------------------------------------------------------------------
# invalid arguments
test_expect_success 'invalid arguments: invalid regexp (in project search)' '
gitweb_run "a=project_list;s=*\.git;sr=1" &&
grep "Status: 400" gitweb.headers &&
grep "400 - Invalid.*regexp" gitweb.body
'
test_debug 'cat gitweb.headers'
test_done