diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/app/templates.py | 4 | ||||
| -rw-r--r-- | src/mailman/model/docs/registration.rst | 33 | ||||
| -rw-r--r-- | src/mailman/model/tests/test_registrar.py | 64 |
3 files changed, 70 insertions, 31 deletions
diff --git a/src/mailman/app/templates.py b/src/mailman/app/templates.py index 742f8c0b2..d62ac7f16 100644 --- a/src/mailman/app/templates.py +++ b/src/mailman/app/templates.py @@ -55,7 +55,7 @@ class MailmanHandler(BaseHandler): assert parsed.scheme == 'mailman' # The path can contain one, two, or three components. Since no empty # path components are legal, filter them out. - parts = [p for p in parsed.path.split('/') if p is not None] + parts = [p for p in parsed.path.split('/') if p] if len(parts) == 0: raise URLError('No template specified') elif len(parts) == 1: @@ -103,4 +103,4 @@ class TemplateLoader: def get(self, uri): """See `ITemplateLoader`.""" with closing(urlopen(uri)) as fp: - return fp.read().decode('utf-8') + return fp.read() diff --git a/src/mailman/model/docs/registration.rst b/src/mailman/model/docs/registration.rst index 32ee27316..738006a3d 100644 --- a/src/mailman/model/docs/registration.rst +++ b/src/mailman/model/docs/registration.rst @@ -8,7 +8,7 @@ additional information they may supply. All registered email addresses must be verified before Mailman will send them any list traffic. The ``IUserManager`` manages users, but it does so at a fairly low level. -Specifically, it does not handle verifications, email address syntax validity +Specifically, it does not handle verification, email address syntax validity checks, etc. The ``IRegistrar`` is the interface to the object handling all this stuff. @@ -19,7 +19,7 @@ this stuff. Here is a helper function to check the token strings. >>> def check_token(token): - ... assert isinstance(token, basestring), 'Not a string' + ... assert isinstance(token, str), 'Not a string' ... assert len(token) == 40, 'Unexpected length: %d' % len(token) ... assert token.isalnum(), 'Not alphanumeric' ... print('ok') @@ -47,31 +47,6 @@ Some amount of sanity checks are performed on the email address, although honestly, not as much as probably should be done. Still, some patently bad addresses are rejected outright. - >>> registrar.register(mlist, '') - Traceback (most recent call last): - ... - InvalidEmailAddressError - >>> registrar.register(mlist, 'some name@example.com') - Traceback (most recent call last): - ... - InvalidEmailAddressError: some name@example.com - >>> registrar.register(mlist, '<script>@example.com') - Traceback (most recent call last): - ... - InvalidEmailAddressError: <script>@example.com - >>> registrar.register(mlist, '\xa0@example.com') - Traceback (most recent call last): - ... - InvalidEmailAddressError: \xa0@example.com - >>> registrar.register(mlist, 'noatsign') - Traceback (most recent call last): - ... - InvalidEmailAddressError: noatsign - >>> registrar.register(mlist, 'nodom@ain') - Traceback (most recent call last): - ... - InvalidEmailAddressError: nodom@ain - Register an email address ========================= @@ -151,7 +126,7 @@ message is sent to the user in order to verify the registered address. _parsemsg : False listname : alpha@example.com nodecorate : True - recipients : set([u'aperson@example.com']) + recipients : {'aperson@example.com'} reduced_list_headers: True version : 3 @@ -312,7 +287,7 @@ Corner cases If you try to confirm a token that doesn't exist in the pending database, the confirm method will just return False. - >>> registrar.confirm(bytes('no token')) + >>> registrar.confirm(bytes(b'no token')) False Likewise, if you try to confirm, through the `IUserRegistrar` interface, a diff --git a/src/mailman/model/tests/test_registrar.py b/src/mailman/model/tests/test_registrar.py new file mode 100644 index 000000000..8d7c00e78 --- /dev/null +++ b/src/mailman/model/tests/test_registrar.py @@ -0,0 +1,64 @@ +# Copyright (C) 2014 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Test `IRegistrar`.""" + +__all__ = [ + 'TestRegistrar', + ] + + +import unittest + +from functools import partial +from mailman.app.lifecycle import create_list +from mailman.interfaces.address import InvalidEmailAddressError +from mailman.interfaces.registrar import IRegistrar +from mailman.testing.layers import ConfigLayer +from zope.component import getUtility + + + +class TestRegistrar(unittest.TestCase): + layer = ConfigLayer + + def setUp(self): + mlist = create_list('test@example.com') + self._register = partial(getUtility(IRegistrar).register, mlist) + + def test_invalid_empty_string(self): + self.assertRaises(InvalidEmailAddressError, self._register, '') + + def test_invalid_space_in_name(self): + self.assertRaises(InvalidEmailAddressError, self._register, + 'some name@example.com') + + def test_invalid_funky_characters(self): + self.assertRaises(InvalidEmailAddressError, self._register, + '<script>@example.com') + + def test_invalid_nonascii(self): + self.assertRaises(InvalidEmailAddressError, self._register, + '\xa0@example.com') + + def test_invalid_no_at_sign(self): + self.assertRaises(InvalidEmailAddressError, self._register, + 'noatsign') + + def test_invalid_no_domain(self): + self.assertRaises(InvalidEmailAddressError, self._register, + 'nodom@ain') |
