diff --git a/chatmaild/src/chatmaild/tests/mail-data/plain.eml b/chatmaild/src/chatmaild/tests/mail-data/plain.eml index 69867b80..80a25422 100644 --- a/chatmaild/src/chatmaild/tests/mail-data/plain.eml +++ b/chatmaild/src/chatmaild/tests/mail-data/plain.eml @@ -7,7 +7,7 @@ Date: Sun, 15 Oct 2023 16:41:44 +0000 Message-ID: References: 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! - + diff --git a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py index 8dafc701..1edd9dff 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py @@ -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."""