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: gzip
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: gzip
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
86 test_expect_success 'fetch changes via http' '
87 echo content >>file &&
88 git commit -a -m two &&
90 (cd clone && git pull) &&
91 test_cmp file clone/file
95 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
96 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
97 GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
98 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
100 test_expect_success 'used upload-pack service' '
106 " >act <"$HTTPD_ROOT_PATH"/access.log &&
110 test_expect_success 'follow redirects (301)' '
111 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
114 test_expect_success 'follow redirects (302)' '
115 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
118 test_expect_success 'redirects re-root further requests' '
119 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
122 test_expect_success 're-rooting dies on insane schemes' '
123 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
126 test_expect_success 'clone from password-protected repository' '
128 set_askpass user@host pass@host &&
129 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
130 expect_askpass both user@host &&
131 git --git-dir=smart-auth log -1 --format=%s >actual &&
132 test_cmp expect actual
135 test_expect_success 'clone from auth-only-for-push repository' '
138 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
139 expect_askpass none &&
140 git --git-dir=smart-noauth log -1 --format=%s >actual &&
141 test_cmp expect actual
144 test_expect_success 'clone from auth-only-for-objects repository' '
146 set_askpass user@host pass@host &&
147 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
148 expect_askpass both user@host &&
149 git --git-dir=half-auth log -1 --format=%s >actual &&
150 test_cmp expect actual
153 test_expect_success 'no-op half-auth fetch does not require a password' '
155 git --git-dir=half-auth fetch &&
159 test_expect_success 'redirects send auth to new location' '
160 set_askpass user@host pass@host &&
161 git -c credential.useHttpPath=true \
162 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
163 expect_askpass both user@host auth/smart/repo.git
166 test_expect_success 'disable dumb http on server' '
167 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
168 config http.getanyfile false
171 test_expect_success 'GIT_SMART_HTTP can disable smart http' '
173 export GIT_SMART_HTTP &&
175 test_must_fail git fetch)
178 test_expect_success 'invalid Content-Type rejected' '
179 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
180 grep "not valid:" actual
183 test_expect_success 'create namespaced refs' '
184 test_commit namespaced &&
185 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
186 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
187 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
190 test_expect_success 'smart clone respects namespace' '
191 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
192 echo namespaced >expect &&
193 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
194 test_cmp expect actual
197 test_expect_success 'dumb clone via http-backend respects namespace' '
198 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
199 config http.getanyfile true &&
200 GIT_SMART_HTTP=0 git clone \
201 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
202 echo namespaced >expect &&
203 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
204 test_cmp expect actual
207 cat >cookies.txt <<EOF
208 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
210 cat >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 test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
216 git config http.cookiefile cookies.txt &&
217 git config http.savecookies true &&
218 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
219 tail -3 cookies.txt >cookies_tail.txt &&
220 test_cmp expect_cookies.txt cookies_tail.txt
223 test_expect_success 'transfer.hiderefs works over smart-http' '
224 test_commit hidden &&
225 test_commit visible &&
226 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
227 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
228 config transfer.hiderefs refs/heads/a &&
229 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
230 test_must_fail git -C hidden.git rev-parse --verify a &&
231 git -C hidden.git rev-parse --verify b
234 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
237 for i in $(test_seq "$1" "$2")
239 # don't use here-doc, because it requires a process
241 echo "commit refs/heads/too-many-refs-$1" &&
243 echo "committer git <git@example.com> $i +0000" &&
245 echo "M 644 inline bla.txt" &&
248 # make every commit dangling by always
249 # rewinding the branch after each commit
250 echo "reset refs/heads/too-many-refs-$1" &&
252 done | git fast-import --export-marks=marks &&
254 # now assign tags to all the dangling commits we created above
255 tag=$(perl -e "print \"bla\" x 30") &&
256 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
259 test_expect_success 'create 2,000 tags in the repo' '
261 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
266 test_expect_success CMDLINE_LIMIT \
267 'clone the 2,000 tag repo to check OS command line overflow' '
268 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
271 git for-each-ref refs/tags >actual &&
272 test_line_count = 2000 actual
276 test_expect_success 'large fetch-pack requests can be split across POSTs' '
277 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
278 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
279 grep "^=> Send header: POST" err >posts &&
280 test_line_count = 2 posts
283 test_expect_success 'test allowreachablesha1inwant' '
284 test_when_finished "rm -rf test_reachable.git" &&
285 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
286 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
287 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
289 git init --bare test_reachable.git &&
290 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
291 git -C test_reachable.git fetch origin "$master_sha"
294 test_expect_success 'test allowreachablesha1inwant with unreachable' '
295 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
297 #create unreachable sha
298 echo content >file2 &&
301 git push public HEAD:refs/heads/doomed &&
302 git push public :refs/heads/doomed &&
304 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
305 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
306 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
308 git init --bare test_reachable.git &&
309 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
310 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
313 test_expect_success 'test allowanysha1inwant with unreachable' '
314 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
316 #create unreachable sha
317 echo content >file2 &&
320 git push public HEAD:refs/heads/doomed &&
321 git push public :refs/heads/doomed &&
323 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
324 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
325 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
327 git init --bare test_reachable.git &&
328 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
329 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
331 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
332 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
335 test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
337 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
338 create_tags 2001 50000
340 git -C too-many-refs fetch -q --tags &&
342 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
343 create_tags 50001 100000
345 git -C too-many-refs fetch -q --tags &&
346 git -C too-many-refs for-each-ref refs/tags >tags &&
347 test_line_count = 100000 tags
350 test_expect_success 'custom http headers' '
351 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
352 fetch "$HTTPD_URL/smart_headers/repo.git" &&
353 git -c http.extraheader="x-magic-one: abra" \
354 -c http.extraheader="x-magic-two: cadabra" \
355 fetch "$HTTPD_URL/smart_headers/repo.git" &&
356 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
357 git config -f .gitmodules submodule.sub.path sub &&
358 git config -f .gitmodules submodule.sub.url \
359 "$HTTPD_URL/smart_headers/repo.git" &&
360 git submodule init sub &&
361 test_must_fail git submodule update sub &&
362 git -c http.extraheader="x-magic-one: abra" \
363 -c http.extraheader="x-magic-two: cadabra" \
367 test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
369 echo "Set-Cookie: Foo=1" >cookies &&
370 echo "Set-Cookie: Bar=2" >>cookies &&
371 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Bar,Baz \
372 git -c "http.cookieFile=$(pwd)/cookies" clone \
373 $HTTPD_URL/smart/repo.git clone 2>err &&
374 grep "Cookie:.*Foo=1" err &&
375 grep "Cookie:.*Bar=<redacted>" err &&
376 ! grep "Cookie:.*Bar=2" err
379 test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
381 echo "Set-Cookie: Foo=" >cookies &&
382 GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Foo \
383 git -c "http.cookieFile=$(pwd)/cookies" clone \
384 $HTTPD_URL/smart/repo.git clone 2>err &&
385 grep "Cookie:.*Foo=<redacted>" err