mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
tests: add test for rejecting SPF & DMARC fails
This commit is contained in:
@@ -7,7 +7,7 @@ Date: Sun, 15 Oct 2023 16:41:44 +0000
|
||||
Message-ID: <Mr.3gckbNy5bch.uK3Hd2Ws6-w@c2.testrun.org>
|
||||
References: <Mr.3gckbNy5bch.uK3Hd2Ws6-w@c2.testrun.org>
|
||||
Chat-Version: 1.0
|
||||
Autocrypt: addr=foobar@c2.testrun.org; prefer-encrypt=mutual;
|
||||
Autocrypt: addr={from_addr}; prefer-encrypt=mutual;
|
||||
keydata=xjMEZSrw3hYJKwYBBAHaRw8BAQdAiEKNQFU28c6qsx4vo/JHdt73RXdjMOmByf/XsGiJ7m
|
||||
nNFzxmb29iYXJAYzIudGVzdHJ1bi5vcmc+wosEEBYIADMCGQEFAmUq8N4CGwMECwkIBwYVCAkKCwID
|
||||
FgIBFiEEGil0OvTIa6RngmCLUYNnEa9leJAACgkQUYNnEa9leJCX3gEAhm0MehE5byBBU1avPczr/I
|
||||
@@ -20,4 +20,4 @@ Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
|
||||
|
||||
Hi!
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,20 @@ def test_reject_forged_from(cmsetup, maildata, gencreds, lp, forgeaddr):
|
||||
assert "500" in str(e.value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("from_addr", ["fake@example.org", "fake@testrun.org"])
|
||||
def test_reject_wrong_dmarc_spf(cmsetup, maildata, from_addr):
|
||||
"""Test that emails with missing or wrong DKIM and SPF entries are rejected."""
|
||||
# create recipient
|
||||
recipient = "charlie@c1.testrun.org" # cmsetup.gen_users(1)[0]
|
||||
# craft email object with fake sender
|
||||
msg = maildata("plain.eml", from_addr=from_addr, to_addr=recipient).as_string()
|
||||
# initiate SMTP connection
|
||||
with smtplib.SMTP(cmsetup.maildomain, 25) as s:
|
||||
with pytest.raises(smtplib.SMTPException):
|
||||
s.sendmail(from_addr=from_addr, to_addrs=recipient, msg=msg)
|
||||
# assert response code == 500 or something
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_exceed_rate_limit(cmsetup, gencreds, maildata, chatmail_config):
|
||||
"""Test that the per-account send-mail limit is exceeded."""
|
||||
|
||||
Reference in New Issue
Block a user