11e934351Sopenharmony_ci/* 21e934351Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 31e934351Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41e934351Sopenharmony_ci * you may not use this file except in compliance with the License. 51e934351Sopenharmony_ci * You may obtain a copy of the License at 61e934351Sopenharmony_ci * 71e934351Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81e934351Sopenharmony_ci * 91e934351Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101e934351Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111e934351Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121e934351Sopenharmony_ci * See the License for the specific language governing permissions and 131e934351Sopenharmony_ci * limitations under the License. 141e934351Sopenharmony_ci */ 151e934351Sopenharmony_ci 161e934351Sopenharmony_ci#include <cstring> 171e934351Sopenharmony_ci#include <iostream> 181e934351Sopenharmony_ci 191e934351Sopenharmony_ci#include "cert_context.h" 201e934351Sopenharmony_ci#include "gtest/gtest.h" 211e934351Sopenharmony_ci#include "net_ssl.h" 221e934351Sopenharmony_ci#include "net_ssl_async_work.h" 231e934351Sopenharmony_ci#include "net_ssl_exec.h" 241e934351Sopenharmony_ci#include "net_ssl_module.h" 251e934351Sopenharmony_ci#include "net_ssl_verify_cert.h" 261e934351Sopenharmony_ci#include "netstack_log.h" 271e934351Sopenharmony_ci 281e934351Sopenharmony_ciclass NetsslTest : public testing::Test { 291e934351Sopenharmony_cipublic: 301e934351Sopenharmony_ci static void SetUpTestCase() {} 311e934351Sopenharmony_ci 321e934351Sopenharmony_ci static void TearDownTestCase() {} 331e934351Sopenharmony_ci 341e934351Sopenharmony_ci virtual void SetUp() {} 351e934351Sopenharmony_ci 361e934351Sopenharmony_ci virtual void TearDown() {} 371e934351Sopenharmony_ci}; 381e934351Sopenharmony_ci 391e934351Sopenharmony_cinamespace { 401e934351Sopenharmony_ciusing namespace testing::ext; 411e934351Sopenharmony_ciusing namespace OHOS::NetStack::Ssl; 421e934351Sopenharmony_ci 431e934351Sopenharmony_ciHWTEST_F(NetsslTest, CertVerifyTest001, TestSize.Level1) 441e934351Sopenharmony_ci{ 451e934351Sopenharmony_ci napi_env env = nullptr; 461e934351Sopenharmony_ci CertContext context(env, nullptr); 471e934351Sopenharmony_ci 481e934351Sopenharmony_ci bool ret = SslExec::ExecVerify(&context); 491e934351Sopenharmony_ci EXPECT_EQ(ret, false); 501e934351Sopenharmony_ci} 511e934351Sopenharmony_ci 521e934351Sopenharmony_ciHWTEST_F(NetsslTest, NetStackVerifyCertificationTest001, TestSize.Level1) 531e934351Sopenharmony_ci{ 541e934351Sopenharmony_ci CertBlob *cert = nullptr; 551e934351Sopenharmony_ci CertBlob *caCert = nullptr; 561e934351Sopenharmony_ci 571e934351Sopenharmony_ci uint32_t ret = NetStackVerifyCertification(cert); 581e934351Sopenharmony_ci EXPECT_EQ(ret, SSL_X509_V_ERR_UNSPECIFIED); 591e934351Sopenharmony_ci 601e934351Sopenharmony_ci ret = NetStackVerifyCertification(cert, caCert); 611e934351Sopenharmony_ci EXPECT_EQ(ret, SSL_X509_V_ERR_UNSPECIFIED); 621e934351Sopenharmony_ci} 631e934351Sopenharmony_ci 641e934351Sopenharmony_ciHWTEST_F(NetsslTest, NetStackVerifyCertificationTest002, TestSize.Level1) 651e934351Sopenharmony_ci{ 661e934351Sopenharmony_ci CertBlob cert; 671e934351Sopenharmony_ci CertBlob caCert; 681e934351Sopenharmony_ci 691e934351Sopenharmony_ci uint32_t ret = NetStackVerifyCertification(&cert); 701e934351Sopenharmony_ci EXPECT_EQ(ret, SSL_X509_V_ERR_UNSPECIFIED); 711e934351Sopenharmony_ci 721e934351Sopenharmony_ci ret = NetStackVerifyCertification(&cert, &caCert); 731e934351Sopenharmony_ci EXPECT_EQ(ret, SSL_X509_V_ERR_UNSPECIFIED); 741e934351Sopenharmony_ci} 751e934351Sopenharmony_ci} // namespace 76