security-manager-tests: helper API for path request testing 23/68923/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 10 May 2016 10:56:29 +0000 (12:56 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 10 May 2016 10:56:29 +0000 (12:56 +0200)
Add wrappers for path request wrapper and path registration.

Change-Id: Ia5d285b4873ca204fdde1edc0434aa7bf8cf48cf

src/security-manager-tests/common/sm_api.cpp
src/security-manager-tests/common/sm_api.h
src/security-manager-tests/common/sm_request.cpp
src/security-manager-tests/common/sm_request.h

index c4a054c..c664482 100644 (file)
@@ -277,6 +277,14 @@ void getSecurityManagerGroups(char ***groups, size_t *groups_count, lib_retcode
                     << " Result: " << result << " Expected: " << expectedResult);
 }
 
+void registerPaths(const PathsRequest& req, lib_retcode expectedResult)
+{
+    int result = security_manager_paths_register(req.get());
+    RUNNER_ASSERT_MSG(static_cast<lib_retcode>(result) == expectedResult,
+                      "Unexpected result in security_manager_paths_register()" << std::endl
+                      << " Result: " << result << " Expected: " << expectedResult);
+}
+
 } // namespace Api
 
 } // namespace SecurityManagerTest
index 8553303..297add6 100644 (file)
@@ -47,7 +47,7 @@ void getPkgIdBySocket(int socketFd, std::string *pkgId, std::string *appId, lib_
 void getPkgIdByPid(pid_t pid, std::string *pkgId, std::string *appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void appHasPrivilege(const char *appId, const char *privilege, uid_t user, int &value, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void getSecurityManagerGroups(char ***groups, size_t *groups_count, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
-
+void registerPaths(const PathsRequest& req, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 } // namespace Api
 
 } // namespace SecurityManagerTest
index 93b6d87..1a4fc97 100644 (file)
@@ -155,4 +155,82 @@ std::ostream& operator<<(std::ostream &os, const InstallRequest &request)
     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;
+}
+
 } // namespace SecurityManagerTest
index 59b9d2e..c24dc61 100644 (file)
@@ -65,6 +65,34 @@ private:
 
 std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::InstallRequest &request);
 
+class PathsRequest
+{
+public:
+    PathsRequest();
+    PathsRequest(const PathsRequest&) = delete;
+    PathsRequest& operator=(const PathsRequest&) = delete;
+    ~PathsRequest();
+
+    void setPkgId(std::string pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+    void addPath(std::string path, app_install_path_type pathType,
+                 lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+    void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
+    void setInstallType(const enum app_install_type &type, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+
+    //app_inst_req *get() { return m_req; }
+    const path_req *get() const { return m_req; }
+    friend std::ostream& operator<<(std::ostream &, const PathsRequest&);
+
+private:
+    path_req *m_req;
+
+    std::string m_pkgId;
+    std::vector<std::pair<std::string, app_install_path_type> > m_paths;
+    std::pair<bool, uid_t> m_uid;
+};
+
+std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::PathsRequest &request);
+
 } // namespace SecurityManagerTest
 
 #endif // SECURITY_MANAGER_TEST_INSTALLREQUEST