Add tests for alternate mail subjects

This commit is contained in:
Daniel Kahn Gillmor
2024-07-13 11:47:04 -04:00
committed by holger krekel
parent c6b083472f
commit c1fd573de2
3 changed files with 15 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
From: {from_addr} From: {from_addr}
To: {to_addr} To: {to_addr}
Subject: ... Subject: {replaced_subject}
Date: Sun, 15 Oct 2023 16:43:21 +0000 Date: Sun, 15 Oct 2023 16:43:21 +0000
Message-ID: <Mr.UVyJWZmkCKM.hGzNc6glBE_@c2.testrun.org> Message-ID: <Mr.UVyJWZmkCKM.hGzNc6glBE_@c2.testrun.org>
In-Reply-To: <Mr.MvmCz-GQbi_.6FGRkhDf05c@c2.testrun.org> In-Reply-To: <Mr.MvmCz-GQbi_.6FGRkhDf05c@c2.testrun.org>

View File

@@ -71,11 +71,11 @@ def maildata(request):
assert datadir.exists(), datadir assert datadir.exists(), datadir
def maildata(name, from_addr, to_addr): def maildata(name, **kwargs):
# Using `.read_bytes().decode()` instead of `.read_text()` to preserve newlines. # Using `.read_bytes().decode()` instead of `.read_text()` to preserve newlines.
data = datadir.joinpath(name).read_bytes().decode() data = datadir.joinpath(name).read_bytes().decode()
text = data.format(from_addr=from_addr, to_addr=to_addr) text = data.format(**kwargs)
return BytesParser(policy=policy.default).parsebytes(text.encode()) return BytesParser(policy=policy.default).parsebytes(text.encode())
return maildata return maildata

View File

@@ -54,10 +54,16 @@ def test_filtermail_no_encryption_detection(maildata):
def test_filtermail_encryption_detection(maildata): def test_filtermail_encryption_detection(maildata):
msg = maildata("encrypted.eml", from_addr="1@example.org", to_addr="2@example.org") for subject in ("...", "[...]"):
assert check_encrypted(msg) msg = maildata(
"encrypted.eml",
from_addr="1@example.org",
to_addr="2@example.org",
replaced_subject=subject,
)
assert check_encrypted(msg)
# if the subject is not "..." it is not considered ac-encrypted # if the subject is not a known encrypted subject value, it is not considered ac-encrypted
msg.replace_header("Subject", "Click this link") msg.replace_header("Subject", "Click this link")
assert not check_encrypted(msg) assert not check_encrypted(msg)
@@ -72,7 +78,7 @@ def test_filtermail_unencrypted_mdn(maildata, gencreds):
"""Unencrypted MDNs should not pass.""" """Unencrypted MDNs should not pass."""
from_addr = gencreds()[0] from_addr = gencreds()[0]
to_addr = gencreds()[0] + ".other" to_addr = gencreds()[0] + ".other"
msg = maildata("mdn.eml", from_addr, to_addr) msg = maildata("mdn.eml", from_addr=from_addr, to_addr=to_addr)
assert not check_encrypted(msg) assert not check_encrypted(msg)
@@ -95,7 +101,7 @@ def test_excempt_privacy(maildata, gencreds, handler):
handler.config.passthrough_recipients = [to_addr] handler.config.passthrough_recipients = [to_addr]
false_to = "privacy@something.org" false_to = "privacy@something.org"
msg = maildata("plain.eml", from_addr, to_addr) msg = maildata("plain.eml", from_addr=from_addr, to_addr=to_addr)
class env: class env:
mail_from = from_addr mail_from = from_addr
@@ -118,7 +124,7 @@ def test_passthrough_senders(gencreds, handler, maildata):
to_addr = "recipient@something.org" to_addr = "recipient@something.org"
handler.config.passthrough_senders = [acc1] handler.config.passthrough_senders = [acc1]
msg = maildata("plain.eml", acc1, to_addr) msg = maildata("plain.eml", from_addr=acc1, to_addr=to_addr)
class env: class env:
mail_from = acc1 mail_from = acc1