mirror of
https://github.com/chatmail/relay.git
synced 2026-05-14 01:44:38 +00:00
get passthrough_recipients list from config
This commit is contained in:
@@ -13,6 +13,7 @@ def test_read_config_without_mailname(tmp_path, create_ini, monkeypatch):
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 9875
|
||||
postfix_reinject_port = 9999
|
||||
passthrough_recipients =
|
||||
"""
|
||||
)
|
||||
config = read_config(inipath)
|
||||
@@ -26,6 +27,7 @@ def test_read_config_without_privacy_policy(tmp_path, create_ini):
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 9875
|
||||
postfix_reinject_port = 9999
|
||||
passthrough_recipients =
|
||||
|
||||
[privacy:testrun]
|
||||
domain = *.example.org
|
||||
@@ -36,6 +38,7 @@ def test_read_config_without_privacy_policy(tmp_path, create_ini):
|
||||
assert config.max_user_send_per_minute == 40
|
||||
assert config.filtermail_smtp_port == 9875
|
||||
assert config.postfix_reinject_port == 9999
|
||||
assert config.passthrough_recipients == []
|
||||
assert not config.privacy_postal
|
||||
assert not config.privacy_mail
|
||||
assert not config.privacy_pdo
|
||||
@@ -49,6 +52,7 @@ def test_read_config(create_ini):
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 10080
|
||||
postfix_reinject_port = 10025
|
||||
passthrough_recipients = x@example.org y@example.org
|
||||
|
||||
[privacy:testrun]
|
||||
domain = *.testrun.org
|
||||
@@ -73,6 +77,7 @@ def test_read_config(create_ini):
|
||||
assert config.mailname == "something.testrun.org"
|
||||
assert config.filtermail_smtp_port == 10080
|
||||
assert config.postfix_reinject_port == 10025
|
||||
assert config.passthrough_recipients == ["x@example.org", "y@example.org"]
|
||||
assert config.privacy_postal == "Postal Ltd"
|
||||
assert config.privacy_mail == "privacy@merlinux.eu"
|
||||
lines = config.privacy_pdo.split("\n")
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from chatmaild.filtermail import (
|
||||
check_encrypted,
|
||||
check_DATA,
|
||||
BeforeQueueHandler,
|
||||
SendRateLimiter,
|
||||
check_mdn,
|
||||
is_passthrough_recipient,
|
||||
)
|
||||
|
||||
from chatmaild.config import read_config
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -14,18 +16,25 @@ def maildomain():
|
||||
return "chatmail.example.org"
|
||||
|
||||
|
||||
def test_reject_forged_from(maildata, gencreds):
|
||||
@pytest.fixture
|
||||
def handler(create_ini, maildomain):
|
||||
config = read_config(create_ini(), maildomain)
|
||||
return BeforeQueueHandler(config)
|
||||
|
||||
|
||||
def test_reject_forged_from(maildata, gencreds, handler):
|
||||
class env:
|
||||
mail_from = gencreds()[0]
|
||||
rcpt_tos = [gencreds()[0]]
|
||||
|
||||
# test that the filter lets good mail through
|
||||
env.content = maildata("plain.eml", from_addr=env.mail_from).as_bytes()
|
||||
assert not check_DATA(envelope=env)
|
||||
|
||||
assert not handler.check_DATA(envelope=env)
|
||||
|
||||
# test that the filter rejects forged mail
|
||||
env.content = maildata("plain.eml", from_addr="forged@c3.testrun.org").as_bytes()
|
||||
error = check_DATA(envelope=env)
|
||||
error = handler.check_DATA(envelope=env)
|
||||
assert "500" in error
|
||||
|
||||
|
||||
@@ -47,7 +56,7 @@ def test_filtermail_encryption_detection(maildata):
|
||||
assert not check_encrypted(msg)
|
||||
|
||||
|
||||
def test_filtermail_is_mdn(maildata, gencreds):
|
||||
def test_filtermail_is_mdn(maildata, gencreds, handler):
|
||||
from_addr = gencreds()[0]
|
||||
to_addr = gencreds()[0] + ".other"
|
||||
msg = maildata("mdn.eml", from_addr, to_addr)
|
||||
@@ -59,7 +68,8 @@ def test_filtermail_is_mdn(maildata, gencreds):
|
||||
|
||||
assert check_mdn(msg, env)
|
||||
print(msg.as_string())
|
||||
assert not check_DATA(env)
|
||||
|
||||
assert not handler.check_DATA(env)
|
||||
|
||||
|
||||
def test_filtermail_to_multiple_recipients_no_mdn(maildata, gencreds):
|
||||
@@ -88,12 +98,12 @@ def test_send_rate_limiter():
|
||||
break
|
||||
|
||||
|
||||
def test_excempt_privacy(maildata, gencreds):
|
||||
def test_excempt_privacy(maildata, gencreds, handler):
|
||||
from_addr = gencreds()[0]
|
||||
to_addr = "privacy@testrun.org"
|
||||
false_to = "privacy@tstrn.org"
|
||||
false_to2 = "prvcy@testrun.org"
|
||||
assert is_passthrough_recipient(to_addr)
|
||||
assert to_addr in handler.config.passthrough_recipients
|
||||
|
||||
msg = maildata("plain.eml", from_addr, to_addr)
|
||||
|
||||
@@ -103,11 +113,11 @@ def test_excempt_privacy(maildata, gencreds):
|
||||
content = msg.as_bytes()
|
||||
|
||||
# assert that None/no error is returned
|
||||
assert not check_DATA(envelope=env)
|
||||
assert not handler.check_DATA(envelope=env)
|
||||
|
||||
class env2:
|
||||
mail_from = from_addr
|
||||
rcpt_tos = [to_addr, false_to, false_to2]
|
||||
content = msg.as_bytes()
|
||||
|
||||
assert "500" in check_DATA(envelope=env2)
|
||||
assert "500" in handler.check_DATA(envelope=env2)
|
||||
|
||||
@@ -6,6 +6,7 @@ import subprocess
|
||||
import textwrap
|
||||
import imaplib
|
||||
import smtplib
|
||||
import importlib.resources
|
||||
import itertools
|
||||
from email.parser import BytesParser
|
||||
from email import policy
|
||||
@@ -38,6 +39,14 @@ def pytest_runtest_setup(item):
|
||||
pytest.skip("skipping slow test, use --slow to run")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inipath():
|
||||
dpath = importlib.resources.files("chatmaild")
|
||||
inipath = dpath.joinpath("../../../chatmail.ini").resolve()
|
||||
assert inipath.exists()
|
||||
return inipath
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def maildomain():
|
||||
domain = os.environ.get("CHATMAIL_DOMAIN")
|
||||
@@ -406,8 +415,10 @@ class CMUser:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def create_ini(tmp_path):
|
||||
def create_ini_func(source):
|
||||
def create_ini(tmp_path, inipath):
|
||||
def create_ini_func(source=None):
|
||||
if source is None:
|
||||
source = inipath.read_text()
|
||||
p = tmp_path.joinpath("chatmail.ini")
|
||||
assert not p.exists(), p
|
||||
p.write_text(textwrap.dedent(source))
|
||||
|
||||
@@ -5,14 +5,15 @@ from deploy_chatmail.www import build_webpages
|
||||
from chatmaild.config import read_config
|
||||
|
||||
|
||||
def create_ini(inipath, domain="example.org"):
|
||||
inipath.write_text(
|
||||
def make_config(create_ini, domain="example.org"):
|
||||
inipath = create_ini(
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
[params]
|
||||
max_user_send_per_minute = 60
|
||||
filtermail_smtp_port = 10080
|
||||
postfix_reinject_port = 10025
|
||||
passthrough_recipients =
|
||||
|
||||
[privacy:{domain}]
|
||||
domain = example.org
|
||||
@@ -27,25 +28,20 @@ def create_ini(inipath, domain="example.org"):
|
||||
"""
|
||||
)
|
||||
)
|
||||
return read_config(inipath, domain)
|
||||
|
||||
|
||||
def test_build_webpages(tmp_path):
|
||||
def test_build_webpages(tmp_path, create_ini):
|
||||
pkgroot = importlib.resources.files("deploy_chatmail")
|
||||
src_dir = pkgroot.joinpath("../../../www/src").resolve()
|
||||
assert src_dir.exists(), src_dir
|
||||
|
||||
inipath = tmp_path.joinpath("chatmail.ini")
|
||||
create_ini(inipath, "example.org")
|
||||
config = read_config(inipath, "example.org")
|
||||
config = make_config(create_ini, "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, "example.org")
|
||||
|
||||
config = read_config(inipath, "example.org")
|
||||
def test_get_settings(tmp_path, create_ini):
|
||||
config = make_config(create_ini, "example.org")
|
||||
assert config.privacy_postal == "address-line1\naddress-line2"
|
||||
assert config.privacy_mail == "privacy@example.org"
|
||||
assert config.privacy_pdo == "address-line3"
|
||||
|
||||
Reference in New Issue
Block a user