Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test git-http-backend-noserver' |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Ævar Arnfjörð Bjarmason | 1fdd31c | 2023-02-07 00:07:52 +0100 | [diff] [blame] | 7 | TEST_PASSES_SANITIZE_LEAK=true |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY" |
| 11 | |
Junio C Hamano | c1cebcf | 2014-05-23 11:19:34 -0700 | [diff] [blame] | 12 | if test_have_prereq GREP_STRIPS_CR |
| 13 | then |
| 14 | GREP_OPTIONS=-U |
| 15 | export GREP_OPTIONS |
| 16 | fi |
Pat Thoyts | a94114a | 2010-09-12 10:37:24 +0100 | [diff] [blame] | 17 | |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 18 | run_backend() { |
Tarmigan Casebolt | fd0a8c2 | 2010-01-02 13:43:59 -0800 | [diff] [blame] | 19 | echo "$2" | |
Kyle J. McKay | ff7a1c6 | 2014-04-11 01:28:19 -0700 | [diff] [blame] | 20 | QUERY_STRING="${1#*[?]}" \ |
| 21 | PATH_TRANSLATED="$HTTPD_DOCUMENT_ROOT_PATH/${1%%[?]*}" \ |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 22 | git http-backend >act.out 2>act.err |
| 23 | } |
| 24 | |
| 25 | GET() { |
Junio C Hamano | 69ae92b | 2010-10-13 11:36:36 -0700 | [diff] [blame] | 26 | REQUEST_METHOD="GET" && export REQUEST_METHOD && |
Tarmigan Casebolt | fd0a8c2 | 2010-01-02 13:43:59 -0800 | [diff] [blame] | 27 | run_backend "/repo.git/$1" && |
Ævar Arnfjörð Bjarmason | 1f5ad6b | 2012-02-12 01:05:12 +0000 | [diff] [blame] | 28 | sane_unset REQUEST_METHOD && |
Tarmigan Casebolt | fd0a8c2 | 2010-01-02 13:43:59 -0800 | [diff] [blame] | 29 | if ! grep "Status" act.out >act |
| 30 | then |
| 31 | printf "Status: 200 OK\r\n" >act |
| 32 | fi |
| 33 | printf "Status: $2\r\n" >exp && |
| 34 | test_cmp exp act |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | POST() { |
Junio C Hamano | 69ae92b | 2010-10-13 11:36:36 -0700 | [diff] [blame] | 38 | REQUEST_METHOD="POST" && export REQUEST_METHOD && |
| 39 | CONTENT_TYPE="application/x-$1-request" && export CONTENT_TYPE && |
Tarmigan Casebolt | fd0a8c2 | 2010-01-02 13:43:59 -0800 | [diff] [blame] | 40 | run_backend "/repo.git/$1" "$2" && |
Ævar Arnfjörð Bjarmason | 1f5ad6b | 2012-02-12 01:05:12 +0000 | [diff] [blame] | 41 | sane_unset REQUEST_METHOD && |
| 42 | sane_unset CONTENT_TYPE && |
Tarmigan Casebolt | fd0a8c2 | 2010-01-02 13:43:59 -0800 | [diff] [blame] | 43 | if ! grep "Status" act.out >act |
| 44 | then |
| 45 | printf "Status: 200 OK\r\n" >act |
| 46 | fi |
| 47 | printf "Status: $3\r\n" >exp && |
| 48 | test_cmp exp act |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 51 | . "$TEST_DIRECTORY"/t556x_common |
| 52 | |
| 53 | expect_aliased() { |
Junio C Hamano | 69ae92b | 2010-10-13 11:36:36 -0700 | [diff] [blame] | 54 | REQUEST_METHOD="GET" && export REQUEST_METHOD && |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 55 | if test $1 = 0; then |
Tarmigan Casebolt | e8189ee | 2010-01-14 22:44:02 -0800 | [diff] [blame] | 56 | run_backend "$2" |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 57 | else |
Tarmigan Casebolt | e8189ee | 2010-01-14 22:44:02 -0800 | [diff] [blame] | 58 | run_backend "$2" && |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 59 | echo "fatal: '$2': aliased" >exp.err && |
| 60 | test_cmp exp.err act.err |
| 61 | fi |
Tarmigan Casebolt | e8189ee | 2010-01-14 22:44:02 -0800 | [diff] [blame] | 62 | unset REQUEST_METHOD |
Tarmigan Casebolt | 04481ad | 2010-01-02 13:38:06 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | test_expect_success 'http-backend blocks bad PATH_INFO' ' |
| 66 | config http.getanyfile true && |
| 67 | |
| 68 | expect_aliased 0 /repo.git/HEAD && |
| 69 | |
| 70 | expect_aliased 1 /repo.git/../HEAD && |
| 71 | expect_aliased 1 /../etc/passwd && |
| 72 | expect_aliased 1 ../etc/passwd && |
| 73 | expect_aliased 1 /etc//passwd && |
| 74 | expect_aliased 1 /etc/./passwd && |
| 75 | expect_aliased 1 //domain/data.txt |
| 76 | ' |
| 77 | |
| 78 | test_done |