[systemd-commits] 4 commits - Makefile.am src/test test/exec-umask-0177.service test/exec-umask-default.service

Ronny Chevalier rchevalier at kemper.freedesktop.org
Thu Dec 11 09:53:06 PST 2014


 Makefile.am                     |    2 +
 src/test/test-condition.c       |   47 ++++++++++++++++++++++++++++++++++++++--
 src/test/test-execute.c         |    6 +++++
 src/test/test-strv.c            |   22 ++++++++++++++++++
 src/test/test-unit-name.c       |    2 +
 test/exec-umask-0177.service    |    7 +++++
 test/exec-umask-default.service |    6 +++++
 7 files changed, 90 insertions(+), 2 deletions(-)

New commits:
commit 015df1f78f443f91b354e0c4b4cb76de86c838eb
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date:   Thu Dec 11 18:30:37 2014 +0100

    test-condition: add more test cases

diff --git a/src/test/test-condition.c b/src/test/test-condition.c
index 349c647..88147c8 100644
--- a/src/test/test-condition.c
+++ b/src/test/test-condition.c
@@ -23,8 +23,13 @@
 #include "log.h"
 #include "architecture.h"
 #include "sd-id128.h"
+#include "selinux-util.h"
+#include "audit.h"
+#include "ima-util.h"
+#include "apparmor-util.h"
+#include "smack-util.h"
 
