From 04481adffe7d4d969d7067d7a6d6e5e46e44f1c8 Mon Sep 17 00:00:00 2001 From: Tarmigan Casebolt Date: Sat, 2 Jan 2010 13:38:06 -0800 Subject: Smart-http tests: Break test t5560-http-backend into pieces This should introduce no functional change in the tests or the amount of test coverage. Acked-by: Shawn O. Pearce Signed-off-by: Tarmigan Casebolt Signed-off-by: Junio C Hamano --- t/t5560-http-backend-noserver.sh | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 t/t5560-http-backend-noserver.sh (limited to 't/t5560-http-backend-noserver.sh') diff --git a/t/t5560-http-backend-noserver.sh b/t/t5560-http-backend-noserver.sh new file mode 100755 index 0000000000..a9ba2d9aae --- /dev/null +++ b/t/t5560-http-backend-noserver.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +test_description='test git-http-backend-noserver' +. ./test-lib.sh + +HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY" + +run_backend() { + REQUEST_METHOD=GET \ + GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \ + PATH_INFO="$1" \ + git http-backend >act.out 2>act.err +} + +GET() { + return 0 +} + +POST() { + return 0 +} + +log_div() { + return 0 +} + +. "$TEST_DIRECTORY"/t556x_common + +expect_aliased() { + if test $1 = 0; then + run_backend "$2" + else + run_backend "$2" && + echo "fatal: '$2': aliased" >exp.err && + test_cmp exp.err act.err + fi +} + +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 -- cgit v1.2.3 From fd0a8c2e6428acb883bf4707de54b3e026c57455 Mon Sep 17 00:00:00 2001 From: Tarmigan Casebolt Date: Sat, 2 Jan 2010 13:43:59 -0800 Subject: Smart-http tests: Test http-backend without curl or a webserver This reuses many of the tests from the old t5560 but runs those tests without curl or a webserver. This will hopefully increase the testing coverage for http-backend because it does not require users to set GIT_TEST_HTTPD. Signed-off-by: Tarmigan Casebolt Signed-off-by: Junio C Hamano --- t/t5560-http-backend-noserver.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 't/t5560-http-backend-noserver.sh') diff --git a/t/t5560-http-backend-noserver.sh b/t/t5560-http-backend-noserver.sh index a9ba2d9aae..5f8c88e261 100755 --- a/t/t5560-http-backend-noserver.sh +++ b/t/t5560-http-backend-noserver.sh @@ -6,18 +6,34 @@ test_description='test git-http-backend-noserver' HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY" run_backend() { - REQUEST_METHOD=GET \ + echo "$2" | + QUERY_STRING="${1#*\?}" \ GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \ - PATH_INFO="$1" \ + PATH_INFO="${1%%\?*}" \ git http-backend >act.out 2>act.err } GET() { - return 0 + REQUEST_METHOD="GET" \ + run_backend "/repo.git/$1" && + 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 } POST() { - return 0 + REQUEST_METHOD="POST" \ + CONTENT_TYPE="application/x-$1-request" \ + run_backend "/repo.git/$1" "$2" && + 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 } log_div() { @@ -28,9 +44,9 @@ log_div() { expect_aliased() { if test $1 = 0; then - run_backend "$2" + REQUEST_METHOD=GET run_backend "$2" else - run_backend "$2" && + REQUEST_METHOD=GET run_backend "$2" && echo "fatal: '$2': aliased" >exp.err && test_cmp exp.err act.err fi -- cgit v1.2.3 From e8189ee90e65094dd46a9e4ee6455d9efa90fa76 Mon Sep 17 00:00:00 2001 From: Tarmigan Casebolt Date: Thu, 14 Jan 2010 22:44:02 -0800 Subject: Test t5560: Fix test when run with dash A command invocation preceded by variable assignments, i.e. VAR1=VAL1 VAR2=VAL2 ... command args are implemented by dash and ksh in such a way not to export these variables, and keep the values after the command finishes, when the command is a shell function. POSIX.1 "2.9.5 Function Definition Command" specifies this behaviour. Many shells however treat this construct the same way as they are calling external commands. They export the variables during the duration of command, and resets their values after command returns. The test relied on the behaviour of the latter kind. Reported-by: Michael Haggerty Signed-off-by: Tarmigan Casebolt Signed-off-by: Junio C Hamano --- t/t5560-http-backend-noserver.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 't/t5560-http-backend-noserver.sh') diff --git a/t/t5560-http-backend-noserver.sh b/t/t5560-http-backend-noserver.sh index 5f8c88e261..44885b850c 100755 --- a/t/t5560-http-backend-noserver.sh +++ b/t/t5560-http-backend-noserver.sh @@ -14,8 +14,9 @@ run_backend() { } GET() { - REQUEST_METHOD="GET" \ + export REQUEST_METHOD="GET" && run_backend "/repo.git/$1" && + unset REQUEST_METHOD && if ! grep "Status" act.out >act then printf "Status: 200 OK\r\n" >act @@ -25,9 +26,11 @@ GET() { } POST() { - REQUEST_METHOD="POST" \ - CONTENT_TYPE="application/x-$1-request" \ + export REQUEST_METHOD="POST" && + export CONTENT_TYPE="application/x-$1-request" && run_backend "/repo.git/$1" "$2" && + unset REQUEST_METHOD && + unset CONTENT_TYPE && if ! grep "Status" act.out >act then printf "Status: 200 OK\r\n" >act @@ -43,13 +46,15 @@ log_div() { . "$TEST_DIRECTORY"/t556x_common expect_aliased() { + export REQUEST_METHOD="GET" && if test $1 = 0; then - REQUEST_METHOD=GET run_backend "$2" + run_backend "$2" else - REQUEST_METHOD=GET run_backend "$2" && + run_backend "$2" && echo "fatal: '$2': aliased" >exp.err && test_cmp exp.err act.err fi + unset REQUEST_METHOD } test_expect_success 'http-backend blocks bad PATH_INFO' ' -- cgit v1.2.3