Add test framework to test

- Mail encryption (when expected)
- Introducer listing, adding and removing
- Locals listing, adding and removing
This commit is contained in:
Malte Meiboom
2026-05-20 14:27:28 +02:00
parent aed368e90d
commit 1f8d7e9a3f
19 changed files with 303 additions and 96 deletions
+7 -10
View File
@@ -1,18 +1,15 @@
#!/usr/bin/bash
echo "Basic: Test if MTA is working"
# source some functions
. common.sh
adduser --shell /bin/bash --disabled-password --gecos "" mtatest
echo "test mail" | sendmail mtatest@example.com
test_header "Basic: Test if MTA is working"
sleep 1
create_unix_user mtatest
send_test_mail mtatest@example.com
if [ -f /var/mail/mtatest ] ; then
RESULT_CODE=0
else
RESULT_CODE=1
fi
RESULT_CODE=$(expect_mail mtatest delivered)
deluser --remove-home mtatest
delete_unix_user mtatest
exit $RESULT_CODE
+8 -17
View File
@@ -1,25 +1,16 @@
#!/usr/bin/bash
echo "Simple: Test encryption for available certificate"
# source some functions
. common.sh
test_header "Simple: Test encryption for available certificate"
# There is an authenticated certificate for bob in the cert store
adduser --shell /bin/bash --disabled-password --gecos "" bob
echo "test mail" | sendmail bob@example.com
create_unix_user bob
send_test_mail bob@example.com
sleep 1
RESULT_CODE=$(expect_mail bob encrypted)
if [ -f /var/mail/bob ] ; then
if grep -q "BEGIN PGP MESSAGE" /var/mail/bob ; then
RESULT_CODE=0
else
echo "no encryption detected"
RESULT_CODE=1
fi
else
echo "no mail detected"
RESULT_CODE=1
fi
deluser --remove-home bob
delete_unix_user bob
exit $RESULT_CODE
+8 -17
View File
@@ -1,25 +1,16 @@
#!/usr/bin/bash
echo "Simple: Test encryption for unavailable certificate"
# source some functions
. common.sh
test_header "Simple: Test encryption for unavailable certificate"
# There is no authenticated certificate for alice in the cert store
adduser --shell /bin/bash --disabled-password --gecos "" alice
echo "test mail" | sendmail alice@example.com
create_unix_user alice
send_test_mail alice@example.com
sleep 1
RESULT_CODE=$(expect_mail alice unencrypted)
if [ -f /var/mail/alice ] ; then
if grep -q "BEGIN PGP MESSAGE" /var/mail/alice ; then
echo "encryption detected - that is wrong"
RESULT_CODE=1
else
RESULT_CODE=0
fi
else
echo "no mail detected"
RESULT_CODE=1
fi
deluser --remove-home alice
delete_unix_user alice
exit $RESULT_CODE
+8 -17
View File
@@ -1,26 +1,17 @@
#!/usr/bin/bash
echo "Test encryption for certificate an a keyserver"
# source some functions
. common.sh
test_header "Test encryption for certificate an a keyserver"
# There is a certificate for carol on the keyserver
# it's certified by an introducer
adduser --shell /bin/bash --disabled-password --gecos "" carol
echo "test mail" | sendmail carol@example.com
create_unix_user carol
send_test_mail carol@example.com
sleep 1
RESULT_CODE=$(expect_mail carol encrypted)
if [ -f /var/mail/carol ] ; then
if grep -q "BEGIN PGP MESSAGE" /var/mail/carol ; then
RESULT_CODE=0
else
echo "no encryption detected"
RESULT_CODE=1
fi
else
echo "no mail detected"
RESULT_CODE=1
fi
deluser --remove-home carol
delete_unix_user carol
exit $RESULT_CODE
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/bash
# source some functions
. common.sh
test_header "Add introducer"
ELLEN_FPR=$(sq key generate --shared-key --without-password --name "Ellen" --email "ellen@example.com" 2>&1 | grep "Fingerprint:" | cut -d ':' -f 2)
cd $HUSK_DIR
$HUSK_BIN introducer add --cert $ELLEN_FPR --domains "example.org" --config config/config.toml
$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 vouch add --certifier $ELLEN_FPR --cert $FRED_FPR --email "fred@example.org"
send_test_mail fred@example.org
RESULT_CODE=$(expect_mail fred encrypted)
if [ "$RESULT_CODE" == "1" ] ; then
exit 1
fi
test_header "Remove introducer"
$HUSK_BIN introducer remove --cert $ELLEN_FPR --config config/config.toml
$HUSK_BIN introducer list --config config/config.toml
rm /var/mail/fred
send_test_mail fred@example.org
RESULT_CODE=$(expect_mail fred unencrypted)
delete_unix_user fred
exit $RESULT_CODE
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/bash
# source some functions
. common.sh
export SEQUOIA_HOME=$(mktemp -d)
test_header "Import introducer from file"
# create ellen
ELLEN_FPR=$(sq key generate --shared-key --without-password --name "Ellen" --email "ellen@example.com" 2>&1 | grep "Fingerprint:" | cut -d ':' -f 2)
sq cert export --cert $ELLEN_FPR > /tmp/ellen_pk.pgp
cd $HUSK_DIR
$HUSK_BIN introducer add --cert-file /tmp/ellen_pk.pgp --domains example.org --config config/config.toml
LIST=$($HUSK_BIN introducer list --config config/config.toml)
echo $LIST | grep -q 'ellen@example.com'
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/bash
# source some functions
. common.sh
test_header "List locals"
GINA_FPR=$(sq key generate --shared-key --without-password --name "Gina" --email "gina@example.com" 2>&1 | grep "Fingerprint:" | cut -d ':' -f 2)
cd $HUSK_DIR
$HUSK_BIN locals list --config config/config.toml | grep $GINA_FPR
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/bash
# source some functions
. common.sh
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
cd $HUSK_DIR
$HUSK_BIN locals add --cert-file /tmp/hubert.pgp --config config/config.toml
if ! $HUSK_BIN locals list --config config/config.toml | grep -q "hubert@example.com" ; then
echo "adding failed"
exit 1
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"
delete_unix_user hubert
exit 1
fi
sleep 1
# remove 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"
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
delete_unix_user hubert
exit $RESULT_CODE