Barry Warsaw pushed to branch master at mailman / Mailman
Commits: 23cada77 by Barry Warsaw at 2015-08-17T21:46:13Z The MHonArc archiver must set stdin=PIPE when calling the subprocess. Given by Walter Doekes. - - - - - 5 changed files: - src/mailman/archiving/mhonarc.py - + src/mailman/archiving/tests/fake_mhonarc.py - + src/mailman/archiving/tests/test_mhonarc.py - src/mailman/archiving/tests/test_prototype.py - src/mailman/docs/NEWS.rst Changes: ===================================== src/mailman/archiving/mhonarc.py ===================================== --- a/src/mailman/archiving/mhonarc.py +++ b/src/mailman/archiving/mhonarc.py @@ -23,12 +23,12 @@ __all__ = [ import logging -import subprocess from mailman.config import config from mailman.config.config import external_configuration from mailman.interfaces.archiver import IArchiver from mailman.utilities.string import expand +from subprocess import PIPE, Popen from urllib.parse import urljoin from zope.interface import implementer @@ -82,8 +82,9 @@ class MHonArc: substitutions = config.__dict__.copy() substitutions['listname'] = mlist.fqdn_listname command = expand(self.command, substitutions) - proc = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + proc = Popen( + command, + stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True) stdout, stderr = proc.communicate(msg.as_string()) if proc.returncode != 0: ===================================== src/mailman/archiving/tests/fake_mhonarc.py ===================================== --- /dev/null +++ b/src/mailman/archiving/tests/fake_mhonarc.py @@ -0,0 +1,35 @@ +# Copyright (C) 2015 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""A fake MHonArc process that reads stdin and writes stdout.""" + +import sys + +from email import message_from_string + + +def main(): + text = sys.stdin.read() + msg = message_from_string(text) + output_file = sys.argv[1] + with open(output_file, 'w', encoding='utf-8') as fp: + print(msg['message-id'], file=fp) + print(msg['message-id-hash'], file=fp) + + +if __name__ == '__main__': + main() ===================================== src/mailman/archiving/tests/test_mhonarc.py ===================================== --- /dev/null +++ b/src/mailman/archiving/tests/test_mhonarc.py @@ -0,0 +1,89 @@ +# Copyright (C) 2015 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Test the MHonArc archiver.""" + +__all__ = [ + 'TestMhonarc', + ] + + +import os +import sys +import shutil +import tempfile +import unittest + +from mailman.archiving.mhonarc import MHonArc +from mailman.app.lifecycle import create_list +from mailman.database.transaction import transaction +from mailman.testing.helpers import ( + configuration, specialized_message_from_string as mfs) +from mailman.testing.layers import ConfigLayer +from pkg_resources import resource_filename + + +class TestMhonarc(unittest.TestCase): + """Test the MHonArc archiver.""" + + layer = ConfigLayer + + def setUp(self): + # Create a fake mailing list and message object. + self._msg = mfs("""\ +To: t...@example.com +From: a...@example.com +Subject: Testing the test list +Message-ID: <ant> +Message-ID-Hash: MS6QLWERIJLGCRF44J7USBFDELMNT2BW + +Tests are better than no tests +but the water deserves to be swum. +""") + with transaction(): + self._mlist = create_list('t...@example.com') + tempdir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tempdir) + # Here's the command to execute our fake MHonArc process. + shutil.copy( + resource_filename('mailman.archiving.tests', 'fake_mhonarc.py'), + tempdir) + self._output_file = os.path.join(tempdir, 'output.txt') + command = '{} {} {}'.format( + sys.executable, + os.path.join(tempdir, 'fake_mhonarc.py'), + self._output_file) + # Write an external configuration file which points the command at our + # fake MHonArc process. + self._cfg = os.path.join(tempdir, 'mhonarc.cfg') + with open(self._cfg, 'w', encoding='utf-8') as fp: + print("""\ +[general] +base_url: http://$hostname/archives/$fqdn_listname +command: {command} +""".format(command=command), file=fp) + + def test_mhonarc(self): + # The archiver properly sends stdin to the subprocess. + with configuration('archiver.mhonarc', + configuration=self._cfg, + enable='yes'): + MHonArc().archive_message(self._mlist, self._msg) + with open(self._output_file, 'r', encoding='utf-8') as fp: + results = fp.read().splitlines() + self.assertEqual(results[0], '<ant>') + self.assertEqual(results[1], 'MS6QLWERIJLGCRF44J7USBFDELMNT2BW') ===================================== src/mailman/archiving/tests/test_prototype.py ===================================== --- a/src/mailman/archiving/tests/test_prototype.py +++ b/src/mailman/archiving/tests/test_prototype.py @@ -47,7 +47,7 @@ class TestPrototypeArchiver(unittest.TestCase): layer = ConfigLayer def setUp(self): - # Create a fake mailing list and message object + # Create a fake mailing list and message object. self._msg = mfs("""\ To: t...@example.com From: a...@example.com ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -28,6 +28,8 @@ Bugs Given by Abhilash Raj. (Closes #115) * `mailman` command with no subcommand now prints the help text. Given by Abhilash Raj. (Closes #137) + * The MHonArc archiver must set stdin=PIPE when calling the subprocess. + Given by Walter Doekes. Configuration ------------- View it on GitLab: https://gitlab.com/mailman/mailman/commit/23cada770294a0efb0fe7d2d52a7c367c87d66ef
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org