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 namespace PinHdi = OHOS::HDI::PinAuth::V1_0;
33
34 namespace OHOS {
35 namespace UserIam {
36 namespace PinAuth {
37 using IamResultCode = OHOS::UserIam::UserAuth::ResultCode;
38 using IamExecutorRole = OHOS::UserIam::UserAuth::ExecutorRole;
39 using IamExecutorInfo = OHOS::UserIam::UserAuth::ExecutorInfo;
40 using IamAuthType = OHOS::UserIam::UserAuth::AuthType;
41 using IamExecutorSecureLevel = OHOS::UserIam::UserAuth::ExecutorSecureLevel;
42 using IamPropertyMode = OHOS::UserIam::UserAuth::PropertyMode;
43 namespace {
44 static const std::map<HDF_STATUS, IamResultCode> RESULT_CODE_MAP = {
45 {HDF_SUCCESS, IamResultCode::SUCCESS},
46 {HDF_FAILURE, IamResultCode::FAIL},
47 {HDF_ERR_TIMEOUT, IamResultCode::TIMEOUT},
48 {HDF_ERR_QUEUE_FULL, IamResultCode::BUSY},
49 {HDF_ERR_DEVICE_BUSY, IamResultCode::BUSY}
50 };
51 }
52
53 class PinAuthExecutorHdiUnitTest : public testing::Test {
54 public:
55 static void SetUpTestCase();
56 static void TearDownTestCase();
57 void SetUp();
58 void TearDown();
59 };
60
SetUpTestCase()61 void PinAuthExecutorHdiUnitTest::SetUpTestCase()
62 {
63 }
64
TearDownTestCase()65 void PinAuthExecutorHdiUnitTest::TearDownTestCase()
66 {
67 }
68
SetUp()69 void PinAuthExecutorHdiUnitTest::SetUp()
70 {
71 }
72
TearDown()73 void PinAuthExecutorHdiUnitTest::TearDown()
74 {
75 }
76
77 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_001, TestSize.Level0)
78 {
79 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
80 ASSERT_TRUE(executorProxy != nullptr);
__anon1dca439e0202(PinHdi::ExecutorInfo &info) 81 EXPECT_CALL(*executorProxy, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([](PinHdi::ExecutorInfo &info) {
82 info = {
83 .executorRole = PinHdi::ExecutorRole::ALL_IN_ONE,
84 .authType = PinHdi::PIN,
85 .esl = PinHdi::ExecutorSecureLevel::ESL0,
86 };
87 return HDF_SUCCESS;
88 });
89 PinAuthExecutorHdi executorHdi(executorProxy);
90 IamExecutorInfo info = {};
91 auto ret = executorHdi.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(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_002, TestSize.Level0)
99 {
100 for (const auto &pair : RESULT_CODE_MAP) {
101 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
102 ASSERT_TRUE(executorProxy != nullptr);
103 EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
104 .Times(Exactly(1))
__anon1dca439e0302(PinHdi::ExecutorInfo &info) 105 .WillOnce([&pair](PinHdi::ExecutorInfo &info) {
106 info = {
107 .executorRole = PinHdi::ExecutorRole::ALL_IN_ONE,
108 .authType = PinHdi::PIN,
109 .esl = PinHdi::ExecutorSecureLevel::ESL0,
110 };
111 return static_cast<int32_t>(pair.first);
112 });
113 PinAuthExecutorHdi executorHdi(executorProxy);
114 IamExecutorInfo info = {};
115 auto ret = executorHdi.GetExecutorInfo(info);
116 EXPECT_TRUE(ret == pair.second);
117 }
118 }
119
120 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_003, TestSize.Level0)
121 {
122 static const std::map<PinHdi::AuthType, pair<IamAuthType, IamResultCode>> data = {
123 {PinHdi::PIN, {IamAuthType::PIN, IamResultCode::SUCCESS}},
124 {static_cast<PinHdi::AuthType>(PinHdi::PIN + 1),
125 {IamAuthType::PIN, IamResultCode::GENERAL_ERROR}},
126 {static_cast<PinHdi::AuthType>(PinHdi::PIN - 1),
127 {IamAuthType::PIN, IamResultCode::GENERAL_ERROR}},
128 };
129 for (const auto &pair : data) {
130 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
131 ASSERT_TRUE(executorProxy != nullptr);
132 EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
133 .Times(Exactly(1))
__anon1dca439e0402(PinHdi::ExecutorInfo &info) 134 .WillOnce([&pair](PinHdi::ExecutorInfo &info) {
135 info = {
136 .executorRole = PinHdi::ExecutorRole::ALL_IN_ONE,
137 .authType = pair.first,
138 .esl = PinHdi::ExecutorSecureLevel::ESL0,
139 };
140 return HDF_SUCCESS;
141 });
142 PinAuthExecutorHdi executorHdi(executorProxy);
143 IamExecutorInfo info = {};
144 auto ret = executorHdi.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(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_004, TestSize.Level0)
153 {
154 static const std::map<PinHdi::ExecutorRole, pair<IamExecutorRole, IamResultCode>> data = {
155 {PinHdi::ExecutorRole::COLLECTOR, {IamExecutorRole::COLLECTOR, IamResultCode::SUCCESS}},
156 {PinHdi::ExecutorRole::VERIFIER, {IamExecutorRole::VERIFIER, IamResultCode::SUCCESS}},
157 {PinHdi::ExecutorRole::ALL_IN_ONE, {IamExecutorRole::ALL_IN_ONE, IamResultCode::SUCCESS}},
158 {static_cast<PinHdi::ExecutorRole>(PinHdi::ExecutorRole::COLLECTOR - 1),
159 {IamExecutorRole::ALL_IN_ONE, IamResultCode::GENERAL_ERROR}},
160 {static_cast<PinHdi::ExecutorRole>(PinHdi::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) PinHdi::MockIExecutor();
165 ASSERT_TRUE(executorProxy != nullptr);
166 EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
167 .Times(Exactly(1))
__anon1dca439e0502(PinHdi::ExecutorInfo &info) 168 .WillOnce([&pair](PinHdi::ExecutorInfo &info) {
169 info = {
170 .executorRole = pair.first,
171 .authType = PinHdi::PIN,
172 .esl = PinHdi::ExecutorSecureLevel::ESL0,
173 };
174 return HDF_SUCCESS;
175 });
176 PinAuthExecutorHdi executorHdi(executorProxy);
177 IamExecutorInfo info = {};
178 auto ret = executorHdi.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(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_005, TestSize.Level0)
187 {
188 static const std::map<PinHdi::ExecutorSecureLevel, pair<IamExecutorSecureLevel, IamResultCode>> data =
189 {
190 {PinHdi::ExecutorSecureLevel::ESL0, {IamExecutorSecureLevel::ESL0, IamResultCode::SUCCESS}},
191 {PinHdi::ExecutorSecureLevel::ESL1, {IamExecutorSecureLevel::ESL1, IamResultCode::SUCCESS}},
192 {PinHdi::ExecutorSecureLevel::ESL2, {IamExecutorSecureLevel::ESL2, IamResultCode::SUCCESS}},
193 {PinHdi::ExecutorSecureLevel::ESL3, {IamExecutorSecureLevel::ESL3, IamResultCode::SUCCESS}},
194 {static_cast<PinHdi::ExecutorSecureLevel>(PinHdi::ExecutorSecureLevel::ESL0 - 1),
195 {IamExecutorSecureLevel::ESL3, IamResultCode::GENERAL_ERROR}},
196 {static_cast<PinHdi::ExecutorSecureLevel>(PinHdi::ExecutorSecureLevel::ESL3 + 1),
197 {IamExecutorSecureLevel::ESL3, IamResultCode::GENERAL_ERROR}},
198 };
199 for (const auto &pair : data) {
200 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
201 ASSERT_TRUE(executorProxy != nullptr);
202 EXPECT_CALL(*executorProxy, GetExecutorInfo(_))
203 .Times(Exactly(1))
__anon1dca439e0602(PinHdi::ExecutorInfo &info) 204 .WillOnce([&pair](PinHdi::ExecutorInfo &info) {
205 info = {
206 .executorRole = PinHdi::ExecutorRole::ALL_IN_ONE,
207 .authType = PinHdi::PIN,
208 .esl = pair.first,
209 };
210 return HDF_SUCCESS;
211 });
212 PinAuthExecutorHdi executorHdi(executorProxy);
213 IamExecutorInfo info = {};
214 auto ret = executorHdi.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(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetExecutorInfo_006, TestSize.Level0)
223 {
224 PinAuthExecutorHdi executorHdi(nullptr);
225 IamExecutorInfo info = {};
226 auto ret = executorHdi.GetExecutorInfo(info);
227 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
228 }
229
230 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetTemplateInfo_001, TestSize.Level0)
231 {
232 const UserAuth::TemplateInfo data = {.executorType = 1,
233 .freezingTime = 2,
234 .remainTimes = 3,
235 .extraInfo = {4, 5, 6}};
236 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
237 ASSERT_TRUE(executorProxy != nullptr);
238 EXPECT_CALL(*executorProxy, GetTemplateInfo(_, _))
239 .Times(Exactly(1))
__anon1dca439e0702(uint64_t templateId, PinHdi::TemplateInfo &info) 240 .WillOnce([&data](uint64_t templateId, PinHdi::TemplateInfo &info) {
241 info = {.executorType = data.executorType,
242 .lockoutDuration = data.freezingTime,
243 .remainAttempts = data.remainTimes,
244 .extraInfo = data.extraInfo};
245 return HDF_SUCCESS;
246 });
247 PinAuthExecutorHdi executorHdi(executorProxy);
248 UserAuth::TemplateInfo info = {};
249 auto ret = executorHdi.GetTemplateInfo(0, info);
250 EXPECT_TRUE(ret == IamResultCode::SUCCESS);
251 EXPECT_TRUE(info.executorType == data.executorType);
252 EXPECT_TRUE(info.freezingTime == data.freezingTime);
253 EXPECT_TRUE(info.remainTimes == data.remainTimes);
254 EXPECT_TRUE(info.extraInfo == data.extraInfo);
255 }
256
257 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetTemplateInfo_002, TestSize.Level0)
258 {
259 for (const auto &pair : RESULT_CODE_MAP) {
260 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
261 ASSERT_TRUE(executorProxy != nullptr);
262 EXPECT_CALL(*executorProxy, GetTemplateInfo(_, _))
263 .Times(Exactly(1))
__anon1dca439e0802(uint64_t templateId, PinHdi::TemplateInfo &info) 264 .WillOnce([&pair](uint64_t templateId, PinHdi::TemplateInfo &info) { return pair.first; });
265 PinAuthExecutorHdi executorHdi(executorProxy);
266 UserAuth::TemplateInfo info = {};
267 auto ret = executorHdi.GetTemplateInfo(0, info);
268 EXPECT_TRUE(ret == pair.second);
269 }
270 }
271
272 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_GetTemplateInfo_003, TestSize.Level0)
273 {
274 PinAuthExecutorHdi executorHdi(nullptr);
275 UserAuth::TemplateInfo info = {};
276 auto ret = executorHdi.GetTemplateInfo(0, info);
277 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
278 }
279
280 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_OnRegisterFinish_001, TestSize.Level0)
281 {
282 for (const auto &pair : RESULT_CODE_MAP) {
283 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
284 ASSERT_TRUE(executorProxy != nullptr);
285 EXPECT_CALL(*executorProxy, OnRegisterFinish(_, _, _))
286 .Times(Exactly(1))
287 .WillOnce(
288 [&pair](const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey,
__anon1dca439e0902(const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) 289 const std::vector<uint8_t> &extraInfo) { return pair.first; });
290 PinAuthExecutorHdi executorHdi(executorProxy);
291 UserAuth::TemplateInfo info = {};
292 auto ret =
293 executorHdi.OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
294 EXPECT_TRUE(ret == pair.second);
295 }
296 }
297
298 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_OnRegisterFinish_002, TestSize.Level0)
299 {
300 PinAuthExecutorHdi executorHdi(nullptr);
301 auto ret = executorHdi.OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
302 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
303 }
304
305 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_OnSetData_001, TestSize.Level0)
306 {
307 for (const auto &pair : RESULT_CODE_MAP) {
308 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
309 ASSERT_TRUE(executorProxy != nullptr);
310 EXPECT_CALL(*executorProxy, OnSetData(_, _, _))
311 .Times(Exactly(1))
312 .WillOnce([&pair](uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data)
__anon1dca439e0a02(uint64_t scheduleId, uint64_t authSubType, const std::vector<uint8_t> &data) 313 { return pair.first; });
314 PinAuthExecutorHdi executorHdi(executorProxy);
315 UserAuth::TemplateInfo info = {};
316 auto ret =
317 executorHdi.OnSetData(0, 0, std::vector<uint8_t>());
318 EXPECT_TRUE(ret == pair.second);
319 }
320 }
321
322 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_OnSetData_002, TestSize.Level0)
323 {
324 PinAuthExecutorHdi executorHdi(nullptr);
325 auto ret = executorHdi.OnSetData(0, 0, std::vector<uint8_t>());
326 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
327 }
328
329 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Enroll_001, TestSize.Level0)
330 {
331 for (const auto &pair : RESULT_CODE_MAP) {
332 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
333 ASSERT_TRUE(executorProxy != nullptr);
334 EXPECT_CALL(*executorProxy, Enroll(_, _, _))
335 .Times(Exactly(1))
336 .WillOnce([&pair](uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
__anon1dca439e0b02(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<PinHdi::IExecutorCallback> &callbackObj) 337 const sptr<PinHdi::IExecutorCallback> &callbackObj) { return pair.first; });
338 auto executorHdi = MakeShared<PinAuthExecutorHdi>(executorProxy);
339 ASSERT_TRUE(executorHdi != nullptr);
340 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
341 ASSERT_TRUE(executeCallback != nullptr);
342 auto ret = executorHdi->Enroll(0, 0, std::vector<uint8_t>(), executeCallback);
343 EXPECT_TRUE(ret == pair.second);
344 }
345 }
346
347 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Enroll_002, TestSize.Level0)
348 {
349 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
350 ASSERT_TRUE(executorProxy != nullptr);
351 auto executorHdi = MakeShared<PinAuthExecutorHdi>(executorProxy);
352 ASSERT_TRUE(executorHdi != nullptr);
353 auto ret = executorHdi->Enroll(0, 0, std::vector<uint8_t>(), nullptr);
354 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
355 }
356
357 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Enroll_003, TestSize.Level0)
358 {
359 auto executorHdi = MakeShared<PinAuthExecutorHdi>(nullptr);
360 ASSERT_TRUE(executorHdi != nullptr);
361 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
362 ASSERT_TRUE(executeCallback != nullptr);
363 auto ret = executorHdi->Enroll(0, 0, std::vector<uint8_t>(), executeCallback);
364 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
365 }
366
367 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Authenticate_001, TestSize.Level0)
368 {
369 for (const auto &pair : RESULT_CODE_MAP) {
370 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
371 ASSERT_TRUE(executorProxy != nullptr);
372 EXPECT_CALL(*executorProxy, Authenticate(_, _, _, _)).Times(Exactly(1)).WillOnce([&pair](uint64_t scheduleId,
373 uint64_t templateIdList, const std::vector<uint8_t> &extraInfo,
__anon1dca439e0c02(uint64_t scheduleId, uint64_t templateIdList, const std::vector<uint8_t> &extraInfo, const sptr<PinHdi::IExecutorCallback> &callbackObj) 374 const sptr<PinHdi::IExecutorCallback> &callbackObj) { return pair.first; });
375 auto executorHdi = MakeShared<PinAuthExecutorHdi>(executorProxy);
376 ASSERT_TRUE(executorHdi != nullptr);
377 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
378 ASSERT_TRUE(executeCallback != nullptr);
379 const std::vector<uint64_t> templateIdList = {1, 2};
380 auto ret = executorHdi->Authenticate(0, 0, templateIdList, std::vector<uint8_t>(), executeCallback);
381 EXPECT_TRUE(ret == pair.second);
382 }
383 }
384
385 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Authenticate_002, TestSize.Level0)
386 {
387 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
388 ASSERT_TRUE(executorProxy != nullptr);
389 auto executorHdi = MakeShared<PinAuthExecutorHdi>(executorProxy);
390 auto ret = executorHdi->Authenticate(0, 0, std::vector<uint64_t>(), std::vector<uint8_t>(), nullptr);
391 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
392 }
393
394 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Authenticate_003, TestSize.Level0)
395 {
396 auto executorHdi = MakeShared<PinAuthExecutorHdi>(nullptr);
397 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
398 ASSERT_TRUE(executeCallback != nullptr);
399 auto ret = executorHdi->Authenticate(0, 0, std::vector<uint64_t>(), std::vector<uint8_t>(), executeCallback);
400 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
401 }
402
403 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Identify_001, TestSize.Level0)
404 {
405 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
406 ASSERT_TRUE(executorProxy != nullptr);
407 PinAuthExecutorHdi executorHdi(executorProxy);
408 auto ret = executorHdi.Identify(0, 0, std::vector<uint8_t>(), nullptr);
409 EXPECT_TRUE(ret == IamResultCode::SUCCESS);
410 }
411
412 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Delete_001, TestSize.Level0)
413 {
414 for (const auto &pair : RESULT_CODE_MAP) {
415 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
416 ASSERT_TRUE(executorProxy != nullptr);
417 EXPECT_CALL(*executorProxy, Delete(_))
418 .Times(Exactly(1))
__anon1dca439e0d02(uint64_t templateId) 419 .WillOnce([&pair](uint64_t templateId) { return pair.first; });
420 auto executorHdi = MakeShared<PinAuthExecutorHdi>(executorProxy);
421 ASSERT_TRUE(executorHdi != nullptr);
422 const std::vector<uint64_t> templateIdList = {1, 2};
423 auto ret = executorHdi->Delete(templateIdList);
424 EXPECT_TRUE(ret == pair.second);
425 }
426 }
427
428 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Delete_002, TestSize.Level0)
429 {
430 PinAuthExecutorHdi executorHdi(nullptr);
431 auto ret = executorHdi.Delete(std::vector<uint64_t>());
432 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
433 }
434
435 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Cancel_001, TestSize.Level0)
436 {
437 for (const auto &pair : RESULT_CODE_MAP) {
438 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
439 ASSERT_TRUE(executorProxy != nullptr);
__anon1dca439e0e02(uint64_t scheduleId) 440 EXPECT_CALL(*executorProxy, Cancel(_)).Times(Exactly(1)).WillOnce([&pair](uint64_t scheduleId) {
441 return pair.first;
442 });
443 PinAuthExecutorHdi executorHdi(executorProxy);
444 auto ret = executorHdi.Cancel(0);
445 EXPECT_TRUE(ret == pair.second);
446 }
447 }
448
449 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_Cancel_002, TestSize.Level0)
450 {
451 PinAuthExecutorHdi executorHdi(nullptr);
452 auto ret = executorHdi.Cancel(0);
453 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
454 }
455
456 HWTEST_F(PinAuthExecutorHdiUnitTest, PinAuthExecutorHdi_SendCommand_001, TestSize.Level0)
457 {
458 auto executorProxy = new (std::nothrow) PinHdi::MockIExecutor();
459 ASSERT_TRUE(executorProxy != nullptr);
460 PinAuthExecutorHdi executorHdi(executorProxy);
461 auto ret = executorHdi.SendCommand(IamPropertyMode::PROPERTY_MODE_FREEZE, std::vector<uint8_t>(), nullptr);
462 EXPECT_TRUE(ret == IamResultCode::SUCCESS);
463 }
464
465 } // namespace PinAuth
466 } // namespace UserIam
467 } // namespace OHOS
468