diff options
| author | Barry Warsaw | 2016-05-03 22:35:04 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2016-05-03 22:35:04 -0400 |
| commit | 201d92a40f09706cb30e6e94f375204a37122f86 (patch) | |
| tree | e71c7a44e8a30552116f0ce85ee97eb9c69ba4ee /src/mailman/rules/tests | |
| parent | 9c6ab1fdfe20dd852157120c939ceec52398834c (diff) | |
| download | mailman-201d92a40f09706cb30e6e94f375204a37122f86.tar.gz mailman-201d92a40f09706cb30e6e94f375204a37122f86.tar.zst mailman-201d92a40f09706cb30e6e94f375204a37122f86.zip | |
Diffstat (limited to 'src/mailman/rules/tests')
| -rw-r--r-- | src/mailman/rules/tests/test_moderation.py | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/src/mailman/rules/tests/test_moderation.py b/src/mailman/rules/tests/test_moderation.py index 7da07b200..197bb6c7d 100644 --- a/src/mailman/rules/tests/test_moderation.py +++ b/src/mailman/rules/tests/test_moderation.py @@ -210,15 +210,19 @@ A message body. self.assertTrue(result) self.assertEqual(msgdata.get('moderation_action'), 'hold') - def test_linked_address_nonmembermoderation(self): + def test_linked_address_nonmembermoderation_misses(self): + # Anne subscribes to a mailing list as a user with her preferred + # address. She also has a secondary linked address, and she uses this + # to post to the mailing list. The NonmemberModeration rule misses + # because Anne is not a nonmember. user_manager = getUtility(IUserManager) anne = user_manager.create_user('anne@example.com') set_preferred(anne) self._mlist.subscribe(anne, MemberRole.member) - anne.link(user_manager.create_address('anne2@example.com')) + anne.link(user_manager.create_address('anne.person@example.com')) rule = moderation.NonmemberModeration() msg = mfs("""\ -From: anne2@example.com +From: anne.person@example.com To: test@example.com Subject: A test message Message-ID: <ant> @@ -226,22 +230,23 @@ MIME-Version: 1.0 A message body. """) - # The NonmemberModeration rule should evaluate - # to False since the linked user is subscribed to the list - msgdata = {} - result = rule.check(self._mlist, msg, msgdata) + result = rule.check(self._mlist, msg, {}) self.assertFalse(result) - def test_linked_address_membermoderation(self): + def test_linked_address_membermoderation_hits(self): + # Anne subscribes to a mailing list as a user with her preferred + # address. She also has a secondary linked address, and she uses this + # to post to the mailing list. The MemberModeration rule hits because + # Anne is a member. self._mlist.default_member_action = Action.accept user_manager = getUtility(IUserManager) anne = user_manager.create_user('anne@example.com') set_preferred(anne) self._mlist.subscribe(anne, MemberRole.member) - anne.link(user_manager.create_address('anne2@example.com')) + anne.link(user_manager.create_address('anne.person@example.com')) rule = moderation.MemberModeration() msg = mfs("""\ -From: anne2@example.com +From: anne.person@example.com To: test@example.com Subject: A test message Message-ID: <ant> @@ -249,22 +254,23 @@ MIME-Version: 1.0 A message body. """) - # The MemberModeration rule should evaluate - # to True since the linked user is subscribed to the list - msgdata = {} - result = rule.check(self._mlist, msg, msgdata) + result = rule.check(self._mlist, msg, {}) self.assertTrue(result) def test_banned_address_linked_to_user(self): + # Anne is subscribed to a mailing list as a user with her preferred + # address. She also has a secondary address which is banned and which + # she uses to post to the mailing list. Both the MemberModeration and + # NonmemberModeration rules miss because the posting address is + # banned. user_manager = getUtility(IUserManager) anne = user_manager.create_user('anne@example.com') set_preferred(anne) self._mlist.subscribe(anne, MemberRole.member) - anne.link(user_manager.create_address('anne2@example.com')) - IBanManager(self._mlist).ban('anne2@example.com') - rule = moderation.MemberModeration() + anne.link(user_manager.create_address('anne.person@example.com')) + IBanManager(self._mlist).ban('anne.person@example.com') msg = mfs("""\ -From: anne2@example.com +From: anne.person@example.com To: test@example.com Subject: A test message Message-ID: <ant> @@ -272,22 +278,25 @@ MIME-Version: 1.0 A message body. """) - msgdata = {} - result = rule.check(self._mlist, msg, msgdata) + rule = moderation.MemberModeration() + result = rule.check(self._mlist, msg, {}) self.assertFalse(result) rule = moderation.NonmemberModeration() - result = rule.check(self._mlist, msg, msgdata) + result = rule.check(self._mlist, msg, {}) self.assertFalse(result) def test_banned_sender_among_multiple_senders(self): + # Two addresses are created, one of which is banned. Even though the + # The Nonmember moderation rule misses if any of the banned addresses + # appear in the 'senders' headers of the message. user_manager = getUtility(IUserManager) - user_manager.create_address('ted@example.com') - user_manager.create_address('cris@example.com') - IBanManager(self._mlist).ban('cris@example.com') + user_manager.create_address('anne@example.com') + user_manager.create_address('bart@example.com') + IBanManager(self._mlist).ban('bart@example.com') rule = moderation.NonmemberModeration() msg = mfs("""\ -From: ted@example.com -Sender: cris@example.com +From: anne@example.com +Sender: bart@example.com To: test@example.com Subject: A test message Message-ID: <ant> @@ -295,6 +304,5 @@ MIME-Version: 1.0 A message body. """) - msgdata = {} - result = rule.check(self._mlist, msg, msgdata) + result = rule.check(self._mlist, msg, {}) self.assertFalse(result) |
