]>
Commit | Line | Data |
---|---|---|
c74c7203 JN |
1 | # Shell library to run an HTTP server for use in tests. |
2 | # Ends the test early if httpd tests should not be run, | |
3 | # for example because the user has not enabled them. | |
4 | # | |
5 | # Usage: | |
6 | # | |
7 | # . ./test-lib.sh | |
8 | # . "$TEST_DIRECTORY"/lib-httpd.sh | |
9 | # start_httpd | |
10 | # | |
11 | # test_expect_success '...' ' | |
12 | # ... | |
13 | # ' | |
14 | # | |
15 | # test_expect_success ... | |
16 | # | |
c74c7203 JN |
17 | # test_done |
18 | # | |
19 | # Can be configured using the following variables. | |
20 | # | |
21 | # GIT_TEST_HTTPD enable HTTPD tests | |
22 | # LIB_HTTPD_PATH web server path | |
23 | # LIB_HTTPD_MODULE_PATH web server modules path | |
24 | # LIB_HTTPD_PORT listening port | |
25 | # LIB_HTTPD_DAV enable DAV | |
a8a5d251 | 26 | # LIB_HTTPD_SVN enable SVN at given location (e.g. "svn") |
c74c7203 | 27 | # LIB_HTTPD_SSL enable SSL |
faa4bc35 CB |
28 | # |
29 | # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> | |
30 | # | |
31 | ||
7596fe95 | 32 | if ! test_have_prereq LIBCURL |
c9d441a8 JK |
33 | then |
34 | skip_all='skipping test, git built without http support' | |
35 | test_done | |
36 | fi | |
37 | ||
309a9e33 JH |
38 | if test -n "$NO_EXPAT" && test -n "$LIB_HTTPD_DAV" |
39 | then | |
40 | skip_all='skipping test, git built without expat support' | |
41 | test_done | |
42 | fi | |
43 | ||
43a2afee | 44 | if ! test_bool_env GIT_TEST_HTTPD true |
faa4bc35 | 45 | then |
83d842dc | 46 | skip_all="Network testing disabled (unset GIT_TEST_HTTPD to enable)" |
faa4bc35 | 47 | test_done |
faa4bc35 CB |
48 | fi |
49 | ||
1767c517 | 50 | if ! test_have_prereq NOT_ROOT; then |
3b072c57 | 51 | test_skip_or_die GIT_TEST_HTTPD \ |
a1a30111 JK |
52 | "Cannot run httpd tests as root" |
53 | fi | |
54 | ||
69707d61 JS |
55 | HTTPD_PARA="" |
56 | ||
0d344738 TC |
57 | for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2' |
58 | do | |
59 | if test -x "$DEFAULT_HTTPD_PATH" | |
60 | then | |
61 | break | |
62 | fi | |
63 | done | |
64 | ||
65 | for DEFAULT_HTTPD_MODULE_PATH in '/usr/libexec/apache2' \ | |
66 | '/usr/lib/apache2/modules' \ | |
67 | '/usr/lib64/httpd/modules' \ | |
1c7dc23d ES |
68 | '/usr/lib/httpd/modules' \ |
69 | '/usr/libexec/httpd' | |
0d344738 TC |
70 | do |
71 | if test -d "$DEFAULT_HTTPD_MODULE_PATH" | |
72 | then | |
73 | break | |
74 | fi | |
75 | done | |
76 | ||
69707d61 JS |
77 | case $(uname) in |
78 | Darwin) | |
69707d61 JS |
79 | HTTPD_PARA="$HTTPD_PARA -DDarwin" |
80 | ;; | |
69707d61 JS |
81 | esac |
82 | ||
83 | LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"} | |
fa840581 | 84 | test_set_port LIB_HTTPD_PORT |
faa4bc35 | 85 | |
bfdbee98 | 86 | TEST_PATH="$TEST_DIRECTORY"/lib-httpd |
faa4bc35 CB |
87 | HTTPD_ROOT_PATH="$PWD"/httpd |
88 | HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www | |
89 | ||
f6288254 JK |
90 | # hack to suppress apache PassEnv warnings |
91 | GIT_VALGRIND=$GIT_VALGRIND; export GIT_VALGRIND | |
92 | GIT_VALGRIND_OPTIONS=$GIT_VALGRIND_OPTIONS; export GIT_VALGRIND_OPTIONS | |
e18edc76 | 93 | GIT_TEST_SIDEBAND_ALL=$GIT_TEST_SIDEBAND_ALL; export GIT_TEST_SIDEBAND_ALL |
89c57ab3 | 94 | GIT_TRACE=$GIT_TRACE; export GIT_TRACE |
f6288254 | 95 | |
faa4bc35 CB |
96 | if ! test -x "$LIB_HTTPD_PATH" |
97 | then | |
3b072c57 | 98 | test_skip_or_die GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'" |
faa4bc35 CB |
99 | fi |
100 | ||
e429dfd5 EP |
101 | HTTPD_VERSION=$($LIB_HTTPD_PATH -v | \ |
102 | sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q') | |
faa4bc35 CB |
103 | |
104 | if test -n "$HTTPD_VERSION" | |
105 | then | |
106 | if test -z "$LIB_HTTPD_MODULE_PATH" | |
107 | then | |
108 | if ! test $HTTPD_VERSION -ge 2 | |
109 | then | |
3b072c57 | 110 | test_skip_or_die GIT_TEST_HTTPD \ |
83d842dc | 111 | "at least Apache version 2 is required" |
faa4bc35 | 112 | fi |
0d344738 TC |
113 | if ! test -d "$DEFAULT_HTTPD_MODULE_PATH" |
114 | then | |
3b072c57 | 115 | test_skip_or_die GIT_TEST_HTTPD \ |
83d842dc | 116 | "Apache module directory not found" |
0d344738 | 117 | fi |
faa4bc35 | 118 | |
69707d61 | 119 | LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH" |
faa4bc35 CB |
120 | fi |
121 | else | |
3b072c57 | 122 | test_skip_or_die GIT_TEST_HTTPD \ |
83d842dc | 123 | "Could not identify web server at '$LIB_HTTPD_PATH'" |
faa4bc35 CB |
124 | fi |
125 | ||
c7db2d16 JK |
126 | install_script () { |
127 | write_script "$HTTPD_ROOT_PATH/$1" <"$TEST_PATH/$1" | |
128 | } | |
129 | ||
faa4bc35 | 130 | prepare_httpd() { |
13b5481e | 131 | mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" |
3cf8fe1d | 132 | cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" |
74b082ad DL |
133 | install_script incomplete-length-upload-pack-v2-http.sh |
134 | install_script incomplete-body-upload-pack-v2-http.sh | |
e4c9538a | 135 | install_script error-no-report.sh |
c7db2d16 | 136 | install_script broken-smart-http.sh |
30dea565 | 137 | install_script error-smart-http.sh |
dbcf2bd3 | 138 | install_script error.sh |
eafff6e4 | 139 | install_script apply-one-time-perl.sh |
988aad99 | 140 | install_script nph-custom-auth.sh |
faa4bc35 | 141 | |
13b5481e | 142 | ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules" |
faa4bc35 CB |
143 | |
144 | if test -n "$LIB_HTTPD_SSL" | |
145 | then | |
5232586c | 146 | HTTPD_PROTO=https |
faa4bc35 CB |
147 | |
148 | RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \ | |
13b5481e | 149 | -config "$TEST_PATH/ssl.cnf" \ |
faa4bc35 | 150 | -new -x509 -nodes \ |
13b5481e MH |
151 | -out "$HTTPD_ROOT_PATH/httpd.pem" \ |
152 | -keyout "$HTTPD_ROOT_PATH/httpd.pem" | |
0e46e704 BD |
153 | GIT_SSL_NO_VERIFY=t |
154 | export GIT_SSL_NO_VERIFY | |
faa4bc35 CB |
155 | HTTPD_PARA="$HTTPD_PARA -DSSL" |
156 | else | |
5232586c | 157 | HTTPD_PROTO=http |
faa4bc35 | 158 | fi |
5232586c JK |
159 | HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT |
160 | HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST | |
161 | HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST | |
afbf5ca5 | 162 | HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST |
faa4bc35 | 163 | |
ce5dadb6 | 164 | if test -n "$LIB_HTTPD_DAV" || test -n "$LIB_HTTPD_SVN" |
faa4bc35 CB |
165 | then |
166 | HTTPD_PARA="$HTTPD_PARA -DDAV" | |
167 | ||
168 | if test -n "$LIB_HTTPD_SVN" | |
169 | then | |
170 | HTTPD_PARA="$HTTPD_PARA -DSVN" | |
a8a5d251 EW |
171 | LIB_HTTPD_SVNPATH="$rawsvnrepo" |
172 | svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/" | |
173 | svnrepo="$svnrepo$LIB_HTTPD_SVN" | |
174 | export LIB_HTTPD_SVN LIB_HTTPD_SVNPATH | |
faa4bc35 CB |
175 | fi |
176 | fi | |
177 | } | |
178 | ||
73c49a44 JK |
179 | enable_http2 () { |
180 | HTTPD_PARA="$HTTPD_PARA -DHTTP2" | |
181 | test_set_prereq HTTP2 | |
182 | } | |
183 | ||
eb1c42da JK |
184 | enable_cgipassauth () { |
185 | # We are looking for 2.4.13 or more recent. Since we only support | |
186 | # 2.4 and up, no need to check for older major/minor. | |
187 | if test "$HTTPD_VERSION_MAJOR" = 2 && | |
188 | test "$HTTPD_VERSION_MINOR" = 4 && | |
189 | test "$(echo $HTTPD_VERSION | cut -d. -f3)" -lt 13 | |
190 | then | |
191 | echo >&4 "apache $HTTPD_VERSION too old for CGIPassAuth" | |
192 | return | |
193 | fi | |
194 | HTTPD_PARA="$HTTPD_PARA -DUSE_CGIPASSAUTH" | |
195 | test_set_prereq CGIPASSAUTH | |
196 | } | |
197 | ||
faa4bc35 | 198 | start_httpd() { |
75318a3b | 199 | prepare_httpd >&3 2>&4 |
faa4bc35 | 200 | |
8c3b9f7f | 201 | test_atexit stop_httpd |
faa4bc35 | 202 | |
13b5481e MH |
203 | "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ |
204 | -f "$TEST_PATH/apache.conf" $HTTPD_PARA \ | |
75318a3b JK |
205 | -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \ |
206 | >&3 2>&4 | |
a5adcbe3 CB |
207 | if test $? -ne 0 |
208 | then | |
44f243d3 | 209 | cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null |
3b072c57 | 210 | test_skip_or_die GIT_TEST_HTTPD "web server setup failed" |
75318a3b | 211 | fi |
faa4bc35 CB |
212 | } |
213 | ||
214 | stop_httpd() { | |
13b5481e | 215 | "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ |
69707d61 | 216 | -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop |
faa4bc35 | 217 | } |
6cbd6e92 | 218 | |
05c1eb10 | 219 | test_http_push_nonff () { |
6cbd6e92 TRC |
220 | REMOTE_REPO=$1 |
221 | LOCAL_REPO=$2 | |
222 | BRANCH=$3 | |
05c1eb10 | 223 | EXPECT_CAS_RESULT=${4-failure} |
6cbd6e92 TRC |
224 | |
225 | test_expect_success 'non-fast-forward push fails' ' | |
226 | cd "$REMOTE_REPO" && | |
227 | HEAD=$(git rev-parse --verify HEAD) && | |
228 | ||
229 | cd "$LOCAL_REPO" && | |
230 | git checkout $BRANCH && | |
231 | echo "changed" > path2 && | |
232 | git commit -a -m path2 --amend && | |
233 | ||
77b5be2a | 234 | test_must_fail git push -v origin >output 2>&1 && |
6cbd6e92 TRC |
235 | (cd "$REMOTE_REPO" && |
236 | test $HEAD = $(git rev-parse --verify HEAD)) | |
237 | ' | |
238 | ||
239 | test_expect_success 'non-fast-forward push show ref status' ' | |
240 | grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output | |
241 | ' | |
242 | ||
d3bd0425 | 243 | test_expect_success 'non-fast-forward push shows help message' ' |
0aff719f | 244 | test_i18ngrep "Updates were rejected because" output |
6cbd6e92 | 245 | ' |
e69fa70f | 246 | |
42aa29ee | 247 | test_expect_${EXPECT_CAS_RESULT} 'force with lease aka cas' ' |
e69fa70f JH |
248 | HEAD=$( cd "$REMOTE_REPO" && git rev-parse --verify HEAD ) && |
249 | test_when_finished '\'' | |
250 | (cd "$REMOTE_REPO" && git update-ref HEAD "$HEAD") | |
251 | '\'' && | |
252 | ( | |
253 | cd "$LOCAL_REPO" && | |
254 | git push -v --force-with-lease=$BRANCH:$HEAD origin | |
255 | ) && | |
256 | git rev-parse --verify "$BRANCH" >expect && | |
257 | ( | |
258 | cd "$REMOTE_REPO" && git rev-parse --verify HEAD | |
259 | ) >actual && | |
260 | test_cmp expect actual | |
261 | ' | |
6cbd6e92 | 262 | } |
e837936c JK |
263 | |
264 | setup_askpass_helper() { | |
265 | test_expect_success 'setup askpass helper' ' | |
266 | write_script "$TRASH_DIRECTORY/askpass" <<-\EOF && | |
267 | echo >>"$TRASH_DIRECTORY/askpass-query" "askpass: $*" && | |
afbf5ca5 JK |
268 | case "$*" in |
269 | *Username*) | |
270 | what=user | |
271 | ;; | |
272 | *Password*) | |
273 | what=pass | |
274 | ;; | |
275 | esac && | |
276 | cat "$TRASH_DIRECTORY/askpass-$what" | |
e837936c JK |
277 | EOF |
278 | GIT_ASKPASS="$TRASH_DIRECTORY/askpass" && | |
279 | export GIT_ASKPASS && | |
280 | export TRASH_DIRECTORY | |
281 | ' | |
282 | } | |
283 | ||
284 | set_askpass() { | |
285 | >"$TRASH_DIRECTORY/askpass-query" && | |
afbf5ca5 JK |
286 | echo "$1" >"$TRASH_DIRECTORY/askpass-user" && |
287 | echo "$2" >"$TRASH_DIRECTORY/askpass-pass" | |
e837936c JK |
288 | } |
289 | ||
290 | expect_askpass() { | |
050ef365 JK |
291 | dest=$HTTPD_DEST${3+/$3} |
292 | ||
e837936c JK |
293 | { |
294 | case "$1" in | |
295 | none) | |
296 | ;; | |
297 | pass) | |
298 | echo "askpass: Password for 'http://$2@$dest': " | |
299 | ;; | |
300 | both) | |
301 | echo "askpass: Username for 'http://$dest': " | |
302 | echo "askpass: Password for 'http://$2@$dest': " | |
303 | ;; | |
304 | *) | |
305 | false | |
306 | ;; | |
307 | esac | |
308 | } >"$TRASH_DIRECTORY/askpass-expect" && | |
309 | test_cmp "$TRASH_DIRECTORY/askpass-expect" \ | |
310 | "$TRASH_DIRECTORY/askpass-query" | |
311 | } | |
6940a060 SG |
312 | |
313 | strip_access_log() { | |
314 | sed -e " | |
315 | s/^.* \"// | |
316 | s/\"// | |
317 | s/ [1-9][0-9]*\$// | |
318 | s/^GET /GET / | |
319 | " "$HTTPD_ROOT_PATH"/access.log | |
320 | } | |
e8b3b2e2 SG |
321 | |
322 | # Requires one argument: the name of a file containing the expected stripped | |
323 | # access log entries. | |
324 | check_access_log() { | |
325 | sort "$1" >"$1".sorted && | |
326 | strip_access_log >access.log.stripped && | |
327 | sort access.log.stripped >access.log.sorted && | |
328 | if ! test_cmp "$1".sorted access.log.sorted | |
329 | then | |
330 | test_cmp "$1" access.log.stripped | |
331 | fi | |
332 | } |