SM: Code cleanup - separate privacy manager tests
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_commons.h
1 /*
2  * Copyright (c) 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 #pragma once
18
19 #include <string>
20 #include <sys/capability.h>
21 #include <sys/types.h>
22 #include <vector>
23
24 #include <security-manager-types.h>
25
26 #include <app_install_helper.h>
27 #include <memory.h>
28 #include <sm_db.h>
29 #include <temp_test_user.h>
30
31 DEFINE_SMARTPTR(cap_free, _cap_struct, CapsSetsUniquePtr);
32
33 struct app_attributes {
34     std::string package;
35     std::string Tizen_ver;
36 };
37
38 const int FTW_MAX_FDS = 16;
39
40 extern const privileges_t SM_ALLOWED_PRIVILEGES;
41 extern const privileges_t SM_DENIED_PRIVILEGES;
42 extern const privileges_t SM_NO_PRIVILEGES;
43 extern const std::vector<std::string> SM_ALLOWED_GROUPS;
44 static const char *const SM_RW_PATH = "/opt/usr/apps/sm_test_02_pkg_id_full/app_dir";
45
46 const std::string uidToStr(const uid_t uid);
47
48 std::string generateAppLabel(const std::string &appId);
49 std::string generatePkgLabel(const std::string &pkgId);
50 std::string genRWPath(int app_num);
51 std::string genROPath(int app_num);
52 std::string genPublicROPath(int app_num);
53 std::string genOwnerRWOthersROPath(int app_num);
54
55 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
56                        int /*typeflag*/, struct FTW* /*ftwbuf*/);
57 void check_app_permissions(const char *const app_id, const char *const pkg_id,
58                            const char *const user, const privileges_t &allowed_privs,
59                            const privileges_t &denied_privs);
60 void check_app_after_install(const char *const app_id, const char *const pkg_id);
61 void check_app_after_install(const char *const app_id, const char *const pkg_id,
62                              const privileges_t &allowed_privs,
63                              const privileges_t &denied_privs,
64                              const std::vector<std::string> &allowed_groups);
65 void check_path(const std::string &path, const std::string &label);
66 void check_app_path_after_install(int app_num, const char *pkgId, bool others_enabled=false);
67 void check_app_after_uninstall(const char *const app_id, const char *const pkg_id,
68                                const bool is_pkg_removed);
69 void check_app_after_uninstall(const char *const app_id, const char *const pkg_id,
70                                const privileges_t &privileges, const bool is_pkg_removed);
71
72 CapsSetsUniquePtr setCaps(const char *cap_string);
73 void prepare_app_env(int app_num, bool others_enabled = false);
74 void install_app(const char *app_id, const char *pkg_id, uid_t uid = 0,
75                  app_install_type type = SM_APP_INSTALL_NONE, bool check_after = true);
76 void uninstall_app(const char *app_id, const char *pkg_id,
77                    bool expect_pkg_removed = false, app_install_type type = SM_APP_INSTALL_NONE,
78                    bool check_after = true);
79
80 void createTestDirs(const TemporaryTestUser &user,
81                     const std::string &appId, const std::string &pkgId);
82 void removeTestDirs(const TemporaryTestUser &user,
83                     const std::string &appId, const std::string &pkgId);