• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "gtest/gtest.h"
17 
18 #include "hdf_base.h"
19 #include "iam_logger.h"
20 #include "iam_ptr.h"
21 
22 #include "pin_auth_all_in_one_hdi.h"
23 #include "iam_common_defines.h"
24 #include "mock_iexecute_callback.h"
25 #include "mock_iall_in_one_executor.h"
26 
27 #define LOG_TAG "PIN_AUTH_SA"
28 
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace OHOS::UserIam::Common;
32 
33 namespace OHOS {
34 namespace UserIam {
35 namespace PinAuth {
36 using IamResultCode = OHOS::UserIam::UserAuth::ResultCode;
37 using IamExecutorRole = OHOS::UserIam::UserAuth::ExecutorRole;
38 using IamExecutorInfo = OHOS::UserIam::UserAuth::ExecutorInfo;
39 using IamAuthType = OHOS::UserIam::UserAuth::AuthType;
40 using IamExecutorSecureLevel = OHOS::UserIam::UserAuth::ExecutorSecureLevel;
41 using IamPropertyMode = OHOS::UserIam::UserAuth::PropertyMode;
42 namespace {
43 static const std::map<HDF_STATUS, IamResultCode> RESULT_CODE_MAP = {
44     {HDF_SUCCESS, UserAuth::ResultCode::SUCCESS},
45     {HDF_FAILURE, UserAuth::ResultCode::GENERAL_ERROR},
46     {HDF_ERR_TIMEOUT, UserAuth::ResultCode::TIMEOUT},
47     {HDF_ERR_QUEUE_FULL, UserAuth::ResultCode::BUSY},
48     {HDF_ERR_DEVICE_BUSY, UserAuth::ResultCode::BUSY},
49     {HDF_ERR_INVALID_PARAM, UserAuth::ResultCode::INVALID_PARAMETERS},
50 };
51 }
52 
53 class PinAuthAllInOneHdiUnitTest : public testing::Test {
54 public:
55     static void SetUpTestCase();
56     static void TearDownTestCase();
57     void SetUp();
58     void TearDown();
59 };
60 
SetUpTestCase()61 void PinAuthAllInOneHdiUnitTest::SetUpTestCase()
62 {
63 }
64 
TearDownTestCase()65 void PinAuthAllInOneHdiUnitTest::TearDownTestCase()
66 {
67 }
68 
SetUp()69 void PinAuthAllInOneHdiUnitTest::SetUp()
70 {
71 }
72 
TearDown()73 void PinAuthAllInOneHdiUnitTest::TearDown()
74 {
75 }
76 
77 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_001, TestSize.Level0)
78 {
79     auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
80     ASSERT_TRUE(executorProxy != nullptr);
__anoncb3b637e0202(ExecutorInfo &info) 81     EXPECT_CALL(*executorProxy, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([](ExecutorInfo &info) {
82         info = {
83             .executorRole = ExecutorRole::ALL_IN_ONE,
84             .authType = AuthType::PIN,
85             .esl = ExecutorSecureLevel::ESL0,
86         };
87         return HDF_SUCCESS;
88     });
89     PinAuthAllInOneHdi allInOneHdi(executorProxy);
90     IamExecutorInfo info = {};
91     auto ret = allInOneHdi.GetExecutorInfo(info);
92     EXPECT_TRUE(info.executorRole == IamExecutorRole::ALL_IN_ONE);
93     EXPECT_TRUE(info.authType == IamAuthType::PIN);
94     EXPECT_TRUE(info.esl == IamExecutorSecureLevel::ESL0);
95     EXPECT_TRUE(ret == IamResultCode::SUCCESS);
96 }
97 
98 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_002, TestSize.Level0)
99 {
100     for (const auto &pair : RESULT_CODE_MAP) {
101         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
102         ASSERT_TRUE(executorProxy != nullptr);
103         EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
104             .Times(Exactly(1))
__anoncb3b637e0302(ExecutorInfo &info) 105             .WillOnce([&pair](ExecutorInfo &info) {
106                 info = {
107                     .executorRole = ExecutorRole::ALL_IN_ONE,
108                     .authType = AuthType::PIN,
109                     .esl = ExecutorSecureLevel::ESL0,
110                 };
111                 return static_cast<int32_t>(pair.first);
112             });
113         PinAuthAllInOneHdi allInOneHdi(executorProxy);
114         IamExecutorInfo info = {};
115         auto ret = allInOneHdi.GetExecutorInfo(info);
116         EXPECT_TRUE(ret == pair.second);
117     }
118 }
119 
120 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_003, TestSize.Level0)
121 {
122     static const std::map<AuthType, pair<IamAuthType, IamResultCode>> data = {
123         {AuthType::PIN, {IamAuthType::PIN, IamResultCode::SUCCESS}},
124         {static_cast<AuthType>(AuthType::PIN + 1),
125             {IamAuthType::PIN, IamResultCode::GENERAL_ERROR}},
126         {static_cast<AuthType>(AuthType::PIN - 1),
127             {IamAuthType::PIN, IamResultCode::GENERAL_ERROR}},
128     };
129     for (const auto &pair : data) {
130         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
131         ASSERT_TRUE(executorProxy != nullptr);
132         EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
133             .Times(Exactly(1))
__anoncb3b637e0402(ExecutorInfo &info) 134             .WillOnce([&pair](ExecutorInfo &info) {
135                 info = {
136                     .executorRole = ExecutorRole::ALL_IN_ONE,
137                     .authType = pair.first,
138                     .esl = ExecutorSecureLevel::ESL0,
139                 };
140                 return HDF_SUCCESS;
141             });
142         PinAuthAllInOneHdi allInOneHdi(executorProxy);
143         IamExecutorInfo info = {};
144         auto ret = allInOneHdi.GetExecutorInfo(info);
145         EXPECT_TRUE(ret == pair.second.second);
146         if (ret == IamResultCode::SUCCESS) {
147             EXPECT_TRUE(info.authType == pair.second.first);
148         }
149     }
150 }
151 
152 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_004, TestSize.Level0)
153 {
154     static const std::map<ExecutorRole, pair<IamExecutorRole, IamResultCode>> data = {
155         {ExecutorRole::COLLECTOR, {IamExecutorRole::COLLECTOR, IamResultCode::SUCCESS}},
156         {ExecutorRole::VERIFIER, {IamExecutorRole::VERIFIER, IamResultCode::SUCCESS}},
157         {ExecutorRole::ALL_IN_ONE, {IamExecutorRole::ALL_IN_ONE, IamResultCode::SUCCESS}},
158         {static_cast<ExecutorRole>(ExecutorRole::COLLECTOR - 1),
159             {IamExecutorRole::ALL_IN_ONE, IamResultCode::GENERAL_ERROR}},
160         {static_cast<ExecutorRole>(ExecutorRole::ALL_IN_ONE + 1),
161             {IamExecutorRole::ALL_IN_ONE, IamResultCode::GENERAL_ERROR}},
162     };
163     for (const auto &pair : data) {
164         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
165         ASSERT_TRUE(executorProxy != nullptr);
166         EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
167             .Times(Exactly(1))
__anoncb3b637e0502(ExecutorInfo &info) 168             .WillOnce([&pair](ExecutorInfo &info) {
169                 info = {
170                     .executorRole = pair.first,
171                     .authType = AuthType::PIN,
172                     .esl = ExecutorSecureLevel::ESL0,
173                 };
174                 return HDF_SUCCESS;
175             });
176         PinAuthAllInOneHdi allInOneHdi(executorProxy);
177         IamExecutorInfo info = {};
178         auto ret = allInOneHdi.GetExecutorInfo(info);
179         EXPECT_TRUE(ret == pair.second.second);
180         if (ret == IamResultCode::SUCCESS) {
181             EXPECT_TRUE(info.executorRole == pair.second.first);
182         }
183     }
184 }
185 
186 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_005, TestSize.Level0)
187 {
188     static const std::map<ExecutorSecureLevel, pair<IamExecutorSecureLevel, IamResultCode>> data =
189         {
190             {ExecutorSecureLevel::ESL0, {IamExecutorSecureLevel::ESL0, IamResultCode::SUCCESS}},
191             {ExecutorSecureLevel::ESL1, {IamExecutorSecureLevel::ESL1, IamResultCode::SUCCESS}},
192             {ExecutorSecureLevel::ESL2, {IamExecutorSecureLevel::ESL2, IamResultCode::SUCCESS}},
193             {ExecutorSecureLevel::ESL3, {IamExecutorSecureLevel::ESL3, IamResultCode::SUCCESS}},
194             {static_cast<ExecutorSecureLevel>(ExecutorSecureLevel::ESL0 - 1),
195                 {IamExecutorSecureLevel::ESL3, IamResultCode::GENERAL_ERROR}},
196             {static_cast<ExecutorSecureLevel>(ExecutorSecureLevel::ESL3 + 1),
197                 {IamExecutorSecureLevel::ESL3, IamResultCode::GENERAL_ERROR}},
198         };
199     for (const auto &pair : data) {
200         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
201         ASSERT_TRUE(executorProxy != nullptr);
202         EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
203             .Times(Exactly(1))
__anoncb3b637e0602(ExecutorInfo &info) 204             .WillOnce([&pair](ExecutorInfo &info) {
205                 info = {
206                     .executorRole = ExecutorRole::ALL_IN_ONE,
207                     .authType = AuthType::PIN,
208                     .esl = pair.first,
209                 };
210                 return HDF_SUCCESS;
211             });
212         PinAuthAllInOneHdi allInOneHdi(executorProxy);
213         IamExecutorInfo info = {};
214         auto ret = allInOneHdi.GetExecutorInfo(info);
215         EXPECT_TRUE(ret == pair.second.second);
216         if (ret == IamResultCode::SUCCESS) {
217             EXPECT_TRUE(info.esl == pair.second.first);
218         }
219     }
220 }
221 
222 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_006, TestSize.Level0)
223 {
224     PinAuthAllInOneHdi allInOneHdi(nullptr);
225     IamExecutorInfo info = {};
226     auto ret = allInOneHdi.GetExecutorInfo(info);
227     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
228 }
229 
230 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_OnRegisterFinish_001, TestSize.Level0)
231 {
232     for (const auto &pair : RESULT_CODE_MAP) {
233         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
234         ASSERT_TRUE(executorProxy != nullptr);
235         EXPECT_CALL(*executorProxy, OnRegisterFinish(_, _, _))
236             .Times(Exactly(1))
237             .WillOnce(
238                 [&pair](const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey,
__anoncb3b637e0702(const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) 239                     const std::vector<uint8_t> &extraInfo) { return pair.first; });
240         PinAuthAllInOneHdi allInOneHdi(executorProxy);
241         auto ret =
242             allInOneHdi.OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
243         EXPECT_TRUE(ret == pair.second);
244     }
245 }
246 
247 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_OnRegisterFinish_002, TestSize.Level0)
248 {
249     PinAuthAllInOneHdi allInOneHdi(nullptr);
250     auto ret = allInOneHdi.OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
251     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
252 }
253 
254 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_OnSetData_001, TestSize.Level0)
255 {
256     for (const auto &pair : RESULT_CODE_MAP) {
257         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
258         ASSERT_TRUE(executorProxy != nullptr);
259         EXPECT_CALL(*executorProxy, SetData(_, _, _, _))
260             .Times(Exactly(1))
261             .WillOnce([&pair](uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t>& data,
262                 int32_t resultCode)
__anoncb3b637e0802(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t>& data, int32_t resultCode) 263                     { return pair.first; });
264         PinAuthAllInOneHdi allInOneHdi(executorProxy);
265         auto ret = allInOneHdi.OnSetData(0, 0, std::vector<uint8_t>(), 0);
266         EXPECT_TRUE(ret == pair.second);
267     }
268 }
269 
270 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_OnSetData_002, TestSize.Level0)
271 {
272     PinAuthAllInOneHdi allInOneHdi(nullptr);
273     auto ret = allInOneHdi.OnSetData(0, 0, std::vector<uint8_t>(), 0);
274     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
275 }
276 
277 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Enroll_001, TestSize.Level0)
278 {
279     for (const auto &pair : RESULT_CODE_MAP) {
280         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
281         ASSERT_TRUE(executorProxy != nullptr);
282         EXPECT_CALL(*executorProxy, Enroll(_, _, _))
283             .Times(Exactly(1))
284             .WillOnce([&pair](uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
__anoncb3b637e0902(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 285                           const sptr<IExecutorCallback> &callbackObj) { return pair.first; });
286         auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
287         ASSERT_TRUE(allInOneHdi != nullptr);
288         auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
289         ASSERT_TRUE(executeCallback != nullptr);
290         auto ret = allInOneHdi->Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, executeCallback);
291         EXPECT_TRUE(ret == pair.second);
292     }
293 }
294 
295 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Enroll_002, TestSize.Level0)
296 {
297     auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
298     ASSERT_TRUE(executorProxy != nullptr);
299     auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
300     ASSERT_TRUE(allInOneHdi != nullptr);
301     auto ret = allInOneHdi->Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, nullptr);
302     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
303 }
304 
305 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Enroll_003, TestSize.Level0)
306 {
307     auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(nullptr);
308     ASSERT_TRUE(allInOneHdi != nullptr);
309     auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
310     ASSERT_TRUE(executeCallback != nullptr);
311     auto ret = allInOneHdi->Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, executeCallback);
312     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
313 }
314 
315 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Enroll_004, TestSize.Level0)
316 {
317     PinAuthAllInOneHdi allInOneHdi(nullptr);
318     auto ret = allInOneHdi.Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, nullptr);
319     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
320 }
321 
322 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_001, TestSize.Level0)
323 {
324     for (const auto &pair : RESULT_CODE_MAP) {
325         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
326         ASSERT_TRUE(executorProxy != nullptr);
327         EXPECT_CALL(*executorProxy, Authenticate(_, _, _, _)).Times(Exactly(1)).WillOnce([&pair](
328             uint64_t scheduleId, const std::vector<uint64_t>& templateIdList, const std::vector<uint8_t> &extraInfo,
__anoncb3b637e0a02( uint64_t scheduleId, const std::vector<uint64_t>& templateIdList, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 329             const sptr<IExecutorCallback> &callbackObj) { return pair.first; });
330         auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
331         ASSERT_TRUE(allInOneHdi != nullptr);
332         auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
333         ASSERT_TRUE(executeCallback != nullptr);
334         const std::vector<uint64_t> templateIdList = {1, 2};
335         auto ret = allInOneHdi->Authenticate(0,
336             UserAuth::AuthenticateParam{0, templateIdList, std::vector<uint8_t>()}, executeCallback);
337         EXPECT_TRUE(ret == pair.second);
338     }
339 }
340 
341 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_002, TestSize.Level0)
342 {
343     auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
344     ASSERT_TRUE(executorProxy != nullptr);
345     auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
346     auto ret = allInOneHdi->Authenticate(0,
347         UserAuth::AuthenticateParam{0, std::vector<uint64_t>(), std::vector<uint8_t>()}, nullptr);
348     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
349 }
350 
351 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_003, TestSize.Level0)
352 {
353     auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(nullptr);
354     auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
355     ASSERT_TRUE(executeCallback != nullptr);
356     auto ret = allInOneHdi->Authenticate(0,
357         UserAuth::AuthenticateParam{0, std::vector<uint64_t>(), std::vector<uint8_t>()}, executeCallback);
358     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
359 }
360 
361 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_004, TestSize.Level0)
362 {
363     PinAuthAllInOneHdi allInOneHdi(nullptr);
364     auto ret = allInOneHdi.Authenticate(0,
365         UserAuth::AuthenticateParam{0, std::vector<uint64_t>(), std::vector<uint8_t>()}, nullptr);
366     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
367 }
368 
369 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Delete_001, TestSize.Level0)
370 {
371     for (const auto &pair : RESULT_CODE_MAP) {
372         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
373         ASSERT_TRUE(executorProxy != nullptr);
374         EXPECT_CALL(*executorProxy, Delete(_))
375             .Times(Exactly(1))
__anoncb3b637e0b02(uint64_t templateId) 376             .WillOnce([&pair](uint64_t templateId) { return pair.first; });
377         auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
378         ASSERT_TRUE(allInOneHdi != nullptr);
379         const std::vector<uint64_t> templateIdList = {1, 2};
380         auto ret = allInOneHdi->Delete(templateIdList);
381         EXPECT_TRUE(ret == pair.second);
382     }
383 }
384 
385 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Delete_002, TestSize.Level0)
386 {
387     PinAuthAllInOneHdi allInOneHdi(nullptr);
388     auto ret = allInOneHdi.Delete(std::vector<uint64_t>());
389     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
390 }
391 
392 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Cancel_001, TestSize.Level0)
393 {
394     for (const auto &pair : RESULT_CODE_MAP) {
395         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
396         ASSERT_TRUE(executorProxy != nullptr);
__anoncb3b637e0c02(uint64_t scheduleId) 397         EXPECT_CALL(*executorProxy, Cancel(_)).Times(Exactly(1)).WillOnce([&pair](uint64_t scheduleId) {
398             return pair.first;
399         });
400         PinAuthAllInOneHdi allInOneHdi(executorProxy);
401         auto ret = allInOneHdi.Cancel(0);
402         EXPECT_TRUE(ret == pair.second);
403     }
404 }
405 
406 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Cancel_002, TestSize.Level0)
407 {
408     PinAuthAllInOneHdi allInOneHdi(nullptr);
409     auto ret = allInOneHdi.Cancel(0);
410     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
411 }
412 
413 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_SendMessage_001, TestSize.Level0)
414 {
415     auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
416     ASSERT_TRUE(executorProxy != nullptr);
417     PinAuthAllInOneHdi allInOneHdi(executorProxy);
418     std::vector<uint8_t> data;
419     auto ret = allInOneHdi.SendMessage(1, 1, data);
420     EXPECT_TRUE(ret == IamResultCode::SUCCESS);
421 }
422 
423 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_SendMessage_002, TestSize.Level0)
424 {
425     PinAuthAllInOneHdi allInOneHdi(nullptr);
426     std::vector<uint8_t> data;
427     auto ret = allInOneHdi.SendMessage(1, 1, data);
428     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
429 }
430 
431 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_001, TestSize.Level0)
432 {
433     PinAuthAllInOneHdi allInOneHdi(nullptr);
434     std::vector<uint64_t> templateIdList;
435     std::vector<UserAuth::Attributes::AttributeKey> keys;
436     UserAuth::Property property = {};
437     auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
438     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
439 }
440 
441 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_002, TestSize.Level0)
442 {
443     auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
444     ASSERT_TRUE(executorProxy != nullptr);
445     PinAuthAllInOneHdi allInOneHdi(executorProxy);
446     std::vector<uint64_t> templateIdList;
447     std::vector<UserAuth::Attributes::AttributeKey> keys = { UserAuth::Attributes::ATTR_SIGNATURE };
448     UserAuth::Property property = {};
449     auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
450     EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
451 }
452 
453 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_003, TestSize.Level0)
454 {
455     for (const auto &pair : RESULT_CODE_MAP) {
456         auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
457         ASSERT_TRUE(executorProxy != nullptr);
458         EXPECT_CALL(*executorProxy, GetProperty(_, _, _)).Times(Exactly(1)).WillOnce([&pair](
459             const std::vector<uint64_t> &templateIdList,
__anoncb3b637e0d02( const std::vector<uint64_t> &templateIdList, const std::vector<int32_t> &propertyTypes, Property &property) 460             const std::vector<int32_t> &propertyTypes, Property &property) {
461                 return pair.first;
462             });
463         PinAuthAllInOneHdi allInOneHdi(executorProxy);
464         std::vector<uint64_t> templateIdList;
465         std::vector<UserAuth::Attributes::AttributeKey> keys;
466         if (pair.first != HDF_SUCCESS) {
467             keys.push_back(UserAuth::Attributes::ATTR_PIN_SUB_TYPE);
468         }
469         UserAuth::Property property = {};
470         auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
471         EXPECT_TRUE(ret == pair.second);
472     }
473 }
474 
475 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_004, TestSize.Level0)
476 {
477     auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
478     ASSERT_TRUE(executorProxy != nullptr);
479         PinAuthAllInOneHdi allInOneHdi(executorProxy);
480     std::vector<uint64_t> templateIdList;
481     std::vector<UserAuth::Attributes::AttributeKey> keys = { UserAuth::Attributes::ATTR_NEXT_FAIL_LOCKOUT_DURATION };
482     UserAuth::Property property = {};
483     auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
484     EXPECT_EQ(ret, IamResultCode::SUCCESS);
485 }
486 } // namespace PinAuth
487 } // namespace UserIam
488 } // namespace OHOS
489