1 # autopkgtest check: helper routines for authdaemond tests
3 # Author: Markus Wanner <markus@bluegap.ch>
5 TEST_USERS
="alice bob carol"
7 CONFIG_FILES
="/etc/courier/authdaemonrc \
8 /etc/courier/authldaprc \
9 /etc/courier/authmysqlrc \
10 /etc/courier/authpgsqlrc \
11 /etc/courier/authsqliterc"
13 export PGOPTIONS
='--client-min-messages=warning'
15 # exits with code 0 if the given user exists
17 id
-u $1 > /dev
/null
2>&1
20 # exits with code 0 if the postgresql client tools are installed
21 has_postgres_client
() {
22 which psql
> /dev
/null
2>&1
25 test_authentication
() {
28 TEST_OUTPUT
="$AUTOPKGTEST_ARTIFACTS/testauth-$1.out"
29 echo "testing: '$user' with password '$password'"
30 /usr
/sbin
/authtest
$user $password > $TEST_OUTPUT
33 authenumerate_as_courier
() {
34 su
-c "/usr/sbin/authenumerate" -s /bin
/sh courier
37 # emits a random (512bit, hex encoded) password on stdout
38 gen_random_password
() {
39 dd if=/dev
/urandom bs
=16 count
=1 2> /dev
/null |
hexdump -e '"%x"'
42 # accepts SQL on stdin
43 postgres_superuser_exec
() {
44 su postgres
-c "psql -X -q -v ON_ERROR_STOP=1 --pset pager=off"
48 echo "== creating test users..."
49 for USER
in $TEST_USERS; do
50 gen_random_password
> $USER.password
51 useradd
--shell /bin
/false
--password $
(cat $USER.password
) $USER
55 backup_config_files
() {
56 echo "== backup config files..."
57 for f
in $CONFIG_FILES; do
59 cp ${f} ${f}.autopkgtest.bak
64 restore_config_files
() {
65 echo "== restore config files..."
66 for f
in $CONFIG_FILES; do
67 if [ -f ${f}.autopkgtest.bak
]; then
68 mv ${f}.autopkgtest.bak
${f}
74 echo "== starting authdameon..."
75 service courier-authdaemon start
79 echo "== starting postgresql..."
80 service postgresql start
83 # helper methods for dumping test status
84 dump_file_if_exists
() {
86 echo "===== BEGIN $1 ====="
88 echo "===== END $1 ====="
93 for f
in $CONFIG_FILES; do
94 if [ -f ${f}.autopkgtest.bak
]; then
95 dump_file_if_exists
$f
99 for f
in `ls $AUTOPKGTEST_ARTIFACTS/`; do
100 dump_file_if_exists
$AUTOPKGTEST_ARTIFACTS/$f
104 # cleanup after running tests
107 # dump and then restore the config files
113 if user_exists alice
; then
114 echo "== dropping user alice"
117 if user_exists bob
; then
118 echo "== dropping user bob"
121 if user_exists carol
; then
122 echo "== dropping user carol"
126 # restore config files, then restart the authdaemon, so it
127 # disconnects from the database. Otherwise authdaemon blocks the
131 # cleanup Postgres databases
132 if has_postgres_client
; then
133 postgres_superuser_exec
<<EOSQL
134 DROP DATABASE IF EXISTS courier_authdaemon_test;
135 DROP ROLE IF EXISTS courier;
139 for NAME
in courier-authdaemon postgresql
; do
140 if [ -x /etc
/init.d
/$NAME ]; then
141 echo "== stopping service $NAME..."
142 service
$NAME stop ||
/bin
/true
146 trap finish EXIT INT QUIT ABRT PIPE TERM