1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#!/bin/bash
set -ue
PATH="/usr/bin:/bin"
export PATH
TESTDIR=( Net_SMTP-*/tests )
if [ ! -d "$TESTDIR" ]; then
echo "Missing test directory" >&2
exit 1
fi
username="user"
password="$(xxd -l16 -p </dev/urandom)"
port=10587
# Cf. Net_SMTP-*/tests/config.php.dist
cat >"$TESTDIR/config.php" <<-EOF
<?php
define('TEST_HOSTNAME', 'localhost');
define('TEST_PORT', $port);
define('TEST_LOCALHOST', 'localhost.localdomain');
define('TEST_AUTH_USER', '$username');
define('TEST_AUTH_PASS', '$password');
define('TEST_FROM', 'from@example.net');
define('TEST_TO', 'to@example.net');
define('TEST_SUBJECT', 'Test Subject');
define('TEST_BODY', 'Test Body');
EOF
home="$AUTOPKGTEST_TMP/home"
dovecot_dir="$AUTOPKGTEST_TMP/dovecot"
run_dir="$dovecot_dir/run"
mkdir -m0700 -- "$home" "$dovecot_dir"
relay_host="127.0.0.1"
relay_port=10025
cat >"$dovecot_dir/config" <<-EOF
dovecot_config_version = 2.4.0
dovecot_storage_version = 2.4.0
log_path = $dovecot_dir/dovecot.log
mail_home = $home
mail_driver = maildir
mail_path = %{home}/mail
mail_inbox_path = %{home}/mail/inbox
mailbox_list_index = yes
ssl = no
listen = 127.0.0.1, 127.0.1.1, ::1
namespace inbox {
inbox = yes
}
# https://doc.dovecot.org/latest/core/config/rootless.html#rootless-installation
base_dir = ${dovecot_dir}/run
default_internal_user = $(id -un)
default_internal_group = $(id -gn)
default_login_user = $(id -un)
service anvil {
chroot =
}
service stats {
chroot =
}
passdb passwd-file {
passdb_default_password_scheme = plain
auth_username_format = %{user | username}
passwd_file_path = $dovecot_dir/users
}
userdb passwd-file {
auth_username_format = %{user | username}
passwd_file_path = $dovecot_dir/users
}
protocols {
submission = yes
}
service submission-login {
chroot =
inet_listener submission {
port = $port
}
}
submission_relay_host = $relay_host
submission_relay_port = $relay_port
EOF
RELAY_PID=""
cleanup() {
local pid
if ! doveadm -c "$dovecot_dir/config" stop; then
pid="$(< "$run_dir/master.pid")"
kill -TERM "$pid" || printf "kill(1) exited with status %d\\n" "$?" >&2
fi
rm -rf -- "$dovecot_dir" "$home"
if [ -n "${RELAY_PID+x}" ]; then
kill -TERM "$RELAY_PID" || printf "kill(1) exited with status %d\\n" "$?" >&2
fi
}
/usr/sbin/dovecot -c "$dovecot_dir/config"
trap cleanup EXIT INT TERM
printf "%s:%s::::%s:\\n" "$username" "$password" "$home" >"$dovecot_dir/users"
# throw away all incoming messages
/usr/sbin/smtp-sink -h smtp-sink.example.net "inet:$relay_host:$relay_port" 8 & RELAY_PID="$!"
sleep 1
pear run-tests "$TESTDIR"
|