SM : Count privacy privileges in app policy tests 61/143061/2
authorZofia Abramowska <z.abramowska@samsung.com>
Tue, 8 Aug 2017 08:13:06 +0000 (10:13 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Tue, 8 Aug 2017 09:46:53 +0000 (11:46 +0200)
Change-Id: I161a7975237cbec143065dacbbae9a90f8e1d2e5

src/security-manager-tests/common/sm_commons.cpp
src/security-manager-tests/common/sm_commons.h
src/security-manager-tests/test_cases_app_policy.cpp
src/security-manager-tests/test_cases_privacy_manager.cpp

index 5010227cdf59974fc24217685f1464ed926a42cb..8f4b740ab5a7e22d91d86b938eaf3b486a676e15 100644 (file)
@@ -32,6 +32,7 @@
 #include <security-manager-types.h>
 #include <app-runtime.h>
 #include <sys/smack.h>
+#include <privilege_info.h>
 
 #include <cynara_test_client.h>
 #include <dpl/test/test_runner.h>
@@ -456,3 +457,15 @@ void runSystemAccessTest(uid_t uid, gid_t gid, const std::string &testPath, int
         runAccessTest(label, uid, gid, testPath, accessType);
 }
 
+bool isPrivilegePrivacy(const std::string &priv) {
+    return (1 == privilege_info_is_privacy(priv.c_str()));
+}
+
+int countPrivacyPrivileges(const PrivilegeVector &privs) {
+    return std::count_if(privs.begin(), privs.end(), isPrivilegePrivacy);
+}
+
+int countPrivacyPrivileges(const std::vector<std::string> &privs) {
+    return std::count_if(privs.begin(), privs.end(), isPrivilegePrivacy);
+}
+
index 70cfb8b8e1587a0982b824608b3cfe097eeefc1a..804e887c7ce97362b0bd58d8c3252aebff575020 100644 (file)
@@ -77,3 +77,7 @@ void runAccessTest(const std::string &label, uid_t uid, gid_t gid,
                    const std::string &testPath, int accessType);
 void runAccessTest(const AppInstallHelper &app, const std::string &testPath, int accessType);
 void runSystemAccessTest(uid_t uid, gid_t gid, const std::string &testPath, int accessType);
+
+bool isPrivilegePrivacy(const std::string &priv);
+int countPrivacyPrivileges(const PrivilegeVector &privs);
+int countPrivacyPrivileges(const std::vector<std::string> &privs);
index 00f99910060447ebfb6f2f5c3bd5b3524f7b4b4f..0ead2538fdf6c2a04850d4c2635ed67e7cd2a185 100644 (file)
@@ -20,6 +20,7 @@
 #include <app_install_helper.h>
 #include <scoped_installer.h>
 #include <sm_api.h>
+#include <sm_commons.h>
 #include <temp_test_user.h>
 #include <tests_common.h>
 
@@ -39,11 +40,13 @@ RUNNER_CHILD_TEST(security_manager_ap1_app_policy_fetch_for_self) {
     TemporaryTestUser tmpUser("sm_test_ap1_user_name", GUM_USERTYPE_NORMAL, false);
     tmpUser.create();
 
-    unsigned expectedPolicyCount = 1;
-
     AppInstallHelper app("sm_test_ap1", tmpUser.getUid());
     app.addPrivileges(TEST_PRIVACY_PRIVILEGES);
 
+    unsigned expectedPolicyCount = countPrivacyPrivileges(app.getPrivileges());
+
+    RUNNER_ASSERT_MSG(expectedPolicyCount > 0, "Application won't be installed with any privacy privileges, fix test");
+
     ScopedInstaller appInstall(app);
 
     pid_t pid = fork();
index 99faed95076d7b97c073f39118b044da50f56dbb..d40e8644fb43a2a7e28aa22c52cb5cd2706b7cc4 100644 (file)
@@ -24,8 +24,6 @@
 #include <utility>
 #include <vector>
 
-#include <privilege_info.h>
-
 #include <app_install_helper.h>
 #include <cynara_test_admin.h>
 #include <dpl/test/test_runner.h>
@@ -95,14 +93,6 @@ const std::vector<Privileges> TEST_PRIVACY_PRIVILEGES = {
     }
 };
 
-bool isPrivilegePrivacy(const Privilege &priv) {
-    return (1 == privilege_info_is_privacy(priv));
-}
-
-int countPrivacyPrivileges(const PrivilegeVector &privs) {
-    return std::count_if(privs.begin(), privs.end(), isPrivilegePrivacy);
-}
-
 }
 
 RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_PRIVACY_MANAGER)