Ticket #861: 861-starttls.patch

File 861-starttls.patch, 3.2 KB (added by Jessica Tallon, 10 years ago)

Patch to add documentation and unit tests

  • mediagoblin/config_spec.ini

    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/")  
    2323
    2424# set to false to enable sending notices
    2525email_debug_mode = boolean(default=True)
     26
     27# Uses SSL/TLS when connecting to SMTP server
    2628email_smtp_use_ssl = boolean(default=False)
    27 email_smtp_force_tls = boolean(default=False)
     29
     30# Uses STARTTLS when connecting to SMTP server
     31email_smtp_force_starttls = boolean(default=False)
     32
     33# Email address which notices are sent from
    2834email_sender_address = string(default="notice@mediagoblin.example.org")
     35
     36# Hostname of SMTP server
    2937email_smtp_host = string(default='')
     38
     39# Port for SMTP server
    3040email_smtp_port = integer(default=0)
     41
     42# Username used for SMTP server
    3143email_smtp_user = string(default=None)
     44
     45# Password used for SMTP server
    3246email_smtp_pass = string(default=None)
    3347
     48
    3449# Set to false to disable registrations
    3550allow_registration = boolean(default=True)
    3651
  • mediagoblin/tests/test_util.py

    diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
    index 9d9b1c1..36563e7 100644
    a b  
    1414# You should have received a copy of the GNU Affero General Public License
    1515# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616
     17import mock
    1718import email
     19import pytest
     20import smtplib
     21import pkg_resources
    1822
     23from mediagoblin.tests.tools import get_app
    1924from mediagoblin.tools import common, url, translate, mail, text, testing
    2025
    2126testing._activate_testing()
    I hope you like unit tests JUST AS MUCH AS I DO!"""  
    6974
    7075I hope you like unit tests JUST AS MUCH AS I DO!"""
    7176
     77@pytest.fixture()
     78def 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
     87def 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
    7299def test_slugify():
    73100    assert url.slugify(u'a walk in the park') == u'a-walk-in-the-park'
    74101    assert url.slugify(u'A Walk in the Park') == u'a-walk-in-the-park'
  • mediagoblin/tools/mail.py

    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):  
    111111            mhost.starttls()
    112112        except smtplib.SMTPException:
    113113            # 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']:
    115115                six.reraise(*sys.exc_info())
    116116
    117117    if ((not common.TESTS_ENABLED)