CKM: Fix policy generation and expectation 44/295844/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 14 Jul 2023 07:53:16 +0000 (09:53 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 14 Jul 2023 11:01:08 +0000 (13:01 +0200)
Some of the possible policy setups were skipped. Make the generate_ckm_policy()
generate all possible combinations.

Expect backend depending on the policy's extractable flag in T1024

Change-Id: I1bd0f5b1a544c8385fdd9c66d23cbd5385137cd0

src/ckm/ckm-common.cpp
src/ckm/unprivileged/main.cpp

index 2ceb95bba89d6329fe0739518636adc0f0fa9268..a0bdcee41b9165cdd5a4b7e0e27865ca94248711 100644 (file)
@@ -621,10 +621,10 @@ CipherCtxPtr create_cipher_ctx(ckmc_cipher_ctx_h ctx)
 }
 
 CKM::Policy generate_ckm_policy(int iterator_nr) {
-    if (iterator_nr % 2) { // policy with password and with / without extractable flag
-        return CKM::Policy(CKM::Password("test_pwd"), iterator_nr % 4);
-    }
-    return CKM::Policy();
+    CKM::Password password;
+    if ((iterator_nr & 0x1) != 0)
+        password.assign("test_pwd");
+    return CKM::Policy(password, (iterator_nr & 0x2) != 0);
 }
 
 void require_default_user(char *argv[])
index 8f02903f0b5019e0f1c5e5b9872367eee76c0961..07edb73890e7fd991d4158bb95835519410d7677 100644 (file)
@@ -459,7 +459,9 @@ RUNNER_TEST(T1024_app_user_save_keys_get_alias_pwd)
     {
         CKM::Policy policy = generate_ckm_policy(it);
         currentAlias = "T1024_appkey" + std::to_string(it);
-        expected.emplace_back(currentAlias, !policy.password.empty(), backend());
+        expected.emplace_back(currentAlias,
+                              !policy.password.empty(),
+                              policy.extractable ? CKM::BackendId::SW : backend());
         RUNNER_ASSERT_MSG(
             CKM_API_SUCCESS == (exitCode = manager->saveKey(currentAlias, key, policy)),
             "Error=" << CKM::APICodeToString(exitCode));