Files
husk-milter/e2e-tests/common.sh
T
Malte Meiboom 8b2f284916 Improve e2e tests
- Add a test for mail splitting.
- Cleanup the code, move common functionality into `common.sh`.
- Reduce noise in the test output.
2026-07-09 12:55:10 +02:00

103 lines
2.8 KiB
Bash

#!/usr/bin/bash
# create a unix (shell) user
create_unix_user() { # name
adduser --quiet --shell /bin/bash --disabled-password --gecos "" $1 > /dev/null 2>&1
}
# delete a unix user, plus remove $HOME and mails
delete_unix_user() { # name
deluser --remove-home $1
}
# send a mail and wait for delivery
send_test_mail() { # email_address
echo "send test mail to $1" >&2
USER=$(echo $1 | cut -f 1 -d '@')
# create an empty mailbox file
touch /var/mail/$USER
chown $USER:mail /var/mail/$USER
chmod 600 /var/mail/$USER
echo -e "To: $1\nSubject: testmail\n\ntest mail" | sendmail -t
inotifywait -qq -t 3 -e close_write /var/mail/$USER
}
# test header
test_header() { # text
echo "##############################################"
echo $1
echo "Workdir: $WORKDIR"
echo "----------------------------------------------"
}
# Generate a key outside the key store. The key will not be
# authenticated.
gen_key() { # email
FILE=$(echo $1 | cut -f 1 -d '@')
FPR=$(sq key generate --home none --shared-key --without-password \
--email $1 \
--output $WORKDIR/${FILE}_sk.pgp \
--rev-cert $WORKDIR/${FILE}.rev |& grep "Fingerprint:" | cut -d ':' -f 2)
echo $FPR
}
# Generate a key outside the key store. The key will not be
# authenticated. Import the certificate of the key.
gen_cert() { # email
FILE=$(echo $1 | cut -f 1 -d '@')
FPR=$(sq key generate --home none --shared-key --without-password \
--email $1 \
--output $WORKDIR/${FILE}_sk.pgp \
--rev-cert $WORKDIR/${FILE}.rev |& grep "Fingerprint:" | cut -d ':' -f 2)
sq cert import $WORKDIR/${FILE}_sk.pgp > /dev/null 2>&1
echo $FPR
}
authenticate() { # Fingerprint
sq pki link add --cert $1 --all > /dev/null 2>&1
}
expect_mail() { # unix_user mode [signature_fpr]
if [ -f /var/mail/$1 ] ; then
case $2 in
encrypted)
if grep -q "BEGIN PGP MESSAGE" /var/mail/$1 ; then
echo "GOOD: found expected encrypted mail" >&2
R=0
if [ "$3" != "" ] ; then
FOUND_FPR=$(sq packet dump /var/mail/$1 | grep "Issuer Fingerprint:" | cut -d ':' -f 2 | tr -d ' ')
if [ "$3" != "$FOUND_FPR" ] ; then
echo "BAD: Found wrong signature '$FOUND_FPR' - expected '$3'" >&2
R=1
else
echo "GOOD: found right signature" >&2
fi
fi
else
echo "BAD: encryped mail expected but not found" >&2
R=1
fi
;;
unencrypted)
if grep -q "BEGIN PGP MESSAGE" /var/mail/$1 ; then
echo "BAD: expected unencrypted mail for $1" >&2
R=1
else
echo "GOOD: found expected unencrypted mail" >&2
R=0
fi
;;
delivered)
echo "GOOD: mail delivery worked" >&2
R=0
;;
esac
else
echo "BAD: no mail for $1" >&2
R=1
fi
echo $R
}