From: tranthanhtung2001 Date: Mon, 5 Aug 2024 05:39:58 +0000 (+0700) Subject: Add test case for update_ca_certificate_file in cert-server-logic.c X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fa9cbdc704e799ad088ec139e12c39cbbc45477a;p=platform%2Fcore%2Fsecurity%2Fcert-svc.git Add test case for update_ca_certificate_file in cert-server-logic.c Change-Id: I8b6a02542774ea98353beef215c54d824022d413 Signed-off-by: tranthanhtung2001 --- diff --git a/unit-tests/test_cert_server_logic.cpp b/unit-tests/test_cert_server_logic.cpp index d20c0e9..1a772fa 100644 --- a/unit-tests/test_cert_server_logic.cpp +++ b/unit-tests/test_cert_server_logic.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include "cert-svc/ccert.h" #include "cert-svc/cerror.h" #include "test_common.h" @@ -99,6 +101,38 @@ void loadCertFromStores(CertStoreType storeType, const std::string &groupName, i free(certBlockBuffer); } +void installCertToStore( + std::string privateKeyGname, + std::string associatedGname, + std::string dataBlock, + CertType certType) +{ + int result; + for(auto storeType: storeTypeMap) + { + result = installCertificateToStore( + storeType.second, + gNamePrefix.c_str(), + commonNamePrefix.c_str(), + privateKeyGname.empty() ? NULL : privateKeyGname.c_str(), + associatedGname.empty() ? NULL : associatedGname.c_str(), + dataBlock.empty() ? NULL : dataBlock.c_str(), + certType); + + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + } +} + +void uninstallCertFromStore() +{ + int result; + for(auto storeType: storeTypeMap) + { + result = deleteCertificateFromStore(storeType.second, gNamePrefix.c_str()); + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + } +} + BOOST_AUTO_TEST_SUITE(CERT_SERVER_LOGIC_TEST) POSITIVE_TEST_CASE(T_install_certificate_to_store) @@ -421,28 +455,11 @@ POSITIVE_TEST_CASE(T_delete_certificate_same_gname_from_stores) result = initialize_db(); BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); - for(auto storeType: storeTypeMap) - { - result = installCertificateToStore( - storeType.second, - gNamePrefix.c_str(), - commonNamePrefix.c_str(), - NULL, - NULL, - PemCertInfo::CertPEM.c_str(), - PEM_CRT); - - BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); - } + installCertToStore(std::string(), std::string(), PemCertInfo::CertPEM, PEM_CRT); - for(auto storeType: storeTypeMap) - { - result = deleteCertificateFromStore(storeType.second, gNamePrefix.c_str()); - BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); - } + uninstallCertFromStore(); deinitialize_db(); - } NEGATIVE_TEST_CASE(T_delete_certificate_from_store_error) @@ -470,4 +487,29 @@ NEGATIVE_TEST_CASE(T_delete_certificate_from_store_error) BOOST_CHECK_EQUAL(result, CERTSVC_FAIL); } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +POSITIVE_TEST_CASE(T_update_ca_certificate_file) +{ + int result = update_ca_certificate_file(const_cast(PemCertInfo::CertPEM.c_str())); + + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); +} + +NEGATIVE_TEST_CASE(T_update_ca_certificate_file_with_parameter_cert_is_null) +{ + int result = update_ca_certificate_file(NULL); + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); + + result = initialize_db(); + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + + installCertToStore(std::string(), std::string(), PemCertInfo::CertPEM, PEM_CRT); + + result = update_ca_certificate_file(NULL); + + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + + uninstallCertFromStore(); + deinitialize_db(); +} + +BOOST_AUTO_TEST_SUITE_END()