• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "gtest/gtest.h"
17 
18 #define private public
19 #include "tls_key.h"
20 
21 namespace OHOS::NetStack::TlsSocket {
22 class TLSKeyTest : public testing::Test {
23 public:
24     static void SetUpTestCase();
25     static void TearDownTestCase();
26     void SetUp() override;
27     void TearDown() override;
28 };
29 
SetUpTestCase()30 void TLSKeyTest::SetUpTestCase() {}
TearDownTestCase()31 void TLSKeyTest::TearDownTestCase() {}
SetUp()32 void TLSKeyTest::SetUp() {}
TearDown()33 void TLSKeyTest::TearDown() {}
34 
35 HWTEST_F(TLSKeyTest, TLSKeyTestt001, testing::ext::TestSize.Level1)
36 {
37     TLSKey key;
38     TLSKey other;
39     key = other;
40     EXPECT_EQ(key.opaque_, nullptr);
41     EXPECT_EQ(key.rsa_, nullptr);
42     EXPECT_EQ(key.dsa_, nullptr);
43     EXPECT_EQ(key.dh_, nullptr);
44     EXPECT_EQ(key.ec_, nullptr);
45     other.rsa_ = RSA_new();
46     other.dsa_ = DSA_new();
47     other.dh_ = DH_new();
48     other.ec_ = EC_KEY_new();
49     key = other;
50     EXPECT_NE(key.rsa_, nullptr);
51     EXPECT_NE(key.dsa_, nullptr);
52     EXPECT_NE(key.dh_, nullptr);
53     EXPECT_NE(key.ec_, nullptr);
54 }
55 
56 HWTEST_F(TLSKeyTest, TLSKeyTestt002, testing::ext::TestSize.Level1)
57 {
58     TLSKey key;
59     key.rsa_ = RSA_new();
60     key.dsa_ = DSA_new();
61     key.dh_ = DH_new();
62     key.ec_ = EC_KEY_new();
63     SecureData data;
64     SecureData phrase;
65     key.DecodeData(data, phrase);
66 
67     key.keyAlgorithm_ = OPAQUE;
68     EXPECT_EQ(key.handle(), nullptr);
69     key.keyAlgorithm_ = ALGORITHM_RSA;
70     EXPECT_NE(key.handle(), nullptr);
71     key.keyAlgorithm_ = ALGORITHM_DSA;
72     EXPECT_NE(key.handle(), nullptr);
73     key.keyAlgorithm_ = ALGORITHM_DH;
74     EXPECT_NE(key.handle(), nullptr);
75     key.keyAlgorithm_ = ALGORITHM_EC;
76     EXPECT_NE(key.handle(), nullptr);
77     key.keyAlgorithm_ = static_cast<KeyAlgorithm>(9999999);
78     EXPECT_EQ(key.handle(), nullptr);
79 }
80 } // namespace OHOS::NetStack::TlsSocket
81