From 0b3b801e85d858a6fde47254d27985386d753762 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 8 Dec 2014 21:35:41 -0500 Subject: Fix the approved rule. Don't decode the payload so that we get a unicode to search against. This may not be in the long-term best interest because it ignores Content-Transfer-Encoding, however with decode=True it always returns binary data. We may have to decode and then re.search() with a bytes pattern. passlib always returns a unicode password in Python 3, so adjust for that. --- src/mailman/rules/approved.py | 2 +- src/mailman/rules/tests/test_approved.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/mailman') diff --git a/src/mailman/rules/approved.py b/src/mailman/rules/approved.py index 2839ffef4..c5d099001 100644 --- a/src/mailman/rules/approved.py +++ b/src/mailman/rules/approved.py @@ -112,7 +112,7 @@ class Approved: # may not work with rtf or whatever else is possible. pattern = header + ':(\s| )*' + re.escape(password) for part in typed_subpart_iterator(msg, 'text'): - payload = part.get_payload(decode=True) + payload = part.get_payload() if payload is not None: if re.search(pattern, payload): reset_payload(part, re.sub(pattern, '', payload)) diff --git a/src/mailman/rules/tests/test_approved.py b/src/mailman/rules/tests/test_approved.py index e7f122410..ec8e861af 100644 --- a/src/mailman/rules/tests/test_approved.py +++ b/src/mailman/rules/tests/test_approved.py @@ -433,7 +433,7 @@ class TestPasswordHashMigration(unittest.TestCase): # hash is chosen after the original password is set. As long as the # old password still validates, the migration happens automatically. self._mlist.moderator_password = config.password_context.encrypt( - b'super secret') + 'super secret') self._rule = approved.Approved() self._msg = mfs("""\ From: anne@example.com @@ -450,7 +450,7 @@ A message body. # hashing algorithm. When the old password is validated, it will be # automatically migrated to the new hash. self.assertEqual(self._mlist.moderator_password, - b'{plaintext}super secret') + '{plaintext}super secret') config_file = os.path.join(config.VAR_DIR, 'passlib.config') # XXX passlib seems to choose the default hashing scheme even if it is # deprecated. The default scheme is either specified explicitly, or @@ -466,14 +466,14 @@ deprecated = roundup_plaintext self._msg['Approved'] = 'super secret' result = self._rule.check(self._mlist, self._msg, {}) self.assertTrue(result) - self.assertEqual(self._mlist.moderator_password, b'super secret') + self.assertEqual(self._mlist.moderator_password, 'super secret') def test_invalid_password_does_not_migrate(self): # Now that the moderator password is set, change the default password # hashing algorithm. When the old password is invalid, it will not be # automatically migrated to the new hash. self.assertEqual(self._mlist.moderator_password, - b'{plaintext}super secret') + '{plaintext}super secret') config_file = os.path.join(config.VAR_DIR, 'passlib.config') # XXX passlib seems to choose the default hashing scheme even if it is # deprecated. The default scheme is either specified explicitly, or @@ -490,4 +490,4 @@ deprecated = roundup_plaintext result = self._rule.check(self._mlist, self._msg, {}) self.assertFalse(result) self.assertEqual(self._mlist.moderator_password, - b'{plaintext}super secret') + '{plaintext}super secret') -- cgit v1.2.3-70-g09d2