t5550-http-fetch-dumb.sh 8.2 KB
Newer Older
J
Jeff King 已提交
1 2
#!/bin/sh

S
Shawn O. Pearce 已提交
3
test_description='test dumb fetching over http via static file'
J
Jeff King 已提交
4 5 6
. ./test-lib.sh

if test -n "$NO_CURL"; then
7
	skip_all='skipping test, git built without http support'
J
Jeff King 已提交
8 9 10
	test_done
fi

C
Clemens Buchacher 已提交
11
. "$TEST_DIRECTORY"/lib-httpd.sh
J
Jeff King 已提交
12 13 14
start_httpd

test_expect_success 'setup repository' '
15
	git config push.default matching &&
16
	echo content1 >file &&
J
Jeff King 已提交
17
	git add file &&
J
Jeff King 已提交
18
	git commit -m one &&
19 20 21
	echo content2 >file &&
	git add file &&
	git commit -m two
J
Jeff King 已提交
22 23
'

24
test_expect_success 'create http-accessible bare repository with loose objects' '
B
Ben Walton 已提交
25
	cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
J
Jeff King 已提交
26
	(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 28
	 git config core.bare true &&
	 mkdir -p hooks &&
J
Jeff King 已提交
29
	 echo "exec git update-server-info" >hooks/post-update &&
30 31
	 chmod +x hooks/post-update &&
	 hooks/post-update
J
Jeff King 已提交
32 33 34 35 36 37
	) &&
	git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
	git push public master:master
'

test_expect_success 'clone http repository' '
38 39
	git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
	cp -R clone-tmpl clone &&
J
Jeff King 已提交
40 41 42
	test_cmp file clone/file
'

J
Jeff King 已提交
43
test_expect_success 'create password-protected repository' '
44
	mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
J
Jeff King 已提交
45
	cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
46
	       "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
J
Jeff King 已提交
47 48
'

J
Jeff King 已提交
49
setup_askpass_helper
50

J
Jeff King 已提交
51
test_expect_success 'cloning password-protected repository can fail' '
J
Jeff King 已提交
52
	set_askpass wrong &&
53
	test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
54
	expect_askpass both wrong
J
Jeff King 已提交
55 56 57
'

test_expect_success 'http auth can use user/pass in URL' '
J
Jeff King 已提交
58
	set_askpass wrong &&
59
	git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
60
	expect_askpass none
J
Jeff King 已提交
61 62
'

63
test_expect_success 'http auth can use just user in URL' '
64
	set_askpass wrong pass@host &&
65
	git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
66
	expect_askpass pass user@host
J
Jeff King 已提交
67 68
'

69
test_expect_success 'http auth can request both user and pass' '
70
	set_askpass user@host pass@host &&
71
	git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
72
	expect_askpass both user@host
73 74
'

75
test_expect_success 'http auth respects credential helper config' '
J
Jeff King 已提交
76 77 78
	test_config_global credential.helper "!f() {
		cat >/dev/null
		echo username=user@host
79
		echo password=pass@host
J
Jeff King 已提交
80
	}; f" &&
J
Jeff King 已提交
81
	set_askpass wrong &&
82
	git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
J
Jeff King 已提交
83 84 85
	expect_askpass none
'

86
test_expect_success 'http auth can get username from config' '
J
Jeff King 已提交
87
	test_config_global "credential.$HTTPD_URL.username" user@host &&
88
	set_askpass wrong pass@host &&
89
	git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
J
Jeff King 已提交
90 91 92
	expect_askpass pass user@host
'

93
test_expect_success 'configured username does not override URL' '
J
Jeff King 已提交
94
	test_config_global "credential.$HTTPD_URL.username" wrong &&
95
	set_askpass wrong pass@host &&
96
	git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
J
Jeff King 已提交
97 98 99
	expect_askpass pass user@host
'

J
Jeff King 已提交
100 101 102
test_expect_success 'fetch changes via http' '
	echo content >>file &&
	git commit -a -m two &&
T
Tay Ray Chuan 已提交
103
	git push public &&
J
Jeff King 已提交
104 105 106 107
	(cd clone && git pull) &&
	test_cmp file clone/file
'

108 109 110 111 112 113 114 115 116 117 118
test_expect_success 'fetch changes via manual http-fetch' '
	cp -R clone-tmpl clone2 &&

	HEAD=$(git rev-parse --verify HEAD) &&
	(cd clone2 &&
	 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
	 git checkout master-new &&
	 test $HEAD = $(git rev-parse --verify HEAD)) &&
	test_cmp file clone2/file
'

