perf: add test showing exponential growth in path globbing
[git.git] / t / t5550-http-fetch-dumb.sh
blob87308cdced9af11365d5eb0644b9ac86fac21177
1 #!/bin/sh
3 test_description='test dumb fetching over http via static file'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-httpd.sh
6 start_httpd
8 test_expect_success 'setup repository' '
9 git config push.default matching &&
10 echo content1 >file &&
11 git add file &&
12 git commit -m one &&
13 echo content2 >file &&
14 git add file &&
15 git commit -m two
18 test_expect_success 'create http-accessible bare repository with loose objects' '
19 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
20 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
21 git config core.bare true &&
22 mkdir -p hooks &&
23 echo "exec git update-server-info" >hooks/post-update &&
24 chmod +x hooks/post-update &&
25 hooks/post-update
26 ) &&
27 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git push public master:master
31 test_expect_success 'clone http repository' '
32 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
33 cp -R clone-tmpl clone &&
34 test_cmp file clone/file
37 test_expect_success 'list refs from outside any repository' '
38 cat >expect <<-EOF &&
39 $(git rev-parse master) HEAD
40 $(git rev-parse master) refs/heads/master
41 EOF
42 nongit git ls-remote "$HTTPD_URL/dumb/repo.git" >actual &&
43 test_cmp expect actual
46 test_expect_success 'create password-protected repository' '
47 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
48 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
49 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
52 setup_askpass_helper
54 test_expect_success 'cloning password-protected repository can fail' '
55 set_askpass wrong &&
56 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
57 expect_askpass both wrong
60 test_expect_success 'http auth can use user/pass in URL' '
61 set_askpass wrong &&
62 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
63 expect_askpass none
66 test_expect_success 'http auth can use just user in URL' '
67 set_askpass wrong pass@host &&
68 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
69 expect_askpass pass user@host
72 test_expect_success 'http auth can request both user and pass' '
73 set_askpass user@host pass@host &&
74 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
75 expect_askpass both user@host
78 test_expect_success 'http auth respects credential helper config' '
79 test_config_global credential.helper "!f() {
80 cat >/dev/null
81 echo username=user@host
82 echo password=pass@host
83 }; f" &&
84 set_askpass wrong &&
85 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
86 expect_askpass none
89 test_expect_success 'http auth can get username from config' '
90 test_config_global "credential.$HTTPD_URL.username" user@host &&
91 set_askpass wrong pass@host &&
92 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
93 expect_askpass pass user@host
96 test_expect_success 'configured username does not override URL' '
97 test_config_global "credential.$HTTPD_URL.username" wrong &&
98 set_askpass wrong pass@host &&
99 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
100 expect_askpass pass user@host
103 test_expect_success 'set up repo with http submodules' '
104 git init super &&
105 set_askpass user@host pass@host &&
107 cd super &&
108 git submodule add "$HTTPD_URL/auth/dumb/repo.git" sub &&
109 git commit -m "add submodule"
113 test_expect_success 'cmdline credential config passes to submodule via clone' '
114 set_askpass wrong pass@host &&
115 test_must_fail git clone --recursive super super-clone &&
116 rm -rf super-clone &&
118 set_askpass wrong pass@host &&
119 git -c "credential.$HTTPD_URL.username=user@host" \
120 clone --recursive super super-clone &&
121 expect_askpass pass user@host
124 test_expect_success 'cmdline credential config passes submodule via fetch' '
125 set_askpass wrong pass@host &&
126 test_must_fail git -C super-clone fetch --recurse-submodules &&
128 set_askpass wrong pass@host &&
129 git -C super-clone \
130 -c "credential.$HTTPD_URL.username=user@host" \
131 fetch --recurse-submodules &&
132 expect_askpass pass user@host
135 test_expect_success 'cmdline credential config passes submodule update' '
136 # advance the submodule HEAD so that a fetch is required
137 git commit --allow-empty -m foo &&
138 git push "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" HEAD &&
139 sha1=$(git rev-parse HEAD) &&
140 git -C super-clone update-index --cacheinfo 160000,$sha1,sub &&
142 set_askpass wrong pass@host &&
143 test_must_fail git -C super-clone submodule update &&
145 set_askpass wrong pass@host &&
146 git -C super-clone \
147 -c "credential.$HTTPD_URL.username=user@host" \
148 submodule update &&
149 expect_askpass pass user@host
152 test_expect_success 'fetch changes via http' '
153 echo content >>file &&
154 git commit -a -m two &&
155 git push public &&
156 (cd clone && git pull) &&
157 test_cmp file clone/file
160 test_expect_success 'fetch changes via manual http-fetch' '
161 cp -R clone-tmpl clone2 &&
163 HEAD=$(git rev-parse --verify HEAD) &&
164 (cd clone2 &&
165 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
166 git checkout master-new &&
167 test $HEAD = $(git rev-parse --verify HEAD)) &&
168 test_cmp file clone2/file
171 test_expect_success 'http remote detects correct HEAD' '
172 git push public master:other &&
173 (cd clone &&
174 git remote set-head origin -d &&
175 git remote set-head origin -a &&
176 git symbolic-ref refs/remotes/origin/HEAD > output &&
177 echo refs/remotes/origin/master > expect &&
178 test_cmp expect output
182 test_expect_success 'fetch packed objects' '
183 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
184 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
185 git --bare repack -a -d
186 ) &&
187 git clone $HTTPD_URL/dumb/repo_pack.git
190 test_expect_success 'fetch notices corrupt pack' '
191 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
192 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
193 p=$(ls objects/pack/pack-*.pack) &&
194 chmod u+w $p &&
195 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
196 ) &&
197 mkdir repo_bad1.git &&
198 (cd repo_bad1.git &&
199 git --bare init &&
200 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
201 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
205 test_expect_success 'fetch notices corrupt idx' '
206 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
207 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
208 p=$(ls objects/pack/pack-*.idx) &&
209 chmod u+w $p &&
210 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
211 ) &&
212 mkdir repo_bad2.git &&
213 (cd repo_bad2.git &&
214 git --bare init &&
215 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
216 test 0 = $(ls objects/pack | wc -l)
220 test_expect_success 'fetch can handle previously-fetched .idx files' '
221 git checkout --orphan branch1 &&
222 echo base >file &&
223 git add file &&
224 git commit -m base &&
225 git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git &&
226 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 &&
227 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
228 git checkout -b branch2 branch1 &&
229 echo b2 >>file &&
230 git commit -a -m b2 &&
231 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 &&
232 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
233 git --bare init clone_packed_branches.git &&
234 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 &&
235 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2
238 test_expect_success 'did not use upload-pack service' '
239 test_might_fail grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act &&
240 : >exp &&
241 test_cmp exp act
244 test_expect_success 'git client shows text/plain errors' '
245 test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
246 grep "this is the error message" stderr
249 test_expect_success 'git client does not show html errors' '
250 test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
251 ! grep "this is the error message" stderr
254 test_expect_success 'git client shows text/plain with a charset' '
255 test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
256 grep "this is the error message" stderr
259 test_expect_success 'http error messages are reencoded' '
260 test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
261 grep "this is the error message" stderr
264 test_expect_success 'reencoding is robust to whitespace oddities' '
265 test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
266 grep "this is the error message" stderr
269 check_language () {
270 case "$2" in
272 >expect
275 echo "=> Send header: Accept-Language: $1" >expect
277 esac &&
278 GIT_TRACE_CURL=true \
279 LANGUAGE=$2 \
280 git ls-remote "$HTTPD_URL/dumb/repo.git" >output 2>&1 &&
281 tr -d '\015' <output |
282 sort -u |
283 sed -ne '/^=> Send header: Accept-Language:/ p' >actual &&
284 test_cmp expect actual
287 test_expect_success 'git client sends Accept-Language based on LANGUAGE' '
288 check_language "ko-KR, *;q=0.9" ko_KR.UTF-8'
290 test_expect_success 'git client sends Accept-Language correctly with unordinary LANGUAGE' '
291 check_language "ko-KR, *;q=0.9" "ko_KR:" &&
292 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" &&
293 check_language "ko-KR, *;q=0.9" ":::ko_KR" &&
294 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" &&
295 check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"'
297 test_expect_success 'git client sends Accept-Language with many preferred languages' '
298 check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \
299 ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \
300 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt &&
301 check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \
302 ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \
303 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb
306 test_expect_success 'git client does not send an empty Accept-Language' '
307 GIT_TRACE_CURL=true LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr &&
308 ! grep "^=> Send header: Accept-Language:" stderr
311 test_expect_success 'remote-http complains cleanly about malformed urls' '
312 # do not actually issue "list" or other commands, as we do not
313 # want to rely on what curl would actually do with such a broken
314 # URL. This is just about making sure we do not segfault during
315 # initialization.
316 test_must_fail git remote-http http::/example.com/repo.git
319 test_expect_success 'redirects can be forbidden/allowed' '
320 test_must_fail git -c http.followRedirects=false \
321 clone $HTTPD_URL/dumb-redir/repo.git dumb-redir &&
322 git -c http.followRedirects=true \
323 clone $HTTPD_URL/dumb-redir/repo.git dumb-redir 2>stderr
326 test_expect_success 'redirects are reported to stderr' '
327 # just look for a snippet of the redirected-to URL
328 test_i18ngrep /dumb/ stderr
331 test_expect_success 'non-initial redirects can be forbidden' '
332 test_must_fail git -c http.followRedirects=initial \
333 clone $HTTPD_URL/redir-objects/repo.git redir-objects &&
334 git -c http.followRedirects=true \
335 clone $HTTPD_URL/redir-objects/repo.git redir-objects
338 test_expect_success 'http.followRedirects defaults to "initial"' '
339 test_must_fail git clone $HTTPD_URL/redir-objects/repo.git default
342 # The goal is for a clone of the "evil" repository, which has no objects
343 # itself, to cause the client to fetch objects from the "victim" repository.
344 test_expect_success 'set up evil alternates scheme' '
345 victim=$HTTPD_DOCUMENT_ROOT_PATH/victim.git &&
346 git init --bare "$victim" &&
347 git -C "$victim" --work-tree=. commit --allow-empty -m secret &&
348 git -C "$victim" repack -ad &&
349 git -C "$victim" update-server-info &&
350 sha1=$(git -C "$victim" rev-parse HEAD) &&
352 evil=$HTTPD_DOCUMENT_ROOT_PATH/evil.git &&
353 git init --bare "$evil" &&
354 # do this by hand to avoid object existence check
355 printf "%s\\t%s\\n" $sha1 refs/heads/master >"$evil/info/refs"
358 # Here we'll just redirect via HTTP. In a real-world attack these would be on
359 # different servers, but we should reject it either way.
360 test_expect_success 'http-alternates is a non-initial redirect' '
361 echo "$HTTPD_URL/dumb/victim.git/objects" \
362 >"$evil/objects/info/http-alternates" &&
363 test_must_fail git -c http.followRedirects=initial \
364 clone $HTTPD_URL/dumb/evil.git evil-initial &&
365 git -c http.followRedirects=true \
366 clone $HTTPD_URL/dumb/evil.git evil-initial
369 # Curl supports a lot of protocols that we'd prefer not to allow
370 # http-alternates to use, but it's hard to test whether curl has
371 # accessed, say, the SMTP protocol, because we are not running an SMTP server.
372 # But we can check that it does not allow access to file://, which would
373 # otherwise allow this clone to complete.
374 test_expect_success 'http-alternates cannot point at funny protocols' '
375 echo "file://$victim/objects" >"$evil/objects/info/http-alternates" &&
376 test_must_fail git -c http.followRedirects=true \
377 clone "$HTTPD_URL/dumb/evil.git" evil-file
380 test_expect_success 'http-alternates triggers not-from-user protocol check' '
381 echo "$HTTPD_URL/dumb/victim.git/objects" \
382 >"$evil/objects/info/http-alternates" &&
383 test_config_global http.followRedirects true &&
384 test_must_fail git -c protocol.http.allow=user \
385 clone $HTTPD_URL/dumb/evil.git evil-user &&
386 git -c protocol.http.allow=always \
387 clone $HTTPD_URL/dumb/evil.git evil-user
390 test_expect_success 'can redirect through non-"info/refs?service=git-upload-pack" URL' '
391 git clone "$HTTPD_URL/redir-to/dumb/repo.git"
394 test_expect_success 'print HTTP error when any intermediate redirect throws error' '
395 test_must_fail git clone "$HTTPD_URL/redir-to/502" 2> stderr &&
396 test_i18ngrep "unable to access.*/redir-to/502" stderr
399 stop_httpd
400 test_done