From f654bd8a281bf1e60865659ca0abb62f8ce78b93 Mon Sep 17 00:00:00 2001 From: "Maciej J. Karpiuk" Date: Thu, 13 Nov 2014 16:53:12 +0100 Subject: [PATCH] CKM table separation: tests adjusted to new C++ API. Change-Id: I74f742a75190fd66618cf0960836c3d7907059d4 --- tests/ckm/async-api.cpp | 270 ++++++++++++++++++++--------------------------- tests/ckm/ckm-common.cpp | 12 +-- tests/ckm/ckm-common.h | 18 +--- tests/ckm/main.cpp | 25 ++--- 4 files changed, 136 insertions(+), 189 deletions(-) diff --git a/tests/ckm/async-api.cpp b/tests/ckm/async-api.cpp index c46c732..a340c98 100644 --- a/tests/ckm/async-api.cpp +++ b/tests/ckm/async-api.cpp @@ -66,9 +66,7 @@ public: void ReceivedSaveCertificate() { Succeeded(); } void ReceivedSaveData() { Succeeded(); } - void ReceivedRemovedKey() { Succeeded(); } - void ReceivedRemovedCertificate() { Succeeded(); } - void ReceivedRemovedData() { Succeeded(); } + void ReceivedRemovedAlias() { Succeeded(); } void ReceivedKey(Key &&) { Succeeded(); } void ReceivedCertificate(Certificate &&) { Succeeded(); } @@ -87,11 +85,11 @@ public: void ReceivedCreateSignature(RawBuffer && buffer) { m_signed = move(buffer); Succeeded(); } void ReceivedVerifySignature() { Succeeded(); } - void ReceivedOCSPCheck(int status) { m_ocspStatus = status; Succeeded(); } void ReceivedSetPermission() { Succeeded(); } + void WaitForResponse() { unique_lock < mutex > lock(m_mutex); @@ -429,10 +427,10 @@ RUNNER_CHILD_TEST(TA0020_save_key_already_exists) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias"), keys[RSA][0].prv, Policy()); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias"), keys[RSA][0].prv, Policy()); test_negative(&ManagerAsync::saveKey, CKM_API_ERROR_DB_ALIAS_EXISTS, - dbc.key("alias"), + dbc.alias("alias"), keys[RSA][0].prv, Policy()); } @@ -442,7 +440,7 @@ RUNNER_CHILD_TEST(TA0050_save_key_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias"), keys[RSA][0].prv, Policy()); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias"), keys[RSA][0].prv, Policy()); } @@ -462,10 +460,10 @@ RUNNER_CHILD_TEST(TA0120_save_cert_already_exists) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveCertificate, dbc.cert("alias"), certs[0], Policy()); + test_positive(&ManagerAsync::saveCertificate, dbc.alias("alias"), certs[0], Policy()); test_negative(&ManagerAsync::saveCertificate, CKM_API_ERROR_DB_ALIAS_EXISTS, - dbc.cert("alias"), + dbc.alias("alias"), certs[0], Policy()); } @@ -475,7 +473,7 @@ RUNNER_CHILD_TEST(TA0150_save_cert_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveCertificate, dbc.cert("alias"), certs[0], Policy()); + test_positive(&ManagerAsync::saveCertificate, dbc.alias("alias"), certs[0], Policy()); } @@ -494,10 +492,10 @@ RUNNER_CHILD_TEST(TA0220_save_data_already_exists) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveData, dbc.data("alias"), test_buffer, Policy()); + test_positive(&ManagerAsync::saveData, dbc.alias("alias"), test_buffer, Policy()); test_negative(&ManagerAsync::saveData, CKM_API_ERROR_DB_ALIAS_EXISTS, - dbc.data("alias"), + dbc.alias("alias"), test_buffer, Policy()); } @@ -507,24 +505,24 @@ RUNNER_CHILD_TEST(TA0250_save_data_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveData, dbc.data("alias"), test_buffer, Policy()); + test_positive(&ManagerAsync::saveData, dbc.alias("alias"), test_buffer, Policy()); } // removeKey -RUNNER_CHILD_TEST(TA0310_remove_key_invalid_param) +RUNNER_CHILD_TEST(TA0310_remove_alias_invalid_param) { switch_to_storage_user(TEST_LABEL); - test_no_observer(&ManagerAsync::removeKey, "alias"); - test_invalid_param(&ManagerAsync::removeKey, ""); + test_no_observer(&ManagerAsync::removeAlias, "alias"); + test_invalid_param(&ManagerAsync::removeAlias, ""); } -RUNNER_CHILD_TEST(TA0330_remove_key_unknown_alias) +RUNNER_CHILD_TEST(TA0330_remove_alias_unknown_alias) { switch_to_storage_user(TEST_LABEL); - test_negative(&ManagerAsync::removeKey, CKM_API_ERROR_DB_ALIAS_UNKNOWN, "non-existing-alias"); + test_negative(&ManagerAsync::removeAlias, CKM_API_ERROR_DB_ALIAS_UNKNOWN, "non-existing-alias"); } RUNNER_CHILD_TEST(TA0350_remove_key_positive) @@ -532,62 +530,28 @@ RUNNER_CHILD_TEST(TA0350_remove_key_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias"), keys[RSA][0].prv, Policy()); - test_positive(&ManagerAsync::removeKey, dbc.key("alias")); -} - - -// removeCert -RUNNER_CHILD_TEST(TA0410_remove_cert_invalid_param) -{ - switch_to_storage_user(TEST_LABEL); - - test_no_observer(&ManagerAsync::removeCertificate, "alias"); - test_invalid_param(&ManagerAsync::removeCertificate, ""); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias"), keys[RSA][0].prv, Policy()); + test_positive(&ManagerAsync::removeAlias, dbc.alias("alias")); } -RUNNER_CHILD_TEST(TA0430_remove_cert_unknown_alias) -{ - switch_to_storage_user(TEST_LABEL); - - test_negative(&ManagerAsync::removeCertificate, - CKM_API_ERROR_DB_ALIAS_UNKNOWN, - "non-existing-alias"); -} RUNNER_CHILD_TEST(TA0450_remove_cert_positive) { switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveCertificate, dbc.cert("alias"), certs[0], Policy()); - test_positive(&ManagerAsync::removeCertificate, dbc.cert("alias")); + test_positive(&ManagerAsync::saveCertificate, dbc.alias("alias"), certs[0], Policy()); + test_positive(&ManagerAsync::removeAlias, dbc.alias("alias")); } -// removeData -RUNNER_CHILD_TEST(TA0510_remove_data_invalid_param) -{ - switch_to_storage_user(TEST_LABEL); - - test_no_observer(&ManagerAsync::removeData, "alias"); - test_invalid_param(&ManagerAsync::removeData, ""); -} - -RUNNER_CHILD_TEST(TA0530_remove_data_unknown_alias) -{ - switch_to_storage_user(TEST_LABEL); - - test_negative(&ManagerAsync::removeData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, "non-existing-alias"); -} - RUNNER_CHILD_TEST(TA0550_remove_data_positive) { switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveData, dbc.data("alias"), test_buffer, Policy()); - test_positive(&ManagerAsync::removeData, dbc.data("alias")); + test_positive(&ManagerAsync::saveData, dbc.alias("alias"), test_buffer, Policy()); + test_positive(&ManagerAsync::removeAlias, dbc.alias("alias")); } @@ -612,10 +576,10 @@ RUNNER_CHILD_TEST(TA0640_get_key_wrong_password) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias"), keys[RSA][0].prv, Policy("password")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias"), keys[RSA][0].prv, Policy("password")); test_negative(&ManagerAsync::getKey, CKM_API_ERROR_SERVER_ERROR, - dbc.key("alias"), + dbc.alias("alias"), "wrong-password"); } @@ -624,8 +588,8 @@ RUNNER_CHILD_TEST(TA0650_get_key_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias"), keys[RSA][0].prv, Policy("password")); - test_positive(&ManagerAsync::getKey, dbc.key("alias"), "password"); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias"), keys[RSA][0].prv, Policy("password")); + test_positive(&ManagerAsync::getKey, dbc.alias("alias"), "password"); } @@ -654,12 +618,12 @@ RUNNER_CHILD_TEST(TA0740_get_cert_wrong_password) DBCleanup dbc; test_positive(&ManagerAsync::saveCertificate, - dbc.cert("alias"), + dbc.alias("alias"), certs[0], Policy("password")); test_negative(&ManagerAsync::getCertificate, CKM_API_ERROR_SERVER_ERROR, - dbc.cert("alias"), + dbc.alias("alias"), "wrong-password"); } @@ -668,8 +632,8 @@ RUNNER_CHILD_TEST(TA0750_get_cert_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveCertificate, dbc.cert("alias"), certs[0], Policy("password")); - test_positive(&ManagerAsync::getCertificate, dbc.cert("alias"), "password"); + test_positive(&ManagerAsync::saveCertificate, dbc.alias("alias"), certs[0], Policy("password")); + test_positive(&ManagerAsync::getCertificate, dbc.alias("alias"), "password"); } @@ -694,10 +658,10 @@ RUNNER_CHILD_TEST(TA0840_get_data_wrong_password) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveData, dbc.data("alias"), test_buffer, Policy("password")); + test_positive(&ManagerAsync::saveData, dbc.alias("alias"), test_buffer, Policy("password")); test_negative(&ManagerAsync::getData, CKM_API_ERROR_SERVER_ERROR, - dbc.data("alias"), + dbc.alias("alias"), "wrong-password"); } @@ -706,8 +670,8 @@ RUNNER_CHILD_TEST(TA0850_get_data_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveData, dbc.data("alias"), test_buffer, Policy("password")); - test_positive(&ManagerAsync::getData, dbc.data("alias"), "password"); + test_positive(&ManagerAsync::saveData, dbc.alias("alias"), test_buffer, Policy("password")); + test_positive(&ManagerAsync::getData, dbc.alias("alias"), "password"); } @@ -724,15 +688,15 @@ RUNNER_CHILD_TEST(TA0950_get_key_alias_vector_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias1"), keys[RSA][0].prv, Policy()); - test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.key("alias1"))) }); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias1"), keys[RSA][0].prv, Policy()); + test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias1"))) }); - test_positive(&ManagerAsync::saveKey, dbc.key("alias2"), keys[DSA][0].prv, Policy()); - test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.key("alias1"))), - format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.key("alias2"))) }); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias2"), keys[DSA][0].prv, Policy()); + test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias1"))), + format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias2"))) }); - test_positive(&ManagerAsync::removeKey, dbc.key("alias1")); - test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.key("alias2"))) }); + test_positive(&ManagerAsync::removeAlias, dbc.alias("alias1")); + test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias2"))) }); } @@ -749,15 +713,15 @@ RUNNER_CHILD_TEST(TA1050_get_cert_alias_vector_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveCertificate, dbc.cert("alias1"), certs[0], Policy()); - test_check_aliases(&ManagerAsync::getCertificateAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.cert("alias1"))) }); + test_positive(&ManagerAsync::saveCertificate, dbc.alias("alias1"), certs[0], Policy()); + test_check_aliases(&ManagerAsync::getCertificateAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias1"))) }); - test_positive(&ManagerAsync::saveCertificate, dbc.cert("alias2"), certs[1], Policy()); - test_check_aliases(&ManagerAsync::getCertificateAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.cert("alias1"))), - format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.cert("alias2"))) }); + test_positive(&ManagerAsync::saveCertificate, dbc.alias("alias2"), certs[1], Policy()); + test_check_aliases(&ManagerAsync::getCertificateAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias1"))), + format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias2"))) }); - test_positive(&ManagerAsync::removeCertificate, dbc.cert("alias1")); - test_check_aliases(&ManagerAsync::getCertificateAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.cert("alias2"))) }); + test_positive(&ManagerAsync::removeAlias, dbc.alias("alias1")); + test_check_aliases(&ManagerAsync::getCertificateAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias2"))) }); } @@ -774,15 +738,15 @@ RUNNER_CHILD_TEST(TA1150_get_data_alias_vector_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveData, dbc.data("alias1"), test_buffer, Policy()); - test_check_aliases(&ManagerAsync::getDataAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias1"))) }); + test_positive(&ManagerAsync::saveData, dbc.alias("alias1"), test_buffer, Policy()); + test_check_aliases(&ManagerAsync::getDataAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias1"))) }); - test_positive(&ManagerAsync::saveData, dbc.data("alias2"), test_buffer, Policy()); - test_check_aliases(&ManagerAsync::getDataAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias1"))), - format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias2"))) }); + test_positive(&ManagerAsync::saveData, dbc.alias("alias2"), test_buffer, Policy()); + test_check_aliases(&ManagerAsync::getDataAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias1"))), + format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias2"))) }); - test_positive(&ManagerAsync::removeData, dbc.data("alias1")); - test_check_aliases(&ManagerAsync::getDataAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias2"))) }); + test_positive(&ManagerAsync::removeAlias, dbc.alias("alias1")); + test_check_aliases(&ManagerAsync::getDataAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias2"))) }); } @@ -804,12 +768,12 @@ RUNNER_CHILD_TEST(TA1220_create_key_pair_rsa_already_exists) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_prv"), keys[RSA][0].prv, Policy()); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_prv"), keys[RSA][0].prv, Policy()); test_negative(&ManagerAsync::createKeyPairRSA, CKM_API_ERROR_DB_ALIAS_EXISTS, 1024, - dbc.key("alias_prv"), - dbc.key("alias_pub"), + dbc.alias("alias_prv"), + dbc.alias("alias_pub"), Policy(), Policy()); } @@ -821,13 +785,13 @@ RUNNER_CHILD_TEST(TA1250_create_key_pair_rsa_positive) DBCleanup dbc; test_positive(&ManagerAsync::createKeyPairRSA, 1024, - dbc.key("alias_prv"), - dbc.key("alias_pub"), + dbc.alias("alias_prv"), + dbc.alias("alias_pub"), Policy(), Policy()); - test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias_prv"))), - format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias_pub"))) }); + test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias_prv"))), + format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias_pub"))) }); } // createKeyPairDSA @@ -848,12 +812,12 @@ RUNNER_CHILD_TEST(TA1280_create_key_pair_dsa_already_exists) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_prv"), keys[DSA][0].prv, Policy()); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_prv"), keys[DSA][0].prv, Policy()); test_negative(&ManagerAsync::createKeyPairDSA, CKM_API_ERROR_DB_ALIAS_EXISTS, 1024, - dbc.key("alias_prv"), - dbc.key("alias_pub"), + dbc.alias("alias_prv"), + dbc.alias("alias_pub"), Policy(), Policy()); } @@ -865,13 +829,13 @@ RUNNER_CHILD_TEST(TA1290_create_key_pair_dsa_positive) DBCleanup dbc; test_positive(&ManagerAsync::createKeyPairDSA, 1024, - dbc.key("alias_prv"), - dbc.key("alias_pub"), + dbc.alias("alias_prv"), + dbc.alias("alias_pub"), Policy(), Policy()); - test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias_prv"))), - format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias_pub"))) }); + test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias_prv"))), + format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias_pub"))) }); } // createKeyPairECDSA @@ -892,12 +856,12 @@ RUNNER_CHILD_TEST(TA1320_create_key_pair_ecdsa_already_exists) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_prv"), keys[ECDSA][0].prv, Policy()); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_prv"), keys[ECDSA][0].prv, Policy()); test_negative(&ManagerAsync::createKeyPairECDSA, CKM_API_ERROR_DB_ALIAS_EXISTS, ElipticCurve::prime192v1, - dbc.key("alias_prv"), - dbc.key("alias_pub"), + dbc.alias("alias_prv"), + dbc.alias("alias_pub"), Policy(), Policy()); } @@ -909,13 +873,13 @@ RUNNER_CHILD_TEST(TA1350_create_key_pair_ecdsa_positive) DBCleanup dbc; test_positive(&ManagerAsync::createKeyPairECDSA, ElipticCurve::prime192v1, - dbc.key("alias_prv"), - dbc.key("alias_pub"), + dbc.alias("alias_prv"), + dbc.alias("alias_pub"), Policy(), Policy()); - test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias_prv"))), - format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.data("alias_pub"))) }); + test_check_aliases(&ManagerAsync::getKeyAliasVector, { format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias_prv"))), + format_full_label_alias(std::string(TEST_LABEL), Alias(dbc.alias("alias_pub"))) }); } @@ -954,7 +918,7 @@ RUNNER_CHILD_TEST(TA1420_get_certificate_chain_negative) CKM_API_ERROR_VERIFICATION_FAILED, cert, certv); - AliasVector aliasv = { dbc.cert("alias") }; + AliasVector aliasv = { dbc.alias("alias") }; test_positive(&ManagerAsync::saveCertificate, aliasv[0], certs[0], Policy()); test_negative(&ManagerAsync::getCertificateChain, CKM_API_ERROR_VERIFICATION_FAILED, @@ -971,7 +935,7 @@ RUNNER_CHILD_TEST(TA1450_get_certificate_chain_positive) CertificateShPtrVector certv = { certs[1] }; test_check_cert_chain(&ManagerAsync::getCertificateChain, 3, cert, certv); - AliasVector aliasv = { dbc.cert("alias") }; + AliasVector aliasv = { dbc.alias("alias") }; test_positive(&ManagerAsync::saveCertificate, aliasv[0], certs[1], Policy()); test_check_cert_chain(&ManagerAsync::getCertificateChain, 3, cert, aliasv); } @@ -1007,10 +971,10 @@ RUNNER_CHILD_TEST(TA1520_create_signature_invalid_password) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias"), keys[RSA][0].prv, Policy("password")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias"), keys[RSA][0].prv, Policy("password")); test_negative(&ManagerAsync::createSignature, CKM_API_ERROR_INPUT_PARAM, - dbc.key("alias"), + dbc.alias("alias"), "wrong-password", RawBuffer(), HashAlgorithm::SHA1, @@ -1022,9 +986,9 @@ RUNNER_CHILD_TEST(TA1550_create_signature_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias"), keys[RSA][0].prv, Policy("password")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias"), keys[RSA][0].prv, Policy("password")); test_positive(&ManagerAsync::createSignature, - dbc.key("alias"), + dbc.alias("alias"), "password", test_buffer, HashAlgorithm::SHA1, @@ -1058,10 +1022,10 @@ RUNNER_CHILD_TEST(TA1620_verify_signature_invalid_password) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_prv"), keys[RSA][0].prv, Policy("pass1")); - test_positive(&ManagerAsync::saveKey, dbc.key("alias_pub"), keys[RSA][0].pub, Policy("pass2")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_prv"), keys[RSA][0].prv, Policy("pass1")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_pub"), keys[RSA][0].pub, Policy("pass2")); auto obs = test_positive(&ManagerAsync::createSignature, - dbc.key("alias_prv"), + dbc.alias("alias_prv"), "pass1", test_buffer, HashAlgorithm::SHA1, @@ -1069,7 +1033,7 @@ RUNNER_CHILD_TEST(TA1620_verify_signature_invalid_password) test_negative(&ManagerAsync::verifySignature, CKM_API_ERROR_SERVER_ERROR, - dbc.key("alias_pub"), + dbc.alias("alias_pub"), "wrong-password", test_buffer, obs->m_signed, @@ -1082,11 +1046,11 @@ RUNNER_CHILD_TEST(TA1630_verify_signature_invalid_message) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_prv"), keys[RSA][0].prv, Policy("")); - test_positive(&ManagerAsync::saveKey, dbc.key("alias_pub"), keys[RSA][0].pub, Policy("")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_prv"), keys[RSA][0].prv, Policy("")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_pub"), keys[RSA][0].pub, Policy("")); auto obs = test_positive(&ManagerAsync::createSignature, - dbc.key("alias_prv"), + dbc.alias("alias_prv"), "", test_buffer, HashAlgorithm::SHA1, @@ -1094,7 +1058,7 @@ RUNNER_CHILD_TEST(TA1630_verify_signature_invalid_message) test_negative(&ManagerAsync::verifySignature, CKM_API_ERROR_VERIFICATION_FAILED, - dbc.key("alias_pub"), + dbc.alias("alias_pub"), "", raw_buffer("invalid-unsigned-mesage"), obs->m_signed, @@ -1107,11 +1071,11 @@ RUNNER_CHILD_TEST(TA1640_verify_signature_invalid_signature) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_pub"), keys[RSA][0].pub, Policy("")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_pub"), keys[RSA][0].pub, Policy("")); test_negative(&ManagerAsync::verifySignature, CKM_API_ERROR_VERIFICATION_FAILED, - dbc.key("alias_pub"), + dbc.alias("alias_pub"), "", test_buffer, raw_buffer("invalid-signature"), @@ -1124,9 +1088,9 @@ RUNNER_CHILD_TEST(TA1650_verify_signature_wrong_key) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_prv"), keys[RSA][0].prv, Policy("")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_prv"), keys[RSA][0].prv, Policy("")); auto obs = test_positive(&ManagerAsync::createSignature, - dbc.key("alias_prv"), + dbc.alias("alias_prv"), "", test_buffer, HashAlgorithm::SHA1, @@ -1134,7 +1098,7 @@ RUNNER_CHILD_TEST(TA1650_verify_signature_wrong_key) test_negative(&ManagerAsync::verifySignature, CKM_API_ERROR_SERVER_ERROR, - dbc.key("alias_prv"), + dbc.alias("alias_prv"), "", test_buffer, obs->m_signed, @@ -1147,17 +1111,17 @@ RUNNER_CHILD_TEST(TA1660_verify_signature_positive) switch_to_storage_user(TEST_LABEL); DBCleanup dbc; - test_positive(&ManagerAsync::saveKey, dbc.key("alias_prv"), keys[RSA][0].prv, Policy("pass1")); - test_positive(&ManagerAsync::saveKey, dbc.key("alias_pub"), keys[RSA][0].pub, Policy("pass2")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_prv"), keys[RSA][0].prv, Policy("pass1")); + test_positive(&ManagerAsync::saveKey, dbc.alias("alias_pub"), keys[RSA][0].pub, Policy("pass2")); auto obs = test_positive(&ManagerAsync::createSignature, - dbc.key("alias_prv"), + dbc.alias("alias_prv"), "pass1", test_buffer, HashAlgorithm::SHA1, RSAPaddingAlgorithm::PKCS1); test_positive(&ManagerAsync::verifySignature, - dbc.key("alias_pub"), + dbc.alias("alias_pub"), "pass2", test_buffer, obs->m_signed, @@ -1200,7 +1164,7 @@ RUNNER_CHILD_TEST(TA1750_ocsp_check_positive) "Verification failed. Error: " << obs->m_ocspStatus); } -// allowAccess +// setPermission RUNNER_CHILD_TEST(TA1810_allow_access_invalid_param) { switch_to_storage_user(TEST_LABEL); @@ -1214,35 +1178,35 @@ RUNNER_TEST(TA1820_allow_access) { DBCleanup dbc; CharPtr top_label = get_label(); - test_positive(&ManagerAsync::saveData, dbc.data("alias"), test_buffer, Policy()); - test_positive(&ManagerAsync::saveData, dbc.data("alias2"), test_buffer, Policy()); - test_positive(&ManagerAsync::saveData, dbc.data("alias3"), test_buffer, Policy()); + test_positive(&ManagerAsync::saveData, dbc.alias("alias"), test_buffer, Policy()); + test_positive(&ManagerAsync::saveData, dbc.alias("alias2"), test_buffer, Policy()); + test_positive(&ManagerAsync::saveData, dbc.alias("alias3"), test_buffer, Policy()); test_positive(&ManagerAsync::setPermission, - dbc.data("alias2"), + dbc.alias("alias2"), TEST_LABEL, Permission::READ); test_positive(&ManagerAsync::setPermission, - dbc.data("alias3"), + dbc.alias("alias3"), TEST_LABEL, Permission::READ_REMOVE); { ScopedLabel label(TEST_LABEL); - test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, dbc.data("alias"), ""); - test_negative(&ManagerAsync::removeData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, dbc.data("alias")); + test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, dbc.alias("alias"), ""); + test_negative(&ManagerAsync::removeAlias, CKM_API_ERROR_DB_ALIAS_UNKNOWN, dbc.alias("alias")); // test from allowed label, but without properly addressing alias (coming from default label) - test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, dbc.data("alias2"), ""); + test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, dbc.alias("alias2"), ""); // now test with appropriate addressing - std::string full_alias2_address = aliasWithLabel(top_label.get(), dbc.data("alias2")); + std::string full_alias2_address = aliasWithLabel(top_label.get(), dbc.alias("alias2")); test_positive(&ManagerAsync::getData, full_alias2_address, ""); - test_negative(&ManagerAsync::removeData, CKM_API_ERROR_ACCESS_DENIED, full_alias2_address); + test_negative(&ManagerAsync::removeAlias, CKM_API_ERROR_ACCESS_DENIED, full_alias2_address); - std::string full_alias3_address = aliasWithLabel(top_label.get(), dbc.data("alias3")); + std::string full_alias3_address = aliasWithLabel(top_label.get(), dbc.alias("alias3")); test_positive(&ManagerAsync::getData, full_alias3_address, ""); - test_positive(&ManagerAsync::removeData, full_alias3_address); + test_positive(&ManagerAsync::removeAlias, full_alias3_address); } } @@ -1260,19 +1224,19 @@ RUNNER_TEST(TA1920_deny_access) { DBCleanup dbc; CharPtr top_label = get_label(); - test_positive(&ManagerAsync::saveData, dbc.data("alias"), test_buffer, Policy()); + test_positive(&ManagerAsync::saveData, dbc.alias("alias"), test_buffer, Policy()); test_positive(&ManagerAsync::setPermission, - dbc.data("alias"), + dbc.alias("alias"), TEST_LABEL, Permission::READ_REMOVE); - test_positive(&ManagerAsync::setPermission, dbc.data("alias"), TEST_LABEL, CKM::Permission::NONE); + test_positive(&ManagerAsync::setPermission, dbc.alias("alias"), TEST_LABEL, CKM::Permission::NONE); { ScopedLabel label(TEST_LABEL); - std::string full_alias_address = aliasWithLabel(top_label.get(), dbc.data("alias")); + std::string full_alias_address = aliasWithLabel(top_label.get(), dbc.alias("alias")); test_negative(&ManagerAsync::getData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, full_alias_address, ""); - test_negative(&ManagerAsync::removeData, CKM_API_ERROR_DB_ALIAS_UNKNOWN, full_alias_address); + test_negative(&ManagerAsync::removeAlias, CKM_API_ERROR_DB_ALIAS_UNKNOWN, full_alias_address); } } diff --git a/tests/ckm/ckm-common.cpp b/tests/ckm/ckm-common.cpp index da358da..676b5b0 100644 --- a/tests/ckm/ckm-common.cpp +++ b/tests/ckm/ckm-common.cpp @@ -45,15 +45,9 @@ DBCleanup::~DBCleanup() { // Let it throw. If db can't be cleared further tests are unreliable CKM::ManagerShPtr mgr = CKM::Manager::create(); - for(const auto& it:m_keys) - mgr->removeKey(it); - m_keys.clear(); - for(const auto& it:m_certs) - mgr->removeCertificate(it); - m_certs.clear(); - for(const auto& it:m_data) - mgr->removeData(it); - m_data.clear(); + for(const auto& it:m_aliases) + mgr->removeAlias(it); + m_aliases.clear(); } // returns process label diff --git a/tests/ckm/ckm-common.h b/tests/ckm/ckm-common.h index cc9bdef..d1f36a7 100644 --- a/tests/ckm/ckm-common.h +++ b/tests/ckm/ckm-common.h @@ -34,27 +34,15 @@ class DBCleanup public: DBCleanup() {} - const char* key(const char* alias) + const char* alias(const char* alias) { - return m_keys.insert(CKM::Alias(alias)).first->c_str(); - } - - const char* cert(const char* alias) - { - return m_certs.insert(CKM::Alias(alias)).first->c_str(); - } - - const char* data(const char* alias) - { - return m_data.insert(CKM::Alias(alias)).first->c_str(); + return m_aliases.insert(CKM::Alias(alias)).first->c_str(); } ~DBCleanup(); private: - std::unordered_set m_keys; - std::unordered_set m_certs; - std::unordered_set m_data; + std::unordered_set m_aliases; }; // scoped free diff --git a/tests/ckm/main.cpp b/tests/ckm/main.cpp index 66160d6..ea39738 100644 --- a/tests/ckm/main.cpp +++ b/tests/ckm/main.cpp @@ -34,9 +34,9 @@ static const int USER_TEST = 5001; */ -RUNNER_TEST_GROUP_INIT(T0000_CKM_CONTROL); +RUNNER_TEST_GROUP_INIT(T0010_CKM_CONTROL); -RUNNER_TEST(T0010_Control) +RUNNER_TEST(T0011_Control) { int temp; auto control = CKM::Control::create(); @@ -50,7 +50,7 @@ RUNNER_TEST(T0010_Control) "Error=" << CKM::ErrorToString(temp)); } -RUNNER_TEST(T0020_Control) +RUNNER_TEST(T0012_Control) { int temp; auto control = CKM::Control::create(); @@ -62,7 +62,7 @@ RUNNER_TEST(T0020_Control) "Error=" << CKM::ErrorToString(temp)); } -RUNNER_TEST(T0030_Control) +RUNNER_TEST(T0013_Control) { int temp; auto control = CKM::Control::create(); @@ -71,7 +71,7 @@ RUNNER_TEST(T0030_Control) "Error=" << CKM::ErrorToString(temp)); } -RUNNER_TEST(T0040_Control) +RUNNER_TEST(T0014_Control) { int temp; auto control = CKM::Control::create(); @@ -80,7 +80,7 @@ RUNNER_TEST(T0040_Control) "Error=" << CKM::ErrorToString(temp)); } -RUNNER_TEST(T0050_Control) +RUNNER_TEST(T0015_Control) { int temp; auto control = CKM::Control::create(); @@ -533,13 +533,13 @@ RUNNER_TEST(T1033_remove_bin_data) std::string invalid_address = aliasWithLabel("i-do-not-exist", "data1"); RUNNER_ASSERT_MSG( - CKM_API_ERROR_DB_ALIAS_UNKNOWN == (temp = manager->removeData(invalid_address.c_str())), + CKM_API_ERROR_DB_ALIAS_UNKNOWN == (temp = manager->removeAlias(invalid_address.c_str())), "Error=" << CKM::ErrorToString(temp)); RUNNER_ASSERT_MSG( - CKM_API_SUCCESS == (temp = manager->removeData("data1")), + CKM_API_SUCCESS == (temp = manager->removeAlias("data1")), "Error=" << CKM::ErrorToString(temp)); RUNNER_ASSERT_MSG( - CKM_API_SUCCESS == (temp = manager->removeData("data3")), + CKM_API_SUCCESS == (temp = manager->removeAlias("data3")), "Error=" << CKM::ErrorToString(temp)); RUNNER_ASSERT_MSG( CKM_API_SUCCESS == (temp = manager->getDataAliasVector(labelAliasVector)), @@ -2680,10 +2680,10 @@ RUNNER_CHILD_TEST(T1611_unlock_default_passwd) std::string invalid_address = aliasWithLabel("i-do-not-exist", alias.c_str()); RUNNER_ASSERT_MSG( - CKM_API_ERROR_DB_ALIAS_UNKNOWN == (temp = manager->removeKey(invalid_address.c_str())), + CKM_API_ERROR_DB_ALIAS_UNKNOWN == (temp = manager->removeAlias(invalid_address.c_str())), "Error=" << CKM::ErrorToString(temp)); RUNNER_ASSERT_MSG( - CKM_API_SUCCESS == (temp = manager->removeKey(alias)), + CKM_API_SUCCESS == (temp = manager->removeAlias(alias)), "Error=" << CKM::ErrorToString(temp)); } @@ -2734,7 +2734,7 @@ RUNNER_CHILD_TEST(T1613_unlock_default_passwd_negative) CKM_API_ERROR_DB_LOCKED == (temp = manager->getKey(alias, CKM::Password(), key2)), "Error=" << CKM::ErrorToString(temp)); RUNNER_ASSERT_MSG( - CKM_API_ERROR_DB_LOCKED == (temp = manager->removeKey(alias)), + CKM_API_ERROR_DB_LOCKED == (temp = manager->removeAlias(alias)), "Error=" << CKM::ErrorToString(temp)); } @@ -3139,6 +3139,7 @@ RUNNER_TEST(T1803_negative_broken_buffer) { "Expected error in PKCS12::create()"); } + RUNNER_TEST_GROUP_INIT(T190_CKM_EMPTY_STORAGE_TESTS); RUNNER_TEST(T1901_init_unlock_key) -- 2.7.4