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