1 /*
2 * Copyright (c) 2022 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 "huks_nullptr_test.h"
17
18 #include <gtest/gtest.h>
19
20 using namespace testing::ext;
21 namespace Unittest::NullPtrTest
22 {
23 class HuksNullptrTest : public testing::Test
24 {
25 public:
26 static void SetUpTestCase(void);
27
28 static void TearDownTestCase(void);
29
30 void SetUp();
31
32 void TearDown();
33 };
34
SetUpTestCase(void)35 void HuksNullptrTest::SetUpTestCase(void) {}
36
TearDownTestCase(void)37 void HuksNullptrTest::TearDownTestCase(void) {}
38
SetUp()39 void HuksNullptrTest::SetUp() {}
40
TearDown()41 void HuksNullptrTest::TearDown() {}
42
43 static struct OH_Huks_ParamSet *paramSetNullptr = nullptr;
44 static struct OH_Huks_Param *paramNullptr = nullptr;
45 static struct OH_Huks_Blob *blobNullptr = nullptr;
46 static struct OH_Huks_CertChain *certChainNullptr = nullptr;
47
48 /**
49 * @tc.name: HuksNullptrTest.Security_HUKS_NAPI_nullptr_0100
50 * @tc.desc: use nullptr.
51 * @tc.type: FUNC
52 */
53 HWTEST_F(HuksNullptrTest, Security_HUKS_NAPI_nullptr_0100, TestSize.Level0)
54 {
55 OH_Huks_Result ret = OH_Huks_InitParamSet(¶mSetNullptr);
56 EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
57
58 ret = OH_Huks_AddParams(paramSetNullptr, paramNullptr, 0);
59 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
60
61 ret = OH_Huks_BuildParamSet(¶mSetNullptr);
62 EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
63
64 ret = OH_Huks_CopyParamSet(paramSetNullptr, 0, ¶mSetNullptr);
65 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
66
67 ret = OH_Huks_GetParam(paramSetNullptr, 0, ¶mNullptr);
68 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
69
70 ret = OH_Huks_FreshParamSet(paramSetNullptr, 0);
71 EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
72
73 ret = OH_Huks_IsParamSetTagValid(paramSetNullptr);
74 EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
75
76 ret = OH_Huks_IsParamSetValid(paramSetNullptr, 0);
77 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
78
79 struct OH_Huks_Param baseParam = {.tag = OH_HUKS_TAG_ALGORITHM, .uint64Param = (uint64_t)1};
80 struct OH_Huks_Param otherParam = {.tag = OH_HUKS_TAG_ALGORITHM, .uint64Param = (uint64_t)2};
81 ret = OH_Huks_CheckParamMatch(&baseParam, &otherParam);
82 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
83
84 ret = OH_Huks_GetSdkVersion(blobNullptr);
85 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
86
87 ret = OH_Huks_GenerateKeyItem(blobNullptr, paramSetNullptr, paramSetNullptr);
88 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
89
90 ret = OH_Huks_ImportWrappedKeyItem(blobNullptr, blobNullptr, paramSetNullptr, blobNullptr);
91 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
92
93 ret = OH_Huks_ExportPublicKeyItem(blobNullptr, paramSetNullptr, blobNullptr);
94 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
95
96 ret = OH_Huks_DeleteKeyItem(blobNullptr, paramSetNullptr);
97 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
98
99 ret = OH_Huks_GetKeyItemParamSet(blobNullptr, paramSetNullptr, paramSetNullptr);
100 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
101
102 ret = OH_Huks_IsKeyItemExist(blobNullptr, paramSetNullptr);
103 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
104
105 ret = OH_Huks_AttestKeyItem(blobNullptr, paramSetNullptr, certChainNullptr);
106 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
107
108 ret = OH_Huks_InitSession(blobNullptr, paramSetNullptr, blobNullptr, blobNullptr);
109 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
110
111 ret = OH_Huks_UpdateSession(blobNullptr, paramSetNullptr, blobNullptr, blobNullptr);
112 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
113
114 ret = OH_Huks_FinishSession(blobNullptr, paramSetNullptr, blobNullptr, blobNullptr);
115 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
116
117 ret = OH_Huks_AbortSession(blobNullptr, paramSetNullptr);
118 EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
119 }
120 }; // namespace Unittest::NullPtrTest
121