diff options
Diffstat (limited to 'debian/tests/usage')
-rwxr-xr-x | debian/tests/usage/00_setup | 50 | ||||
-rwxr-xr-x | debian/tests/usage/imap | 38 | ||||
-rwxr-xr-x | debian/tests/usage/pop3 | 31 |
3 files changed, 119 insertions, 0 deletions
diff --git a/debian/tests/usage/00_setup b/debian/tests/usage/00_setup new file mode 100755 index 0000000..2eeeb2f --- /dev/null +++ b/debian/tests/usage/00_setup @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +echo "Setting up dovecot for the test" +# Move aside 10-auth.conf to disable passwd-based auth +if [ -f /etc/dovecot/conf.d/10-auth.conf ]; then + mv /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf.bak +fi + +cat >/etc/dovecot/local.conf <<-EOF + auth_mechanisms = plain + mail_location = maildir:~/Maildir + + passdb { + driver = static + args = password=test + } + + userdb { + driver = static + args = uid=nobody gid=nogroup home=/srv/dovecot-dep8/%u + } +EOF + +mkdir -p /srv/dovecot-dep8 +chown nobody:nogroup /srv/dovecot-dep8 + +echo "Restarting the service" +systemctl restart dovecot + +echo "Sending a test message via the LDA" +/usr/lib/dovecot/dovecot-lda -f "test@example.com" -d dep8 <<EOF +Return-Path: <test@example.com> +Message-Id: <dep8-test-1@debian.org> +From: Test User <test@example.com> +To: dep8 <dep8@example.com> +Subject: DEP-8 test + +This is just a test +EOF + +echo "Verifying that the email was correctly delivered" +if [ -z "$(doveadm search -u dep8 header message-id dep8-test-1@debian.org)" ]; then + echo "Message not found" + exit 1 +fi + +echo "Done" +echo diff --git a/debian/tests/usage/imap b/debian/tests/usage/imap new file mode 100755 index 0000000..5bdede7 --- /dev/null +++ b/debian/tests/usage/imap @@ -0,0 +1,38 @@ +#!/usr/bin/python3 +import imaplib + +imaplib.Debug = 4 + +print("Testing IMAP") +print("Connecting") +client = imaplib.IMAP4('localhost') + +print("Checking for STARTTLS capability") +assert 'STARTTLS' in client.capabilities + +client.starttls() + +print("Logging in") +client.login('dep8', 'test') + +print("Selecting INBOX") +client.select() + +print("Looking for the test message") +res, uids = client.search(None, 'HEADER', 'MESSAGE-ID', '"<dep8-test-1@debian.org>"') + +assert res == 'OK' +assert len(uids[0]) > 0 + +uid = uids[0].split()[0] + +print("Fetching and verifying test message") +res, data = client.fetch(uid, '(RFC822)') + +assert res == 'OK' + +lines = data[0][1].splitlines() + +assert b'Subject: DEP-8 test' in lines + +print("Done") diff --git a/debian/tests/usage/pop3 b/debian/tests/usage/pop3 new file mode 100755 index 0000000..00b1657 --- /dev/null +++ b/debian/tests/usage/pop3 @@ -0,0 +1,31 @@ +#!/usr/bin/python3 +import poplib + +print("Testing POP3") +print("Connecting") +client = poplib.POP3('localhost') +client.set_debuglevel(2) + +print("Checking for STARTTLS capability") +assert 'STLS' in client.capa() + +client.stls() + +print("Logging in") +client.user('dep8') +client.pass_('test') + +print("Listing INBOX") +res, data, _ = client.list() +assert res.startswith(b'+OK') + +print("Fetching and verifying test message") +for entry in data: + _id, _ = entry.split(maxsplit=1) + res, body, _ = client.retr(int(_id)) + if b'Subject: DEP-8 test' in body: + break +else: + raise AssertionError("Test message not found") + +print("Done") |