From: Piotr Bartosiewicz
Date: Tue, 8 Oct 2013 14:51:06 +0000 (+0200)
Subject: Checking whether required application is installed
X-Git-Tag: security-manager_5.5_testing~340
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53be55126951dfa833e058bfdfa0ed6707747bc2;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git
Checking whether required application is installed
[Issue#] SSDWSSP-573
[Bug/Feature] Poor assertion message when wrt or osp application is
not installed correctly.
[Cause] Tested process calls exit so there is printed useless
message 'Reading pipe error'.
[Solution] Additional checks are added before api call.
[Verification] Build, install, run tests.
Change-Id: Ia25efb5d8d5ca6450277d11b84b5345efa92a636
---
diff --git a/tests/libprivilege-control-tests/common/libprivilege-control_test_common.h b/tests/libprivilege-control-tests/common/libprivilege-control_test_common.h
index 446306b..35d2338 100644
--- a/tests/libprivilege-control-tests/common/libprivilege-control_test_common.h
+++ b/tests/libprivilege-control-tests/common/libprivilege-control_test_common.h
@@ -318,6 +318,9 @@ void cleaning_smack_app_files (void);
void read_gids(std::set &set, const char *file_path);
void check_groups(const char *dac_file);
+int file_exists(const char *path);
+void check_app_installed(int line_no, const char *app_path);
+
int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
int /*typeflag*/, struct FTW* /*ftwbuf*/);
int nftw_check_labels_app_dir(const char *fpath, const struct stat *sb,
diff --git a/tests/libprivilege-control-tests/libprivilege-control_test_common.cpp b/tests/libprivilege-control-tests/libprivilege-control_test_common.cpp
index 9e815f7..fc98daf 100644
--- a/tests/libprivilege-control-tests/libprivilege-control_test_common.cpp
+++ b/tests/libprivilege-control-tests/libprivilege-control_test_common.cpp
@@ -120,6 +120,22 @@ void check_groups(const char *dac_file)
RUNNER_ASSERT_MSG(groups_check.empty(), "Application doesn't belong to some required groups: " << groups_left);
}
+int file_exists(const char *path)
+{
+ FILE *file = fopen(path, "r");
+ if (file) {
+ fclose(file);
+ return 0;
+ }
+ return -1;
+}
+
+void check_app_installed(int line_no, const char *app_path)
+{
+ RUNNER_ASSERT_MSG(file_exists(app_path) == 0, "Line: " << line_no <<
+ " App not installed: " << app_path);
+}
+
int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
int /*typeflag*/, struct FTW* /*ftwbuf*/)
{
diff --git a/tests/libprivilege-control-tests/test_cases.cpp b/tests/libprivilege-control-tests/test_cases.cpp
index 79636b8..bd7032c 100644
--- a/tests/libprivilege-control-tests/test_cases.cpp
+++ b/tests/libprivilege-control-tests/test_cases.cpp
@@ -218,16 +218,6 @@ int check_labels_dir(const char *fpath, const struct stat *sb,
return 0;
}
-int file_exists(const char *path)
-{
- FILE *file = fopen(path, "r");
- if (file) {
- fclose(file);
- return 0;
- }
- return -1;
-}
-
void osp_blahblah_check(int line_no, const std::vector &rules)
{
std::ifstream smack_file(OSP_BLAHBLAH);
@@ -481,6 +471,7 @@ void set_app_privilege(int line_no,
const char** privileges, const char* type,
const char* app_path, const char* dac_file,
const std::vector< std::vector > &rules) {
+ check_app_installed(line_no, app_path);
int result = perm_app_uninstall(app_id);
RUNNER_ASSERT_MSG(result == 0, "Line: " << line_no <<
diff --git a/tests/libprivilege-control-tests/test_cases_nosmack.cpp b/tests/libprivilege-control-tests/test_cases_nosmack.cpp
index 36df1ba..42c587c 100644
--- a/tests/libprivilege-control-tests/test_cases_nosmack.cpp
+++ b/tests/libprivilege-control-tests/test_cases_nosmack.cpp
@@ -187,6 +187,39 @@ RUNNER_TEST_NOSMACK(privilege_control04_add_permissions_nosmack)
RUNNER_ASSERT_MSG(fs.tellg() > 0, "SMACK file empty, but privileges list was not empty.");
}
+void set_app_privilege_nosmack(int line_no,
+ const char* app_id, app_type_t app_type,
+ const char** privileges, const char* type,
+ const char* app_path, const char* dac_file,
+ const std::vector< std::vector > &rules)
+{
+ check_app_installed(line_no, app_path);
+
+ int result;
+
+ result = perm_app_enable_permissions(app_id, app_type, privileges, 1);
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Line: " << line_no <<
+ " Error enabling app permissions. Result: " << result);
+
+ result = test_have_nosmack_accesses(rules);
+ RUNNER_ASSERT_MSG(result == -1, "Line: " << line_no <<
+ " Permissions shouldn't be added. Result: " << result);
+
+ result = perm_app_set_privilege(app_id, type, app_path);
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Line: " << line_no <<
+ " Error in perm_app_set_privilege. Error: " << result);
+
+ //Even though app privileges are set, no smack label should be extracted.
+ char* label = NULL;
+ result = smack_new_label_from_self(&label);
+ RUNNER_ASSERT_MSG(result == -1, "Line: " << line_no <<
+ " new_label_from_self should return error (SMACK is off). Result: " << result);
+ RUNNER_ASSERT_MSG(label == NULL, "Line: " << line_no <<
+ " new_label_from_self shouldn't allocate memory for label.");
+
+ check_groups(dac_file);
+}
+
/**
* NOSMACK version of privilege_control05_set_app_privilege test.
*
@@ -197,6 +230,8 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_nosmack)
{
int result;
+ check_app_installed(__LINE__, APP_SET_PRIV_PATH);
+
//Preset exec label
smack_lsetlabel(APP_SET_PRIV_PATH_REAL, APP_ID, SMACK_LABEL_EXEC);
smack_lsetlabel(APP_SET_PRIV_PATH, APP_ID "_symlink", SMACK_LABEL_EXEC);
@@ -204,7 +239,7 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_nosmack)
//Set app privileges
result = perm_app_set_privilege(APP_ID, NULL, APP_SET_PRIV_PATH);
RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error in perm_app_set_privilege. Result: " << result);
+ "Error in perm_app_set_privilege. Error: " << result);
//Even though app privileges are set, no smack label should be extracted.
char* label = NULL;
@@ -233,27 +268,8 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_nosmack)
*/
RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_wgt_nosmack)
{
- int result;
-
- result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS_WGT, 1);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- " Error enabling app permissions. Result: " << result);
-
- result = test_have_nosmack_accesses(rules_wgt);
- RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added. Result: " << result);
-
- result = perm_app_set_privilege(WGT_APP_ID, "wgt", WGT_APP_PATH);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error in perm_app_set_privilege. Result: " << result);
-
- //Even though app privileges are set, no smack label should be extracted.
- char* label = NULL;
- result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG(result == -1,
- "new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
-
- check_groups(LIBPRIVILEGE_TEST_DAC_FILE_WGT);
+ set_app_privilege_nosmack(__LINE__, WGT_APP_ID, APP_TYPE_WGT, PRIVS_WGT, "wgt", WGT_APP_PATH,
+ LIBPRIVILEGE_TEST_DAC_FILE_WGT, rules_wgt);
}
/**
@@ -263,27 +279,9 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_wgt_nosmack)
*/
RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_wgt_partner_nosmack)
{
- int result;
-
- result = perm_app_enable_permissions(WGT_PARTNER_APP_ID, APP_TYPE_WGT_PARTNER, PRIVS_WGT, 1);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- " Error enabling app permissions. Result: " << result);
-
- result = test_have_nosmack_accesses(rules_wgt_partner);
- RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added. Result: " << result);
-
- result = perm_app_set_privilege(WGT_PARTNER_APP_ID, "wgt_partner", WGT_PARTNER_APP_PATH);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error in perm_app_set_privilege. Result: " << result);
-
- //Even though app privileges are set, no smack label should be extracted.
- char* label = NULL;
- result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG(result == -1,
- "new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
-
- check_groups(LIBPRIVILEGE_TEST_DAC_FILE_WGT);
+ set_app_privilege_nosmack(__LINE__, WGT_PARTNER_APP_ID, APP_TYPE_WGT_PARTNER, PRIVS_WGT,
+ "wgt_partner", WGT_PARTNER_APP_PATH,
+ LIBPRIVILEGE_TEST_DAC_FILE_WGT, rules_wgt_partner);
}
/**
@@ -293,27 +291,9 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_wgt_partner_nosm
*/
RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_wgt_platform_nosmack)
{
- int result;
-
- result = perm_app_enable_permissions(WGT_PLATFORM_APP_ID, APP_TYPE_WGT_PLATFORM, PRIVS_WGT, 1);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- " Error enabling app permissions. Result: " << result);
-
- result = test_have_nosmack_accesses(rules_wgt_platform);
- RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added. Result: " << result);
-
- result = perm_app_set_privilege(WGT_PLATFORM_APP_ID, "wgt_platform", WGT_PLATFORM_APP_PATH);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error in perm_app_set_privilege. Result: " << result);
-
- //Even though app privileges are set, no smack label should be extracted.
- char* label = NULL;
- result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG(result == -1,
- "new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
-
- check_groups(LIBPRIVILEGE_TEST_DAC_FILE_WGT);
+ set_app_privilege_nosmack(__LINE__, WGT_PLATFORM_APP_ID, APP_TYPE_WGT_PLATFORM, PRIVS_WGT,
+ "wgt_platform", WGT_PLATFORM_APP_PATH,
+ LIBPRIVILEGE_TEST_DAC_FILE_WGT, rules_wgt_platform);
}
/**
@@ -323,27 +303,8 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_wgt_platform_nos
*/
RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_osp_nosmack)
{
- int result;
-
- result = perm_app_enable_permissions(OSP_APP_ID, APP_TYPE_OSP, PRIVS_OSP, 1);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- " Error enabling app permissions. Result: " << result);
-
- result = test_have_nosmack_accesses(rules_osp);
- RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added. Result: " << result);
-
- result = perm_app_set_privilege(OSP_APP_ID, NULL, OSP_APP_PATH);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error in perm_app_set_privilege. Result: " << result);
-
- //Even though app privileges are set, no smack label should be extracted.
- char* label = NULL;
- result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG(result == -1,
- "new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
-
- check_groups(LIBPRIVILEGE_TEST_DAC_FILE_OSP);
+ set_app_privilege_nosmack(__LINE__, OSP_APP_ID, APP_TYPE_OSP, PRIVS_OSP, NULL, OSP_APP_PATH,
+ LIBPRIVILEGE_TEST_DAC_FILE_OSP, rules_osp);
}
/**
@@ -353,27 +314,8 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_osp_nosmack)
*/
RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_osp_partner_nosmack)
{
- int result;
-
- result = perm_app_enable_permissions(OSP_PARTNER_APP_ID, APP_TYPE_OSP_PARTNER, PRIVS_OSP, 1);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error enabling app permissions. Result: " << result);
-
- result = test_have_nosmack_accesses(rules_osp_partner);
- RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added.");
-
- result = perm_app_set_privilege(OSP_PARTNER_APP_ID, NULL, OSP_PARTNER_APP_PATH);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error in perm_app_set_privilege. Result: " << result);
-
- //Even though app privileges are set, no smack label should be extracted.
- char* label = NULL;
- result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG(result == -1,
- "new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
-
- check_groups(LIBPRIVILEGE_TEST_DAC_FILE_OSP);
+ set_app_privilege_nosmack(__LINE__, OSP_PARTNER_APP_ID, APP_TYPE_OSP_PARTNER, PRIVS_OSP,
+ NULL, OSP_PARTNER_APP_PATH, LIBPRIVILEGE_TEST_DAC_FILE_OSP, rules_osp_partner);
}
/**
@@ -383,27 +325,9 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_osp_partner_nosm
*/
RUNNER_CHILD_TEST_NOSMACK(privilege_control05_set_app_privilege_osp_platform_nosmack)
{
- int result;
-
- result = perm_app_enable_permissions(OSP_PLATFORM_APP_ID, APP_TYPE_OSP_PLATFORM, PRIVS_OSP, 1);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- " Error enabling app permissions. Result: " << result);
-
- result = test_have_nosmack_accesses(rules_osp_platform);
- RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added. Result: " << result);
-
- result = perm_app_set_privilege(OSP_PLATFORM_APP_ID, NULL, OSP_PLATFORM_APP_PATH);
- RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
- "Error in perm_app_set_privilege. Result: " << result);
-
- //Even though app privileges are set, no smack label should be extracted.
- char* label = NULL;
- result = smack_new_label_from_self(&label);
- RUNNER_ASSERT_MSG(result == -1,
- "new_label_from_self should return error (SMACK is off). Result: " << result);
- RUNNER_ASSERT_MSG(label == NULL, "new_label_from_self shouldn't allocate memory for label.");
-
- check_groups(LIBPRIVILEGE_TEST_DAC_FILE_OSP);
+ set_app_privilege_nosmack(__LINE__, OSP_PLATFORM_APP_ID, APP_TYPE_OSP_PLATFORM, PRIVS_OSP,
+ NULL, OSP_PLATFORM_APP_PATH,
+ LIBPRIVILEGE_TEST_DAC_FILE_OSP, rules_osp_platform);
}
/*