Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTPD_USE_SSL only honored when set in a separate fixture #50

Closed
jwodder opened this issue Feb 26, 2021 · 1 comment · Fixed by #58
Closed

SMTPD_USE_SSL only honored when set in a separate fixture #50

jwodder opened this issue Feb 26, 2021 · 1 comment · Fixed by #58

Comments

@jwodder
Copy link
Contributor

jwodder commented Feb 26, 2021

On Python 3.9.2 on macOS 11.2.1, using pytest 6.2.2 and smtpdfix 0.2.9, the following fails on the client = smtplib.SMTP_SSL(...) line with an SSL error:

from email.message import EmailMessage
import smtplib

def test_smtpd_ssl(monkeypatch, smtpd):
    monkeypatch.setenv("SMTPD_USE_SSL", "True")
    client = smtplib.SMTP_SSL(smtpd.hostname, smtpd.port)
    msg = EmailMessage()
    msg["Subject"] = "Hello, World!"
    msg["To"] = "world@earth.space"
    msg["From"] = "me@here.qq"
    msg.set_content("Hi, world!  How you doin'?\n")
    client.send_message(msg)
    client.quit()
    assert len(smtpd.messages) == 1

Meanwhile, setting SMTPD_USE_SSL outside of the test in a fixture succeeds:

from email.message import EmailMessage
import smtplib
import pytest

@pytest.fixture
def mock_smtpd_use_ssl(monkeypatch):
    monkeypatch.setenv("SMTPD_USE_SSL", "True")

def test_smtpd_ssl(mock_smtpd_use_ssl, smtpd):
    client = smtplib.SMTP_SSL(smtpd.hostname, smtpd.port)
    msg = EmailMessage()
    msg["Subject"] = "Hello, World!"
    msg["To"] = "world@earth.space"
    msg["From"] = "me@here.qq"
    msg.set_content("Hi, world!  How you doin'?\n")
    client.send_message(msg)
    client.quit()
    assert len(smtpd.messages) == 1

This is presumably not the intended way to set SMTPD_USE_SSL, and so I am reporting it as a bug.

bebleo added a commit that referenced this issue Mar 5, 2021
Until a fix is implemented for issue #50 add it to the known issues
list.
bebleo added a commit that referenced this issue Mar 5, 2021
Until a fix is implemented for issue #50 add it to the known issues
list.
@bebleo bebleo linked a pull request Mar 11, 2021 that will close this issue
@bebleo
Copy link
Owner

bebleo commented Mar 14, 2021

Thanks @jwodder for taking the time to report this issue! 🎉

As of version 0.3.0 this behaviour can now be handled by setting the smtpd.config.use_ssl property to True.

def test_smtpd_ssl(smtpd):
    smtpd.confg.use_ssl = True  # Not using monkeypatch!
    client = smtplib.SMTP_SSL(smtpd.hostname, smtpd.port)
    msg = EmailMessage()
    msg["Subject"] = "Hello, World!"
    msg["To"] = "world@earth.space"
    msg["From"] = "me@here.qq"
    msg.set_content("Hi, world!  How you doin'?\n")
    client.send_message(msg)
    client.quit()
    assert len(smtpd.messages) == 1

@bebleo bebleo closed this as completed Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants