Add tests checking pkcs12 has password 91/316491/3
authorLe <xuan.tien@samsung.com>
Thu, 22 Aug 2024 06:32:54 +0000 (13:32 +0700)
committerLe <xuan.tien@samsung.com>
Thu, 22 Aug 2024 07:16:05 +0000 (14:16 +0700)
Change-Id: I4138846fc1133bf8f6d98f42ed82f63707ff9d66
Signed-off-by: Le <xuan.tien@samsung.com>
unit-tests/test_vcore_api.cpp

index 44fcd4ebf7c0aa30324200c4302153eb24ca6504..6d51d33969208407f83eedabdf7754ace2a35ea3 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "test_macros.h"
 #include "test_common.h"
+#include "test_constant.h"
 #include "cert-svc/cprimitives.h"
 #include "cert-svc/cinstance.h"
 #include "cert-svc/cstring.h"
@@ -295,4 +296,43 @@ NEGATIVE_TEST_CASE(T_pkcs12_private_key_and_evp_pkey_dup_from_store_wrong_param)
        certsvc_instance_free(instance);
 }
 
+POSITIVE_TEST_CASE(T_certsvc_pkcs12_has_password)
+{
+       int result;
+       int hasPassword;
+
+       BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+       CertSvcString certPath = wrapperCertsvcStringNew(instance, ServerCert::P12WithPassPath.c_str(), &result);
+       BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+       result = certsvc_pkcs12_has_password(instance, certPath, &hasPassword);
+       BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+       BOOST_CHECK_EQUAL(hasPassword, CERTSVC_TRUE);
+
+       certsvc_string_free(certPath);
+       certsvc_instance_free(instance);
+}
+
+NEGATIVE_TEST_CASE(T_certsvc_pkcs12_has_password_with_invalid_param)
+{
+       int result;
+       int hasPassword;
+
+       BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+       CertSvcString certPath = wrapperCertsvcStringNew(instance, ServerCert::P12WithoutPassPath.c_str(), &result);
+       result = certsvc_pkcs12_has_password(instance, certPath, &hasPassword);
+       BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+       BOOST_CHECK_EQUAL(hasPassword, CERTSVC_FALSE);
+
+       CertSvcString certPathEmpty;
+       result = certsvc_pkcs12_has_password(instance, certPathEmpty, &hasPassword);
+       BOOST_CHECK_EQUAL(result, CERTSVC_IO_ERROR);
+       BOOST_CHECK_EQUAL(hasPassword, CERTSVC_FALSE);
+
+       certsvc_string_free(certPath);
+       certsvc_instance_free(instance);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file