Let vigil run without sudo.
Now using user namespaces which allow unprivileged users to create the sandbox.
This commit is contained in:
parent
5a9b29bb84
commit
60fe921881
8 changed files with 100 additions and 94 deletions
|
|
@ -4,40 +4,39 @@
|
|||
# Licensed under the Artistic License 2.0.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import sandbox_fs
|
||||
|
||||
tempfile.tempdir = os.getcwd() # This tests fails when using /tmp.
|
||||
|
||||
|
||||
def _get_test_paths(temp_dir):
|
||||
a_dir = os.path.join(temp_dir, "a")
|
||||
foo_path = os.path.join(a_dir, "foo")
|
||||
bar_path = os.path.join(temp_dir, "bar")
|
||||
return a_dir, foo_path, bar_path
|
||||
|
||||
|
||||
class SandboxFilesystemTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.temp_dir = tempfile.mkdtemp()
|
||||
self.sandbox = sandbox_fs.SandboxFs(self.temp_dir)
|
||||
self.sandbox.mount()
|
||||
|
||||
def tearDown(self):
|
||||
self.sandbox.umount()
|
||||
os.rmdir(self.temp_dir)
|
||||
|
||||
def test_sandbox_minimal(self):
|
||||
foo_upper_path = os.path.join(self.sandbox.mount_point, "foo")
|
||||
subprocess.check_call(["sudo", "touch", foo_upper_path])
|
||||
self.assertTrue(os.path.exists(foo_upper_path))
|
||||
foo_lower_path = os.path.join(self.sandbox.overlay_mounts[0].lower_dir,
|
||||
"foo")
|
||||
self.assertFalse(os.path.exists(foo_lower_path))
|
||||
|
||||
def test_home_directory_exists_in_the_sandbox(self):
|
||||
home_directory = (self.sandbox.mount_point + os.environ["HOME"])
|
||||
self.assertTrue(os.path.exists(home_directory))
|
||||
|
||||
def test_run_a_command_in_the_sandbox(self):
|
||||
stdout = subprocess.check_output(self.sandbox.command(["pwd"]))
|
||||
self.assertEqual(stdout.strip().decode("utf-8"), os.environ["PWD"])
|
||||
def test_sandbox(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
a_dir, foo_path, bar_path = _get_test_paths(temp_dir)
|
||||
os.mkdir(a_dir)
|
||||
subprocess.check_call(["./sandbox_fs", a_dir, "--", __file__,
|
||||
temp_dir])
|
||||
self.assertTrue(os.path.exists(foo_path))
|
||||
self.assertFalse(os.path.exists(bar_path))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
if len(sys.argv) > 1:
|
||||
temp_dir = sys.argv[1]
|
||||
a_dir, foo_path, bar_path = _get_test_paths(temp_dir)
|
||||
subprocess.check_call(["touch", foo_path])
|
||||
subprocess.check_call(["touch", bar_path])
|
||||
else:
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue