diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index 72993ed..b5c957c 100644
a
|
b
|
direct_remote_path = string(default="/mgoblin_static/")
|
23 | 23 | |
24 | 24 | # set to false to enable sending notices |
25 | 25 | email_debug_mode = boolean(default=True) |
| 26 | |
| 27 | # Uses SSL/TLS when connecting to SMTP server |
26 | 28 | email_smtp_use_ssl = boolean(default=False) |
27 | | email_smtp_force_tls = boolean(default=False) |
| 29 | |
| 30 | # Uses STARTTLS when connecting to SMTP server |
| 31 | email_smtp_force_starttls = boolean(default=False) |
| 32 | |
| 33 | # Email address which notices are sent from |
28 | 34 | email_sender_address = string(default="notice@mediagoblin.example.org") |
| 35 | |
| 36 | # Hostname of SMTP server |
29 | 37 | email_smtp_host = string(default='') |
| 38 | |
| 39 | # Port for SMTP server |
30 | 40 | email_smtp_port = integer(default=0) |
| 41 | |
| 42 | # Username used for SMTP server |
31 | 43 | email_smtp_user = string(default=None) |
| 44 | |
| 45 | # Password used for SMTP server |
32 | 46 | email_smtp_pass = string(default=None) |
33 | 47 | |
| 48 | |
34 | 49 | # Set to false to disable registrations |
35 | 50 | allow_registration = boolean(default=True) |
36 | 51 | |
diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
index 9d9b1c1..36563e7 100644
a
|
b
|
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
| 17 | import mock |
17 | 18 | import email |
| 19 | import pytest |
| 20 | import smtplib |
| 21 | import pkg_resources |
18 | 22 | |
| 23 | from mediagoblin.tests.tools import get_app |
19 | 24 | from mediagoblin.tools import common, url, translate, mail, text, testing |
20 | 25 | |
21 | 26 | testing._activate_testing() |
… |
… |
I hope you like unit tests JUST AS MUCH AS I DO!"""
|
69 | 74 | |
70 | 75 | I hope you like unit tests JUST AS MUCH AS I DO!""" |
71 | 76 | |
| 77 | @pytest.fixture() |
| 78 | def starttls_enabled_app(request): |
| 79 | return get_app( |
| 80 | request, |
| 81 | mgoblin_config=pkg_resources.resource_filename( |
| 82 | "mediagoblin.tests", |
| 83 | "starttls_config.ini" |
| 84 | ) |
| 85 | ) |
| 86 | |
| 87 | def test_email_force_starttls(starttls_enabled_app): |
| 88 | common.TESTS_ENABLED = False |
| 89 | SMTP = lambda *args, **kwargs: mail.FakeMhost() |
| 90 | with mock.patch('smtplib.SMTP', SMTP): |
| 91 | with pytest.raises(smtplib.SMTPException): |
| 92 | mail.send_email( |
| 93 | from_addr="notices@my.test.instance.com", |
| 94 | to_addrs="someone@someplace.com", |
| 95 | subject="Testing is so much fun!", |
| 96 | message_body="Ohai ^_^" |
| 97 | ) |
| 98 | |
72 | 99 | def test_slugify(): |
73 | 100 | assert url.slugify(u'a walk in the park') == u'a-walk-in-the-park' |
74 | 101 | assert url.slugify(u'A Walk in the Park') == u'a-walk-in-the-park' |
diff --git a/mediagoblin/tools/mail.py b/mediagoblin/tools/mail.py
index 889a442..ab35583 100644
a
|
b
|
def send_email(from_addr, to_addrs, subject, message_body):
|
111 | 111 | mhost.starttls() |
112 | 112 | except smtplib.SMTPException: |
113 | 113 | # Only raise an exception if we're forced to |
114 | | if mg_globals.app_config['email_smtp_force_tls']: |
| 114 | if mg_globals.app_config['email_smtp_force_starttls']: |
115 | 115 | six.reraise(*sys.exc_info()) |
116 | 116 | |
117 | 117 | if ((not common.TESTS_ENABLED) |