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' '
104 test_expect_success
'follow redirects (301)' '
105 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
108 test_expect_success
'follow redirects (302)' '
109 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
112 test_expect_success
'redirects re-root further requests' '
113 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
116 test_expect_success
're-rooting dies on insane schemes' '
117 test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
120 test_expect_success
'clone from password-protected repository' '
122 set_askpass user@host pass@host &&
123 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
124 expect_askpass both user@host &&
125 git --git-dir=smart-auth log -1 --format=%s >actual &&
126 test_cmp expect actual
129 test_expect_success
'clone from auth-only-for-push repository' '
132 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
133 expect_askpass none &&
134 git --git-dir=smart-noauth log -1 --format=%s >actual &&
135 test_cmp expect actual
138 test_expect_success
'clone from auth-only-for-objects repository' '
140 set_askpass user@host pass@host &&
141 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
142 expect_askpass both user@host &&
143 git --git-dir=half-auth log -1 --format=%s >actual &&
144 test_cmp expect actual
147 test_expect_success
'no-op half-auth fetch does not require a password' '
149 git --git-dir=half-auth fetch &&
153 test_expect_success
'redirects send auth to new location' '
154 set_askpass user@host pass@host &&
155 git -c credential.useHttpPath=true \
156 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
157 expect_askpass both user@host auth/smart/repo.git
160 test_expect_success
'disable dumb http on server' '
161 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
162 config http.getanyfile false
165 test_expect_success
'GIT_SMART_HTTP can disable smart http' '
167 export GIT_SMART_HTTP &&
169 test_must_fail git fetch)
172 test_expect_success
'invalid Content-Type rejected' '
173 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
174 grep "not valid:" actual
177 test_expect_success
'create namespaced refs' '
178 test_commit namespaced &&
179 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
180 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
181 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
184 test_expect_success
'smart clone respects namespace' '
185 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
186 echo namespaced >expect &&
187 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
188 test_cmp expect actual
191 test_expect_success
'dumb clone via http-backend respects namespace' '
192 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
193 config http.getanyfile true &&
194 GIT_SMART_HTTP=0 git clone \
195 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
196 echo namespaced >expect &&
197 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
198 test_cmp expect actual
201 cat >cookies.txt
<<EOF
202 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
204 cat >expect_cookies.txt
<<EOF
206 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
207 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
209 test_expect_success
'cookies stored in http.cookiefile when http.savecookies set' '
210 git config http.cookiefile cookies.txt &&
211 git config http.savecookies true &&
212 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
213 tail -3 cookies.txt >cookies_tail.txt &&
214 test_cmp expect_cookies.txt cookies_tail.txt
217 test_expect_success
'transfer.hiderefs works over smart-http' '
218 test_commit hidden &&
219 test_commit visible &&
220 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
221 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
222 config transfer.hiderefs refs/heads/a &&
223 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
224 test_must_fail git -C hidden.git rev-parse --verify a &&
225 git -C hidden.git rev-parse --verify b
228 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
231 for i
in $
(test_seq
"$1" "$2")
233 # don't use here-doc, because it requires a process
235 echo "commit refs/heads/too-many-refs-$1" &&
237 echo "committer git <git@example.com> $i +0000" &&
239 echo "M 644 inline bla.txt" &&
242 # make every commit dangling by always
243 # rewinding the branch after each commit
244 echo "reset refs/heads/too-many-refs-$1" &&
246 done | git fast-import
--export-marks=marks
&&
248 # now assign tags to all the dangling commits we created above
249 tag
=$
(perl
-e "print \"bla\" x 30") &&
250 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks
>>packed-refs
253 test_expect_success
'create 2,000 tags in the repo' '
255 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
260 test_expect_success CMDLINE_LIMIT \
261 'clone the 2,000 tag repo to check OS command line overflow' '
262 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
265 git for-each-ref refs/tags >actual &&
266 test_line_count = 2000 actual
270 test_expect_success
'large fetch-pack requests can be split across POSTs' '
271 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
272 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
273 grep "^=> Send header: POST" err >posts &&
274 test_line_count = 2 posts
277 test_expect_success
'test allowreachablesha1inwant' '
278 test_when_finished "rm -rf test_reachable.git" &&
279 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
280 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
281 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
283 git init --bare test_reachable.git &&
284 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
285 git -C test_reachable.git fetch origin "$master_sha"
288 test_expect_success
'test allowreachablesha1inwant with unreachable' '
289 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
291 #create unreachable sha
292 echo content >file2 &&
295 git push public HEAD:refs/heads/doomed &&
296 git push public :refs/heads/doomed &&
298 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
299 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
300 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
302 git init --bare test_reachable.git &&
303 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
304 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
307 test_expect_success
'test allowanysha1inwant with unreachable' '
308 test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
310 #create unreachable sha
311 echo content >file2 &&
314 git push public HEAD:refs/heads/doomed &&
315 git push public :refs/heads/doomed &&
317 server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
318 master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
319 git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
321 git init --bare test_reachable.git &&
322 git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
323 test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
325 git -C "$server" config uploadpack.allowanysha1inwant 1 &&
326 git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
329 test_expect_success EXPENSIVE
'http can handle enormous ref negotiation' '
331 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
332 create_tags 2001 50000
334 git -C too-many-refs fetch -q --tags &&
336 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
337 create_tags 50001 100000
339 git -C too-many-refs fetch -q --tags &&
340 git -C too-many-refs for-each-ref refs/tags >tags &&
341 test_line_count = 100000 tags
344 test_expect_success
'custom http headers' '
345 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
346 fetch "$HTTPD_URL/smart_headers/repo.git" &&
347 git -c http.extraheader="x-magic-one: abra" \
348 -c http.extraheader="x-magic-two: cadabra" \
349 fetch "$HTTPD_URL/smart_headers/repo.git" &&
350 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
351 git config -f .gitmodules submodule.sub.path sub &&
352 git config -f .gitmodules submodule.sub.url \
353 "$HTTPD_URL/smart_headers/repo.git" &&
354 git submodule init sub &&
355 test_must_fail git submodule update sub &&
356 git -c http.extraheader="x-magic-one: abra" \
357 -c http.extraheader="x-magic-two: cadabra" \