From: Jacek Bukarewicz Date: Fri, 11 Jul 2014 13:56:53 +0000 (+0200) Subject: Add tests for setting current process label X-Git-Tag: security-manager_5.5_testing~227 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dae32029a9cfd9fc8e61a57e80a026a78e4af7ab;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Add tests for setting current process label Change-Id: I020b8c812526c7e13d86df8ffe72c4d80a1e0fe0 Signed-off-by: Jacek Bukarewicz --- diff --git a/tests/security-manager-tests/security_manager_tests.cpp b/tests/security-manager-tests/security_manager_tests.cpp index b33e468..45c581d 100644 --- a/tests/security-manager-tests/security_manager_tests.cpp +++ b/tests/security-manager-tests/security_manager_tests.cpp @@ -17,6 +17,8 @@ DEFINE_SMARTPTR(security_manager_app_inst_req_free, app_inst_req, AppInstReqUniquePtr); +static const char *const LABELLED_BINARY_PATH = "/usr/bin/test-app-efl"; + static const char *const SM_APP_ID1 = "sm_test_app_id_double"; static const char *const SM_PKG_ID1 = "sm_test_pkg_id_double"; @@ -289,6 +291,46 @@ static void check_app_after_uninstall(const char *const app_id, const char *cons dbtest.test_db_after__app_uninstall(app_id, pkg_id, is_pkg_removed); } +static void install_app(const char *app_id, const char *pkg_id) +{ + int result; + AppInstReqUniquePtr request; + request.reset(do_app_inst_req_new()); + + result = security_manager_app_inst_req_set_app_id(request.get(), app_id); + RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS, + "setting app id failed. Result: " << result); + + result = security_manager_app_inst_req_set_pkg_id(request.get(), pkg_id); + RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS, + "setting pkg id failed. Result: " << result); + + result = security_manager_app_install(request.get()); + RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS, + "installing app failed. Result: " << result); + + check_app_after_install(app_id, pkg_id); + +} + +static void uninstall_app(const char *app_id, const char *pkg_id, + bool expect_installed, bool expect_pkg_removed) +{ + int result; + AppInstReqUniquePtr request; + request.reset(do_app_inst_req_new()); + + result = security_manager_app_inst_req_set_app_id(request.get(), app_id); + RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS, + "setting app id failed. Result: " << result); + + result = security_manager_app_uninstall(request.get()); + RUNNER_ASSERT_MSG_BT(!expect_installed || (lib_retcode)result == SECURITY_MANAGER_SUCCESS, + "uninstalling app failed. Result: " << result); + + check_app_after_uninstall(app_id, pkg_id, expect_pkg_removed); +} + RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER) @@ -404,6 +446,92 @@ RUNNER_TEST(security_manager_02_app_install_uninstall_full) SM_ALLOWED_PRIVILEGES, TestSecurityManagerDatabase::REMOVED); } +RUNNER_CHILD_TEST_SMACK(security_manager_03_set_label_from_binary) +{ + const char *const testBinaryPath = LABELLED_BINARY_PATH; + const char *const expectedLabel = USER_APP_ID; + int result; + char *label = NULL; + CStringPtr labelPtr; + + result = security_manager_set_process_label_from_binary(testBinaryPath); + RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS, + "security_manager_set_process_label_from_binary(" << + testBinaryPath << ") failed. Result: " << result); + + result = smack_new_label_from_self(&label); + RUNNER_ASSERT_MSG_BT(result >= 0, + " Error getting current process label"); + RUNNER_ASSERT_MSG_BT(label != NULL, + " Process label is not set"); + labelPtr.reset(label); + + result = strcmp(expectedLabel, label); + RUNNER_ASSERT_MSG_BT(result == 0, + " Process label is incorrect. Expected: \"" << expectedLabel << "\" Actual: \"" + << label << "\""); +} + +RUNNER_CHILD_TEST_NOSMACK(security_manager_03_set_label_from_binary_nosmack) +{ + const char *const testBinaryPath = LABELLED_BINARY_PATH; + int result; + + result = security_manager_set_process_label_from_binary(testBinaryPath); + RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS, + "security_manager_set_process_label_from_binary(" << + testBinaryPath << ") failed. Result: " << result); +} + +RUNNER_CHILD_TEST_SMACK(security_manager_04_set_label_from_appid) +{ + const char *const app_id = "sm_test_app_id_set_label_from_appid"; + const char *const pkg_id = "sm_test_pkg_id_set_label_from_appid"; + const char *const expected_label = USER_APP_ID; + char *label = NULL; + CStringPtr labelPtr; + int result; + + uninstall_app(app_id, pkg_id, false, true); + install_app(app_id, pkg_id); + + result = security_manager_set_process_label_from_appid(app_id); + RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS, + "security_manager_set_process_label_from_appid(" << + app_id << ") failed. Result: " << result); + + result = smack_new_label_from_self(&label); + RUNNER_ASSERT_MSG_BT(result >= 0, + " Error getting current process label"); + RUNNER_ASSERT_MSG_BT(label != NULL, + " Process label is not set"); + labelPtr.reset(label); + + result = strcmp(expected_label, label); + RUNNER_ASSERT_MSG_BT(result == 0, + " Process label is incorrect. Expected: \"" << expected_label << + "\" Actual: \"" << label << "\""); + + uninstall_app(app_id, pkg_id, true, true); +} + +RUNNER_CHILD_TEST_NOSMACK(security_manager_04_set_label_from_appid_nosmack) +{ + const char *const app_id = "sm_test_app_id_set_label_from_appid"; + const char *const pkg_id = "sm_test_pkg_id_set_label_from_appid"; + int result; + + uninstall_app(app_id, pkg_id, false, true); + install_app(app_id, pkg_id); + + result = security_manager_set_process_label_from_appid(app_id); + RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS, + "security_manager_set_process_label_from_appid(" << + app_id << ") failed. Result: " << result); + + uninstall_app(app_id, pkg_id, true, true); +} + int main(int argc, char *argv[]) { SummaryCollector::Register();