CKM: Make TA2000 and TA2010 independent 92/39792/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 22 May 2015 10:01:51 +0000 (12:01 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 22 May 2015 12:26:34 +0000 (14:26 +0200)
[Problem] Because of dependency between TA2000 and TA2010 the latter fails after
introduction of CKMAsyncAPIEnv.
[Solution] Made tests independent.

[Verification] Run tests: ckm-tests --group=CKM_ASYNC_API

Change-Id: I6a218c1c36e4f2f7c9725b74bdf94b5ae4a56559

src/ckm/async-api.cpp

index 3b74ea3..7e790f0 100644 (file)
@@ -347,6 +347,41 @@ public:
     }
 };
 
+CKM::Alias alias_PKCS_exportable = "async-test-PKCS-export";
+CKM::Alias alias_PKCS_not_exportable = "async-test-PKCS-no-export";
+
+CKM::PKCS12ShPtr loadPkcs()
+{
+    std::ifstream is("/usr/share/ckm-test/pkcs.p12");
+    std::istreambuf_iterator<char> begin(is), end;
+    std::vector<char> buff(begin, end);
+
+    CKM::RawBuffer buffer(buff.size());
+    memcpy(buffer.data(), buff.data(), buff.size());
+
+    auto pkcs = CKM::PKCS12::create(buffer, CKM::Password());
+    RUNNER_ASSERT_MSG(
+        NULL != pkcs.get(),
+        "Error in PKCS12::create()");
+
+    auto cert = pkcs->getCertificate();
+    RUNNER_ASSERT_MSG(
+        NULL != cert.get(),
+        "Error in PKCS12::getCertificate()");
+
+    auto key = pkcs->getKey();
+    RUNNER_ASSERT_MSG(
+        NULL != key.get(),
+        "Error in PKCS12::getKey()");
+
+    auto caVector = pkcs->getCaCertificateShPtrVector();
+    RUNNER_ASSERT_MSG(
+        2 == caVector.size(),
+        "Wrong size of vector");
+
+    return pkcs;
+}
+
 } // namespace anonymous
 
 
@@ -1217,67 +1252,35 @@ RUNNER_TEST(TA1920_deny_access, CKMAsyncAPIEnv)
     }
 }
 
-namespace
-{
-CKM::Alias alias_PKCS_exportable = "async-test-PKCS-export";
-CKM::Alias alias_PKCS_not_exportable = "async-test-PKCS-no-export";
-}
-
 RUNNER_TEST(TA2000_PKCS_add_bundle_with_chain_certs, CKMAsyncAPIEnv)
 {
     DBCleanup dbc;
-    auto manager = CKM::Manager::create();
-    std::ifstream is("/usr/share/ckm-test/pkcs.p12");
-    std::istreambuf_iterator<char> begin(is), end;
-    std::vector<char> buff(begin, end);
-
-    CKM::RawBuffer buffer(buff.size());
-    memcpy(buffer.data(), buff.data(), buff.size());
-
-    auto pkcs = CKM::PKCS12::create(buffer, CKM::Password());
-    RUNNER_ASSERT_MSG(
-        NULL != pkcs.get(),
-        "Error in PKCS12::create()");
-
-    auto cert = pkcs->getCertificate();
-    RUNNER_ASSERT_MSG(
-        NULL != cert.get(),
-        "Error in PKCS12::getCertificate()");
-
-    auto key = pkcs->getKey();
-    RUNNER_ASSERT_MSG(
-        NULL != key.get(),
-        "Error in PKCS12::getKey()");
-
-    auto caVector = pkcs->getCaCertificateShPtrVector();
-    RUNNER_ASSERT_MSG(
-        2 == caVector.size(),
-        "Wrong size of vector");
+    auto pkcs = loadPkcs();
 
     // save to the CKM
     CKM::Policy exportable;
     CKM::Policy notExportable(CKM::Password(), false);
 
     test_positive(&ManagerAsync::savePKCS12,
-                  alias_PKCS_exportable,
+                  dbc.alias(alias_PKCS_exportable.c_str()),
                   pkcs,
                   exportable,
                   exportable);
     test_negative(&ManagerAsync::savePKCS12,
                   CKM_API_ERROR_DB_ALIAS_EXISTS,
-                  alias_PKCS_exportable,
+                  dbc.alias(alias_PKCS_exportable.c_str()),
                   pkcs,
                   exportable,
                   exportable);
 
     test_positive(&ManagerAsync::savePKCS12,
-                  alias_PKCS_not_exportable,
+                  dbc.alias(alias_PKCS_not_exportable.c_str()),
                   pkcs,
                   notExportable,
                   notExportable);
     test_negative(&ManagerAsync::savePKCS12,
                   CKM_API_ERROR_DB_ALIAS_EXISTS,
-                  alias_PKCS_not_exportable,
+                  dbc.alias(alias_PKCS_not_exportable.c_str()),
                   pkcs,
                   notExportable,
                   notExportable);
@@ -1286,7 +1289,23 @@ RUNNER_TEST(TA2000_PKCS_add_bundle_with_chain_certs, CKMAsyncAPIEnv)
 RUNNER_TEST(TA2010_PKCS_get, CKMAsyncAPIEnv)
 {
     DBCleanup dbc;
-    auto manager = CKM::Manager::create();
+
+    auto pkcs = loadPkcs();
+
+    // save to the CKM
+    CKM::Policy exportable;
+    CKM::Policy notExportable(CKM::Password(), false);
+
+    test_positive(&ManagerAsync::savePKCS12,
+                  dbc.alias(alias_PKCS_exportable.c_str()),
+                  pkcs,
+                  exportable,
+                  exportable);
+    test_positive(&ManagerAsync::savePKCS12,
+                  dbc.alias(alias_PKCS_not_exportable.c_str()),
+                  pkcs,
+                  notExportable,
+                  notExportable);
 
     // fail - no entry
     test_negative(&ManagerAsync::getPKCS12,