summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2016-09-29 18:28:22 +0100
committerTiago Gomes <tiago.gomes@codethink.co.uk>2016-10-06 12:05:56 +0100
commitf66ce361bbdc6523e729806bd304db0a558e5928 (patch)
tree61122c6fd25fa9344e72389ecd90d276951e1038
parent50ea68400d3795ff0b970074509dac90b622ade7 (diff)
downloadsandboxlib-f66ce361bbdc6523e729806bd304db0a558e5928.tar.gz
Fix unit tests
- Fix missing source argument in the 'mount' command. - Add missing datapath assigment to ensure that file is created in the expected location. - Remove unnecessary extra_mounts that were causing the test files in /data to not be accessible inside the sandbox as that directory was being overlapped with a mount bind. Also, mention that the C library static libraries are required to be installed for running the tests.
-rw-r--r--HACKING.rst3
-rw-r--r--sandboxlib/chroot.py9
-rw-r--r--sandboxlib/linux_user_chroot.py2
-rw-r--r--tests/test_all.py14
4 files changed, 15 insertions, 13 deletions
diff --git a/HACKING.rst b/HACKING.rst
index 9144885..e771db0 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -40,6 +40,9 @@ Running the automated test suite
Use ``tox``. You'll need 'py.test', 'tox' and their dependencies available.
+You will also need to have installed the C library static libraries for
+-static linking (glibc-static package in Fedora).
+
Note that a lot of the tests will be skipped or fail if you don't run as
'root', because some of the sandboxing backends only work when you are the
'root' user. The test suite could handle this better than it does.
diff --git a/sandboxlib/chroot.py b/sandboxlib/chroot.py
index c0d13f8..b7a07ad 100644
--- a/sandboxlib/chroot.py
+++ b/sandboxlib/chroot.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015 Codethink Limited
+# Copyright (C) 2015-2016 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -101,7 +101,10 @@ def mount(source, path, mount_type, mount_options):
# We depend on the host system's 'mount' program here, which is a
# little sad. It's possible to call the libc's mount() function
# directly from Python using the 'ctypes' library, and perhaps we
- # should do that instead.
+ # should do that instead. The 'mount' requires that a source is
+ # given even for the special filesystems (e.g. proc, tmpfs), so we
+ # use the mount type as the source if the latter is not explicitly
+ # given.
def is_none(value):
return value in (None, 'none', '')
@@ -112,6 +115,8 @@ def mount(source, path, mount_type, mount_options):
argv.extend(('-o', mount_options))
if not is_none(source):
argv.append(source)
+ else:
+ argv.append(mount_type)
argv.append(path)
exit, out, err = sandboxlib._run_command(
diff --git a/sandboxlib/linux_user_chroot.py b/sandboxlib/linux_user_chroot.py
index 979d5d5..cab5344 100644
--- a/sandboxlib/linux_user_chroot.py
+++ b/sandboxlib/linux_user_chroot.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015 Codethink Limited
+# Copyright (C) 2015-2016 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff --git a/tests/test_all.py b/tests/test_all.py
index eed2f79..9270607 100644
--- a/tests/test_all.py
+++ b/tests/test_all.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015 Codethink Limited
+# Copyright (C) 2015-2016 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -114,7 +114,7 @@ class TestWriteablePaths(object):
bin_path.join('test-file-is-writable').chmod(0o755)
data_path = sandbox_path.mkdir('data')
- data_path.mkdir('1')
+ data_path = data_path.mkdir('1')
data_path.join('canary').write("Please don't overwrite me.")
return sandbox_path
@@ -169,10 +169,7 @@ class TestWriteablePaths(object):
exit, out, err = sandboxlib_executor.run_sandbox(
['test-file-is-writable', '/data/1/canary'],
filesystem_root=str(writable_paths_test_sandbox),
- filesystem_writable_paths='none',
- extra_mounts=[
- (None, '/data', 'tmpfs')
- ])
+ filesystem_writable_paths='none')
assert err.decode('unicode-escape') == ''
assert out.decode('unicode-escape') == \
@@ -187,10 +184,7 @@ class TestWriteablePaths(object):
exit, out, err = sandboxlib_executor.run_sandbox(
['test-file-is-writable', '/data/1/canary'],
filesystem_root=str(writable_paths_test_sandbox),
- filesystem_writable_paths=['/data'],
- extra_mounts=[
- (None, '/data', 'tmpfs')
- ])
+ filesystem_writable_paths=['/data'])
assert err.decode('unicode-escape') == ''
assert out.decode('unicode-escape') == \