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";
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)
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();