2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @author Marcin Lis (m.lis@samsung.com)
21 * @brief security-manager tests database record check functions
24 #ifndef SECURITY_MANAGER_TEST_DB_H_
25 #define SECURITY_MANAGER_TEST_DB_H_
28 #include "db_sqlite.h"
30 typedef std::vector<std::string> privileges_t;
33 * @class TestSecurityManagerDatabase
34 * @brief Class containing methods for testing libprivlege database.
36 class TestSecurityManagerDatabase
40 * @brief A usefull constant to indicate that app/pkg should be present in db
42 const static bool NOT_REMOVED;
44 * @brief A usefull constant to indicate that app/pkg should not be present in db
46 const static bool REMOVED;
48 * @brief A constructor
50 TestSecurityManagerDatabase();
55 ~TestSecurityManagerDatabase() = default;
58 * @brief Method for testing database after "security_manager_app_install" was run.
60 * It checks existence of proper: - app_name
63 * @param app_name name of the app previously used in security_manager_app_install.
64 * @param pkg_name name of the pkg previously used in security_manager_app_install.
66 void test_db_after__app_install(const std::string &app_name, const std::string &pkg_name);
69 * @brief Method for testing database after "security_manager_app_install" was run.
71 * It checks existence of proper: - app_name
74 * TODO: appPaths are currently not handled directly by security-manager, so they are not tested.
76 * @param app_name name of the app previously used in security_manager_app_install.
77 * @param pkg_name name of the pkg previously used in security_manager_app_install.
78 * @param privileges vector of privileges previously used in security_manager_app_install.
80 void test_db_after__app_install(const std::string &app_name, const std::string &pkg_name,
81 const privileges_t &privileges);
84 * @brief Method for testing database after "security_manager_app_uninstall" was run.
86 * It checks absence of proper: - app_name
87 * - optionally pkg_name
89 * @param app_name name of the app previously used in security_manager_app_uninstall.
90 * @param pkg_name name of the pkg previously used in security_manager_app_uninstall.
91 * @param is_pkg_removed tells if pkg_id is expected to remain in db or not.
93 void test_db_after__app_uninstall(const std::string &app_name, const std::string &pkg_name,
94 const bool is_pkg_removed);
97 * @brief Method for testing database after "security_manager_app_uninstall" was run.
99 * It checks absence of proper: - app_name
100 * - optionally pkg_name
102 * TODO: appPaths are currently not handled directly by security-manager, so they are not tested.
104 * @param app_name name of the app previously used in security_manager_app_uninstall.
105 * @param pkg_name name of the pkg previously used in security_manager_app_uninstall.
106 * @param privileges vector of privileges previously used in security_manager_app_uninstall.
107 * @param is_pkg_removed tells if pkg_id is expected to remain in db or not.
109 void test_db_after__app_uninstall(const std::string &app_name, const std::string &pkg_name,
110 const privileges_t &privileges, const bool is_pkg_removed);
113 * @brief It checks db for existence of a all privileges from install request.
115 * @param app_name name of the app previously used i.e. in security_manager_app_install.
116 * @param pkg_name name of the pkg previously used i.e. in security_manager_app_install.
117 * @param privileges vector of privileges previously used i.e. in security_manager_app_install.
119 void check_privileges(const std::string &app_name, const std::string &pkg_name,
120 const privileges_t &privileges);
123 * @brief It checks in db if all app privileges from install request are removed.
125 * @param app_name name of the app previously used i.e. in security_manager_app_uninstall.
126 * @param pkg_name name of the pkg previously used i.e. in security_manager_app_uninstall.
127 * @param privileges vector of privileges previously used i.e. in security_manager_app_uninstall.
129 void check_privileges_removed(const std::string &app_name, const std::string &pkg_name,
130 const privileges_t &privileges);
133 * @brief Method for setting privilege to groups mapping in security-manager database
135 * @param privilege name of the privilege
136 * @param gids vector of group ids
138 void setup_privilege_gids(const std::string &privilege, const std::vector<gid_t> &gids);
143 * @brief Sqlite3DBase object giving simple access to database
145 * Connection to database is open first time it is needed
146 * and closed in destructor of TestSecurityManagerDatabase.
151 * @brief Check db for [non]existence of given app_name in pkg_name
153 * @param app_name name of application
154 * @param pkg_name name of package
155 * @param is_app_removed tells if app is expected in db
157 void check_app_and_pkg(const std::string &app_name, const std::string &pkg_name,
158 const bool is_app_removed);
161 * @brief Check db for [non]existence of given pkg_name
163 * @param pkg_name name of the package
164 * @param is_pkg_removed tells if pkg is expected in db
166 void check_pkg(const std::string &pkg_name,
167 const bool is_pkg_removed);
170 * @brief Check db for existence of a single privilege.
172 * @param app_name name of application
173 * @param pkg_name application's package name
174 * @param privilege name of the privilege
176 * @return true when privilege present
177 * false when privilege not present
179 bool check_privilege(const std::string &app_name, const std::string &pkg_name,
180 const std::string &privilege);
183 #endif /* SECURITY_MANAGER_TEST_DB_H_ */