Test for app_give_access, app_revoke_access function.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Wed, 10 Apr 2013 14:32:50 +0000 (16:32 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 13:19:15 +0000 (14:19 +0100)
[Issue#]   SSDWSSP-177
[Bug]      N/A
[Cause]    N/A
[Solution] N/A

[Verification] Build. Run libprivilege-control tests.
New test has been added and it should pass.

Change-Id: I5877111a60f2b95d871df45095eaf00da6e4f3f5

tests/libprivilege-control-tests/test_cases.cpp

index d16d0d52ff758aa85249c05f6ef007dfad61ee20..625891445c92eeede908bea74e09857b2a1dfa6f 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <vector>
 #include <errno.h>
+#include <memory>
 #include <ftw.h>
 #include <dpl/test/test_runner.h>
 #include <dpl/test/test_runner_child.h>
@@ -361,7 +362,7 @@ RUNNER_TEST(privilege_control04_revoke_permissions)
 /**
  * Set APP privileges.
  */
-RUNNER_TEST(privilege_control05_set_app_privilege)
+RUNNER_CHILD_TEST(privilege_control05_set_app_privilege)
 {
     int result;
     char* labelApp = "test_pc_label";
@@ -394,3 +395,32 @@ RUNNER_TEST(privilege_control05_set_app_privilege)
     RUNNER_ASSERT_MSG(result == 0, "Wrong user USER NAME");
 }
 
+RUNNER_TEST(privilege_control06_app_give_access)
+{
+    const char *subject = "lkjq345v34sfa";
+    const char *object = "lk9290f92lkjz";
+    smack_accesses *tmp = NULL;
+
+    RUNNER_ASSERT(0 == smack_accesses_new(&tmp));
+
+    std::unique_ptr<smack_accesses,std::function<void(smack_accesses*)>>
+        smack(tmp, smack_accesses_free);
+
+    RUNNER_ASSERT(0 == smack_accesses_add(smack.get(), subject, object, "r--a-"));
+    RUNNER_ASSERT(0 == smack_accesses_apply(smack.get()));
+
+    app_give_access(subject, object, "wt");
+
+    RUNNER_ASSERT(1 == smack_have_access(subject, object, "rwat"));
+    RUNNER_ASSERT(0 == smack_have_access(subject, object, "x"));
+
+    app_revoke_access(subject, object);
+
+    RUNNER_ASSERT(1 == smack_have_access(subject, object, "ra"));
+    RUNNER_ASSERT(0 == smack_have_access(subject, object, "w"));
+    RUNNER_ASSERT(0 == smack_have_access(subject, object, "x"));
+    RUNNER_ASSERT(0 == smack_have_access(subject, object, "t"));
+
+    RUNNER_ASSERT(0 == smack_accesses_add(smack.get(), subject, object, "-"));
+    RUNNER_ASSERT(0 == smack_accesses_apply(smack.get()));
+}