eris/sandbox_fs_test.py
Andrew Hamilton 60fe921881 Let vigil run without sudo.
Now using user namespaces which allow unprivileged users to create
the sandbox.
2016-11-09 01:30:40 +01:00

42 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright (C) 2016 Andrew Hamilton. All rights reserved.
# Licensed under the Artistic License 2.0.
import os
import sys
import subprocess
import tempfile
import unittest
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 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__":
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()