test: remove httpd tests that ask for user
[git] / t / t5551-http-fetch-smart.sh
1 #!/bin/sh
2
3 test_description='test smart fetching over http via http-backend'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-httpd.sh
6 start_httpd
7
8 test_expect_success 'setup repository' '
9         git config push.default matching &&
10         echo content >file &&
11         git add file &&
12         git commit -m one
13 '
14
15 test_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
24 setup_askpass_helper
25
26 cat >exp <<EOF
27 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
28 > Accept: */*
29 > Accept-Encoding: gzip
30 > Pragma: no-cache
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
35 > POST /smart/repo.git/git-upload-pack HTTP/1.1
36 > Accept-Encoding: gzip
37 > Content-Type: application/x-git-upload-pack-request
38 > Accept: application/x-git-upload-pack-result
39 > Content-Length: xxx
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
44 EOF
45 test_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
52                 /^$/d
53                 /^< $/d
54
55                 /^[^><]/{
56                         s/^/> /
57                 }
58
59                 /^> User-Agent: /d
60                 /^> Host: /d
61                 /^> POST /,$ {
62                         /^> Accept: [*]\\/[*]/d
63                 }
64                 s/^> Content-Length: .*/> Content-Length: xxx/
65                 /^> 00..want /d
66                 /^> 00.*done/d
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
77 test_expect_success 'fetch changes via http' '
78         echo content >>file &&
79         git commit -a -m two &&
80         git push public &&
81         (cd clone && git pull) &&
82         test_cmp file clone/file
83 '
84
85 cat >exp <<EOF
86 GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
87 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
88 GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
89 POST /smart/repo.git/git-upload-pack HTTP/1.1 200
90 EOF
91 test_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
101 test_expect_success 'follow redirects (301)' '
102         git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
103 '
104
105 test_expect_success 'follow redirects (302)' '
106         git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
107 '
108
109 test_expect_success 'redirects re-root further requests' '
110         git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
111 '
112
113 test_expect_success 'clone from auth-only-for-push repository' '
114         echo two >expect &&
115         set_askpass wrong &&
116         git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
117         expect_askpass none &&
118         git --git-dir=smart-noauth log -1 --format=%s >actual &&
119         test_cmp expect actual
120 '
121
122 test_expect_success 'disable dumb http on server' '
123         git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
124                 config http.getanyfile false
125 '
126
127 test_expect_success 'GIT_SMART_HTTP can disable smart http' '
128         (GIT_SMART_HTTP=0 &&
129          export GIT_SMART_HTTP &&
130          cd clone &&
131          test_must_fail git fetch)
132 '
133
134 test_expect_success 'invalid Content-Type rejected' '
135         test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
136         grep "not valid:" actual
137 '
138
139 test_expect_success 'create namespaced refs' '
140         test_commit namespaced &&
141         git push public HEAD:refs/namespaces/ns/refs/heads/master &&
142         git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
143                 symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
144 '
145
146 test_expect_success 'smart clone respects namespace' '
147         git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
148         echo namespaced >expect &&
149         git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
150         test_cmp expect actual
151 '
152
153 test_expect_success 'dumb clone via http-backend respects namespace' '
154         git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
155                 config http.getanyfile true &&
156         GIT_SMART_HTTP=0 git clone \
157                 "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
158         echo namespaced >expect &&
159         git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
160         test_cmp expect actual
161 '
162
163 cat >cookies.txt <<EOF
164 127.0.0.1       FALSE   /smart_cookies/ FALSE   0       othername       othervalue
165 EOF
166 cat >expect_cookies.txt <<EOF
167
168 127.0.0.1       FALSE   /smart_cookies/ FALSE   0       othername       othervalue
169 127.0.0.1       FALSE   /smart_cookies/repo.git/info/   FALSE   0       name    value
170 EOF
171 test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
172         git config http.cookiefile cookies.txt &&
173         git config http.savecookies true &&
174         git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
175         tail -3 cookies.txt >cookies_tail.txt &&
176         test_cmp expect_cookies.txt cookies_tail.txt
177 '
178
179 test_expect_success 'transfer.hiderefs works over smart-http' '
180         test_commit hidden &&
181         test_commit visible &&
182         git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
183         git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
184                 config transfer.hiderefs refs/heads/a &&
185         git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
186         test_must_fail git -C hidden.git rev-parse --verify a &&
187         git -C hidden.git rev-parse --verify b
188 '
189
190 # create an arbitrary number of tags, numbered from tag-$1 to tag-$2
191 create_tags () {
192         rm -f marks &&
193         for i in $(test_seq "$1" "$2")
194         do
195                 # don't use here-doc, because it requires a process
196                 # per loop iteration
197                 echo "commit refs/heads/too-many-refs-$1" &&
198                 echo "mark :$i" &&
199                 echo "committer git <git@example.com> $i +0000" &&
200                 echo "data 0" &&
201                 echo "M 644 inline bla.txt" &&
202                 echo "data 4" &&
203                 echo "bla" &&
204                 # make every commit dangling by always
205                 # rewinding the branch after each commit
206                 echo "reset refs/heads/too-many-refs-$1" &&
207                 echo "from :$1"
208         done | git fast-import --export-marks=marks &&
209
210         # now assign tags to all the dangling commits we created above
211         tag=$(perl -e "print \"bla\" x 30") &&
212         sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
213 }
214
215 test_expect_success 'create 2,000 tags in the repo' '
216         (
217                 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
218                 create_tags 1 2000
219         )
220 '
221
222 test_expect_success CMDLINE_LIMIT \
223         'clone the 2,000 tag repo to check OS command line overflow' '
224         run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
225         (
226                 cd too-many-refs &&
227                 git for-each-ref refs/tags >actual &&
228                 test_line_count = 2000 actual
229         )
230 '
231
232 test_expect_success 'large fetch-pack requests can be split across POSTs' '
233         GIT_CURL_VERBOSE=1 git -c http.postbuffer=65536 \
234                 clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
235         grep "^> POST" err >posts &&
236         test_line_count = 2 posts
237 '
238
239 test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
240         (
241                 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
242                 create_tags 2001 50000
243         ) &&
244         git -C too-many-refs fetch -q --tags &&
245         (
246                 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
247                 create_tags 50001 100000
248         ) &&
249         git -C too-many-refs fetch -q --tags &&
250         git -C too-many-refs for-each-ref refs/tags >tags &&
251         test_line_count = 100000 tags
252 '
253
254 stop_httpd
255 test_done