This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from backend.app.services.email_service import send_test_email, send_verification_email
|
||||
from backend.app.services.email_service import send_password_reset_email, send_test_email, send_verification_email
|
||||
|
||||
|
||||
def test_send_verification_email_uses_smtp_settings(monkeypatch):
|
||||
@@ -15,6 +15,7 @@ def test_send_verification_email_uses_smtp_settings(monkeypatch):
|
||||
monkeypatch.setattr(settings, 'smtp_username', 'mailer')
|
||||
monkeypatch.setattr(settings, 'smtp_password', 'secret')
|
||||
monkeypatch.setattr(settings, 'smtp_use_tls', True)
|
||||
monkeypatch.setattr(settings, 'public_url', 'https://linklog.example')
|
||||
|
||||
with patch('backend.app.services.email_service.SMTP') as smtp_class:
|
||||
smtp = smtp_class.return_value.__enter__.return_value
|
||||
@@ -25,7 +26,22 @@ def test_send_verification_email_uses_smtp_settings(monkeypatch):
|
||||
smtp.login.assert_called_once_with('mailer', 'secret')
|
||||
message = smtp.send_message.call_args.args[0]
|
||||
assert message['To'] == 'user@example.com'
|
||||
assert 'https://linklog.example/verify' in message.get_content()
|
||||
assert 'https://linklog.example/verify' in message.get_body(preferencelist=('plain',)).get_content()
|
||||
html = message.get_body(preferencelist=('html',)).get_content()
|
||||
assert 'cid:linklog-logo' in html
|
||||
assert 'width="50" height="50"' in html
|
||||
assert 'font-family:\'Asset\',Georgia,serif' in html
|
||||
assert 'Hello, a message from' in html
|
||||
assert 'vertical-align:top' in html
|
||||
assert 'padding:20px 0 20px 12px' in html
|
||||
assert 'font-size:18px' in html
|
||||
assert 'href="https://linklog.example"' in html
|
||||
assert '>linklog.example</a>' in html
|
||||
assert any(
|
||||
part.get_content_type() == 'image/svg+xml'
|
||||
and part['Content-ID'] == '<linklog-logo>'
|
||||
for part in message.walk()
|
||||
)
|
||||
|
||||
|
||||
def test_send_test_email_uses_configured_recipient(monkeypatch):
|
||||
@@ -40,6 +56,23 @@ def test_send_test_email_uses_configured_recipient(monkeypatch):
|
||||
message = smtp.send_message.call_args.args[0]
|
||||
assert message['To'] == 'admin@example.com'
|
||||
assert message['Subject'] == 'LinkLog SMTP test'
|
||||
assert message.get_body(preferencelist=('html',)) is not None
|
||||
|
||||
|
||||
def test_password_reset_email_escapes_html_and_includes_logo(monkeypatch):
|
||||
from backend.app.core.config import settings
|
||||
|
||||
monkeypatch.setattr(settings, 'smtp_host', 'smtp.example.com')
|
||||
monkeypatch.setattr(settings, 'smtp_from', 'LinkLog <no-reply@example.com>')
|
||||
with patch('backend.app.services.email_service.SMTP') as smtp_class:
|
||||
smtp = smtp_class.return_value.__enter__.return_value
|
||||
send_password_reset_email('user@example.com', '<User>', 'https://linklog.example/reset?x=1&y=2')
|
||||
|
||||
message = smtp.send_message.call_args.args[0]
|
||||
html = message.get_body(preferencelist=('html',)).get_content()
|
||||
assert '<User>' in html
|
||||
assert 'x=1&y=2' in html
|
||||
assert 'cid:linklog-logo' in html
|
||||
|
||||
|
||||
def test_smtp_password_is_encrypted_at_rest():
|
||||
|
||||
Reference in New Issue
Block a user