Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits:
7661347e by Abhilash Raj at 2019-02-23T23:57:15Z
Catch ValueError and return 400 instead of 500.
Uncaught ValueErrors return 500 errors but instead should be returning 400
errors.
- - - - -
f2c0101d by Abhilash Raj at 2019-02-23T23:57:15Z
Merge branch 'fix-uncaught-errors' into 'master'
Catch ValueError and return 400 instead of 500.
See merge request mailman/mailman!458
- - - - -
5 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/rest/domains.py
- src/mailman/rest/lists.py
- src/mailman/rest/tests/test_domains.py
- src/mailman/rest/tests/test_lists.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -16,6 +16,10 @@ Here is a history of user visible changes to Mailman.
=====
(2019-XX-XX)
+REST
+----
+* Failed validation to new Mailing List creation and Domain creation no longer
+ returns 500 errors.
3.2.1
=====================================
src/mailman/rest/domains.py
=====================================
@@ -163,7 +163,7 @@ class AllDomains(_DomainBase):
if owners is not None:
values['owners'] = owners
domain = domain_manager.add(**values)
- except BadDomainSpecificationError as error:
+ except (BadDomainSpecificationError, ValueError) as error:
bad_request(response, str(error))
else:
location = self.api.path_to('domains/{}'.format(domain.mail_host))
=====================================
src/mailman/rest/lists.py
=====================================
@@ -299,6 +299,8 @@ class AllLists(_ListBase):
style_name=str,
_optional=('style_name',))
mlist = create_list(**validator(request))
+ except ValueError as error:
+ bad_request(response, str(error))
except ListAlreadyExistsError:
bad_request(response, b'Mailing list exists')
except BadDomainSpecificationError as error:
=====================================
src/mailman/rest/tests/test_domains.py
=====================================
@@ -48,6 +48,18 @@ class TestDomains(unittest.TestCase):
'http://localhost:9001/3.0/domains', data, method="POST")
self.assertEqual(response.status_code, 201)
+ def test_create_domain_bad_values(self):
+ # Failed validation of values don't return 500 error but 400.
+ data = dict(
+ mail_host='example.org',
+ random=10,
+ )
+ with self.assertRaises(HTTPError) as cm:
+ content, response = call_api(
+ 'http://localhost:9001/3.0/domains', data, method="POST")
+ self.assertEqual(cm.exception.code, 400)
+ self.assertEqual(cm.exception.reason, 'Unexpected parameters: random')
+
def test_patch_domain_description(self):
# Patch the example.com description.
data = {'description': 'Patched example domain'}
=====================================
src/mailman/rest/tests/test_lists.py
=====================================
@@ -225,6 +225,15 @@ class TestLists(unittest.TestCase):
self.assertEqual(cm.exception.reason,
'Invalid list posting address: @example.com')
+ def test_create_list_failed_validator_returns_bad_requests(self):
+ # Test that missing parameter or any other error that fails validation
+ # doesn't raise 500 error.
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/lists', method='POST')
+ self.assertEqual(cm.exception.code, 400)
+ self.assertEqual(cm.exception.reason,
+ 'Missing parameters: fqdn_listname')
+
def test_cannot_create_list_with_invalid_name(self):
# You cannot create a mailing list which would have an invalid list
# posting address.
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/9a4c03c6f6dad5b7d7cb80cb83ac82bc157f1989...f2c0101d373591cc317dd3e1cb183c2f4cf2af03
--
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/9a4c03c6f6dad5b7d7cb80cb83ac82bc157f1989...f2c0101d373591cc317dd3e1cb183c2f4cf2af03
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org