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
7 skip_all='skipping test, git built without http support'
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' '
16 echo content >file &&
17 git add file &&
18 git commit -m one
19'
20
21test_expect_success 'create http-accessible bare repository' '
22 mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
23 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
24 git --bare init
25 ) &&
26 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27 git push public master:master
28'
29
30setup_askpass_helper
31
32cat >exp <<EOF
33> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
34> Accept: */*
35> Accept-Encoding: gzip
36> Pragma: no-cache
37< HTTP/1.1 200 OK
38< Pragma: no-cache
39< Cache-Control: no-cache, max-age=0, must-revalidate
40< Content-Type: application/x-git-upload-pack-advertisement
41> POST /smart/repo.git/git-upload-pack HTTP/1.1
42> Accept-Encoding: gzip
43> Content-Type: application/x-git-upload-pack-request
44> Accept: application/x-git-upload-pack-result
45> Content-Length: xxx
46< HTTP/1.1 200 OK
47< Pragma: no-cache
48< Cache-Control: no-cache, max-age=0, must-revalidate
49< Content-Type: application/x-git-upload-pack-result
50EOF
51test_expect_success 'clone http repository' '
52 GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
53 test_cmp file clone/file &&
54 tr '\''\015'\'' Q <err |
55 sed -e "
56 s/Q\$//
57 /^[*] /d
58 /^$/d
59 /^< $/d
60
61 /^[^><]/{
62 s/^/> /
63 }
64
65 /^> User-Agent: /d
66 /^> Host: /d
67 /^> POST /,$ {
68 /^> Accept: [*]\\/[*]/d
69 }
70 s/^> Content-Length: .*/> Content-Length: xxx/
71 /^> 00..want /d
72 /^> 00.*done/d
73
74 /^< Server: /d
75 /^< Expires: /d
76 /^< Date: /d
77 /^< Content-Length: /d
78 /^< Transfer-Encoding: /d
79 " >act &&
80 test_cmp exp act
81'
82
83test_expect_success 'fetch changes via http' '
84 echo content >>file &&
85 git commit -a -m two &&
86 git push public
87 (cd clone && git pull) &&
88 test_cmp file clone/file
89'
90
91cat >exp <<EOF
92GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
93POST /smart/repo.git/git-upload-pack HTTP/1.1 200
94GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
95POST /smart/repo.git/git-upload-pack HTTP/1.1 200
96EOF
97test_expect_success 'used upload-pack service' '
98 sed -e "
99 s/^.* \"//
100 s/\"//
101 s/ [1-9][0-9]*\$//
102 s/^GET /GET /
103 " >act <"$HTTPD_ROOT_PATH"/access.log &&
104 test_cmp exp act
105'
106
107test_expect_success 'follow redirects (301)' '
108 git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
109'
110
111test_expect_success 'follow redirects (302)' '
112 git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
113'
114
115test_expect_success 'clone from password-protected repository' '
116 echo two >expect &&
117 set_askpass user@host &&
118 git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
119 expect_askpass both user@host &&
120 git --git-dir=smart-auth log -1 --format=%s >actual &&
121 test_cmp expect actual
122'
123
124test_expect_success 'clone from auth-only-for-push repository' '
125 echo two >expect &&
126 set_askpass wrong &&
127 git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
128 expect_askpass none &&
129 git --git-dir=smart-noauth log -1 --format=%s >actual &&
130 test_cmp expect actual
131'
132
133test_expect_success 'clone from auth-only-for-objects repository' '
134 echo two >expect &&
135 set_askpass user@host &&
136 git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
137 expect_askpass both user@host &&
138 git --git-dir=half-auth log -1 --format=%s >actual &&
139 test_cmp expect actual
140'
141
142test_expect_success 'no-op half-auth fetch does not require a password' '
143 set_askpass wrong &&
144 git --git-dir=half-auth fetch &&
145 expect_askpass none
146'
147
148test_expect_success 'disable dumb http on server' '
149 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
150 config http.getanyfile false
151'
152
153test_expect_success 'GIT_SMART_HTTP can disable smart http' '
154 (GIT_SMART_HTTP=0 &&
155 export GIT_SMART_HTTP &&
156 cd clone &&
157 test_must_fail git fetch)
158'
159
160test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
161
162test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
163 (
164 cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
165 for i in `test_seq 50000`
166 do
167 echo "commit refs/heads/too-many-refs"
168 echo "mark :$i"
169 echo "committer git <git@example.com> $i +0000"
170 echo "data 0"
171 echo "M 644 inline bla.txt"
172 echo "data 4"
173 echo "bla"
174 # make every commit dangling by always
175 # rewinding the branch after each commit
176 echo "reset refs/heads/too-many-refs"
177 echo "from :1"
178 done | git fast-import --export-marks=marks &&
179
180 # now assign tags to all the dangling commits we created above
181 tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
182 sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
183 )
184'
185
186test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
187 git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
188 test_line_count = 0 err
189'
190
191stop_httpd
192test_done