Replace magic policy level strings with constexpr 84/229684/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 2 Apr 2020 12:41:59 +0000 (14:41 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Thu, 9 Apr 2020 16:18:07 +0000 (16:18 +0000)
Change-Id: Ia539ec68d641448a8d84e175eb8efe2e888e6671

src/common/sm_policy_request.cpp
src/common/sm_policy_request.h
src/security-manager-tests/test_cases.cpp
src/security-manager-tests/test_cases_nss.cpp
src/security-manager-tests/test_cases_prepare_app.cpp
src/security-manager-tests/test_cases_privacy_manager.cpp

index debda17..c129a76 100644 (file)
 
 namespace SecurityManagerTest {
 
+constexpr char PolicyEntry::LEVEL_ALLOW[];
+constexpr char PolicyEntry::LEVEL_DENY[];
+constexpr char PolicyEntry::LEVEL_ASK_USER[];
+
 PolicyEntry::PolicyEntry()
     : m_appId(true, std::string(SECURITY_MANAGER_ANY))
     , m_user(true, std::string(SECURITY_MANAGER_ANY))
index 4c12102..d1791a7 100644 (file)
@@ -29,6 +29,10 @@ namespace SecurityManagerTest {
 class PolicyEntry
 {
 public:
+    static constexpr char LEVEL_ALLOW[] = "Allow";
+    static constexpr char LEVEL_DENY[] = "Deny";
+    static constexpr char LEVEL_ASK_USER[] = "Ask user";
+
     PolicyEntry();
 
     PolicyEntry(const std::string &appId,
index 8b7a7fc..1f5441c 100644 (file)
@@ -693,7 +693,7 @@ RUNNER_CHILD_TEST(security_manager_21_security_manager_admin_deny_user_priv)
         PolicyRequest addPolicyReq;
         for (auto &deniedPriv : deniedPrivsAfterChange) {
             PolicyEntry entry(SECURITY_MANAGER_ANY, normalUser.getUidString(), deniedPriv);
-            entry.setMaxLevel("Deny");
+            entry.setMaxLevel(PolicyEntry::LEVEL_DENY);
             addPolicyReq.addEntry(entry);
         }
         Api::sendPolicy(addPolicyReq);
index 82ce87b..3cfdc64 100644 (file)
@@ -111,7 +111,7 @@ RUNNER_CHILD_TEST(nss_03_guest_user_without_inter_daemon_groups_unaffected_by_cy
         SECURITY_MANAGER_ANY,
         std::to_string(static_cast<int>(testUser.getUid())),
         "http://tizen.org/privilege/camera");
-    entry.setMaxLevel("Deny");
+    entry.setMaxLevel(PolicyEntry::LEVEL_DENY);
 
     policyRequest.addEntry(entry);
     Api::sendPolicy(policyRequest);
index 9ff9179..32dad32 100644 (file)
@@ -336,11 +336,11 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
 
         PolicyRequest policyRequest;
         PolicyEntry policyEntry(app.getAppId(), std::to_string(tmpUser.getUid()), EXTERNAL_STORAGE_PRIVILEGE);
-        policyEntry.setLevel("Deny");
+        policyEntry.setLevel(PolicyEntry::LEVEL_DENY);
         policyRequest.addEntry(policyEntry);
 
         policyEntry = PolicyEntry(app.getAppId(), std::to_string(tmpUser.getUid()), MEDIA_STORAGE_PRIVILEGE);
-        policyEntry.setLevel("Deny");
+        policyEntry.setLevel(PolicyEntry::LEVEL_DENY);
         policyRequest.addEntry(policyEntry);
         Api::sendPolicy(policyRequest);
 
@@ -352,11 +352,11 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
         RUNNER_ASSERT_ERRNO_MSG(result == true, "path is not bound");
 
         policyEntry = PolicyEntry(app.getAppId(),  std::to_string(tmpUser.getUid()), EXTERNAL_STORAGE_PRIVILEGE);
-        policyEntry.setLevel("Allow");
+        policyEntry.setLevel(PolicyEntry::LEVEL_ALLOW);
         policyRequest.addEntry(policyEntry);
 
         policyEntry = PolicyEntry(app.getAppId(),  std::to_string(tmpUser.getUid()), MEDIA_STORAGE_PRIVILEGE);
-        policyEntry.setLevel("Allow");
+        policyEntry.setLevel(PolicyEntry::LEVEL_ALLOW);
         policyRequest.addEntry(policyEntry);
         Api::sendPolicy(policyRequest);
 
index c354041..edd750f 100644 (file)
@@ -389,7 +389,7 @@ RUNNER_CHILD_TEST(security_manager_13_privacy_manager_fetch_policy_after_update_
                 normalUser.getUidString(),
                 app1.getPrivileges()[0]
                 );
-        policyEntry.setLevel("Deny");
+        policyEntry.setLevel(PolicyEntry::LEVEL_DENY);
 
         policyRequest.addEntry(policyEntry);
         policyEntry = PolicyEntry(
@@ -397,7 +397,7 @@ RUNNER_CHILD_TEST(security_manager_13_privacy_manager_fetch_policy_after_update_
                 normalUser.getUidString(),
                 app1.getPrivileges()[1]
                 );
-        policyEntry.setLevel("Deny");
+        policyEntry.setLevel(PolicyEntry::LEVEL_DENY);
         policyRequest.addEntry(policyEntry);
         Api::sendPolicy(policyRequest);
 
@@ -468,11 +468,11 @@ RUNNER_CHILD_TEST(security_manager_14_privacy_manager_fetch_and_update_policy_fo
         const std::string displayPriv = "http://tizen.org/privilege/display";
 
         PolicyEntry internetPolicyEntry(SECURITY_MANAGER_ANY, SECURITY_MANAGER_ANY, internetPriv);
-        internetPolicyEntry.setMaxLevel("Deny");
+        internetPolicyEntry.setMaxLevel(PolicyEntry::LEVEL_DENY);
         setPolicyRequest.addEntry(internetPolicyEntry);
 
         PolicyEntry displayPolicyEntry(SECURITY_MANAGER_ANY, SECURITY_MANAGER_ANY, displayPriv);
-        displayPolicyEntry.setMaxLevel("Deny");
+        displayPolicyEntry.setMaxLevel(PolicyEntry::LEVEL_DENY);
         setPolicyRequest.addEntry(displayPolicyEntry);
 
         Api::sendPolicy(setPolicyRequest);
@@ -528,7 +528,7 @@ RUNNER_CHILD_TEST(security_manager_15_privacy_manager_send_policy_update_for_adm
                                 "drop_root_privileges failed");
 
         PolicyEntry entry(updatedApp.getAppId(), adminUser.getUidString(), updatePriv);
-        entry.setMaxLevel("Allow");
+        entry.setMaxLevel(PolicyEntry::LEVEL_ALLOW);
         PolicyRequest addPolicyRequest;
         addPolicyRequest.addEntry(entry);
         Api::sendPolicy(addPolicyRequest);
@@ -564,7 +564,7 @@ RUNNER_CHILD_TEST(security_manager_15_privacy_manager_send_policy_update_for_adm
                           "drop_root_privileges failed");
 
         PolicyEntry entry(SECURITY_MANAGER_ANY, adminUser.getUidString(), updatePriv);
-        entry.setMaxLevel("Allow");
+        entry.setMaxLevel(PolicyEntry::LEVEL_ALLOW);
 
         PolicyRequest addPolicyRequest;
         addPolicyRequest.addEntry(entry);
@@ -600,7 +600,7 @@ RUNNER_CHILD_TEST(security_manager_15_privacy_manager_send_policy_update_for_sel
                           "drop_root_privileges failed");
 
         PolicyEntry entry(app.getAppId(), user.getUidString(), updatePriv);
-        entry.setLevel("Allow");
+        entry.setLevel(PolicyEntry::LEVEL_ALLOW);
 
         PolicyRequest addPolicyRequest;
         addPolicyRequest.addEntry(entry);
@@ -637,11 +637,11 @@ RUNNER_CHILD_TEST(security_manager_16_policy_levels_get)
         std::string allowPolicy = std::string(levels[count-1]);
 
         // first should always be Deny
-        RUNNER_ASSERT_MSG(denyPolicy.compare("Deny") == 0,
+        RUNNER_ASSERT_MSG(denyPolicy.compare(PolicyEntry::LEVEL_DENY) == 0,
                 "Invalid first policy level. Should be Deny, instead there is: " << levels[0]);
 
         // last should always be Allow
-        RUNNER_ASSERT_MSG(allowPolicy.compare("Allow") == 0,
+        RUNNER_ASSERT_MSG(allowPolicy.compare(PolicyEntry::LEVEL_ALLOW) == 0,
                 "Invalid last policy level. Should be Allow, instead there is: " << levels[count-1]);
         exit(0);
     }
@@ -679,7 +679,7 @@ RUNNER_CHILD_TEST(security_manager_17a_privacy_manager_delete_policy_for_self)
                                             "drop_root_privileges failed");
 
         PolicyEntry entry(app.getAppId(), user.getUidString(), updatePriv);
-        entry.setLevel("Allow");
+        entry.setLevel(PolicyEntry::LEVEL_ALLOW);
         PolicyRequest addPolicyRequest;
         addPolicyRequest.addEntry(entry);
         Api::sendPolicy(addPolicyRequest);
@@ -734,7 +734,7 @@ RUNNER_CHILD_TEST(security_manager_17b_privacy_manager_delete_policy_for_self)
                                 "drop_root_privileges failed");
 
         PolicyEntry entry(app.getAppId(), user.getUidString(), updatePriv);
-        entry.setLevel("Allow");
+        entry.setLevel(PolicyEntry::LEVEL_ALLOW);
         PolicyRequest addPolicyRequest;
         addPolicyRequest.addEntry(entry);
         Api::sendPolicy(addPolicyRequest);
@@ -827,7 +827,6 @@ RUNNER_CHILD_TEST(security_manager_17_privacy_manager_fetch_whole_policy_for_sel
 
 RUNNER_CHILD_TEST(security_manager_18_privacy_manager_privacy_related_privileges_policy_install_remove)
 {
-    const std::string askUserDescription = "Ask user";
     TemporaryTestUser user("sm_test_18_username", GUM_USERTYPE_NORMAL);
     user.create();
 
@@ -851,7 +850,7 @@ RUNNER_CHILD_TEST(security_manager_18_privacy_manager_privacy_related_privileges
             unsigned int privacyActNum = 0;
             for (auto &entry : policyEntries)
                 if (isPrivilegePrivacy(entry.getPrivilege())) {
-                    RUNNER_ASSERT_MSG(entry.getCurrentLevel() == askUserDescription,
+                    RUNNER_ASSERT_MSG(entry.getCurrentLevel() == PolicyEntry::LEVEL_ASK_USER,
                                       "Invalid policy setup; policy should be \"Ask user\" but is "
                                       << entry.getCurrentLevel());
                     ++privacyActNum;
@@ -870,7 +869,6 @@ RUNNER_CHILD_TEST(security_manager_18_privacy_manager_privacy_related_privileges
 }
 
 void test_privacy_related_privileges(bool isHybrid) {
-    const std::string askUserDescription = "Ask user";
     TemporaryTestUser user("sm_test_19_username", GUM_USERTYPE_NORMAL);
     user.create();
 
@@ -911,7 +909,7 @@ void test_privacy_related_privileges(bool isHybrid) {
                           "Invalid appId: should be either " << app1.getAppId() << " or "
                           << app2.getAppId() << " but is " << entry.getAppId());
         if (PolicyConfiguration::getIsAskuserEnabled() && isPrivilegePrivacy(entry.getPrivilege())) {
-            RUNNER_ASSERT_MSG(entry.getCurrentLevel() == askUserDescription,
+            RUNNER_ASSERT_MSG(entry.getCurrentLevel() == PolicyEntry::LEVEL_ASK_USER,
                               "Invalid policy setup; policy should be \"Ask user\" but is "
                               << entry.getCurrentLevel());
             if (entry.getAppId() == app1.getAppId())
@@ -938,7 +936,6 @@ RUNNER_CHILD_TEST(security_manager_19b_privacy_manager_privacy_related_privilege
 
 RUNNER_CHILD_TEST(security_manager_20_privacy_manager_privacy_related_privileges_policy_admin_check)
 {
-    const std::string askUserDescription = "Ask user";
     TemporaryTestUser user("sm_test_20_username", GUM_USERTYPE_NORMAL);
     user.create();
 
@@ -952,7 +949,7 @@ RUNNER_CHILD_TEST(security_manager_20_privacy_manager_privacy_related_privileges
     int policyType = CYNARA_ADMIN_ALLOW;
     int privacyPolicyType = -1;
     if (PolicyConfiguration::getIsAskuserEnabled())
-        admin.getPolicyTypeForDescription(askUserDescription, privacyPolicyType);
+        admin.getPolicyTypeForDescription(PolicyEntry::LEVEL_ASK_USER, privacyPolicyType);
 
     for (auto &priv : app.getPrivileges()) {
         if (PolicyConfiguration::getIsAskuserEnabled() && isPrivilegePrivacy(priv)) {