1 /*
2 * Copyright (c) 2022-2023 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 "securec.h"
19
20 #include "adaptor_time.h"
21 #include "buffer.h"
22 #include "coauth.h"
23 #include "defines.h"
24 #include "executor_message.h"
25 #include "idm_database.h"
26 #include "idm_session.h"
27 #include "pool.h"
28 #include "user_idm_funcs.h"
29 #include "udid_manager.h"
30
31 extern "C" {
32 extern struct SessionInfo {
33 int32_t userId;
34 uint32_t authType;
35 uint64_t time;
36 uint64_t validAuthTokenTime;
37 uint8_t challenge[CHALLENGE_LEN];
38 uint64_t scheduleId;
39 ScheduleType scheduleType;
40 bool isScheduleValid;
41 PinChangeScence pinChangeScence;
42 Buffer *oldRootSecret;
43 Buffer *curRootSecret;
44 Buffer *newRootSecret;
45 } *g_session;
46 extern LinkedList *g_poolList;
47 extern LinkedList *g_userInfoList;
48 extern LinkedList *g_scheduleList;
49 extern CoAuthSchedule *GenerateIdmSchedule(const PermissionCheckParam *param, ScheduleType scheduleType);
50 extern int32_t GetCredentialInfoFromSchedule(const ExecutorResultInfo *executorInfo,
51 CredentialInfoHal *credentialInfo, const CoAuthSchedule *schedule);
52 extern int32_t GetDeletedCredential(int32_t userId, CredentialInfoHal *deletedCredential);
53 extern int32_t CheckResultValid(uint64_t scheduleId, int32_t userId);
54 }
55
56 namespace OHOS {
57 namespace UserIam {
58 namespace UserAuth {
59 using namespace testing;
60 using namespace testing::ext;
61
62 class UserIdmFuncsTest : public testing::Test {
63 public:
SetUpTestCase()64 static void SetUpTestCase() {};
65
TearDownTestCase()66 static void TearDownTestCase() {};
67
SetUp()68 void SetUp() {};
69
TearDown()70 void TearDown() {};
71 };
72
73 HWTEST_F(UserIdmFuncsTest, TestGenerateIdmSchedule_001, TestSize.Level0)
74 {
75 PermissionCheckParam param = {};
76 constexpr uint32_t executorSensorHint = 10;
77 param.executorSensorHint = executorSensorHint;
78 ScheduleType scheduleType = SCHEDULE_TYPE_ENROLL;
79 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
80 }
81
82 HWTEST_F(UserIdmFuncsTest, TestGenerateIdmSchedule_002, TestSize.Level0)
83 {
84 InitResourcePool();
85 EXPECT_NE(g_poolList, nullptr);
86 constexpr uint32_t executorSensorHint = 10;
87 ExecutorInfoHal *info = static_cast<ExecutorInfoHal *>(malloc(sizeof(ExecutorInfoHal)));
88 EXPECT_NE(info, nullptr);
89 info->authType = PIN_AUTH;
90 info->executorSensorHint = executorSensorHint;
91 info->executorRole = COLLECTOR;
92 g_poolList->insert(g_poolList, static_cast<void *>(info));
93 PermissionCheckParam param = {};
94 param.authType = PIN_AUTH;
95 param.executorSensorHint = executorSensorHint;
96 ScheduleType scheduleType = SCHEDULE_TYPE_ENROLL;
97 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
98 DestroyResourcePool();
99 }
100
101 HWTEST_F(UserIdmFuncsTest, TestGenerateIdmSchedule_003, TestSize.Level0)
102 {
103 LOG_INFO("TestGenerateIdmSchedule_003 start");
104 PermissionCheckParam param = {};
105 constexpr uint32_t executorSensorHint = 0;
106 constexpr int32_t userId = 1;
107 param.userId = userId;
108 param.authType = PIN_AUTH;
109 param.executorSensorHint = executorSensorHint;
110 ScheduleType scheduleType = SCHEDULE_TYPE_UPDATE;
111 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
112 param.executorSensorHint = INVALID_SENSOR_HINT;
113 static char udid[UDID_LEN + 1] = "0123456789012345678901234567890123456789012345678901234567890123";
114 SetLocalUdid(udid);
115 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
116 g_userInfoList = CreateLinkedList(DestroyUserInfoNode);
117 EXPECT_NE(g_userInfoList, nullptr);
118 UserInfo *userInfo = static_cast<UserInfo *>(malloc(sizeof(UserInfo)));
119 EXPECT_NE(userInfo, nullptr);
120 userInfo->userId = userId;
121 userInfo->credentialInfoList = CreateLinkedList(DestroyCredentialNode);
122 userInfo->enrolledInfoList = CreateLinkedList(DestroyEnrolledNode);
123 g_userInfoList->insert(g_userInfoList, static_cast<void *>(userInfo));
124 CredentialInfoHal *credentialInfo = static_cast<CredentialInfoHal *>(malloc(sizeof(CredentialInfoHal)));
125 EXPECT_NE(credentialInfo, nullptr);
126 credentialInfo->credentialId = 1;
127 credentialInfo->templateId = 1;
128 credentialInfo->authType = PIN_AUTH;
129 credentialInfo->isAbandoned = false;
130 userInfo->credentialInfoList->insert(userInfo->credentialInfoList, static_cast<void *>(credentialInfo));
131 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
132 InitResourcePool();
133 InitCoAuth();
134 ExecutorInfoHal *info = static_cast<ExecutorInfoHal *>(malloc(sizeof(ExecutorInfoHal)));
135 EXPECT_NE(info, nullptr);
136 info->authType = PIN_AUTH;
137 info->executorSensorHint = executorSensorHint;
138 info->executorRole = ALL_IN_ONE;
139 memcpy_s(info->deviceUdid, UDID_LEN, udid, UDID_LEN);
140 g_poolList->insert(g_poolList, static_cast<void *>(info));
141 EXPECT_NE(GenerateIdmSchedule(¶m, scheduleType), nullptr);
142 DestroyResourcePool();
143 DestoryCoAuth();
144 LOG_INFO("TestGenerateIdmSchedule_003 end");
145 }
146
147 HWTEST_F(UserIdmFuncsTest, TestGenerateIdmSchedule_004, TestSize.Level0)
148 {
149 LOG_INFO("TestGenerateIdmSchedule_004 start");
150 InitResourcePool();
151 EXPECT_NE(g_poolList, nullptr);
152 constexpr uint32_t executorSensorHint = 0;
153 ExecutorInfoHal *info = static_cast<ExecutorInfoHal *>(malloc(sizeof(ExecutorInfoHal)));
154 EXPECT_NE(info, nullptr);
155 info->authType = PIN_AUTH;
156 info->executorSensorHint = executorSensorHint;
157 info->executorRole = ALL_IN_ONE;
158 g_poolList->insert(g_poolList, static_cast<void *>(info));
159 PermissionCheckParam param = {};
160 param.authType = PIN_AUTH;
161 param.executorSensorHint = executorSensorHint;
162 ScheduleType scheduleType = SCHEDULE_TYPE_UPDATE;
163 static char udid[UDID_LEN + 1] = "0123456789012345678901234567890123456789012345678901234567890123";
164 SetLocalUdid(udid);
165 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
166 DestroyResourcePool();
167 LOG_INFO("TestGenerateIdmSchedule_004 end");
168 }
169
TestInitUserInfoList()170 static void TestInitUserInfoList()
171 {
172 g_userInfoList = CreateLinkedList(DestroyUserInfoNode);
173 EXPECT_NE(g_userInfoList, nullptr);
174 UserInfo *userInfo = static_cast<UserInfo *>(malloc(sizeof(UserInfo)));
175 EXPECT_NE(userInfo, nullptr);
176 userInfo->userId = 1;
177 userInfo->credentialInfoList = CreateLinkedList(DestroyCredentialNode);
178 userInfo->enrolledInfoList = CreateLinkedList(DestroyEnrolledNode);
179 g_userInfoList->insert(g_userInfoList, static_cast<void *>(userInfo));
180 CredentialInfoHal *credentialInfo = static_cast<CredentialInfoHal *>(malloc(sizeof(CredentialInfoHal)));
181 EXPECT_NE(credentialInfo, nullptr);
182 credentialInfo->credentialId = 1;
183 credentialInfo->templateId = 1;
184 credentialInfo->authType = PIN_AUTH;
185 credentialInfo->isAbandoned = false;
186 userInfo->credentialInfoList->insert(userInfo->credentialInfoList, static_cast<void *>(credentialInfo));
187 }
188
189 HWTEST_F(UserIdmFuncsTest, TestGenerateIdmSchedule_005, TestSize.Level0)
190 {
191 LOG_INFO("TestGenerateIdmSchedule_005 start");
192 PermissionCheckParam param = {};
193 constexpr uint32_t executorSensorHint = 10;
194 constexpr int32_t userId = 1;
195 param.userId = userId;
196 param.authType = PIN_AUTH;
197 param.executorSensorHint = executorSensorHint;
198 ScheduleType scheduleType = SCHEDULE_TYPE_ABANDON;
199 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
200 param.executorSensorHint = INVALID_SENSOR_HINT;
201 static char udid[UDID_LEN + 1] = "0123456789012345678901234567890123456789012345678901234567890123";
202 SetLocalUdid(udid);
203 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
204 TestInitUserInfoList();
205 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
206 InitResourcePool();
207 InitCoAuth();
208 ExecutorInfoHal *info = static_cast<ExecutorInfoHal *>(malloc(sizeof(ExecutorInfoHal)));
209 EXPECT_NE(info, nullptr);
210 info->authType = PIN_AUTH;
211 info->executorSensorHint = executorSensorHint;
212 info->executorRole = ALL_IN_ONE;
213 memcpy_s(info->deviceUdid, UDID_LEN, udid, UDID_LEN);
214 g_poolList->insert(g_poolList, static_cast<void *>(info));
215 struct SessionInfo session = {};
216 session.userId = userId;
217 session.isScheduleValid = true;
218 session.scheduleId = 10;
219 session.authType = PIN_AUTH;
220 session.time = GetSystemTime();
221 session.pinChangeScence = PIN_UPDATE_SCENCE;
222 g_session = &session;
223 EXPECT_NE(GenerateIdmSchedule(¶m, scheduleType), nullptr);
224 DestroyResourcePool();
225 DestoryCoAuth();
226 g_session = nullptr;
227 LOG_INFO("TestGenerateIdmSchedule_005 end");
228 }
229
230 HWTEST_F(UserIdmFuncsTest, TestGenerateIdmSchedule_006, TestSize.Level0)
231 {
232 LOG_INFO("TestGenerateIdmSchedule_006 start");
233 PermissionCheckParam param = {};
234 constexpr uint32_t executorSensorHint = 10;
235 constexpr int32_t userId = 1;
236 param.userId = userId;
237 param.authType = PIN_AUTH;
238 param.executorSensorHint = executorSensorHint;
239 ScheduleType scheduleType = SCHEDULE_TYPE_ABANDON;
240 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
241 param.executorSensorHint = INVALID_SENSOR_HINT;
242 static char udid[UDID_LEN + 1] = "0123456789012345678901234567890123456789012345678901234567890123";
243 SetLocalUdid(udid);
244 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
245 TestInitUserInfoList();
246 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
247 InitResourcePool();
248 InitCoAuth();
249 ExecutorInfoHal *info = static_cast<ExecutorInfoHal *>(malloc(sizeof(ExecutorInfoHal)));
250 EXPECT_NE(info, nullptr);
251 info->authType = PIN_AUTH;
252 info->executorSensorHint = executorSensorHint;
253 info->executorRole = ALL_IN_ONE;
254 memcpy_s(info->deviceUdid, UDID_LEN, udid, UDID_LEN);
255 g_poolList->insert(g_poolList, static_cast<void *>(info));
256 struct SessionInfo session = {};
257 session.userId = userId;
258 session.isScheduleValid = true;
259 session.scheduleId = 10;
260 session.authType = PIN_AUTH;
261 session.time = GetSystemTime();
262 session.pinChangeScence = PIN_RESET_SCENCE;
263 g_session = &session;
264 EXPECT_NE(GenerateIdmSchedule(¶m, scheduleType), nullptr);
265 DestroyResourcePool();
266 DestoryCoAuth();
267 g_session = nullptr;
268 LOG_INFO("TestGenerateIdmSchedule_006 end");
269 }
270
271 HWTEST_F(UserIdmFuncsTest, TestGenerateIdmSchedule_007, TestSize.Level0)
272 {
273 LOG_INFO("TestGenerateIdmSchedule_006 start");
274 InitResourcePool();
275 EXPECT_NE(g_poolList, nullptr);
276 constexpr uint32_t executorSensorHint = 10;
277 ExecutorInfoHal *info = static_cast<ExecutorInfoHal *>(malloc(sizeof(ExecutorInfoHal)));
278 EXPECT_NE(info, nullptr);
279 info->authType = PIN_AUTH;
280 info->executorSensorHint = executorSensorHint;
281 info->executorRole = ALL_IN_ONE;
282 g_poolList->insert(g_poolList, static_cast<void *>(info));
283 PermissionCheckParam param = {};
284 param.authType = PIN_AUTH;
285 param.executorSensorHint = executorSensorHint;
286 ScheduleType scheduleType = SCHEDULE_TYPE_ABANDON;
287 static char udid[UDID_LEN + 1] = "0123456789012345678901234567890123456789012345678901234567890123";
288 SetLocalUdid(udid);
289 EXPECT_EQ(GenerateIdmSchedule(¶m, scheduleType), nullptr);
290 DestroyResourcePool();
291 LOG_INFO("TestGenerateIdmSchedule_006 start");
292 }
293
294 HWTEST_F(UserIdmFuncsTest, TestCheckEnrollPermission_001, TestSize.Level0)
295 {
296 PermissionCheckParam param = {};
297 EXPECT_EQ(CheckEnrollPermission(¶m), RESULT_NEED_INIT);
298 }
299
300 HWTEST_F(UserIdmFuncsTest, TestCheckEnrollPermission_002, TestSize.Level0)
301 {
302 constexpr int32_t userId = 32156;
303 struct SessionInfo session = {};
304 session.userId = userId;
305 session.time = GetSystemTime();
306 g_session = &session;
307
308 g_userInfoList = CreateLinkedList(DestroyUserInfoNode);
309 EXPECT_NE(g_userInfoList, nullptr);
310 PermissionCheckParam param = {};
311 param.authType = FACE_AUTH;
312 EXPECT_EQ(CheckEnrollPermission(¶m), RESULT_GENERAL_ERROR);
313 param.userId = userId;
314 EXPECT_EQ(CheckEnrollPermission(¶m), RESULT_VERIFY_TOKEN_FAIL);
315 DestroyLinkedList(g_userInfoList);
316 g_userInfoList = nullptr;
317 g_session = nullptr;
318 }
319
320 HWTEST_F(UserIdmFuncsTest, TestCheckUpdatePermission_001, TestSize.Level0)
321 {
322 PermissionCheckParam param = {};
323 param.authType = FACE_AUTH;
324 EXPECT_EQ(CheckUpdatePermission(¶m), RESULT_BAD_PARAM);
325 param.authType = PIN_AUTH;
326 EXPECT_EQ(CheckUpdatePermission(¶m), RESULT_NEED_INIT);
327 }
328
329 HWTEST_F(UserIdmFuncsTest, TestCheckUpdatePermission_002, TestSize.Level0)
330 {
331 constexpr int32_t userId = 32156;
332 constexpr uint32_t excutorSensorHint1 = 10;
333 constexpr uint32_t excutorSensorHint2 = 20;
334 struct SessionInfo session = {};
335 session.userId = userId;
336 session.time = GetSystemTime();
337 g_session = &session;
338 g_userInfoList = CreateLinkedList(DestroyUserInfoNode);
339 EXPECT_NE(g_userInfoList, nullptr);
340
341 PermissionCheckParam param = {};
342 param.authType = PIN_AUTH;
343 param.userId = userId;
344 EXPECT_EQ(CheckUpdatePermission(¶m), RESULT_SUCCESS);
345 UserInfo *userInfo = static_cast<UserInfo *>(malloc(sizeof(UserInfo)));
346 EXPECT_NE(userInfo, nullptr);
347 userInfo->userId = userId;
348 userInfo->credentialInfoList = CreateLinkedList(DestroyCredentialNode);
349 userInfo->enrolledInfoList = CreateLinkedList(DestroyEnrolledNode);
350 EXPECT_NE(userInfo->credentialInfoList, nullptr);
351 CredentialInfoHal *credInfo = static_cast<CredentialInfoHal *>(malloc(sizeof(CredentialInfoHal)));
352 EXPECT_NE(credInfo, nullptr);
353 credInfo->authType = PIN_AUTH;
354 credInfo->executorSensorHint = excutorSensorHint2;
355 credInfo->isAbandoned = false;
356 userInfo->credentialInfoList->insert(userInfo->credentialInfoList, static_cast<void *>(credInfo));
357 g_userInfoList->insert(g_userInfoList, static_cast<void *>(userInfo));
358 param.executorSensorHint = excutorSensorHint1;
359 EXPECT_EQ(CheckUpdatePermission(¶m), RESULT_VERIFY_TOKEN_FAIL);
360 DestroyUserInfoList();
361 g_session = nullptr;
362 }
363
364 HWTEST_F(UserIdmFuncsTest, TestGetCredentialInfoFromSchedule, TestSize.Level0)
365 {
366 g_session = nullptr;
367 ExecutorResultInfo resultInfo = {};
368 CredentialInfoHal credInfo = {};
369 CoAuthSchedule scheduleInfo = {};
370 EXPECT_EQ(GetCredentialInfoFromSchedule(&resultInfo, &credInfo, &scheduleInfo), RESULT_GENERAL_ERROR);
371
372 constexpr int32_t userId = 32158;
373 struct SessionInfo session = {};
374 session.userId = userId;
375 session.isScheduleValid = true;
376 session.scheduleId = 10;
377 session.authType = FACE_AUTH;
378 session.time = UINT64_MAX;
379 g_session = &session;
380
381 resultInfo.scheduleId = 311157;
382 EXPECT_EQ(GetCredentialInfoFromSchedule(&resultInfo, &credInfo, &scheduleInfo), RESULT_GENERAL_ERROR);
383 resultInfo.scheduleId = 10;
384 EXPECT_EQ(GetCredentialInfoFromSchedule(&resultInfo, &credInfo, &scheduleInfo), RESULT_GENERAL_ERROR);
385
386 session.time = GetSystemTime();
387 g_scheduleList = nullptr;
388 EXPECT_EQ(GetCredentialInfoFromSchedule(&resultInfo, &credInfo, &scheduleInfo), RESULT_SUCCESS);
389 g_session = nullptr;
390 }
391
392 HWTEST_F(UserIdmFuncsTest, TestAddCredentialFunc, TestSize.Level0)
393 {
394 constexpr int32_t userId1 = 21345;
395 constexpr int32_t userId2 = 1122;
396 EXPECT_EQ(AddCredentialFunc(userId1, nullptr, nullptr, nullptr, nullptr), RESULT_BAD_PARAM);
397 Buffer *scheduleResult = CreateBufferBySize(20);
398 uint64_t credentialId = 0;
399 Buffer *rootSecret = nullptr;
400 Buffer *authToken = nullptr;
401 EXPECT_EQ(AddCredentialFunc(userId1, scheduleResult, &credentialId, &rootSecret, &authToken), RESULT_UNKNOWN);
402 struct SessionInfo session = {};
403 session.userId = userId2;
404 g_session = &session;
405 EXPECT_EQ(AddCredentialFunc(userId1, scheduleResult, &credentialId, &rootSecret, &authToken), RESULT_UNKNOWN);
406 g_session = nullptr;
407 }
408
409 HWTEST_F(UserIdmFuncsTest, TestDeleteCredentialFunc, TestSize.Level0)
410 {
411 CredentialDeleteParam param = {};
412 EXPECT_EQ(DeleteCredentialFunc(param, nullptr), RESULT_BAD_PARAM);
413
414 OperateResult operateResult = {};
415 UserAuthTokenHal token = {};
416 token.tokenDataPlain.authType = 4;
417 EXPECT_EQ(memcpy_s(param.token, sizeof(UserAuthTokenHal), &token, sizeof(UserAuthTokenHal)), EOK);
418 EXPECT_EQ(DeleteCredentialFunc(param, &operateResult), RESULT_VERIFY_TOKEN_FAIL);
419 }
420
421 HWTEST_F(UserIdmFuncsTest, TestQueryCredentialFunc, TestSize.Level0)
422 {
423 EXPECT_EQ(QueryCredentialFunc(0, 0, nullptr), RESULT_BAD_PARAM);
424 LinkedList *creds = nullptr;
425 g_userInfoList = nullptr;
426 EXPECT_EQ(QueryCredentialFunc(0, 0, &creds), RESULT_UNKNOWN);
427 }
428
429 HWTEST_F(UserIdmFuncsTest, TestGetUserInfoFunc, TestSize.Level0)
430 {
431 EXPECT_EQ(GetUserInfoFunc(0, nullptr, nullptr, nullptr, nullptr), RESULT_BAD_PARAM);
432 }
433
434 HWTEST_F(UserIdmFuncsTest, TestGetDeletedCredential, TestSize.Level0)
435 {
436 g_userInfoList = nullptr;
437 constexpr int32_t userId = 2156;
438 CredentialInfoHal deletedCredInfo = {};
439 EXPECT_EQ(GetDeletedCredential(userId, &deletedCredInfo), RESULT_UNKNOWN);
440
441 g_userInfoList = CreateLinkedList(DestroyUserInfoNode);
442 EXPECT_NE(g_userInfoList, nullptr);
443 EXPECT_EQ(GetDeletedCredential(userId, &deletedCredInfo), RESULT_UNKNOWN);
444
445 UserInfo *userInfo = static_cast<UserInfo *>(malloc(sizeof(UserInfo)));
446 EXPECT_NE(userInfo, nullptr);
447 userInfo->userId = userId;
448 userInfo->credentialInfoList = CreateLinkedList(DestroyCredentialNode);
449 userInfo->enrolledInfoList = CreateLinkedList(DestroyEnrolledNode);
450 EXPECT_NE(userInfo->credentialInfoList, nullptr);
451 CredentialInfoHal *credInfo = static_cast<CredentialInfoHal *>(malloc(sizeof(CredentialInfoHal)));
452 EXPECT_NE(credInfo, nullptr);
453 credInfo->authType = 1;
454 credInfo->isAbandoned = false;
455 userInfo->credentialInfoList->insert(userInfo->credentialInfoList, static_cast<void *>(credInfo));
456 g_userInfoList->insert(g_userInfoList, static_cast<void *>(userInfo));
457 EXPECT_EQ(GetDeletedCredential(userId, &deletedCredInfo), RESULT_SUCCESS);
458 DestroyUserInfoList();
459 }
460
461 HWTEST_F(UserIdmFuncsTest, TestCheckResultValid, TestSize.Level0)
462 {
463 g_session = nullptr;
464 constexpr uint64_t scheduleId = 10;
465 constexpr int32_t userId = 2112;
466 EXPECT_EQ(CheckResultValid(scheduleId, userId), RESULT_GENERAL_ERROR);
467
468 struct SessionInfo session = {};
469 session.userId = 1122;
470 session.scheduleId = 20;
471 session.authType = FACE_AUTH;
472 session.isScheduleValid = true;
473 session.time = UINT64_MAX;
474 g_session = &session;
475 EXPECT_EQ(CheckResultValid(scheduleId, userId), RESULT_GENERAL_ERROR);
476
477 session.scheduleId = scheduleId;
478 EXPECT_EQ(CheckResultValid(scheduleId, userId), RESULT_GENERAL_ERROR);
479
480 session.time = GetSystemTime();
481 EXPECT_EQ(CheckResultValid(scheduleId, userId), RESULT_REACH_LIMIT);
482
483 session.userId = userId;
484 EXPECT_EQ(CheckResultValid(scheduleId, userId), RESULT_UNKNOWN);
485 }
486
487 HWTEST_F(UserIdmFuncsTest, TestUpdateCredentialFunc, TestSize.Level0)
488 {
489 EXPECT_EQ(UpdateCredentialFunc(0, nullptr, nullptr), RESULT_BAD_PARAM);
490
491 constexpr uint32_t bufferSize = 10;
492 Buffer *scheduleResult = CreateBufferBySize(bufferSize);
493 UpdateCredentialOutput output = {};
494 EXPECT_EQ(UpdateCredentialFunc(0, scheduleResult, &output), RESULT_UNKNOWN);
495 }
496 } // namespace UserAuth
497 } // namespace UserIam
498 } // namespace OHOS
499