File macros.apache-module-test of Package apache-rpm-macros
1
%__test_dir /tmp/%{name}-test
2
%__test_mpm prefork
3
%__test_user abuild
4
%__test_group abuild
5
%__test_port 60080
6
7
# world writeable dir for testing purposes (logs, document root, ..)
8
%apache_test_module_dir %{__test_dir}
9
10
#
11
# macro: apache_test_module_start_apache -- start apache with specified modules loaded
12
#
13
# usage: apache_test_module_start_apache [-m module_list] [-i include_list] [-r document_root]
14
# [-u user] [-g group] [-p port] [-t mpm]
15
#
16
# module_list: colon separated list of module names to be loaded with test run
17
# search path: %{buildroot} tree
18
# %{apache_libexecdir}-prefork
19
# %{apache_libexecdir}
20
# [example value: asn:dbd]
21
# include_list: colon separated list of names of apache configuration files
22
# to be included; can be either existing path or just name
23
# of the configuration file,which will be searched under:
24
# %{buildroot}%{apache_sysconfdir} tree
25
# $PWD tree
26
# %{apache_test_module_dir}
27
# [example value: mod_asn.conf]
28
# document_root: document root of the test server,
29
# [default value: /tmp/%%{name}-test/htdocs]
30
# user: user under which will run test instance (usable only
31
# when the test is run by root)
32
# [default value: abuild]
33
# group: group under which will run test instance (usable only
34
# when the test is run by root)
35
# [default value: abuild]
36
# port: listen on port
37
# [default value: 60080]
38
# mpm: multiprocessing module (prefork, worker, event)
39
# [default value: prefork]
40
#
41
#
42
%apache_test_module_start_apache(m:,i:,r:,u:,g:,p:,t:) \
43
# constants \
44
TEST_DIR='%{__test_dir}' \
45
# arguments \
46
# modules to load, from BUILD tree or system \
47
MODULES=$(echo %{-m:%{-m*}} | tr ':' ' ') \
48
# configs to include \
49
CONFIGS="%{-i:%{-i*}}" \
50
# document root of the test server \
51
DOCUMENT_ROOT="%{-r:%{-r*}}" \
52
if [ -z "$DOCUMENT_ROOT" ]; then \
53
DOCUMENT_ROOT=$TEST_DIR/htdocs \
54
fi \
55
# user and group running the apache instance \
56
# (usable only when the test is run as root) \
57
TEST_USER="%{-u:%{-u*}}" \
58
if [ -z "$TEST_USER" ]; then \
59
TEST_USER='%{__test_user}' \
60
fi \
61
TEST_GROUP="%{-g:%{-g*}}" \
62
if [ -z "$TEST_GROUP" ]; then \
63
TEST_GROUP='%{__test_group}' \
64
fi \
65
TEST_PORT="%{-p:%{-p*}}" \
66
if [ -z "$TEST_PORT" ]; then \
67
TEST_PORT='%{__test_port}' \
68
fi \
69
TEST_MPM="%{-t:%{-t*}}" \
70
if [ -z "$TEST_MPM" ]; then \
71
TEST_MPM='%{__test_mpm}' \
72
fi \
73
# helpers \
74
# begin \
75
echo "-----------------------------------------------------------" \
76
echo "APACHE MODULE TEST" \
77
echo \
78
echo "modules to load: $MODULES" \
79
echo "configs to include: $CONFIGS" \
80
# create test dir \
81
mkdir -p $TEST_DIR \
82
# create document root if not exist \
83
mkdir -p $DOCUMENT_ROOT \
84
# create test/httpd-test.conf \
85
TEST_CONF_FILE="$TEST_DIR/httpd.conf" \
86
SYSTEM_MODULE_PATH="%{apache_libexecdir}-$TEST_MPM" \
87
echo "ServerName test" > $TEST_CONF_FILE \
88
echo "User $TEST_USER" >> $TEST_CONF_FILE \
89
echo "Group $TEST_GROUP" >> $TEST_CONF_FILE \
90
echo "Listen $TEST_PORT" >> $TEST_CONF_FILE \
91
echo "PidFile $TEST_DIR/pid" >> $TEST_CONF_FILE \
92
echo "ErrorLog $TEST_DIR/error_log" >> $TEST_CONF_FILE \
93
echo "LoadModule dir_module $SYSTEM_MODULE_PATH/mod_dir.so" >> $TEST_CONF_FILE \
94
echo "LoadModule auth_basic_module $SYSTEM_MODULE_PATH/mod_auth_basic.so" >> $TEST_CONF_FILE \
95
if [ %{apache_branch} -ge 204 ]; then \
96
echo "LoadModule authz_core_module $SYSTEM_MODULE_PATH/mod_authz_core.so" >> $TEST_CONF_FILE \
97
fi \
98
echo "LoadModule authz_host_module $SYSTEM_MODULE_PATH/mod_authz_host.so" >> $TEST_CONF_FILE \
99
for m in $(echo $MODULES | tr ':' ' '); do \
100
module_path=$(find %{buildroot} %{apache_libexecdir}-$TEST_MPM %{apache_libexecdir} -name "mod_$m.so" | tail -n 1) \
101
if [ -z "$module_path" ]; then \
102
echo "ERROR: Module $m not found." \
103
exit 1 \
104
fi \
105
echo "Will load ${m}_module $module_path" \
106
echo "LoadModule ${m}_module $module_path" >> $TEST_CONF_FILE \
107
done \
108
for c in $(echo $CONFIGS | tr ':' ' '); do \
109
if [ -f $c ]; then \
110
if [[ ! "$c" = /* ]]; then \
111
c="$PWD/$c" \
112
fi \
113
include_path="$c" \
114
else \
115
include_path=$(find %{buildroot}%{apache_sysconfdir} %{apache_test_module_dir} $PWD -name "$c" 2>/dev/null | tail -n 1) \
116
fi \
117
if [ -z "$include_path" ]; then \
118
echo "ERROR: Config file $c not found." \
119
exit 1 \
120
fi \
121
echo "Will include $include_path" \
122
echo "Include $include_path" >> $TEST_CONF_FILE \
123
done \
124
echo "DocumentRoot $DOCUMENT_ROOT" >> $TEST_CONF_FILE \
125
echo "DirectoryIndex index.html" >> $TEST_CONF_FILE \
126
# run apache \
127
CMD=$(ls %{_sbindir}/httpd*-$TEST_MPM | head -n 1) \
128
echo -n "Starting Apache ... " \
129
$CMD -f $TEST_CONF_FILE -k start \
130
# wait to be sure apache finished start \
131
sleep 2 \
132
if [ ! -f $TEST_DIR/pid ]; then \
133
echo "FAILED, $TEST_DIR/error_log: >&2" \
134
cat $TEST_DIR/error_log >&2 \
135
echo "See $TEST_DIR for details" >&2 \
136
echo "FAILED, $TEST_DIR/error_log:" \
137
cat $TEST_DIR/error_log \
138
echo "See $TEST_DIR for details" \
139
exit 1 \
140
fi \
141
echo "SUCCESS" \
142
%nil
143
144
#
145
# macro: apache_test_module_stop_apache -- stops apache previously started with *_start_apache
146
#
147
# usage: apache_test_module_stop_apache [-f]
148
#
149
# -f: force
150
#
151
%apache_test_module_stop_apache(f) \
152
TEST_DIR='%{__test_dir}' \
153
SIGNAL=%{!-f:TERM}%{-f:KILL} \
154
# stop apache \
155
echo "Stopping Apache ..." \
156
kill -$SIGNAL -$(cat $TEST_DIR/pid) \
157
echo "Done." \
158
echo "-----------------------------------------------------------" \
159
%nil
160
161
#
162
# macro: apache_test_module_curl -- outputs curl on particular document relative to
163
# document root of test instance
164
#
165
# usage: apache_test_module_curl -d document_to_curl -o output_of_curl
166
# -p port -u user:password -r protocol
167
#
168
# document_to_curl: relative to DocumentRoot [default: /]
169
# output_of_curl: where to save document (required)
170
# port: from which port of localhost will be document
171
# downloaded [default value: 60080]
172
# user:password: --user parameter of curl
173
# protocol: protocol to download document
174
# [default: http]
175
#
176
# example: apache_test_module_curl -d foo/test.html -o test.html
177
# apache_test_module_curl -d foo/ -o output.txt
178
#
179
%apache_test_module_curl(d:,o:,p:,u:,r:) \
180
TEST_DOCUMENT="%{-d:%{-d*}}" \
181
TEST_OUTPUT="%{-o:%{-o*}}" \
182
TEST_PORT="%{-p:%{-p*}}" \
183
TEST_CURL_USER="%{-u:%{-u*}}" \
184
TEST_PROTO="%{-r:%{-r*}}" \
185
if [ -z "$TEST_PORT" ]; then \
186
TEST_PORT='%{__test_port}' \
187
fi \
188
if [ -z "$TEST_OUTPUT" ]; then \
189
echo "Missing argument -o to apache_test_module_curl." \
190
exit 1 \
191
fi \
192
USER_PARAM="" \
193
if [ ! -z "$TEST_CURL_USER" ]; then \
194
USER_PARAM="-u $TEST_CURL_USER" \
195
fi \
196
if [ -z "$TEST_PROTO" ]; then \
197
TEST_PROTO="http" \
198
fi \
199
curl -s -k "$TEST_PROTO://127.0.0.1:$TEST_PORT/$TEST_DOCUMENT" --create-dirs -o "$TEST_OUTPUT" $USER_PARAM \
200
%nil
201
202
#
203
# macro: apache_test_module_load -- tests that module(s) can be loaded
204
#
205
# usage: apache_test_module_load [-m module_list] [-i include_list] [-t mpm]
206
#
207
# module_list: colon separated list of module names to be loaded with test run
208
# search path: %{buildroot} tree
209
# %{apache_libexecdir}-prefork
210
# %{apache_libexecdir}
211
# [example value: asn:dbd]
212
# include_list: colon separated list of names of apache configuration files
213
# to be included (path relative to current dir)
214
# search path %{buildroot}%{apache_sysconfdir} tree
215
# $PWD tree
216
# [example value: mod_asn.conf]
217
# mpm: multiprocessing module (prefork, worker, event)
218
# [default value: prefork]
219
#
220
%apache_test_module_load(m:,i:,t:) \
221
%apache_test_module_start_apache %{-m:-m %{-m*}} %{-i:-i %{-i*}} %{-t:-t %{-t*}} \
222
%apache_test_module_stop_apache \
223
%nil
224
225