From 6003c9294d5f61f3f8c878aa15d324185f809ac8 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 14 Oct 2023 12:07:46 +0200 Subject: [PATCH] add tests --- online-tests/test_online_login.py | 44 +++++++++++++++++++++++++++++++ scripts/test.sh | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 online-tests/test_online_login.py diff --git a/online-tests/test_online_login.py b/online-tests/test_online_login.py new file mode 100644 index 00000000..24d3a57b --- /dev/null +++ b/online-tests/test_online_login.py @@ -0,0 +1,44 @@ +import pytest +import imaplib +import smtplib + + +class TestDovecot: + def test_login_ok(self, imap, gencreds): + user, password = gencreds() + imap.connect() + imap.login(user, password) + # verify it works on another connection + imap.connect() + imap.login(user, password) + + def test_login_fail(self, imap, gencreds): + user, password = gencreds() + imap.connect() + imap.login(user, password) + imap.connect() + with pytest.raises(imaplib.IMAP4.error) as excinfo: + imap.login(user, password + "wrong") + assert "AUTHENTICATIONFAILED" in str(excinfo) + + +class TestPostfix: + def test_login_ok(self, smtp, gencreds): + user, password = gencreds() + smtp.connect() + smtp.login(user, password) + # verify it works on another connection + smtp.connect() + smtp.login(user, password) + + def test_login_fail(self, smtp, gencreds): + user, password = gencreds() + smtp.connect() + smtp.login(user, password) + smtp.connect() + with pytest.raises(smtplib.SMTPAuthenticationError) as excinfo: + smtp.login(user, password + "wrong") + assert excinfo.value.smtp_code == 535 + assert "authentication failed" in str(excinfo) + + diff --git a/scripts/test.sh b/scripts/test.sh index 0bca51c8..ba949357 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -3,4 +3,4 @@ pushd doveauth/src/doveauth ../../venv/bin/pytest popd -online-tests/venv/bin/pytest online-tests/ -vrx +online-tests/venv/bin/pytest online-tests/ -vrx --durations=5