diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2019-03-18 09:39:28 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2019-03-18 09:39:28 -0400 |
commit | a191b8f35eadb567d4bbb8d8826fc3702e99538b (patch) | |
tree | 3fa400823c9415175d0c8fd1bf6500a8ed7690cf /buildscripts/tests | |
parent | 6af32a3527aee45652a7765bff1d8222efe97756 (diff) | |
download | mongo-a191b8f35eadb567d4bbb8d8826fc3702e99538b.tar.gz |
SERVER-40180 Escape null bytes in output of subprocesses.
Diffstat (limited to 'buildscripts/tests')
-rw-r--r-- | buildscripts/tests/resmokelib/core/__init__.py | 1 | ||||
-rw-r--r-- | buildscripts/tests/resmokelib/core/test_pipe.py | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/buildscripts/tests/resmokelib/core/__init__.py b/buildscripts/tests/resmokelib/core/__init__.py new file mode 100644 index 00000000000..4b7a2bb941b --- /dev/null +++ b/buildscripts/tests/resmokelib/core/__init__.py @@ -0,0 +1 @@ +"""Empty.""" diff --git a/buildscripts/tests/resmokelib/core/test_pipe.py b/buildscripts/tests/resmokelib/core/test_pipe.py new file mode 100644 index 00000000000..69b0e3fb576 --- /dev/null +++ b/buildscripts/tests/resmokelib/core/test_pipe.py @@ -0,0 +1,45 @@ +"""Unit tests for buildscripts/resmokelib/core/pipe.py.""" + +from __future__ import absolute_import + +import io +import logging +import unittest + +import mock + +from buildscripts.resmokelib.core import pipe as _pipe + +# pylint: disable=missing-docstring + + +class TestLoggerPipe(unittest.TestCase): + LOG_LEVEL = logging.DEBUG + + @classmethod + def _get_log_calls(cls, output): + logger = logging.Logger("for_testing") + logger.log = mock.MagicMock() + + logger_pipe = _pipe.LoggerPipe(logger=logger, level=cls.LOG_LEVEL, + pipe_out=io.BytesIO(output)) + logger_pipe.wait_until_started() + logger_pipe.wait_until_finished() + + return logger.log.call_args_list + + def test_strips_trailing_whitespace(self): + calls = self._get_log_calls(b" a ") + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u" a")]) + + def test_strips_trailing_newlines(self): + calls = self._get_log_calls(b"a\r\n") + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u"a")]) + + def test_handles_invalid_utf8(self): + calls = self._get_log_calls(b"a\x80b") + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u"a\ufffdb")]) + + def test_escapes_null_bytes(self): + calls = self._get_log_calls(b"a\0b") + self.assertEqual(calls, [mock.call(self.LOG_LEVEL, u"a\\0b")]) |