-
-RUNNER_TEST(privilege_control27_perm_app_get_privileges_empty)
-{
- char** pp_privileges = NULL;
- int result;
- CStringListPtr privileges;
-
- DB_BEGIN
-
- result = perm_app_uninstall(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_uninstall failed: " << perm_strerror(result));
-
- result = perm_app_install(APP_ID);
-
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_install failed: " << perm_strerror(result));
-
- DB_END
-
- result = perm_app_get_permissions(APP_ID, PERM_APP_TYPE_WGT, &pp_privileges);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_get_permissions failed: " << perm_strerror(result));
- privileges.reset(pp_privileges);
-
- RUNNER_ASSERT_MSG_BT(pp_privileges != NULL,
- "perm_app_get_permissions failed to set pointer to cstring array");
- RUNNER_ASSERT_MSG_BT(*pp_privileges == NULL,
- "perm_app_get_permissions found permissions when not supposed to");
-}
-
-RUNNER_TEST(privilege_control27_perm_app_get_privileges)
-{
- char** pp_privileges = NULL;
- int result;
- size_t i;
- CStringListPtr privileges;
-
- DB_BEGIN
-
- result = perm_app_uninstall(APP_ID);
-
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_uninstall failed: " << perm_strerror(result));
-
- result = perm_app_install(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_install failed: " << perm_strerror(result));
-
- result = perm_app_setup_permissions(APP_ID, PERM_APP_TYPE_WGT, PRIVS);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_register_permissions failed: " << perm_strerror(result));
-
- result = perm_app_setup_permissions(APP_ID, PERM_APP_TYPE_WGT, PRIVS2);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_register_permissions failed: " << perm_strerror(result));
-
- result = perm_app_disable_permissions(APP_ID, PERM_APP_TYPE_WGT, PRIVS2);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_disable_permissions failed: " << perm_strerror(result));
- DB_END
-
- result = perm_app_get_permissions(APP_ID, PERM_APP_TYPE_WGT, &pp_privileges);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_get_permissions returned " << result << ": " << perm_strerror(result));
- privileges.reset(pp_privileges);
-
- for(i = 0; pp_privileges[i] != NULL; ++i) {
- RUNNER_ASSERT_MSG_BT(PRIVS[i] != NULL,
- "perm_app_get_permissions returned too many permissions");
- RUNNER_ASSERT_MSG_BT(strcmp(pp_privileges[i], PRIVS[i]) == 0,
- "perm_app_get_permissions returned wrong permission, " << pp_privileges[i] <<
- " != " << PRIVS[i]);
- }
- RUNNER_ASSERT_MSG_BT(PRIVS[i] == NULL,
- "perm_app_get_permissions returned too few enabled permissions");
-}
-
-RUNNER_TEST(privilege_control28_perm_app_get_paths_empty)
-{
- char **pp_paths = NULL;
- int result;
- CStringListPtr paths;
-
- DB_BEGIN
-
- result = perm_app_uninstall(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
- "perm_app_uninstall failed: " << perm_strerror(result));
-
- result = perm_app_install(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_install failed: " <<
- perm_strerror(result));
-
- DB_END
-
- result = perm_app_get_paths(APP_ID, PERM_APP_PATH_PUBLIC, &pp_paths);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_get_paths failed: " <<
- perm_strerror(result));
- paths.reset(pp_paths);
-
- RUNNER_ASSERT_MSG_BT(pp_paths != NULL,
- "perm_app_get_paths failed to set pointer to cstring array");
- RUNNER_ASSERT_MSG_BT(*pp_paths == NULL, "perm_app_get_paths found paths when not supposed to");
-}
-
-RUNNER_TEST(privilege_control28_perm_app_get_paths)
-{
- char **pp_paths = NULL;
- int result;
- size_t i;
- size_t DIR_NUM = 3;
- CStringListPtr paths;
- std::vector<Directory> test_paths;
-
- for (i = 0; i < DIR_NUM; ++i) {
- test_paths.push_back(Directory("/tmp/dir" + std::to_string(i), 0));
- RUNNER_ASSERT_MSG_BT(test_paths[i].isCreated(), "failed to create a directory " <<
- test_paths[i].path() << ": " << strerror(test_paths[i].errorCode()));
- }
-
- DB_BEGIN
-
- result = perm_app_uninstall(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_uninstall failed: " <<
- perm_strerror(result));
-
- result = perm_app_install(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_install failed: " <<
- perm_strerror(result));
-
- for (auto itr = test_paths.begin(); itr != test_paths.end(); ++itr) {
- result = perm_app_setup_path(APP_ID, itr->path().c_str(), PERM_APP_PATH_PUBLIC);
- RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_setup_path failed: " << perm_strerror(result));
- }
-
- DB_END
-
- result = perm_app_get_paths(APP_ID, PERM_APP_PATH_PUBLIC, &pp_paths);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_get_paths failed: " <<
- perm_strerror(result));
- paths.reset(pp_paths);
-
- for(i = 0; pp_paths[i] != NULL; ++i) {
- RUNNER_ASSERT_MSG_BT(i < test_paths.size(), "perm_app_get_paths returned too many paths");
- RUNNER_ASSERT_MSG_BT(test_paths[i].path() == pp_paths[i],
- "perm_app_get_paths returned unexpected path, " << pp_paths[i] << " != " <<
- test_paths[i].path());
- }
- RUNNER_ASSERT_MSG_BT(i == test_paths.size(), "perm_app_get_paths returned too few paths");
-
- DB_BEGIN
-
- result = perm_app_uninstall(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_uninstall failed: " <<
- perm_strerror(result));
-
- DB_END
-}
-
-RUNNER_TEST(privilege_control29_perm_app_remove_path)
-{
- char** pp_paths;
- int result;
- size_t i;
- const size_t i_num_paths_to_remove = 4;
- const size_t i_num_paths = 7;
- CStringListPtr paths;
- std::vector<Directory> test_paths;
-
- for (i = 0; i < i_num_paths; ++i) {
- test_paths.push_back(Directory("/tmp/dir" + std::to_string(i), 0));
- RUNNER_ASSERT_MSG_BT(test_paths[i].isCreated(), "failed to create a directory " <<
- test_paths[i].path() << ": " << strerror(test_paths[i].errorCode()));
- }
-
- DB_BEGIN
-
- result = perm_app_uninstall(APP_ID);
-
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_uninstall failed: " <<
- perm_strerror(result));
-
- result = perm_app_install(APP_ID);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_install failed: " <<
- perm_strerror(result));
-
- for (i = 0; i < i_num_paths; ++i) {
- result = perm_app_setup_path(APP_ID, test_paths[i].path().c_str(), PERM_APP_PATH_PUBLIC);
- RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_setup_path failed: " << perm_strerror(result));
- }
-
- for (i = 0; i < i_num_paths_to_remove; ++i) {
- result = perm_app_remove_path(APP_ID, test_paths[i].path().c_str());
- RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_remove_path failed: " << perm_strerror(result));
- }
-
- result = perm_app_get_paths(APP_ID, PERM_APP_PATH_PUBLIC, &pp_paths);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_get_paths failed: " <<
- perm_strerror(result));
- paths.reset(pp_paths);
-
- DB_END
-
- for (i = 0; pp_paths[i] != NULL; ++i) {
- RUNNER_ASSERT_MSG_BT(i < i_num_paths - i_num_paths_to_remove,
- "perm_app_remove_path removed too few paths");
- RUNNER_ASSERT_MSG_BT(test_paths[i + i_num_paths_to_remove].path() == pp_paths[i],
- "unexpected path encountered - " << pp_paths[i] << " instead of " <<
- test_paths[i + i_num_paths].path() <<
- " - perm_app_remove_path removed wrong path?");
- }
- RUNNER_ASSERT_MSG_BT(i == i_num_paths - i_num_paths_to_remove,
- "perm_app_remove_path removed too many paths");
-
- for (i = i_num_paths_to_remove; i < i_num_paths; ++i) {
- RUNNER_ASSERT_MSG_BT(mkdir(test_paths[i].path().c_str(), 0) == -1 && errno == EEXIST,
- "unexpected error " << strerror(errno) <<
- "- perm_app_remove_path removed data from file system?");
- }
-}
-
-RUNNER_TEST(privilege_control29_perm_app_remove_path_group)
-{
- const char* label = "perm.app.remove.path.group";
- int result;
- Directory directory("/tmp/perm_app_remove_path_dir1", 0);
- TestLibPrivilegeControlDatabase db_test;
-
- RUNNER_ASSERT_MSG_BT(directory.isCreated(), "failed to create the directory " <<
- directory.path() << ": " << strerror(directory.errorCode()));
-
- DB_BEGIN
-
- result = perm_app_uninstall(APP_1);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_uninstall failed: " <<
- perm_strerror(result));
-
- result = perm_app_uninstall(APP_2);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_uninstall failed: " <<
- perm_strerror(result));
-
- result = perm_app_install(APP_1);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_install failed: " <<
- perm_strerror(result));
-
- result = perm_app_install(APP_2);
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_install failed: " <<
- perm_strerror(result));
-
- result = perm_app_setup_path(APP_1, directory.path().c_str(), PERM_APP_PATH_GROUP, label);
- RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_setup_path failed: " << perm_strerror(result));
-
- result = perm_app_setup_path(APP_2, directory.path().c_str(), PERM_APP_PATH_GROUP, label);
- RUNNER_ASSERT_MSG_BT(result == 0, "perm_app_setup_path failed: " << perm_strerror(result));
-
- result = perm_app_remove_path(APP_1, directory.path().c_str());
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_remove_path failed: " <<
- perm_strerror(result));
-
- DB_END
-
- db_test.test_db_label(label);
- db_test.test_db__perm_app_remove_path(APP_1, directory.path());
- db_test.test_db__perm_app_setup_path(APP_2, directory.path());
-
- DB_BEGIN
-
- result = perm_app_remove_path(APP_2, directory.path().c_str());
- RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, "perm_app_remove_path failed: " <<
- perm_strerror(result));
-
- DB_END
-
- db_test.test_db__perm_app_remove_path(APP_2, directory.path());
- db_test.test_db_not_label(label);
-
- RUNNER_ASSERT_MSG_BT(mkdir(directory.path().c_str(), 0) == -1 && errno == EEXIST,
- "unexpected error " << strerror(errno) <<
- "- perm_app_remove_path removed data from file system?");
-}