| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# This script runs a quick integration test using MailHog as the SMTP server and |
| 4 |
# socat to provide a TLS wrapper for TLS integratoin tests. |
| 5 |
# |
| 6 |
# https://github.com/mailhog/MailHog |
| 7 |
# |
| 8 |
# If you wish to run these tests, ensure mailhog and socat are in your path. |
| 9 |
# You'll probably need OpenSSL too. |
| 10 |
# |
| 11 |
# Results must be verified manually, either with the UI or the MailHog API: |
| 12 |
# |
| 13 |
# curl http://127.0.0.1${MAILHOG_API_PORT}/api/v2/messages -s | \ |
| 14 |
# jq '.total, .items[].Content.Headers.Subject' |
| 15 |
# |
| 16 |
# |
| 17 |
|
| 18 |
# Define the ports the services listen on |
| 19 |
SMTP_PORT=${SMTP_PORT:="7025"} |
| 20 |
TLS_PORT=${TLS_PORT:="7026"} |
| 21 |
|
| 22 |
# PID files for cleanup |
| 23 |
MAILHOG_PID="$(pwd)/mailhog.pid" |
| 24 |
SOCAT_PID="$(pwd)/socat.pid" |
| 25 |
|
| 26 |
INT_DIR=$(dirname "$(realpath -s "$0")") |
| 27 |
|
| 28 |
# kill -9 a process with a pidfile at the first argument. |
| 29 |
function stop_pidfile() { |
| 30 |
pid_file=$1 |
| 31 |
if [ -f "${pid_file}" ]; then |
| 32 |
kill -9 "$(cat "${pid_file}")" || true |
| 33 |
rm "${pid_file}" |
| 34 |
fi |
| 35 |
} |
| 36 |
|
| 37 |
function cleanup() { |
| 38 |
stop_pidfile "${MAILHOG_PID}"; |
| 39 |
stop_pidfile "${SOCAT_PID}"; |
| 40 |
} |
| 41 |
trap cleanup EXIT |
| 42 |
|
| 43 |
mailhog -smtp-bind-addr=127.0.0.1:${SMTP_PORT} & echo "$!" > "${MAILHOG_PID}" |
| 44 |
socat -v openssl-listen:${TLS_PORT},cert="${INT_DIR}/cert.pem",verify=0,reuseaddr,fork tcp4:127.0.0.1:${SMTP_PORT} & echo "$!" > "${SOCAT_PID}" |
| 45 |
|
| 46 |
wait "$(cat "${MAILHOG_PID}")" |