diff options
author | 2021-04-08 15:09:46 -0700 | |
---|---|---|
committer | 2021-04-08 15:09:46 -0700 | |
commit | 93f99fb909a60b2bcc12c4967adf767c0a82c804 (patch) | |
tree | 3df6941de7dd075c1a44c2a84d1f6242f8ad60fd /tests/test_nsjail.py | |
parent | Bump urllib3 from 1.26.3 to 1.26.4 (diff) | |
parent | Clarify documentation of None return code (diff) |
Merge PR #100 - avoid decoding of invalid Unicode output
Use PYTHONIOENCODING to enable utf-8 stdout for the nsjail pipe,
and handle the potential case where this is bypassable.
Diffstat (limited to 'tests/test_nsjail.py')
-rw-r--r-- | tests/test_nsjail.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py index 4d4676b..46193b2 100644 --- a/tests/test_nsjail.py +++ b/tests/test_nsjail.py @@ -100,6 +100,23 @@ class NsJailTests(unittest.TestCase): self.assertEqual(result.stdout, "ValueError: embedded null byte") self.assertEqual(result.stderr, None) + def test_print_bad_unicode_encode_error(self): + result = self.nsjail.python3("print(chr(56550))") + self.assertEqual(result.returncode, 1) + self.assertIn("UnicodeEncodeError", result.stdout) + self.assertEqual(result.stderr, None) + + def test_unicode_env_erase_escape_fails(self): + result = self.nsjail.python3(dedent(""" + import os + import sys + os.unsetenv('PYTHONIOENCODING') + os.execl(sys.executable, 'python', '-c', 'print(chr(56550))') + """).strip()) + self.assertEqual(result.returncode, None) + self.assertEqual(result.stdout, "UnicodeDecodeError: invalid Unicode in output pipe") + self.assertEqual(result.stderr, None) + @unittest.mock.patch("snekbox.nsjail.DEBUG", new=False) def test_log_parser(self): log_lines = ( |