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 clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
47 test_cmp file clone/file &&
48 tr '\''\015'\'' Q <err |
71 /^> Accept: [*]\\/[*]/d
73 s/^> Content-Length: .*/> Content-Length: xxx/
80 /^< Content-Length: /d
81 /^< Transfer-Encoding: /d
83 sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
84 actual >actual.smudged &&
85 test_cmp exp actual.smudged &&
87 grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
88 test_line_count = 2 actual.gzip
91 test_expect_success
'fetch changes via http' '
92 echo content >>file &&
93 git commit -a -m two &&
95 (cd clone && git pull) &&
96 test_cmp file clone/file
99 test_expect_success
'used upload-pack service' '
101 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
102 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
103 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
104 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
109 test_expect_success
'follow redirects (301)' '
110 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
113 test_expect_success
'follow redirects (302)' '
114 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
117 test_expect_success
'redirects re-root further requests' '
118 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
121 test_expect_success
're-rooting dies on insane schemes' '
122 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
125 test_expect_success
'clone from password-protected repository' '
127 set_askpass user@host pass@host &&
128 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
129 expect_askpass both user@host &&
130 git --git-dir=smart-auth log -1 --format=%s >actual &&
131 test_cmp expect actual
134 test_expect_success
'clone from auth-only-for-push repository' '
137 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
138 expect_askpass none &&
139 git --git-dir=smart-noauth log -1 --format=%s >actual &&
140 test_cmp expect actual
143 test_expect_success
'clone from auth-only-for-objects repository' '
145 set_askpass user@host pass@host &&
146 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
147 expect_askpass both user@host &&
148 git --git-dir=half-auth log -1 --format=%s >actual &&
149 test_cmp expect actual
152 test_expect_success
'no-op half-auth fetch does not require a password' '
154 git --git-dir=half-auth fetch &&
158 test_expect_success
'redirects send auth to new location' '
159 set_askpass user@host pass@host &&
160 git -c credential.useHttpPath=true \
161 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
162 expect_askpass both user@host auth/smart/repo.git
165 test_expect_success
'disable dumb http on server' '
166 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
167 config http.getanyfile false
170 test_expect_success
'GIT_SMART_HTTP can disable smart http' '
172 export GIT_SMART_HTTP &&
174 test_must_fail git fetch)
177 test_expect_success
'invalid Content-Type rejected' '
178 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
179 grep "not valid:" actual
182 test_expect_success
'create namespaced refs' '
183 test_commit namespaced &&
184 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
185 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
186 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
189 test_expect_success
'smart clone respects namespace' '
190 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
191 echo namespaced >expect &&
192 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
193 test_cmp expect actual
196 test_expect_success
'dumb clone via http-backend respects namespace' '
197 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
198 config http.getanyfile true &&
199 GIT_SMART_HTTP=0 git clone \
200 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
201 echo namespaced >expect &&
202 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
203 test_cmp expect actual
206 test_expect_success
'cookies stored in http.cookiefile when http.savecookies set' '
207 cat >cookies.txt <<-\EOF &&
208 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
210 sort >expect_cookies.txt <<-\EOF &&
212 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
213 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
215 git config http.cookiefile cookies.txt &&
216 git config http.savecookies true &&
217 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
218 tail -3 cookies.txt | sort >cookies_tail.txt &&
219 test_cmp expect_cookies.txt cookies_tail.txt
222 test_expect_success
'transfer.hiderefs works over smart-http' '
223 test_commit hidden &&
224 test_commit visible &&
225 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
226 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
227 config transfer.hiderefs refs/heads/a &&
228 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
229 test_must_fail git -C hidden.git rev-parse --verify a &&
230 git -C hidden.git rev-parse --verify b
233 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
236 for i
in $
(test_seq
"$1" "$2")
238 # don't use here-doc, because it requires a process
240 echo "commit refs/heads/too-many-refs-$1" &&
242 echo "committer git <git@example.com> $i +0000" &&
244 echo "M 644 inline bla.txt" &&
247 # make every commit dangling by always
248 # rewinding the branch after each commit
249 echo "reset refs/heads/too-many-refs-$1" &&
251 done | git fast-import
--export-marks=marks
&&
253 # now assign tags to all the dangling commits we created above
254 tag
=$
(perl
-e "print \"bla\" x 30") &&
255 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks
>>packed-refs
258 test_expect_success
'create 2,000 tags in the repo' '
260 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
265 test_expect_success CMDLINE_LIMIT \
266 'clone the 2,000 tag repo to check OS command line overflow' '
267 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
270 git for-each-ref refs/tags >actual &&
271 test_line_count = 2000 actual
275 test_expect_success
'large fetch-pack requests can be split across POSTs' '
276 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
277 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
278 grep "^=> Send header: POST" err >posts &&
279 test_line_count = 2 posts
282 test_expect_success
'test allowreachablesha1inwant' '
283 test_when_finished "rm -rf test_reachable.git" &&
284 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
285 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
286 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
288 git init --bare test_reachable.git &&
289 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
290 git -C test_reachable.git fetch origin "$master_sha"
293 test_expect_success
'test allowreachablesha1inwant with unreachable' '
294 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
296 #create unreachable sha
297 echo content >file2 &&
300 git push public HEAD:refs/heads/doomed &&
301 git push public :refs/heads/doomed &&
303 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
304 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
305 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
307 git init --bare test_reachable.git &&
308 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
309 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
312 test_expect_success
'test allowanysha1inwant with unreachable' '
313 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
315 #create unreachable sha
316 echo content >file2 &&
319 git push public HEAD:refs/heads/doomed &&
320 git push public :refs/heads/doomed &&
322 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
323 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
324 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
326 git init --bare test_reachable.git &&
327 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
328 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
330 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
331 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
334 test_expect_success EXPENSIVE
'http can handle enormous ref negotiation' '
336 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
337 create_tags 2001 50000
339 git -C too-many-refs fetch -q --tags &&
341 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
342 create_tags 50001 100000
344 git -C too-many-refs fetch -q --tags &&
345 git -C too-many-refs for-each-ref refs/tags >tags &&
346 test_line_count = 100000 tags
349 test_expect_success
'custom http headers' '
350 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
351 fetch "$HTTPD_URL/smart_headers/repo.git" &&
352 git -c http.extraheader="x-magic-one: abra" \
353 -c http.extraheader="x-magic-two: cadabra" \
354 fetch "$HTTPD_URL/smart_headers/repo.git" &&
355 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
356 git config -f .gitmodules submodule.sub.path sub &&
357 git config -f .gitmodules submodule.sub.url \
358 "$HTTPD_URL/smart_headers/repo.git" &&
359 git submodule init sub &&
360 test_must_fail git submodule update sub &&
361 git -c http.extraheader="x-magic-one: abra" \
362 -c http.extraheader="x-magic-two: cadabra" \
366 test_expect_success
'using fetch command in remote-curl updates refs' '
367 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/twobranch" &&
368 rm -rf "$SERVER" client &&
370 git init "$SERVER" &&
371 test_commit -C "$SERVER" foo &&
372 git -C "$SERVER" update-ref refs/heads/anotherbranch foo &&
374 git clone $HTTPD_URL/smart/twobranch client &&
376 test_commit -C "$SERVER" bar &&
377 git -C client -c protocol.version=0 fetch &&
379 git -C "$SERVER" rev-parse master >expect &&
380 git -C client rev-parse origin/master >actual &&
381 test_cmp expect actual
384 test_expect_success
'fetch by SHA-1 without tag following' '
385 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
386 rm -rf "$SERVER" client &&
388 git init "$SERVER" &&
389 test_commit -C "$SERVER" foo &&
391 git clone $HTTPD_URL/smart/server client &&
393 test_commit -C "$SERVER" bar &&
394 git -C "$SERVER" rev-parse bar >bar_hash &&
395 git -C client -c protocol.version=0 fetch \
396 --no-tags origin $(cat bar_hash)
399 test_expect_success
'GIT_REDACT_COOKIES redacts cookies' '
401 echo "Set-Cookie: Foo=1" >cookies &&
402 echo "Set-Cookie: Bar=2" >>cookies &&
403 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Bar,Baz \
404 git -c "http.cookieFile=$(pwd)/cookies" clone \
405 $HTTPD_URL/smart/repo.git clone 2>err &&
406 grep "Cookie:.*Foo=1" err &&
407 grep "Cookie:.*Bar=<redacted>" err &&
408 ! grep "Cookie:.*Bar=2" err
411 test_expect_success
'GIT_REDACT_COOKIES handles empty values' '
413 echo "Set-Cookie: Foo=" >cookies &&
414 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Foo \
415 git -c "http.cookieFile=$(pwd)/cookies" clone \
416 $HTTPD_URL/smart/repo.git clone 2>err &&
417 grep "Cookie:.*Foo=<redacted>" err
420 test_expect_success
'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
422 GIT_TRACE_CURL=true \
423 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
424 grep "=> Send data" err &&
427 GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
428 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
429 ! grep "=> Send data" err
432 test_expect_success
'server-side error detected' '
433 test_must_fail git clone $HTTPD_URL/error_smart/repo.git 2>actual &&
434 grep "server-side error" actual