/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace SecurityManagerTest {
+void prepare_request(InstallRequest &request,
+ const std::string &app_id,
+ const std::string &pkg_id,
+ app_install_path_type pathType,
+ const std::string &path,
+ uid_t uid)
+{
+ request.setAppId(app_id);
+ request.setPkgId(pkg_id);
+ request.addPath(path, pathType);
+
+ if (uid != 0)
+ request.setUid(uid);
+}
+
InstallRequest::InstallRequest()
: m_req(nullptr)
, m_tizenVer("3.0")
- , m_appId(nullptr)
- , m_pkgId(nullptr)
, m_uid(false, 0)
{
int result = security_manager_app_inst_req_new(&m_req);
security_manager_app_inst_req_free(m_req);
}
-void InstallRequest::setAppTizenVersion(const char * tizenVer, lib_retcode expectedResult)
+void InstallRequest::setAppTizenVersion(std::string tizenVer, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_set_target_version(m_req, tizenVer);
+ int result = security_manager_app_inst_req_set_target_version(m_req, tizenVer.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting app id returned wrong value."
<< " Tizen version: " << tizenVer << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_tizenVer = std::string(tizenVer);
+ m_tizenVer = std::move(tizenVer);
}
-void InstallRequest::setAppId(const char *appId, lib_retcode expectedResult)
+void InstallRequest::setAppId(std::string appId, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_set_app_id(m_req, appId);
+ int result = security_manager_app_inst_req_set_app_id(m_req, appId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting app id returned wrong value."
<< " App id: " << appId << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_appId = appId;
+ m_appId = std::move(appId);
}
-void InstallRequest::setPkgId(const char *pkgId, lib_retcode expectedResult)
+void InstallRequest::setPkgId(std::string pkgId, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId);
+ int result = security_manager_app_inst_req_set_pkg_id(m_req, pkgId.c_str());
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"setting pkg id returned wrong value."
<< " Pkg id: " << pkgId << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_pkgId = pkgId;
+ m_pkgId = std::move(pkgId);
}
void InstallRequest::addPrivilege(const char *privilege, lib_retcode expectedResult)
<< " Privilege: " << privilege << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_privileges.push_back(privilege);
+ m_privileges.push_back(strdup(privilege));
}
-void InstallRequest::addPath(const char *path, app_install_path_type pathType, lib_retcode expectedResult)
+void InstallRequest::addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult)
{
- int result = security_manager_app_inst_req_add_path(m_req, path, pathType);
+ int result = security_manager_app_inst_req_add_path(m_req, path.c_str(), pathType);
RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
"adding path returned wrong value."
<< " Path: " << path << ";"
<< " Path type: " << pathType << ";"
<< " Result: " << result << ";"
<< " Expected result: " << expectedResult);
- m_paths.push_back(std::pair<std::string, app_install_path_type>(path, pathType));
+ m_paths.emplace_back(std::pair<std::string, app_install_path_type>(std::move(path), pathType));
}
void InstallRequest::setUid(const uid_t uid, lib_retcode expectedResult)
m_uid.second = uid;
}
+void InstallRequest::setAuthorId(std::string authorId, lib_retcode expectedResult)
+{
+ int result = security_manager_app_inst_req_set_author_id(m_req, authorId.c_str());
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting author id returned wrong value."
+ << " Author id: " << m_authorId << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_authorId = std::move(authorId);
+}
+
+void InstallRequest::setInstallType(const enum app_install_type &type, lib_retcode expectedResult)
+{
+ int result = security_manager_app_inst_req_set_install_type(m_req, type);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting install type returned wrong value."
+ << " Install type: " << type << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+}
+
std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
{
- if (request.m_appId != nullptr)
+ if (!request.m_appId.empty())
os << "app id: " << request.m_appId << "; ";
- if (request.m_pkgId != nullptr)
+ if (!request.m_pkgId.empty())
os << "pkg id: " << request.m_pkgId << "; ";
if (!request.m_privileges.empty()) {
os << "privileges: [ " << request.m_privileges[0];
}
if (request.m_uid.first)
os << "uid: " << request.m_uid.second << "; ";
+ if (!request.m_authorId.empty()) {
+ os << "author id: " << request.m_authorId << "; ";
+ }
+ return os;
+}
+
+PathsRequest::PathsRequest()
+ : m_req(nullptr)
+ , m_uid(false, 0)
+{
+ int result = security_manager_path_req_new(&m_req);
+ RUNNER_ASSERT_MSG((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+ "creation of new request failed. Result: " << result);
+ RUNNER_ASSERT_MSG(m_req != nullptr, "creation of new request did not allocate memory");
+}
+
+PathsRequest::~PathsRequest()
+{
+ security_manager_path_req_free(m_req);
+}
+
+void PathsRequest::setPkgId(std::string pkgId, lib_retcode expectedResult)
+{
+ int result = security_manager_path_req_set_pkg_id(m_req, pkgId.c_str());
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting pkg id returned wrong value."
+ << " Pkg id: " << pkgId << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_pkgId = std::move(pkgId);
+}
+
+void PathsRequest::addPath(std::string path, app_install_path_type pathType, lib_retcode expectedResult)
+{
+ int result = security_manager_path_req_add_path(m_req, path.c_str(), pathType);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "adding path returned wrong value."
+ << " Path: " << path << ";"
+ << " Path type: " << pathType << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_paths.emplace_back(std::pair<std::string, app_install_path_type>(std::move(path), pathType));
+}
+
+void PathsRequest::setUid(const uid_t uid, lib_retcode expectedResult)
+{
+ int result = security_manager_path_req_set_uid(m_req, uid);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting uid returned wrong value."
+ << " Uid: " << uid << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+ m_uid.first = true;
+ m_uid.second = uid;
+}
+
+void PathsRequest::setInstallType(const enum app_install_type &type, lib_retcode expectedResult)
+{
+ int result = security_manager_path_req_set_install_type(m_req, type);
+ RUNNER_ASSERT_MSG((lib_retcode)result == expectedResult,
+ "setting install type returned wrong value."
+ << " Install type: " << type << ";"
+ << " Result: " << result << ";"
+ << " Expected result: " << expectedResult);
+}
+
+std::ostream& operator<<(std::ostream &os, const PathsRequest &request)
+{
+ if (!request.m_pkgId.empty())
+ os << "pkg id: " << request.m_pkgId << "; ";
+ if (!request.m_paths.empty()) {
+ os << "paths: [ " << "< " << request.m_paths[0].first << "; "
+ << request.m_paths[0].second << " >";
+ for (size_t i=1; i < request.m_paths.size(); ++i) {
+ os << "; < " << request.m_paths[i].first << "; "
+ << request.m_paths[i].second << " >";
+ }
+ os << " ]";
+ }
+ if (request.m_uid.first)
+ os << "uid: " << request.m_uid.second << "; ";
return os;
}