Merge branch 'jn/maint-fast-import-object-reuse' into maint
[git] / t / t5560-http-backend-noserver.sh
1 #!/bin/sh
2
3 test_description='test git-http-backend-noserver'
4 . ./test-lib.sh
5
6 HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
7
8 run_backend() {
9         echo "$2" |
10         QUERY_STRING="${1#*\?}" \
11         GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
12         PATH_INFO="${1%%\?*}" \
13         git http-backend >act.out 2>act.err
14 }
15
16 GET() {
17         REQUEST_METHOD="GET" && export REQUEST_METHOD &&
18         run_backend "/repo.git/$1" &&
19         unset REQUEST_METHOD &&
20         if ! grep "Status" act.out >act
21         then
22                 printf "Status: 200 OK\r\n" >act
23         fi
24         printf "Status: $2\r\n" >exp &&
25         test_cmp exp act
26 }
27
28 POST() {
29         REQUEST_METHOD="POST" && export REQUEST_METHOD &&
30         CONTENT_TYPE="application/x-$1-request" && export CONTENT_TYPE &&
31         run_backend "/repo.git/$1" "$2" &&
32         unset REQUEST_METHOD &&
33         unset CONTENT_TYPE &&
34         if ! grep "Status" act.out >act
35         then
36                 printf "Status: 200 OK\r\n" >act
37         fi
38         printf "Status: $3\r\n" >exp &&
39         test_cmp exp act
40 }
41
42 log_div() {
43         return 0
44 }
45
46 . "$TEST_DIRECTORY"/t556x_common
47
48 expect_aliased() {
49         REQUEST_METHOD="GET" && export REQUEST_METHOD &&
50         if test $1 = 0; then
51                 run_backend "$2"
52         else
53                 run_backend "$2" &&
54                 echo "fatal: '$2': aliased" >exp.err &&
55                 test_cmp exp.err act.err
56         fi
57         unset REQUEST_METHOD
58 }
59
60 test_expect_success 'http-backend blocks bad PATH_INFO' '
61         config http.getanyfile true &&
62
63         expect_aliased 0 /repo.git/HEAD &&
64
65         expect_aliased 1 /repo.git/../HEAD &&
66         expect_aliased 1 /../etc/passwd &&
67         expect_aliased 1 ../etc/passwd &&
68         expect_aliased 1 /etc//passwd &&
69         expect_aliased 1 /etc/./passwd &&
70         expect_aliased 1 //domain/data.txt
71 '
72
73 test_done