SM : Add tests for external paths of application 83/162483/1
authorZofia Abramowska <z.abramowska@samsung.com>
Fri, 20 Oct 2017 14:51:23 +0000 (16:51 +0200)
committerZofia Grzelewska <z.abramowska@samsung.com>
Fri, 1 Dec 2017 16:21:47 +0000 (17:21 +0100)
Change-Id: If20436654fca450881c8504984ea4501cc4b62b7

src/security-manager-tests/CMakeLists.txt
src/security-manager-tests/test_cases_paths.cpp [new file with mode: 0644]

index 9d9bcf8..46e51d8 100644 (file)
@@ -46,6 +46,7 @@ SET(SEC_MGR_SOURCES
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_credentials.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_dyntransition.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_nss.cpp
+    ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_paths.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_privacy_manager.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_private_sharing.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_public_sharing.cpp
diff --git a/src/security-manager-tests/test_cases_paths.cpp b/src/security-manager-tests/test_cases_paths.cpp
new file mode 100644 (file)
index 0000000..6e6652f
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include <app_install_helper.h>
+#include <dpl/test/test_runner.h>
+#include <scoped_installer.h>
+#include <temp_test_user.h>
+#include <label_generator.h>
+#include <sm_commons.h>
+
+using namespace SecurityManagerTest;
+
+RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_PATHS)
+
+static void checkPaths(const AppInstallHelper &app, AppInstallHelper::RootType type) {
+    check_path(app.getPrivateDir(0, type), generatePathRWLabel(app.getPkgId()));
+    check_path(app.getPrivateRODir(0, type), generatePathROLabel(app.getPkgId()), false);
+    check_path(app.getPublicDir(type), getPublicPathLabel());
+}
+
+RUNNER_TEST(security_manager_101_paths_global_extended)
+{
+    AppInstallHelper app("sm_test_101");
+    app.createPrivateDir(0, AppInstallHelper::RootType::EXTENDED);
+    app.createPrivateRODir(0, AppInstallHelper::RootType::EXTENDED);
+    app.createPublicDir(AppInstallHelper::RootType::EXTENDED);
+
+    ScopedInstaller install(app);
+
+    checkPaths(app, AppInstallHelper::RootType::EXTENDED);
+}
+
+RUNNER_TEST(security_manager_102_paths_local_extended)
+{
+    TemporaryTestUser user("sm_test_102", GUM_USERTYPE_NORMAL);
+    user.create();
+
+    AppInstallHelper app("sm_test_102", user.getUid());
+    app.createPrivateDir(0, AppInstallHelper::RootType::EXTENDED);
+    app.createPrivateRODir(0, AppInstallHelper::RootType::EXTENDED);
+    app.createPublicDir(AppInstallHelper::RootType::EXTENDED);
+
+    ScopedInstaller install(app);
+
+    checkPaths(app, AppInstallHelper::RootType::EXTENDED);
+}
+
+RUNNER_TEST(security_manager_103_paths_global_skel)
+{
+    AppInstallHelper app("sm_test_103");
+    app.createPrivateDir(0, AppInstallHelper::RootType::SKEL);
+    app.createPrivateRODir(0, AppInstallHelper::RootType::SKEL);
+    app.createPublicDir(AppInstallHelper::RootType::SKEL);
+
+    ScopedInstaller install(app);
+
+    check_path(app.getPrivateDir(0, AppInstallHelper::RootType::SKEL), generatePathRWLabel(app.getPkgId()));
+    // Below doesn't work, because /etc/skel/apps_rw has transmute and label "User::Home", to which "System::Privileged" has a 't' access
+    //check_path(app.getPrivateRODir(0, AppInstallHelper::RootType::SKEL), generatePathROLabel(app.getPkgId()), false);
+    check_path(app.getPublicDir(AppInstallHelper::RootType::SKEL), getPublicPathLabel());
+}
+
+RUNNER_TEST(security_manager_104_paths_local_skel)
+{
+    TemporaryTestUser user("sm_test_104", GUM_USERTYPE_NORMAL);
+    user.create();
+
+    AppInstallHelper app("sm_test_104", user.getUid());
+    app.createPrivateDir(0, AppInstallHelper::RootType::SKEL);
+
+    InstallRequest req;
+    req.setAppId(app.getAppId());
+    req.setPkgId(app.getPkgId());
+    req.setUid(app.getUID());
+    req.addPath(app.getPrivateDir(0, AppInstallHelper::RootType::SKEL), SECURITY_MANAGER_PATH_RW);
+    Api::install(req, SECURITY_MANAGER_ERROR_NOT_PATH_OWNER);
+}
+