From 36d114b37755ef96c4b0215feabe5095237c15e2 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Wed, 30 Mar 2016 12:07:22 +0200 Subject: Cover another header match import case --- src/mailman/utilities/importer.py | 2 +- src/mailman/utilities/tests/test_import.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py index c908a2ada..b2138cb9b 100644 --- a/src/mailman/utilities/importer.py +++ b/src/mailman/utilities/importer.py @@ -336,7 +336,7 @@ def import_config_pck(mlist, config_dict): for line_pattern in line_patterns.splitlines(): if len(line_pattern.strip()) == 0: continue - for sep in (': ', ':.', ':'): + for sep in (': ', ':.*', ':.', ':'): header, sep, pattern = line_pattern.partition(sep) if sep: # We found it. diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py index d2729e8e1..0d245d594 100644 --- a/src/mailman/utilities/tests/test_import.py +++ b/src/mailman/utilities/tests/test_import.py @@ -336,6 +336,7 @@ class TestBasicImport(unittest.TestCase): ('^Subject: dev-\r\n^Subject: staging-', 3, False), ('from: .*info@aolanchem.com\r\nfrom: .*@jw-express.com', 2, False), + ('^Subject:.*\\Wwas:\\W', 3, False), ('^Received: from smtp-.*\\.fedoraproject\\.org\r\n' '^Received: from mx.*\\.redhat.com\r\n' '^Resent-date:\r\n' @@ -372,6 +373,7 @@ class TestBasicImport(unittest.TestCase): ('subject', 'staging-', 'discard'), ('from', '.*info@aolanchem.com', 'reject'), ('from', '.*@jw-express.com', 'reject'), + ('subject', '\\Wwas:\\W', 'discard'), ('received', 'from smtp-.*\\.fedoraproject\\.org', 'hold'), ('received', 'from mx.*\\.redhat.com', 'hold'), ('resent-date', '.*', 'hold'), -- cgit v1.3.1 From a8f2fc64c683420f40bac1b4c5d551305a0e0ecc Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Mon, 18 Jan 2016 18:25:03 +0100 Subject: Don't show the disabled archivers in the REST API Because one can't add a configuration overlay to the running REST server in testing mode, the prototype archiver was disabled in the testing configuration. This is where most of the changes in this commit come from. --- src/mailman/rest/docs/lists.rst | 4 ---- src/mailman/rest/lists.py | 6 ++++-- src/mailman/rest/tests/test_lists.py | 10 ++++------ src/mailman/testing/testing.cfg | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/mailman/rest/docs/lists.rst b/src/mailman/rest/docs/lists.rst index 6554b04c2..0fb877722 100644 --- a/src/mailman/rest/docs/lists.rst +++ b/src/mailman/rest/docs/lists.rst @@ -250,7 +250,6 @@ archivers are available, and whether they are enabled for this mailing list. http_etag: "..." mail-archive: True mhonarc: True - prototype: True You can set all the archiver states by putting new state flags on the resource. @@ -260,7 +259,6 @@ resource. ... 'http://localhost:9001/3.0/lists/dog@example.com/archivers', { ... 'mail-archive': False, ... 'mhonarc': True, - ... 'prototype': False, ... }, method='PUT') content-length: 0 date: ... @@ -271,7 +269,6 @@ resource. http_etag: "..." mail-archive: False mhonarc: True - prototype: False You can change the state of a subset of the list archivers. :: @@ -289,7 +286,6 @@ You can change the state of a subset of the list archivers. http_etag: "..." mail-archive: False mhonarc: False - prototype: False List digests diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index c3919c001..8e82cd1a4 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -330,13 +330,15 @@ class ListArchivers: """Get all the archiver statuses.""" archiver_set = IListArchiverSet(self._mlist) resource = {archiver.name: archiver.is_enabled - for archiver in archiver_set.archivers} + for archiver in archiver_set.archivers + if archiver.system_archiver.is_enabled} okay(response, etag(resource)) def patch_put(self, request, response, is_optional): archiver_set = IListArchiverSet(self._mlist) kws = {archiver.name: ArchiverGetterSetter(self._mlist) - for archiver in archiver_set.archivers} + for archiver in archiver_set.archivers + if archiver.system_archiver.is_enabled} if is_optional: # For a PATCH, all attributes are optional. kws['_optional'] = kws.keys() diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index 787009855..d83f70058 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -32,7 +32,7 @@ from mailman.interfaces.usermanager import IUserManager from mailman.model.mailinglist import AcceptableAlias from mailman.runners.digest import DigestRunner from mailman.testing.helpers import ( - call_api, get_queue_messages, make_testable_runner, + call_api, configuration, get_queue_messages, make_testable_runner, specialized_message_from_string as mfs) from mailman.testing.layers import RESTLayer from mailman.utilities.datetime import now as right_now @@ -339,7 +339,6 @@ class TestListArchivers(unittest.TestCase): self.assertEqual(resource, { 'mail-archive': True, 'mhonarc': True, - 'prototype': True, }) def test_archiver_statuses_on_missing_lists(self): @@ -375,7 +374,7 @@ class TestListArchivers(unittest.TestCase): def test_put_incomplete_statuses(self): # PUT requires the full resource representation. This one forgets to - # specify the prototype and mhonarc archiver. + # specify the mhonarc archiver. with self.assertRaises(HTTPError) as cm: call_api( 'http://localhost:9001/3.0/lists/ant.example.com/archivers', { @@ -384,7 +383,7 @@ class TestListArchivers(unittest.TestCase): method='PUT') self.assertEqual(cm.exception.code, 400) self.assertEqual(cm.exception.reason, - b'Missing parameters: mhonarc, prototype') + b'Missing parameters: mhonarc') def test_patch_bogus_status(self): # Archiver statuses must be interpretable as booleans. @@ -392,8 +391,7 @@ class TestListArchivers(unittest.TestCase): call_api( 'http://localhost:9001/3.0/lists/ant.example.com/archivers', { 'mail-archive': 'sure', - 'mhonarc': False, - 'prototype': 'no' + 'mhonarc': 'no' }, method='PATCH') self.assertEqual(cm.exception.code, 400) diff --git a/src/mailman/testing/testing.cfg b/src/mailman/testing/testing.cfg index 022f9f289..8b6a48c36 100644 --- a/src/mailman/testing/testing.cfg +++ b/src/mailman/testing/testing.cfg @@ -65,7 +65,7 @@ max_restarts: 1 max_restarts: 1 [archiver.prototype] -enable: yes +enable: no [archiver.mail_archive] enable: yes -- cgit v1.3.1 From accc4f1a883d4a5757eb9b0156e58e72b77a8af7 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Thu, 21 Jan 2016 11:46:49 +0100 Subject: Fix tests --- src/mailman/config/tests/test_archivers.py | 6 +++--- src/mailman/model/tests/test_mailinglist.py | 14 +++++++------- src/mailman/rest/tests/test_lists.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/mailman/config/tests/test_archivers.py b/src/mailman/config/tests/test_archivers.py index 322a5040d..b09b89273 100644 --- a/src/mailman/config/tests/test_archivers.py +++ b/src/mailman/config/tests/test_archivers.py @@ -28,11 +28,11 @@ class TestArchivers(unittest.TestCase): layer = ConfigLayer def test_enabled(self): - # By default, the testing configuration enables the archivers. + # By default, the testing configuration enables some archivers. archivers = {} for archiver in config.archivers: archivers[archiver.name] = archiver - self.assertTrue(archivers['prototype'].is_enabled) + self.assertFalse(archivers['prototype'].is_enabled) self.assertTrue(archivers['mail-archive'].is_enabled) self.assertTrue(archivers['mhonarc'].is_enabled) @@ -42,6 +42,6 @@ class TestArchivers(unittest.TestCase): archivers = {} for archiver in config.archivers: archivers[archiver.name] = archiver - self.assertTrue(archivers['prototype'].is_enabled) + self.assertFalse(archivers['prototype'].is_enabled) self.assertTrue(archivers['mail-archive'].is_enabled) self.assertFalse(archivers['mhonarc'].is_enabled) diff --git a/src/mailman/model/tests/test_mailinglist.py b/src/mailman/model/tests/test_mailinglist.py index c9aecc93b..0f37fa2f3 100644 --- a/src/mailman/model/tests/test_mailinglist.py +++ b/src/mailman/model/tests/test_mailinglist.py @@ -108,11 +108,11 @@ class TestListArchiver(unittest.TestCase): def test_get_archiver(self): # Use .get() to see if a mailing list has an archiver. - archiver = self._set.get('prototype') - self.assertEqual(archiver.name, 'prototype') + archiver = self._set.get('mhonarc') + self.assertEqual(archiver.name, 'mhonarc') self.assertTrue(archiver.is_enabled) self.assertEqual(archiver.mailing_list, self._mlist) - self.assertEqual(archiver.system_archiver.name, 'prototype') + self.assertEqual(archiver.system_archiver.name, 'mhonarc') def test_get_archiver_no_such(self): # Using .get() on a non-existing name returns None. @@ -124,15 +124,15 @@ class TestListArchiver(unittest.TestCase): # then the site-wide archiver gets disabled, so the list specific # archiver will also be disabled. archiver_set = IListArchiverSet(self._mlist) - archiver = archiver_set.get('prototype') + archiver = archiver_set.get('mhonarc') self.assertTrue(archiver.is_enabled) # Disable the site-wide archiver. - config.push('enable prototype', """\ - [archiver.prototype] + config.push('enable mhonarc', """\ + [archiver.mhonarc] enable: no """) self.assertFalse(archiver.is_enabled) - config.pop('enable prototype') + config.pop('enable mhonarc') class TestDisabledListArchiver(unittest.TestCase): diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index d83f70058..3bee23314 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -32,7 +32,7 @@ from mailman.interfaces.usermanager import IUserManager from mailman.model.mailinglist import AcceptableAlias from mailman.runners.digest import DigestRunner from mailman.testing.helpers import ( - call_api, configuration, get_queue_messages, make_testable_runner, + call_api, get_queue_messages, make_testable_runner, specialized_message_from_string as mfs) from mailman.testing.layers import RESTLayer from mailman.utilities.datetime import now as right_now -- cgit v1.3.1 From db0fa111a30a372adf690a567df74a776adc4bb3 Mon Sep 17 00:00:00 2001 From: Jan Luca Naumann Date: Thu, 3 Nov 2016 16:48:20 +0100 Subject: Fix sphinx-build for output formats "man" and "latex". The current version of conf.py use source "index" for the manpage and Latex-output. This source does not exist. This commit fixes the build by using the source "README". --- conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf.py b/conf.py index 5100c63dd..e28627fe6 100644 --- a/conf.py +++ b/conf.py @@ -182,7 +182,7 @@ htmlhelp_basename = 'GNUMailmandoc' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'GNUMailman.tex', u'GNU Mailman Documentation', + ('README', 'GNUMailman.tex', u'GNU Mailman Documentation', u'Barry Warsaw', 'manual'), ] @@ -215,7 +215,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'gnumailman', u'GNU Mailman Documentation', + ('README', 'gnumailman', u'GNU Mailman Documentation', [u'Barry Warsaw'], 1) ] -- cgit v1.3.1 From cecb66d21dbe523ae516e1c30038084190f284b1 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Fri, 2 Sep 2016 01:07:36 +0200 Subject: Transmit the moderation reason to hold_message() The `reason` attribute of `hold_message()` was always None. Serialize the moderation reasons list and pass it to the function. This allows the `reason` attribute in REST to actually contain the moderation reason. It was always blank before. --- src/mailman/chains/hold.py | 3 ++- src/mailman/chains/tests/test_hold.py | 8 ++++++++ src/mailman/docs/NEWS.rst | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py index f111aee3c..075191704 100644 --- a/src/mailman/chains/hold.py +++ b/src/mailman/chains/hold.py @@ -142,8 +142,9 @@ class HoldChain(TerminalChainBase): rule_misses = msgdata.get('rule_misses') if rule_misses: msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses) + reasons = msgdata.get('moderation_reasons', ['N/A']) # Hold the message by adding it to the list's request database. - request_id = hold_message(mlist, msg, msgdata, None) + request_id = hold_message(mlist, msg, msgdata, SEMISPACE.join(reasons)) # Calculate a confirmation token to send to the author of the # message. pendable = HeldMessagePendable(id=request_id) diff --git a/src/mailman/chains/tests/test_hold.py b/src/mailman/chains/tests/test_hold.py index 13dd1b40e..fc8b8fd3b 100644 --- a/src/mailman/chains/tests/test_hold.py +++ b/src/mailman/chains/tests/test_hold.py @@ -26,6 +26,7 @@ from mailman.core.chains import process as process_chain from mailman.interfaces.autorespond import IAutoResponseSet, Response from mailman.interfaces.member import MemberRole from mailman.interfaces.messages import IMessageStore +from mailman.interfaces.requests import IListRequests, RequestType from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import ( LogFileMark, configuration, get_queue_messages, set_preferred, @@ -130,6 +131,13 @@ A message body. logged = logfile.read() self.assertIn('TEST-REASON-1', logged) self.assertIn('TEST-REASON-2', logged) + # Check the reason passed to hold_message(). + requests = IListRequests(self._mlist) + self.assertEqual(requests.count_of(RequestType.held_message), 1) + request = requests.of_type(RequestType.held_message)[0] + key, data = requests.get_request(request.id) + self.assertEqual( + data.get('_mod_reason'), 'TEST-REASON-1; TEST-REASON-2') def test_hold_chain_charset(self): # Issue #144 - UnicodeEncodeError in the hold chain. diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 80cadd1b7..db65e9c69 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -99,6 +99,8 @@ Bugs Bompard. (Closes: #259) * Messages sent to the list's moderators now include the actual recipient addresses. Given by Tom Briles. (Closes: #68) + * Transmit the moderation reason and expose it in the REST API as the + ``reason`` attribute. Given by Aurélien Bompard. Configuration ------------- -- cgit v1.3.1 From 7142a0ea33e800744036219998f36c2adf2f84e0 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 25 Nov 2016 11:28:36 -0500 Subject: Minor cleanup and test added. --- src/mailman/chains/hold.py | 2 +- src/mailman/chains/tests/test_hold.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py index 075191704..42fed66a6 100644 --- a/src/mailman/chains/hold.py +++ b/src/mailman/chains/hold.py @@ -142,7 +142,7 @@ class HoldChain(TerminalChainBase): rule_misses = msgdata.get('rule_misses') if rule_misses: msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses) - reasons = msgdata.get('moderation_reasons', ['N/A']) + reasons = msgdata.get('moderation_reasons', ['n/a']) # Hold the message by adding it to the list's request database. request_id = hold_message(mlist, msg, msgdata, SEMISPACE.join(reasons)) # Calculate a confirmation token to send to the author of the diff --git a/src/mailman/chains/tests/test_hold.py b/src/mailman/chains/tests/test_hold.py index fc8b8fd3b..6686c4777 100644 --- a/src/mailman/chains/tests/test_hold.py +++ b/src/mailman/chains/tests/test_hold.py @@ -139,6 +139,24 @@ A message body. self.assertEqual( data.get('_mod_reason'), 'TEST-REASON-1; TEST-REASON-2') + def test_hold_chain_no_reasons_given(self): + msg = mfs("""\ +From: anne@example.com +To: test@example.com +Subject: A message +Message-ID: +MIME-Version: 1.0 + +A message body. +""") + process_chain(self._mlist, msg, {}, start_chain='hold') + # No reason was given, so a default is used. + requests = IListRequests(self._mlist) + self.assertEqual(requests.count_of(RequestType.held_message), 1) + request = requests.of_type(RequestType.held_message)[0] + key, data = requests.get_request(request.id) + self.assertEqual(data.get('_mod_reason'), 'n/a') + def test_hold_chain_charset(self): # Issue #144 - UnicodeEncodeError in the hold chain. self._mlist.admin_immed_notify = True -- cgit v1.3.1 From 5a02cc713f9897cd9ec0df48dd7718f019a6e510 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Fri, 14 Oct 2016 12:29:57 -0700 Subject: Return 'defective message' for a bad held message If a message can't be parsed by Python due to bad structure, don't raise an error but return a generic 'this message is defective' string instead. --- src/mailman/rest/post_moderation.py | 8 +++++++- src/mailman/rest/tests/data/bad_email | 8 ++++++++ src/mailman/rest/tests/test_moderation.py | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/mailman/rest/tests/data/bad_email diff --git a/src/mailman/rest/post_moderation.py b/src/mailman/rest/post_moderation.py index fc38af359..ee31e8694 100644 --- a/src/mailman/rest/post_moderation.py +++ b/src/mailman/rest/post_moderation.py @@ -71,7 +71,13 @@ class _HeldMessageBase(_ModerationBase): # resource. XXX See LP: #967954 key = resource.pop('key') msg = getUtility(IMessageStore).get_message_by_id(key) - resource['msg'] = msg.as_string() + try: + resource['msg'] = msg.as_string() + except KeyError: + # If the message can't be parsed, return a generic message instead + # of raising an error. + # See http://bugs.python.org/issue27321 and #256 + resource['msg'] = 'this message is defective' # Some of the _mod_* keys we want to rename and place into the JSON # resource. Others we can drop. Since we're mutating the dictionary, # we need to make a copy of the keys. When you port this to Python 3, diff --git a/src/mailman/rest/tests/data/bad_email b/src/mailman/rest/tests/data/bad_email new file mode 100644 index 000000000..83f9337dd --- /dev/null +++ b/src/mailman/rest/tests/data/bad_email @@ -0,0 +1,8 @@ +To: +Subject: =?koi8-r?B?UF9AX/NfQ1/5X+xfS1/p?= +From: =?koi8-r?B?8sXL0sXB1MnXzs/FIMHHxc7U09TXzw==?= +Content-Type: text/plain; charset=koi8-r +Message-Id: <20160614102505.9OFQ19L1C> + +þôï ôáëïå òåëìáíîáñ òáóóùìëá? +ëÁËÏÊ ÏÔËÌÉË ÖÄÁÔØ ÏÔ ÜÔÏÇÏ ÍÅÔÏÄÁ ÐÏÉÓËÁ ËÌÉÅÎÔÏ×? diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py index e0c3f1ccf..03d52dfc4 100644 --- a/src/mailman/rest/tests/test_moderation.py +++ b/src/mailman/rest/tests/test_moderation.py @@ -17,8 +17,10 @@ """REST moderation tests.""" +import os 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 @@ -206,6 +208,23 @@ 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. + pwd = os.path.dirname(os.path.realpath(__file__)) + email_path = os.path.join(pwd, 'data/bad_email') + msg = message_from_binary_file(open(email_path, 'rb')) + msg.sender = 'bogussender@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(): -- cgit v1.3.1 From 1f4919ab99bc6ca15553e2e4f569313b91b4a752 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Fri, 21 Oct 2016 23:54:56 -0700 Subject: Rename test email and use resource filename instead of __file__. --- src/mailman/rest/tests/data/__init__.py | 0 src/mailman/rest/tests/data/bad_email | 8 -------- src/mailman/rest/tests/data/bad_email.eml | 8 ++++++++ src/mailman/rest/tests/test_moderation.py | 10 ++++++---- 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 src/mailman/rest/tests/data/__init__.py delete mode 100644 src/mailman/rest/tests/data/bad_email create mode 100644 src/mailman/rest/tests/data/bad_email.eml diff --git a/src/mailman/rest/tests/data/__init__.py b/src/mailman/rest/tests/data/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/mailman/rest/tests/data/bad_email b/src/mailman/rest/tests/data/bad_email deleted file mode 100644 index 83f9337dd..000000000 --- a/src/mailman/rest/tests/data/bad_email +++ /dev/null @@ -1,8 +0,0 @@ -To: -Subject: =?koi8-r?B?UF9AX/NfQ1/5X+xfS1/p?= -From: =?koi8-r?B?8sXL0sXB1MnXzs/FIMHHxc7U09TXzw==?= -Content-Type: text/plain; charset=koi8-r -Message-Id: <20160614102505.9OFQ19L1C> - -þôï ôáëïå òåëìáíîáñ òáóóùìëá? -ëÁËÏÊ ÏÔËÌÉË ÖÄÁÔØ ÏÔ ÜÔÏÇÏ ÍÅÔÏÄÁ ÐÏÉÓËÁ ËÌÉÅÎÔÏ×? diff --git a/src/mailman/rest/tests/data/bad_email.eml b/src/mailman/rest/tests/data/bad_email.eml new file mode 100644 index 000000000..83f9337dd --- /dev/null +++ b/src/mailman/rest/tests/data/bad_email.eml @@ -0,0 +1,8 @@ +To: +Subject: =?koi8-r?B?UF9AX/NfQ1/5X+xfS1/p?= +From: =?koi8-r?B?8sXL0sXB1MnXzs/FIMHHxc7U09TXzw==?= +Content-Type: text/plain; charset=koi8-r +Message-Id: <20160614102505.9OFQ19L1C> + +þôï ôáëïå òåëìáíîáñ òáóóùìëá? +ëÁËÏÊ ÏÔËÌÉË ÖÄÁÔØ ÏÔ ÜÔÏÇÏ ÍÅÔÏÄÁ ÐÏÉÓËÁ ËÌÉÅÎÔÏ×? diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py index 03d52dfc4..628b79e52 100644 --- a/src/mailman/rest/tests/test_moderation.py +++ b/src/mailman/rest/tests/test_moderation.py @@ -33,6 +33,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 @@ -210,10 +211,11 @@ class TestSubscriptionModeration(unittest.TestCase): def test_view_malformed_held_message(self): # Opening a bad (i.e. bad structure) email and holding it. - pwd = os.path.dirname(os.path.realpath(__file__)) - email_path = os.path.join(pwd, 'data/bad_email') - msg = message_from_binary_file(open(email_path, 'rb')) - msg.sender = 'bogussender@example.com' + email_path = resource_filename('mailman.rest.tests.data', + 'bad_email.eml') + with open(email_path, 'rb') as f: + msg = message_from_binary_file(f) + msg.sender = 'aperson@example.com' with transaction(): hold_message(self._mlist, msg) # Now trying to access held messages from REST API should not give -- cgit v1.3.1 From 17ec368191f4e2c80fbead954511bb5a251dfe45 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 25 Nov 2016 11:54:10 -0500 Subject: Add NEWS and a little bit of cleanup. --- src/mailman/docs/NEWS.rst | 2 ++ src/mailman/rest/post_moderation.py | 5 +++-- src/mailman/rest/tests/test_moderation.py | 10 +++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index db65e9c69..27f3ea5eb 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -101,6 +101,8 @@ Bugs addresses. Given by Tom Briles. (Closes: #68) * Transmit the moderation reason and expose it in the REST API as the ``reason`` attribute. Given by Aurélien Bompard. + * Don't return a 500 error from the REST API when trying to handle a held + message with defective content. Given by Abhilash Raj. (Closes: #256) Configuration ------------- diff --git a/src/mailman/rest/post_moderation.py b/src/mailman/rest/post_moderation.py index ee31e8694..33a32de20 100644 --- a/src/mailman/rest/post_moderation.py +++ b/src/mailman/rest/post_moderation.py @@ -76,8 +76,9 @@ class _HeldMessageBase(_ModerationBase): except KeyError: # If the message can't be parsed, return a generic message instead # of raising an error. - # See http://bugs.python.org/issue27321 and #256 - resource['msg'] = 'this message is defective' + # + # See http://bugs.python.org/issue27321 and GL#256 + resource['msg'] = 'This message is defective' # Some of the _mod_* keys we want to rename and place into the JSON # resource. Others we can drop. Since we're mutating the dictionary, # we need to make a copy of the keys. When you port this to Python 3, diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py index 628b79e52..7ac23da21 100644 --- a/src/mailman/rest/tests/test_moderation.py +++ b/src/mailman/rest/tests/test_moderation.py @@ -211,10 +211,10 @@ class TestSubscriptionModeration(unittest.TestCase): 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 f: - msg = message_from_binary_file(f) + 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) @@ -225,7 +225,7 @@ class TestSubscriptionModeration(unittest.TestCase): self.assertEqual(response.status, 200) self.assertEqual(len(content['entries']), 1) self.assertEqual(content['entries'][0]['msg'], - 'this message is defective') + 'This message is defective') def test_individual_request(self): # We can view an individual request. -- cgit v1.3.1 From b4c663e717f702f0ffe8a3bc9207b2eda635a32d Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 25 Nov 2016 13:09:52 -0500 Subject: Fix QA. --- src/mailman/rest/tests/test_moderation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py index 7ac23da21..21129207c 100644 --- a/src/mailman/rest/tests/test_moderation.py +++ b/src/mailman/rest/tests/test_moderation.py @@ -17,7 +17,6 @@ """REST moderation tests.""" -import os import unittest from email import message_from_binary_file -- cgit v1.3.1 From 86162ef47bbf9ab71faceed9eaa656ebb8e1ec63 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Sat, 26 Nov 2016 00:06:55 -0500 Subject: NEWS. --- src/mailman/docs/NEWS.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 27f3ea5eb..26d7433c3 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -245,6 +245,8 @@ REST Aurélien Bompard. (Closes #284) * Query parameters now allow you to filter mailing lists by the ``advertised`` boolean parameter. Given by Aurélien Bompard. + * Only the system-enabled archivers are returned in the REST API. Given by + Aurélien Bompard. Other ----- -- cgit v1.3.1