blob: f75068de64851faf86d7ae270c1b88bb9d08df16 [file] [log] [blame]
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -08001#!/bin/sh
2
3test_description='test git-http-backend-noserver'
Johannes Schindelin028cb642020-11-18 23:44:34 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Ævar Arnfjörð Bjarmason1fdd31c2023-02-07 00:07:52 +01007TEST_PASSES_SANITIZE_LEAK=true
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -08008. ./test-lib.sh
9
10HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
11
Junio C Hamanoc1cebcf2014-05-23 11:19:34 -070012if test_have_prereq GREP_STRIPS_CR
13then
14 GREP_OPTIONS=-U
15 export GREP_OPTIONS
16fi
Pat Thoytsa94114a2010-09-12 10:37:24 +010017
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -080018run_backend() {
Tarmigan Caseboltfd0a8c22010-01-02 13:43:59 -080019 echo "$2" |
Kyle J. McKayff7a1c62014-04-11 01:28:19 -070020 QUERY_STRING="${1#*[?]}" \
21 PATH_TRANSLATED="$HTTPD_DOCUMENT_ROOT_PATH/${1%%[?]*}" \
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -080022 git http-backend >act.out 2>act.err
23}
24
25GET() {
Junio C Hamano69ae92b2010-10-13 11:36:36 -070026 REQUEST_METHOD="GET" && export REQUEST_METHOD &&
Tarmigan Caseboltfd0a8c22010-01-02 13:43:59 -080027 run_backend "/repo.git/$1" &&
Ævar Arnfjörð Bjarmason1f5ad6b2012-02-12 01:05:12 +000028 sane_unset REQUEST_METHOD &&
Tarmigan Caseboltfd0a8c22010-01-02 13:43:59 -080029 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 Casebolt04481ad2010-01-02 13:38:06 -080035}
36
37POST() {
Junio C Hamano69ae92b2010-10-13 11:36:36 -070038 REQUEST_METHOD="POST" && export REQUEST_METHOD &&
39 CONTENT_TYPE="application/x-$1-request" && export CONTENT_TYPE &&
Tarmigan Caseboltfd0a8c22010-01-02 13:43:59 -080040 run_backend "/repo.git/$1" "$2" &&
Ævar Arnfjörð Bjarmason1f5ad6b2012-02-12 01:05:12 +000041 sane_unset REQUEST_METHOD &&
42 sane_unset CONTENT_TYPE &&
Tarmigan Caseboltfd0a8c22010-01-02 13:43:59 -080043 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 Casebolt04481ad2010-01-02 13:38:06 -080049}
50
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -080051. "$TEST_DIRECTORY"/t556x_common
52
53expect_aliased() {
Junio C Hamano69ae92b2010-10-13 11:36:36 -070054 REQUEST_METHOD="GET" && export REQUEST_METHOD &&
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -080055 if test $1 = 0; then
Tarmigan Casebolte8189ee2010-01-14 22:44:02 -080056 run_backend "$2"
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -080057 else
Tarmigan Casebolte8189ee2010-01-14 22:44:02 -080058 run_backend "$2" &&
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -080059 echo "fatal: '$2': aliased" >exp.err &&
60 test_cmp exp.err act.err
61 fi
Tarmigan Casebolte8189ee2010-01-14 22:44:02 -080062 unset REQUEST_METHOD
Tarmigan Casebolt04481ad2010-01-02 13:38:06 -080063}
64
65test_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
78test_done