diff options
| author | Barry Warsaw | 2016-03-20 21:31:19 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2016-03-20 21:31:50 -0400 |
| commit | 472eb9765f4163aad785f483584ff607f01fdeeb (patch) | |
| tree | de3c113e48cf8c311a246dc3fa7fab456198fe39 /src/mailman/handlers/tests | |
| parent | d6d598a15d34b60fa4ceb3ee292bf2740addc878 (diff) | |
| download | mailman-472eb9765f4163aad785f483584ff607f01fdeeb.tar.gz mailman-472eb9765f4163aad785f483584ff607f01fdeeb.tar.zst mailman-472eb9765f4163aad785f483584ff607f01fdeeb.zip | |
Diffstat (limited to 'src/mailman/handlers/tests')
| -rw-r--r-- | src/mailman/handlers/tests/test_decorate.py | 57 | ||||
| -rw-r--r-- | src/mailman/handlers/tests/test_rfc_2369.py | 41 |
2 files changed, 96 insertions, 2 deletions
diff --git a/src/mailman/handlers/tests/test_decorate.py b/src/mailman/handlers/tests/test_decorate.py index 84adceb9a..2a44d4186 100644 --- a/src/mailman/handlers/tests/test_decorate.py +++ b/src/mailman/handlers/tests/test_decorate.py @@ -18,6 +18,7 @@ """Test the decorate handler.""" __all__ = [ + 'TestBrokenPermalink', 'TestDecorate', ] @@ -29,7 +30,8 @@ from mailman.app.lifecycle import create_list from mailman.config import config from mailman.handlers import decorate from mailman.interfaces.archiver import IArchiver -from mailman.testing.helpers import specialized_message_from_string as mfs +from mailman.testing.helpers import ( + LogFileMark, specialized_message_from_string as mfs) from mailman.testing.layers import ConfigLayer from tempfile import TemporaryDirectory from zope.interface import implementer @@ -48,6 +50,16 @@ class TestArchiver: return 'http://example.com/link_to_message' +@implementer(IArchiver) +class BrokenArchiver: + name = 'broken' + is_enabled = True + + @staticmethod + def permalink(mlist, msg): + raise RuntimeError('Cannot get permalink') + + class TestDecorate(unittest.TestCase): """Test the cook_headers handler.""" @@ -116,3 +128,46 @@ This is a test message. decorate.process(self._mlist, self._msg, {}) self.assertIn('http://example.com/link_to_message', self._msg.as_string()) + + +class TestBrokenPermalink(unittest.TestCase): + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('ant@example.com') + self._msg = mfs("""\ +To: ant@example.com +From: aperson@example.com +Message-ID: <alpha> +Content-Type: text/plain; + +This is a test message. +""") + temporary_dir = TemporaryDirectory() + self.addCleanup(temporary_dir.cleanup) + template_dir = temporary_dir.name + config.push('archiver', """\ + [paths.testing] + template_dir: {} + [archiver.testarchiver] + class: mailman.handlers.tests.test_decorate.BrokenArchiver + enable: yes + """.format(template_dir)) + self.addCleanup(config.pop, 'archiver') + + def test_broken_permalink(self): + # GL issue #208 - IArchive messages raise exceptions, breaking the + # rfc-2369 handler and shunting messages. + site_dir = os.path.join(config.TEMPLATE_DIR, 'site', 'en') + os.makedirs(site_dir) + footer_path = os.path.join(site_dir, 'myfooter.txt') + with open(footer_path, 'w', encoding='utf-8') as fp: + print('${broken_url}', file=fp) + self._mlist.footer_uri = 'mailman:///myfooter.txt' + self._mlist.preferred_language = 'en' + mark = LogFileMark('mailman.archiver') + decorate.process(self._mlist, self._msg, {}) + log_messages = mark.read() + self.assertNotIn('http:', self._msg.as_string()) + self.assertIn('Exception in "broken" archiver', log_messages) + self.assertIn('RuntimeError: Cannot get permalink', log_messages) diff --git a/src/mailman/handlers/tests/test_rfc_2369.py b/src/mailman/handlers/tests/test_rfc_2369.py index 110024c16..cbbaf2153 100644 --- a/src/mailman/handlers/tests/test_rfc_2369.py +++ b/src/mailman/handlers/tests/test_rfc_2369.py @@ -28,7 +28,8 @@ from mailman.app.lifecycle import create_list from mailman.config import config from mailman.handlers import rfc_2369 from mailman.interfaces.archiver import ArchivePolicy, IArchiver -from mailman.testing.helpers import specialized_message_from_string as mfs +from mailman.testing.helpers import ( + LogFileMark, specialized_message_from_string as mfs) from mailman.testing.layers import ConfigLayer from urllib.parse import urljoin from zope.interface import implementer @@ -56,6 +57,23 @@ class DummyArchiver: return None +@implementer(IArchiver) +class BrokenArchiver: + """An archiver that has some broken methods.""" + + name = 'broken' + + def list_url(self, mlist): + raise RuntimeError('Cannot get list URL') + + def permalink(self, mlist, msg): + raise RuntimeError('Cannot get permalink') + + @staticmethod + def archive_message(mlist, message): + raise RuntimeError('Cannot archive message') + + class TestRFC2369(unittest.TestCase): """Test the rfc_2369 handler.""" @@ -123,3 +141,24 @@ Dummy text rfc_2369.process(self._mlist, self._msg, {}) self.assertNotIn('List-Archive', self._msg) self.assertNotIn('Archived-At', self._msg) + + def test_broken_archiver(self): + # GL issue #208 - IArchive messages raise exceptions, breaking the + # rfc-2369 handler and shunting messages. + config.push('archiver', """ + [archiver.broken] + class: {}.BrokenArchiver + enable: yes + """.format(BrokenArchiver.__module__)) + self.addCleanup(config.pop, 'archiver') + mark = LogFileMark('mailman.archiver') + rfc_2369.process(self._mlist, self._msg, {}) + log_messages = mark.read() + # Because .list_url() was broken, there will be no List-Archive header. + self.assertIsNone(self._msg.get('list-archive')) + self.assertIn('Exception in "broken" archiver', log_messages) + self.assertIn('RuntimeError: Cannot get list URL', log_messages) + # Because .permalink() was broken, there will be no Archived-At header. + self.assertIsNone(self._msg.get('archived-at')) + self.assertIn('Exception in "broken" archiver', log_messages) + self.assertIn('RuntimeError: Cannot get permalink', log_messages) |
