Test for app_label_dir
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 17 May 2013 08:10:23 +0000 (10:10 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 13:43:52 +0000 (14:43 +0100)
[Issue#] SSDWSSP-233
[Feature] Requirements for app_label_dir
[Problem] N/A
[Cause] N/A
[Solution] Tests updated

[Verification] Run libprivilege-control-test --regexp=app_label_dir

Change-Id: Ia5bbeaad35f34d1fcbb0c01e760805eb2d9c4f9d

tests/libprivilege-control-tests/test_cases.cpp
tests/libprivilege-control-tests/test_privilege_control_DIR/app_dir/link_to_exec [new symlink]

index f846a4e..6b74d5d 100644 (file)
@@ -268,8 +268,6 @@ int test_have_any_accesses(const std::vector< std::vector<std::string> >& rules)
     return 0;
 }
 
-RUNNER_TEST_GROUP_INIT(libprivilegecontrol)
-
 int nftw_remove_labels(const char *fpath, const struct stat * /*sb*/,
                                int /*typeflag*/, struct FTW * /*ftwbuf*/)
 {
@@ -336,6 +334,18 @@ int nftw_check_labels_app_dir(const char *fpath, const struct stat *sb,
         RUNNER_ASSERT_MSG(label != NULL, "EXEC label on " << fpath << " is not set");
         result = strcmp(APPID_DIR, label);
         RUNNER_ASSERT_MSG(result == 0, "EXEC label on executable file " << fpath << " is incorrect");
+    } else if(S_ISLNK(sb->st_mode)) {
+        struct stat buf;
+        char* target = realpath(fpath, NULL);
+        RUNNER_ASSERT_MSG(0 == stat(target, &buf),"Stat failed for " << fpath);
+        free(target);
+        if (buf.st_mode != (buf.st_mode | S_IXUSR | S_IFREG)) {
+            RUNNER_ASSERT_MSG(label == NULL, "EXEC label on " << fpath << " is set");
+        } else {
+            RUNNER_ASSERT_MSG(label != NULL, "EXEC label on " << fpath << " is not set");
+            result = strcmp(APPID_DIR, label);
+            RUNNER_ASSERT_MSG(result == 0, "EXEC label on link to executable file " << fpath << " is incorrect");
+        }
     } else
         RUNNER_ASSERT_MSG(label == NULL, "EXEC label on " << fpath << " is set");
 
@@ -477,6 +487,8 @@ int cleaning_smack_database_files (void)
 }
 } // namespace
 
+RUNNER_TEST_GROUP_INIT(libprivilegecontrol)
+
 /**
  * Test setting labels for all files and folders in given path.
  */
@@ -756,6 +768,12 @@ RUNNER_CHILD_TEST(privilege_control05_set_app_privilege)
     smack_lsetlabel(APP_SET_PRIV_PATH_REAL, APP_ID, SMACK_LABEL_EXEC);
     smack_lsetlabel(APP_SET_PRIV_PATH, APP_ID "_symlink", SMACK_LABEL_EXEC);
 
+    /**
+     * TODO This test should also verify set_app_privilege behavior for OSP and
+     * WRT apps. To do that we'll have to install real apps on device as a
+     * precondition.
+     */
+
     // Set APP privileges
     result = set_app_privilege(APP_ID, NULL, APP_SET_PRIV_PATH);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Error in set_app_privilege. Error: " << result);
diff --git a/tests/libprivilege-control-tests/test_privilege_control_DIR/app_dir/link_to_exec b/tests/libprivilege-control-tests/test_privilege_control_DIR/app_dir/link_to_exec
new file mode 120000 (symlink)
index 0000000..94e5405
--- /dev/null
@@ -0,0 +1 @@
+../non_app_dir/exec
\ No newline at end of file