summaryrefslogtreecommitdiff
path: root/src/mailman/rest
diff options
context:
space:
mode:
authorMark Sapiro2017-02-19 17:37:05 -0800
committerMark Sapiro2017-02-19 17:44:16 -0800
commitc39ef107c1765f1eb937bfcaae2e23dda0b4c581 (patch)
treec7df0bb15b8631d12284dcc548e49b6d37569f70 /src/mailman/rest
parent1bde5f4b0f91831b22ebba135dc361ad9d622b3e (diff)
downloadmailman-c39ef107c1765f1eb937bfcaae2e23dda0b4c581.tar.gz
mailman-c39ef107c1765f1eb937bfcaae2e23dda0b4c581.tar.zst
mailman-c39ef107c1765f1eb937bfcaae2e23dda0b4c581.zip
Diffstat (limited to 'src/mailman/rest')
-rw-r--r--src/mailman/rest/lists.py10
-rw-r--r--src/mailman/rest/tests/test_lists.py22
2 files changed, 31 insertions, 1 deletions
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', {