}
/**
+ * Check perm_get_permissions()
+ */
+bool is_permission_on_the_list(char **permissions, const char *const test_permission_name)
+{
+ if(permissions != NULL) {
+ for(size_t i = 0; permissions[i] != NULL; ++i) {
+ if(strcmp(permissions[i], test_permission_name) == 0)
+ return true;
+ }
+ }
+ return false;
+}
+
+RUNNER_TEST(privilege_control05_perm_get_permissions)
+{
+ DBBackup dbbackup;
+
+ char **permissions_1 = NULL;
+ char **permissions_2 = NULL;
+ const char *test_permission_name = "perm_get_permissions_test_2";
+ bool permission_found_1;
+ bool permission_found_2;
+ int result;
+
+ result = perm_get_permissions(&permissions_1, APP_TYPE_OSP);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_get_permissions returned " << perm_strerror(result));
+ CStringListPtr listPtr_1(permissions_1);
+
+ permission_found_1 = is_permission_on_the_list(permissions_1, test_permission_name);
+ RUNNER_ASSERT_MSG_BT(permission_found_1 == false, "permission_found_1 = " << permission_found_1);
+
+ DB_BEGIN
+
+ result = perm_add_api_feature(APP_TYPE_OSP, test_permission_name, (const char*[]) {
+ "~APP~ object\t rwxatl",
+ " \t \n",
+ "subject2\t~APP~ ltxarw",
+ "",
+ NULL
+ }, NULL, 0);
+ RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_add_api_feature returned: " <<
+ perm_strerror(result));
+
+ DB_END
+
+ result = perm_get_permissions(&permissions_2, APP_TYPE_OSP);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_get_permissions returned " << perm_strerror(result));
+ CStringListPtr listPtr_2(permissions_2);
+
+ permission_found_2 = is_permission_on_the_list(permissions_2, test_permission_name);
+ RUNNER_ASSERT_MSG_BT(permission_found_2 == true, "permission_found_2 = " << permission_found_2);
+}
+
+/**
+ * Check perm_get_apps_with_permission()
+ */
+int get_app_index(perm_app_status_t *apps, const char *pkg_id, size_t apps_count)
+{
+ size_t i = 0;
+ if(apps_count > 0) {
+ for(i = 0; i < apps_count; ++i) {
+ if(strcmp(pkg_id, apps[i].app_id) == 0)
+ return i;
+ }
+ }
+ return -1;
+}
+
+void wrapper_perm_free_apps_list(perm_app_status_list_t *list) {
+ perm_free_apps_list(list->status, list->size);
+}
+
+RUNNER_TEST(privilege_control05_perm_get_apps_with_permission_default)
+{
+ perm_app_status_t *apps_1 = NULL;
+ perm_app_status_t *apps_2 = NULL;
+ size_t apps_count_1 = 0;
+ size_t apps_count_2 = 0;
+ int app_index_2 = 0;
+ int result = 0;
+
+ DB_BEGIN
+
+ result = perm_app_uninstall(APP_ID);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_uninstall (1) returned " << perm_strerror(result));
+
+ DB_END
+
+ result = perm_get_apps_with_permission(&apps_1, &apps_count_1, APP_TYPE_OSP, PRIVS_OSP[0]);
+
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_get_apps_with_permission (1) returned " <<
+ perm_strerror(result));
+
+ perm_app_status_list_t app_list_1;
+ app_list_1.status = apps_1;
+ app_list_1.size = apps_count_1;
+ ListAppStatusPtr listAppStatusPtr_1(&app_list_1, wrapper_perm_free_apps_list);
+
+ DB_BEGIN
+
+ result = perm_app_install(APP_ID);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned " << perm_strerror(result));
+
+ result = perm_app_enable_permissions(APP_ID, APP_TYPE_OSP, PRIVS_OSP, true);
+ RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+ "error enabling app permissions. Result: " << perm_strerror(result));
+ DB_END
+
+ result = perm_get_apps_with_permission(&apps_2, &apps_count_2, APP_TYPE_OSP, PRIVS_OSP[0]);
+
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_get_apps_with_permission (2) returned " <<
+ perm_strerror(result));
+
+ perm_app_status_list_t app_list_2;
+ app_list_2.status = apps_2;
+ app_list_2.size = apps_count_2;
+ ListAppStatusPtr listAppStatusPtr_2(&app_list_2, wrapper_perm_free_apps_list);
+
+ RUNNER_ASSERT_MSG_BT(apps_count_2 > apps_count_1, "no new app added " << perm_strerror(result));
+
+ DB_BEGIN
+
+ // check default is_permanent (true), is_enabled (true)
+ app_index_2 = get_app_index(apps_2, APP_ID, apps_count_2);
+
+ RUNNER_ASSERT_MSG_BT(app_index_2 >= 0, "index not found (2): " << app_index_2);
+
+ RUNNER_ASSERT_MSG_BT(apps_2[app_index_2].is_permanent,
+ "incorrect is_permanent value: " << apps_2[app_index_2].is_permanent);
+
+ RUNNER_ASSERT_MSG_BT(apps_2[app_index_2].is_enabled,
+ "incorrect is_enabled value: " << apps_2[app_index_2].is_enabled);
+
+ result = perm_app_uninstall(APP_ID);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_uninstall (2) returned " << perm_strerror(result));
+
+ DB_END
+}
+
+RUNNER_TEST(privilege_control05_perm_get_apps_with_permission_is_permanent)
+{
+ perm_app_status_t *apps = NULL;
+ size_t apps_count = 0;
+ int app_index = 0;
+ int result = 0;
+
+ DB_BEGIN
+
+ result = perm_app_install(APP_ID);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned " << perm_strerror(result));
+
+ // change is_permanent to false using perm_app_enable_permissions
+
+ bool is_permanent = false;
+ result = perm_app_enable_permissions(APP_ID, APP_TYPE_OSP, PRIVS_OSP, is_permanent);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_enable_permissions returned " <<
+ perm_strerror(result));
+
+ DB_END
+
+ result = perm_get_apps_with_permission(&apps, &apps_count, APP_TYPE_OSP, PRIVS_OSP[0]);
+
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_get_apps_with_permission returned " <<
+ perm_strerror(result));
+
+ perm_app_status_list_t app_list;
+ app_list.status = apps;
+ app_list.size = apps_count;
+ ListAppStatusPtr listAppStatusPtr(&app_list, wrapper_perm_free_apps_list);
+
+ DB_BEGIN
+
+ app_index = get_app_index(apps, APP_ID, apps_count);
+
+ RUNNER_ASSERT_MSG_BT(app_index >= 0, "index not found: " << app_index);
+
+ RUNNER_ASSERT_MSG_BT(apps[app_index].is_permanent == false,
+ "incorrect is_permanent value: " << apps[app_index].is_permanent);
+
+ result = perm_app_uninstall(APP_ID);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_uninstall (2) returned " << perm_strerror(result));
+
+ DB_END
+}
+
+RUNNER_TEST(privilege_control05_perm_get_apps_with_permission_is_enabled)
+{
+ perm_app_status_t *apps = NULL;
+ size_t apps_count = 0;
+ int app_index = 0;
+ int result = 0;
+
+ DB_BEGIN
+
+ result = perm_app_install(APP_ID);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_install returned " << perm_strerror(result));
+
+ // enable (i.e. register) permission for installed app
+
+ result = perm_app_enable_permissions(APP_ID, APP_TYPE_OSP, PRIVS_OSP, false);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_enable_permissions returned " <<
+ perm_strerror(result));
+
+ // change is_enabled to false
+ result = perm_app_disable_permissions(APP_ID, APP_TYPE_OSP, PRIVS_OSP);
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_disable_permissions returned " <<
+ perm_strerror(result));
+
+ DB_END
+
+ result = perm_get_apps_with_permission(&apps, &apps_count, APP_TYPE_OSP, PRIVS_OSP[0]);
+
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_get_apps_with_permission returned " <<
+ perm_strerror(result));
+
+ perm_app_status_list_t app_list;
+ app_list.status = apps;
+ app_list.size = apps_count;
+ ListAppStatusPtr listAppStatusPtr(&app_list, wrapper_perm_free_apps_list);
+
+ DB_BEGIN
+
+ app_index = get_app_index(apps, APP_ID, apps_count);
+
+ RUNNER_ASSERT_MSG_BT(app_index >= 0, "index not found: " << app_index);
+
+ RUNNER_ASSERT_MSG_BT(apps[app_index].is_enabled == false,
+ "incorrect is_enabled value: " << apps[app_index].is_enabled);
+
+ result = perm_app_uninstall(APP_ID);
+
+ RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_uninstall returned " << perm_strerror(result));
+
+ DB_END
+}
+
+/**
* Add new API feature
*/
RUNNER_TEST(privilege_control11_add_api_feature)