mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 04:18:09 +00:00
various fixes
This commit is contained in:
@@ -1,21 +1,55 @@
|
||||
from chatmaild.config import read_config
|
||||
import chatmaild.config
|
||||
|
||||
|
||||
def test_read_config_no_privacy_policy(tmp_path, create_ini):
|
||||
def test_read_config_without_mailname(tmp_path, create_ini, monkeypatch):
|
||||
mailname_path = tmp_path.joinpath("mailname")
|
||||
mailname_path.write_text("something.example.org")
|
||||
monkeypatch.setattr(chatmaild.config, "system_mailname_path", mailname_path)
|
||||
|
||||
inipath = create_ini(
|
||||
"""
|
||||
[params]
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 9875
|
||||
postfix_reinject_port = 9999
|
||||
"""
|
||||
)
|
||||
config = read_config(inipath)
|
||||
assert config.mailname == "something.example.org"
|
||||
|
||||
|
||||
def test_read_config_without_privacy_policy(tmp_path, create_ini):
|
||||
inipath = create_ini(
|
||||
"""
|
||||
[params]
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 9875
|
||||
postfix_reinject_port = 9999
|
||||
|
||||
[privacy:testrun]
|
||||
domain = *.example.org
|
||||
"""
|
||||
)
|
||||
config = read_config(inipath, "something.example.org")
|
||||
assert config.mailname == "something.example.org"
|
||||
assert not config.has_privacy_policy
|
||||
assert config.max_user_send_per_minute == 40
|
||||
assert config.filtermail_smtp_port == 9875
|
||||
assert config.postfix_reinject_port == 9999
|
||||
assert not config.privacy_postal
|
||||
assert not config.privacy_mail
|
||||
assert not config.privacy_pdo
|
||||
assert not config.privacy_supervisor
|
||||
|
||||
|
||||
def test_read_config(create_ini):
|
||||
inipath = create_ini(
|
||||
"""
|
||||
[params]
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 10080
|
||||
postfix_reinject_port = 10025
|
||||
|
||||
[privacy:testrun]
|
||||
domain = *.testrun.org
|
||||
|
||||
@@ -35,9 +69,10 @@ def test_read_config(create_ini):
|
||||
)
|
||||
|
||||
config = read_config(inipath, "something.testrun.org")
|
||||
assert config.has_privacy_policy
|
||||
|
||||
assert config.mailname == "something.testrun.org"
|
||||
assert config.filtermail_smtp_port == 10080
|
||||
assert config.postfix_reinject_port == 10025
|
||||
assert config.privacy_postal == "Postal Ltd"
|
||||
assert config.privacy_mail == "privacy@merlinux.eu"
|
||||
lines = config.privacy_pdo.split("\n")
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import sys
|
||||
import pytest
|
||||
import threading
|
||||
import queue
|
||||
@@ -7,7 +6,7 @@ import traceback
|
||||
|
||||
import chatmaild.doveauth
|
||||
from chatmaild.doveauth import get_user_data, lookup_passdb, handle_dovecot_request
|
||||
from chatmaild.database import Database, DBError
|
||||
from chatmaild.database import DBError
|
||||
|
||||
|
||||
def test_basic(db):
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
from chatmaild.filtermail import check_encrypted, check_DATA, SendRateLimiter, check_mdn, is_passthrough_recipient
|
||||
from chatmaild.filtermail import (
|
||||
check_encrypted,
|
||||
check_DATA,
|
||||
SendRateLimiter,
|
||||
check_mdn,
|
||||
is_passthrough_recipient,
|
||||
)
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -73,12 +79,12 @@ def test_filtermail_to_multiple_recipients_no_mdn(maildata, gencreds):
|
||||
def test_send_rate_limiter():
|
||||
limiter = SendRateLimiter()
|
||||
for i in range(100):
|
||||
if limiter.is_sending_allowed("some@example.org"):
|
||||
if i <= SendRateLimiter.MAX_USER_SEND_PER_MINUTE:
|
||||
if limiter.is_sending_allowed("some@example.org", 10):
|
||||
if i <= 10:
|
||||
continue
|
||||
pytest.fail("limiter didn't work")
|
||||
else:
|
||||
assert i == SendRateLimiter.MAX_USER_SEND_PER_MINUTE + 1
|
||||
assert i == 11
|
||||
break
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ def test_exceed_rate_limit(cmsetup, gencreds, maildata):
|
||||
try:
|
||||
user1.smtp.sendmail(user1.addr, [user2.addr], mail)
|
||||
except smtplib.SMTPException as e:
|
||||
if i < 80:
|
||||
if i < 60:
|
||||
pytest.fail(f"rate limit was exceeded too early with msg {i}")
|
||||
outcome = e.recipients[user2.addr]
|
||||
assert outcome[0] == 450
|
||||
|
||||
@@ -2,20 +2,25 @@ import textwrap
|
||||
import importlib.resources
|
||||
|
||||
from deploy_chatmail.www import build_webpages
|
||||
from deploy_chatmail import get_ini_settings
|
||||
from chatmaild.config import read_config
|
||||
|
||||
|
||||
def create_ini(inipath):
|
||||
def create_ini(inipath, domain="example.org"):
|
||||
inipath.write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
[config]
|
||||
f"""\
|
||||
[params]
|
||||
max_user_send_per_minute = 60
|
||||
filtermail_smtp_port = 10080
|
||||
postfix_reinject_port = 10025
|
||||
|
||||
[privacy:{domain}]
|
||||
domain = example.org
|
||||
privacy_postal =
|
||||
address-line1
|
||||
address-line2
|
||||
|
||||
privacy_mail = privacy@example.org
|
||||
privacy_mail = privacy@{domain}
|
||||
|
||||
privacy_pdo =
|
||||
address-line3
|
||||
@@ -30,18 +35,18 @@ def test_build_webpages(tmp_path):
|
||||
assert src_dir.exists(), src_dir
|
||||
|
||||
inipath = tmp_path.joinpath("chatmail.ini")
|
||||
create_ini(inipath)
|
||||
config = get_ini_settings("example.org", inipath)
|
||||
create_ini(inipath, "example.org")
|
||||
config = read_config(inipath, "example.org")
|
||||
build_dir = tmp_path.joinpath("build")
|
||||
build_webpages(src_dir, build_dir, config)
|
||||
|
||||
|
||||
def test_get_settings(tmp_path):
|
||||
inipath = tmp_path.joinpath("chatmail.ini")
|
||||
create_ini(inipath)
|
||||
create_ini(inipath, "example.org")
|
||||
|
||||
d = get_ini_settings("x.testrun.org", inipath)
|
||||
assert d["privacy_postal"] == "address-line1\naddress-line2"
|
||||
assert d["privacy_mail"] == "privacy@example.org"
|
||||
assert d["privacy_pdo"] == "address-line3"
|
||||
assert d["mail_domain"] == "x.testrun.org"
|
||||
config = read_config(inipath, "example.org")
|
||||
assert config.privacy_postal == "address-line1\naddress-line2"
|
||||
assert config.privacy_mail == "privacy@example.org"
|
||||
assert config.privacy_pdo == "address-line3"
|
||||
assert config.mailname == "example.org"
|
||||
|
||||
Reference in New Issue
Block a user