1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-19 14:57:04 +00:00
Files
go-chasquid-smtp/test/util/lib.sh
Alberto Bertogli e138f0dc05 chasquid: De-couple TLS certificates from domains
Having the certificates inside the domain directory may cause some confusion,
as it's possible they're not for the same name (they should be for the MX we
serve as, not the domain itself).

So it's not a problem if we have domains with no certificates (we could be
their MX with another name), and we could have more than one certificate per
"domain" (if we act as MXs with different names).

So this patch moves the certificates out of the domains into a new certs/
directory, where we do a one-level deep lookup for the files.

While at it, change the names of the files to "fullchain.pem" and
"privkey.pem", which match the names generated by the letsencrypt client, to
make it easier to set up.  There's no general convention for these names
anyway.
2016-10-10 00:51:04 +01:00

91 lines
1.8 KiB
Bash

# Library to write the shell scripts in the tests.
function init() {
if [ "$V" == "1" ]; then
set -v
fi
export TBASE="$(realpath `dirname ${0}`)"
cd ${TBASE}
export UTILDIR="$(realpath ${TBASE}/../util/)"
if [ "${RACE}" == "1" ]; then
RACE="-race"
fi
# Remove the directory where test-mda will deliver mail, so previous
# runs don't interfere with this one.
rm -rf .mail
# Set traps to kill our subprocesses when we exit (for any reason).
# https://stackoverflow.com/questions/360201/
trap "exit" INT TERM
trap "kill 0" EXIT
}
function generate_cert() {
go run ${UTILDIR}/generate_cert.go "$@"
}
function chasquid() {
# HOSTALIASES: so we "fake" hostnames.
# PATH: so chasquid can call test-mda without path issues.
# MDA_DIR: so our test-mda knows where to deliver emails.
HOSTALIASES=${TBASE}/hosts \
PATH=${UTILDIR}:${PATH} \
MDA_DIR=${TBASE}/.mail \
go run ${RACE} ${TBASE}/../../chasquid.go "$@"
}
function add_user() {
go run ${TBASE}/../../cmd/chasquid-util/chasquid-util.go \
adduser "config/domains/${1}/users" "${2}" --password "${3}" \
>> .add_user_logs
}
function run_msmtp() {
# msmtp will check that the rc file is only user readable.
chmod 600 msmtprc
HOSTALIASES=${TBASE}/hosts \
msmtp -C msmtprc "$@"
}
function mail_diff() {
${UTILDIR}/mail_diff "$@"
}
function success() {
echo "SUCCESS"
}
function skip() {
echo "SKIPPED" $*
}
# Wait until there's something listening on the given port.
function wait_until_ready() {
PORT=$1
while ! nc -z localhost $PORT; do
sleep 0.1
done
}
# Wait for the given file to exist.
function wait_for_file() {
while ! [ -e ${1} ]; do
sleep 0.1
done
}
# Generate certs for the given hostname.
function generate_certs_for() {
mkdir -p config/certs/${1}/
(
cd config/certs/${1}
generate_cert -ca -duration=1h -host=${1}
)
}