-static void test_condition_test_path_exists(void) {
+static void test_condition_test_path(void) {
         Condition *condition;
 
         condition = condition_new(CONDITION_PATH_EXISTS, "/bin/sh", false, false);
@@ -82,6 +87,14 @@ static void test_condition_test_path_exists(void) {
         condition = condition_new(CONDITION_PATH_IS_MOUNT_POINT, "/bin", false, false);
         assert_se(!condition_test(condition));
         condition_free(condition);
+
+        condition = condition_new(CONDITION_PATH_IS_READ_WRITE, "/tmp", false, false);
+        assert_se(condition_test(condition));
+        condition_free(condition);
+
+        condition = condition_new(CONDITION_PATH_IS_SYMBOLIC_LINK, "/dev/stdout", false, false);
+        assert_se(condition_test(condition));
+        condition_free(condition);
 }
 
 static void test_condition_test_ac_power(void) {
@@ -179,16 +192,46 @@ static void test_condition_test_null(void) {
         condition_free(condition);
 }
 
+static void test_condition_test_security(void) {
+        Condition *condition;
+
+        condition = condition_new(CONDITION_SECURITY, "garbage oifdsjfoidsjoj", false, false);
+        assert_se(!condition_test(condition));
+        condition_free(condition);
+
+        condition = condition_new(CONDITION_SECURITY, "selinux", false, true);
+        assert_se(condition_test(condition) != mac_selinux_use());
+        condition_free(condition);
+
+        condition = condition_new(CONDITION_SECURITY, "ima", false, false);
+        assert_se(condition_test(condition) == use_ima());
+        condition_free(condition);
+
+        condition = condition_new(CONDITION_SECURITY, "apparmor", false, false);
+        assert_se(condition_test(condition) == mac_apparmor_use());
+        condition_free(condition);
+
+        condition = condition_new(CONDITION_SECURITY, "smack", false, false);
+        assert_se(condition_test(condition) == mac_smack_use());
+        condition_free(condition);
+
+        condition = condition_new(CONDITION_SECURITY, "audit", false, false);
+        assert_se(condition_test(condition) == use_audit());
+        condition_free(condition);
+}
+
+
 int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
 
-        test_condition_test_path_exists();
+        test_condition_test_path();
         test_condition_test_ac_power();
         test_condition_test_host();
         test_condition_test_architecture();
         test_condition_test_kernel_command_line();
         test_condition_test_null();
+        test_condition_test_security();
 
         return 0;
 }

commit e74aa253e977ffd768a6d3af3535ea5b31e350a7
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date:   Thu Dec 11 18:30:16 2014 +0100

    test-strv: add test for strv_equal

diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index 674c1b5..e09b4fb 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -470,6 +470,27 @@ static void test_strv_push(void) {
         assert_se(streq_ptr(a[3], NULL));
 }
 
+static void test_strv_equal(void) {
+        _cleanup_strv_free_ char **a = NULL;
+        _cleanup_strv_free_ char **b = NULL;
+        _cleanup_strv_free_ char **c = NULL;
+
+        a = strv_new("one", "two", "three", NULL);
+        assert_se(a);
+        b = strv_new("one", "two", "three", NULL);
+        assert_se(a);
+        c = strv_new("one", "two", "three", "four", NULL);
+        assert_se(a);
+
+        assert_se(strv_equal(a, a));
+        assert_se(strv_equal(a, b));
+        assert_se(strv_equal(NULL, NULL));
+
+        assert_se(!strv_equal(a, c));
+        assert_se(!strv_equal(b, c));
+        assert_se(!strv_equal(b, NULL));
+}
+
 int main(int argc, char *argv[]) {
         test_specifier_printf();
         test_strv_foreach();
@@ -519,6 +540,7 @@ int main(int argc, char *argv[]) {
         test_strv_from_stdarg_alloca();
         test_strv_push_prepend();
         test_strv_push();
+        test_strv_equal();
 
         return 0;
 }

commit 27c5347c8c38bafedb1b48a5d8587d13eadcb90b
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date:   Thu Dec 11 17:59:10 2014 +0100

    test-execute: add tests for UMask directive

diff --git a/Makefile.am b/Makefile.am
index 9255fcf..15e4484 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1443,6 +1443,8 @@ EXTRA_DIST += \
 	test/exec-systemcallfilter-not-failing.service \
 	test/exec-user.service \
 	test/exec-workingdirectory.service \
+	test/exec-umask-0177.service \
+	test/exec-umask-default.service \
 	test/bus-policy/hello.conf \
 	test/bus-policy/methods.conf \
 	test/bus-policy/ownerships.conf \
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 60466f0..91ccaf7 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -132,6 +132,11 @@ static void test_exec_environment(Manager *m) {
         test(m, "exec-environment-empty.service", 0, CLD_EXITED);
 }
 
+static void test_exec_umask(Manager *m) {
+        test(m, "exec-umask-default.service", 0, CLD_EXITED);
+        test(m, "exec-umask-0177.service", 0, CLD_EXITED);
+}
+
 int main(int argc, char *argv[]) {
         test_function_t tests[] = {
                 test_exec_workingdirectory,
@@ -144,6 +149,7 @@ int main(int argc, char *argv[]) {
                 test_exec_user,
                 test_exec_group,
                 test_exec_environment,
+                test_exec_umask,
                 NULL,
         };
         test_function_t *test = NULL;
diff --git a/test/exec-umask-0177.service b/test/exec-umask-0177.service
new file mode 100644
index 0000000..af92958
--- /dev/null
+++ b/test/exec-umask-0177.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Test for UMask
+
+[Service]
+ExecStart=/bin/sh -c 'touch /tmp/test-exec-umask; s=$(stat -c %a /tmp/test-exec-umask); echo $s; exit $(test $s = "600")'
+UMask=0177
+PrivateTmp=yes
diff --git a/test/exec-umask-default.service b/test/exec-umask-default.service
new file mode 100644
index 0000000..41e20a6
--- /dev/null
+++ b/test/exec-umask-default.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=Test for UMask default
+
+[Service]
+ExecStart=/bin/sh -c 'touch /tmp/test-exec-umask; s=$(stat -c %a /tmp/test-exec-umask); echo $s; exit $(test $s = "644")'
+PrivateTmp=yes

commit 14b0295f916a7ce5262b0b5b8a3418ce474b9c69
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date:   Thu Dec 11 17:58:40 2014 +0100

    test-unit-name: add tests for %f

diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index ab6c488..65b6975 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -159,6 +159,7 @@ static int test_unit_printf(void) {
 
         /* normal unit */
         expect(u, "%n", "blah.service");
+        expect(u, "%f", "/blah");
         expect(u, "%N", "blah");
         expect(u, "%p", "blah");
         expect(u, "%P", "blah");
@@ -178,6 +179,7 @@ static int test_unit_printf(void) {
 
         expect(u2, "%n", "blah at foo-foo.service");
         expect(u2, "%N", "blah at foo-foo");
+        expect(u2, "%f", "/foo/foo");
         expect(u2, "%p", "blah");
         expect(u2, "%P", "blah");
         expect(u2, "%i", "foo-foo");



More information about the systemd-commits mailing list