CKM: Adjust tests to AliasInfo changes
[platform/core/test/security-tests.git] / src / ckm / ckm-common.cpp
index c34aaa2..7a584ba 100644 (file)
@@ -387,59 +387,47 @@ void check_alias_list(const CKM::AliasVector& expected)
     RUNNER_ASSERT_MSG(expected == actual, "Actual list of aliases differ from expected list.");
 }
 
-void check_alias_info_list_helper(const CKM::AliasInfoVector& expected,
-                                  const CKM::AliasInfoVector& actual,
+void check_alias_info_list_helper(const PasswordInfoVector& expected,
+                                  const std::unordered_map<std::string, bool>& actual,
                                   const std::string &userSmackLabel)
 {
     std::string errorLogMsg;
-    std::unordered_map<std::string, bool> aliasPwdMap;
 
     RUNNER_ASSERT_MSG(expected.size() == actual.size(), "Aliases item count differs, expected: " <<
         expected.size() << " actual: " << actual.size());
 
-    for (const auto &it : actual)
-    {
-        aliasPwdMap[std::get<0>(it)] = std::get<1>(it).passwordProtected;
-    }
-
-
     for (const auto &it : expected)
     {
-        auto aliasPwd = aliasPwdMap.find(userSmackLabel + std::get<0>(it));
-        if (aliasPwd != aliasPwdMap.end()) {
-            if (aliasPwd->second != std::get<1>(it).passwordProtected) {
-                errorLogMsg += "Alias: " + std::get<0>(it) + " has wrong encryption status: "
-                                + std::to_string(std::get<1>(it).passwordProtected) + "\n";
+        auto aliasPwd = actual.find(userSmackLabel + it.alias);
+        if (aliasPwd != actual.end()) {
+            if (aliasPwd->second != it.passwordProtected) {
+                errorLogMsg += "Alias: " + it.alias + " has wrong encryption status: "
+                                + std::to_string(it.passwordProtected) + "\n";
             }
         }
         else {
-            errorLogMsg += "Expected alias: " + std::get<0>(it) + " not found.\n";
+            errorLogMsg += "Expected alias: " + it.alias + " not found.\n";
         }
     }
 
     if (!errorLogMsg.empty()) {
-        for (const auto &it : actual)
+        for (const auto& [alias, passwordProtected] : actual)
         {
-            errorLogMsg += "Actual alias: " + std::get<0>(it) + " status: "
-                + std::to_string(std::get<1>(it).passwordProtected) + "\n";
+            errorLogMsg += "Actual alias: " + alias + " status: "
+                + std::to_string(passwordProtected) + "\n";
         }
         RUNNER_FAIL_MSG("Actual list of aliases differ from expected list.\n" + errorLogMsg);
     }
 }
 
-std::pair<std::string, CKM::AliasInfo> make_alias_info(const std::string& alias, bool password)
-{
-    return std::make_pair(alias, CKM::AliasInfo({password, CKM::BackendId::SW}));
-}
-
-void check_alias_info_list(const CKM::AliasInfoVector& expected)
+void check_alias_info_list(const PasswordInfoVector& expected)
 {
     ckmc_alias_info_list_s *aliasInfoList = NULL;
     int ret = ckmc_get_data_alias_info_list(&aliasInfoList);
     RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get the list of data aliases. " << ret << " / "
                       << CKMCErrorToString(ret));
 
-    CKM::AliasInfoVector actual;
+    std::unordered_map<std::string, bool> actual;
     ckmc_alias_info_list_s *plist = aliasInfoList;
     char* alias;
     bool isPasswordProtected;
@@ -453,7 +441,8 @@ void check_alias_info_list(const CKM::AliasInfoVector& expected)
         RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get password protection status" << ret << " / "
                           << CKMCErrorToString(ret));
         RUNNER_ASSERT_MSG(alias != nullptr, "Got null alias. Iterator: " << it);
-        actual.push_back(make_alias_info(alias, isPasswordProtected));
+
+        actual[alias] = isPasswordProtected;
         plist = plist->next;
         it++;
     }