1 | #!/bin/bash |
---|
2 | # -*- mode: shell-script; -*- |
---|
3 | # $Id$ |
---|
4 | |
---|
5 | # This script simplifies preparation of environment for Subversion client |
---|
6 | # communicating with a server via DAV protocol. The prerequisites of such |
---|
7 | # testing are: |
---|
8 | # - Subversion built using --enable-shared --enable-dso --with-apxs options, |
---|
9 | # - Working Apache 2 HTTPD Server with the apxs program reachable through |
---|
10 | # PATH or specified via the APXS environment variable, |
---|
11 | # - Modules dav_module and log_config_module compiled as DSO or built into |
---|
12 | # Apache HTTPD Server executable. |
---|
13 | # The basic intension of this script is to be able to perform "make check" |
---|
14 | # operation over DAV without any configuration efforts whatsoever, provided |
---|
15 | # that conditions above are met. |
---|
16 | # |
---|
17 | # The script will find Apache and all necessary modules including mod_dav_svn, |
---|
18 | # create a temporary directory in subversion/tests/cmdline, create |
---|
19 | # Apache 2 configuration file in this directory, start Apache 2 on a random |
---|
20 | # port number higher than 1024, and execute Subversion command-line client |
---|
21 | # test suites against this instance of HTTPD. Every vital configuration |
---|
22 | # parameter is checked before the tests start. The script will ask questions |
---|
23 | # about browsing Apache error log (default is "no") and about deleting |
---|
24 | # temporary directory (default "yes") and pause for 32 seconds before |
---|
25 | # proceeding with the default. HTTPD access log is also created in the |
---|
26 | # temporary directory. |
---|
27 | # |
---|
28 | # Run this script without parameters to execute the full battery of tests: |
---|
29 | # subversion/tests/cmdline/davautocheck.sh |
---|
30 | # Run this script with the name of a test suite to run this suite: |
---|
31 | # subversion/tests/cmdline/davautocheck.sh basic |
---|
32 | # Run this script with the test suite name and test number to execute just this |
---|
33 | # test: |
---|
34 | # subversion/tests/cmdline/davautocheck.sh basic 4 |
---|
35 | # |
---|
36 | # If the temporary directory is not deleted, it can be reused for further |
---|
37 | # manual DAV protocol interoperation testing. HTTPD must be started by |
---|
38 | # specifying configuration file on the command line: |
---|
39 | # httpd -f subversion/tests/cmdline/<httpd-...>/cfg |
---|
40 | # |
---|
41 | # If you want to run this against an *installed* HTTPD (for example, to test |
---|
42 | # one version's client against another version's server) specify both APXS |
---|
43 | # *and* MODULE_PATH for the other server: |
---|
44 | # |
---|
45 | # APXS=/opt/svn/1.4.x/bin/apxs MODULE_PATH=/opt/svn/1.4.x/modules \ |
---|
46 | # subversion/tests/cmdline/davautocheck.sh |
---|
47 | |
---|
48 | SCRIPTDIR=$(dirname $0) |
---|
49 | SCRIPT=$(basename $0) |
---|
50 | |
---|
51 | trap stop_httpd_and_die SIGHUP SIGTERM SIGINT |
---|
52 | |
---|
53 | function stop_httpd_and_die() { |
---|
54 | [ -e "$HTTPD_PID" ] && kill $(cat "$HTTPD_PID") |
---|
55 | exit 1 |
---|
56 | } |
---|
57 | |
---|
58 | function say() { |
---|
59 | echo "$SCRIPT: $*" |
---|
60 | } |
---|
61 | |
---|
62 | function fail() { |
---|
63 | say $* |
---|
64 | stop_httpd_and_die |
---|
65 | } |
---|
66 | |
---|
67 | function query() { |
---|
68 | echo -n "$SCRIPT: $1 (y/n)? [$2] " |
---|
69 | read -n 1 -t 32 |
---|
70 | echo |
---|
71 | [ "${REPLY:-$2}" = 'y' ] |
---|
72 | } |
---|
73 | |
---|
74 | function get_loadmodule_config() { |
---|
75 | local SO="$($APXS -q LIBEXECDIR)/$1.so" |
---|
76 | |
---|
77 | # shared object module? |
---|
78 | if [ -r "$SO" ]; then |
---|
79 | local NM=$(echo "$1" | sed 's|mod_\(.*\)|\1_module|') |
---|
80 | echo "LoadModule $NM \"$SO\"" && |
---|
81 | return |
---|
82 | fi |
---|
83 | |
---|
84 | # maybe it's built-in? |
---|
85 | "$HTTPD" -l | grep -q "$1\\.c" && return |
---|
86 | |
---|
87 | return 1 |
---|
88 | } |
---|
89 | |
---|
90 | # Check apxs's SBINDIR and BINDIR for given program names |
---|
91 | function get_prog_name() { |
---|
92 | for prog in $* |
---|
93 | do |
---|
94 | for dir in $($APXS -q SBINDIR) $($APXS -q BINDIR) |
---|
95 | do |
---|
96 | if [ -e "$dir/$prog" ]; then |
---|
97 | echo "$dir/$prog" && return |
---|
98 | fi |
---|
99 | done |
---|
100 | done |
---|
101 | |
---|
102 | return 1 |
---|
103 | } |
---|
104 | |
---|
105 | # Don't assume sbin is in the PATH. |
---|
106 | PATH="$PATH:/usr/sbin:/usr/local/sbin" |
---|
107 | |
---|
108 | # Remove any proxy environmental variables that affect wget or curl. |
---|
109 | # We don't need a proxy to connect to localhost and having the proxy |
---|
110 | # environmental variables set breaks the Apache configuration file |
---|
111 | # test below, since wget or curl will ask the proxy to connect to |
---|
112 | # localhost. |
---|
113 | unset PROXY |
---|
114 | unset http_proxy |
---|
115 | unset HTTPS_PROXY |
---|
116 | |
---|
117 | # Pick up value from environment or PATH (also try apxs2 - for Debian) |
---|
118 | [ ${APXS:+set} ] \ |
---|
119 | || APXS=$(which apxs) \ |
---|
120 | || APXS=$(which apxs2) \ |
---|
121 | || fail "neither apxs or apxs2 found - required to run davautocheck" |
---|
122 | |
---|
123 | [ -x $APXS ] || fail "Can't execute apxs executable $APXS" |
---|
124 | |
---|
125 | say "Using '$APXS'..." |
---|
126 | |
---|
127 | if [ -x subversion/svn/svn ]; then |
---|
128 | ABS_BUILDDIR=$(pwd) |
---|
129 | elif [ -x $SCRIPTDIR/../../svn/svn ]; then |
---|
130 | pushd $SCRIPTDIR/../../../ >/dev/null |
---|
131 | ABS_BUILDDIR=$(pwd) |
---|
132 | popd >/dev/null |
---|
133 | else |
---|
134 | fail "Run this script from the root of Subversion's build tree!" |
---|
135 | fi |
---|
136 | |
---|
137 | if [ ${MODULE_PATH:+set} ]; then |
---|
138 | MOD_DAV_SVN="$MODULE_PATH/mod_dav_svn.so" |
---|
139 | MOD_AUTHZ_SVN="$MODULE_PATH/mod_authz_svn.so" |
---|
140 | else |
---|
141 | MOD_DAV_SVN="$ABS_BUILDDIR/subversion/mod_dav_svn/.libs/mod_dav_svn.so" |
---|
142 | MOD_AUTHZ_SVN="$ABS_BUILDDIR/subversion/mod_authz_svn/.libs/mod_authz_svn.so" |
---|
143 | fi |
---|
144 | |
---|
145 | [ -r "$MOD_DAV_SVN" ] \ |
---|
146 | || fail "dav_svn_module not found, please use '--enable-shared --enable-dso --with-apxs' with your 'configure' script" |
---|
147 | [ -r "$MOD_AUTHZ_SVN" ] \ |
---|
148 | || fail "authz_svn_module not found, please use '--enable-shared --enable-dso --with-apxs' with your 'configure' script" |
---|
149 | |
---|
150 | export LD_LIBRARY_PATH="$ABS_BUILDDIR/subversion/libsvn_ra_neon/.libs:$ABS_BUILDDIR/subversion/libsvn_ra_local/.libs:$ABS_BUILDDIR/subversion/libsvn_ra_svn/.libs" |
---|
151 | |
---|
152 | case "`uname`" in |
---|
153 | Darwin*) LDD='otool -L' |
---|
154 | ;; |
---|
155 | *) LDD='ldd' |
---|
156 | ;; |
---|
157 | esac |
---|
158 | |
---|
159 | CLIENT_CMD="$ABS_BUILDDIR/subversion/svn/svn" |
---|
160 | $LDD "$CLIENT_CMD" | grep -q 'not found' \ |
---|
161 | && fail "Subversion client couldn't be fully linked at run-time" |
---|
162 | "$CLIENT_CMD" --version | egrep -q '^[*] ra_(neon|serf)' \ |
---|
163 | || fail "Subversion client couldn't find and/or load ra_dav library" |
---|
164 | |
---|
165 | httpd="$($APXS -q PROGNAME)" |
---|
166 | HTTPD=$(get_prog_name $httpd) || fail "HTTPD not found" |
---|
167 | [ -x $HTTPD ] || fail "HTTPD '$HTTPD' not executable" |
---|
168 | |
---|
169 | "$HTTPD" -v 1>/dev/null 2>&1 \ |
---|
170 | || fail "HTTPD '$HTTPD' doesn't start properly" |
---|
171 | |
---|
172 | say "Using '$HTTPD'..." |
---|
173 | |
---|
174 | HTPASSWD=$(get_prog_name htpasswd htpasswd2) \ |
---|
175 | || fail "Could not find htpasswd or htpasswd2" |
---|
176 | [ -x $HTPASSWD ] \ |
---|
177 | || fail "HTPASSWD '$HTPASSWD' not executable" |
---|
178 | say "Using '$HTPASSWD'..." |
---|
179 | |
---|
180 | LOAD_MOD_DAV=$(get_loadmodule_config mod_dav) \ |
---|
181 | || fail "DAV module not found" |
---|
182 | |
---|
183 | LOAD_MOD_LOG_CONFIG=$(get_loadmodule_config mod_log_config) \ |
---|
184 | || fail "log_config module not found" |
---|
185 | |
---|
186 | # needed for TypesConfig |
---|
187 | LOAD_MOD_MIME=$(get_loadmodule_config mod_mime) \ |
---|
188 | || fail "MIME module not found" |
---|
189 | |
---|
190 | # needed for Auth*, Require, etc. directives |
---|
191 | LOAD_MOD_AUTH=$(get_loadmodule_config mod_auth) \ |
---|
192 | || { |
---|
193 | say "Monolithic Auth module not found. Assuming we run against Apache 2.1+" |
---|
194 | LOAD_MOD_AUTH="$(get_loadmodule_config mod_auth_basic)" \ |
---|
195 | || fail "Auth_Basic module not found." |
---|
196 | LOAD_MOD_ACCESS_COMPAT="$(get_loadmodule_config mod_access_compat)" \ |
---|
197 | && { |
---|
198 | say "Found Auth modules for Apache 2.3.0+" |
---|
199 | LOAD_MOD_AUTHN_CORE="$(get_loadmodule_config mod_authn_core)" \ |
---|
200 | || fail "Authn_Core module not found." |
---|
201 | LOAD_MOD_AUTHZ_CORE="$(get_loadmodule_config mod_authz_core)" \ |
---|
202 | || fail "Authz_Core module not found." |
---|
203 | LOAD_MOD_AUTHZ_HOST="$(get_loadmodule_config mod_authz_host)" \ |
---|
204 | || fail "Authz_Host module not found." |
---|
205 | } |
---|
206 | LOAD_MOD_AUTHN_FILE="$(get_loadmodule_config mod_authn_file)" \ |
---|
207 | || fail "Authn_File module not found." |
---|
208 | LOAD_MOD_AUTHZ_USER="$(get_loadmodule_config mod_authz_user)" \ |
---|
209 | || fail "Authz_User module not found." |
---|
210 | } |
---|
211 | |
---|
212 | HTTPD_PORT=$(($RANDOM+1024)) |
---|
213 | HTTPD_ROOT="$ABS_BUILDDIR/subversion/tests/cmdline/httpd-$(date '+%Y%m%d-%H%M%S')" |
---|
214 | HTTPD_CFG="$HTTPD_ROOT/cfg" |
---|
215 | HTTPD_PID="$HTTPD_ROOT/pid" |
---|
216 | HTTPD_ACCESS_LOG="$HTTPD_ROOT/access_log" |
---|
217 | HTTPD_ERROR_LOG="$HTTPD_ROOT/error_log" |
---|
218 | HTTPD_MIME_TYPES="$HTTPD_ROOT/mime.types" |
---|
219 | BASE_URL="http://localhost:$HTTPD_PORT" |
---|
220 | HTTPD_USERS="$HTTPD_ROOT/users" |
---|
221 | |
---|
222 | mkdir "$HTTPD_ROOT" \ |
---|
223 | || fail "couldn't create temporary directory '$HTTPD_ROOT'" |
---|
224 | |
---|
225 | say "Using directory '$HTTPD_ROOT'..." |
---|
226 | |
---|
227 | say "Adding users for lock authentication" |
---|
228 | $HTPASSWD -bc $HTTPD_USERS jrandom rayjandom |
---|
229 | $HTPASSWD -b $HTTPD_USERS jconstant rayjandom |
---|
230 | |
---|
231 | touch $HTTPD_MIME_TYPES |
---|
232 | |
---|
233 | cat > "$HTTPD_CFG" <<__EOF__ |
---|
234 | $LOAD_MOD_LOG_CONFIG |
---|
235 | $LOAD_MOD_MIME |
---|
236 | $LOAD_MOD_DAV |
---|
237 | LoadModule dav_svn_module "$MOD_DAV_SVN" |
---|
238 | $LOAD_MOD_AUTH |
---|
239 | $LOAD_MOD_AUTHN_CORE |
---|
240 | $LOAD_MOD_AUTHN_FILE |
---|
241 | $LOAD_MOD_AUTHZ_CORE |
---|
242 | $LOAD_MOD_AUTHZ_USER |
---|
243 | $LOAD_MOD_AUTHZ_HOST |
---|
244 | LoadModule authz_svn_module "$MOD_AUTHZ_SVN" |
---|
245 | |
---|
246 | LockFile lock |
---|
247 | User $(whoami) |
---|
248 | Group $(groups | awk '{print $1}') |
---|
249 | Listen localhost:$HTTPD_PORT |
---|
250 | ServerName localhost |
---|
251 | PidFile "$HTTPD_PID" |
---|
252 | LogFormat "%h %l %u %t \"%r\" %>s %b" common |
---|
253 | CustomLog "$HTTPD_ACCESS_LOG" common |
---|
254 | ErrorLog "$HTTPD_ERROR_LOG" |
---|
255 | LogLevel Debug |
---|
256 | ServerRoot "$HTTPD_ROOT" |
---|
257 | DocumentRoot "$HTTPD_ROOT" |
---|
258 | ScoreBoardFile "$HTTPD_ROOT/run" |
---|
259 | CoreDumpDirectory "$HTTPD_ROOT" |
---|
260 | TypesConfig "$HTTPD_MIME_TYPES" |
---|
261 | StartServers 4 |
---|
262 | MaxRequestsPerChild 0 |
---|
263 | <IfModule worker.c> |
---|
264 | ThreadsPerChild 8 |
---|
265 | </IfModule> |
---|
266 | MaxClients 16 |
---|
267 | HostNameLookups Off |
---|
268 | LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" format |
---|
269 | CustomLog "$HTTPD_ROOT/req" format |
---|
270 | CustomLog "$HTTPD_ROOT/ops" "%t %u %{SVN-REPOS-NAME}e %{SVN-ACTION}e" env=SVN-ACTION |
---|
271 | |
---|
272 | <Directory /> |
---|
273 | AllowOverride none |
---|
274 | </Directory> |
---|
275 | <Directory "$HTTPD_ROOT"> |
---|
276 | AllowOverride none |
---|
277 | #Require all granted |
---|
278 | </Directory> |
---|
279 | |
---|
280 | <Location /svn-test-work/repositories> |
---|
281 | DAV svn |
---|
282 | SVNParentPath "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/repositories" |
---|
283 | AuthzSVNAccessFile "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/authz" |
---|
284 | AuthType Basic |
---|
285 | AuthName "Subversion Repository" |
---|
286 | AuthUserFile $HTTPD_USERS |
---|
287 | Require valid-user |
---|
288 | </Location> |
---|
289 | <Location /svn-test-work/local_tmp/repos> |
---|
290 | DAV svn |
---|
291 | SVNPath "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/local_tmp/repos" |
---|
292 | AuthzSVNAccessFile "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/authz" |
---|
293 | AuthType Basic |
---|
294 | AuthName "Subversion Repository" |
---|
295 | AuthUserFile $HTTPD_USERS |
---|
296 | Require valid-user |
---|
297 | </Location> |
---|
298 | __EOF__ |
---|
299 | |
---|
300 | START="$HTTPD -f $HTTPD_CFG" |
---|
301 | |
---|
302 | $START -t \ |
---|
303 | || fail "Configuration file didn't pass the check, most likely modules couldn't be loaded" |
---|
304 | |
---|
305 | # need to pause for some time to let HTTPD start |
---|
306 | $START & |
---|
307 | sleep 2 |
---|
308 | |
---|
309 | say "HTTPD started and listening on '$BASE_URL'..." |
---|
310 | |
---|
311 | # Perform a trivial validation of our httpd configuration by |
---|
312 | # downloading a file and comparing it to the original copy. |
---|
313 | ### The file at the path "/cfg" can't be retrieved from Apache 2.3+. |
---|
314 | ### We get a 500 ISE, with the following error in the log from httpd's |
---|
315 | ### server/request.c:ap_process_request_internal(): |
---|
316 | ### [Wed Feb 22 13:06:55 2006] [crit] [client 127.0.0.1] configuration error: couldn't check user: /cfg |
---|
317 | HTTP_FETCH=wget |
---|
318 | HTTP_FETCH_OUTPUT="-q -O" |
---|
319 | type wget > /dev/null 2>&1 |
---|
320 | if [ $? -ne 0 ]; then |
---|
321 | type curl > /dev/null 2>&1 |
---|
322 | if [ $? -ne 0 ]; then |
---|
323 | fail "Neither curl or wget found." |
---|
324 | fi |
---|
325 | HTTP_FETCH=curl |
---|
326 | HTTP_FETCH_OUTPUT='-s -o' |
---|
327 | fi |
---|
328 | $HTTP_FETCH $HTTP_FETCH_OUTPUT "$HTTPD_CFG-copy" "$BASE_URL/cfg" |
---|
329 | diff -q "$HTTPD_CFG" "$HTTPD_CFG-copy" > /dev/null \ |
---|
330 | || fail "HTTPD doesn't operate according to the generated configuration" |
---|
331 | rm "$HTTPD_CFG-copy" |
---|
332 | |
---|
333 | say "HTTPD is good" |
---|
334 | |
---|
335 | if [ $# -eq 1 ] && [ "x$1" = 'x--no-tests' ]; then |
---|
336 | exit |
---|
337 | fi |
---|
338 | |
---|
339 | say "starting the tests..." |
---|
340 | |
---|
341 | if [ $# = 0 ]; then |
---|
342 | time make check "BASE_URL=$BASE_URL" |
---|
343 | r=$? |
---|
344 | else |
---|
345 | pushd "$ABS_BUILDDIR/subversion/tests/cmdline/" >/dev/null |
---|
346 | TEST="$1" |
---|
347 | shift |
---|
348 | time "$SCRIPTDIR/${TEST}_tests.py" "--url=$BASE_URL" "$@" |
---|
349 | r=$? |
---|
350 | popd >/dev/null |
---|
351 | fi |
---|
352 | |
---|
353 | say "Finished testing..." |
---|
354 | |
---|
355 | kill $(cat "$HTTPD_PID") |
---|
356 | |
---|
357 | query 'Browse server access log' n \ |
---|
358 | && less "$HTTPD_ACCESS_LOG" |
---|
359 | |
---|
360 | query 'Browse server error log' n \ |
---|
361 | && less "$HTTPD_ERROR_LOG" |
---|
362 | |
---|
363 | query 'Delete HTTPD root directory' y \ |
---|
364 | && rm -fr "$HTTPD_ROOT/" |
---|
365 | |
---|
366 | say 'Done' |
---|
367 | |
---|
368 | exit $r |
---|