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);
__anon04c73eb60202(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))
__anon04c73eb60302(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))
__anon04c73eb60402(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))
__anon04c73eb60502(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))
__anon04c73eb60602(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,
__anon04c73eb60702(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)
__anon04c73eb60802(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,
__anon04c73eb60902(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 allInOneHdi->authType_ = AuthType::PIN;
288 ASSERT_TRUE(allInOneHdi != nullptr);
289 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
290 ASSERT_TRUE(executeCallback != nullptr);
291 auto ret = allInOneHdi->Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, executeCallback);
292 EXPECT_TRUE(ret == pair.second);
293 }
294 }
295
296 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Enroll_002, TestSize.Level0)
297 {
298 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
299 ASSERT_TRUE(executorProxy != nullptr);
300 auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
301 ASSERT_TRUE(allInOneHdi != nullptr);
302 auto ret = allInOneHdi->Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, nullptr);
303 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
304 }
305
306 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Enroll_003, TestSize.Level0)
307 {
308 auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(nullptr);
309 ASSERT_TRUE(allInOneHdi != nullptr);
310 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
311 ASSERT_TRUE(executeCallback != nullptr);
312 auto ret = allInOneHdi->Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, executeCallback);
313 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
314 }
315
316 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Enroll_004, TestSize.Level0)
317 {
318 PinAuthAllInOneHdi allInOneHdi(nullptr);
319 auto ret = allInOneHdi.Enroll(0, UserAuth::EnrollParam{0, std::vector<uint8_t>()}, nullptr);
320 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
321 }
322
323 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_001, TestSize.Level0)
324 {
325 for (const auto &pair : RESULT_CODE_MAP) {
326 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
327 ASSERT_TRUE(executorProxy != nullptr);
328 EXPECT_CALL(*executorProxy, Authenticate(_, _, _, _)).Times(Exactly(1)).WillOnce([&pair](
329 uint64_t scheduleId, const std::vector<uint64_t>& templateIdList, const std::vector<uint8_t> &extraInfo,
__anon04c73eb60a02( uint64_t scheduleId, const std::vector<uint64_t>& templateIdList, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 330 const sptr<IExecutorCallback> &callbackObj) { return pair.first; });
331 auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
332 ASSERT_TRUE(allInOneHdi != nullptr);
333 allInOneHdi->authType_ = AuthType::PIN;
334 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
335 ASSERT_TRUE(executeCallback != nullptr);
336 const std::vector<uint64_t> templateIdList = {1, 2};
337 auto ret = allInOneHdi->Authenticate(0,
338 UserAuth::AuthenticateParam{0, templateIdList, std::vector<uint8_t>()}, executeCallback);
339 EXPECT_TRUE(ret == pair.second);
340 }
341 }
342
343 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_002, TestSize.Level0)
344 {
345 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
346 ASSERT_TRUE(executorProxy != nullptr);
347 auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
348 auto ret = allInOneHdi->Authenticate(0,
349 UserAuth::AuthenticateParam{0, std::vector<uint64_t>(), std::vector<uint8_t>()}, nullptr);
350 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
351 }
352
353 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_003, TestSize.Level0)
354 {
355 auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(nullptr);
356 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
357 ASSERT_TRUE(executeCallback != nullptr);
358 auto ret = allInOneHdi->Authenticate(0,
359 UserAuth::AuthenticateParam{0, std::vector<uint64_t>(), std::vector<uint8_t>()}, executeCallback);
360 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
361 }
362
363 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Authenticate_004, TestSize.Level0)
364 {
365 PinAuthAllInOneHdi allInOneHdi(nullptr);
366 auto ret = allInOneHdi.Authenticate(0,
367 UserAuth::AuthenticateParam{0, std::vector<uint64_t>(), std::vector<uint8_t>()}, nullptr);
368 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
369 }
370
371 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Delete_001, TestSize.Level0)
372 {
373 for (const auto &pair : RESULT_CODE_MAP) {
374 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
375 ASSERT_TRUE(executorProxy != nullptr);
376 EXPECT_CALL(*executorProxy, Delete(_))
377 .Times(Exactly(1))
__anon04c73eb60b02(uint64_t templateId) 378 .WillOnce([&pair](uint64_t templateId) { return pair.first; });
379 auto allInOneHdi = MakeShared<PinAuthAllInOneHdi>(executorProxy);
380 ASSERT_TRUE(allInOneHdi != nullptr);
381 const std::vector<uint64_t> templateIdList = {1, 2};
382 auto ret = allInOneHdi->Delete(templateIdList);
383 EXPECT_TRUE(ret == pair.second);
384 }
385 }
386
387 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Delete_002, TestSize.Level0)
388 {
389 PinAuthAllInOneHdi allInOneHdi(nullptr);
390 auto ret = allInOneHdi.Delete(std::vector<uint64_t>());
391 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
392 }
393
394 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Cancel_001, TestSize.Level0)
395 {
396 for (const auto &pair : RESULT_CODE_MAP) {
397 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
398 ASSERT_TRUE(executorProxy != nullptr);
__anon04c73eb60c02(uint64_t scheduleId) 399 EXPECT_CALL(*executorProxy, Cancel(_)).Times(Exactly(1)).WillOnce([&pair](uint64_t scheduleId) {
400 return pair.first;
401 });
402 PinAuthAllInOneHdi allInOneHdi(executorProxy);
403 auto ret = allInOneHdi.Cancel(0);
404 EXPECT_TRUE(ret == pair.second);
405 }
406 }
407
408 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_Cancel_002, TestSize.Level0)
409 {
410 PinAuthAllInOneHdi allInOneHdi(nullptr);
411 auto ret = allInOneHdi.Cancel(0);
412 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
413 }
414
415 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_SendMessage_001, TestSize.Level0)
416 {
417 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
418 ASSERT_TRUE(executorProxy != nullptr);
419 PinAuthAllInOneHdi allInOneHdi(executorProxy);
420 std::vector<uint8_t> data;
421 auto ret = allInOneHdi.SendMessage(1, 1, data);
422 EXPECT_TRUE(ret == IamResultCode::SUCCESS);
423 }
424
425 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_SendMessage_002, TestSize.Level0)
426 {
427 PinAuthAllInOneHdi allInOneHdi(nullptr);
428 std::vector<uint8_t> data;
429 auto ret = allInOneHdi.SendMessage(1, 1, data);
430 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
431 }
432
433 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_001, TestSize.Level0)
434 {
435 PinAuthAllInOneHdi allInOneHdi(nullptr);
436 std::vector<uint64_t> templateIdList;
437 std::vector<UserAuth::Attributes::AttributeKey> keys;
438 UserAuth::Property property = {};
439 auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
440 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
441 }
442
443 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_002, TestSize.Level0)
444 {
445 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
446 ASSERT_TRUE(executorProxy != nullptr);
447 PinAuthAllInOneHdi allInOneHdi(executorProxy);
448 std::vector<uint64_t> templateIdList;
449 std::vector<UserAuth::Attributes::AttributeKey> keys = { UserAuth::Attributes::ATTR_SIGNATURE };
450 UserAuth::Property property = {};
451 auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
452 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
453 }
454
455 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_003, TestSize.Level0)
456 {
457 for (const auto &pair : RESULT_CODE_MAP) {
458 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
459 ASSERT_TRUE(executorProxy != nullptr);
460 EXPECT_CALL(*executorProxy, GetProperty(_, _, _)).Times(Exactly(1)).WillOnce([&pair](
461 const std::vector<uint64_t> &templateIdList,
__anon04c73eb60d02( const std::vector<uint64_t> &templateIdList, const std::vector<int32_t> &propertyTypes, Property &property) 462 const std::vector<int32_t> &propertyTypes, Property &property) {
463 return pair.first;
464 });
465 PinAuthAllInOneHdi allInOneHdi(executorProxy);
466 std::vector<uint64_t> templateIdList;
467 std::vector<UserAuth::Attributes::AttributeKey> keys;
468 if (pair.first != HDF_SUCCESS) {
469 keys.push_back(UserAuth::Attributes::ATTR_PIN_SUB_TYPE);
470 }
471 UserAuth::Property property = {};
472 auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
473 EXPECT_TRUE(ret == pair.second);
474 }
475 }
476
477 HWTEST_F(PinAuthAllInOneHdiUnitTest, PinAuthExecutorHdi_GetProperty_004, TestSize.Level0)
478 {
479 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
480 ASSERT_TRUE(executorProxy != nullptr);
481 PinAuthAllInOneHdi allInOneHdi(executorProxy);
482 std::vector<uint64_t> templateIdList;
483 std::vector<UserAuth::Attributes::AttributeKey> keys = { UserAuth::Attributes::ATTR_NEXT_FAIL_LOCKOUT_DURATION };
484 UserAuth::Property property = {};
485 auto ret = allInOneHdi.GetProperty(templateIdList, keys, property);
486 EXPECT_EQ(ret, IamResultCode::SUCCESS);
487 }
488 } // namespace PinAuth
489 } // namespace UserIam
490 } // namespace OHOS
491