Add test check_alias_exists_in_store function in cert-server-logic.c 96/315796/9
authortranthanhtung2001 <tran.tung@samsung.com>
Thu, 8 Aug 2024 01:05:08 +0000 (08:05 +0700)
committertung tran <tran.tung@samsung.com>
Tue, 20 Aug 2024 10:55:40 +0000 (10:55 +0000)
Change-Id: I4babbf5509cfc8b39639c0c85db717a71ea8b6be
Signed-off-by: tranthanhtung2001 <tran.tung@samsung.com>
unit-tests/test_cert_server_logic.cpp

index ab6f2dc..583d593 100644 (file)
@@ -169,6 +169,24 @@ void getCertStatusFromStore(int expectedResult, CertStatus expectedStatus, bool
        }
 }
 
+void checkAliasExistsAtStore(int expectedResult, int expectedUnique, std::string alias, bool isInstallCert)
+{
+       if (isInstallCert)
+               installCertToStore(std::string(), std::string(), PemCertInfo::CertPEM.c_str(), PEM_CRT);
+
+       int unique = 0, result;
+       for (auto storeType : storeTypeMap)
+       {
+               result = checkAliasExistsInStore(storeType.second, alias.empty() ? NULL : alias.c_str(), &unique);
+
+               BOOST_CHECK_EQUAL(result, expectedResult);
+               BOOST_CHECK_EQUAL(unique, expectedUnique);
+       }
+
+       if (isInstallCert)
+               uninstallCertFromStore();
+}
+
 BOOST_AUTO_TEST_SUITE(CERT_SERVER_LOGIC_TEST)
 
 POSITIVE_TEST_CASE(T_get_certificate_status_from_store)
@@ -254,6 +272,25 @@ NEGATIVE_TEST_CASE(T_set_certificate_status_to_store_with_status_parameter_inval
        }
 }
 
+POSITIVE_TEST_CASE(T_check_alias_exists_in_store)
+{
+       int result = initialize_db();
+       BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+       checkAliasExistsAtStore(CERTSVC_SUCCESS, 0, commonNamePrefix, true);
+
+       checkAliasExistsAtStore(CERTSVC_SUCCESS, 1, commonNamePrefix, false);
+
+       deinitialize_db();
+}
+
+NEGATIVE_TEST_CASE(T_check_alias_exists_in_store_with_alias_param_null_and_db_no_init)
+{
+       checkAliasExistsAtStore(CERTSVC_WRONG_ARGUMENT, 0, std::string(), false);
+
+       checkAliasExistsAtStore(CERTSVC_FAIL, 0, commonNamePrefix, false);
+}
+
 POSITIVE_TEST_CASE(T_install_certificate_to_store)
 {
        int result;