@matheusbsbs / matheus-bagliano / commits / 7f640b778f
Fork 0

http-backend: Test configuration options

Test the major configuration settings which control access to the repository: http.getanyfile http.uploadpack http.receivepack Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Nov 4, 2009 at 17:16 UTC 7f640b778f8cf87159890157a815f1d728573477
1 file changed +229
t/t5560-http-backend.sh new
+229
@@ -0,0 +1,229 @@
1 +#!/bin/sh
2 +
3 +test_description='test git-http-backend'
4 +. ./test-lib.sh
5 +
6 +if test -n "$NO_CURL"; then
7 + say 'skipping test, git built without http support'
8 + test_done
9 +fi
10 +
11 +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5560'}
12 +. "$TEST_DIRECTORY"/lib-httpd.sh
13 +start_httpd
14 +
15 +find_file() {
16 + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
17 + find $1 -type f |
18 + sed -e 1q
19 +}
20 +
21 +config() {
22 + git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" config $1 $2
23 +}
24 +
25 +GET() {
26 + curl --include "$HTTPD_URL/smart/repo.git/$1" >out 2>/dev/null &&
27 + tr '\015' Q <out |
28 + sed '
29 + s/Q$//
30 + 1q
31 + ' >act &&
32 + echo "HTTP/1.1 $2" >exp &&
33 + test_cmp exp act
34 +}
35 +
36 +POST() {
37 + curl --include --data "$2" \
38 + --header "Content-Type: application/x-$1-request" \
39 + "$HTTPD_URL/smart/repo.git/$1" >out 2>/dev/null &&
40 + tr '\015' Q <out |
41 + sed '
42 + s/Q$//
43 + 1q
44 + ' >act &&
45 + echo "HTTP/1.1 $3" >exp &&
46 + test_cmp exp act
47 +}
48 +
49 +log_div() {
50 + echo >>"$HTTPD_ROOT_PATH"/access.log
51 + echo "### $1" >>"$HTTPD_ROOT_PATH"/access.log
52 + echo "###" >>"$HTTPD_ROOT_PATH"/access.log
53 +}
54 +
55 +test_expect_success 'setup repository' '
56 + echo content >file &&
57 + git add file &&
58 + git commit -m one &&
59 +
60 + mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
61 + (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
62 + git --bare init &&
63 + : >objects/info/alternates &&
64 + : >objects/info/http-alternates
65 + ) &&
66 + git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
67 + git push public master:master &&
68 +
69 + (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
70 + git repack -a -d
71 + ) &&
72 +
73 + echo other >file &&
74 + git add file &&
75 + git commit -m two &&
76 + git push public master:master &&
77 +
78 + LOOSE_URL=$(find_file objects/??) &&
79 + PACK_URL=$(find_file objects/pack/*.pack) &&
80 + IDX_URL=$(find_file objects/pack/*.idx)
81 +'
82 +
83 +get_static_files() {
84 + GET HEAD "$1" &&
85 + GET info/refs "$1" &&
86 + GET objects/info/packs "$1" &&
87 + GET objects/info/alternates "$1" &&
88 + GET objects/info/http-alternates "$1" &&
89 + GET $LOOSE_URL "$1" &&
90 + GET $PACK_URL "$1" &&
91 + GET $IDX_URL "$1"
92 +}
93 +
94 +test_expect_success 'direct refs/heads/master not found' '
95 + log_div "refs/heads/master"
96 + GET refs/heads/master "404 Not Found"
97 +'
98 +test_expect_success 'static file is ok' '
99 + log_div "getanyfile default"
100 + get_static_files "200 OK"
101 +'
102 +test_expect_success 'static file if http.getanyfile true is ok' '
103 + log_div "getanyfile true"
104 + config http.getanyfile true &&
105 + get_static_files "200 OK"
106 +'
107 +test_expect_success 'static file if http.getanyfile false fails' '
108 + log_div "getanyfile false"
109 + config http.getanyfile false &&
110 + get_static_files "403 Forbidden"
111 +'
112 +
113 +test_expect_success 'http.uploadpack default enabled' '
114 + log_div "uploadpack default"
115 + GET info/refs?service=git-upload-pack "200 OK" &&
116 + POST git-upload-pack 0000 "200 OK"
117 +'
118 +test_expect_success 'http.uploadpack true' '
119 + log_div "uploadpack true"
120 + config http.uploadpack true &&
121 + GET info/refs?service=git-upload-pack "200 OK" &&
122 + POST git-upload-pack 0000 "200 OK"
123 +'
124 +test_expect_success 'http.uploadpack false' '
125 + log_div "uploadpack false"
126 + config http.uploadpack false &&
127 + GET info/refs?service=git-upload-pack "403 Forbidden" &&
128 + POST git-upload-pack 0000 "403 Forbidden"
129 +'
130 +
131 +test_expect_success 'http.receivepack default disabled' '
132 + log_div "receivepack default"
133 + GET info/refs?service=git-receive-pack "403 Forbidden" &&
134 + POST git-receive-pack 0000 "403 Forbidden"
135 +'
136 +test_expect_success 'http.receivepack true' '
137 + log_div "receivepack true"
138 + config http.receivepack true &&
139 + GET info/refs?service=git-receive-pack "200 OK" &&
140 + POST git-receive-pack 0000 "200 OK"
141 +'
142 +test_expect_success 'http.receivepack false' '
143 + log_div "receivepack false"
144 + config http.receivepack false &&
145 + GET info/refs?service=git-receive-pack "403 Forbidden" &&
146 + POST git-receive-pack 0000 "403 Forbidden"
147 +'
148 +
149 +cat >exp <<EOF
150 +
151 +### refs/heads/master
152 +###
153 +GET /smart/repo.git/refs/heads/master HTTP/1.1 404 -
154 +
155 +### getanyfile default
156 +###
157 +GET /smart/repo.git/HEAD HTTP/1.1 200
158 +GET /smart/repo.git/info/refs HTTP/1.1 200
159 +GET /smart/repo.git/objects/info/packs HTTP/1.1 200
160 +GET /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
161 +GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
162 +GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
163 +GET /smart/repo.git/$PACK_URL HTTP/1.1 200
164 +GET /smart/repo.git/$IDX_URL HTTP/1.1 200
165 +
166 +### getanyfile true
167 +###
168 +GET /smart/repo.git/HEAD HTTP/1.1 200
169 +GET /smart/repo.git/info/refs HTTP/1.1 200
170 +GET /smart/repo.git/objects/info/packs HTTP/1.1 200
171 +GET /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
172 +GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
173 +GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
174 +GET /smart/repo.git/$PACK_URL HTTP/1.1 200
175 +GET /smart/repo.git/$IDX_URL HTTP/1.1 200
176 +
177 +### getanyfile false
178 +###
179 +GET /smart/repo.git/HEAD HTTP/1.1 403 -
180 +GET /smart/repo.git/info/refs HTTP/1.1 403 -
181 +GET /smart/repo.git/objects/info/packs HTTP/1.1 403 -
182 +GET /smart/repo.git/objects/info/alternates HTTP/1.1 403 -
183 +GET /smart/repo.git/objects/info/http-alternates HTTP/1.1 403 -
184 +GET /smart/repo.git/$LOOSE_URL HTTP/1.1 403 -
185 +GET /smart/repo.git/$PACK_URL HTTP/1.1 403 -
186 +GET /smart/repo.git/$IDX_URL HTTP/1.1 403 -
187 +
188 +### uploadpack default
189 +###
190 +GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
191 +POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
192 +
193 +### uploadpack true
194 +###
195 +GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
196 +POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
197 +
198 +### uploadpack false
199 +###
200 +GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 403 -
201 +POST /smart/repo.git/git-upload-pack HTTP/1.1 403 -
202 +
203 +### receivepack default
204 +###
205 +GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
206 +POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
207 +
208 +### receivepack true
209 +###
210 +GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
211 +POST /smart/repo.git/git-receive-pack HTTP/1.1 200 -
212 +
213 +### receivepack false
214 +###
215 +GET /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
216 +POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
217 +EOF
218 +test_expect_success 'server request log matches test results' '
219 + sed -e "
220 + s/^.* \"//
221 + s/\"//
222 + s/ [1-9][0-9]*\$//
223 + s/^GET /GET /
224 + " >act <"$HTTPD_ROOT_PATH"/access.log &&
225 + test_cmp exp act
226 +'
227 +
228 +stop_httpd
229 +test_done