3 test_description
='test git-http-backend'
6 if test -n "$NO_CURL"; then
7 say
'skipping test, git built without http support'
11 LIB_HTTPD_PORT
=${LIB_HTTPD_PORT-'5560'}
12 .
"$TEST_DIRECTORY"/lib-httpd.sh
16 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
22 git
--git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" config
$1 $2
26 curl
--include "$HTTPD_URL/smart/repo.git/$1" >out
2>/dev
/null
&&
32 echo "HTTP/1.1 $2" >exp
&&
37 curl
--include --data "$2" \
38 --header "Content-Type: application/x-$1-request" \
39 "$HTTPD_URL/smart/repo.git/$1" >out
2>/dev
/null
&&
45 echo "HTTP/1.1 $3" >exp
&&
50 echo >>"$HTTPD_ROOT_PATH"/access.log
51 echo "### $1" >>"$HTTPD_ROOT_PATH"/access.log
52 echo "###" >>"$HTTPD_ROOT_PATH"/access.log
55 test_expect_success
'setup repository' '
60 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
61 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
63 : >objects/info/alternates &&
64 : >objects/info/http-alternates
66 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
67 git push public master:master &&
69 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
76 git push public master:master &&
78 LOOSE_URL=$(find_file objects/??) &&
79 PACK_URL=$(find_file objects/pack/*.pack) &&
80 IDX_URL=$(find_file objects/pack/*.idx)
86 GET objects
/info
/packs
"$1" &&
87 GET objects
/info
/alternates
"$1" &&
88 GET objects
/info
/http-alternates
"$1" &&
89 GET
$LOOSE_URL "$1" &&
94 test_expect_success
'direct refs/heads/master not found' '
95 log_div "refs/heads/master"
96 GET refs/heads/master "404 Not Found"
98 test_expect_success
'static file is ok' '
99 log_div "getanyfile default"
100 get_static_files "200 OK"
102 test_expect_success
'static file if http.getanyfile true is ok' '
103 log_div "getanyfile true"
104 config http.getanyfile true &&
105 get_static_files "200 OK"
107 test_expect_success
'static file if http.getanyfile false fails' '
108 log_div "getanyfile false"
109 config http.getanyfile false &&
110 get_static_files "403 Forbidden"
113 test_expect_success
'http.uploadpack default enabled' '
114 log_div "uploadpack default"
115 GET info/refs?service=git-upload-pack "200 OK" &&
116 POST git-upload-pack 0000 "200 OK"
118 test_expect_success
'http.uploadpack true' '
119 log_div "uploadpack true"
120 config http.uploadpack true &&
121 GET info/refs?service=git-upload-pack "200 OK" &&
122 POST git-upload-pack 0000 "200 OK"
124 test_expect_success
'http.uploadpack false' '
125 log_div "uploadpack false"
126 config http.uploadpack false &&
127 GET info/refs?service=git-upload-pack "403 Forbidden" &&
128 POST git-upload-pack 0000 "403 Forbidden"
131 test_expect_success
'http.receivepack default disabled' '
132 log_div "receivepack default"
133 GET info/refs?service=git-receive-pack "403 Forbidden" &&
134 POST git-receive-pack 0000 "403 Forbidden"
136 test_expect_success
'http.receivepack true' '
137 log_div "receivepack true"
138 config http.receivepack true &&
139 GET info/refs?service=git-receive-pack "200 OK" &&
140 POST git-receive-pack 0000 "200 OK"
142 test_expect_success
'http.receivepack false' '
143 log_div "receivepack false"
144 config http.receivepack false &&
145 GET info/refs?service=git-receive-pack "403 Forbidden" &&
146 POST git-receive-pack 0000 "403 Forbidden"
151 GIT_PROJECT_ROOT
="$HTTPD_DOCUMENT_ROOT_PATH" \
153 git http-backend
>act.out
2>act.err
160 test_must_fail run_backend
"$2" &&
161 echo "fatal: '$2': aliased" >exp.err
&&
162 test_cmp exp.err act.err
166 test_expect_success
'http-backend blocks bad PATH_INFO' '
167 config http.getanyfile true &&
169 run_backend 0 /repo.git/HEAD &&
171 run_backend 1 /repo.git/../HEAD &&
172 run_backend 1 /../etc/passwd &&
173 run_backend 1 ../etc/passwd &&
174 run_backend 1 /etc//passwd &&
175 run_backend 1 /etc/./passwd &&
176 run_backend 1 /etc/.../passwd &&
177 run_backend 1 //domain/data.txt
182 ### refs/heads/master
184 GET /smart/repo.git/refs/heads/master HTTP/1.1 404 -
186 ### getanyfile default
188 GET /smart/repo.git/HEAD HTTP/1.1 200
189 GET /smart/repo.git/info/refs HTTP/1.1 200
190 GET /smart/repo.git/objects/info/packs HTTP/1.1 200
191 GET /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
192 GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
193 GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
194 GET /smart/repo.git/$PACK_URL HTTP/1.1 200
195 GET /smart/repo.git/$IDX_URL HTTP/1.1 200
199 GET /smart/repo.git/HEAD HTTP/1.1 200
200 GET /smart/repo.git/info/refs HTTP/1.1 200
201 GET /smart/repo.git/objects/info/packs HTTP/1.1 200
202 GET /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
203 GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
204 GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
205 GET /smart/repo.git/$PACK_URL HTTP/1.1 200
206 GET /smart/repo.git/$IDX_URL HTTP/1.1 200
210 GET /smart/repo.git/HEAD HTTP/1.1 403 -
211 GET /smart/repo.git/info/refs HTTP/1.1 403 -
212 GET /smart/repo.git/objects/info/packs HTTP/1.1 403 -
213 GET /smart/repo.git/objects/info/alternates HTTP/1.1 403 -
214 GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 403 -
215 GET /smart/repo.git/$LOOSE_URL HTTP/1.1 403 -
216 GET /smart/repo.git/$PACK_URL HTTP/1.1 403 -
217 GET /smart/repo.git/$IDX_URL HTTP/1.1 403 -
219 ### uploadpack default
221 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
222 POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
226 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
227 POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
231 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 403 -
232 POST /smart/repo.git/git-upload-pack HTTP/1.1 403 -
234 ### receivepack default
236 GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
237 POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
241 GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
242 POST /smart/repo.git/git-receive-pack HTTP/1.1 200 -
244 ### receivepack false
246 GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
247 POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
249 test_expect_success
'server request log matches test results' '
255 " >act <"$HTTPD_ROOT_PATH"/access.log &&