Improve e2e tests
- Add a test for mail splitting. - Cleanup the code, move common functionality into `common.sh`. - Reduce noise in the test output.
This commit is contained in:
+37
-7
@@ -12,13 +12,14 @@ delete_unix_user() { # name
|
||||
|
||||
# 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 "Subject: testmail\n\ntest mail" | sendmail $1
|
||||
echo -e "To: $1\nSubject: testmail\n\ntest mail" | sendmail -t
|
||||
inotifywait -qq -t 3 -e close_write /var/mail/$USER
|
||||
}
|
||||
|
||||
@@ -27,10 +28,10 @@ test_header() { # text
|
||||
echo "##############################################"
|
||||
echo $1
|
||||
echo "Workdir: $WORKDIR"
|
||||
echo "##############################################"
|
||||
echo "----------------------------------------------"
|
||||
}
|
||||
|
||||
# Generate a key outside the cert store. The key will not be
|
||||
# Generate a key outside the key store. The key will not be
|
||||
# authenticated.
|
||||
gen_key() { # email
|
||||
FILE=$(echo $1 | cut -f 1 -d '@')
|
||||
@@ -41,31 +42,60 @@ gen_key() { # email
|
||||
echo $FPR
|
||||
}
|
||||
|
||||
expect_mail() { # unix_user mode
|
||||
# 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 "expected encrypted mail for $1" >&2
|
||||
echo "BAD: encryped mail expected but not found" >&2
|
||||
R=1
|
||||
fi
|
||||
;;
|
||||
unencrypted)
|
||||
if grep -q "BEGIN PGP MESSAGE" /var/mail/$1 ; then
|
||||
echo "expected unencrypted mail for $1" >&2
|
||||
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 "no mail for $1" >&2
|
||||
echo "BAD: no mail for $1" >&2
|
||||
R=1
|
||||
fi
|
||||
echo $R
|
||||
|
||||
Reference in New Issue
Block a user