Add test for APP_PATH_ANY_LABEL case in function app_setup_path.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Wed, 29 May 2013 15:57:29 +0000 (17:57 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 13:43:52 +0000 (14:43 +0100)
[Issue#]   SSDWSSP-307
[Bug]      N/A
[Cause]    N/A
[Solution] N/A

[Verification] Run libprivilege-control tests.

Change-Id: I2a997ed36aa557b8a9410db711eed37433289a9e

tests/libprivilege-control-tests/test_cases.cpp

index c0d850f..c8ecb56 100644 (file)
@@ -1926,3 +1926,44 @@ RUNNER_TEST(privilege_control15_app_id_from_socket)
         waitpid(pid, NULL, 0);
     }
 }
+
+RUNNER_TEST(privilege_control16_app_setup_path){
+    const char *path1 = "/usr/share/privilege-control/app_setup_access_test";
+    const char *path2 = "/usr/share/privilege-control/app_setup_access_test/directory";
+    const char *path3 = "/usr/share/privilege-control/app_setup_access_test/one";
+    const char *path4 = "/usr/share/privilege-control/app_setup_access_test/directory/two";
+    const char *label1 = "qwert123456za";
+    const char *label2 = "trewq654123az";
+
+    std::unique_ptr<char, std::function<void(void*)>> labelPtr(NULL,free);
+
+    mkdir(path1,0);
+    mkdir(path2,0);
+
+    int fd = creat(path3, S_IRWXU);
+    if (fd >= 0)
+        close(fd);
+    fd = creat(path4, S_IRWXU);
+    if (fd >= 0)
+        close(fd);
+
+    char *label = NULL;
+
+    RUNNER_ASSERT(PC_OPERATION_SUCCESS == app_setup_path("somepackageid", path1, APP_PATH_ANY_LABEL, label1));
+    RUNNER_ASSERT(0 == smack_lgetlabel(path3, &label, SMACK_LABEL_ACCESS));
+    labelPtr.reset(label);
+    label = NULL;
+    RUNNER_ASSERT(0 == strcmp(labelPtr.get(), label1));
+
+    RUNNER_ASSERT(PC_OPERATION_SUCCESS == app_setup_path("somepackageid", path1, APP_PATH_ANY_LABEL, label2));
+    RUNNER_ASSERT(0 == smack_lgetlabel(path4, &label, SMACK_LABEL_EXEC));
+    labelPtr.reset(label);
+    label = NULL;
+    RUNNER_ASSERT(0 == strcmp(labelPtr.get(), label2));
+
+    RUNNER_ASSERT(0 == smack_lgetlabel(path1, &label, SMACK_LABEL_EXEC));
+    labelPtr.reset(label);
+    label = NULL;
+    RUNNER_ASSERT(labelPtr.get() == NULL);
+}
+