diff options
author | 2022-06-06 18:53:52 -0700 | |
---|---|---|
committer | 2022-06-06 20:18:52 -0700 | |
commit | c7a2a24e4740bb248bd73f03d8d11067c48cde9e (patch) | |
tree | 6cb35d7a88c1c9d7895a9364956c76f479a89882 | |
parent | Fix NsJail patch for API tests (diff) |
Test NsJail args are set and used when passed to __init__
-rw-r--r-- | tests/test_nsjail.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py index dc30dfa..745c44f 100644 --- a/tests/test_nsjail.py +++ b/tests/test_nsjail.py @@ -1,6 +1,8 @@ import io import logging +import shutil import sys +import tempfile import unittest import unittest.mock from textwrap import dedent @@ -280,3 +282,38 @@ class NsJailTests(unittest.TestCase): self.assertEqual(result.returncode, 0) self.assertEqual(result.args[-3:-1], args) + + +class NsJailArgsTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls._temp_dir = tempfile.TemporaryDirectory() + cls.addClassCleanup(cls._temp_dir.cleanup) + + cls.nsjail_path = shutil.copy2("/usr/sbin/nsjail", cls._temp_dir.name) + cls.config_path = shutil.copy2("./config/snekbox.cfg", cls._temp_dir.name) + cls.max_output_size = 1_234_567 + cls.read_chunk_size = 12_345 + + cls.nsjail = NsJail( + cls.nsjail_path, cls.config_path, cls.max_output_size, cls.read_chunk_size + ) + + logging.getLogger("snekbox.nsjail").setLevel(logging.WARNING) + + def test_nsjail_path(self): + result = self.nsjail.python3("") + + self.assertEqual(result.args[0], self.nsjail_path) + + def test_config_path(self): + result = self.nsjail.python3("") + + i = result.args.index("--config") + 1 + self.assertEqual(result.args[i], self.config_path) + + def test_init_args(self): + self.assertEqual(self.nsjail.nsjail_path, self.nsjail_path) + self.assertEqual(self.nsjail.config_path, self.config_path) + self.assertEqual(self.nsjail.max_output_size, self.max_output_size) + self.assertEqual(self.nsjail.read_chunk_size, self.read_chunk_size) |