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" &&
95 test_expect_success
'direct refs/heads/master not found' '
96 log_div "refs/heads/master"
97 GET refs/heads/master "404 Not Found"
99 test_expect_success
'static file is ok' '
100 log_div "getanyfile default"
101 get_static_files "200 OK"
104 test_expect_success
'no export by default' '
105 log_div "no git-daemon-export-ok"
106 get_static_files "404 Not Found"
108 test_expect_success
'export if git-daemon-export-ok' '
109 log_div "git-daemon-export-ok"
110 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
111 touch git-daemon-export-ok
113 get_static_files "200 OK"
116 test_expect_success
'static file if http.getanyfile true is ok' '
117 log_div "getanyfile true"
118 config http.getanyfile true &&
119 get_static_files "200 OK"
121 test_expect_success
'static file if http.getanyfile false fails' '
122 log_div "getanyfile false"
123 config http.getanyfile false &&
124 get_static_files "403 Forbidden"
127 test_expect_success
'http.uploadpack default enabled' '
128 log_div "uploadpack default"
129 GET info/refs?service=git-upload-pack "200 OK" &&
130 POST git-upload-pack 0000 "200 OK"
132 test_expect_success
'http.uploadpack true' '
133 log_div "uploadpack true"
134 config http.uploadpack true &&
135 GET info/refs?service=git-upload-pack "200 OK" &&
136 POST git-upload-pack 0000 "200 OK"
138 test_expect_success
'http.uploadpack false' '
139 log_div "uploadpack false"
140 config http.uploadpack false &&
141 GET info/refs?service=git-upload-pack "403 Forbidden" &&
142 POST git-upload-pack 0000 "403 Forbidden"
145 test_expect_success
'http.receivepack default disabled' '
146 log_div "receivepack default"
147 GET info/refs?service=git-receive-pack "403 Forbidden" &&
148 POST git-receive-pack 0000 "403 Forbidden"
150 test_expect_success
'http.receivepack true' '
151 log_div "receivepack true"
152 config http.receivepack true &&
153 GET info/refs?service=git-receive-pack "200 OK" &&
154 POST git-receive-pack 0000 "200 OK"
156 test_expect_success
'http.receivepack false' '
157 log_div "receivepack false"
158 config http.receivepack false &&
159 GET info/refs?service=git-receive-pack "403 Forbidden" &&
160 POST git-receive-pack 0000 "403 Forbidden"
164 GIT_PROJECT_ROOT
="$HTTPD_DOCUMENT_ROOT_PATH" \
166 git http-backend
>act.out
2>act.err
174 echo "fatal: '$2': aliased" >exp.err
&&
175 test_cmp exp.err act.err
179 test_expect_success
'http-backend blocks bad PATH_INFO' '
180 config http.getanyfile true &&
182 expect_aliased 0 /repo.git/HEAD &&
184 expect_aliased 1 /repo.git/../HEAD &&
185 expect_aliased 1 /../etc/passwd &&
186 expect_aliased 1 ../etc/passwd &&
187 expect_aliased 1 /etc//passwd &&
188 expect_aliased 1 /etc/./passwd &&
189 expect_aliased 1 //domain/data.txt
194 ### refs/heads/master
196 GET /smart/repo.git/refs/heads/master HTTP/1.1 404 -
198 ### getanyfile default
200 GET /smart/repo.git/HEAD HTTP/1.1 200
201 GET /smart/repo.git/info/refs HTTP/1.1 200
202 GET /smart/repo.git/objects/info/packs HTTP/1.1 200
203 GET /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
204 GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
205 GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
206 GET /smart/repo.git/$PACK_URL HTTP/1.1 200
207 GET /smart/repo.git/$IDX_URL HTTP/1.1 200
209 ### no git-daemon-export-ok
211 GET /smart_noexport/repo.git/HEAD HTTP/1.1 404 -
212 GET /smart_noexport/repo.git/info/refs HTTP/1.1 404 -
213 GET /smart_noexport/repo.git/objects/info/packs HTTP/1.1 404 -
214 GET /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 404 -
215 GET /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 404 -
216 GET /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 404 -
217 GET /smart_noexport/repo.git/$PACK_URL HTTP/1.1 404 -
218 GET /smart_noexport/repo.git/$IDX_URL HTTP/1.1 404 -
220 ### git-daemon-export-ok
222 GET /smart_noexport/repo.git/HEAD HTTP/1.1 200
223 GET /smart_noexport/repo.git/info/refs HTTP/1.1 200
224 GET /smart_noexport/repo.git/objects/info/packs HTTP/1.1 200
225 GET /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 200 -
226 GET /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 200 -
227 GET /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 200
228 GET /smart_noexport/repo.git/$PACK_URL HTTP/1.1 200
229 GET /smart_noexport/repo.git/$IDX_URL HTTP/1.1 200
233 GET /smart/repo.git/HEAD HTTP/1.1 200
234 GET /smart/repo.git/info/refs HTTP/1.1 200
235 GET /smart/repo.git/objects/info/packs HTTP/1.1 200
236 GET /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
237 GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
238 GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
239 GET /smart/repo.git/$PACK_URL HTTP/1.1 200
240 GET /smart/repo.git/$IDX_URL HTTP/1.1 200
244 GET /smart/repo.git/HEAD HTTP/1.1 403 -
245 GET /smart/repo.git/info/refs HTTP/1.1 403 -
246 GET /smart/repo.git/objects/info/packs HTTP/1.1 403 -
247 GET /smart/repo.git/objects/info/alternates HTTP/1.1 403 -
248 GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 403 -
249 GET /smart/repo.git/$LOOSE_URL HTTP/1.1 403 -
250 GET /smart/repo.git/$PACK_URL HTTP/1.1 403 -
251 GET /smart/repo.git/$IDX_URL HTTP/1.1 403 -
253 ### uploadpack default
255 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
256 POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
260 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
261 POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
265 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 403 -
266 POST /smart/repo.git/git-upload-pack HTTP/1.1 403 -
268 ### receivepack default
270 GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
271 POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
275 GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
276 POST /smart/repo.git/git-receive-pack HTTP/1.1 200 -
278 ### receivepack false
280 GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
281 POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
283 test_expect_success
'server request log matches test results' '
289 " >act <"$HTTPD_ROOT_PATH"/access.log &&