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