-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from piotrsz/develop
PLAIN security mode
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,48 @@ def test_security_starttls(mocker, tmp_path): | |
assert smtp.sendmail.call_count == 1 | ||
|
||
|
||
def test_security_plain(mocker, tmp_path): | ||
"""Verify plain security configuration.""" | ||
# Config for Plain SMTP server | ||
config_path = tmp_path/"server.conf" | ||
config_path.write_text(textwrap.dedent("""\ | ||
[smtp_server] | ||
host = newman.eecs.umich.edu | ||
port = 25 | ||
security = PLAIN | ||
username = YOUR_USERNAME_HERE | ||
""")) | ||
|
||
# Simple template | ||
sendmail_client = SendmailClient(config_path, dry_run=False) | ||
message = email.message_from_string("Hello world") | ||
|
||
# Mock SMTP | ||
mock_smtp = mocker.patch('smtplib.SMTP') | ||
mock_smtp_ssl = mocker.patch('smtplib.SMTP_SSL') | ||
|
||
# Mock the password entry | ||
mock_getpass = mocker.patch('getpass.getpass') | ||
mock_getpass.return_value = "password" | ||
|
||
# Send a message | ||
sendmail_client.sendmail( | ||
sender="[email protected]", | ||
recipients=["[email protected]"], | ||
message=message, | ||
) | ||
|
||
# Verify SMTP library calls | ||
assert mock_getpass.call_count == 1 | ||
assert mock_smtp.call_count == 1 | ||
assert mock_smtp_ssl.call_count == 0 | ||
smtp = mock_smtp.return_value.__enter__.return_value | ||
assert smtp.ehlo.call_count == 0 | ||
assert smtp.starttls.call_count == 0 | ||
assert smtp.login.call_count == 1 | ||
assert smtp.sendmail.call_count == 1 | ||
|
||
|
||
def test_security_ssl(mocker, tmp_path): | ||
"""Verify open (Never) security configuration.""" | ||
# Config for SSL SMTP server | ||
|