summaryrefslogtreecommitdiff
path: root/src/mailman/rest/tests/test_moderation.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rest/tests/test_moderation.py')
-rw-r--r--src/mailman/rest/tests/test_moderation.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py
index e0c3f1ccf..21129207c 100644
--- a/src/mailman/rest/tests/test_moderation.py
+++ b/src/mailman/rest/tests/test_moderation.py
@@ -19,6 +19,7 @@
import unittest
+from email import message_from_binary_file
from mailman.app.lifecycle import create_list
from mailman.app.moderator import hold_message
from mailman.database.transaction import transaction
@@ -31,6 +32,7 @@ from mailman.testing.helpers import (
call_api, get_queue_messages, set_preferred,
specialized_message_from_string as mfs)
from mailman.testing.layers import RESTLayer
+from pkg_resources import resource_filename
from urllib.error import HTTPError
from zope.component import getUtility
@@ -206,6 +208,24 @@ class TestSubscriptionModeration(unittest.TestCase):
emails = set(json['email'] for json in content['entries'])
self.assertEqual(emails, {'anne@example.com', 'bart@example.com'})
+ def test_view_malformed_held_message(self):
+ # Opening a bad (i.e. bad structure) email and holding it.
+ email_path = resource_filename(
+ 'mailman.rest.tests.data', 'bad_email.eml')
+ with open(email_path, 'rb') as fp:
+ msg = message_from_binary_file(fp)
+ msg.sender = 'aperson@example.com'
+ with transaction():
+ hold_message(self._mlist, msg)
+ # Now trying to access held messages from REST API should not give
+ # 500 server error if one of the messages can't be parsed properly.
+ content, response = call_api(
+ 'http://localhost:9001/3.0/lists/ant@example.com/held')
+ self.assertEqual(response.status, 200)
+ self.assertEqual(len(content['entries']), 1)
+ self.assertEqual(content['entries'][0]['msg'],
+ 'This message is defective')
+
def test_individual_request(self):
# We can view an individual request.
with transaction():