3 test_description='test smart fetching over http via http-backend'
5 . "$TEST_DIRECTORY"/lib-httpd.sh
8 test_expect_success 'setup repository' '
9 git config push.default matching &&
15 test_expect_success 'create http-accessible bare repository' '
16 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
17 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
20 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
21 git push public master:master
26 test_expect_success 'clone http repository' '
28 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
30 > Accept-Encoding: ENCODINGS
34 < Cache-Control: no-cache, max-age=0, must-revalidate
35 < Content-Type: application/x-git-upload-pack-advertisement
36 > POST /smart/repo.git/git-upload-pack HTTP/1.1
37 > Accept-Encoding: ENCODINGS
38 > Content-Type: application/x-git-upload-pack-request
39 > Accept: application/x-git-upload-pack-result
43 < Cache-Control: no-cache, max-age=0, must-revalidate
44 < Content-Type: application/x-git-upload-pack-result
46 GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 \
47 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
48 test_cmp file clone/file &&
49 tr '\''\015'\'' Q <err |
72 /^> Accept: [*]\\/[*]/d
74 s/^> Content-Length: .*/> Content-Length: xxx/
81 /^< Content-Length: /d
82 /^< Transfer-Encoding: /d
85 # NEEDSWORK: If the overspecification of the expected result is reduced, we
86 # might be able to run this test in all protocol versions.
87 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
89 sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
90 actual >actual.smudged &&
91 test_cmp exp actual.smudged &&
93 grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
94 test_line_count = 2 actual.gzip
98 test_expect_success 'fetch changes via http' '
99 echo content >>file &&
100 git commit -a -m two &&
102 (cd clone && git pull) &&
103 test_cmp file clone/file
106 test_expect_success 'used upload-pack service' '
108 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
109 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
110 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
111 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
114 # NEEDSWORK: If the overspecification of the expected result is reduced, we
115 # might be able to run this test in all protocol versions.
116 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
122 test_expect_success 'follow redirects (301)' '
123 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
126 test_expect_success 'follow redirects (302)' '
127 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
130 test_expect_success 'redirects re-root further requests' '
131 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
134 test_expect_success 're-rooting dies on insane schemes' '
135 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
138 test_expect_success 'clone from password-protected repository' '
140 set_askpass user@host pass@host &&
141 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
142 expect_askpass both user@host &&
143 git --git-dir=smart-auth log -1 --format=%s >actual &&
144 test_cmp expect actual
147 test_expect_success 'clone from auth-only-for-push repository' '
150 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
151 expect_askpass none &&
152 git --git-dir=smart-noauth log -1 --format=%s >actual &&
153 test_cmp expect actual
156 test_expect_success 'clone from auth-only-for-objects repository' '
158 set_askpass user@host pass@host &&
159 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
160 expect_askpass both user@host &&
161 git --git-dir=half-auth log -1 --format=%s >actual &&
162 test_cmp expect actual
165 test_expect_success 'no-op half-auth fetch does not require a password' '
168 # NEEDSWORK: When using HTTP(S), protocol v0 supports a "half-auth"
169 # configuration with authentication required only when downloading
170 # objects and not refs, by having the HTTP server only require
171 # authentication for the "git-upload-pack" path and not "info/refs".
172 # This is not possible with protocol v2, since both objects and refs
173 # are obtained from the "git-upload-pack" path. A solution to this is
174 # to teach the server and client to be able to inline ls-refs requests
175 # as an Extra Parameter (see pack-protocol.txt), so that "info/refs"
176 # can serve refs, just like it does in protocol v0.
177 GIT_TEST_PROTOCOL_VERSION=0 git --git-dir=half-auth fetch &&
181 test_expect_success 'redirects send auth to new location' '
182 set_askpass user@host pass@host &&
183 git -c credential.useHttpPath=true \
184 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
185 expect_askpass both user@host auth/smart/repo.git
188 test_expect_success 'GIT_TRACE_CURL redacts auth details' '
189 rm -rf redact-auth trace &&
190 set_askpass user@host pass@host &&
191 GIT_TRACE_CURL="$(pwd)/trace" git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
192 expect_askpass both user@host &&
194 # Ensure that there is no "Basic" followed by a base64 string, but that
195 # the auth details are redacted
196 ! grep "Authorization: Basic [0-9a-zA-Z+/]" trace &&
197 grep "Authorization: Basic <redacted>" trace
200 test_expect_success 'GIT_CURL_VERBOSE redacts auth details' '
201 rm -rf redact-auth trace &&
202 set_askpass user@host pass@host &&
203 GIT_CURL_VERBOSE=1 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth 2>trace &&
204 expect_askpass both user@host &&
206 # Ensure that there is no "Basic" followed by a base64 string, but that
207 # the auth details are redacted
208 ! grep "Authorization: Basic [0-9a-zA-Z+/]" trace &&
209 grep "Authorization: Basic <redacted>" trace
212 test_expect_success 'disable dumb http on server' '
213 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
214 config http.getanyfile false
217 test_expect_success 'GIT_SMART_HTTP can disable smart http' '
219 export GIT_SMART_HTTP &&
221 test_must_fail git fetch)
224 test_expect_success 'invalid Content-Type rejected' '
225 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
226 test_i18ngrep "not valid:" actual
229 test_expect_success 'create namespaced refs' '
230 test_commit namespaced &&
231 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
232 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
233 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
236 test_expect_success 'smart clone respects namespace' '
237 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
238 echo namespaced >expect &&
239 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
240 test_cmp expect actual
243 test_expect_success 'dumb clone via http-backend respects namespace' '
244 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
245 config http.getanyfile true &&
246 GIT_SMART_HTTP=0 git clone \
247 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
248 echo namespaced >expect &&
249 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
250 test_cmp expect actual
253 test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
254 cat >cookies.txt <<-\EOF &&
255 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
257 sort >expect_cookies.txt <<-\EOF &&
259 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
260 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
262 git config http.cookiefile cookies.txt &&
263 git config http.savecookies true &&
264 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
266 # NEEDSWORK: If the overspecification of the expected result is reduced, we
267 # might be able to run this test in all protocol versions.
268 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
270 tail -3 cookies.txt | sort >cookies_tail.txt &&
271 test_cmp expect_cookies.txt cookies_tail.txt
275 test_expect_success 'transfer.hiderefs works over smart-http' '
276 test_commit hidden &&
277 test_commit visible &&
278 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
279 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
280 config transfer.hiderefs refs/heads/a &&
281 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
282 test_must_fail git -C hidden.git rev-parse --verify a &&
283 git -C hidden.git rev-parse --verify b
286 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
289 for i in $(test_seq "$1" "$2")
291 # don't use here-doc, because it requires a process
293 echo "commit refs/heads/too-many-refs-$1" &&
295 echo "committer git <git@example.com> $i +0000" &&
297 echo "M 644 inline bla.txt" &&
300 # make every commit dangling by always
301 # rewinding the branch after each commit
302 echo "reset refs/heads/too-many-refs-$1" &&
304 done | git fast-import --export-marks=marks &&
306 # now assign tags to all the dangling commits we created above
307 tag=$(perl -e "print \"bla\" x 30") &&
308 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
311 test_expect_success 'create 2,000 tags in the repo' '
313 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
318 test_expect_success CMDLINE_LIMIT \
319 'clone the 2,000 tag repo to check OS command line overflow' '
320 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
323 git for-each-ref refs/tags >actual &&
324 test_line_count = 2000 actual
328 test_expect_success 'large fetch-pack requests can be sent using chunked encoding' '
329 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
330 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
331 grep "^=> Send header: Transfer-Encoding: chunked" err
334 test_expect_success 'test allowreachablesha1inwant' '
335 test_when_finished "rm -rf test_reachable.git" &&
336 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
337 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
338 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
340 git init --bare test_reachable.git &&
341 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
342 git -C test_reachable.git fetch origin "$master_sha"
345 test_expect_success 'test allowreachablesha1inwant with unreachable' '
346 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
348 #create unreachable sha
349 echo content >file2 &&
352 git push public HEAD:refs/heads/doomed &&
353 git push public :refs/heads/doomed &&
355 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
356 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
357 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
359 git init --bare test_reachable.git &&
360 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
361 # Some protocol versions (e.g. 2) support fetching
362 # unadvertised objects, so restrict this test to v0.
363 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
364 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
367 test_expect_success 'test allowanysha1inwant with unreachable' '
368 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
370 #create unreachable sha
371 echo content >file2 &&
374 git push public HEAD:refs/heads/doomed &&
375 git push public :refs/heads/doomed &&
377 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
378 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
379 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
381 git init --bare test_reachable.git &&
382 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
383 # Some protocol versions (e.g. 2) support fetching
384 # unadvertised objects, so restrict this test to v0.
385 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
386 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
388 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
389 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
392 test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
394 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
395 create_tags 2001 50000
397 git -C too-many-refs fetch -q --tags &&
399 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
400 create_tags 50001 100000
402 git -C too-many-refs fetch -q --tags &&
403 git -C too-many-refs for-each-ref refs/tags >tags &&
404 test_line_count = 100000 tags
407 test_expect_success 'custom http headers' '
408 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
409 fetch "$HTTPD_URL/smart_headers/repo.git" &&
410 git -c http.extraheader="x-magic-one: abra" \
411 -c http.extraheader="x-magic-two: cadabra" \
412 fetch "$HTTPD_URL/smart_headers/repo.git" &&
413 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
414 git config -f .gitmodules submodule.sub.path sub &&
415 git config -f .gitmodules submodule.sub.url \
416 "$HTTPD_URL/smart_headers/repo.git" &&
417 git submodule init sub &&
418 test_must_fail git submodule update sub &&
419 git -c http.extraheader="x-magic-one: abra" \
420 -c http.extraheader="x-magic-two: cadabra" \
424 test_expect_success 'using fetch command in remote-curl updates refs' '
425 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/twobranch" &&
426 rm -rf "$SERVER" client &&
428 git init "$SERVER" &&
429 test_commit -C "$SERVER" foo &&
430 git -C "$SERVER" update-ref refs/heads/anotherbranch foo &&
432 git clone $HTTPD_URL/smart/twobranch client &&
434 test_commit -C "$SERVER" bar &&
435 git -C client -c protocol.version=0 fetch &&
437 git -C "$SERVER" rev-parse master >expect &&
438 git -C client rev-parse origin/master >actual &&
439 test_cmp expect actual
442 test_expect_success 'fetch by SHA-1 without tag following' '
443 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
444 rm -rf "$SERVER" client &&
446 git init "$SERVER" &&
447 test_commit -C "$SERVER" foo &&
449 git clone $HTTPD_URL/smart/server client &&
451 test_commit -C "$SERVER" bar &&
452 git -C "$SERVER" rev-parse bar >bar_hash &&
453 git -C client -c protocol.version=0 fetch \
454 --no-tags origin $(cat bar_hash)
457 test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
459 echo "Set-Cookie: Foo=1" >cookies &&
460 echo "Set-Cookie: Bar=2" >>cookies &&
461 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Bar,Baz \
462 git -c "http.cookieFile=$(pwd)/cookies" clone \
463 $HTTPD_URL/smart/repo.git clone 2>err &&
464 grep "Cookie:.*Foo=1" err &&
465 grep "Cookie:.*Bar=<redacted>" err &&
466 ! grep "Cookie:.*Bar=2" err
469 test_expect_success 'GIT_REDACT_COOKIES redacts cookies when GIT_CURL_VERBOSE=1' '
471 echo "Set-Cookie: Foo=1" >cookies &&
472 echo "Set-Cookie: Bar=2" >>cookies &&
473 GIT_CURL_VERBOSE=1 GIT_REDACT_COOKIES=Bar,Baz \
474 git -c "http.cookieFile=$(pwd)/cookies" clone \
475 $HTTPD_URL/smart/repo.git clone 2>err &&
476 grep "Cookie:.*Foo=1" err &&
477 grep "Cookie:.*Bar=<redacted>" err &&
478 ! grep "Cookie:.*Bar=2" err
481 test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
483 echo "Set-Cookie: Foo=" >cookies &&
484 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Foo \
485 git -c "http.cookieFile=$(pwd)/cookies" clone \
486 $HTTPD_URL/smart/repo.git clone 2>err &&
487 grep "Cookie:.*Foo=<redacted>" err
490 test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
492 GIT_TRACE_CURL=true \
493 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
494 grep "=> Send data" err &&
497 GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
498 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
499 ! grep "=> Send data" err
502 test_expect_success 'server-side error detected' '
503 test_must_fail git clone $HTTPD_URL/error_smart/repo.git 2>actual &&
504 test_i18ngrep "server-side error" actual