• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstring>
17 #include <iostream>
18 
19 #include "cert_context.h"
20 #include "gtest/gtest.h"
21 #include "net_ssl.h"
22 #include "net_ssl_async_work.h"
23 #include "net_ssl_exec.h"
24 #include "net_ssl_module.h"
25 #include "net_ssl_verify_cert.h"
26 #include "netstack_log.h"
27 
28 class NetsslTest : public testing::Test {
29 public:
SetUpTestCase()30     static void SetUpTestCase() {}
31 
TearDownTestCase()32     static void TearDownTestCase() {}
33 
SetUp()34     virtual void SetUp() {}
35 
TearDown()36     virtual void TearDown() {}
37 };
38 
39 namespace {
40 using namespace testing::ext;
41 using namespace OHOS::NetStack;
42 using namespace OHOS::NetStack::Ssl;
43 constexpr const uint32_t CERT_BlOB_TO_X509_ERROR = 2305069;
44 
45 HWTEST_F(NetsslTest, CertVerifyTest001, TestSize.Level1)
46 {
47     napi_env env = nullptr;
48     std::shared_ptr<EventManager> manager = nullptr;
49     CertContext context(env, manager);
50 
51     bool ret = SslExec::ExecVerify(&context);
52     EXPECT_EQ(ret, false);
53 }
54 
55 HWTEST_F(NetsslTest, NetStackVerifyCertificationTest001, TestSize.Level1)
56 {
57     CertBlob *cert = nullptr;
58     CertBlob *caCert = nullptr;
59 
60     uint32_t ret = NetStackVerifyCertification(cert);
61     EXPECT_EQ(ret, CERT_BlOB_TO_X509_ERROR);
62 
63     ret = NetStackVerifyCertification(cert, caCert);
64     EXPECT_EQ(ret, CERT_BlOB_TO_X509_ERROR);
65 }
66 
67 HWTEST_F(NetsslTest, NetStackVerifyCertificationTest002, TestSize.Level1)
68 {
69     CertBlob cert;
70     CertBlob caCert;
71 
72     uint32_t ret = NetStackVerifyCertification(&cert);
73     EXPECT_EQ(ret, CERT_BlOB_TO_X509_ERROR);
74 
75     ret = NetStackVerifyCertification(&cert, &caCert);
76     EXPECT_EQ(ret, CERT_BlOB_TO_X509_ERROR);
77 }
78 } // namespace
79