Barry Warsaw pushed to branch release-3.0 at mailman / Mailman
Commits:
6d14d8c5 by Barry Warsaw at 2016-01-02T23:10:00Z
Don't crash the REST server when trying to subscribe a user without a
preferred address.
Closes #185
- - - - -
3 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/rest/members.py
- src/mailman/rest/tests/test_membership.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -34,6 +34,8 @@ REST
Aurélien Bompard.
* Fixed a number of corner cases for the return codes when PUTing or PATCHing
list configuration variables. (Closes: #182)
+ * Don't crash the REST server when trying to subscribe a user without a
+ preferred address. (Closes: #185)
3.0.1 -- "Show Don't Tell"
=====================================
src/mailman/rest/members.py
=====================================
--- a/src/mailman/rest/members.py
+++ b/src/mailman/rest/members.py
@@ -30,7 +30,7 @@ from mailman.interfaces.address import IAddress,
InvalidEmailAddressError
from mailman.interfaces.listmanager import IListManager
from mailman.interfaces.member import (
AlreadySubscribedError, DeliveryMode, MemberRole, MembershipError,
- MembershipIsBannedError, NotAMemberError)
+ MembershipIsBannedError, MissingPreferredAddressError, NotAMemberError)
from mailman.interfaces.registrar import IRegistrar
from mailman.interfaces.subscriptions import (
ISubscriptionService, RequestRecord, TokenOwner)
@@ -269,6 +269,9 @@ class AllMembers(_MemberBase):
except AlreadySubscribedError:
conflict(response, b'Member already subscribed')
return
+ except MissingPreferredAddressError:
+ bad_request(response, b'User has no preferred address')
+ return
if token is None:
assert token_owner is TokenOwner.no_one, token_owner
# The subscription completed. Let's get the resulting member
=====================================
src/mailman/rest/tests/test_membership.py
=====================================
--- a/src/mailman/rest/tests/test_membership.py
+++ b/src/mailman/rest/tests/test_membership.py
@@ -253,6 +253,20 @@ class TestMembership(unittest.TestCase):
call_api('http://localhost:9001/3.0/members/1/all')
self.assertEqual(cm.exception.code, 404)
+ def test_subscribe_user_without_preferred_address(self):
+ with transaction():
+ getUtility(IUserManager).create_user('[email protected]')
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/members', {
+ 'list_id': 'test.example.com',
+ 'subscriber': 1,
+ 'pre_verified': True,
+ 'pre_confirmed': True,
+ 'pre_approved': True,
+ })
+ self.assertEqual(cm.exception.code, 400)
+ self.assertEqual(cm.exception.reason, b'User has no preferred address')
+
class CustomLayer(ConfigLayer):
View it on GitLab:
https://gitlab.com/mailman/mailman/commit/6d14d8c5ae6e52a3970af6d0ad6489cfd153920d
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org