rename fixture to maildata and rename doveauth

This commit is contained in:
holger krekel
2023-10-21 00:48:37 +02:00
parent 7dd2d0b9b4
commit 0950d7ea8f
4 changed files with 19 additions and 19 deletions

View File

@@ -2,34 +2,32 @@ from chatmaild.filtermail import check_encrypted, check_DATA, SendRateLimiter
import pytest
def test_reject_forged_from(get_mail_data, gencreds):
def test_reject_forged_from(maildata, gencreds):
class env:
mail_from = gencreds()[0]
rcpt_tos = [gencreds()[0]]
# test that the filter lets good mail through
env.content = get_mail_data("plain.eml", from_addr=env.mail_from).as_bytes()
env.content = maildata("plain.eml", from_addr=env.mail_from).as_bytes()
assert not check_DATA(envelope=env)
# test that the filter rejects forged mail
env.content = get_mail_data(
"plain.eml", from_addr="forged@c3.testrun.org"
).as_bytes()
env.content = maildata("plain.eml", from_addr="forged@c3.testrun.org").as_bytes()
error = check_DATA(envelope=env)
assert "500" in error
def test_filtermail_no_encryption_detection(get_mail_data):
msg = get_mail_data("plain.eml")
def test_filtermail_no_encryption_detection(maildata):
msg = maildata("plain.eml")
assert not check_encrypted(msg)
# https://xkcd.com/1181/
msg = get_mail_data("fake-encrypted.eml")
msg = maildata("fake-encrypted.eml")
assert not check_encrypted(msg)
def test_filtermail_encryption_detection(get_mail_data):
msg = get_mail_data("encrypted.eml")
def test_filtermail_encryption_detection(maildata):
msg = maildata("encrypted.eml")
assert check_encrypted(msg)
# if the subject is not "..." it is not considered ac-encrypted
@@ -37,8 +35,8 @@ def test_filtermail_encryption_detection(get_mail_data):
assert not check_encrypted(msg)
def test_filtermail_mdn_is_not_encrypted(get_mail_data):
assert not check_encrypted(get_mail_data("mdn.eml"))
def test_filtermail_mdn_is_not_encrypted(maildata):
assert not check_encrypted(maildata("mdn.eml"))
def test_send_rate_limiter():

View File

@@ -287,10 +287,10 @@ class Remote:
@pytest.fixture
def get_mail_data(request, gencreds):
def maildata(request, gencreds):
datadir = conftestdir.joinpath("mail-data")
def get_mail_data(name, parsed=True, from_addr=None, to_addr=None):
def maildata(name, parsed=True, from_addr=None, to_addr=None):
if from_addr is None:
from_addr = gencreds()[0]
if to_addr is None:
@@ -299,7 +299,7 @@ def get_mail_data(request, gencreds):
text = data.format(from_addr=from_addr, to_addr=to_addr)
return BytesParser(policy=policy.default).parsebytes(text.encode())
return get_mail_data
return maildata
@pytest.fixture

View File

@@ -20,7 +20,7 @@ def test_use_two_chatmailservers(cmfactory, maildomain2):
@pytest.mark.parametrize("forgeaddr", ["internal", "someone@example.org"])
def test_reject_forged_from(cmsetup, get_mail_data, lp, forgeaddr):
def test_reject_forged_from(cmsetup, maildata, lp, forgeaddr):
user1, user3 = cmsetup.gen_users(2)
lp.sec("send encrypted message with forged from")
@@ -31,7 +31,7 @@ def test_reject_forged_from(cmsetup, get_mail_data, lp, forgeaddr):
addr_to_forge = "someone@example.org"
print("message to inject:")
msg = get_mail_data("encrypted.eml", from_addr=addr_to_forge, to_addr=user3.addr)
msg = maildata("encrypted.eml", from_addr=addr_to_forge, to_addr=user3.addr)
msg = msg.as_string()
for line in msg.split("\n")[:4]:
print(f" {line}")
@@ -43,10 +43,12 @@ def test_reject_forged_from(cmsetup, get_mail_data, lp, forgeaddr):
@pytest.mark.slow
def test_exceed_rate_limit(cmsetup, gencreds, get_mail_data):
def test_exceed_rate_limit(cmsetup, gencreds, maildata):
"""Test that the per-account send-mail limit is exceeded."""
user1, user2 = cmsetup.gen_users(2)
mail = get_mail_data("encrypted", from_addr=user1.addr, to_addr=user2.addr)
mail = maildata(
"encrypted.eml", from_addr=user1.addr, to_addr=user2.addr
).as_string()
for i in range(100):
print("Sending mail", str(i))
try: