2 * Copyright (c) 2017 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.
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>
24 using namespace SecurityManagerTest;
26 RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_PATHS)
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());
34 RUNNER_TEST(security_manager_101_paths_global_extended)
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);
41 ScopedInstaller install(app);
43 checkPaths(app, AppInstallHelper::RootType::EXTENDED);
46 RUNNER_TEST(security_manager_102_paths_local_extended)
48 TemporaryTestUser user("sm_test_102", GUM_USERTYPE_NORMAL);
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);
56 ScopedInstaller install(app);
58 checkPaths(app, AppInstallHelper::RootType::EXTENDED);
61 RUNNER_TEST(security_manager_103_paths_global_skel)
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);
68 ScopedInstaller install(app);
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());
76 RUNNER_TEST(security_manager_104_paths_local_skel)
78 TemporaryTestUser user("sm_test_104", GUM_USERTYPE_NORMAL);
81 AppInstallHelper app("sm_test_104", user.getUid());
82 app.createPrivateDir(0, AppInstallHelper::RootType::SKEL);
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);