};
typedef std::unique_ptr<char, free_deleter> CStringPtr;
+struct list_deleter {
+ void operator()(void* p) {
+ char** list = (char**) p;
+
+ for (int i = 0; list[i] != NULL; ++i) {
+ free(list[i]);
+ }
+
+ free(p);
+ }
+};
+typedef std::unique_ptr<char*, list_deleter> CStringListPtr;
+
+class Directory
+{
+public:
+ Directory(std::string path, mode_t mode) : m_errorCode(0), m_path(path)
+ {
+ if (mkdir(path.c_str(), mode) != 0) {
+ m_errorCode = errno;
+ }
+ }
+
+ Directory(const Directory& directory) = delete;
+
+ Directory(Directory&& directory)
+ : m_errorCode(std::move(directory.m_errorCode)), m_path(std::move(directory.m_path))
+ {
+ directory.m_path = "";
+ }
+
+ const Directory& operator=(const Directory& directory) = delete;
+
+ const Directory& operator=(Directory&& directory)
+ {
+ m_errorCode = directory.m_errorCode;
+ m_path = std::move(directory.m_path);
+ directory.m_path = "";
+
+ return *this;
+ }
+
+ ~Directory()
+ {
+ if (m_errorCode == 0 && !m_path.empty()) {
+ rmdir(m_path.c_str());
+ }
+ }
+
+ bool isCreated() const
+ {
+ return m_errorCode == 0;
+ }
+
+ int errorCode() const
+ {
+ return m_errorCode;
+ }
+
+ const std::string& path() const
+ {
+ return m_path;
+ }
+
+private:
+ int m_errorCode;
+
+ std::string m_path;
+};
+
// Rules from test_privilege_control_rules.smack
const rules_t rules = {
{ APP_ID, "test_book_1", "r" },
RUNNER_ASSERT_MSG(strcmp(result, "Unknown error") == 0,
"Bad message returned for invalid error code: \"" << result << "\"");
}
+
+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(result == PC_OPERATION_SUCCESS,
+ "perm_app_uninstall failed: " << perm_strerror(result));
+
+ result = perm_app_install(APP_ID);
+ RUNNER_ASSERT_MSG(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(result == PC_OPERATION_SUCCESS, "perm_app_get_paths failed: " <<
+ perm_strerror(result));
+ paths.reset(pp_paths);
+
+ RUNNER_ASSERT_MSG(pp_paths != NULL,
+ "perm_app_get_paths failed to set pointer to cstring array");
+ RUNNER_ASSERT_MSG(*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(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(result == PC_OPERATION_SUCCESS, "perm_app_uninstall failed: " <<
+ perm_strerror(result));
+
+ result = perm_app_install(APP_ID);
+ RUNNER_ASSERT_MSG(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(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(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(i < test_paths.size(), "perm_app_get_paths returned too many paths");
+ RUNNER_ASSERT_MSG(test_paths[i].path() == pp_paths[i],
+ "perm_app_get_paths returned unexpected path, " << pp_paths[i] << " != " <<
+ test_paths[i].path());
+ }
+ RUNNER_ASSERT_MSG(i == test_paths.size(), "perm_app_get_paths returned too few paths");
+
+ DB_BEGIN
+
+ result = perm_app_uninstall(APP_ID);
+ RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "perm_app_uninstall failed: " <<
+ perm_strerror(result));
+
+ DB_END
+}
"perm_app_setup_permissions didn't check if pkg_id is valid");
}
+RUNNER_TEST(privilege_control22n_incorrect_params_perm_app_get_paths)
+{
+ char **pp_paths;
+
+ RUNNER_ASSERT_MSG(perm_app_get_paths(NULL, PERM_APP_PATH_PUBLIC,
+ &pp_paths) == PC_ERR_INVALID_PARAM,
+ "perm_app_get_paths didn't check if pkg_id isn't NULL.");
+
+ RUNNER_ASSERT_MSG(perm_app_get_paths(APP_ID, PERM_APP_PATH_PUBLIC,
+ NULL) == PC_ERR_INVALID_PARAM,
+ "perm_app_get_paths didn't check if ppp_paths isn't NULL.");
+
+ RUNNER_ASSERT_MSG(perm_app_get_paths(APP_ID, PERM_APP_PATH_PRIVATE,
+ &pp_paths) == PC_ERR_INVALID_PARAM,
+ "perm_app_get_paths shouldn't accept paths of type PERM_APP_PATH_PRIVATE");
+ RUNNER_ASSERT_MSG(perm_app_get_paths(APP_ID, PERM_APP_PATH_ANY_LABEL,
+ &pp_paths) == PC_ERR_INVALID_PARAM,
+ "perm_app_get_paths should not accept paths of type PERM_APP_PATH_ANY_LABEL");
+}