Barry Warsaw pushed to branch master at mailman / Mailman
Commits:
cd5607de by Aurélien Bompard at 2016-01-20T10:24:19+01:00
Give a meaningful message when a banned member tries to join
- - - - -
a33f1c52 by Aurélien Bompard at 2016-01-20T10:33:22+01:00
Also add a test for the global ban list
- - - - -
2 changed files:
- src/mailman/rest/members.py
- src/mailman/rest/tests/test_membership.py
Changes:
=====================================
src/mailman/rest/members.py
=====================================
--- a/src/mailman/rest/members.py
+++ b/src/mailman/rest/members.py
@@ -276,6 +276,9 @@ class AllMembers(_MemberBase):
except MissingPreferredAddressError:
bad_request(response, b'User has no preferred address')
return
+ except MembershipIsBannedError:
+ bad_request(response, b'Membership is banned')
+ 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
@@ -29,6 +29,7 @@ import unittest
from mailman.app.lifecycle import create_list
from mailman.config import config
from mailman.database.transaction import transaction
+from mailman.interfaces.bans import IBanManager
from mailman.interfaces.member import DeliveryMode, MemberRole
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import (
@@ -359,6 +360,30 @@ class TestMembership(unittest.TestCase):
self.assertEqual(headers.status, 204)
self.assertEqual(len(list(self._mlist.moderators.members)), 0)
+ def test_banned_member_tries_to_join(self):
+ # A user tries to join a list they are banned from.
+ with transaction():
+ IBanManager(self._mlist).ban('[email protected]')
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/members', {
+ 'list_id': 'test.example.com',
+ 'subscriber': '[email protected]',
+ })
+ self.assertEqual(cm.exception.code, 400)
+ self.assertEqual(cm.exception.reason, b'Membership is banned')
+
+ def test_globally_banned_member_tries_to_join(self):
+ # A user tries to join a list they are banned from.
+ with transaction():
+ IBanManager(None).ban('[email protected]')
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/members', {
+ 'list_id': 'test.example.com',
+ 'subscriber': '[email protected]',
+ })
+ self.assertEqual(cm.exception.code, 400)
+ self.assertEqual(cm.exception.reason, b'Membership is banned')
+
class CustomLayer(ConfigLayer):
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/29ad7d4a658081a442c6cb120943f7014d36dade...a33f1c528f7565beff8c4b3898714adca4dc33d4
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org