tests: use generic recipient for DKIM testing

This commit is contained in:
missytake 2023-12-26 13:18:48 +01:00 committed by link2xt
parent 265403e110
commit 536c12d989

View File

@ -43,16 +43,13 @@ def test_reject_forged_from(cmsetup, maildata, gencreds, lp, forgeaddr):
@pytest.mark.parametrize("from_addr", ["fake@example.org", "fake@testrun.org"]) @pytest.mark.parametrize("from_addr", ["fake@example.org", "fake@testrun.org"])
def test_reject_wrong_dmarc_spf(cmsetup, maildata, from_addr): def test_reject_missing_dkim(cmsetup, maildata, from_addr):
"""Test that emails with missing or wrong DKIM and SPF entries are rejected.""" """Test that emails with missing or wrong DKIM entries are rejected."""
# create recipient recipient = cmsetup.gen_users(1)[0]
recipient = "charlie@c1.testrun.org" # cmsetup.gen_users(1)[0] msg = maildata("plain.eml", from_addr=from_addr, to_addr=recipient.addr).as_string()
# 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 smtplib.SMTP(cmsetup.maildomain, 25) as s:
with pytest.raises(smtplib.SMTPException): with pytest.raises(smtplib.SMTPDataError):
s.sendmail(from_addr=from_addr, to_addrs=recipient, msg=msg) s.sendmail(from_addr=from_addr, to_addrs=recipient.addr, msg=msg)
# assert response code == 500 or something # assert response code == 500 or something