119 120 121 122 123 124 125 126 127 128 129
test_expect_success 'http remote detects correct HEAD' '
	git push public master:other &&
	(cd clone &&
	 git remote set-head origin -d &&
	 git remote set-head origin -a &&
	 git symbolic-ref refs/remotes/origin/HEAD > output &&
	 echo refs/remotes/origin/master > expect &&
	 test_cmp expect output
	)
'

130 131
test_expect_success 'fetch packed objects' '
	cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
132
	(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
133
	 git --bare repack -a -d
134
	) &&
135
	git clone $HTTPD_URL/dumb/repo_pack.git
136 137
'

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
test_expect_success 'fetch notices corrupt pack' '
	cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
	(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
	 p=`ls objects/pack/pack-*.pack` &&
	 chmod u+w $p &&
	 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
	) &&
	mkdir repo_bad1.git &&
	(cd repo_bad1.git &&
	 git --bare init &&
	 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
	 test 0 = `ls objects/pack/pack-*.pack | wc -l`
	)
'

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
test_expect_success 'fetch notices corrupt idx' '
	cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
	(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
	 p=`ls objects/pack/pack-*.idx` &&
	 chmod u+w $p &&
	 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
	) &&
	mkdir repo_bad2.git &&
	(cd repo_bad2.git &&
	 git --bare init &&
	 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
	 test 0 = `ls objects/pack | wc -l`
	)
'

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
test_expect_success 'fetch can handle previously-fetched .idx files' '
	git checkout --orphan branch1 &&
	echo base >file &&
	git add file &&
	git commit -m base &&
	git --bare init "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git &&
	git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch1 &&
	git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
	git checkout -b branch2 branch1 &&
	echo b2 >>file &&
	git commit -a -m b2 &&
	git push "$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git branch2 &&
	git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH"/repo_packed_branches.git repack -d &&
	git --bare init clone_packed_branches.git &&
	git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch1:branch1 &&
	git --git-dir=clone_packed_branches.git fetch "$HTTPD_URL"/dumb/repo_packed_branches.git branch2:branch2
'

S
Shawn O. Pearce 已提交
186
test_expect_success 'did not use upload-pack service' '
187 188
	test_might_fail grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act &&
	: >exp &&
S
Shawn O. Pearce 已提交
189 190 191
	test_cmp exp act
'

192 193 194 195 196 197 198 199 200 201
test_expect_success 'git client shows text/plain errors' '
	test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr &&
	grep "this is the error message" stderr
'

test_expect_success 'git client does not show html errors' '
	test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr &&
	! grep "this is the error message" stderr
'

202 203 204 205 206
test_expect_success 'git client shows text/plain with a charset' '
	test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr &&
	grep "this is the error message" stderr
'

207 208 209 210 211
test_expect_success 'http error messages are reencoded' '
	test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr &&
	grep "this is the error message" stderr
'

212 213 214 215 216
test_expect_success 'reencoding is robust to whitespace oddities' '
	test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr &&
	grep "this is the error message" stderr
'

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
check_language () {
	case "$2" in
	'')
		>expect
		;;
	?*)
		echo "Accept-Language: $1" >expect
		;;
	esac &&
	GIT_CURL_VERBOSE=1 \
	LANGUAGE=$2 \
	git ls-remote "$HTTPD_URL/dumb/repo.git" >output 2>&1 &&
	tr -d '\015' <output |
	sort -u |
	sed -ne '/^Accept-Language:/ p' >actual &&
	test_cmp expect actual
}

test_expect_success 'git client sends Accept-Language based on LANGUAGE' '
	check_language "ko-KR, *;q=0.9" ko_KR.UTF-8'

test_expect_success 'git client sends Accept-Language correctly with unordinary LANGUAGE' '
	check_language "ko-KR, *;q=0.9" "ko_KR:" &&
	check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR::en_US" &&
	check_language "ko-KR, *;q=0.9" ":::ko_KR" &&
	check_language "ko-KR, en-US;q=0.9, *;q=0.8" "ko_KR!!:en_US" &&
	check_language "ko-KR, ja-JP;q=0.9, *;q=0.8" "ko_KR en_US:ja_JP"'

test_expect_success 'git client sends Accept-Language with many preferred languages' '
	check_language "ko-KR, en-US;q=0.9, fr-CA;q=0.8, de;q=0.7, sr;q=0.6, \
ja;q=0.5, zh;q=0.4, sv;q=0.3, pt;q=0.2, *;q=0.1" \
		ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt &&
	check_language "ko-KR, en-US;q=0.99, fr-CA;q=0.98, de;q=0.97, sr;q=0.96, \
ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \
		ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb
'

test_expect_success 'git client does not send an empty Accept-Language' '
	GIT_CURL_VERBOSE=1 LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr &&
	! grep "^Accept-Language:" stderr
'

J
Jeff King 已提交
259 260
stop_httpd
test_done