]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test for BindPaths= and BindReadOnlyPaths=
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 12 Oct 2017 04:25:06 +0000 (13:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 12 Oct 2017 04:25:06 +0000 (13:25 +0900)
Follow-up for a8cabc612b16834260831a8163ae4b479b5c33a5.

src/test/test-execute.c
test/meson.build
test/test-execute/exec-bind-paths.service [new file with mode: 0644]

index 486c7e1226a1ea5b62b03ee650a45775141375f2..7e36900ce82a3c54bfdb39d00f3bd467da691fa3 100644 (file)
@@ -100,6 +100,16 @@ static void test(Manager *m, const char *unit_name, int status_expected, int cod
         check(m, unit, status_expected, code_expected);
 }
 
+static void test_exec_bind_paths(Manager *m) {
+        assert_se(mkdir_p("/tmp/test-exec_bind_paths", 0755) >= 0);
+        assert_se(mkdir_p("/tmp/test-exec_bind_readonly_paths", 0755) >= 0);
+
+        test(m, "exec-bind-paths.service", 0, CLD_EXITED);
+
+        (void) rm_rf("/tmp/test-exec_bind_paths", REMOVE_ROOT|REMOVE_PHYSICAL);
+        (void) rm_rf("/tmp/test-exec_bind_readonly_paths", REMOVE_ROOT|REMOVE_PHYSICAL);
+}
+
 static void test_exec_workingdirectory(Manager *m) {
         assert_se(mkdir_p("/tmp/test-exec_workingdirectory", 0755) >= 0);
 
@@ -483,6 +493,7 @@ static int run_tests(UnitFileScope scope, const test_function_t *tests) {
 
 int main(int argc, char *argv[]) {
         static const test_function_t user_tests[] = {
+                test_exec_bind_paths,
                 test_exec_workingdirectory,
                 test_exec_personality,
                 test_exec_ignoresigpipe,
index c2df7ec226bb8bf8c9f8c209c3074120284e5365..2b523da725092bee76649657bc01e93eb127aadf 100644 (file)
@@ -46,6 +46,7 @@ test_data_files = '''
         test-path/path-makedirectory.path
         test-path/path-modified.path
         test-path/path-unit.path
+        test-execute/exec-bind-paths.service
         test-execute/exec-environment-empty.service
         test-execute/exec-environment-multiple.service
         test-execute/exec-environment.service
diff --git a/test/test-execute/exec-bind-paths.service b/test/test-execute/exec-bind-paths.service
new file mode 100644 (file)
index 0000000..e6584c8
--- /dev/null
@@ -0,0 +1,14 @@
+[Service]
+Type=oneshot
+# Create a file in /tmp/test-exec_bind_paths
+ExecStart=/bin/sh -c 'touch /tmp/test-exec_bind_paths/thisisasimpletest'
+# Then, the file can be access through /tmp
+ExecStart=/bin/sh -c 'test -f /tmp/thisisasimpletest'
+# Also, through /tmp/test-exec_bind_readonly_paths
+ExecStart=/bin/sh -c 'test -f /tmp/test-exec_bind_readonly_paths/thisisasimpletest'
+# The file cannot modify through /tmp/test-exec_bind_readonly_paths
+ExecStart=/bin/sh -x -c '! touch /tmp/test-exec_bind_readonly_paths/thisisasimpletest'
+# Cleanup
+ExecStart=/bin/sh -c 'rm /tmp/thisisasimpletest'
+BindPaths=/tmp:/tmp/test-exec_bind_paths
+BindReadOnlyPaths=/tmp:/tmp/test-exec_bind_readonly_paths