From e4c01fe6afd304aba2de8168147578d1be6e402a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 2 Oct 2019 00:22:58 +0900 Subject: [PATCH] test: add test cases for RuntimeDirectoryPreserve=yes --- src/test/test-execute.c | 4 ++++ .../exec-dynamicuser-runtimedirectory1.service | 11 +++++++++++ .../exec-dynamicuser-runtimedirectory2.service | 12 ++++++++++++ .../exec-dynamicuser-runtimedirectory3.service | 11 +++++++++++ 4 files changed, 38 insertions(+) create mode 100644 test/test-execute/exec-dynamicuser-runtimedirectory1.service create mode 100644 test/test-execute/exec-dynamicuser-runtimedirectory2.service create mode 100644 test/test-execute/exec-dynamicuser-runtimedirectory3.service diff --git a/src/test/test-execute.c b/src/test/test-execute.c index f10e32b5b9..79ad8aaf20 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -595,6 +595,10 @@ static void test_exec_dynamicuser(Manager *m) { (void) rm_rf("/var/lib/test-dynamicuser-migrate2", REMOVE_ROOT|REMOVE_PHYSICAL); (void) rm_rf("/var/lib/private/test-dynamicuser-migrate", REMOVE_ROOT|REMOVE_PHYSICAL); (void) rm_rf("/var/lib/private/test-dynamicuser-migrate2", REMOVE_ROOT|REMOVE_PHYSICAL); + + test(__func__, m, "exec-dynamicuser-runtimedirectory1.service", can_unshare ? 0 : EXIT_NAMESPACE, CLD_EXITED); + test(__func__, m, "exec-dynamicuser-runtimedirectory2.service", can_unshare ? 0 : EXIT_NAMESPACE, CLD_EXITED); + test(__func__, m, "exec-dynamicuser-runtimedirectory3.service", can_unshare ? 0 : EXIT_NAMESPACE, CLD_EXITED); } static void test_exec_environment(Manager *m) { diff --git a/test/test-execute/exec-dynamicuser-runtimedirectory1.service b/test/test-execute/exec-dynamicuser-runtimedirectory1.service new file mode 100644 index 0000000000..a3e566248d --- /dev/null +++ b/test/test-execute/exec-dynamicuser-runtimedirectory1.service @@ -0,0 +1,11 @@ +[Unit] +Description=Test for RuntimeDirectory with RuntimeDirectoryPreserve=yes and DynamicUser=yes + +[Service] +ExecStart=/bin/sh -x -c 'test -d %t/test-exec_runtimedirectorypreserve' +ExecStart=/bin/sh -x -c 'test "$$RUNTIME_DIRECTORY" = "%t/test-exec_runtimedirectorypreserve"' +ExecStart=/bin/sh -x -c 'touch $$RUNTIME_DIRECTORY/test' +Type=oneshot +RuntimeDirectory=test-exec_runtimedirectorypreserve +RuntimeDirectoryPreserve=yes +DynamicUser=yes diff --git a/test/test-execute/exec-dynamicuser-runtimedirectory2.service b/test/test-execute/exec-dynamicuser-runtimedirectory2.service new file mode 100644 index 0000000000..d7af69907a --- /dev/null +++ b/test/test-execute/exec-dynamicuser-runtimedirectory2.service @@ -0,0 +1,12 @@ +[Unit] +Description=Test for RuntimeDirectory with RuntimeDirectoryPreserve=yes and DynamicUser=yes 2nd trial + +[Service] +ExecStart=/bin/sh -x -c 'test -d %t/test-exec_runtimedirectorypreserve' +ExecStart=/bin/sh -x -c 'test "$$RUNTIME_DIRECTORY" = "%t/test-exec_runtimedirectorypreserve"' +ExecStart=/bin/sh -x -c 'test -f $$RUNTIME_DIRECTORY/test' +ExecStart=/bin/sh -x -c 'touch $$RUNTIME_DIRECTORY/test' +Type=oneshot +RuntimeDirectory=test-exec_runtimedirectorypreserve +RuntimeDirectoryPreserve=yes +DynamicUser=yes diff --git a/test/test-execute/exec-dynamicuser-runtimedirectory3.service b/test/test-execute/exec-dynamicuser-runtimedirectory3.service new file mode 100644 index 0000000000..1ea47ef6ea --- /dev/null +++ b/test/test-execute/exec-dynamicuser-runtimedirectory3.service @@ -0,0 +1,11 @@ +[Unit] +Description=Test for RuntimeDirectory with DynamicUser=yes migrated from RuntimeDirectoryPreserve=yes + +[Service] +ExecStart=/bin/sh -x -c 'test -d %t/test-exec_runtimedirectorypreserve' +ExecStart=/bin/sh -x -c 'test "$$RUNTIME_DIRECTORY" = "%t/test-exec_runtimedirectorypreserve"' +ExecStart=/bin/sh -x -c 'test -f $$RUNTIME_DIRECTORY/test' +ExecStart=/bin/sh -x -c 'touch $$RUNTIME_DIRECTORY/test' +Type=oneshot +RuntimeDirectory=test-exec_runtimedirectorypreserve +DynamicUser=yes