http: add http.savecookies option to write out HTTP cookies
[git/git.git] / t / t5551-http-fetch.sh
CommitLineData
7da4e228
SP
1#!/bin/sh
2
3test_description='test smart fetching over http via http-backend'
4. ./test-lib.sh
5
6if test -n "$NO_CURL"; then
fadb5156 7 skip_all='skipping test, git built without http support'
7da4e228
SP
8 test_done
9fi
10
11LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'}
12. "$TEST_DIRECTORY"/lib-httpd.sh
13start_httpd
14
15test_expect_success 'setup repository' '
bd7ac599 16 git config push.default matching &&
7da4e228
SP
17 echo content >file &&
18 git add file &&
19 git commit -m one
20'
21
22test_expect_success 'create http-accessible bare repository' '
23 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
24 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
25 git --bare init
26 ) &&
27 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28 git push public master:master
29'
30
6ac2b3ae
JK
31setup_askpass_helper
32
7da4e228
SP
33cat >exp <<EOF
34> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
35> Accept: */*
aa90b969 36> Accept-Encoding: gzip
7da4e228 37> Pragma: no-cache
7da4e228
SP
38< HTTP/1.1 200 OK
39< Pragma: no-cache
40< Cache-Control: no-cache, max-age=0, must-revalidate
41< Content-Type: application/x-git-upload-pack-advertisement
7da4e228 42> POST /smart/repo.git/git-upload-pack HTTP/1.1
aa90b969 43> Accept-Encoding: gzip
7da4e228 44> Content-Type: application/x-git-upload-pack-request
8efa5f62 45> Accept: application/x-git-upload-pack-result
7da4e228 46> Content-Length: xxx
7da4e228
SP
47< HTTP/1.1 200 OK
48< Pragma: no-cache
49< Cache-Control: no-cache, max-age=0, must-revalidate
50< Content-Type: application/x-git-upload-pack-result
7da4e228
SP
51EOF
52test_expect_success 'clone http repository' '
53 GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
54 test_cmp file clone/file &&
55 tr '\''\015'\'' Q <err |
56 sed -e "
57 s/Q\$//
58 /^[*] /d
0a8fcbdc
SP
59 /^$/d
60 /^< $/d
7da4e228
SP
61
62 /^[^><]/{
63 s/^/> /
64 }
65
66 /^> User-Agent: /d
67 /^> Host: /d
20366635
SP
68 /^> POST /,$ {
69 /^> Accept: [*]\\/[*]/d
70 }
7da4e228 71 s/^> Content-Length: .*/> Content-Length: xxx/
0a8fcbdc
SP
72 /^> 00..want /d
73 /^> 00.*done/d
7da4e228
SP
74
75 /^< Server: /d
76 /^< Expires: /d
77 /^< Date: /d
78 /^< Content-Length: /d
79 /^< Transfer-Encoding: /d
80 " >act &&
81 test_cmp exp act
82'
83
84test_expect_success 'fetch changes via http' '
85 echo content >>file &&
86 git commit -a -m two &&
87 git push public
88 (cd clone && git pull) &&
89 test_cmp file clone/file
90'
91
92cat >exp <<EOF
93GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
94POST /smart/repo.git/git-upload-pack HTTP/1.1 200
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
97EOF
98test_expect_success 'used upload-pack service' '
99 sed -e "
100 s/^.* \"//
101 s/\"//
102 s/ [1-9][0-9]*\$//
103 s/^GET /GET /
104 " >act <"$HTTPD_ROOT_PATH"/access.log &&
105 test_cmp exp act
106'
107
311e2ea0
TRC
108test_expect_success 'follow redirects (301)' '
109 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
110'
111
112test_expect_success 'follow redirects (302)' '
113 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
114'
115
6ac2b3ae
JK
116test_expect_success 'clone from password-protected repository' '
117 echo two >expect &&
118 set_askpass user@host &&
119 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
120 expect_askpass both user@host &&
121 git --git-dir=smart-auth log -1 --format=%s >actual &&
122 test_cmp expect actual
123'
124
4c71009d
JK
125test_expect_success 'clone from auth-only-for-push repository' '
126 echo two >expect &&
127 set_askpass wrong &&
128 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
129 expect_askpass none &&
130 git --git-dir=smart-noauth log -1 --format=%s >actual &&
131 test_cmp expect actual
132'
133
2e736fd5
JK
134test_expect_success 'clone from auth-only-for-objects repository' '
135 echo two >expect &&
136 set_askpass user@host &&
137 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
138 expect_askpass both user@host &&
139 git --git-dir=half-auth log -1 --format=%s >actual &&
140 test_cmp expect actual
141'
142
143test_expect_success 'no-op half-auth fetch does not require a password' '
144 set_askpass wrong &&
145 git --git-dir=half-auth fetch &&
146 expect_askpass none
147'
148
02572c2e
JK
149test_expect_success 'disable dumb http on server' '
150 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
151 config http.getanyfile false
152'
153
154test_expect_success 'GIT_SMART_HTTP can disable smart http' '
155 (GIT_SMART_HTTP=0 &&
156 export GIT_SMART_HTTP &&
157 cd clone &&
158 test_must_fail git fetch)
159'
160
4656bf47 161test_expect_success 'invalid Content-Type rejected' '
4656bf47 162 test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual
af3aec44 163 grep "not valid:" actual
4656bf47
SP
164'
165
6130f86d
JK
166test_expect_success 'create namespaced refs' '
167 test_commit namespaced &&
168 git push public HEAD:refs/namespaces/ns/refs/heads/master &&
169 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
170 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
171'
172
173test_expect_success 'smart clone respects namespace' '
174 git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
175 echo namespaced >expect &&
176 git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
177 test_cmp expect actual
178'
179
180test_expect_success 'dumb clone via http-backend respects namespace' '
181 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
182 config http.getanyfile true &&
183 GIT_SMART_HTTP=0 git clone \
184 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
185 echo namespaced >expect &&
186 git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
187 test_cmp expect actual
188'
189
912b2acf
DB
190cat >cookies.txt <<EOF
191127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
192EOF
193cat >expect_cookies.txt <<EOF
194# Netscape HTTP Cookie File
195# http://curl.haxx.se/docs/http-cookies.html
196# This file was generated by libcurl! Edit at your own risk.
197
198127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
199127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
200EOF
201test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
202 git config http.cookiefile cookies.txt &&
203 git config http.savecookies true &&
204 git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
205 test_cmp expect_cookies.txt cookies.txt
206'
207
7103d254
IT
208test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
209
210test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
211 (
212 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
d17cf5f3 213 for i in `test_seq 50000`
7103d254
IT
214 do
215 echo "commit refs/heads/too-many-refs"
216 echo "mark :$i"
217 echo "committer git <git@example.com> $i +0000"
218 echo "data 0"
219 echo "M 644 inline bla.txt"
220 echo "data 4"
221 echo "bla"
222 # make every commit dangling by always
223 # rewinding the branch after each commit
224 echo "reset refs/heads/too-many-refs"
225 echo "from :1"
226 done | git fast-import --export-marks=marks &&
227
228 # now assign tags to all the dangling commits we created above
7096b648 229 tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
5e2c7cd2 230 sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
7103d254
IT
231 )
232'
233
234test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
235 git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
5e2c7cd2
JH
236 test_line_count = 0 err &&
237 (
238 cd too-many-refs &&
239 test $(git for-each-ref refs/tags | wc -l) = 50000
240 )
7103d254
IT
241'
242
7da4e228
SP
243stop_httpd
244test_done