From 2b553fd18c25db175349b054666c02a1d7146704 Mon Sep 17 00:00:00 2001 From: tranthanhtung2001 Date: Wed, 7 Aug 2024 13:19:44 +0700 Subject: [PATCH] Add test case for set_certificate_status_to_store function in cert-server-logic.c Change-Id: I88ec1284f71230412096dc467a6d092a71dcd9ec Signed-off-by: tranthanhtung2001 --- unit-tests/test_cert_server_logic.cpp | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/unit-tests/test_cert_server_logic.cpp b/unit-tests/test_cert_server_logic.cpp index 1a772fa..e669d19 100644 --- a/unit-tests/test_cert_server_logic.cpp +++ b/unit-tests/test_cert_server_logic.cpp @@ -133,8 +133,74 @@ void uninstallCertFromStore() } } +void setCertStatusToStore(CertStatus certStatus) +{ + int result; + for (auto storeType : storeTypeMap) + { + installCertToStore(std::string(), std::string(), PemCertInfo::CertPEM.c_str(), PEM_CRT); + + result = setCertificateStatusToStore(storeType.second, certStatus, gNamePrefix.c_str(), DISABLED); + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + + result = setCertificateStatusToStore(storeType.second, certStatus, gNamePrefix.c_str(), ENABLED); + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + + uninstallCertFromStore(); + } +} + BOOST_AUTO_TEST_SUITE(CERT_SERVER_LOGIC_TEST) +POSITIVE_TEST_CASE(T_set_certificate_status_to_store) +{ + int result = initialize_db(); + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + + setCertStatusToStore(ENABLED); + + setCertStatusToStore(DISABLED); + + deinitialize_db(); +} + +NEGATIVE_TEST_CASE(T_set_certificate_status_to_store_with_database_no_records) +{ + int result = initialize_db(); + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); + + for (auto storeType : storeTypeMap) + { + result = setCertificateStatusToStore(storeType.second, DISABLED, systemGname.c_str(), ENABLED); + BOOST_CHECK_EQUAL(result, CERTSVC_FAIL); + } + + deinitialize_db(); +} + +NEGATIVE_TEST_CASE(T_set_certificate_status_to_store_with_database_no_init_and_gname_parameter_is_null) +{ + int result = setCertificateStatusToStore(SYSTEM_STORE, DISABLED, systemGname.c_str(), ENABLED); + BOOST_CHECK_EQUAL(result, CERTSVC_FAIL); + + for (auto storeType : storeTypeMap) + { + result = setCertificateStatusToStore(storeType.second, ENABLED, NULL, ENABLED); + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); + } +} + +NEGATIVE_TEST_CASE(T_set_certificate_status_to_store_with_status_parameter_invalid) +{ + CertStatus outOfCertStatus = static_cast(1 << 2); + int result; + for (auto storeType : storeTypeMap) + { + result = setCertificateStatusToStore(storeType.second, ENABLED, systemGname.c_str(), outOfCertStatus); + BOOST_CHECK_EQUAL(result, CERTSVC_INVALID_STATUS); + } +} + POSITIVE_TEST_CASE(T_install_certificate_to_store) { int result; -- 2.7.4