diff options
| -rw-r--r-- | src/mailman/app/lifecycle.py | 4 | ||||
| -rw-r--r-- | src/mailman/app/tests/test_lifecycle.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/lists.py | 10 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_lists.py | 22 |
4 files changed, 36 insertions, 2 deletions
diff --git a/src/mailman/app/lifecycle.py b/src/mailman/app/lifecycle.py index 6970de187..e373bf4d9 100644 --- a/src/mailman/app/lifecycle.py +++ b/src/mailman/app/lifecycle.py @@ -44,6 +44,10 @@ _listname_chars = re.compile('[-_.+=!$*{}~0-9a-z]', re.IGNORECASE) class InvalidListNameError(InvalidEmailAddressError): """List name is invalid.""" + def __init__(self, listname): + super().__init__('{}@any.example.com'.format(listname)) + self.listname = listname + @public def create_list(fqdn_listname, owners=None, style_name=None): diff --git a/src/mailman/app/tests/test_lifecycle.py b/src/mailman/app/tests/test_lifecycle.py index 3730291da..4b198d973 100644 --- a/src/mailman/app/tests/test_lifecycle.py +++ b/src/mailman/app/tests/test_lifecycle.py @@ -54,7 +54,7 @@ class TestLifecycle(unittest.TestCase): mlist = create_list('test@example.com') # Check the error log. self.assertRegex( - mark.readline()[-93:-1], + mark.readline(), '^.*Bad config\.mailman\.listname_chars setting: ' '\[a-z0-9-\+\\\]: ' '(unterminated character set|' diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index e665515ec..4b467afb3 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -20,8 +20,10 @@ from lazr.config import as_boolean from mailman.app.digests import ( bump_digest_number_and_volume, maybe_send_digest_now) -from mailman.app.lifecycle import create_list, remove_list +from mailman.app.lifecycle import ( + InvalidListNameError, create_list, remove_list) from mailman.config import config +from mailman.interfaces.address import InvalidEmailAddressError from mailman.interfaces.domain import BadDomainSpecificationError from mailman.interfaces.listmanager import ( IListManager, ListAlreadyExistsError) @@ -246,6 +248,12 @@ class AllLists(_ListBase): except BadDomainSpecificationError as error: reason = 'Domain does not exist: {}'.format(error.domain) bad_request(response, reason.encode('utf-8')) + except InvalidListNameError as error: + reason = 'Invalid list name: {}'.format(error.listname) + bad_request(response, reason.encode('utf-8')) + except InvalidEmailAddressError as error: + reason = 'Invalid list posting address: {}'.format(error.email) + bad_request(response, reason.encode('utf-8')) else: location = self.api.path_to('lists/{0}'.format(mlist.list_id)) created(response, location) diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index 7bb7bd333..75a81f3cb 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -129,6 +129,28 @@ class TestLists(unittest.TestCase): self.assertEqual(cm.exception.reason, 'Domain does not exist: no-domain.example.org') + def test_cannot_create_list_with_invalid_posting_address(self): + # You cannot create a mailing list which would have an invalid list + # posting address. + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.0/lists', { + 'fqdn_listname': '@example.com', + }) + self.assertEqual(cm.exception.code, 400) + self.assertEqual(cm.exception.reason, + 'Invalid list posting address: @example.com') + + def test_cannot_create_list_with_invalid_name(self): + # You cannot create a mailing list which would have an invalid list + # posting address. + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.0/lists', { + 'fqdn_listname': 'a/list@example.com', + }) + self.assertEqual(cm.exception.code, 400) + self.assertEqual(cm.exception.reason, + 'Invalid list name: a/list') + def test_cannot_create_duplicate_list(self): # You cannot create a list that already exists. call_api('http://localhost:9001/3.0/lists', { |
