mirror of
https://github.com/chatmail/relay.git
synced 2026-05-11 16:34:39 +00:00
Compare commits
28 Commits
link2xt/ch
...
link2xt/se
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20d9947573 | ||
|
|
408da296f1 | ||
|
|
192238567b | ||
|
|
c35e485510 | ||
|
|
1bac4b5b46 | ||
|
|
63a7ad82ff | ||
|
|
37ef3f13b4 | ||
|
|
9dfd0ceb5a | ||
|
|
55c58e3c7a | ||
|
|
c2692c7e92 | ||
|
|
ea5eccf377 | ||
|
|
c9ecf24b3e | ||
|
|
b943f24587 | ||
|
|
df00333a19 | ||
|
|
4fc63461fb | ||
|
|
00af333694 | ||
|
|
c9fd133942 | ||
|
|
caed6a3754 | ||
|
|
f71d372491 | ||
|
|
6debf11f6f | ||
|
|
60e1671062 | ||
|
|
3c57155c40 | ||
|
|
cf1be90115 | ||
|
|
5781d3b04e | ||
|
|
862b09d268 | ||
|
|
9b438a7a96 | ||
|
|
a107fb3cca | ||
|
|
2a59cd4702 |
@@ -52,6 +52,7 @@ 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
|
test.sh # run all local and online tests
|
||||||
|
bench.sh # run performance benchmark tests
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ def encrypt_password(password: str):
|
|||||||
password = password.encode("ascii")
|
password = password.encode("ascii")
|
||||||
# https://doc.dovecot.org/configuration_manual/authentication/password_schemes/
|
# https://doc.dovecot.org/configuration_manual/authentication/password_schemes/
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
["doveadm", "pw", "-s", "BLF-CRYPT"],
|
["doveadm", "pw", "-s", "SHA512-CRYPT"],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
@@ -59,7 +59,7 @@ def handle_dovecot_request(msg, db):
|
|||||||
if short_command == "L": # LOOKUP
|
if short_command == "L": # LOOKUP
|
||||||
parts = msg[1:].split("\t")
|
parts = msg[1:].split("\t")
|
||||||
keyname, user = parts[:2]
|
keyname, user = parts[:2]
|
||||||
namespace, type, arg = keyname.split("/", 3)
|
namespace, type, *args = keyname.split("/")
|
||||||
reply_command = "F"
|
reply_command = "F"
|
||||||
res = ""
|
res = ""
|
||||||
if namespace == "shared":
|
if namespace == "shared":
|
||||||
@@ -70,7 +70,7 @@ def handle_dovecot_request(msg, db):
|
|||||||
else:
|
else:
|
||||||
reply_command = "N"
|
reply_command = "N"
|
||||||
elif type == "passdb":
|
elif type == "passdb":
|
||||||
res = lookup_passdb(db, user, password=arg)
|
res = lookup_passdb(db, user, password=args[0])
|
||||||
if res:
|
if res:
|
||||||
reply_command = "O"
|
reply_command = "O"
|
||||||
else:
|
else:
|
||||||
@@ -95,7 +95,7 @@ def main():
|
|||||||
while True:
|
while True:
|
||||||
msg = self.rfile.readline().strip().decode()
|
msg = self.rfile.readline().strip().decode()
|
||||||
if not msg:
|
if not msg:
|
||||||
continue
|
break
|
||||||
res = handle_dovecot_request(msg, db)
|
res = handle_dovecot_request(msg, db)
|
||||||
if res:
|
if res:
|
||||||
print(f"sending result: {res!r}", file=sys.stderr)
|
print(f"sending result: {res!r}", file=sys.stderr)
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ from aiosmtpd.controller import UnixSocketController
|
|||||||
from smtplib import SMTP as SMTPClient
|
from smtplib import SMTP as SMTPClient
|
||||||
|
|
||||||
|
|
||||||
def check_encrypted(content):
|
def check_encrypted(message):
|
||||||
"""Check that the message is an OpenPGP-encrypted message."""
|
"""Check that the message is an OpenPGP-encrypted message."""
|
||||||
message = BytesParser(policy=policy.default).parsebytes(content)
|
|
||||||
if not message.is_multipart():
|
if not message.is_multipart():
|
||||||
return False
|
return False
|
||||||
if message.get("subject") != "...":
|
if message.get("subject") != "...":
|
||||||
@@ -47,7 +46,8 @@ class ExampleHandler:
|
|||||||
|
|
||||||
valid_recipients = []
|
valid_recipients = []
|
||||||
|
|
||||||
mail_encrypted = check_encrypted(envelope.content)
|
message = BytesParser(policy=policy.default).parsebytes(envelope.content)
|
||||||
|
mail_encrypted = check_encrypted(message)
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
for recipient in envelope.rcpt_tos:
|
for recipient in envelope.rcpt_tos:
|
||||||
@@ -68,7 +68,13 @@ class ExampleHandler:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
is_outgoing = recipient_local_domain[1] != my_local_domain[1]
|
is_outgoing = recipient_local_domain[1] != my_local_domain[1]
|
||||||
if is_outgoing and not mail_encrypted:
|
|
||||||
|
if (
|
||||||
|
is_outgoing
|
||||||
|
and not mail_encrypted
|
||||||
|
and message.get("secure-join") != "vc-request"
|
||||||
|
and message.get("secure-join") != "vg-request"
|
||||||
|
):
|
||||||
res += ["500 Outgoing mail must be encrypted"]
|
res += ["500 Outgoing mail must be encrypted"]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
from .filtermail import check_encrypted
|
from .filtermail import check_encrypted
|
||||||
|
from email.parser import BytesParser
|
||||||
|
from email import policy
|
||||||
|
|
||||||
|
|
||||||
def test_filtermail():
|
def test_filtermail():
|
||||||
assert not check_encrypted(b"foo")
|
def check_encrypted_bstr(content):
|
||||||
|
message = BytesParser(policy=policy.default).parsebytes(content)
|
||||||
|
return check_encrypted(message)
|
||||||
|
|
||||||
assert not check_encrypted(
|
assert not check_encrypted_bstr(b"foo")
|
||||||
|
|
||||||
|
assert not check_encrypted_bstr(
|
||||||
"\r\n".join(
|
"\r\n".join(
|
||||||
[
|
[
|
||||||
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
||||||
@@ -36,7 +40,7 @@ def test_filtermail():
|
|||||||
).encode()
|
).encode()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert not check_encrypted(
|
assert not check_encrypted_bstr(
|
||||||
"\r\n".join(
|
"\r\n".join(
|
||||||
[
|
[
|
||||||
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
||||||
@@ -67,7 +71,7 @@ def test_filtermail():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# https://xkcd.com/1181/
|
# https://xkcd.com/1181/
|
||||||
assert not check_encrypted(
|
assert not check_encrypted_bstr(
|
||||||
"\r\n".join(
|
"\r\n".join(
|
||||||
[
|
[
|
||||||
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
"Subject: =?utf-8?q?Message_from_foobar=40c2=2Etestrun=2Eorg?=",
|
||||||
@@ -99,7 +103,7 @@ def test_filtermail():
|
|||||||
).encode()
|
).encode()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert check_encrypted(
|
assert check_encrypted_bstr(
|
||||||
"\r\n".join(
|
"\r\n".join(
|
||||||
[
|
[
|
||||||
"Subject: ...",
|
"Subject: ...",
|
||||||
@@ -172,7 +176,7 @@ def test_filtermail():
|
|||||||
).encode()
|
).encode()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert not check_encrypted(
|
assert not check_encrypted_bstr(
|
||||||
"\r\n".join(
|
"\r\n".join(
|
||||||
[
|
[
|
||||||
"Subject: Buy Penis Enlargement at www.malicious-domain.com",
|
"Subject: Buy Penis Enlargement at www.malicious-domain.com",
|
||||||
@@ -245,7 +249,7 @@ def test_filtermail():
|
|||||||
).encode()
|
).encode()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert not check_encrypted(
|
assert not check_encrypted_bstr(
|
||||||
"\r\n".join(
|
"\r\n".join(
|
||||||
[
|
[
|
||||||
"Subject: Message opened",
|
"Subject: Message opened",
|
||||||
|
|||||||
@@ -160,6 +160,16 @@ def _configure_dovecot(mail_server: str) -> bool:
|
|||||||
)
|
)
|
||||||
need_restart |= auth_config.changed
|
need_restart |= auth_config.changed
|
||||||
|
|
||||||
|
files.put(
|
||||||
|
src=importlib.resources.files(__package__)
|
||||||
|
.joinpath("dovecot/expunge.cron")
|
||||||
|
.open("rb"),
|
||||||
|
dest="/etc/cron.d/expunge",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="644",
|
||||||
|
)
|
||||||
|
|
||||||
return need_restart
|
return need_restart
|
||||||
|
|
||||||
|
|
||||||
@@ -171,7 +181,7 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N
|
|||||||
:param dkim_selector:
|
:param dkim_selector:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
apt.update(name="apt update")
|
apt.update(name="apt update", cache_time=24 * 3600)
|
||||||
server.group(name="Create vmail group", group="vmail", system=True)
|
server.group(name="Create vmail group", group="vmail", system=True)
|
||||||
server.user(name="Create vmail user", user="vmail", group="vmail", system=True)
|
server.user(name="Create vmail user", user="vmail", group="vmail", system=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
uri = proxy:/run/dovecot/doveauth.socket:auth
|
uri = proxy:/run/dovecot/doveauth.socket:auth
|
||||||
iterate_disable = yes
|
iterate_disable = yes
|
||||||
default_pass_scheme = plain
|
default_pass_scheme = plain
|
||||||
password_key = passdb/%w
|
password_key = passdb/%w/%u
|
||||||
user_key = userdb/%u
|
user_key = userdb/%u
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ auth_verbose = yes
|
|||||||
auth_debug = yes
|
auth_debug = yes
|
||||||
auth_debug_passwords = yes
|
auth_debug_passwords = yes
|
||||||
auth_verbose_passwords = plain
|
auth_verbose_passwords = plain
|
||||||
|
auth_cache_size = 100M
|
||||||
|
mail_plugins = quota
|
||||||
|
mail_debug = yes
|
||||||
|
|
||||||
# Authentication for system users.
|
# Authentication for system users.
|
||||||
passdb {
|
passdb {
|
||||||
@@ -59,13 +62,28 @@ mail_privileged_group = vmail
|
|||||||
# Enable IMAP COMPRESS (RFC 4978).
|
# Enable IMAP COMPRESS (RFC 4978).
|
||||||
# <https://datatracker.ietf.org/doc/html/rfc4978.html>
|
# <https://datatracker.ietf.org/doc/html/rfc4978.html>
|
||||||
protocol imap {
|
protocol imap {
|
||||||
mail_plugins = $mail_plugins imap_zlib
|
mail_plugins = $mail_plugins imap_zlib imap_quota
|
||||||
|
}
|
||||||
|
|
||||||
|
protocol lmtp {
|
||||||
|
mail_plugins = $mail_plugins quota
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin {
|
plugin {
|
||||||
imap_compress_deflate_level = 6
|
imap_compress_deflate_level = 6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin {
|
||||||
|
# for now we define static quota-rules for all users
|
||||||
|
quota = maildir:User quota
|
||||||
|
quota_rule = *:storage=100M
|
||||||
|
quota_max_mail_size=30M
|
||||||
|
quota_grace = 0
|
||||||
|
# quota_over_flag_value = TRUE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
service lmtp {
|
service lmtp {
|
||||||
user=vmail
|
user=vmail
|
||||||
|
|
||||||
|
|||||||
4
deploy-chatmail/src/deploy_chatmail/dovecot/expunge.cron
Normal file
4
deploy-chatmail/src/deploy_chatmail/dovecot/expunge.cron
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
2 0 * * * dovecot doveadm expunge -A SEEN BEFORE 40d INBOX
|
||||||
|
2 0 * * * dovecot doveadm expunge -A SEEN BEFORE 40d Deltachat
|
||||||
|
2 0 * * * dovecot doveadm expunge -A SEEN BEFORE 40d Trash
|
||||||
|
2 30 * * * dovecot doveadm purge -A
|
||||||
@@ -37,6 +37,8 @@ mydestination =
|
|||||||
relayhost =
|
relayhost =
|
||||||
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
|
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
|
||||||
mailbox_size_limit = 0
|
mailbox_size_limit = 0
|
||||||
|
# maximum 30MB sized messages
|
||||||
|
message_size_limit = 31457280
|
||||||
recipient_delimiter = +
|
recipient_delimiter = +
|
||||||
inet_interfaces = all
|
inet_interfaces = all
|
||||||
inet_protocols = all
|
inet_protocols = all
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
# service type private unpriv chroot wakeup maxproc command + args
|
# service type private unpriv chroot wakeup maxproc command + args
|
||||||
# (yes) (yes) (no) (never) (100)
|
# (yes) (yes) (no) (never) (100)
|
||||||
# ==========================================================================
|
# ==========================================================================
|
||||||
smtp inet n - y - - smtpd
|
smtp inet n - y - - smtpd -v
|
||||||
#smtp inet n - y - 1 postscreen
|
#smtp inet n - y - 1 postscreen
|
||||||
#smtpd pass - - y - - smtpd
|
#smtpd pass - - y - - smtpd
|
||||||
#dnsblog unix - - y - 0 dnsblog
|
#dnsblog unix - - y - 0 dnsblog
|
||||||
@@ -28,7 +28,7 @@ submission inet n - y - - smtpd
|
|||||||
-o smtpd_recipient_restrictions=
|
-o smtpd_recipient_restrictions=
|
||||||
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
|
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
|
||||||
-o milter_macro_daemon_name=ORIGINATING
|
-o milter_macro_daemon_name=ORIGINATING
|
||||||
-o content_filter=filter:unix:private/filtemail
|
-o content_filter=filter:unix:private/filtermail
|
||||||
smtps inet n - y - - smtpd
|
smtps inet n - y - - smtpd
|
||||||
-o syslog_name=postfix/smtps
|
-o syslog_name=postfix/smtps
|
||||||
-o smtpd_tls_wrappermode=yes
|
-o smtpd_tls_wrappermode=yes
|
||||||
|
|||||||
34
online-tests/benchmark.py
Normal file
34
online-tests/benchmark.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
def test_tls_serialized_connect(benchmark, imap_or_smtp):
|
||||||
|
def connect():
|
||||||
|
imap_or_smtp.connect()
|
||||||
|
|
||||||
|
benchmark(connect)
|
||||||
|
|
||||||
|
|
||||||
|
def test_login(benchmark, imap_or_smtp, gencreds):
|
||||||
|
cls = imap_or_smtp.__class__
|
||||||
|
conns = []
|
||||||
|
for i in range(20):
|
||||||
|
conn = cls(imap_or_smtp.host)
|
||||||
|
conn.connect()
|
||||||
|
conns.append(conn)
|
||||||
|
|
||||||
|
def login():
|
||||||
|
conn = conns.pop()
|
||||||
|
conn.login(*gencreds())
|
||||||
|
|
||||||
|
benchmark(login)
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_and_receive_10(benchmark, cmfactory, lp):
|
||||||
|
"""send many messages between two accounts"""
|
||||||
|
ac1, ac2 = cmfactory.get_online_accounts(2)
|
||||||
|
chat = cmfactory.get_accepted_chat(ac1, ac2)
|
||||||
|
|
||||||
|
def send_10_receive_all():
|
||||||
|
for i in range(10):
|
||||||
|
chat.send_text(f"hello {i}")
|
||||||
|
for i in range(10):
|
||||||
|
ac2.wait_next_incoming_message()
|
||||||
|
|
||||||
|
benchmark(send_10_receive_all)
|
||||||
@@ -1,14 +1,57 @@
|
|||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
|
import random
|
||||||
|
import subprocess
|
||||||
import imaplib
|
import imaplib
|
||||||
import smtplib
|
import smtplib
|
||||||
import itertools
|
import itertools
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption(
|
||||||
|
"--slow", action="store_true", default=False, help="also run slow tests"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_runtest_setup(item):
|
||||||
|
markers = list(item.iter_markers(name="slow"))
|
||||||
|
if markers:
|
||||||
|
if not item.config.getoption("--slow"):
|
||||||
|
pytest.skip("skipping slow test, use --slow to run")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def maildomain():
|
def maildomain():
|
||||||
return os.environ.get("CHATMAIL_DOMAIN", "c1.testrun.org")
|
domain = os.environ.get("CHATMAIL_DOMAIN")
|
||||||
|
if not domain:
|
||||||
|
pytest.skip("set CHATMAIL_DOMAIN to a ssh-reachable chatmail instance")
|
||||||
|
return domain
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sshdomain(maildomain):
|
||||||
|
return os.environ.get("CHATMAIL_SSH", maildomain)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def maildomain2():
|
||||||
|
domain = os.environ.get("CHATMAIL_DOMAIN2")
|
||||||
|
if not domain:
|
||||||
|
pytest.skip("set CHATMAIL_DOMAIN2 to a ssh-reachable chatmail instance")
|
||||||
|
return domain
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sshdomain2(maildomain2):
|
||||||
|
return os.environ.get("CHATMAIL_SSH2", maildomain2)
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_report_header():
|
||||||
|
domain = os.environ.get("CHATMAIL_DOMAIN")
|
||||||
|
if domain:
|
||||||
|
text = f"chatmail test instance: {domain}"
|
||||||
|
return ["-" * len(text), text, "-" * len(text)]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -17,6 +60,10 @@ def imap(maildomain):
|
|||||||
|
|
||||||
|
|
||||||
class ImapConn:
|
class ImapConn:
|
||||||
|
AuthError = imaplib.IMAP4.error
|
||||||
|
logcmd = "journalctl -f -u dovecot"
|
||||||
|
name = "dovecot"
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
self.host = host
|
self.host = host
|
||||||
|
|
||||||
@@ -35,6 +82,10 @@ def smtp(maildomain):
|
|||||||
|
|
||||||
|
|
||||||
class SmtpConn:
|
class SmtpConn:
|
||||||
|
AuthError = smtplib.SMTPAuthenticationError
|
||||||
|
logcmd = "journalctl -f -t postfix/smtpd -t postfix/smtp -t postfix/lmtp"
|
||||||
|
name = "postfix"
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
self.host = host
|
self.host = host
|
||||||
|
|
||||||
@@ -47,16 +98,27 @@ class SmtpConn:
|
|||||||
self.conn.login(user, password)
|
self.conn.login(user, password)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=["imap", "smtp"])
|
||||||
|
def imap_or_smtp(request):
|
||||||
|
return request.getfixturevalue(request.param)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def gencreds(maildomain):
|
def gencreds(maildomain):
|
||||||
count = itertools.count()
|
count = itertools.count()
|
||||||
|
next(count)
|
||||||
|
|
||||||
def gen():
|
def gen(domain=None):
|
||||||
|
domain = domain if domain else maildomain
|
||||||
while 1:
|
while 1:
|
||||||
num = next(count)
|
num = next(count)
|
||||||
yield f"user{num}@{maildomain}", f"password{num}"
|
alphanumeric = "abcdefghijklmnopqrstuvwxyz1234567890"
|
||||||
|
user = "".join(random.choices(alphanumeric, k=10))
|
||||||
|
user = f"ac{num}_{user}"
|
||||||
|
password = "".join(random.choices(alphanumeric, k=10))
|
||||||
|
yield f"{user}@{domain}", f"{password}"
|
||||||
|
|
||||||
return lambda: next(gen())
|
return lambda domain=None: next(gen(domain))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -71,13 +133,20 @@ class ChatmailTestProcess:
|
|||||||
def __init__(self, pytestconfig, maildomain, gencreds):
|
def __init__(self, pytestconfig, maildomain, gencreds):
|
||||||
self.pytestconfig = pytestconfig
|
self.pytestconfig = pytestconfig
|
||||||
self.maildomain = maildomain
|
self.maildomain = maildomain
|
||||||
|
assert "." in self.maildomain, maildomain
|
||||||
self.gencreds = gencreds
|
self.gencreds = gencreds
|
||||||
self._addr2files = {}
|
self._addr2files = {}
|
||||||
|
|
||||||
def get_liveconfig_producer(self):
|
def get_liveconfig_producer(self):
|
||||||
while 1:
|
while 1:
|
||||||
user, password = self.gencreds()
|
user, password = self.gencreds(self.maildomain)
|
||||||
config = {"addr": user, "mail_pw": password}
|
config = {
|
||||||
|
"addr": user,
|
||||||
|
"mail_pw": password,
|
||||||
|
}
|
||||||
|
# speed up account configuration
|
||||||
|
config["mail_server"] = self.maildomain
|
||||||
|
config["send_server"] = self.maildomain
|
||||||
yield config
|
yield config
|
||||||
|
|
||||||
def cache_maybe_retrieve_configured_db_files(self, cache_addr, db_target_path):
|
def cache_maybe_retrieve_configured_db_files(self, cache_addr, db_target_path):
|
||||||
@@ -88,17 +157,45 @@ class ChatmailTestProcess:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cmfactory(request, maildomain, gencreds, tmpdir, data):
|
def cmfactory(request, gencreds, tmpdir, data, maildomain):
|
||||||
# cloned from deltachat.testplugin.amfactory
|
# cloned from deltachat.testplugin.amfactory
|
||||||
pytest.importorskip("deltachat")
|
pytest.importorskip("deltachat")
|
||||||
from deltachat.testplugin import ACFactory
|
from deltachat.testplugin import ACFactory
|
||||||
|
|
||||||
testproc = ChatmailTestProcess(request.config, maildomain, gencreds)
|
testproc = ChatmailTestProcess(request.config, maildomain, gencreds)
|
||||||
am = ACFactory(request=request, tmpdir=tmpdir, testprocess=testproc, data=data)
|
am = ACFactory(request=request, tmpdir=tmpdir, testprocess=testproc, data=data)
|
||||||
|
|
||||||
|
# nb. a bit hacky
|
||||||
|
# would probably be better if deltachat's test machinery grows native support
|
||||||
|
def switch_maildomain(maildomain2):
|
||||||
|
am.testprocess.maildomain = maildomain2
|
||||||
|
|
||||||
|
am.switch_maildomain = switch_maildomain
|
||||||
|
|
||||||
yield am
|
yield am
|
||||||
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
|
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
|
||||||
if testprocess.pytestconfig.getoption("--extra-info"):
|
if testproc.pytestconfig.getoption("--extra-info"):
|
||||||
logfile = io.StringIO()
|
logfile = io.StringIO()
|
||||||
am.dump_imap_summary(logfile=logfile)
|
am.dump_imap_summary(logfile=logfile)
|
||||||
print(logfile.getvalue())
|
print(logfile.getvalue())
|
||||||
# request.node.add_report_section("call", "imap-server-state", s)
|
# request.node.add_report_section("call", "imap-server-state", s)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def remote(sshdomain):
|
||||||
|
return Remote(sshdomain)
|
||||||
|
|
||||||
|
|
||||||
|
class Remote:
|
||||||
|
def __init__(self, sshdomain):
|
||||||
|
self.sshdomain = sshdomain
|
||||||
|
|
||||||
|
def iter_output(self, logcmd=""):
|
||||||
|
getjournal = f"journalctl -f" if not logcmd else logcmd
|
||||||
|
self.popen = subprocess.Popen(
|
||||||
|
["ssh", f"root@{self.sshdomain}", getjournal],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
while 1:
|
||||||
|
line = self.popen.stdout.readline()
|
||||||
|
yield line.decode().strip().lower()
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
addopts = -vrsx
|
addopts = -vrsx --strict-markers
|
||||||
|
markers = slow: mark test as slow (requires --slow option to run)
|
||||||
|
|||||||
15
online-tests/test_0_basic.py
Normal file
15
online-tests/test_0_basic.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
def test_remote(remote, imap_or_smtp):
|
||||||
|
lineproducer = remote.iter_output(imap_or_smtp.logcmd)
|
||||||
|
imap_or_smtp.connect()
|
||||||
|
assert imap_or_smtp.name in next(lineproducer)
|
||||||
|
|
||||||
|
|
||||||
|
def test_use_two_chatmailservers(cmfactory, maildomain2):
|
||||||
|
ac1 = cmfactory.new_online_configuring_account(cache=False)
|
||||||
|
cmfactory.switch_maildomain(maildomain2)
|
||||||
|
ac2 = cmfactory.new_online_configuring_account(cache=False)
|
||||||
|
cmfactory.bring_accounts_online()
|
||||||
|
cmfactory.get_accepted_chat(ac1, ac2)
|
||||||
|
domain1 = ac1.get_config("addr").split("@")[1]
|
||||||
|
domain2 = ac2.get_config("addr").split("@")[1]
|
||||||
|
assert domain1 != domain2
|
||||||
@@ -1,42 +1,36 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import imaplib
|
|
||||||
import smtplib
|
|
||||||
|
|
||||||
|
|
||||||
class TestDovecot:
|
def test_login_basic_functioning(imap_or_smtp, gencreds, lp):
|
||||||
def test_login_ok(self, imap, gencreds):
|
"""Test a) that an initial login creates a user automatically
|
||||||
user, password = gencreds()
|
and b) verify we can also login a second time with the same password
|
||||||
imap.connect()
|
and c) that using a different password fails the login."""
|
||||||
imap.login(user, password)
|
user, password = gencreds()
|
||||||
# verify it works on another connection
|
lp.sec(f"login first time with {user} {password}")
|
||||||
imap.connect()
|
imap_or_smtp.connect()
|
||||||
imap.login(user, password)
|
imap_or_smtp.login(user, password)
|
||||||
|
lp.indent("success")
|
||||||
|
|
||||||
def test_login_fail(self, imap, gencreds):
|
lp.sec(f"reconnect and login second time {user} {password}")
|
||||||
user, password = gencreds()
|
imap_or_smtp.connect()
|
||||||
imap.connect()
|
imap_or_smtp.login(user, password)
|
||||||
imap.login(user, password)
|
imap_or_smtp.connect()
|
||||||
imap.connect()
|
lp.sec("success")
|
||||||
with pytest.raises(imaplib.IMAP4.error) as excinfo:
|
|
||||||
imap.login(user, password + "wrong")
|
lp.sec(f"reconnect and verify wrong password fails {user} ")
|
||||||
assert "AUTHENTICATIONFAILED" in str(excinfo)
|
imap_or_smtp.connect()
|
||||||
|
with pytest.raises(imap_or_smtp.AuthError):
|
||||||
|
imap_or_smtp.login(user, password + "wrong")
|
||||||
|
|
||||||
|
|
||||||
class TestPostfix:
|
def test_login_same_password(imap_or_smtp, gencreds):
|
||||||
def test_login_ok(self, smtp, gencreds):
|
"""Test two different users logging in with the same password
|
||||||
user, password = gencreds()
|
to ensure that authentication process does not confuse the users
|
||||||
smtp.connect()
|
by using only the password hash as a key.
|
||||||
smtp.login(user, password)
|
"""
|
||||||
# verify it works on another connection
|
user1, password1 = gencreds()
|
||||||
smtp.connect()
|
user2, _ = gencreds()
|
||||||
smtp.login(user, password)
|
imap_or_smtp.connect()
|
||||||
|
imap_or_smtp.login(user1, password1)
|
||||||
def test_login_fail(self, smtp, gencreds):
|
imap_or_smtp.connect()
|
||||||
user, password = gencreds()
|
imap_or_smtp.login(user2, password1)
|
||||||
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)
|
|
||||||
|
|||||||
@@ -1,11 +1,83 @@
|
|||||||
class TestMailSending:
|
import random
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class TestEndToEndDeltaChat:
|
||||||
|
"Tests that use Delta Chat accounts on the chat mail instance."
|
||||||
|
|
||||||
def test_one_on_one(self, cmfactory, lp):
|
def test_one_on_one(self, cmfactory, lp):
|
||||||
|
"""Test that a DC account can send a message to a second DC account
|
||||||
|
on the same chat-mail instance."""
|
||||||
ac1, ac2 = cmfactory.get_online_accounts(2)
|
ac1, ac2 = cmfactory.get_online_accounts(2)
|
||||||
chat = cmfactory.get_accepted_chat(ac1, ac2)
|
chat = cmfactory.get_accepted_chat(ac1, ac2)
|
||||||
|
|
||||||
lp.sec("ac1: prepare and send text message to ac2")
|
lp.sec("ac1: prepare and send text message to ac2")
|
||||||
msg1 = chat.send_text("message0")
|
chat.send_text("message0")
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
msg2 = ac2._evtracker.wait_next_incoming_message()
|
msg2 = ac2._evtracker.wait_next_incoming_message()
|
||||||
assert msg2.text == "message0"
|
assert msg2.text == "message0"
|
||||||
|
|
||||||
|
@pytest.mark.slow
|
||||||
|
def test_exceed_quota(self, cmfactory, lp, tmpdir, remote):
|
||||||
|
"""This is a very slow test as it needs to upload >100MB of mail data
|
||||||
|
before quota is exceeded, and thus depends on the speed of the upload.
|
||||||
|
"""
|
||||||
|
ac1, ac2 = cmfactory.get_online_accounts(2)
|
||||||
|
chat = cmfactory.get_accepted_chat(ac1, ac2)
|
||||||
|
|
||||||
|
quota = 1024 * 1024 * 100
|
||||||
|
attachsize = 1 * 1024 * 1024
|
||||||
|
num_to_send = quota // attachsize + 2
|
||||||
|
lp.sec(f"ac1: send {num_to_send} large files to ac2")
|
||||||
|
lp.indent(f"per-user quota is assumed to be: {quota/(1024*1024)}MB")
|
||||||
|
alphanumeric = "abcdefghijklmnopqrstuvwxyz1234567890"
|
||||||
|
msgs = []
|
||||||
|
for i in range(num_to_send):
|
||||||
|
attachment = tmpdir / f"attachment{i}"
|
||||||
|
data = "".join(random.choice(alphanumeric) for i in range(1024))
|
||||||
|
with open(attachment, "w+") as f:
|
||||||
|
for j in range(attachsize // len(data)):
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
|
msg = chat.send_file(str(attachment))
|
||||||
|
msgs.append(msg)
|
||||||
|
lp.indent(f"Sent out msg {i}, size {attachsize/(1024*1024)}MB")
|
||||||
|
|
||||||
|
lp.sec("ac2: check messages are arriving until quota is reached")
|
||||||
|
|
||||||
|
addr = ac2.get_config("addr").lower()
|
||||||
|
saved_ok = 0
|
||||||
|
for line in remote.iter_output("journalctl -f -u dovecot"):
|
||||||
|
if addr not in line:
|
||||||
|
# print(line)
|
||||||
|
continue
|
||||||
|
if "quota" in line:
|
||||||
|
if "quota exceeded" in line:
|
||||||
|
if saved_ok < num_to_send // 2:
|
||||||
|
pytest.fail(
|
||||||
|
f"quota exceeded too early: after {saved_ok} messages already"
|
||||||
|
)
|
||||||
|
lp.indent("good, message sending failed because quota was exceeded")
|
||||||
|
return
|
||||||
|
if "saved mail to inbox" in line:
|
||||||
|
saved_ok += 1
|
||||||
|
print(f"{saved_ok}: {line}")
|
||||||
|
if saved_ok >= num_to_send:
|
||||||
|
break
|
||||||
|
|
||||||
|
pytest.fail("sending succeeded although messages should exceed quota")
|
||||||
|
|
||||||
|
def test_securejoin(self, cmfactory, lp, maildomain2):
|
||||||
|
ac1 = cmfactory.new_online_configuring_account(cache=False)
|
||||||
|
cmfactory.switch_maildomain(maildomain2)
|
||||||
|
ac2 = cmfactory.new_online_configuring_account(cache=False)
|
||||||
|
cmfactory.bring_accounts_online()
|
||||||
|
|
||||||
|
lp.sec("ac1: create QR code and let ac2 scan it, starting the securejoin")
|
||||||
|
qr = ac1.get_setup_contact_qr()
|
||||||
|
|
||||||
|
lp.sec("ac2: start QR-code based setup contact protocol")
|
||||||
|
ch = ac2.qr_setup_contact(qr)
|
||||||
|
assert ch.id >= 10
|
||||||
|
ac1._evtracker.wait_securejoin_inviter_progress(1000)
|
||||||
|
|||||||
15
plan.txt
15
plan.txt
@@ -2,19 +2,10 @@
|
|||||||
|
|
||||||
## Dovecot goals/steps
|
## Dovecot goals/steps
|
||||||
|
|
||||||
2. (holger) per-user storage quota (adaptive)
|
- automatic expiry of messages older than M days
|
||||||
a) define a static 100MB per-user quota
|
- also expunge unread messages
|
||||||
|
|
||||||
3. automatic expiry of messages older than M days
|
- limit: configure max-connections per account
|
||||||
- delete unconditionally messages older than 40 days
|
|
||||||
|
|
||||||
4. limit: max-connections per account
|
|
||||||
|
|
||||||
|
|
||||||
## Filtermail
|
|
||||||
|
|
||||||
- (alex, Only allow (outgoing) mails if secure-join or autocrypt-pgp-encrypted format.
|
|
||||||
TODO: mime-parse mails and check/add tests
|
|
||||||
|
|
||||||
|
|
||||||
## nami: send out rate limit / rspamd
|
## nami: send out rate limit / rspamd
|
||||||
|
|||||||
4
scripts/bench.sh
Executable file
4
scripts/bench.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
online-tests/venv/bin/pytest online-tests/benchmark.py -vrx
|
||||||
@@ -7,7 +7,7 @@ domain = os.environ.get("CHATMAIL_DOMAIN", "c3.testrun.org")
|
|||||||
print("connecting")
|
print("connecting")
|
||||||
conn = imaplib.IMAP4_SSL(domain)
|
conn = imaplib.IMAP4_SSL(domain)
|
||||||
print("logging in")
|
print("logging in")
|
||||||
conn.login(f"measure{time.time()}", "pass")
|
conn.login(f"imapcapa", "pass")
|
||||||
status, res = conn.capability()
|
status, res = conn.capability()
|
||||||
for capa in sorted(res[0].decode().split()):
|
for capa in sorted(res[0].decode().split()):
|
||||||
print(capa)
|
print(capa)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ chatmaild/venv/bin/pip install pytest
|
|||||||
chatmaild/venv/bin/pip install -e chatmaild
|
chatmaild/venv/bin/pip install -e chatmaild
|
||||||
|
|
||||||
python3 -m venv online-tests/venv
|
python3 -m venv online-tests/venv
|
||||||
online-tests/venv/bin/pip install pytest pytest-timeout pdbpp deltachat
|
online-tests/venv/bin/pip install pytest pytest-timeout pdbpp deltachat pytest-benchmark
|
||||||
|
|
||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
venv/bin/pip install build
|
venv/bin/pip install build
|
||||||
|
|||||||
1
scripts/measure_tls_and_logins.py
Normal file → Executable file
1
scripts/measure_tls_and_logins.py
Normal file → Executable file
@@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import imaplib
|
import imaplib
|
||||||
|
|||||||
Reference in New Issue
Block a user