Unify privilege representation
[platform/core/test/security-tests.git] / src / security-manager-tests / test_cases_prepare_app.cpp
index 32dad32..cf72e77 100644 (file)
 #include <sm_commons.h>
 #include <memory.h>
 #include <tests_common.h>
+#include <privilege_names.h>
 
 using namespace SecurityManagerTest;
+using namespace PrivilegeNames;
 
 namespace {
 bool finish = false;
@@ -45,9 +47,6 @@ const size_t THREADS = 10;
 
 const std::string APP_TEST_USER = "app_test_user";
 
-const std::string EXTERNAL_STORAGE_PRIVILEGE = "http://tizen.org/privilege/externalstorage";
-const std::string MEDIA_STORAGE_PRIVILEGE = "http://tizen.org/privilege/mediastorage";
-
 const std::string ACCESS_DENIED_DIR_PATH = "/usr/share/security-manager/dummy";
 const std::string EXTERNAL_STORAGE_DIR_PATH = "/opt/media";
 const std::string MEDIA_STORAGE_RW_DIR_PATH = "/opt/usr/media";
@@ -307,8 +306,7 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
     tmpUser.create();
 
     AppInstallHelper app("app103", tmpUser.getUid());
-    app.addPrivilege(EXTERNAL_STORAGE_PRIVILEGE);
-    app.addPrivilege(MEDIA_STORAGE_PRIVILEGE);
+    app.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE});
     ScopedInstaller appInstall(app);
 
     SynchronizationPipe synchPipe;
@@ -335,11 +333,11 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
         RUNNER_ASSERT_ERRNO_MSG(result == false, "path is bound");
 
         PolicyRequest policyRequest;
-        PolicyEntry policyEntry(app.getAppId(), std::to_string(tmpUser.getUid()), EXTERNAL_STORAGE_PRIVILEGE);
+        PolicyEntry policyEntry(app.getAppId(), std::to_string(tmpUser.getUid()), PRIV_EXTERNALSTORAGE);
         policyEntry.setLevel(PolicyEntry::LEVEL_DENY);
         policyRequest.addEntry(policyEntry);
 
-        policyEntry = PolicyEntry(app.getAppId(), std::to_string(tmpUser.getUid()), MEDIA_STORAGE_PRIVILEGE);
+        policyEntry = PolicyEntry(app.getAppId(), std::to_string(tmpUser.getUid()), PRIV_MEDIASTORAGE);
         policyEntry.setLevel(PolicyEntry::LEVEL_DENY);
         policyRequest.addEntry(policyEntry);
         Api::sendPolicy(policyRequest);
@@ -351,11 +349,11 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
         result = isPathBound(ACCESS_DENIED_DIR_PATH, MEDIA_STORAGE_RO_DIR_PATH, pid);
         RUNNER_ASSERT_ERRNO_MSG(result == true, "path is not bound");
 
-        policyEntry = PolicyEntry(app.getAppId(),  std::to_string(tmpUser.getUid()), EXTERNAL_STORAGE_PRIVILEGE);
+        policyEntry = PolicyEntry(app.getAppId(),  std::to_string(tmpUser.getUid()), PRIV_EXTERNALSTORAGE);
         policyEntry.setLevel(PolicyEntry::LEVEL_ALLOW);
         policyRequest.addEntry(policyEntry);
 
-        policyEntry = PolicyEntry(app.getAppId(),  std::to_string(tmpUser.getUid()), MEDIA_STORAGE_PRIVILEGE);
+        policyEntry = PolicyEntry(app.getAppId(),  std::to_string(tmpUser.getUid()), PRIV_MEDIASTORAGE);
         policyEntry.setLevel(PolicyEntry::LEVEL_ALLOW);
         policyRequest.addEntry(policyEntry);
         Api::sendPolicy(policyRequest);
@@ -469,10 +467,7 @@ RUNNER_TEST(security_manager_200_prepare_app_perf)
     for (int i = 0; i < nAppsMax; i++) {
         apps.emplace_back(App{AppInstallHelper("app200_" + std::to_string(i), uid), 0});
         auto &hlp = apps.back().hlp;
-        for (const auto &p : { EXTERNAL_STORAGE_PRIVILEGE, MEDIA_STORAGE_PRIVILEGE,
-                std::string("http://tizen.org/privilege/camera"),
-                std::string("http://tizen.org/privilege/internet") })
-            hlp.addPrivilege(p);
+        hlp.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE, PRIV_CAMERA, PRIV_INTERNET});
         hlp.createSharedRODir();
         appInstalls.emplace_back(ScopedInstaller(hlp));
     }