1 /*
2 * Copyright (C) 2022-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 "auth_widget_helper.h"
17
18 #include <future>
19
20 #include <gtest/gtest.h>
21 #include "iam_common_defines.h"
22 #include "iam_logger.h"
23 #include "mock_iuser_auth_interface.h"
24 #include "mock_schedule_node.h"
25 #include "mock_resource_node.h"
26 #include "resource_node_pool.h"
27 #include "iam_ptr.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31 namespace OHOS {
32 namespace UserIam {
33 namespace UserAuth {
34
35 class AuthWidgetHelperTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38
39 static void TearDownTestCase();
40
41 void SetUp() override;
42
43 void TearDown() override;
44 };
45
SetUpTestCase()46 void AuthWidgetHelperTest::SetUpTestCase()
47 {
48 }
49
TearDownTestCase()50 void AuthWidgetHelperTest::TearDownTestCase()
51 {
52 }
53
SetUp()54 void AuthWidgetHelperTest::SetUp()
55 {
56 }
57
TearDown()58 void AuthWidgetHelperTest::TearDown()
59 {
60 }
61
62 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam001, TestSize.Level0)
63 {
64 AuthParamInner authParam;
65 authParam.authTypes.push_back(FACE);
66 authParam.authTypes.push_back(ALL);
67 authParam.authTypes.push_back(PIN);
68 authParam.authTypes.push_back(FINGERPRINT);
69 authParam.authTrustLevel = ATL2;
70 WidgetParamInner widgetParam;
71 widgetParam.title = "使用密码验证";
72 widgetParam.navigationButtonText = "确定";
73 ContextFactory::AuthWidgetContextPara para;
74 para.userId = 1;
75 std::vector<AuthType> validType;
76 EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
77 }
78
79 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam002, TestSize.Level0)
80 {
81 AuthParamInner authParam;
82 authParam.authTypes.push_back(FACE);
83 authParam.authTypes.push_back(ALL);
84 authParam.authTypes.push_back(PIN);
85 authParam.authTypes.push_back(FINGERPRINT);
86 authParam.authTrustLevel = ATL2;
87 WidgetParamInner widgetParam;
88 widgetParam.title = "使用密码验证";
89 widgetParam.navigationButtonText = "确定";
90 ContextFactory::AuthWidgetContextPara para;
91 para.userId = 1;
92 std::vector<AuthType> validType = authParam.authTypes;
93 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
94 }
95
96 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam003, TestSize.Level0)
97 {
98 AuthParamInner authParam;
99 authParam.authTypes.push_back(PIN);
100 authParam.authTrustLevel = ATL2;
101 WidgetParamInner widgetParam;
102 widgetParam.title = "使用密码验证";
103 widgetParam.navigationButtonText = "确定";
104 ContextFactory::AuthWidgetContextPara para;
105 para.userId = 1;
106 std::vector<AuthType> validType = authParam.authTypes;
107 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
108 EXPECT_NE(mockHdi, nullptr);
109 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillOnce(Return(HDF_FAILURE));
110 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
111 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillOnce(Return(HDF_SUCCESS));
112 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
113 constexpr uint64_t executorIndex = 61;
__anon22e3fa320102(std::vector<HdiCredentialInfo> &list) 114 auto fillUpInfos = [](std::vector<HdiCredentialInfo> &list) {
115 std::vector<HdiCredentialInfo> infos = {};
116 HdiCredentialInfo temp = {
117 .credentialId = 1,
118 .executorIndex = executorIndex,
119 .templateId = 3,
120 .authType = static_cast<HdiAuthType>(1),
121 .executorMatcher = 2,
122 .executorSensorHint = 3,
123 };
124 infos.push_back(temp);
125 list.swap(infos);
126 };
127 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
128 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
129 auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, PIN, ALL_IN_ONE);
130 EXPECT_NE(resourceNode, nullptr);
131 EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
132 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
133 EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
134 MockIUserAuthInterface::Holder::GetInstance().Reset();
135 }
136
137 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam004, TestSize.Level0)
138 {
139 AuthParamInner authParam;
140 authParam.authTypes.push_back(PRIVATE_PIN);
141 authParam.authTrustLevel = ATL2;
142 WidgetParamInner widgetParam;
143 widgetParam.title = "使用密码验证";
144 widgetParam.navigationButtonText = "确定";
145 ContextFactory::AuthWidgetContextPara para;
146 para.userId = 1;
147 std::vector<AuthType> validType = authParam.authTypes;
148 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
149 EXPECT_NE(mockHdi, nullptr);
150 constexpr uint64_t executorIndex = 61;
__anon22e3fa320202(std::vector<HdiCredentialInfo> &list) 151 auto fillUpInfos = [](std::vector<HdiCredentialInfo> &list) {
152 std::vector<HdiCredentialInfo> infos = {};
153 HdiCredentialInfo temp = {
154 .credentialId = 1,
155 .executorIndex = executorIndex,
156 .templateId = 3,
157 .authType = static_cast<HdiAuthType>(16),
158 .executorMatcher = 2,
159 .executorSensorHint = 3,
160 };
161 infos.push_back(temp);
162 list.swap(infos);
163 };
164 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
165 auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, PRIVATE_PIN, ALL_IN_ONE);
166 EXPECT_NE(resourceNode, nullptr);
167 EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
168 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
169 EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
170 MockIUserAuthInterface::Holder::GetInstance().Reset();
171 }
172
173 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam005, TestSize.Level0)
174 {
175 AuthParamInner authParam;
176 authParam.authTypes.push_back(FINGERPRINT);
177 authParam.authTrustLevel = ATL2;
178 WidgetParamInner widgetParam;
179 widgetParam.title = "使用密码验证";
180 widgetParam.navigationButtonText = "确定";
181 ContextFactory::AuthWidgetContextPara para;
182 para.userId = 1;
183 std::vector<AuthType> validType = authParam.authTypes;
184 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
185 EXPECT_NE(mockHdi, nullptr);
186 constexpr uint64_t executorIndex = 61;
__anon22e3fa320302(std::vector<HdiCredentialInfo> &list) 187 auto fillUpInfos = [](std::vector<HdiCredentialInfo> &list) {
188 std::vector<HdiCredentialInfo> infos = {};
189 HdiCredentialInfo temp = {
190 .credentialId = 1,
191 .executorIndex = executorIndex,
192 .templateId = 3,
193 .authType = static_cast<HdiAuthType>(4),
194 .executorMatcher = 2,
195 .executorSensorHint = 3,
196 };
197 infos.push_back(temp);
198 list.swap(infos);
199 };
200 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
201 auto resourceNode = Common::MakeShared<MockResourceNode>();
202 EXPECT_CALL(*resourceNode, GetExecutorIndex()).WillRepeatedly(Return(executorIndex));
203 EXPECT_NE(resourceNode, nullptr);
204 ON_CALL(*resourceNode, GetProperty).WillByDefault(
__anon22e3fa320402(const Attributes &condition, Attributes &values) 205 [](const Attributes &condition, Attributes &values) {
206 values.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, 10001);
207 values.SetStringValue(Attributes::ATTR_SENSOR_INFO, "test");
208 values.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 5);
209 values.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 0);
210 return SUCCESS;
211 }
212 );
213 EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
214 EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
215 EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
216 MockIUserAuthInterface::Holder::GetInstance().Reset();
217 }
218
219 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam006, TestSize.Level0)
220 {
221 AuthParamInner authParam;
222 authParam.authTypes.push_back(FINGERPRINT);
223 authParam.authTrustLevel = ATL2;
224 WidgetParamInner widgetParam;
225 widgetParam.title = "使用密码验证";
226 widgetParam.navigationButtonText = "确定";
227 ContextFactory::AuthWidgetContextPara para;
228 para.userId = 1;
229 std::vector<AuthType> validType = authParam.authTypes;
230 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
231 EXPECT_NE(mockHdi, nullptr);
232 constexpr uint64_t executorIndex = 61;
__anon22e3fa320502(std::vector<HdiCredentialInfo> &list) 233 auto fillUpInfos = [](std::vector<HdiCredentialInfo> &list) {
234 std::vector<HdiCredentialInfo> infos = {};
235 HdiCredentialInfo temp = {
236 .credentialId = 1,
237 .executorIndex = executorIndex,
238 .templateId = 3,
239 .authType = static_cast<HdiAuthType>(4),
240 .executorMatcher = 2,
241 .executorSensorHint = 3,
242 };
243 infos.push_back(temp);
244 list.swap(infos);
245 };
246 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
247 auto resourceNode = Common::MakeShared<MockResourceNode>();
248 EXPECT_CALL(*resourceNode, GetExecutorIndex()).WillRepeatedly(Return(executorIndex));
249 EXPECT_NE(resourceNode, nullptr);
250 ON_CALL(*resourceNode, GetProperty).WillByDefault(
__anon22e3fa320602(const Attributes &condition, Attributes &values) 251 [](const Attributes &condition, Attributes &values) {
252 values.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, 10001);
253 values.SetStringValue(Attributes::ATTR_SENSOR_INFO, "test");
254 values.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 5);
255 values.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 0);
256 return HDF_ERR_INVALID_PARAM;
257 }
258 );
259 EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
260 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
261 EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
262 MockIUserAuthInterface::Holder::GetInstance().Reset();
263 }
264
265 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam007, TestSize.Level0)
266 {
267 AuthParamInner authParam;
268 authParam.authTypes.push_back(FINGERPRINT);
269 authParam.authTrustLevel = ATL2;
270 WidgetParamInner widgetParam;
271 widgetParam.title = "使用密码验证";
272 widgetParam.navigationButtonText = "确定";
273 ContextFactory::AuthWidgetContextPara para;
274 para.userId = 1;
275 std::vector<AuthType> validType = authParam.authTypes;
276 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
277 EXPECT_NE(mockHdi, nullptr);
278 constexpr uint64_t executorIndex = 61;
__anon22e3fa320702(std::vector<HdiCredentialInfo> &list) 279 auto fillUpInfos = [](std::vector<HdiCredentialInfo> &list) {
280 std::vector<HdiCredentialInfo> infos = {};
281 HdiCredentialInfo temp = {
282 .credentialId = 1,
283 .executorIndex = executorIndex,
284 .templateId = 3,
285 .authType = static_cast<HdiAuthType>(4),
286 .executorMatcher = 2,
287 .executorSensorHint = 3,
288 };
289 infos.push_back(temp);
290 list.swap(infos);
291 };
292 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
293 auto resourceNode = Common::MakeShared<MockResourceNode>();
294 EXPECT_CALL(*resourceNode, GetExecutorIndex()).WillRepeatedly(Return(executorIndex));
295 EXPECT_NE(resourceNode, nullptr);
296 ON_CALL(*resourceNode, GetProperty).WillByDefault(
__anon22e3fa320802(const Attributes &condition, Attributes &values) 297 [](const Attributes &condition, Attributes &values) {
298 values.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, 10001);
299 values.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 5);
300 values.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 0);
301 return SUCCESS;
302 }
303 );
304 EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
305 EXPECT_FALSE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
306 EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
307 MockIUserAuthInterface::Holder::GetInstance().Reset();
308 }
309
310 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam008, TestSize.Level0)
311 {
312 AuthParamInner authParam;
313 authParam.authTypes.push_back(PIN);
314 authParam.authTrustLevel = ATL2;
315 WidgetParamInner widgetParam;
316 widgetParam.title = "使用密码验证";
317 widgetParam.navigationButtonText = "确定";
318 widgetParam.windowMode = WindowModeType::DIALOG_BOX;
319 ContextFactory::AuthWidgetContextPara para;
320 para.userId = 1;
321 std::vector<AuthType> validType = authParam.authTypes;
322 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
323 EXPECT_NE(mockHdi, nullptr);
324 constexpr uint64_t executorIndex = 61;
__anon22e3fa320902(std::vector<HdiCredentialInfo> &list) 325 auto fillUpInfos = [](std::vector<HdiCredentialInfo> &list) {
326 std::vector<HdiCredentialInfo> infos = {};
327 HdiCredentialInfo temp = {
328 .credentialId = 1,
329 .executorIndex = executorIndex,
330 .templateId = 3,
331 .authType = static_cast<HdiAuthType>(1),
332 .executorMatcher = 2,
333 .executorSensorHint = 3,
334 };
335 infos.push_back(temp);
336 list.swap(infos);
337 };
338 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
339 auto resourceNode = Common::MakeShared<MockResourceNode>();
340 EXPECT_CALL(*resourceNode, GetExecutorIndex()).WillRepeatedly(Return(executorIndex));
341 EXPECT_NE(resourceNode, nullptr);
342 ON_CALL(*resourceNode, GetProperty).WillByDefault(
__anon22e3fa320a02(const Attributes &condition, Attributes &values) 343 [](const Attributes &condition, Attributes &values) {
344 values.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, 10001);
345 values.SetStringValue(Attributes::ATTR_SENSOR_INFO, "test");
346 values.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 5);
347 values.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 0);
348 return SUCCESS;
349 }
350 );
351 EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
352 EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
353 EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
354 MockIUserAuthInterface::Holder::GetInstance().Reset();
355 }
356
357 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestInitWidgetContextParam009, TestSize.Level0)
358 {
359 AuthParamInner authParam;
360 authParam.authTypes.push_back(PRIVATE_PIN);
361 authParam.authTrustLevel = ATL2;
362 WidgetParamInner widgetParam;
363 widgetParam.title = "使用密码验证";
364 widgetParam.navigationButtonText = "确定";
365 widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE;
366 ContextFactory::AuthWidgetContextPara para;
367 para.userId = 1;
368 std::vector<AuthType> validType = authParam.authTypes;
369 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
370 EXPECT_NE(mockHdi, nullptr);
371 constexpr uint64_t executorIndex = 61;
__anon22e3fa320b02(std::vector<HdiCredentialInfo> &list) 372 auto fillUpInfos = [](std::vector<HdiCredentialInfo> &list) {
373 std::vector<HdiCredentialInfo> infos = {};
374 HdiCredentialInfo temp = {
375 .credentialId = 1,
376 .executorIndex = executorIndex,
377 .templateId = 3,
378 .authType = static_cast<HdiAuthType>(16),
379 .executorMatcher = 2,
380 .executorSensorHint = 3,
381 };
382 infos.push_back(temp);
383 list.swap(infos);
384 };
385 EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
386 auto resourceNode = Common::MakeShared<MockResourceNode>();
387 EXPECT_CALL(*resourceNode, GetExecutorIndex()).WillRepeatedly(Return(executorIndex));
388 EXPECT_NE(resourceNode, nullptr);
389 ON_CALL(*resourceNode, GetProperty).WillByDefault(
__anon22e3fa320c02(const Attributes &condition, Attributes &values) 390 [](const Attributes &condition, Attributes &values) {
391 values.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, 10001);
392 values.SetStringValue(Attributes::ATTR_SENSOR_INFO, "test");
393 values.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 5);
394 values.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 0);
395 return SUCCESS;
396 }
397 );
398 EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
399 EXPECT_TRUE(AuthWidgetHelper::InitWidgetContextParam(authParam, validType, widgetParam, para));
400 EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
401 MockIUserAuthInterface::Holder::GetInstance().Reset();
402 }
403
404 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckValidSolution001, TestSize.Level0)
405 {
406 int32_t userId = 1;
407 std::vector<AuthType> authTypeList;
408 authTypeList.push_back(FACE);
409 authTypeList.push_back(ALL);
410 authTypeList.push_back(PIN);
411 authTypeList.push_back(FINGERPRINT);
412 AuthTrustLevel atl = ATL3;
413 std::vector<AuthType> validTypeList;
414 EXPECT_FALSE(AuthWidgetHelper::CheckValidSolution(userId, authTypeList, atl, validTypeList));
415 }
416
417 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckValidSolution002, TestSize.Level0)
418 {
419 int32_t userId = 1;
420 std::vector<AuthType> authTypeList;
421 authTypeList.push_back(FACE);
422 authTypeList.push_back(ALL);
423 authTypeList.push_back(PIN);
424 authTypeList.push_back(FINGERPRINT);
425 AuthTrustLevel atl = ATL3;
426 std::vector<AuthType> validTypeList;
427 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
428 EXPECT_NE(mockHdi, nullptr);
429 EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillOnce(Return(HDF_FAILURE));
430 EXPECT_TRUE(AuthWidgetHelper::CheckValidSolution(userId, authTypeList, atl, validTypeList));
431 MockIUserAuthInterface::Holder::GetInstance().Reset();
432 }
433
434 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckReuseUnlockResult001, TestSize.Level0)
435 {
436 ContextFactory::AuthWidgetContextPara para;
437 para.userId = 1;
438 Attributes extraInfo;
439 AuthParamInner authParam;
440 authParam.reuseUnlockResult.isReuse = false;
441 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), INVALID_PARAMETERS);
442
443 authParam.reuseUnlockResult.isReuse = true;
444 authParam.reuseUnlockResult.reuseDuration = 0;
445 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), INVALID_PARAMETERS);
446
447 authParam.reuseUnlockResult.reuseDuration = 6 * 60 * 1000;
448 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), INVALID_PARAMETERS);
449 }
450
451 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestCheckReuseUnlockResult002, TestSize.Level0)
452 {
453 ContextFactory::AuthWidgetContextPara para;
454 para.userId = 1;
455 Attributes extraInfo;
456 AuthParamInner authParam;
457 authParam.reuseUnlockResult.isReuse = true;
458 authParam.reuseUnlockResult.reuseDuration = 5 * 60 * 1000;
459 authParam.reuseUnlockResult.reuseMode = AUTH_TYPE_RELEVANT;
460
461 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
462 EXPECT_NE(mockHdi, nullptr);
463 EXPECT_CALL(*mockHdi, CheckReuseUnlockResult(_, _)).Times(5);
464 ON_CALL(*mockHdi, CheckReuseUnlockResult)
465 .WillByDefault(Return(HDF_FAILURE));
466 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), HDF_FAILURE);
467 ON_CALL(*mockHdi, CheckReuseUnlockResult)
468 .WillByDefault(
__anon22e3fa320d02(const HdiReuseUnlockParam &info, HdiReuseUnlockInfo &reuseInfo) 469 [](const HdiReuseUnlockParam &info, HdiReuseUnlockInfo &reuseInfo) {
470 std::vector<uint8_t> token;
471 token.push_back(1);
472 return HDF_SUCCESS;
473 }
474 );
475 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), HDF_SUCCESS);
476 ON_CALL(*mockHdi, CheckReuseUnlockResult)
477 .WillByDefault(Return(HDF_SUCCESS));
478 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), SUCCESS);
479
480 para.sdkVersion = 10001;
481 authParam.authTypes.push_back(FINGERPRINT);
482 ON_CALL(*mockHdi, CheckReuseUnlockResult).WillByDefault(Return(HDF_SUCCESS));
483 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), SUCCESS);
484
485 authParam.reuseUnlockResult.isReuse = true;
486 authParam.reuseUnlockResult.reuseDuration = 4 * 60 * 1000;
487 authParam.reuseUnlockResult.reuseMode = CALLER_IRRELEVANT_AUTH_TYPE_IRRELEVANT;
488 EXPECT_EQ(AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo), SUCCESS);
489 MockIUserAuthInterface::Holder::GetInstance().Reset();
490 }
491
492 HWTEST_F(AuthWidgetHelperTest, AuthWidgetHelperTestParseAttributes001, TestSize.Level0)
493 {
494 Attributes attributes;
495 attributes.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, 10001);
496 attributes.SetStringValue(Attributes::ATTR_SENSOR_INFO, "test");
497 attributes.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 5);
498 attributes.SetInt32Value(Attributes::ATTR_FREEZING_TIME, 0);
499 AuthType authType = PIN;
500 ContextFactory::AuthProfile authProfile;
501 EXPECT_EQ(AuthWidgetHelper::ParseAttributes(attributes, authType, authProfile), true);
502 authType = ALL;
503 EXPECT_EQ(AuthWidgetHelper::ParseAttributes(attributes, authType, authProfile), true);
504 }
505 } // namespace UserAuth
506 } // namespace UserIam
507 } // namespace OHOS