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
|
||||
|
||||
@@ -14,12 +14,11 @@ $HUSK_BIN introducer list --config config/config.toml
|
||||
create_unix_user fred
|
||||
FRED_FPR=$(sq key generate --shared-key --without-password --name "Fred" --email "fred@example.org" 2>&1 | grep "Fingerprint:" | cut -d ':' -f 2)
|
||||
sleep 1
|
||||
sq pki link retract --cert $FRED_FPR --all
|
||||
sq pki link retract --cert $FRED_FPR --all > /dev/null 2>&1
|
||||
|
||||
sq pki vouch add --certifier $ELLEN_FPR --cert $FRED_FPR --email "fred@example.org"
|
||||
sq pki vouch add --certifier $ELLEN_FPR --cert $FRED_FPR --email "fred@example.org" > /dev/null 2>&1
|
||||
|
||||
send_test_mail fred@example.org
|
||||
|
||||
RESULT_CODE=$(expect_mail fred encrypted)
|
||||
|
||||
if [ "$RESULT_CODE" == "1" ] ; then
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
test_header "Add locals"
|
||||
|
||||
sq key generate --shared-key --without-password --email 'hubert@example.com' --output /tmp/hubert.pgp --rev-cert /tmp/hubert_rev.pgp
|
||||
sq key generate --shared-key --without-password --email 'hubert@example.com' --output /tmp/hubert.pgp --rev-cert /tmp/hubert_rev.pgp > /dev/null 2>&1
|
||||
|
||||
cd $HUSK_DIR
|
||||
|
||||
@@ -16,47 +16,27 @@ if ! $HUSK_BIN locals list --config config/config.toml | grep -q "hubert@example
|
||||
fi
|
||||
|
||||
# send a mail, husk should encrypt it
|
||||
echo "send mail to hubert@example.com"
|
||||
create_unix_user hubert
|
||||
send_test_mail hubert@example.com
|
||||
|
||||
if [ -f /var/mail/hubert ] ; then
|
||||
if grep -q "BEGIN PGP MESSAGE" /var/mail/hubert ; then
|
||||
RESULT_CODE=0
|
||||
else
|
||||
echo "no encryption detected"
|
||||
delete_unix_user hubert
|
||||
exit 1
|
||||
fi
|
||||
# remove mail
|
||||
rm /var/mail/hubert
|
||||
else
|
||||
echo "no mail detected"
|
||||
R=$(expect_mail hubert encrypted)
|
||||
if [ $R != 0 ] ; then
|
||||
delete_unix_user hubert
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
# remove hubert as local
|
||||
|
||||
echo "removing hubert as local"
|
||||
HUBERT_FPR=$(sq cert list --cert-email hubert@example.com 2>/dev/null | head -n 1 | cut -d ' ' -f 3)
|
||||
$HUSK_BIN locals remove --cert $HUBERT_FPR --config config/config.toml
|
||||
|
||||
echo "send mail to hubert@example.com"
|
||||
rm /var/mail/hubert
|
||||
send_test_mail hubert@example.com
|
||||
|
||||
if [ -f /var/mail/hubert ] ; then
|
||||
if grep -q "BEGIN PGP MESSAGE" /var/mail/hubert ; then
|
||||
echo "encryption detected where there should be none"
|
||||
RESULT_CODE=1
|
||||
else
|
||||
RESULT_CODE=0
|
||||
fi
|
||||
else
|
||||
echo "no mail detected"
|
||||
RESULT_CODE=1
|
||||
fi
|
||||
R=$(expect_mail hubert unencrypted)
|
||||
|
||||
delete_unix_user hubert
|
||||
|
||||
exit $RESULT_CODE
|
||||
exit $R
|
||||
|
||||
|
||||
@@ -5,39 +5,28 @@
|
||||
|
||||
test_header "Signing"
|
||||
|
||||
# sq key generate --shared-key --without-password --email 'signing@example.com' --output /tmp/signing.pgp --rev-cert /tmp/signing.rev
|
||||
|
||||
SIGN_FPR=$(sq key generate --own-key --without-password --name "Signing Key" 2>&1 | grep "Fingerprint:" | cut -d ':' -f 2)
|
||||
SIGN_FPR_GEN=$(sq key generate --own-key --without-password --name "Signing Key" 2>&1 | grep "Fingerprint:" | cut -d ':' -f 2 | tr -d ' ')
|
||||
|
||||
cd $HUSK_DIR
|
||||
|
||||
$HUSK_BIN --config config/config.toml signkey set --cert $SIGN_FPR
|
||||
$HUSK_BIN --config config/config.toml signkey set --cert $SIGN_FPR_GEN
|
||||
SIGN_FPR=$($HUSK_BIN --config config/config.toml signkey show | cut -d ':' -f 2 | tr -d ' ')
|
||||
echo "found signing key $SIGN_FPR"
|
||||
|
||||
if [ "$SIGN_FPR" != "$SIGN_FPR_GEN" ] ; then
|
||||
echo "setting new siging key failed, found $SIGN_FPR expected $SIGN_FPR_GEN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
create_unix_user juliette
|
||||
JULIETTE_FPR=$(sq key generate --own-key --without-password --name "Juliette" --email "juliette@example.com" 2>&1 | grep "Fingerprint:" | cut -d ':' -f 2)
|
||||
sq pki vouch add --certifier-userid "CA" --cert $JULIETTE_FPR --all > /dev/null 2>&1
|
||||
# sq pki vouch add --certifier-userid "CA" --cert $JULIETTE_FPR --all > /dev/null 2>&1
|
||||
|
||||
# send a mail, husk should encrypt it
|
||||
echo "send mail to juliette@example.com"
|
||||
send_test_mail juliette@example.com
|
||||
|
||||
if [ -f /var/mail/juliette ] ; then
|
||||
if grep -q "BEGIN PGP MESSAGE" /var/mail/juliette ; then
|
||||
|
||||
FOUND_FPR=$(sq packet dump /var/mail/juliette | grep "Issuer Fingerprint:" | cut -d ':' -f 2 | tr -d ' ')
|
||||
|
||||
if [ "$SIGN_FPR" != "$FOUND_FPR" ] ; then
|
||||
echo "Found wrong fingerprint '$FOUND_FPR' - expected '$SIGN_FPR'"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "no encryption detected"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "no mail detected"
|
||||
R=$(expect_mail juliette encrypted $SIGN_FPR)
|
||||
if [ $R != 0 ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -50,23 +39,6 @@ echo "new signing key $SIGN_FPR"
|
||||
# remove old mail
|
||||
rm /var/mail/juliette
|
||||
|
||||
echo "send mail to juliette@example.com"
|
||||
send_test_mail juliette@example.com
|
||||
|
||||
if [ -f /var/mail/juliette ] ; then
|
||||
if grep -q "BEGIN PGP MESSAGE" /var/mail/juliette ; then
|
||||
|
||||
FOUND_FPR=$(sq packet dump /var/mail/juliette | grep "Issuer Fingerprint:" | cut -d ':' -f 2 | tr -d ' ')
|
||||
|
||||
if [ "$SIGN_FPR" != "$FOUND_FPR" ] ; then
|
||||
echo "Found wrong fingerprint '$FOUND_FPR' - expected '$SIGN_FPR'"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "no encryption detected"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "no mail detected"
|
||||
exit 1
|
||||
fi
|
||||
exit $(expect_mail juliette encrypted $SIGN_FPR)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# source some functions
|
||||
. common.sh
|
||||
|
||||
test_header "Mail split"
|
||||
|
||||
create_unix_user karl
|
||||
KARL_FPR=$(gen_cert karl@example.com)
|
||||
authenticate $KARL_FPR
|
||||
|
||||
create_unix_user laura
|
||||
|
||||
echo -e "To: karl@example.com, Laura <laura@example.com>\nSubject: Testmail\n\nTestmail." | sendmail -t
|
||||
sleep 1
|
||||
|
||||
R=1
|
||||
if [ $(expect_mail karl encrypted) == 0 ] ; then
|
||||
if [ $(expect_mail laura unencrypted) == 0 ] ; then
|
||||
R=0
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $R
|
||||
Reference in New Issue
Block a user