From: Phan Xuan Tan Date: Tue, 9 Jul 2024 05:51:33 +0000 (+0700) Subject: Add positive and negative test cases for vcore_client_install_certificate_to_store X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F33%2F314233%2F7;p=platform%2Fcore%2Fsecurity%2Fcert-svc.git Add positive and negative test cases for vcore_client_install_certificate_to_store Change-Id: Ia499fe1a2b06748f96b422b20dc1964118b34557 --- diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt index 8ba8c02..2b1e96a 100644 --- a/unit-tests/CMakeLists.txt +++ b/unit-tests/CMakeLists.txt @@ -69,6 +69,7 @@ SET(UNIT_TESTS_SOURCES test_vcore_api.cpp test_vcore_time_conversion.cpp test_vcore_certificate_collection.cpp + test_vcore_client.cpp test_vcore_api_cert.cpp test_vcore_api_pkcs12.cpp test_vcore_signature_data.cpp diff --git a/unit-tests/test_vcore_client.cpp b/unit-tests/test_vcore_client.cpp new file mode 100644 index 0000000..0e0a468 --- /dev/null +++ b/unit-tests/test_vcore_client.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cert-svc/ccert.h" +#include "test_common.h" +#include "test_constant.h" +#include "test_macros.h" +#include "vcore/Client.h" +#include + +static const std::string ValidGname = "9737fca362f1e671c1ca21a8e9a7a01e9acda93f"; +static const std::string CommonName = "TEST_PEM_CLIENT"; + +const std::string LargeString = createLargeString(VCORE_MAX_FILENAME_SIZE + 1); + +BOOST_AUTO_TEST_SUITE(VCORE_CLIENT_TEST) + +POSITIVE_TEST_CASE(T_vcore_client_install_certificate_to_store) +{ + int result; + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + CommonName.c_str(), + NULL, + NULL, + PemCertInfo::CertPEM.c_str(), + static_cast(PemCertInfo::CertPEM.size()), + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS); +} + +NEGATIVE_TEST_CASE(T_vcore_client_install_certificate_to_store_wrong_argument) +{ + int result; + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + NULL, + CommonName.c_str(), + NULL, + NULL, + NULL, + 0, + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + CommonName.c_str(), + NULL, + NULL, + NULL, + 0, + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_FAIL); + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + CommonName.c_str(), + NULL, + NULL, + PemCertInfo::CertPEM.c_str(), + 0, + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_FAIL); + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + LargeString.c_str(), + CommonName.c_str(), + NULL, + NULL, + PemCertInfo::CertPEM.c_str(), + static_cast(PemCertInfo::CertPEM.size()), + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + LargeString.c_str(), + NULL, + NULL, + PemCertInfo::CertPEM.c_str(), + static_cast(PemCertInfo::CertPEM.size()), + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + CommonName.c_str(), + LargeString.c_str(), + NULL, + PemCertInfo::CertPEM.c_str(), + static_cast(PemCertInfo::CertPEM.size()), + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + CommonName.c_str(), + NULL, + LargeString.c_str(), + PemCertInfo::CertPEM.c_str(), + static_cast(PemCertInfo::CertPEM.size()), + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); + + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + CommonName.c_str(), + NULL, + NULL, + PemCertInfo::CertPEM.c_str(), + static_cast(PemCertInfo::CertPEM.size()), + INVALID_DATA); + + BOOST_CHECK_EQUAL(result, CERTSVC_BAD_ALLOC); + + const std::string LargeCert = createLargeString(VCORE_MAX_SEND_DATA_SIZE + 1); + result = vcore_client_install_certificate_to_store( + VPN_STORE, + ValidGname.c_str(), + CommonName.c_str(), + NULL, + NULL, + LargeCert.c_str(), + static_cast(VCORE_MAX_SEND_DATA_SIZE + 1), + PEM_CRT); + + BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file