Add security-manager tests. 53/20753/11
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 8 May 2014 18:28:43 +0000 (20:28 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Tue, 20 May 2014 06:30:35 +0000 (08:30 +0200)
security-manager service has been added to security-server repository.
See:
-> 'Implement installer service'
-> 'Added security-manager API'

Verification:
-> security-tests.sh security-manager --output=text
   (test should pass)

Change-Id: Idb69adada46864373208eb932f46402a4561e31e

14 files changed:
packaging/security-tests.manifest
packaging/security-tests.spec
tests/CMakeLists.txt
tests/libprivilege-control-tests/common/libprivilege-control_test_common.h
tests/libprivilege-control-tests/libprivilege-control_test_common.cpp
tests/libprivilege-control-tests/test_cases.cpp
tests/security-manager-tests/CMakeLists.txt [new file with mode: 0644]
tests/security-manager-tests/WRT_security_manager_test_rules1.smack [new file with mode: 0644]
tests/security-manager-tests/WRT_security_manager_test_rules2.smack [new file with mode: 0644]
tests/security-manager-tests/WRT_security_manager_test_rules2_no_r.smack [new file with mode: 0644]
tests/security-manager-tests/WRT_security_manager_test_rules2_r.smack [new file with mode: 0644]
tests/security-manager-tests/security_manager_tests.cpp [new file with mode: 0644]
tests/security-tests-all.sh
tests/security-tests.sh

index 22a9b7e..23852f5 100644 (file)
@@ -14,6 +14,7 @@
         <filesystem path="/usr/bin/security-server-tests-password" exec_label="_" />
         <filesystem path="/usr/bin/security-server-tests-stress" exec_label="_" />
         <filesystem path="/usr/bin/security-server-tests-dbus" exec_label="_" />
+        <filesystem path="/usr/bin/security-manager-tests" exec_label="_" />
 
         <filesystem path="/usr/bin/hello-tizen" exec_label="User" />
     </assign>
index ccce7cf..113f1fe 100644 (file)
@@ -11,6 +11,7 @@ BuildRequires: cmake
 BuildRequires: pkgconfig(libsmack)
 BuildRequires: pkgconfig(libprivilege-control)
 BuildRequires: pkgconfig(security-server)
+BuildRequires: pkgconfig(security-manager)
 BuildRequires: pkgconfig(dpl-test-efl)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(dbus-1)
@@ -80,6 +81,7 @@ osp-installer -u uqNfgEjqc7
 /etc/smack/test_smack_rules4
 /usr/bin/security-server-tests-mt
 /usr/bin/security-server-tests-api-speed
+/usr/bin/security-manager-tests
 /etc/smack/test_smack_rules
 /etc/smack/test_smack_rules_lnk
 /usr/share/privilege-control/*
index 27b1f8b..c98a356 100644 (file)
@@ -63,3 +63,4 @@ ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(libprivilege-control-tests)
 ADD_SUBDIRECTORY(libsmack-tests)
 ADD_SUBDIRECTORY(security-server-tests)
+ADD_SUBDIRECTORY(security-manager-tests)
index a89ff95..20f773a 100644 (file)
@@ -212,6 +212,10 @@ void check_groups(const std::set<unsigned> &groups_prev, const char *dac_file);
 int file_exists(const char *path);
 void check_app_installed(const char *app_path);
 
+void check_perm_app_has_permission(const char *app_label,
+                                   const char *permission,
+                                   bool is_enabled_expected);
+
 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
                        int /*typeflag*/, struct FTW* /*ftwbuf*/);
 int nftw_check_labels_app_private_dir(const char *fpath, const struct stat *sb,
index 357db17..6eaa018 100644 (file)
@@ -64,15 +64,12 @@ const char *PRIV_APPSETTING_RULES[] = { "~APP~ ~SETTINGS_PATH~ rwx",
  */
 int test_have_all_accesses(const rules_t &rules)
 {
-    int result = 1;
-    for (uint i = 0; i < rules.size(); ++i) {
+    for (size_t i = 0; i < rules.size(); ++i) {
         int access = smack_have_access(rules[i][0].c_str(),rules[i][1].c_str(),rules[i][2].c_str());
-        if (access < 0)
-            return -1;
-        if (access == 0)
-            result = 0;
+        if (access <= 0)
+            return 0;
     }
-    return result;
+    return 1;
 }
 
 /**
@@ -81,15 +78,12 @@ int test_have_all_accesses(const rules_t &rules)
  */
 int test_have_any_accesses(const rules_t &rules)
 {
-    int result = 0;
-    for (uint i = 0; i < rules.size(); ++i) {
+    for (size_t i = 0; i < rules.size(); ++i) {
         int access = smack_have_access(rules[i][0].c_str(),rules[i][1].c_str(),rules[i][2].c_str());
-        if (access < 0)
-            return -1;
         if (access > 0)
-            result = 1;
+            return 1;
     }
-    return result;
+    return 0;
 }
 
 /**
@@ -242,6 +236,21 @@ int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
     return 0;
 }
 
+void check_perm_app_has_permission(const char *app_label,
+                                   const char *permission,
+                                   bool is_enabled_expected)
+{
+    int result;
+    bool is_enabled_result;
+
+    result = perm_app_has_permission(app_label, APP_TYPE_WGT, permission, &is_enabled_result);
+    RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+            " Error calling perm_app_has_permission. Result: " << result);
+
+    RUNNER_ASSERT_MSG_BT(is_enabled_result == is_enabled_expected,
+            " Result of perm_app_has_permission should be: " << is_enabled_expected);
+}
+
 int nftw_check_labels_app_dir(const char *fpath, const struct stat *sb,
                               const char* correctLabel)
 {
index c88e35a..f96f4ff 100644 (file)
@@ -860,19 +860,6 @@ RUNNER_MULTIPROCESS_TEST_SMACK(privilege_control15_app_id_from_socket)
     }
 }
 
-void check_perm_app_has_permission(const char* app_label, const char* permission, bool is_enabled_expected)
-{
-    int result;
-    bool is_enabled;
-
-    result = perm_app_has_permission(app_label, APP_TYPE_WGT, permission, &is_enabled);
-    RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
-            "Error calling perm_app_has_permission. Result: " << result);
-
-    RUNNER_ASSERT_MSG_BT(is_enabled == is_enabled_expected,
-            "Result of perm_app_has_permission should be: " << is_enabled_expected);
-}
-
 RUNNER_TEST(privilege_control20_perm_app_has_permission)
 {
     int result;
diff --git a/tests/security-manager-tests/CMakeLists.txt b/tests/security-manager-tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..59af8af
--- /dev/null
@@ -0,0 +1,74 @@
+#
+#Copyright (c) 2014 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.
+#
+# @file        CMakeLists.txt
+# @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
+# @brief
+#
+
+INCLUDE(FindPkgConfig)
+
+# Dependencies
+PKG_CHECK_MODULES(SEC_MGR_TESTS_DEP
+    REQUIRED
+    libsmack
+    libprivilege-control
+    security-manager
+    dpl-test-efl)
+
+
+SET(TARGET_SEC_MGR_TESTS "security-manager-tests")
+
+SET(SEC_MGR_SOURCES
+    ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/security_manager_tests.cpp
+    ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/libprivilege-control_test_common.cpp
+   )
+
+INCLUDE_DIRECTORIES(SYSTEM
+    ${SEC_MGR_TESTS_DEP_INCLUDE_DIRS}
+   )
+
+INCLUDE_DIRECTORIES(
+    ${PROJECT_SOURCE_DIR}/tests/common/
+    ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/common/
+   )
+
+ADD_EXECUTABLE(${TARGET_SEC_MGR_TESTS} ${SEC_MGR_SOURCES})
+
+TARGET_LINK_LIBRARIES(${TARGET_SEC_MGR_TESTS}
+    ${SEC_MGR_TESTS_DEP_LIBRARIES}
+    tests-common)
+
+INSTALL(TARGETS ${TARGET_SEC_MGR_TESTS} DESTINATION /usr/bin)
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/WRT_security_manager_test_rules1.smack
+    DESTINATION /usr/share/privilege-control/
+  )
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/WRT_security_manager_test_rules2.smack
+    DESTINATION /usr/share/privilege-control/
+  )
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/WRT_security_manager_test_rules2_no_r.smack
+    DESTINATION /usr/share/privilege-control/
+  )
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/security-manager-tests/WRT_security_manager_test_rules2_r.smack
+    DESTINATION /usr/share/privilege-control/
+  )
diff --git a/tests/security-manager-tests/WRT_security_manager_test_rules1.smack b/tests/security-manager-tests/WRT_security_manager_test_rules1.smack
new file mode 100644 (file)
index 0000000..0dfa560
--- /dev/null
@@ -0,0 +1,14 @@
+~APP~ test_sm_book_1 r
+~APP~ test_sm_book_2 w
+~APP~ test_sm_book_3 x
+~APP~ test_sm_book_4 rw
+~APP~ test_sm_book_5 rx
+~APP~ test_sm_book_6 wx
+~APP~ test_sm_book_7 rwx
+test_sm_subject_1 ~APP~ r
+test_sm_subject_2 ~APP~ w
+test_sm_subject_3 ~APP~ x
+test_sm_subject_4 ~APP~ rw
+test_sm_subject_5 ~APP~ rx
+test_sm_subject_6 ~APP~ wx
+test_sm_subject_7 ~APP~ rwx
diff --git a/tests/security-manager-tests/WRT_security_manager_test_rules2.smack b/tests/security-manager-tests/WRT_security_manager_test_rules2.smack
new file mode 100644 (file)
index 0000000..da67f85
--- /dev/null
@@ -0,0 +1,16 @@
+~APP~ test_sm_book_8 r
+~APP~ test_sm_book_9 w
+~APP~ test_sm_book_10 x
+~APP~ test_sm_book_11 rw
+~APP~ test_sm_book_12 rx
+~APP~ test_sm_book_13 wx
+~APP~ test_sm_book_14 rwx
+~APP~ test_sm_book_15 rwxat
+test_sm_subject_8 ~APP~ r
+test_sm_subject_9 ~APP~ w
+test_sm_subject_10 ~APP~ x
+test_sm_subject_11 ~APP~ rw
+test_sm_subject_12 ~APP~ rx
+test_sm_subject_13 ~APP~ wx
+test_sm_subject_14 ~APP~ rwx
+test_sm_subject_15 ~APP~ rwxat
diff --git a/tests/security-manager-tests/WRT_security_manager_test_rules2_no_r.smack b/tests/security-manager-tests/WRT_security_manager_test_rules2_no_r.smack
new file mode 100644 (file)
index 0000000..693a26a
--- /dev/null
@@ -0,0 +1,14 @@
+~APP~ test_sm_book_9 w
+~APP~ test_sm_book_10 x
+~APP~ test_sm_book_11 w
+~APP~ test_sm_book_12 x
+~APP~ test_sm_book_13 wx
+~APP~ test_sm_book_14 wx
+~APP~ test_sm_book_15 wxat
+test_sm_subject_9 ~APP~ w
+test_sm_subject_10 ~APP~ x
+test_sm_subject_11 ~APP~ w
+test_sm_subject_12 ~APP~ x
+test_sm_subject_13 ~APP~ wx
+test_sm_subject_14 ~APP~ wx
+test_sm_subject_15 ~APP~ wxat
diff --git a/tests/security-manager-tests/WRT_security_manager_test_rules2_r.smack b/tests/security-manager-tests/WRT_security_manager_test_rules2_r.smack
new file mode 100644 (file)
index 0000000..8d2d49b
--- /dev/null
@@ -0,0 +1,10 @@
+~APP~ test_sm_book_8 r
+~APP~ test_sm_book_11 r
+~APP~ test_sm_book_12 r
+~APP~ test_sm_book_14 r
+~APP~ test_sm_book_15 r
+test_sm_subject_8 ~APP~ r
+test_sm_subject_11 ~APP~ r
+test_sm_subject_12 ~APP~ r
+test_sm_subject_14 ~APP~ r
+test_sm_subject_15 ~APP~ r
diff --git a/tests/security-manager-tests/security_manager_tests.cpp b/tests/security-manager-tests/security_manager_tests.cpp
new file mode 100644 (file)
index 0000000..d1d26a7
--- /dev/null
@@ -0,0 +1,184 @@
+#include <dpl/test/test_runner.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <memory.h>
+#include <summary_collector.h>
+
+#include <libprivilege-control_test_common.h>
+#include <tests_common.h>
+
+#include <security-manager.h>
+
+DEFINE_SMARTPTR(security_manager_app_inst_req_free, app_inst_req, AppInstReqUniquePtr);
+
+static const char* SM_APP_ID = "sm_test_app_id";
+static const char* SM_PKG_ID = "sm_test_pkg_id";
+
+static uid_t SM_ALLOWED_UID1 = 6666;
+static uid_t SM_ALLOWED_UID2 = 7777;
+
+static const char* SM_ALLOWED_PERMISSION1 = "security_manager_test_rules2_r";
+static const char* SM_ALLOWED_PERMISSION2 = "security_manager_test_rules2_no_r";
+
+static const rules_t SM_ALLOWED_RULES = {
+    { USER_APP_ID, "test_sm_book_8", "r" },
+    { USER_APP_ID, "test_sm_book_9", "w" },
+    { USER_APP_ID, "test_sm_book_10", "x" },
+    { USER_APP_ID, "test_sm_book_11", "rw" },
+    { USER_APP_ID, "test_sm_book_12", "rx" },
+    { USER_APP_ID, "test_sm_book_13", "wx" },
+    { USER_APP_ID, "test_sm_book_14", "rwx" },
+    { USER_APP_ID, "test_sm_book_15", "rwxat" },
+    { "test_sm_subject_8", USER_APP_ID, "r" },
+    { "test_sm_subject_9", USER_APP_ID, "w" },
+    { "test_sm_subject_10", USER_APP_ID, "x" },
+    { "test_sm_subject_11", USER_APP_ID, "rw" },
+    { "test_sm_subject_12", USER_APP_ID, "rx" },
+    { "test_sm_subject_13", USER_APP_ID, "wx" },
+    { "test_sm_subject_14", USER_APP_ID, "rwx" },
+    { "test_sm_subject_15", USER_APP_ID, "rwxat" }
+};
+static const rules_t SM_DENIED_RULES = {
+    { USER_APP_ID, "test_sm_book_1", "r" },
+    { USER_APP_ID, "test_sm_book_2", "w" },
+    { USER_APP_ID, "test_sm_book_3", "x" },
+    { USER_APP_ID, "test_sm_book_4", "rw" },
+    { USER_APP_ID, "test_sm_book_5", "rx" },
+    { USER_APP_ID, "test_sm_book_6", "wx" },
+    { USER_APP_ID, "test_sm_book_7", "rwx" },
+    { "test_sm_subject_1", USER_APP_ID, "r" },
+    { "test_sm_subject_2", USER_APP_ID, "w" },
+    { "test_sm_subject_3", USER_APP_ID, "x" },
+    { "test_sm_subject_4", USER_APP_ID, "rw" },
+    { "test_sm_subject_5", USER_APP_ID, "rx" },
+    { "test_sm_subject_6", USER_APP_ID, "wx" },
+    { "test_sm_subject_7", USER_APP_ID, "rwx" }
+};
+
+static const char* SM_DENIED_PERMISSION1 = "security_manager_test_rules1";
+static const char* SM_DENIED_PERMISSION2 = "security_manager_test_rules2";
+
+static const char* SM_ALLOWED_PATH = TEST_APP_DIR;
+static const char* SM_DENIED_PATH = TEST_NON_APP_DIR;
+
+RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER)
+
+static app_inst_req* do_app_inst_req_new()
+{
+    int result;
+    app_inst_req *req = NULL;
+
+    result = security_manager_app_inst_req_new(&req);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "creation of new request failed. Result: " << result);
+    RUNNER_ASSERT_MSG_BT(req != NULL, "creation of new request did not allocate memory");
+    return req;
+}
+
+static void prepare_app_path()
+{
+    int result;
+
+    result = nftw(SM_ALLOWED_PATH, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG_BT(result == 0, "Unable to clean Smack labels in " << SM_ALLOWED_PATH);
+
+    result = nftw(SM_DENIED_PATH, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG_BT(result == 0, "Unable to set Smack labels in " << SM_DENIED_PATH);
+}
+
+static void check_app_path_after_install()
+{
+    int result;
+
+    result = nftw(SM_ALLOWED_PATH, &nftw_check_labels_app_private_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG_BT(result == 0, "Unable to check Smack labels for " << SM_ALLOWED_PATH);
+
+    result = nftw(SM_DENIED_PATH, &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG_BT(result == 0, "Unable to check Smack labels for " << SM_DENIED_PATH);
+}
+
+static void check_app_permission_after_install()
+{
+    bool result;
+
+    result = check_all_accesses(smack_check(), SM_ALLOWED_RULES);
+    RUNNER_ASSERT_MSG_BT(result, "Permissions not added.");
+    result = check_no_accesses(smack_check(), SM_DENIED_RULES);
+    RUNNER_ASSERT_MSG_BT(result, "Permissions added.");
+
+    check_perm_app_has_permission(USER_APP_ID, SM_ALLOWED_PERMISSION1, true);
+    check_perm_app_has_permission(USER_APP_ID, SM_ALLOWED_PERMISSION2, true);
+    check_perm_app_has_permission(USER_APP_ID, SM_DENIED_PERMISSION1, false);
+    check_perm_app_has_permission(USER_APP_ID, SM_DENIED_PERMISSION2, false);
+}
+
+static void prepare_app_env()
+{
+    prepare_app_path();
+}
+
+static void check_app_env_after_install()
+{
+    check_app_path_after_install();
+    check_app_permission_after_install();
+}
+
+RUNNER_TEST(security_manager_01_app_install_unsinstall)
+{
+    int result;
+    AppInstReqUniquePtr request;
+
+    prepare_app_env();
+
+    request.reset(do_app_inst_req_new());
+
+    result = security_manager_app_inst_req_set_app_id(request.get(), SM_APP_ID);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting app id failed. Result: " << result);
+
+    result = security_manager_app_inst_req_set_pkg_id(request.get(), SM_PKG_ID);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting pkg id failed. Result: " << result);
+
+    result = security_manager_app_inst_req_add_allowed_user(request.get(), SM_ALLOWED_UID1);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting allowed user failed. Result: " << result);
+    result = security_manager_app_inst_req_add_allowed_user(request.get(), SM_ALLOWED_UID2);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting allowed user failed. Result: " << result);
+
+    result = security_manager_app_inst_req_add_privilege(request.get(), SM_ALLOWED_PERMISSION1);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting allowed permission failed. Result: " << result);
+    result = security_manager_app_inst_req_add_privilege(request.get(), SM_ALLOWED_PERMISSION2);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting allowed permission failed. Result: " << result);
+
+    result = security_manager_app_inst_req_add_path(request.get(), SM_ALLOWED_PATH,
+                                                    SECURITY_MANAGER_PATH_PRIVATE);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting allowed path failed. Result: " << result);
+
+    result = security_manager_app_install(request.get());
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "installing app failed. Result: " << result);
+
+    check_app_env_after_install();
+
+    request.reset(do_app_inst_req_new());
+
+    result = security_manager_app_inst_req_set_app_id(request.get(), SM_APP_ID);
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "setting app id failed. Result: " << result);
+
+    result = security_manager_app_uninstall(request.get());
+    RUNNER_ASSERT_MSG_BT((lib_retcode)result == SECURITY_MANAGER_SUCCESS,
+            "uninstalling app failed. Result: " << result);
+
+}
+
+int main(int argc, char *argv[])
+{
+    SummaryCollector::Register();
+    return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
+}
index 32063c0..4c171c0 100644 (file)
@@ -22,6 +22,7 @@ security-tests.sh ss-server --output=text --output=summary $ign
 security-tests.sh ss-password --output=text --output=summary $ign
 security-tests.sh ss-dbus --output=text --output=summary $ign
 security-tests.sh ss-stress --output=text --output=summary $ign
+security-tests.sh security-manager --output=text --output=summary $ign
 
 # print summary
 tests-summary.sh $summary_file
index 2f87cbc..5b5036e 100644 (file)
@@ -70,12 +70,20 @@ case $1 in
     echo
     security-server-tests-dbus "${@:2}"
     ;;
+"security-manager")
+    echo "========================================================================="
+    echo "SECURITY MANAGER TESTS"
+    echo
+    security-manager-tests "${@:2}"
+    ;;
+
 *)
     echo "Correct using:"
     echo "    security_test.sh <module> <args_for_module>"
     echo
     echo "modules: smack, libprivilege-control, ss-clientsmack"
     echo "         ss-server, ss-api-speed, ss-password, ss-stress"
+    echo "         security-manager"
     ;;
 
 esac