2015-09-06 11:35:52 +00:00
|
|
|
%__test_dir /tmp/%{name}-test
|
|
|
|
%__test_mpm prefork
|
|
|
|
%__test_user abuild
|
|
|
|
%__test_group abuild
|
|
|
|
%__test_port 60080
|
|
|
|
|
|
|
|
# world writeable dir for testing purposes (logs, document root, ..)
|
|
|
|
%apache_test_module_dir %{__test_dir}
|
|
|
|
|
2015-09-02 10:28:28 +00:00
|
|
|
#
|
|
|
|
# macro: apache_test_module_start_apache -- start apache with specified modules loaded
|
|
|
|
#
|
2015-10-02 20:13:35 +00:00
|
|
|
# usage: apache_test_module_start_apache [-m module_list] [-i include_list] [-r document_root]
|
|
|
|
# [-u user] [-g group] [-p port] [-t mpm]
|
2015-09-02 10:28:28 +00:00
|
|
|
#
|
|
|
|
# module_list: colon separated list of module names to be loaded with test run
|
|
|
|
# search path: %{buildroot} tree
|
|
|
|
# %{apache_libexecdir}-prefork
|
|
|
|
# %{apache_libexecdir}
|
|
|
|
# [example value: asn:dbd]
|
|
|
|
# include_list: colon separated list of names of apache configuration files
|
2015-09-06 11:35:52 +00:00
|
|
|
# to be included; can be either existing path or just name
|
|
|
|
# of the configuration file,which will be searched under:
|
|
|
|
# %{buildroot}%{apache_sysconfdir} tree
|
|
|
|
# $PWD tree
|
|
|
|
# %{apache_test_module_dir}
|
2015-09-02 10:28:28 +00:00
|
|
|
# [example value: mod_asn.conf]
|
|
|
|
# document_root: document root of the test server,
|
2015-09-25 14:10:14 +00:00
|
|
|
# [default value: /tmp/%%{name}-test/htdocs]
|
|
|
|
# user: user under which will run test instance (usable only
|
|
|
|
# when the test is run by root)
|
|
|
|
# [default value: abuild]
|
|
|
|
# group: group under which will run test instance (usable only
|
|
|
|
# when the test is run by root)
|
|
|
|
# [default value: abuild]
|
|
|
|
# port: listen on port
|
|
|
|
# [default value: 60080]
|
2015-10-02 20:13:35 +00:00
|
|
|
# mpm: multiprocessing module (prefork, worker, event)
|
|
|
|
# [default value: prefork]
|
2015-09-02 10:28:28 +00:00
|
|
|
#
|
|
|
|
#
|
2015-12-11 12:28:09 +00:00
|
|
|
%apache_test_module_start_apache(m:,i:,r:,u:,g:,p:,t:) \
|
2015-09-02 10:28:28 +00:00
|
|
|
# constants \
|
2015-09-06 11:35:52 +00:00
|
|
|
TEST_DIR='%{__test_dir}' \
|
2015-09-02 10:28:28 +00:00
|
|
|
# arguments \
|
|
|
|
# modules to load, from BUILD tree or system \
|
|
|
|
MODULES=$(echo %{-m:%{-m*}} | tr ':' ' ') \
|
|
|
|
# configs to include \
|
|
|
|
CONFIGS="%{-i:%{-i*}}" \
|
|
|
|
# document root of the test server \
|
|
|
|
DOCUMENT_ROOT="%{-r:%{-r*}}" \
|
|
|
|
if [ -z "$DOCUMENT_ROOT" ]; then \
|
2015-09-06 11:35:52 +00:00
|
|
|
DOCUMENT_ROOT=$TEST_DIR/htdocs \
|
2015-09-02 10:28:28 +00:00
|
|
|
fi \
|
2015-09-25 14:10:14 +00:00
|
|
|
# user and group running the apache instance \
|
|
|
|
# (usable only when the test is run as root) \
|
|
|
|
TEST_USER="%{-u:%{-u*}}" \
|
|
|
|
if [ -z "$TEST_USER" ]; then \
|
|
|
|
TEST_USER='%{__test_user}' \
|
|
|
|
fi \
|
|
|
|
TEST_GROUP="%{-g:%{-g*}}" \
|
|
|
|
if [ -z "$TEST_GROUP" ]; then \
|
|
|
|
TEST_GROUP='%{__test_group}' \
|
|
|
|
fi \
|
|
|
|
TEST_PORT="%{-p:%{-p*}}" \
|
|
|
|
if [ -z "$TEST_PORT" ]; then \
|
|
|
|
TEST_PORT='%{__test_port}' \
|
|
|
|
fi \
|
2015-10-02 20:13:35 +00:00
|
|
|
TEST_MPM="%{-t:%{-t*}}" \
|
|
|
|
if [ -z "$TEST_MPM" ]; then \
|
|
|
|
TEST_MPM='%{__test_mpm}' \
|
|
|
|
fi \
|
2015-09-02 10:28:28 +00:00
|
|
|
# helpers \
|
|
|
|
# begin \
|
|
|
|
echo "-----------------------------------------------------------" \
|
|
|
|
echo "APACHE MODULE TEST" \
|
|
|
|
echo \
|
|
|
|
echo "modules to load: $MODULES" \
|
|
|
|
echo "configs to include: $CONFIGS" \
|
2015-09-06 11:35:52 +00:00
|
|
|
# create test dir \
|
2015-09-05 07:21:55 +00:00
|
|
|
mkdir -p $TEST_DIR \
|
2015-09-02 10:28:28 +00:00
|
|
|
# create document root if not exist \
|
|
|
|
mkdir -p $DOCUMENT_ROOT \
|
|
|
|
# create test/httpd-test.conf \
|
2015-09-06 11:35:52 +00:00
|
|
|
TEST_CONF_FILE="$TEST_DIR/httpd.conf" \
|
2015-09-02 10:28:28 +00:00
|
|
|
SYSTEM_MODULE_PATH="%{apache_libexecdir}-$TEST_MPM" \
|
|
|
|
echo "ServerName test" > $TEST_CONF_FILE \
|
|
|
|
echo "User $TEST_USER" >> $TEST_CONF_FILE \
|
|
|
|
echo "Group $TEST_GROUP" >> $TEST_CONF_FILE \
|
|
|
|
echo "Listen $TEST_PORT" >> $TEST_CONF_FILE \
|
2015-09-06 11:35:52 +00:00
|
|
|
echo "PidFile $TEST_DIR/pid" >> $TEST_CONF_FILE \
|
|
|
|
echo "ErrorLog $TEST_DIR/error_log" >> $TEST_CONF_FILE \
|
2015-09-02 10:28:28 +00:00
|
|
|
echo "LoadModule dir_module $SYSTEM_MODULE_PATH/mod_dir.so" >> $TEST_CONF_FILE \
|
|
|
|
echo "LoadModule auth_basic_module $SYSTEM_MODULE_PATH/mod_auth_basic.so" >> $TEST_CONF_FILE \
|
2015-12-11 12:28:09 +00:00
|
|
|
if [ %{apache_branch} -ge 204 ]; then \
|
2015-09-02 10:28:28 +00:00
|
|
|
echo "LoadModule authz_core_module $SYSTEM_MODULE_PATH/mod_authz_core.so" >> $TEST_CONF_FILE \
|
|
|
|
fi \
|
|
|
|
echo "LoadModule authz_host_module $SYSTEM_MODULE_PATH/mod_authz_host.so" >> $TEST_CONF_FILE \
|
|
|
|
for m in $(echo $MODULES | tr ':' ' '); do \
|
|
|
|
module_path=$(find %{buildroot} %{apache_libexecdir}-$TEST_MPM %{apache_libexecdir} -name "mod_$m.so" | tail -n 1) \
|
|
|
|
if [ -z "$module_path" ]; then \
|
|
|
|
echo "ERROR: Module $m not found." \
|
|
|
|
exit 1 \
|
|
|
|
fi \
|
|
|
|
echo "Will load ${m}_module $module_path" \
|
|
|
|
echo "LoadModule ${m}_module $module_path" >> $TEST_CONF_FILE \
|
|
|
|
done \
|
|
|
|
for c in $(echo $CONFIGS | tr ':' ' '); do \
|
2015-09-06 11:35:52 +00:00
|
|
|
if [ -f $c ]; then \
|
|
|
|
if [[ ! "$c" = /* ]]; then \
|
|
|
|
c="$PWD/$c" \
|
|
|
|
fi \
|
|
|
|
include_path="$c" \
|
|
|
|
else \
|
|
|
|
include_path=$(find %{buildroot}%{apache_sysconfdir} %{apache_test_module_dir} $PWD -name "$c" 2>/dev/null | tail -n 1) \
|
|
|
|
fi \
|
2015-09-02 10:28:28 +00:00
|
|
|
if [ -z "$include_path" ]; then \
|
|
|
|
echo "ERROR: Config file $c not found." \
|
|
|
|
exit 1 \
|
|
|
|
fi \
|
|
|
|
echo "Will include $include_path" \
|
|
|
|
echo "Include $include_path" >> $TEST_CONF_FILE \
|
|
|
|
done \
|
|
|
|
echo "DocumentRoot $DOCUMENT_ROOT" >> $TEST_CONF_FILE \
|
|
|
|
echo "DirectoryIndex index.html" >> $TEST_CONF_FILE \
|
|
|
|
# run apache \
|
2015-09-05 07:21:55 +00:00
|
|
|
CMD=$(ls %{_sbindir}/httpd*-$TEST_MPM | head -n 1) \
|
2015-09-02 10:28:28 +00:00
|
|
|
echo -n "Starting Apache ... " \
|
2015-09-06 11:35:52 +00:00
|
|
|
$CMD -f $TEST_CONF_FILE -k start \
|
2015-09-05 07:21:55 +00:00
|
|
|
# wait to be sure apache finished start \
|
|
|
|
sleep 2 \
|
|
|
|
if [ ! -f $TEST_DIR/pid ]; then \
|
2015-12-11 12:28:09 +00:00
|
|
|
echo "FAILED, $TEST_DIR/error_log: >&2" \
|
|
|
|
cat $TEST_DIR/error_log >&2 \
|
|
|
|
echo "See $TEST_DIR for details" >&2 \
|
|
|
|
echo "FAILED, $TEST_DIR/error_log:" \
|
2015-09-05 07:21:55 +00:00
|
|
|
cat $TEST_DIR/error_log \
|
2015-12-11 12:28:09 +00:00
|
|
|
echo "See $TEST_DIR for details" \
|
2015-09-05 07:21:55 +00:00
|
|
|
exit 1 \
|
|
|
|
fi \
|
2015-09-02 10:28:28 +00:00
|
|
|
echo "SUCCESS" \
|
|
|
|
%nil
|
|
|
|
|
|
|
|
#
|
|
|
|
# macro: apache_test_module_stop_apache -- stops apache previously started with *_start_apache
|
|
|
|
#
|
2015-12-11 12:28:09 +00:00
|
|
|
# usage: apache_test_module_stop_apache [-f]
|
2015-09-02 10:28:28 +00:00
|
|
|
#
|
2015-12-11 12:28:09 +00:00
|
|
|
# -f: force
|
|
|
|
#
|
|
|
|
%apache_test_module_stop_apache(f) \
|
2015-09-06 11:35:52 +00:00
|
|
|
TEST_DIR='%{__test_dir}' \
|
2015-12-11 12:28:09 +00:00
|
|
|
SIGNAL=%{!-f:TERM}%{-f:KILL} \
|
2015-09-02 10:28:28 +00:00
|
|
|
# stop apache \
|
|
|
|
echo "Stopping Apache ..." \
|
2015-12-11 12:28:09 +00:00
|
|
|
kill -$SIGNAL -$(cat $TEST_DIR/pid) \
|
2015-09-02 10:28:28 +00:00
|
|
|
echo "Done." \
|
|
|
|
echo "-----------------------------------------------------------" \
|
|
|
|
%nil
|
|
|
|
|
2015-09-06 11:35:52 +00:00
|
|
|
#
|
|
|
|
# macro: apache_test_module_curl -- outputs curl on particular document relative to
|
|
|
|
# document root of test instance
|
|
|
|
#
|
2015-09-25 14:10:14 +00:00
|
|
|
# usage: apache_test_module_curl -d document_to_curl -o output_of_curl
|
2015-10-02 20:13:35 +00:00
|
|
|
# -p port -u user:password -r protocol
|
2015-09-25 14:10:14 +00:00
|
|
|
#
|
|
|
|
# document_to_curl: relative to DocumentRoot [default: /]
|
|
|
|
# output_of_curl: where to save document (required)
|
|
|
|
# port: from which port of localhost will be document
|
|
|
|
# downloaded [default value: 60080]
|
|
|
|
# user:password: --user parameter of curl
|
2015-10-02 20:13:35 +00:00
|
|
|
# protocol: protocol to download document
|
|
|
|
# [default: http]
|
2015-09-25 14:10:14 +00:00
|
|
|
#
|
2015-09-06 11:35:52 +00:00
|
|
|
# example: apache_test_module_curl -d foo/test.html -o test.html
|
|
|
|
# apache_test_module_curl -d foo/ -o output.txt
|
|
|
|
#
|
2015-10-02 20:13:35 +00:00
|
|
|
%apache_test_module_curl(d:,o:,p:,u:,r:) \
|
2015-09-06 11:35:52 +00:00
|
|
|
TEST_DOCUMENT="%{-d:%{-d*}}" \
|
|
|
|
TEST_OUTPUT="%{-o:%{-o*}}" \
|
2015-09-25 14:10:14 +00:00
|
|
|
TEST_PORT="%{-p:%{-p*}}" \
|
|
|
|
TEST_CURL_USER="%{-u:%{-u*}}" \
|
2015-10-02 20:13:35 +00:00
|
|
|
TEST_PROTO="%{-r:%{-r*}}" \
|
2015-09-25 14:10:14 +00:00
|
|
|
if [ -z "$TEST_PORT" ]; then \
|
|
|
|
TEST_PORT='%{__test_port}' \
|
|
|
|
fi \
|
2015-09-06 11:35:52 +00:00
|
|
|
if [ -z "$TEST_OUTPUT" ]; then \
|
|
|
|
echo "Missing argument -o to apache_test_module_curl." \
|
|
|
|
exit 1 \
|
|
|
|
fi \
|
2015-09-25 14:10:14 +00:00
|
|
|
USER_PARAM="" \
|
|
|
|
if [ ! -z "$TEST_CURL_USER" ]; then \
|
|
|
|
USER_PARAM="-u $TEST_CURL_USER" \
|
|
|
|
fi \
|
2015-10-02 20:13:35 +00:00
|
|
|
if [ -z "$TEST_PROTO" ]; then \
|
|
|
|
TEST_PROTO="http" \
|
|
|
|
fi \
|
|
|
|
curl -s -k "$TEST_PROTO://127.0.0.1:$TEST_PORT/$TEST_DOCUMENT" --create-dirs -o "$TEST_OUTPUT" $USER_PARAM \
|
2015-09-06 11:35:52 +00:00
|
|
|
%nil
|
|
|
|
|
2015-09-02 10:28:28 +00:00
|
|
|
#
|
|
|
|
# macro: apache_test_module_load -- tests that module(s) can be loaded
|
|
|
|
#
|
2015-10-02 20:13:35 +00:00
|
|
|
# usage: apache_test_module_load [-m module_list] [-i include_list] [-t mpm]
|
2015-09-02 10:28:28 +00:00
|
|
|
#
|
|
|
|
# module_list: colon separated list of module names to be loaded with test run
|
|
|
|
# search path: %{buildroot} tree
|
|
|
|
# %{apache_libexecdir}-prefork
|
|
|
|
# %{apache_libexecdir}
|
|
|
|
# [example value: asn:dbd]
|
|
|
|
# include_list: colon separated list of names of apache configuration files
|
|
|
|
# to be included (path relative to current dir)
|
|
|
|
# search path %{buildroot}%{apache_sysconfdir} tree
|
|
|
|
# $PWD tree
|
|
|
|
# [example value: mod_asn.conf]
|
2015-10-02 20:13:35 +00:00
|
|
|
# mpm: multiprocessing module (prefork, worker, event)
|
|
|
|
# [default value: prefork]
|
2015-09-02 10:28:28 +00:00
|
|
|
#
|
2015-10-02 20:13:35 +00:00
|
|
|
%apache_test_module_load(m:,i:,t:) \
|
|
|
|
%apache_test_module_start_apache %{-m:-m %{-m*}} %{-i:-i %{-i*}} %{-t:-t %{-t*}} \
|
2015-09-02 10:28:28 +00:00
|
|
|
%apache_test_module_stop_apache \
|
|
|
|
%nil
|
|
|
|
|