Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core


Commits:
aaa6c921 by Abhilash Raj at 2019-05-08T19:30:23Z
Fix 500 error when creating a user with invalid email address.

- - - - -
78ef269e by Abhilash Raj at 2019-05-09T15:36:08Z
Merge branch 'fix-263' into 'master'

Fix 500 error when creating a user with invalid email address.

Closes #263

See merge request mailman/mailman!514
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rest/tests/test_users.py
- src/mailman/rest/users.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -45,6 +45,7 @@ REST
 * Expose `header_matches/find` API to find a list of ``HeaderMatches`` 
belonging
   to a MailingList. (See !497)
 * Allow adding a comment when rejecting held messages. (Closes #594)
+* Fix a 500 error when creating a user with invalid email address. (Closes 
#263)
 
 Other
 -----


=====================================
src/mailman/rest/tests/test_users.py
=====================================
@@ -238,6 +238,15 @@ class TestUsers(unittest.TestCase):
         json, response = call_api('http://localhost:9001/3.0/users')
         self.assertEqual(json['total_size'], 1)
 
+    def test_create_user_bad_email(self):
+        # https://gitlab.com/mailman/mailman/issues/263
+        with self.assertRaises(HTTPError) as cm:
+            call_api('http://localhost:9001/3.0/users', dict(
+                email='anne@invalid'))
+        # There is now one user.
+        self.assertEqual(cm.exception.code, 400)
+        self.assertEqual(cm.exception.reason, 'anne@invalid')
+
     def test_create_server_owner_false(self):
         # Issue #136: Creating a user with is_server_owner=no should create
         # user who is not a server owner.


=====================================
src/mailman/rest/users.py
=====================================
@@ -20,7 +20,8 @@
 from functools import lru_cache
 from lazr.config import as_boolean
 from mailman.config import config
-from mailman.interfaces.address import ExistingAddressError
+from mailman.interfaces.address import (
+    ExistingAddressError, InvalidEmailAddressError)
 from mailman.interfaces.usermanager import IUserManager
 from mailman.rest.addresses import PreferredAddress, UserAddresses
 from mailman.rest.helpers import (
@@ -160,10 +161,10 @@ class AllUsers(_UserBase):
         try:
             validator = Validator(**CREATION_FIELDS)
             arguments = validator(request)
-        except ValueError as error:
+            create_user(self.api, arguments, response)
+        except (ValueError, InvalidEmailAddressError) as error:
             bad_request(response, str(error))
             return
-        create_user(self.api, arguments, response)
 
 
 @public



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/9b6eabf9a70911e43dced5553e2c18241612ee43...78ef269ef419e3607593ea249831ce554b7e749c

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/9b6eabf9a70911e43dced5553e2c18241612ee43...78ef269ef419e3607593ea249831ce554b7e749c
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to