1#!/bin/sh
23
test_description='test git-http-backend-noserver'
4. ./test-lib.sh
56
HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
78
if test_have_prereq GREP_STRIPS_CR
9then
10GREP_OPTIONS=-U
11export GREP_OPTIONS
12fi
1314
run_backend() {
15echo "$2" |
16QUERY_STRING="${1#*[?]}" \
17PATH_TRANSLATED="$HTTPD_DOCUMENT_ROOT_PATH/${1%%[?]*}" \
18git http-backend >act.out 2>act.err
19}
2021
GET() {
22REQUEST_METHOD="GET" && export REQUEST_METHOD &&
23run_backend "/repo.git/$1" &&
24sane_unset REQUEST_METHOD &&
25if ! grep "Status" act.out >act
26then
27printf "Status: 200 OK\r\n" >act
28fi
29printf "Status: $2\r\n" >exp &&
30test_cmp exp act
31}
3233
POST() {
34REQUEST_METHOD="POST" && export REQUEST_METHOD &&
35CONTENT_TYPE="application/x-$1-request" && export CONTENT_TYPE &&
36run_backend "/repo.git/$1" "$2" &&
37sane_unset REQUEST_METHOD &&
38sane_unset CONTENT_TYPE &&
39if ! grep "Status" act.out >act
40then
41printf "Status: 200 OK\r\n" >act
42fi
43printf "Status: $3\r\n" >exp &&
44test_cmp exp act
45}
4647
log_div() {
48return 0
49}
5051
. "$TEST_DIRECTORY"/t556x_common
5253
expect_aliased() {
54REQUEST_METHOD="GET" && export REQUEST_METHOD &&
55if test $1 = 0; then
56run_backend "$2"
57else
58run_backend "$2" &&
59echo "fatal: '$2': aliased" >exp.err &&
60test_cmp exp.err act.err
61fi
62unset REQUEST_METHOD
63}
6465
test_expect_success 'http-backend blocks bad PATH_INFO' '
66config http.getanyfile true &&
6768
expect_aliased 0 /repo.git/HEAD &&
6970
expect_aliased 1 /repo.git/../HEAD &&
71expect_aliased 1 /../etc/passwd &&
72expect_aliased 1 ../etc/passwd &&
73expect_aliased 1 /etc//passwd &&
74expect_aliased 1 /etc/./passwd &&
75expect_aliased 1 //domain/data.txt
76'
7778
test_done