diff --git a/bandit/backends/base.py b/bandit/backends/base.py index 9774fe6..48f455f 100644 --- a/bandit/backends/base.py +++ b/bandit/backends/base.py @@ -2,6 +2,7 @@ import logging +from email.utils import parseaddr from functools import reduce from operator import and_ @@ -31,7 +32,8 @@ def send_messages(self, email_messages): [email for name, email in admins]) def is_approved(email): - local_part, _, domain = email.rpartition('@') + _, email = parseaddr(email) + _, _, domain = email.rpartition('@') return email in approved_emails or domain in whitelist_emails to_send = [] diff --git a/bandit/tests.py b/bandit/tests.py index b0159f1..d3e06fa 100644 --- a/bandit/tests.py +++ b/bandit/tests.py @@ -162,12 +162,14 @@ def test_send_multiple(self): self.assertEqual(message.get_all('to'), ['admin@example.com', ]) def test_whitelist_domain(self): - addresses = ['foo@whitelisted.test.com', 'bar@whitelisted.test.com'] + addresses = ['foo@whitelisted.test.com', + '', + 'Foo Bar '] emails = [EmailMessage( 'Subject', 'Content', 'from@example.com', addresses)] num_sent = self.get_connection().send_messages(emails) self.assertEqual(len(emails), num_sent) messages = self.get_mailbox_content() - self.assertEqual(messages[0].get_all('to'), [', '.join(addresses)]) + self.assertEqual(messages[0].get_all('to')[0].replace('\n', ''), ', '.join(addresses)) class LogOnlyBackendTestCase(BaseBackendTestCase): diff --git a/runtests.py b/runtests.py index c10a4cf..4e09507 100644 --- a/runtests.py +++ b/runtests.py @@ -31,15 +31,14 @@ def runtests(): - if django.VERSION > (1, 7): - # http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts - django.setup() + django.setup() from django.test.utils import get_runner TestRunner = get_runner(settings) test_runner = TestRunner(verbosity=1, interactive=True, failfast=True) - failures = test_runner.run_tests(['bandit', ]) + failures = test_runner.run_tests(['bandit']) if failures: sys.exit(1) + if __name__ == '__main__': runtests(*sys.argv[1:])