2010-01-03 05:38:06 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='test git-http-backend-noserver'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
|
|
|
|
|
|
|
|
run_backend() {
|
2010-01-03 05:43:59 +08:00
|
|
|
echo "$2" |
|
|
|
|
QUERY_STRING="${1#*\?}" \
|
2010-01-03 05:38:06 +08:00
|
|
|
GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
|
2010-01-03 05:43:59 +08:00
|
|
|
PATH_INFO="${1%%\?*}" \
|
2010-01-03 05:38:06 +08:00
|
|
|
git http-backend >act.out 2>act.err
|
|
|
|
}
|
|
|
|
|
|
|
|
GET() {
|
2010-01-15 14:44:02 +08:00
|
|
|
export REQUEST_METHOD="GET" &&
|
2010-01-03 05:43:59 +08:00
|
|
|
run_backend "/repo.git/$1" &&
|
2010-01-15 14:44:02 +08:00
|
|
|
unset REQUEST_METHOD &&
|
2010-01-03 05:43:59 +08:00
|
|
|
if ! grep "Status" act.out >act
|
|
|
|
then
|
|
|
|
printf "Status: 200 OK\r\n" >act
|
|
|
|
fi
|
|
|
|
printf "Status: $2\r\n" >exp &&
|
|
|
|
test_cmp exp act
|
2010-01-03 05:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
POST() {
|
2010-01-15 14:44:02 +08:00
|
|
|
export REQUEST_METHOD="POST" &&
|
|
|
|
export CONTENT_TYPE="application/x-$1-request" &&
|
2010-01-03 05:43:59 +08:00
|
|
|
run_backend "/repo.git/$1" "$2" &&
|
2010-01-15 14:44:02 +08:00
|
|
|
unset REQUEST_METHOD &&
|
|
|
|
unset CONTENT_TYPE &&
|
2010-01-03 05:43:59 +08:00
|
|
|
if ! grep "Status" act.out >act
|
|
|
|
then
|
|
|
|
printf "Status: 200 OK\r\n" >act
|
|
|
|
fi
|
|
|
|
printf "Status: $3\r\n" >exp &&
|
|
|
|
test_cmp exp act
|
2010-01-03 05:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log_div() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
. "$TEST_DIRECTORY"/t556x_common
|
|
|
|
|
|
|
|
expect_aliased() {
|
2010-01-15 14:44:02 +08:00
|
|
|
export REQUEST_METHOD="GET" &&
|
2010-01-03 05:38:06 +08:00
|
|
|
if test $1 = 0; then
|
2010-01-15 14:44:02 +08:00
|
|
|
run_backend "$2"
|
2010-01-03 05:38:06 +08:00
|
|
|
else
|
2010-01-15 14:44:02 +08:00
|
|
|
run_backend "$2" &&
|
2010-01-03 05:38:06 +08:00
|
|
|
echo "fatal: '$2': aliased" >exp.err &&
|
|
|
|
test_cmp exp.err act.err
|
|
|
|
fi
|
2010-01-15 14:44:02 +08:00
|
|
|
unset REQUEST_METHOD
|
2010-01-03 05:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'http-backend blocks bad PATH_INFO' '
|
|
|
|
config http.getanyfile true &&
|
|
|
|
|
|
|
|
expect_aliased 0 /repo.git/HEAD &&
|
|
|
|
|
|
|
|
expect_aliased 1 /repo.git/../HEAD &&
|
|
|
|
expect_aliased 1 /../etc/passwd &&
|
|
|
|
expect_aliased 1 ../etc/passwd &&
|
|
|
|
expect_aliased 1 /etc//passwd &&
|
|
|
|
expect_aliased 1 /etc/./passwd &&
|
|
|
|
expect_aliased 1 //domain/data.txt
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|