]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5550-http-fetch-dumb.sh
Merge branch 'va/mailinfo-doc-typofix' into maint
[thirdparty/git.git] / t / t5550-http-fetch-dumb.sh
CommitLineData
119c8eee
JK
1#!/bin/sh
2
7da4e228 3test_description='test dumb fetching over http via static file'
119c8eee 4. ./test-lib.sh
55bc3dc4 5. "$TEST_DIRECTORY"/lib-httpd.sh
119c8eee
JK
6start_httpd
7
8test_expect_success 'setup repository' '
c9704aa7 9 git config push.default matching &&
5a9681f4 10 echo content1 >file &&
119c8eee 11 git add file &&
99094a7a 12 git commit -m one &&
5a9681f4
CB
13 echo content2 >file &&
14 git add file &&
15 git commit -m two
119c8eee
JK
16'
17
5a9681f4 18test_expect_success 'create http-accessible bare repository with loose objects' '
d4a7ffaa 19 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
119c8eee 20 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
5a9681f4
CB
21 git config core.bare true &&
22 mkdir -p hooks &&
119c8eee 23 echo "exec git update-server-info" >hooks/post-update &&
5a9681f4
CB
24 chmod +x hooks/post-update &&
25 hooks/post-update
119c8eee
JK
26 ) &&
27 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git push public master:master
29'
30
31test_expect_success 'clone http repository' '
6cfc0286
TRC
32 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
33 cp -R clone-tmpl clone &&
119c8eee
JK
34 test_cmp file clone/file
35'
36
5232586c 37test_expect_success 'create password-protected repository' '
726800a8 38 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
5232586c 39 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
726800a8 40 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
5232586c
JK
41'
42
e837936c 43setup_askpass_helper
148bb6a7 44
5232586c 45test_expect_success 'cloning password-protected repository can fail' '
e837936c 46 set_askpass wrong &&
726800a8 47 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
148bb6a7 48 expect_askpass both wrong
5232586c
JK
49'
50
51test_expect_success 'http auth can use user/pass in URL' '
e837936c 52 set_askpass wrong &&
726800a8 53 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
148bb6a7 54 expect_askpass none
5232586c
JK
55'
56
dfa1725a 57test_expect_success 'http auth can use just user in URL' '
afbf5ca5 58 set_askpass wrong pass@host &&
726800a8 59 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
148bb6a7 60 expect_askpass pass user@host
5232586c
JK
61'
62
dfa1725a 63test_expect_success 'http auth can request both user and pass' '
afbf5ca5 64 set_askpass user@host pass@host &&
726800a8 65 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
148bb6a7 66 expect_askpass both user@host
3cf8fe1d
GC
67'
68
dfa1725a 69test_expect_success 'http auth respects credential helper config' '
11825072
JK
70 test_config_global credential.helper "!f() {
71 cat >/dev/null
72 echo username=user@host
afbf5ca5 73 echo password=pass@host
11825072 74 }; f" &&
e837936c 75 set_askpass wrong &&
726800a8 76 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
11825072
JK
77 expect_askpass none
78'
79
dfa1725a 80test_expect_success 'http auth can get username from config' '
d5742425 81 test_config_global "credential.$HTTPD_URL.username" user@host &&
afbf5ca5 82 set_askpass wrong pass@host &&
726800a8 83 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
d5742425
JK
84 expect_askpass pass user@host
85'
86
dfa1725a 87test_expect_success 'configured username does not override URL' '
d5742425 88 test_config_global "credential.$HTTPD_URL.username" wrong &&
afbf5ca5 89 set_askpass wrong pass@host &&
726800a8 90 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
d5742425
JK
91 expect_askpass pass user@host
92'
93
119c8eee
JK
94test_expect_success 'fetch changes via http' '
95 echo content >>file &&
96 git commit -a -m two &&
2bcd9ec5 97 git push public &&
119c8eee
JK
98 (cd clone && git pull) &&
99 test_cmp file clone/file
100'
101
6cfc0286
TRC
102test_expect_success 'fetch changes via manual http-fetch' '
103 cp -R clone-tmpl clone2 &&
104
105 HEAD=$(git rev-parse --verify HEAD) &&
106 (cd clone2 &&
107 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
108 git checkout master-new &&
109 test $HEAD = $(git rev-parse --verify HEAD)) &&
110 test_cmp file clone2/file
111'
112
fbb074c2
JK
113test_expect_success 'http remote detects correct HEAD' '
114 git push public master:other &&
115 (cd clone &&
116 git remote set-head origin -d &&
117 git remote set-head origin -a &&
118 git symbolic-ref refs/remotes/origin/HEAD > output &&
119 echo refs/remotes/origin/master > expect &&
120 test_cmp expect output
121 )
122'
123
96a4f187
TRC
124test_expect_success 'fetch packed objects' '
125 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
d761b2ac 126 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
1327d839 127 git --bare repack -a -d
d761b2ac 128 ) &&
024bb125 129 git clone $HTTPD_URL/dumb/repo_pack.git
96a4f187
TRC
130'
131
fe72d420
SP
132test_expect_success 'fetch notices corrupt pack' '
133 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
134 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
bacb1c01 135 p=$(ls objects/pack/pack-*.pack) &&
fe72d420
SP
136 chmod u+w $p &&
137 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
138 ) &&
139 mkdir repo_bad1.git &&
140 (cd repo_bad1.git &&
141 git --bare init &&
142 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
bacb1c01 143 test 0 = $(ls objects/pack/pack-*.pack | wc -l)
fe72d420
SP
144 )
145'
146
750ef425
SP
147test_expect_success 'fetch notices corrupt idx' '
148 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
149 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
bacb1c01 150 p=$(ls objects/pack/pack-*.idx) &&
750ef425
SP
151 chmod u+w $p &&
152 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
153 ) &&
154 mkdir repo_bad2.git &&
155 (cd repo_bad2.git &&
156 git --bare init &&
157 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
bacb1c01 158 test 0 = $(ls objects/pack | wc -l)
750ef425
SP
159 )
160'
161
8b9c2dd4
JK
162test_expect_success 'fetch can handle previously-fetched .idx files' '
163 git checkout --orphan branch1 &&
164 echo base >file &&
165 git add file &&
166 git commit -m base &&
167 git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git &&
168 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 &&
169 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
170 git checkout -b branch2 branch1 &&
171 echo b2 >>file &&
172 git commit -a -m b2 &&
173 git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 &&
174 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
175 git --bare init clone_packed_branches.git &&
176 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 &&
177 git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2
178'
179
7da4e228 180test_expect_success 'did not use upload-pack service' '
35da1bf5
JK
181 test_might_fail grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act &&
182 : >exp &&
7da4e228
SP
183 test_cmp exp act
184'
185
dbcf2bd3
JK
186test_expect_success 'git client shows text/plain errors' '
187 test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
188 grep "this is the error message" stderr
189'
190
191test_expect_success 'git client does not show html errors' '
192 test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
193 ! grep "this is the error message" stderr
194'
195
bf197fd7
JK
196test_expect_success 'git client shows text/plain with a charset' '
197 test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
198 grep "this is the error message" stderr
199'
200
fc1b774c
JK
201test_expect_success 'http error messages are reencoded' '
202 test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
203 grep "this is the error message" stderr
204'
205
f34a655d
YE
206test_expect_success 'reencoding is robust to whitespace oddities' '
207 test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
208 grep "this is the error message" stderr
209'
210
f18604bb
YE
211check_language () {
212 case "$2" in
213 '')
214 >expect
215 ;;
216 ?*)
217 echo "Accept-Language: $1" >expect
218 ;;
219 esac &&
220 GIT_CURL_VERBOSE=1 \
221 LANGUAGE=$2 \
222 git ls-remote "$HTTPD_URL/dumb/repo.git" >output 2>&1 &&
223 tr -d '\015' <output |
224 sort -u |
225 sed -ne '/^Accept-Language:/ p' >actual &&
226 test_cmp expect actual
227}
228
229test_expect_success 'git client sends Accept-Language based on LANGUAGE' '
230 check_language "ko-KR, *;q=0.9" ko_KR.UTF-8'
231
232test_expect_success 'git client sends Accept-Language correctly with unordinary LANGUAGE' '
233 check_language "ko-KR, *;q=0.9" "ko_KR:" &&
234 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" &&
235 check_language "ko-KR, *;q=0.9" ":::ko_KR" &&
236 check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" &&
237 check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"'
238
239test_expect_success 'git client sends Accept-Language with many preferred languages' '
240 check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \
241ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \
242 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt &&
243 check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \
244ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \
245 ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb
246'
247
248test_expect_success 'git client does not send an empty Accept-Language' '
249 GIT_CURL_VERBOSE=1 LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr &&
250 ! grep "^Accept-Language:" stderr
251'
252
119c8eee
JK
253stop_httpd
254test_done