Add positive and negative test cases for vcore_client_install_certificate_to_store 33/314233/7
authorPhan Xuan Tan <xuan.tan@samsung.com>
Tue, 9 Jul 2024 05:51:33 +0000 (12:51 +0700)
committerDariusz Michaluk <d.michaluk@samsung.com>
Tue, 16 Jul 2024 06:37:14 +0000 (06:37 +0000)
Change-Id: Ia499fe1a2b06748f96b422b20dc1964118b34557

unit-tests/CMakeLists.txt
unit-tests/test_vcore_client.cpp [new file with mode: 0644]

index 8ba8c02..2b1e96a 100644 (file)
@@ -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 (file)
index 0000000..0e0a468
--- /dev/null
@@ -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 <cstring>
+
+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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(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<size_t>(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