CKM: Check backend info
[platform/core/test/security-tests.git] / src / ckm / ckm-common.cpp
index 7a584ba..2ceb95b 100644 (file)
@@ -387,8 +387,8 @@ 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 PasswordInfoVector& expected,
-                                  const std::unordered_map<std::string, bool>& actual,
+void check_alias_info_list_helper(const InfoVector& expected,
+                                  const InfoMap& actual,
                                   const std::string &userSmackLabel)
 {
     std::string errorLogMsg;
@@ -396,40 +396,54 @@ void check_alias_info_list_helper(const PasswordInfoVector& expected,
     RUNNER_ASSERT_MSG(expected.size() == actual.size(), "Aliases item count differs, expected: " <<
         expected.size() << " actual: " << actual.size());
 
-    for (const auto &it : expected)
+    for (const auto &expectedIt : expected)
     {
-        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";
+        auto actualIt = actual.find(userSmackLabel + expectedIt.alias);
+        if (actualIt != actual.end()) {
+            if (actualIt->second.passwordProtected != expectedIt.passwordProtected) {
+                errorLogMsg += "Alias: " + actualIt->second.alias + " has wrong encryption status: "
+                    + std::to_string(actualIt->second.passwordProtected) + "\n";
+            }
+            if (actualIt->second.backend != expectedIt.backend) {
+                errorLogMsg += "Alias: " + actualIt->second.alias + " belongs to wrong backend: "
+                    + std::to_string(static_cast<int>(actualIt->second.backend)) + "\n";
             }
         }
         else {
-            errorLogMsg += "Expected alias: " + it.alias + " not found.\n";
+            errorLogMsg += "Expected alias: " + actualIt->second.alias + " not found.\n";
         }
     }
 
     if (!errorLogMsg.empty()) {
-        for (const auto& [alias, passwordProtected] : actual)
+        for (const auto& [alias, info] : actual)
         {
-            errorLogMsg += "Actual alias: " + alias + " status: "
-                + std::to_string(passwordProtected) + "\n";
+            errorLogMsg += "Actual alias: " + alias +
+                " status: " + std::to_string(info.passwordProtected) +
+                " backend: " + std::to_string(static_cast<int>(info.backend)) + "\n";
         }
         RUNNER_FAIL_MSG("Actual list of aliases differ from expected list.\n" + errorLogMsg);
     }
 }
 
-void check_alias_info_list(const PasswordInfoVector& expected)
+CKM::BackendId backend()
+{
+#ifdef TZ_BACKEND
+    return CKM::BackendId::TZ;
+#else
+    return CKM::BackendId::SW;
+#endif
+}
+
+void check_alias_info_list(const InfoVector& 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));
 
-    std::unordered_map<std::string, bool> actual;
+    InfoMap actual;
     ckmc_alias_info_list_s *plist = aliasInfoList;
-    char* alias;
+    char* alias = nullptr;
     bool isPasswordProtected;
     unsigned int it = 0;
     while (plist)
@@ -437,12 +451,18 @@ void check_alias_info_list(const PasswordInfoVector& expected)
         ret = ckmc_alias_info_get_alias(plist->info, &alias);
         RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get alias. " << ret << " / "
                           << CKMCErrorToString(ret));
+        RUNNER_ASSERT_MSG(alias != nullptr, "Got null alias. Iterator: " << it);
+
         ret = ckmc_alias_info_is_password_protected(plist->info, &isPasswordProtected);
         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[alias] = isPasswordProtected;
+        ckmc_backend_id_e backend;
+        ret = ckmc_alias_info_get_backend(plist->info, &backend);
+        RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get backend" << ret << " / "
+                          << CKMCErrorToString(ret));
+
+        actual.try_emplace(alias, alias, isPasswordProtected, static_cast<CKM::BackendId>(backend));
         plist = plist->next;
         it++;
     }