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