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
27 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
29 > Accept-Encoding: ENCODINGS
33 < Cache-Control: no-cache, max-age=0, must-revalidate
34 < Content-Type: application/x-git-upload-pack-advertisement
35 > POST /smart/repo.git/git-upload-pack HTTP/1.1
36 > Accept-Encoding: ENCODINGS
37 > Content-Type: application/x-git-upload-pack-request
38 > Accept: application/x-git-upload-pack-result
42 < Cache-Control: no-cache, max-age=0, must-revalidate
43 < Content-Type: application/x-git-upload-pack-result
45 test_expect_success
'clone http repository' '
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
100 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
101 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
102 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
103 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
105 test_expect_success
'used upload-pack service' '
111 " >act <"$HTTPD_ROOT_PATH"/access.log &&
115 test_expect_success
'follow redirects (301)' '
116 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
119 test_expect_success
'follow redirects (302)' '
120 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
123 test_expect_success
'redirects re-root further requests' '
124 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
127 test_expect_success
're-rooting dies on insane schemes' '
128 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
131 test_expect_success
'clone from password-protected repository' '
133 set_askpass user@host pass@host &&
134 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
135 expect_askpass both user@host &&
136 git --git-dir=smart-auth log -1 --format=%s >actual &&
137 test_cmp expect actual
140 test_expect_success
'clone from auth-only-for-push repository' '
143 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
144 expect_askpass none &&
145 git --git-dir=smart-noauth log -1 --format=%s >actual &&
146 test_cmp expect actual
149 test_expect_success
'clone from auth-only-for-objects repository' '
151 set_askpass user@host pass@host &&
152 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
153 expect_askpass both user@host &&
154 git --git-dir=half-auth log -1 --format=%s >actual &&
155 test_cmp expect actual
158 test_expect_success
'no-op half-auth fetch does not require a password' '
160 git --git-dir=half-auth fetch &&
164 test_expect_success
'redirects send auth to new location' '
165 set_askpass user@host pass@host &&
166 git -c credential.useHttpPath=true \
167 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
168 expect_askpass both user@host auth/smart/repo.git
171 test_expect_success
'disable dumb http on server' '
172 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
173 config http.getanyfile false
176 test_expect_success
'GIT_SMART_HTTP can disable smart http' '
178 export GIT_SMART_HTTP &&
180 test_must_fail git fetch)
183 test_expect_success
'invalid Content-Type rejected' '
184 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
185 grep "not valid:" actual
188 test_expect_success
'create namespaced refs' '
189 test_commit namespaced &&
190 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
191 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
192 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
195 test_expect_success
'smart clone respects namespace' '
196 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
197 echo namespaced >expect &&
198 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
199 test_cmp expect actual
202 test_expect_success
'dumb clone via http-backend respects namespace' '
203 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
204 config http.getanyfile true &&
205 GIT_SMART_HTTP=0 git clone \
206 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
207 echo namespaced >expect &&
208 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
209 test_cmp expect actual
212 cat >cookies.txt
<<EOF
213 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
215 cat >expect_cookies.txt
<<EOF
217 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
218 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
220 test_expect_success
'cookies stored in http.cookiefile when http.savecookies set' '
221 git config http.cookiefile cookies.txt &&
222 git config http.savecookies true &&
223 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
224 tail -3 cookies.txt >cookies_tail.txt &&
225 test_cmp expect_cookies.txt cookies_tail.txt
228 test_expect_success
'transfer.hiderefs works over smart-http' '
229 test_commit hidden &&
230 test_commit visible &&
231 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
232 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
233 config transfer.hiderefs refs/heads/a &&
234 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
235 test_must_fail git -C hidden.git rev-parse --verify a &&
236 git -C hidden.git rev-parse --verify b
239 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
242 for i
in $
(test_seq
"$1" "$2")
244 # don't use here-doc, because it requires a process
246 echo "commit refs/heads/too-many-refs-$1" &&
248 echo "committer git <git@example.com> $i +0000" &&
250 echo "M 644 inline bla.txt" &&
253 # make every commit dangling by always
254 # rewinding the branch after each commit
255 echo "reset refs/heads/too-many-refs-$1" &&
257 done | git fast-import
--export-marks=marks
&&
259 # now assign tags to all the dangling commits we created above
260 tag
=$
(perl
-e "print \"bla\" x 30") &&
261 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks
>>packed-refs
264 test_expect_success
'create 2,000 tags in the repo' '
266 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
271 test_expect_success CMDLINE_LIMIT \
272 'clone the 2,000 tag repo to check OS command line overflow' '
273 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
276 git for-each-ref refs/tags >actual &&
277 test_line_count = 2000 actual
281 test_expect_success
'large fetch-pack requests can be split across POSTs' '
282 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
283 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
284 grep "^=> Send header: POST" err >posts &&
285 test_line_count = 2 posts
288 test_expect_success
'test allowreachablesha1inwant' '
289 test_when_finished "rm -rf test_reachable.git" &&
290 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
291 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
292 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
294 git init --bare test_reachable.git &&
295 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
296 git -C test_reachable.git fetch origin "$master_sha"
299 test_expect_success
'test allowreachablesha1inwant with unreachable' '
300 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
302 #create unreachable sha
303 echo content >file2 &&
306 git push public HEAD:refs/heads/doomed &&
307 git push public :refs/heads/doomed &&
309 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
310 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
311 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
313 git init --bare test_reachable.git &&
314 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
315 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
318 test_expect_success
'test allowanysha1inwant with unreachable' '
319 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
321 #create unreachable sha
322 echo content >file2 &&
325 git push public HEAD:refs/heads/doomed &&
326 git push public :refs/heads/doomed &&
328 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
329 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
330 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
332 git init --bare test_reachable.git &&
333 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
334 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
336 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
337 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
340 test_expect_success EXPENSIVE
'http can handle enormous ref negotiation' '
342 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
343 create_tags 2001 50000
345 git -C too-many-refs fetch -q --tags &&
347 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
348 create_tags 50001 100000
350 git -C too-many-refs fetch -q --tags &&
351 git -C too-many-refs for-each-ref refs/tags >tags &&
352 test_line_count = 100000 tags
355 test_expect_success
'custom http headers' '
356 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
357 fetch "$HTTPD_URL/smart_headers/repo.git" &&
358 git -c http.extraheader="x-magic-one: abra" \
359 -c http.extraheader="x-magic-two: cadabra" \
360 fetch "$HTTPD_URL/smart_headers/repo.git" &&
361 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
362 git config -f .gitmodules submodule.sub.path sub &&
363 git config -f .gitmodules submodule.sub.url \
364 "$HTTPD_URL/smart_headers/repo.git" &&
365 git submodule init sub &&
366 test_must_fail git submodule update sub &&
367 git -c http.extraheader="x-magic-one: abra" \
368 -c http.extraheader="x-magic-two: cadabra" \
372 test_expect_success
'GIT_REDACT_COOKIES redacts cookies' '
374 echo "Set-Cookie: Foo=1" >cookies &&
375 echo "Set-Cookie: Bar=2" >>cookies &&
376 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Bar,Baz \
377 git -c "http.cookieFile=$(pwd)/cookies" clone \
378 $HTTPD_URL/smart/repo.git clone 2>err &&
379 grep "Cookie:.*Foo=1" err &&
380 grep "Cookie:.*Bar=<redacted>" err &&
381 ! grep "Cookie:.*Bar=2" err
384 test_expect_success
'GIT_REDACT_COOKIES handles empty values' '
386 echo "Set-Cookie: Foo=" >cookies &&
387 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Foo \
388 git -c "http.cookieFile=$(pwd)/cookies" clone \
389 $HTTPD_URL/smart/repo.git clone 2>err &&
390 grep "Cookie:.*Foo=<redacted>" err
393 test_expect_success
'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
395 GIT_TRACE_CURL=true \
396 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
397 grep "=> Send data" err &&
400 GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
401 git clone $HTTPD_URL/smart/repo.git clone 2>err &&
402 ! grep "=> Send data" err