fix(proxy): case-insensitive SMTP_USE_SSL check + lowercase test

This commit is contained in:
Ishaan Jaffer 2026-04-29 12:31:23 -07:00
parent e74bcc11ce
commit 1d167974ff
No known key found for this signature in database
2 changed files with 26 additions and 1 deletions

View file

@ -4717,7 +4717,7 @@ async def send_email(
# Attach the body to the email
email_message.attach(MIMEText(html, "html"))
smtp_use_ssl = os.getenv("SMTP_USE_SSL", "False") == "True"
smtp_use_ssl = os.getenv("SMTP_USE_SSL", "False").lower() == "true"
use_ssl = smtp_use_ssl or smtp_port == 465
try:

View file

@ -80,6 +80,31 @@ async def test_send_email_smtp_use_ssl_env_forces_ssl(monkeypatch):
mock_server.starttls.assert_not_called()
@pytest.mark.asyncio
async def test_send_email_smtp_use_ssl_env_lowercase(monkeypatch):
"""SMTP_USE_SSL=true (lowercase) must also trigger SMTP_SSL."""
monkeypatch.setenv("SMTP_HOST", "smtp.example.com")
monkeypatch.setenv("SMTP_PORT", "2525")
monkeypatch.setenv("SMTP_USE_SSL", "true")
monkeypatch.setenv("SMTP_SENDER_EMAIL", "noreply@example.com")
mock_server = MagicMock()
mock_server.__enter__ = lambda s: s
mock_server.__exit__ = MagicMock(return_value=False)
with (
patch("smtplib.SMTP_SSL", return_value=mock_server) as mock_ssl,
patch("smtplib.SMTP") as mock_plain,
):
await send_email(
receiver_email="user@example.com",
subject="Test",
html="<p>Hi</p>",
)
mock_ssl.assert_called_once_with(host="smtp.example.com", port=2525)
mock_plain.assert_not_called()
@pytest.mark.asyncio
async def test_send_email_port_587_uses_starttls(monkeypatch):
"""Port 587 (default) must use SMTP + starttls — backwards compat regression guard."""