Compare commits

...

8 Commits

Author SHA1 Message Date
holger krekel
c0f20f0c0b adapt init 2023-10-14 14:04:56 +02:00
holger krekel
d07aab03b9 add basic delta chat tests 2023-10-14 13:56:18 +02:00
holger krekel
fb7d34b06a fix/merge test files 2023-10-14 13:15:58 +02:00
holger krekel
d6eeb0b1d4 merge accidental test files 2023-10-14 13:15:07 +02:00
holger krekel
fc1779926a let mail connection setting come from CHATMAIL_DOMAIN env 2023-10-14 12:25:13 +02:00
holger krekel
0f2cb90e09 add tests 2023-10-14 12:07:46 +02:00
holger krekel
207d7c7060 add smtp tests and fix scripts 2023-10-14 12:01:39 +02:00
holger krekel
c7dfd7ca41 refactor dovecot tests, move online tests one level up 2023-10-14 11:42:58 +02:00
7 changed files with 171 additions and 34 deletions

View File

@@ -27,9 +27,6 @@ chatmail-pyinfra
pyproject.toml pyproject.toml
chatmail/__init__ ... chatmail/__init__ ...
# tests against the deployed system
tests/test_online_test.py
# doveauth tool used by dovecot's auth mechanism on the host system # doveauth tool used by dovecot's auth mechanism on the host system
doveauth doveauth
README.md README.md
@@ -44,12 +41,18 @@ filtermail
pyproject.toml pyproject.toml
.... ....
# online tests (after deploy)
online-tests # runnable via pytest
# scripts for setup/development/deployment # scripts for setup/development/deployment
scripts/ scripts/
init.sh # create venv/other perequires init.sh # create venv/other perequires
deploy.sh # run pyinfra based deploy of everything deploy.sh # run pyinfra based deploy of everything
test.sh # run all local and online tests
``` ```

View File

@@ -1,28 +0,0 @@
import pytest
import imaplib
@pytest.fixture
def conn():
return connect("c1.testrun.org")
def login(conn, user, password):
print("trying to login", user, password)
conn.login(user, password)
def connect(host):
print(f"connecting to {host}")
conn = imaplib.IMAP4_SSL(host)
return conn
def test_login_ok(conn):
login(conn, "link2xt@c1.testrun.org", "Ahyei6ie")
def test_login_fail(conn):
with pytest.raises(imaplib.IMAP4.error) as excinfo:
login(conn, "link2xt@c1.testrun.org", "qweqwe")
assert "AUTHENTICATIONFAILED" in str(excinfo)

101
online-tests/conftest.py Normal file
View File

@@ -0,0 +1,101 @@
import os
import io
import imaplib
import smtplib
import itertools
import pytest
@pytest.fixture
def maildomain():
return os.environ.get("CHATMAIL_DOMAIN", "c1.testrun.org")
@pytest.fixture
def imap(maildomain):
return ImapConn(maildomain)
class ImapConn:
def __init__(self, host):
self.host = host
def connect(self):
print(f"imap-connect {self.host}")
self.conn = imaplib.IMAP4_SSL(self.host)
def login(self, user, password):
print(f"imap-login {user!r} {password!r}")
self.conn.login(user, password)
@pytest.fixture
def smtp(maildomain):
return SmtpConn(maildomain)
class SmtpConn:
def __init__(self, host):
self.host = host
def connect(self):
print(f"smtp-connect {self.host}")
self.conn = smtplib.SMTP_SSL(self.host)
def login(self, user, password):
print(f"smtp-login {user!r} {password!r}")
self.conn.login(user, password)
@pytest.fixture
def gencreds(maildomain):
count = itertools.count()
def gen():
while 1:
num = next(count)
yield f"user{num}@{maildomain}", f"password{num}"
return lambda: next(gen())
#
# Delta Chat testplugin re-use
# use the cmfactory fixture to get chatmail instance accounts
#
class ChatmailTestProcess:
"""Provider for chatmail instance accounts as used by deltachat.testplugin.acfactory """
def __init__(self, pytestconfig, maildomain, gencreds):
self.pytestconfig = pytestconfig
self.maildomain = maildomain
self.gencreds = gencreds
self._addr2files = {}
def get_liveconfig_producer(self):
while 1:
user, password = self.gencreds()
config = {"addr": user, "mail_pw": password}
yield config
def cache_maybe_retrieve_configured_db_files(self, cache_addr, db_target_path):
pass
def cache_maybe_store_configured_db_files(self, acc):
pass
@pytest.fixture
def cmfactory(request, maildomain, gencreds, tmpdir, data):
# cloned from deltachat.testplugin.amfactory
pytest.importorskip("deltachat")
from deltachat.testplugin import ACFactory
testproc = ChatmailTestProcess(request.config, maildomain, gencreds)
am = ACFactory(request=request, tmpdir=tmpdir, testprocess=testproc, data=data)
yield am
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
if testprocess.pytestconfig.getoption("--extra-info"):
logfile = io.StringIO()
am.dump_imap_summary(logfile=logfile)
print(logfile.getvalue())
# request.node.add_report_section("call", "imap-server-state", s)

View File

@@ -0,0 +1,13 @@
class TestMailSending:
def test_one_on_one(self, cmfactory, lp):
ac1, ac2 = cmfactory.get_online_accounts(2)
chat = cmfactory.get_accepted_chat(ac1, ac2)
lp.sec("ac1: prepare and send text message to ac2")
msg1 = chat.send_text("message0")
lp.sec("wait for ac2 to receive message")
msg2 = ac2._evtracker.wait_next_incoming_message()
assert msg2.text == "message0"

View File

@@ -0,0 +1,42 @@
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)

View File

@@ -3,6 +3,10 @@ python3 -m venv chatmail-pyinfra/venv
chatmail-pyinfra/venv/bin/pip install pyinfra pytest chatmail-pyinfra/venv/bin/pip install pyinfra pytest
chatmail-pyinfra/venv/bin/pip install -e chatmail-pyinfra chatmail-pyinfra/venv/bin/pip install -e chatmail-pyinfra
chatmail-pyinfra/venv/bin/pip install -e doveauth chatmail-pyinfra/venv/bin/pip install -e doveauth
python3 -m venv doveauth/venv python3 -m venv doveauth/venv
doveauth/venv/bin/pip install pytest build doveauth/venv/bin/pip install pytest build
doveauth/venv/bin/pip install -e doveauth doveauth/venv/bin/pip install -e doveauth
python3 -m venv online-tests/venv
online-tests/venv/bin/pip install pytest pytest-timeout pdbpp deltachat

View File

@@ -1,4 +1,6 @@
#!/bin/sh #!/bin/bash
chatmail-pyinfra/venv/bin/pytest chatmail-pyinfra/tests pushd doveauth/src/doveauth
cd doveauth/src/doveauth
../../venv/bin/pytest ../../venv/bin/pytest
popd
online-tests/venv/bin/pytest online-tests/ -vrx --durations=5