]>
Commit | Line | Data |
---|---|---|
04481adf TC |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git-http-backend-noserver' | |
028cb644 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
04481adf TC |
7 | . ./test-lib.sh |
8 | ||
9 | HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY" | |
10 | ||
c1cebcf4 JH |
11 | if test_have_prereq GREP_STRIPS_CR |
12 | then | |
13 | GREP_OPTIONS=-U | |
14 | export GREP_OPTIONS | |
15 | fi | |
a94114ad | 16 | |
04481adf | 17 | run_backend() { |
fd0a8c2e | 18 | echo "$2" | |
ff7a1c67 KM |
19 | QUERY_STRING="${1#*[?]}" \ |
20 | PATH_TRANSLATED="$HTTPD_DOCUMENT_ROOT_PATH/${1%%[?]*}" \ | |
04481adf TC |
21 | git http-backend >act.out 2>act.err |
22 | } | |
23 | ||
24 | GET() { | |
69ae92bd | 25 | REQUEST_METHOD="GET" && export REQUEST_METHOD && |
fd0a8c2e | 26 | run_backend "/repo.git/$1" && |
1f5ad6b1 | 27 | sane_unset REQUEST_METHOD && |
fd0a8c2e TC |
28 | if ! grep "Status" act.out >act |
29 | then | |
30 | printf "Status: 200 OK\r\n" >act | |
31 | fi | |
32 | printf "Status: $2\r\n" >exp && | |
33 | test_cmp exp act | |
04481adf TC |
34 | } |
35 | ||
36 | POST() { | |
69ae92bd JH |
37 | REQUEST_METHOD="POST" && export REQUEST_METHOD && |
38 | CONTENT_TYPE="application/x-$1-request" && export CONTENT_TYPE && | |
fd0a8c2e | 39 | run_backend "/repo.git/$1" "$2" && |
1f5ad6b1 ÆAB |
40 | sane_unset REQUEST_METHOD && |
41 | sane_unset CONTENT_TYPE && | |
fd0a8c2e TC |
42 | if ! grep "Status" act.out >act |
43 | then | |
44 | printf "Status: 200 OK\r\n" >act | |
45 | fi | |
46 | printf "Status: $3\r\n" >exp && | |
47 | test_cmp exp act | |
04481adf TC |
48 | } |
49 | ||
04481adf TC |
50 | . "$TEST_DIRECTORY"/t556x_common |
51 | ||
52 | expect_aliased() { | |
69ae92bd | 53 | REQUEST_METHOD="GET" && export REQUEST_METHOD && |
04481adf | 54 | if test $1 = 0; then |
e8189ee9 | 55 | run_backend "$2" |
04481adf | 56 | else |
e8189ee9 | 57 | run_backend "$2" && |
04481adf TC |
58 | echo "fatal: '$2': aliased" >exp.err && |
59 | test_cmp exp.err act.err | |
60 | fi | |
e8189ee9 | 61 | unset REQUEST_METHOD |
04481adf TC |
62 | } |
63 | ||
64 | test_expect_success 'http-backend blocks bad PATH_INFO' ' | |
65 | config http.getanyfile true && | |
66 | ||
67 | expect_aliased 0 /repo.git/HEAD && | |
68 | ||
69 | expect_aliased 1 /repo.git/../HEAD && | |
70 | expect_aliased 1 /../etc/passwd && | |
71 | expect_aliased 1 ../etc/passwd && | |
72 | expect_aliased 1 /etc//passwd && | |
73 | expect_aliased 1 /etc/./passwd && | |
74 | expect_aliased 1 //domain/data.txt | |
75 | ' | |
76 | ||
77 | test_done |