From bee8ed28ca0eea8c7590e9bb8e5567dbfdd156b6 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 17 May 2013 10:10:23 +0200 Subject: [PATCH] Test for app_label_dir [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 | 22 ++++++++++++++++++++-- .../app_dir/link_to_exec | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) create mode 120000 tests/libprivilege-control-tests/test_privilege_control_DIR/app_dir/link_to_exec diff --git a/tests/libprivilege-control-tests/test_cases.cpp b/tests/libprivilege-control-tests/test_cases.cpp index f846a4e..6b74d5d 100644 --- a/tests/libprivilege-control-tests/test_cases.cpp +++ b/tests/libprivilege-control-tests/test_cases.cpp @@ -268,8 +268,6 @@ int test_have_any_accesses(const std::vector< std::vector >& 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 index 0000000..94e5405 --- /dev/null +++ b/tests/libprivilege-control-tests/test_privilege_control_DIR/app_dir/link_to_exec @@ -0,0 +1 @@ +../non_app_dir/exec \ No newline at end of file -- 2.7.4