Git 2.11.0-rc1
[git/git.git] / t / t5551-http-fetch-smart.sh
CommitLineData
7da4e228
SP
1#!/bin/sh
2
3test_description='test smart fetching over http via http-backend'
4. ./test-lib.sh
7da4e228
SP
5. "$TEST_DIRECTORY"/lib-httpd.sh
6start_httpd
7
8test_expect_success 'setup repository' '
bd7ac599 9 git config push.default matching &&
7da4e228
SP
10 echo content >file &&
11 git add file &&
12 git commit -m one
13'
14
15test_expect_success 'create http-accessible bare repository' '
16 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
17 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
18 git --bare init
19 ) &&
20 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
21 git push public master:master
22'
23
6ac2b3ae
JK
24setup_askpass_helper
25
7da4e228
SP
26cat >exp <<EOF
27> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
28> Accept: */*
aa90b969 29> Accept-Encoding: gzip
7da4e228 30> Pragma: no-cache
7da4e228
SP
31< HTTP/1.1 200 OK
32< Pragma: no-cache
33< Cache-Control: no-cache, max-age=0, must-revalidate
34< Content-Type: application/x-git-upload-pack-advertisement
7da4e228 35> POST /smart/repo.git/git-upload-pack HTTP/1.1
aa90b969 36> Accept-Encoding: gzip
7da4e228 37> Content-Type: application/x-git-upload-pack-request
8efa5f62 38> Accept: application/x-git-upload-pack-result
7da4e228 39> Content-Length: xxx
7da4e228
SP
40< HTTP/1.1 200 OK
41< Pragma: no-cache
42< Cache-Control: no-cache, max-age=0, must-revalidate
43< Content-Type: application/x-git-upload-pack-result
7da4e228
SP
44EOF
45test_expect_success 'clone http repository' '
14e24114 46 GIT_TRACE_CURL=true git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
7da4e228
SP
47 test_cmp file clone/file &&
48 tr '\''\015'\'' Q <err |
49 sed -e "
50 s/Q\$//
51 /^[*] /d
14e24114
EP
52 /^== Info:/d
53 /^=> Send header, /d
54 /^=> Send header:$/d
55 /^<= Recv header, /d
56 /^<= Recv header:$/d
57 s/=> Send header: //
58 s/= Recv header://
59 /^<= Recv data/d
60 /^=> Send data/d
0a8fcbdc
SP
61 /^$/d
62 /^< $/d
7da4e228
SP
63
64 /^[^><]/{
65 s/^/> /
66 }
67
68 /^> User-Agent: /d
69 /^> Host: /d
20366635
SP
70 /^> POST /,$ {
71 /^> Accept: [*]\\/[*]/d
72 }
7da4e228 73 s/^> Content-Length: .*/> Content-Length: xxx/
0a8fcbdc
SP
74 /^> 00..want /d
75 /^> 00.*done/d
7da4e228
SP
76
77 /^< Server: /d
78 /^< Expires: /d
79 /^< Date: /d
80 /^< Content-Length: /d
81 /^< Transfer-Encoding: /d
82 " >act &&
83 test_cmp exp act
84'
85
86test_expect_success 'fetch changes via http' '
87 echo content >>file &&
88 git commit -a -m two &&
99094a7a 89 git push public &&
7da4e228
SP
90 (cd clone && git pull) &&
91 test_cmp file clone/file
92'
93
94cat >exp <<EOF
95GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
96POST /smart/repo.git/git-upload-pack HTTP/1.1 200
97GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
98POST /smart/repo.git/git-upload-pack HTTP/1.1 200
99EOF
100test_expect_success 'used upload-pack service' '
101 sed -e "
102 s/^.* \"//
103 s/\"//
104 s/ [1-9][0-9]*\$//
105 s/^GET /GET /
106 " >act <"$HTTPD_ROOT_PATH"/access.log &&
107 test_cmp exp act
108'
109
311e2ea0
TRC
110test_expect_success 'follow redirects (301)' '
111 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
112'
113
114test_expect_success 'follow redirects (302)' '
115 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
116'
117
050ef365
JK
118test_expect_success 'redirects re-root further requests' '
119 git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
120'
121
6ac2b3ae
JK
122test_expect_success 'clone from password-protected repository' '
123 echo two >expect &&
afbf5ca5 124 set_askpass user@host pass@host &&
6ac2b3ae
JK
125 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
126 expect_askpass both user@host &&
127 git --git-dir=smart-auth log -1 --format=%s >actual &&
128 test_cmp expect actual
129'
130
4c71009d
JK
131test_expect_success 'clone from auth-only-for-push repository' '
132 echo two >expect &&
133 set_askpass wrong &&
134 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
135 expect_askpass none &&
136 git --git-dir=smart-noauth log -1 --format=%s >actual &&
137 test_cmp expect actual
138'
139
2e736fd5
JK
140test_expect_success 'clone from auth-only-for-objects repository' '
141 echo two >expect &&
afbf5ca5 142 set_askpass user@host pass@host &&
2e736fd5
JK
143 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
144 expect_askpass both user@host &&
145 git --git-dir=half-auth log -1 --format=%s >actual &&
146 test_cmp expect actual
147'
148
149test_expect_success 'no-op half-auth fetch does not require a password' '
150 set_askpass wrong &&
151 git --git-dir=half-auth fetch &&
152 expect_askpass none
153'
154
050ef365 155test_expect_success 'redirects send auth to new location' '
afbf5ca5 156 set_askpass user@host pass@host &&
050ef365
JK
157 git -c credential.useHttpPath=true \
158 clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
159 expect_askpass both user@host auth/smart/repo.git
160'
161
02572c2e
JK
162test_expect_success 'disable dumb http on server' '
163 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
164 config http.getanyfile false
165'
166
167test_expect_success 'GIT_SMART_HTTP can disable smart http' '
168 (GIT_SMART_HTTP=0 &&
169 export GIT_SMART_HTTP &&
170 cd clone &&
171 test_must_fail git fetch)
172'
173
4656bf47 174test_expect_success 'invalid Content-Type rejected' '
8fb26872 175 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
af3aec44 176 grep "not valid:" actual
4656bf47
SP
177'
178
6130f86d
JK
179test_expect_success 'create namespaced refs' '
180 test_commit namespaced &&
181 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
182 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
183 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
184'
185
186test_expect_success 'smart clone respects namespace' '
187 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
188 echo namespaced >expect &&
189 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
190 test_cmp expect actual
191'
192
193test_expect_success 'dumb clone via http-backend respects namespace' '
194 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
195 config http.getanyfile true &&
196 GIT_SMART_HTTP=0 git clone \
197 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
198 echo namespaced >expect &&
199 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
200 test_cmp expect actual
201'
202
912b2acf
DB
203cat >cookies.txt <<EOF
204127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
205EOF
206cat >expect_cookies.txt <<EOF
912b2acf
DB
207
208127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
209127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
210EOF
211test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
212 git config http.cookiefile cookies.txt &&
213 git config http.savecookies true &&
214 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
60687de5 215 tail -3 cookies.txt >cookies_tail.txt &&
580cf0a0 216 test_cmp expect_cookies.txt cookies_tail.txt
912b2acf
DB
217'
218
e172755b
JK
219test_expect_success 'transfer.hiderefs works over smart-http' '
220 test_commit hidden &&
221 test_commit visible &&
222 git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
223 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
224 config transfer.hiderefs refs/heads/a &&
225 git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
226 test_must_fail git -C hidden.git rev-parse --verify a &&
227 git -C hidden.git rev-parse --verify b
228'
229
cc969c8d
JK
230# create an arbitrary number of tags, numbered from tag-$1 to tag-$2
231create_tags () {
232 rm -f marks &&
233 for i in $(test_seq "$1" "$2")
7103d254 234 do
cc969c8d
JK
235 # don't use here-doc, because it requires a process
236 # per loop iteration
237 echo "commit refs/heads/too-many-refs-$1" &&
238 echo "mark :$i" &&
239 echo "committer git <git@example.com> $i +0000" &&
240 echo "data 0" &&
241 echo "M 644 inline bla.txt" &&
242 echo "data 4" &&
243 echo "bla" &&
7103d254
IT
244 # make every commit dangling by always
245 # rewinding the branch after each commit
cc969c8d
JK
246 echo "reset refs/heads/too-many-refs-$1" &&
247 echo "from :$1"
7103d254
IT
248 done | git fast-import --export-marks=marks &&
249
250 # now assign tags to all the dangling commits we created above
94221d22 251 tag=$(perl -e "print \"bla\" x 30") &&
5e2c7cd2 252 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
cc969c8d
JK
253}
254
7419a03f 255test_expect_success 'create 2,000 tags in the repo' '
cc969c8d
JK
256 (
257 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
7419a03f 258 create_tags 1 2000
7103d254
IT
259 )
260'
261
376e4b39
JK
262test_expect_success CMDLINE_LIMIT \
263 'clone the 2,000 tag repo to check OS command line overflow' '
264 run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
5e2c7cd2
JH
265 (
266 cd too-many-refs &&
376e4b39
JK
267 git for-each-ref refs/tags >actual &&
268 test_line_count = 2000 actual
5e2c7cd2 269 )
7103d254
IT
270'
271
376e4b39 272test_expect_success 'large fetch-pack requests can be split across POSTs' '
14e24114 273 GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
376e4b39 274 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
14e24114 275 grep "^=> Send header: POST" err >posts &&
376e4b39
JK
276 test_line_count = 2 posts
277'
278
6bc0cb51 279test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
7419a03f
JH
280 (
281 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
282 create_tags 2001 50000
283 ) &&
6bc0cb51
JK
284 git -C too-many-refs fetch -q --tags &&
285 (
286 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
287 create_tags 50001 100000
288 ) &&
289 git -C too-many-refs fetch -q --tags &&
290 git -C too-many-refs for-each-ref refs/tags >tags &&
291 test_line_count = 100000 tags
292'
293
8cb01e2f 294test_expect_success 'custom http headers' '
e31165ce
JS
295 test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
296 fetch "$HTTPD_URL/smart_headers/repo.git" &&
8cb01e2f
JS
297 git -c http.extraheader="x-magic-one: abra" \
298 -c http.extraheader="x-magic-two: cadabra" \
0bbe7317
JS
299 fetch "$HTTPD_URL/smart_headers/repo.git" &&
300 git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
301 git config -f .gitmodules submodule.sub.path sub &&
302 git config -f .gitmodules submodule.sub.url \
303 "$HTTPD_URL/smart_headers/repo.git" &&
304 git submodule init sub &&
305 test_must_fail git submodule update sub &&
306 git -c http.extraheader="x-magic-one: abra" \
307 -c http.extraheader="x-magic-two: cadabra" \
308 submodule update sub
8cb01e2f
JS
309'
310
7da4e228
SP
311stop_httpd
312test_done