1536a57b5cfc6e8ac5e7b611f70130110845a576
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_db.h
1 /*
2  * Copyright (c) 2014-2016 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 /*
18  * @file        sm_db.h
19  * @author      Marcin Lis (m.lis@samsung.com)
20  * @version     1.0
21  * @brief       security-manager tests database record check functions
22  */
23
24 #ifndef SECURITY_MANAGER_TEST_DB_H_
25 #define SECURITY_MANAGER_TEST_DB_H_
26
27 #include <string>
28 #include "db_sqlite.h"
29
30 typedef std::vector<std::string> privileges_t;
31
32 /**
33  * @class       TestSecurityManagerDatabase
34  * @brief       Class containing methods for testing libprivlege database.
35  */
36 class TestSecurityManagerDatabase
37 {
38 public:
39 /**
40  * @brief A usefull constant to indicate that app/pkg should be present in db
41  */
42     const static bool NOT_REMOVED;
43 /**
44  * @brief A usefull constant to indicate that app/pkg should not be present in db
45  */
46     const static bool REMOVED;
47 /**
48  * @brief A constructor
49  */
50     TestSecurityManagerDatabase();
51
52 /**
53  * @brief A destructor
54  */
55     ~TestSecurityManagerDatabase() = default;
56
57 /**
58  * @brief Method for testing database after "security_manager_app_install" was run.
59  *
60  * It checks existence of proper: - app_name
61  *                                - pkg_name
62  *
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.
65  */
66     void test_db_after__app_install(const std::string &app_name, const std::string &pkg_name);
67
68 /**
69  * @brief Method for testing database after "security_manager_app_uninstall" was run.
70  *
71  * It checks absence of proper: - app_name
72  *                              - optionally pkg_name
73  *
74  * @param  app_name           name of the app previously used in security_manager_app_uninstall.
75  * @param  pkg_name           name of the pkg previously used in security_manager_app_uninstall.
76  * @param  is_pkg_removed     tells if pkg_id is expected to remain in db or not.
77  */
78     void test_db_after__app_uninstall(const std::string &app_name, const std::string &pkg_name,
79                                       const bool is_pkg_removed);
80
81 /**
82  * @brief Method for setting privilege to groups mapping in security-manager database
83  *
84  * @param privilege name of the privilege
85  * @param groups vector of group names
86  */
87     void setup_privilege_groups(const std::string &privilege,
88                                 const std::vector<std::string> &groups);
89
90 /**
91  * @brief Method for getting author id from database.
92  */
93     int64_t get_author_id(const std::string &authorName);
94 /**
95  * @brief Method for path label from database.
96  */
97     std::string get_path_label(const std::string &path);
98 private:
99 /**
100  * @var base
101  * @brief Sqlite3DBase object giving simple access to database
102  *
103  * Connection to database is open first time it is needed
104  * and closed in destructor of TestSecurityManagerDatabase.
105  */
106     Sqlite3DBase m_base;
107
108 /**
109  * @brief Check db for [non]existence of given app_name in pkg_name
110  *
111  * @param  app_name        name of application
112  * @param  pkg_name        name of package
113  * @param  is_app_removed  tells if app is expected in db
114  */
115     void check_app_and_pkg(const std::string &app_name, const std::string &pkg_name,
116                            const bool is_app_removed);
117
118 /**
119  * @brief Check db for [non]existence of given pkg_name
120  *
121  * @param  pkg_name        name of the package
122  * @param  is_pkg_removed  tells if pkg is expected in db
123  */
124     void check_pkg(const std::string &pkg_name,
125                    const bool is_pkg_removed);
126 };
127
128 #endif /* SECURITY_MANAGER_TEST_DB_H_ */