API - allow EMAIL_URL without authentication - fix #127

This commit is contained in:
Sam
2022-01-01 11:04:08 +01:00
parent 9e683653d8
commit 33fde0394a
10 changed files with 62 additions and 8 deletions

View File

@ -63,7 +63,8 @@ class TestEmailSending(CallArgsMixin):
)
smtp = mock_smtp.return_value.__enter__.return_value
assert smtp.starttls.not_called
assert smtp.login.call_count == 1
smtp.starttls.assert_not_called()
self.assert_smtp(smtp)
@patch('smtplib.SMTP_SSL')
@ -79,7 +80,8 @@ class TestEmailSending(CallArgsMixin):
)
smtp = mock_smtp_ssl.return_value.__enter__.return_value
assert smtp.starttls.not_called
assert smtp.login.call_count == 1
smtp.starttls.assert_not_called()
self.assert_smtp(smtp)
@patch('smtplib.SMTP_SSL')
@ -95,5 +97,24 @@ class TestEmailSending(CallArgsMixin):
)
smtp = mock_smtp.return_value.__enter__.return_value
assert smtp.login.call_count == 1
assert smtp.starttls.call_count == 1
self.assert_smtp(smtp)
@patch('smtplib.SMTP_SSL')
@patch('smtplib.SMTP')
def test_it_sends_message_without_authentication(
self, mock_smtp: Mock, mock_smtp_ssl: Mock, app_wo_email_auth: Flask
) -> None:
email_service.send(
template='password_reset_request',
lang='en',
recipient='test@test.com',
data=self.email_data,
)
smtp = mock_smtp.return_value.__enter__.return_value
smtp.login.assert_not_called()
smtp.starttls.assert_not_called()
self.assert_smtp(smtp)

View File

@ -12,6 +12,16 @@ class TestEmailUrlParser:
with pytest.raises(InvalidEmailUrlScheme):
parse_email_url(url)
def test_it_parses_email_url_without_authentication(self) -> None:
url = 'smtp://localhost:25'
parsed_email = parse_email_url(url)
assert parsed_email['username'] is None
assert parsed_email['password'] is None
assert parsed_email['host'] == 'localhost'
assert parsed_email['port'] == 25
assert parsed_email['use_tls'] is False
assert parsed_email['use_ssl'] is False
def test_it_parses_email_url(self) -> None:
url = 'smtp://test@example.com:12345678@localhost:25'
parsed_email = parse_email_url(url)

View File

@ -125,13 +125,23 @@ def app_no_config() -> Generator:
@pytest.fixture
def app_ssl(monkeypatch: pytest.MonkeyPatch) -> Generator:
monkeypatch.setenv('EMAIL_URL', 'smtp://none:none@0.0.0.0:1025?ssl=True')
monkeypatch.setenv(
'EMAIL_URL', 'smtp://username:password@0.0.0.0:1025?ssl=True'
)
yield from get_app(with_config=True)
@pytest.fixture
def app_tls(monkeypatch: pytest.MonkeyPatch) -> Generator:
monkeypatch.setenv('EMAIL_URL', 'smtp://none:none@0.0.0.0:1025?tls=True')
monkeypatch.setenv(
'EMAIL_URL', 'smtp://username:password@0.0.0.0:1025?tls=True'
)
yield from get_app(with_config=True)
@pytest.fixture
def app_wo_email_auth(monkeypatch: pytest.MonkeyPatch) -> Generator:
monkeypatch.setenv('EMAIL_URL', 'smtp://0.0.0.0:1025')
yield from get_app(with_config=True)