Adjust tests to API change
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_request.h
1 /*
2  * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef SECURITY_MANAGER_TEST_INSTALLREQUEST
18 #define SECURITY_MANAGER_TEST_INSTALLREQUEST
19
20 #include <iostream>
21 #include <string>
22 #include <sys/types.h>
23 #include <utility>
24 #include <vector>
25
26 #include <security-manager.h>
27 #include <app_def_privilege.h>
28
29 namespace SecurityManagerTest {
30 class InstallRequest;
31 void prepare_request(InstallRequest &request,
32                      const std::string &app_id,
33                      const std::string &pkg_id,
34                      app_install_path_type pathType,
35                      const std::string &path,
36                      uid_t uid);
37 class InstallRequest
38 {
39 public:
40     InstallRequest();
41     InstallRequest(const InstallRequest&) = delete;
42     InstallRequest& operator=(const InstallRequest&) = delete;
43     InstallRequest(InstallRequest &&other)
44         : m_req(std::move(other.m_req)),
45           m_appId(std::move(other.m_appId)),
46           m_pkgId(std::move(other.m_pkgId)),
47           m_authorId(std::move(other.m_authorId)),
48           m_privileges(std::move(other.m_privileges)),
49           m_paths(std::move(other.m_paths)),
50           m_uid(std::move(other.m_uid))
51     {
52         other.m_req = nullptr;
53         other.m_uid.first = false;
54         other.m_uid.second = 0;
55     }
56     ~InstallRequest();
57
58     void setAppTizenVersion(std::string tizenVer,
59             lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
60     void setAppId(std::string appId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
61     void setPkgId(std::string pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
62     void addPrivilege(const std::string &privilege, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
63     void addClientPrivilege(const std::pair<std::string, std::string> &privilege, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
64     void addAppDefinedPrivilege(const AppDefinedPrivilege &privilege, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
65     void addPath(std::string path, app_install_path_type pathType,
66                  lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
67     void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
68     void setAuthorId(std::string authorId, lib_retcode expectedResult= SECURITY_MANAGER_SUCCESS);
69     void setInstallType(const enum app_install_type &type, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
70     void setHybrid(lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
71     std::string getAppTizenVersion() const { return m_tizenVer; }
72     app_inst_req *get() { return m_req; }
73     const app_inst_req *get() const { return m_req; }
74     friend std::ostream& operator<<(std::ostream &, const InstallRequest&);
75
76 private:
77     app_inst_req *m_req;
78
79     std::string m_tizenVer;
80     std::string m_appId;
81     std::string m_pkgId;
82     std::string m_authorId;
83     std::vector<std::pair<std::string, std::string>> m_privileges;
84     AppDefinedPrivilegesVector m_appDefinedPrivileges;
85     std::vector<std::pair<std::string, app_install_path_type> > m_paths;
86     std::pair<bool, uid_t> m_uid;
87 };
88
89 std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::InstallRequest &request);
90
91 class PathsRequest
92 {
93 public:
94     PathsRequest();
95     PathsRequest(const PathsRequest&) = delete;
96     PathsRequest& operator=(const PathsRequest&) = delete;
97     ~PathsRequest();
98
99     void setPkgId(std::string pkgId, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
100     void addPath(std::string path, app_install_path_type pathType,
101                  lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
102     void setUid(const uid_t uid, lib_retcode expectedresult = SECURITY_MANAGER_SUCCESS);
103     void setInstallType(const enum app_install_type &type, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
104
105     //app_inst_req *get() { return m_req; }
106     const path_req *get() const { return m_req; }
107     friend std::ostream& operator<<(std::ostream &, const PathsRequest&);
108
109 private:
110     path_req *m_req;
111
112     std::string m_pkgId;
113     std::vector<std::pair<std::string, app_install_path_type> > m_paths;
114     std::pair<bool, uid_t> m_uid;
115 };
116
117 std::ostream& operator<<(std::ostream &os, const SecurityManagerTest::PathsRequest &request);
118
119 } // namespace SecurityManagerTest
120
121 #endif // SECURITY_MANAGER_TEST_INSTALLREQUEST