CKM: Multithreaded encryption test
[platform/core/test/security-tests.git] / src / security-manager-tests / test_cases_paths.cpp
1 /*
2  * Copyright (c) 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 #include <app_install_helper.h>
18 #include <dpl/test/test_runner.h>
19 #include <scoped_installer.h>
20 #include <temp_test_user.h>
21 #include <label_generator.h>
22 #include <sm_commons.h>
23
24 using namespace SecurityManagerTest;
25
26 RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_PATHS)
27
28 static void checkPaths(const AppInstallHelper &app, AppInstallHelper::RootType type) {
29     check_path(app.getPrivateDir(0, type), generatePathRWLabel(app.getPkgId()));
30     check_path(app.getPrivateRODir(0, type), generatePathROLabel(app.getPkgId()), false);
31     check_path(app.getPublicDir(type), getPublicPathLabel());
32 }
33
34 RUNNER_TEST(security_manager_101_paths_global_extended)
35 {
36     AppInstallHelper app("sm_test_101");
37     app.createPrivateDir(0, AppInstallHelper::RootType::EXTENDED);
38     app.createPrivateRODir(0, AppInstallHelper::RootType::EXTENDED);
39     app.createPublicDir(AppInstallHelper::RootType::EXTENDED);
40
41     ScopedInstaller install(app);
42
43     checkPaths(app, AppInstallHelper::RootType::EXTENDED);
44 }
45
46 RUNNER_TEST(security_manager_102_paths_local_extended)
47 {
48     TemporaryTestUser user("sm_test_102", GUM_USERTYPE_NORMAL);
49     user.create();
50
51     AppInstallHelper app("sm_test_102", user.getUid());
52     app.createPrivateDir(0, AppInstallHelper::RootType::EXTENDED);
53     app.createPrivateRODir(0, AppInstallHelper::RootType::EXTENDED);
54     app.createPublicDir(AppInstallHelper::RootType::EXTENDED);
55
56     ScopedInstaller install(app);
57
58     checkPaths(app, AppInstallHelper::RootType::EXTENDED);
59 }
60
61 RUNNER_TEST(security_manager_103_paths_global_skel)
62 {
63     AppInstallHelper app("sm_test_103");
64     app.createPrivateDir(0, AppInstallHelper::RootType::SKEL);
65     app.createPrivateRODir(0, AppInstallHelper::RootType::SKEL);
66     app.createPublicDir(AppInstallHelper::RootType::SKEL);
67
68     ScopedInstaller install(app);
69
70     check_path(app.getPrivateDir(0, AppInstallHelper::RootType::SKEL), generatePathRWLabel(app.getPkgId()));
71     // Below doesn't work, because /etc/skel/apps_rw has transmute and label "User::Home", to which "System::Privileged" has a 't' access
72     //check_path(app.getPrivateRODir(0, AppInstallHelper::RootType::SKEL), generatePathROLabel(app.getPkgId()), false);
73     check_path(app.getPublicDir(AppInstallHelper::RootType::SKEL), getPublicPathLabel());
74 }
75
76 RUNNER_TEST(security_manager_104_paths_local_skel)
77 {
78     TemporaryTestUser user("sm_test_104", GUM_USERTYPE_NORMAL);
79     user.create();
80
81     AppInstallHelper app("sm_test_104", user.getUid());
82     app.createPrivateDir(0, AppInstallHelper::RootType::SKEL);
83
84     InstallRequest req;
85     req.setAppId(app.getAppId());
86     req.setPkgId(app.getPkgId());
87     req.setUid(app.getUID());
88     req.addPath(app.getPrivateDir(0, AppInstallHelper::RootType::SKEL), SECURITY_MANAGER_PATH_RW);
89     Api::install(req, SECURITY_MANAGER_ERROR_NOT_PATH_OWNER);
90 }
91