1 /*
2  * Copyright (c) 2023-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 "iam_hat_test.h"
17 #include "user_auth_hdi_test.h"
18 
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS::UserIam::Common;
22 using namespace OHOS::HDI::UserAuth;
23 using namespace OHOS::HDI::UserAuth::V2_0;
24 
25 static const uint32_t MAX_FUZZ_STRUCT_LEN = 20;
26 static UserAuthInterfaceService g_service;
27 int32_t Expectedvalue = 0;
28 static OHOS::Parcel parcel;
29 
30 struct HdiBeginEnrollmentList {
31     int32_t userId[4] = {12345, 1234, 12345, 12345};
32     int32_t authType[4] = {1, 0, 2, 4};
33     uint32_t executorSensorHint[4] = {0, 65535, 1, 0};
34 };
35 struct HdiBeginAuthenticationList {
36     uint32_t authType[4] = {0, 1, 2, 4};
37     uint32_t userId[4] = {356581, 1};
38 };
39 struct HdiBeginIdentificationList {
40     uint32_t addExecutor[2] = {0, 1};
41     uint32_t authType[4] = {0, 1, 2, 4};
42 };
43 
SetUpTestCase()44 void UserIamUserAuthTestAdditional::SetUpTestCase() {}
45 
TearDownTestCase()46 void UserIamUserAuthTestAdditional::TearDownTestCase() {}
47 
SetUp()48 void UserIamUserAuthTestAdditional::SetUp()
49 {
50     const std::string deviceUdid = std::string(64, '0');
51     EXPECT_EQ(g_service.Init(deviceUdid), 0);
52 }
53 
TearDown()54 void UserIamUserAuthTestAdditional::TearDown() {}
55 
FillEnrollParam(Parcel &parcel, EnrollParam &enrollParam)56 static void FillEnrollParam(Parcel &parcel, EnrollParam &enrollParam)
57 {
58     enrollParam.authType = static_cast<AuthType>(parcel.ReadInt32());
59     enrollParam.executorSensorHint = parcel.ReadUint32();
60     enrollParam.userId = parcel.ReadInt32();
61 }
62 
FillExecutorIndexInfo(Parcel &parcel, uint64_t &executorIndex)63 static void FillExecutorIndexInfo(Parcel &parcel, uint64_t &executorIndex)
64 {
65     executorIndex = parcel.ReadUint64();
66 }
67 
FillExecutorIndexVector(Parcel &parcel, vector<uint64_t > &vector)68 static void FillExecutorIndexVector(Parcel &parcel, vector<uint64_t > &vector)
69 {
70     uint32_t len = parcel.ReadInt32() % MAX_FUZZ_STRUCT_LEN;
71     vector.resize(len);
72     for (uint32_t i = 0; i < len; i++) {
73         FillExecutorIndexInfo(parcel, vector[i]);
74     }
75 }
76 
FillScheduleInfo(Parcel &parcel, ScheduleInfo &scheduleInfo)77 static void FillScheduleInfo(Parcel &parcel, ScheduleInfo &scheduleInfo)
78 {
79     scheduleInfo.scheduleId = parcel.ReadUint64();
80     FillTestUint64Vector(parcel, scheduleInfo.templateIds);
81     scheduleInfo.authType = static_cast<AuthType>(parcel.ReadInt32());
82     scheduleInfo.executorMatcher = parcel.ReadUint32();
83     scheduleInfo.scheduleMode = static_cast<ScheduleMode>(parcel.ReadInt32());
84     FillExecutorIndexVector(parcel, scheduleInfo.executorIndexes);
85 }
86 
FillCredentialInfo(Parcel &parcel, CredentialInfo &credentialInfo)87 static void FillCredentialInfo(Parcel &parcel, CredentialInfo &credentialInfo)
88 {
89     credentialInfo.credentialId = parcel.ReadUint64();
90     credentialInfo.executorIndex = parcel.ReadUint64();
91     credentialInfo.templateId = parcel.ReadUint64();
92     credentialInfo.authType = static_cast<AuthType>(parcel.ReadInt32());
93     credentialInfo.executorMatcher = parcel.ReadUint32();
94     credentialInfo.executorSensorHint = parcel.ReadUint32();
95 }
96 
FillEnrolledInfo(Parcel &parcel, EnrolledInfo &enrolledInfo)97 static void FillEnrolledInfo(Parcel &parcel, EnrolledInfo &enrolledInfo)
98 {
99     enrolledInfo.enrolledId = parcel.ReadUint64();
100     enrolledInfo.authType = static_cast<AuthType>(parcel.ReadInt32());
101 }
102 
FillCredentialInfoVector(Parcel &parcel, vector<CredentialInfo> &vector)103 static void FillCredentialInfoVector(Parcel &parcel, vector<CredentialInfo> &vector)
104 {
105     uint32_t len = parcel.ReadInt32() % MAX_FUZZ_STRUCT_LEN;
106     vector.resize(len);
107     for (uint32_t i = 0; i < len; i++) {
108         FillCredentialInfo(parcel, vector[i]);
109     }
110 }
111 
FillEnrolledInfoVector(Parcel &parcel, vector<EnrolledInfo> &vector)112 static void FillEnrolledInfoVector(Parcel &parcel, vector<EnrolledInfo> &vector)
113 {
114     uint32_t len = parcel.ReadInt32() % MAX_FUZZ_STRUCT_LEN;
115     vector.resize(len);
116     for (uint32_t i = 0; i < len; i++) {
117         FillEnrolledInfo(parcel, vector[i]);
118     }
119 }
120 
121 /**
122  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_0200
123  * @tc.name  : testAddExecutor001
124  * @tc.desc  : First input parameter being the ExecutorRegisterInfo structure ->authType value being
125  * ALL/PIN/FACE/FINGERPRINT
126  */
HWTEST_F(UserIamUserAuthTestAdditional, testAddExecutor001, Function | MediumTest | Level1)127 HWTEST_F(UserIamUserAuthTestAdditional, testAddExecutor001, Function | MediumTest | Level1)
128 {
129     uint32_t i = 0;
130     uint32_t authType[4] = {0, 1, 2, 4};
131     ExecutorRegisterInfo info = {};
132     uint64_t index = 0;
133     std::vector<uint8_t> publicKey;
134     std::vector<uint64_t> templateIds;
135 
136     for (i = 0; i < 4; i++) {
137         info.authType = static_cast<AuthType>(authType[i]);
138         info.publicKey.resize(32);
139         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
140         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
141     }
142 }
143 /**
144  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_1800
145  * @tc.name  : testDeleteExecutor001
146  * @tc.desc  : Delete call without adding an authentication executor
147  */
HWTEST_F(UserIamUserAuthTestAdditional, testDeleteExecutor001, Function | MediumTest | Level2)148 HWTEST_F(UserIamUserAuthTestAdditional, testDeleteExecutor001, Function | MediumTest | Level2)
149 {
150     cout << "start DeleteExecutor" << endl;
151     uint64_t index = -1;
152     auto ret = g_service.DeleteExecutor(index);
153     cout << "ret is " << ret << endl;
154     ASSERT_EQ(ret != Expectedvalue, true);
155 }
156 /**
157  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_1900
158  * @tc.name  : testDeleteExecutor002
159  * @tc.desc  : First call the AddExecutor function to add an authentication executor,
160  *              and then call the DeleteExecutor function to delete it
161  */
HWTEST_F(UserIamUserAuthTestAdditional, testDeleteExecutor002, Function | MediumTest | Level1)162 HWTEST_F(UserIamUserAuthTestAdditional, testDeleteExecutor002, Function | MediumTest | Level1)
163 {
164     cout << "start DeleteExecutor" << endl;
165     ExecutorRegisterInfo info = {};
166     info.authType = AuthType::ALL;
167     info.publicKey.resize(32);
168     uint64_t index = 0;
169     std::vector<uint8_t> publicKey;
170     std::vector<uint64_t> templateIds;
171     EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
172 
173     auto ret = g_service.DeleteExecutor(index);
174     cout << "ret is " << ret << endl;
175     EXPECT_EQ(ret, 0);
176 }
177 /**
178  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_2000
179  * @tc.name  : testDeleteExecutor003
180  * @tc.desc  : Call the AddExecutor function to add an authentication executor,
181  *              and then call the DeleteExecutor function to pass in different parameters for deletion
182  */
HWTEST_F(UserIamUserAuthTestAdditional, testDeleteExecutor003, Function | MediumTest | Level2)183 HWTEST_F(UserIamUserAuthTestAdditional, testDeleteExecutor003, Function | MediumTest | Level2)
184 {
185     cout << "start DeleteExecutor" << endl;
186     ExecutorRegisterInfo info = {};
187     info.authType = AuthType::ALL;
188     info.publicKey.resize(32);
189     uint64_t index = 0;
190     std::vector<uint8_t> publicKey;
191     std::vector<uint64_t> templateIds;
192     EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
193     EXPECT_NE(index, 0);
194     index = 0;
195     auto ret = g_service.DeleteExecutor(index);
196     cout << "ret is " << ret << endl;
197     EXPECT_NE(ret, 0);
198 }
199 /**
200  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_2200
201  * @tc.name  : testOpenSession002
202  * @tc.desc  : Call the OpenSession function with the parameter userId = -1/0/1
203  */
HWTEST_F(UserIamUserAuthTestAdditional, testOpenSession002, Function | MediumTest | Level1)204 HWTEST_F(UserIamUserAuthTestAdditional, testOpenSession002, Function | MediumTest | Level1)
205 {
206     cout << "start OpenSession" << endl;
207     uint32_t i = 0;
208     int32_t userId[3] = {-1, 0, 1};
209     std::vector<uint8_t> challenge;
210     for (i = 0; i < 3; i++) {
211         FillTestUint8Vector(parcel, challenge);
212         EXPECT_EQ(g_service.OpenSession(userId[i], challenge), 0);
213         EXPECT_EQ(g_service.CloseSession(userId[i]), 0);
214     }
215 }
216 /**
217  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_2500
218  * @tc.name  : testCloseSession002
219  * @tc.desc  : Close unopened authentication credential management sessions
220  */
HWTEST_F(UserIamUserAuthTestAdditional, testCloseSession002, Function | MediumTest | Level2)221 HWTEST_F(UserIamUserAuthTestAdditional, testCloseSession002, Function | MediumTest | Level2)
222 {
223     cout << "start CloseSession" << endl;
224     uint32_t i = 0;
225     uint32_t ret = 0;
226     int32_t userId[2] = {-1, 1000};
227     for (i = 0; i < 2; i++) {
228         EXPECT_NE(g_service.CloseSession(userId[i]), 0);
229     }
230     cout << "ret is " << ret << endl;
231 }
232 /**
233  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_2600
234  * @tc.name  : testCloseSession003
235  * @tc.desc  : Close unopened authentication credential management sessions
236  */
HWTEST_F(UserIamUserAuthTestAdditional, testCloseSession003, Function | MediumTest | Level2)237 HWTEST_F(UserIamUserAuthTestAdditional, testCloseSession003, Function | MediumTest | Level2)
238 {
239     cout << "start CloseSession" << endl;
240     int32_t userId = 1000;
241     int32_t i = 0;
242     while (i < 50) {
243         EXPECT_NE(g_service.CloseSession(userId), 0);
244         i++;
245     }
246 }
247 /**
248  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_2700
249  * @tc.name  : testBeginEnrollment001
250  * @tc.desc  : Directly call the BeginEnrollment function without preprocessing
251  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginEnrollment001, Function | MediumTest | Level2)252 HWTEST_F(UserIamUserAuthTestAdditional, testBeginEnrollment001, Function | MediumTest | Level2)
253 {
254     cout << "start BeginEnrollment" << endl;
255     std::vector<uint8_t> authToken;
256     FillTestUint8Vector(parcel, authToken);
257     EnrollParam param;
258     FillEnrollParam(parcel, param);
259     ScheduleInfo info;
260     FillScheduleInfo(parcel, info);
261     auto ret = g_service.BeginEnrollment(authToken, param, info);
262     cout << "ret is " << ret << endl;
263     EXPECT_NE(ret, 0);
264 }
265 /**
266  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_2800
267  * @tc.name  : testBeginEnrollment002
268  * @tc.desc  : Call the OpenSession function and AddExecutor function, then call the BeginEnrollment function
269  * and test different authTypes
270  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginEnrollment002, Function | MediumTest | Level1)271 HWTEST_F(UserIamUserAuthTestAdditional, testBeginEnrollment002, Function | MediumTest | Level1)
272 {
273     uint32_t i = 0;
274     uint64_t index = 0;
275     std::vector<uint8_t> challenge;
276     std::vector<uint8_t> authToken;
277     std::vector<uint8_t> publicKey;
278     std::vector<uint64_t> templateIds;
279     ScheduleInfo scheduleInfo = {};
280     ExecutorRegisterInfo info = {};
281     EnrollParam param = {};
282     param.userId = 12345;
283     uint32_t authType[4] = {0, 1, 2, 4};
284 
285     for (i = 0; i < 4; i++) {
286         EXPECT_EQ(g_service.OpenSession(param.userId, challenge), 0);
287         info.executorRole = ExecutorRole::ALL_IN_ONE;
288         info.esl = ExecutorSecureLevel::ESL0;
289         info.publicKey.resize(32);
290         info.authType = static_cast<AuthType>(authType[i]);
291         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
292         param.authType = static_cast<AuthType>(authType[i]);
293 
294         if (i == 1) {
295             EXPECT_EQ(g_service.BeginEnrollment(authToken, param, scheduleInfo), 0);
296 
297             EXPECT_EQ(g_service.CancelEnrollment(param.userId), 0);
298         } else {
299             EXPECT_NE(g_service.BeginEnrollment(authToken, param, scheduleInfo), 0);
300         }
301         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
302         EXPECT_EQ(g_service.CloseSession(param.userId), 0);
303     }
304 }
305 /**
306  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_3200
307  * @tc.name  : testCancelEnrollment001
308  * @tc.desc  : Call the CancelEnrollment function with userId=-123 as the input parameter
309  */
HWTEST_F(UserIamUserAuthTestAdditional, testCancelEnrollment001, Function | MediumTest | Level1)310 HWTEST_F(UserIamUserAuthTestAdditional, testCancelEnrollment001, Function | MediumTest | Level1)
311 {
312     cout << "start CancelEnrollment" << endl;
313     int32_t userId = -123;
314     auto ret = g_service.CancelEnrollment(userId);
315     cout << "ret is " << ret << endl;
316     EXPECT_EQ(ret, 0);
317 }
318 /**
319  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_3300
320  * @tc.name  : testCancelEnrollment002
321  * @tc.desc  : The BeginEnrollment function is invoked to register the authentication credentials,
322  *              and then the CancelEnrollment function is invoked to cancel the registration
323  */
HWTEST_F(UserIamUserAuthTestAdditional, testCancelEnrollment002, Function | MediumTest | Level1)324 HWTEST_F(UserIamUserAuthTestAdditional, testCancelEnrollment002, Function | MediumTest | Level1)
325 {
326     uint32_t i = 0;
327     int32_t userId[3] = {-12345, 0, 1};
328     std::vector<uint8_t> challenge;
329     ExecutorRegisterInfo info = {};
330     uint64_t index = 0;
331     std::vector<uint8_t> publicKey;
332     std::vector<uint64_t> templateIds;
333     std::vector<uint8_t> authToken;
334     EnrollParam param = {};
335     ScheduleInfo scheduleInfo = {};
336 
337     for (i = 0; i < 3; i++) {
338         EXPECT_EQ(g_service.OpenSession(userId[i], challenge), 0);
339 
340         info.authType = AuthType::PIN;
341         info.executorRole = ExecutorRole::ALL_IN_ONE;
342         info.esl = ExecutorSecureLevel::ESL0;
343         info.publicKey.resize(32);
344         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
345 
346         param.authType = AuthType::PIN;
347         param.userId = userId[i];
348         EXPECT_EQ(g_service.BeginEnrollment(authToken, param, scheduleInfo), 0);
349 
350         EXPECT_EQ(g_service.CancelEnrollment(userId[i]), 0);
351         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
352         EXPECT_EQ(g_service.CloseSession(userId[i]), 0);
353     }
354 }
355 /**
356  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_3700
357  * @tc.name  : testCancelEnrollment006
358  * @tc.desc  : Call the BeginEnrollment function to register the authentication credentials,
359  *              then call the CancelEnrollment function to cancel, and then continue to cancel 50 times
360  */
HWTEST_F(UserIamUserAuthTestAdditional, testCancelEnrollment006, Function | MediumTest | Level1)361 HWTEST_F(UserIamUserAuthTestAdditional, testCancelEnrollment006, Function | MediumTest | Level1)
362 {
363     int32_t userId = 1;
364     int32_t i = 0;
365     std::vector<uint8_t> challenge;
366     EXPECT_EQ(g_service.OpenSession(userId, challenge), 0);
367 
368     ExecutorRegisterInfo info = {};
369     info.authType = AuthType::PIN;
370     info.executorRole = ExecutorRole::ALL_IN_ONE;
371     info.esl = ExecutorSecureLevel::ESL0;
372     info.publicKey.resize(32);
373     uint64_t index = 0;
374     std::vector<uint8_t> publicKey;
375     std::vector<uint64_t> templateIds;
376     EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
377 
378     std::vector<uint8_t> authToken;
379     EnrollParam param = {};
380     param.userId = userId;
381     param.authType = AuthType::PIN;
382     ScheduleInfo scheduleInfo = {};
383     EXPECT_EQ(g_service.BeginEnrollment(authToken, param, scheduleInfo), 0);
384 
385     EXPECT_EQ(g_service.CancelEnrollment(userId), 0);
386     while (i < 50) {
387         EXPECT_EQ(g_service.CancelEnrollment(userId), 0);
388         i++;
389     }
390     EXPECT_EQ(g_service.DeleteExecutor(index), 0);
391     EXPECT_EQ(g_service.CloseSession(userId), 0);
392 }
393 /**
394  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_3800
395  * @tc.name  : testGetCredential001
396  * @tc.desc  : Call the GetCredential function, with the first input parameter being userId=-1、0、1
397  */
HWTEST_F(UserIamUserAuthTestAdditional, testGetCredential001, Function | MediumTest | Level1)398 HWTEST_F(UserIamUserAuthTestAdditional, testGetCredential001, Function | MediumTest | Level1)
399 {
400     cout << "start GetCredential" << endl;
401     uint32_t i = 0;
402     uint32_t userId[3] = {-1, 0, 1};
403     AuthType authType = static_cast<AuthType>(parcel.ReadInt32());
404     std::vector<CredentialInfo> infos;
405 
406     for (i = 0; i < 3; i++) {
407         FillCredentialInfoVector(parcel, infos);
408         EXPECT_EQ(g_service.GetCredential(userId[i], authType, infos), 0);
409     }
410 }
411 /**
412  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_3900
413  * @tc.name  : testGetCredential002
414  * @tc.desc  : Pass the authType authentication type to all types and determine the result of the function
415  */
HWTEST_F(UserIamUserAuthTestAdditional, testGetCredential002, Function | MediumTest | Level1)416 HWTEST_F(UserIamUserAuthTestAdditional, testGetCredential002, Function | MediumTest | Level1)
417 {
418     cout << "start GetCredential" << endl;
419     uint32_t i = 0;
420     int32_t userId = parcel.ReadInt32();
421     uint32_t authType[4] = {0, 1, 2, 4};
422     std::vector<CredentialInfo> infos;
423 
424     for (i = 0; i < 4; i++) {
425         FillCredentialInfoVector(parcel, infos);
426         EXPECT_EQ(g_service.GetCredential(userId, static_cast<AuthType>(authType[i]), infos), 0);
427     }
428 }
429 /**
430  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_4500
431  * @tc.name  : testGetUserInfo001
432  * @tc.desc  : Pass the wrong userId to the function to determine the result of the function
433  */
HWTEST_F(UserIamUserAuthTestAdditional, testGetUserInfo001, Function | MediumTest | Level2)434 HWTEST_F(UserIamUserAuthTestAdditional, testGetUserInfo001, Function | MediumTest | Level2)
435 {
436     cout << "start GetUserInfo" << endl;
437     uint32_t i = 0;
438     int userId[2] = {6789, -6789};
439     uint64_t secureUid = parcel.ReadUint64();
440     int32_t pinSubType = parcel.ReadInt32();
441     std::vector<EnrolledInfo> infos;
442 
443     for (i = 0; i < 2; i++) {
444         FillEnrolledInfoVector(parcel, infos);
445         EXPECT_NE(g_service.GetUserInfo(userId[i], secureUid, pinSubType, infos), 0);
446     }
447 }
448 /**
449  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_4700
450  * @tc.name  : testDeleteUser001
451  * @tc.desc  : Call the DeleteUser function, with the first input parameter
452  *              being userId=-1 and the second parameter being empty
453  */
HWTEST_F(UserIamUserAuthTestAdditional, testDeleteUser001, Function | MediumTest | Level2)454 HWTEST_F(UserIamUserAuthTestAdditional, testDeleteUser001, Function | MediumTest | Level2)
455 {
456     cout << "start DeleteUser" << endl;
457 
458     int32_t userId = -1;
459     std::vector<uint8_t> challenge;
460     EXPECT_EQ(g_service.OpenSession(userId, challenge), 0);
461 
462     ExecutorRegisterInfo info = {};
463     info.authType = AuthType::PIN;
464     info.executorRole = ExecutorRole::ALL_IN_ONE;
465     info.esl = ExecutorSecureLevel::ESL0;
466     info.publicKey.resize(32);
467 
468     std::vector<uint8_t> publicKey;
469     std::vector<uint64_t> templateIds;
470     uint64_t index = 0;
471     EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
472 
473     std::vector<uint8_t> authToken;
474     std::vector<CredentialInfo> deletedInfos;
475     std::vector<uint8_t> rootSecret;
476     auto ret = g_service.DeleteUser(userId, authToken, deletedInfos, rootSecret);
477     cout << "ret is " << ret << endl;
478     EXPECT_NE(ret, 0);
479 }
480 /**
481  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_4800
482  * @tc.name  : testDeleteUser002
483  * @tc.desc  : Call the DeleteUser function, with the second input parameter being authToken=-1、0
484  */
HWTEST_F(UserIamUserAuthTestAdditional, testDeleteUser002, Function | MediumTest | Level2)485 HWTEST_F(UserIamUserAuthTestAdditional, testDeleteUser002, Function | MediumTest | Level2)
486 {
487     cout << "start DeleteUser" << endl;
488     uint32_t i = 0;
489     uint32_t num[2] = {-1, 0};
490     std::vector<CredentialInfo> deletedInfos;
491     int32_t userId = parcel.ReadInt32();
492     std::vector<uint8_t> authToken(1);
493     FillTestUint8Vector(parcel, authToken);
494     std::vector<uint8_t> rootSecret(1);
495     FillTestUint8Vector(parcel, rootSecret);
496     for (i = 0; i < 2; i++) {
497         authToken[0] = num[i];
498         EXPECT_NE(g_service.DeleteUser(userId, authToken, deletedInfos, rootSecret), 0);
499     }
500 }
501 /**
502  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_5000
503  * @tc.name  : testEnforceDeleteUser001
504  * @tc.desc  : Directly call the EnforceDeleteUser function, with the first input parameter being userId=-1,65535
505  */
HWTEST_F(UserIamUserAuthTestAdditional, testEnforceDeleteUser001, Function | MediumTest | Level2)506 HWTEST_F(UserIamUserAuthTestAdditional, testEnforceDeleteUser001, Function | MediumTest | Level2)
507 {
508     cout << "start EnforceDeleteUser" << endl;
509     uint32_t i = 0;
510     int32_t userId[2] = {-1, 65535};
511     std::vector<CredentialInfo> deletedInfos;
512 
513     for (i = 0; i < 2; i++) {
514         EXPECT_NE(g_service.EnforceDeleteUser(userId[i], deletedInfos), 0);
515     }
516 }
517 /**
518  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_5200
519  * @tc.name  : testBeginAuthentication001
520  * @tc.desc  : When the registration results are not updated and the registration is completed,
521  *              The first entry is contextId = 1/0/-1, the second entry is the AuthSolution structure ->userId = 365861,
522  *              authTrustLevel = 10000,authType = PIN,executorSensorHint = 1
523  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginAuthentication001, Function | MediumTest | Level2)524 HWTEST_F(UserIamUserAuthTestAdditional, testBeginAuthentication001, Function | MediumTest | Level2)
525 {
526     uint32_t i = 0;
527     uint64_t contextId[3] = {1, 0, -1};
528     AuthType authType = AuthType::PIN;
529     std::vector<uint8_t> challenge;
530     ExecutorRegisterInfo info = {};
531     std::vector<uint8_t> publicKey;
532     std::vector<uint64_t> templateIds;
533     uint64_t index = 0;
534     ScheduleInfo scheduleInfo = {};
535     std::vector<uint8_t> authToken;
536     EnrollParam enrollParam = {};
537     enrollParam.userId = 365861;
538     AuthParam authParam = {};
539     std::vector<ScheduleInfo> scheduleInfos;
540 
541     for (i = 0; i < 3; i++) {
542         EXPECT_EQ(g_service.OpenSession(enrollParam.userId, challenge), 0);
543 
544         info.authType = authType;
545         info.executorRole = ExecutorRole::ALL_IN_ONE;
546         info.esl = ExecutorSecureLevel::ESL0;
547         info.publicKey.resize(32);
548         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
549 
550         enrollParam.authType = authType;
551         EXPECT_EQ(g_service.BeginEnrollment(authToken, enrollParam, scheduleInfo), 0);
552 
553         authParam.baseParam.userId = enrollParam.userId;
554         authParam.baseParam.authTrustLevel = 10000;
555         authParam.authType = authType;
556         authParam.baseParam.executorSensorHint = 1;
557         authParam.baseParam.challenge = challenge;
558         EXPECT_NE(g_service.BeginAuthentication(contextId[i], authParam, scheduleInfos), 0);
559 
560         EXPECT_EQ(g_service.CancelEnrollment(enrollParam.userId), 0);
561         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
562         EXPECT_EQ(g_service.CloseSession(enrollParam.userId), 0);
563     }
564 }
565 /**
566  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_5500
567  * @tc.name  : testBeginAuthentication004
568  * @tc.desc  : The first input parameter is contextId=1, the second input parameter is the
569  *              AuthSolution structure->userId=0, authTrustLevel=-1、0、1000, authType=PIN, executorSensorHint=1
570  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginAuthentication004, Function | MediumTest | Level2)571 HWTEST_F(UserIamUserAuthTestAdditional, testBeginAuthentication004, Function | MediumTest | Level2)
572 {
573     uint32_t i = 0;
574     int32_t userId = 0;
575     uint64_t index = 0;
576     uint64_t contextId = 1;
577     uint32_t authTrustLevel[3] = {-1, 0, 1000};
578     AuthParam authParam = {};
579     ExecutorRegisterInfo info = {};
580     AuthType authType = AuthType::PIN;
581     std::vector<uint8_t> challenge;
582     std::vector<uint8_t> publicKey;
583     std::vector<uint64_t> templateIds;
584     std::vector<ScheduleInfo> scheduleInfos;
585 
586     for (i = 0; i < 3; i++) {
587         EXPECT_EQ(g_service.OpenSession(userId, challenge), 0);
588 
589         info.authType = authType;
590         info.executorRole = ExecutorRole::ALL_IN_ONE;
591         info.esl = ExecutorSecureLevel::ESL0;
592         info.publicKey.resize(32);
593         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
594 
595         authParam.baseParam.userId = userId;
596         authParam.baseParam.authTrustLevel = authTrustLevel[i];
597         authParam.authType = authType;
598         authParam.baseParam.executorSensorHint = 1;
599         authParam.baseParam.challenge = challenge;
600         EXPECT_NE(g_service.BeginAuthentication(contextId, authParam, scheduleInfos), 0);
601 
602         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
603         EXPECT_EQ(g_service.CloseSession(userId), 0);
604     }
605 }
606 /**
607  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_6200
608  * @tc.name  : testUpdateAuthenticationResult001
609  * @tc.desc  : The first input parameter is contextId=-1、0、1234567, and the second input parameter
610  *              is scheduleResult is empty
611  */
HWTEST_F(UserIamUserAuthTestAdditional, testUpdateAuthenticationResult001, Function | MediumTest | Level2)612 HWTEST_F(UserIamUserAuthTestAdditional, testUpdateAuthenticationResult001, Function | MediumTest | Level2)
613 {
614     uint32_t i = 0;
615     uint64_t contextId[3] = {-1, 0, 1234567};
616     std::vector<uint8_t> scheduleResult;
617     AuthResultInfo authResultInfo = {};
618     EnrolledState enrollState = {};
619 
620     for (i = 0; i < 3; i++) {
621         EXPECT_NE(g_service.UpdateAuthenticationResult(contextId[i], scheduleResult, authResultInfo, enrollState), 0);
622     }
623 }
624 /**
625  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_6500
626  * @tc.name  : testUpdateAuthenticationResult004
627  * @tc.desc  : The first input is contextId = 1, the second input is scheduleResult The size is 100,
628  *              and all inputs are initialized to 1 and 0
629  */
HWTEST_F(UserIamUserAuthTestAdditional, testUpdateAuthenticationResult004, Function | MediumTest | Level2)630 HWTEST_F(UserIamUserAuthTestAdditional, testUpdateAuthenticationResult004, Function | MediumTest | Level2)
631 {
632     uint32_t i = 0;
633     uint64_t contextId = 1;
634     uint64_t num[2] = {1, 0};
635     std::vector<uint8_t> scheduleResult(100);
636     AuthResultInfo authResultInfo = {};
637     EnrolledState enrollState = {};
638 
639     for (i = 0; i < 2; i++) {
640         scheduleResult.insert(scheduleResult.begin(), 100, num[i]);
641         EXPECT_NE(g_service.UpdateAuthenticationResult(contextId, scheduleResult, authResultInfo, enrollState), 0);
642     }
643 }
644 /**
645  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_6700
646  * @tc.name  : testCancelAuthentication001
647  * @tc.desc  : Verify the CancelAuthentication function with the first input being contextId = 0、-1、1000
648  */
HWTEST_F(UserIamUserAuthTestAdditional, testCancelAuthentication001, Function | MediumTest | Level2)649 HWTEST_F(UserIamUserAuthTestAdditional, testCancelAuthentication001, Function | MediumTest | Level2)
650 {
651     cout << "start CancelAuthentication" << endl;
652     uint32_t i = 0;
653     uint64_t contextId[3] = {0, -1, 1000};
654 
655     for (i = 0; i < 3; i++) {
656         EXPECT_NE(g_service.CancelAuthentication(contextId[i]), 0);
657     }
658 }
659 /**
660  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_7000
661  * @tc.name  : testBeginIdentification001
662  * @tc.desc  : The AddExecutor function is called first to add the authentication actuator,
663  *              and then the BeginIdentification function is called to start the identification
664  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification001, Function | MediumTest | Level1)665 HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification001, Function | MediumTest | Level1)
666 {
667     uint32_t i = 0;
668     uint64_t index = 0;
669     uint64_t contextId = 123456;
670     uint32_t authType[3] = {0, 2, 4};
671     ExecutorRegisterInfo info = {};
672     std::vector<uint8_t> challenge;
673     uint32_t executorSensorHint = 0;
674     ScheduleInfo scheduleInfo = {};
675     std::vector<uint8_t> publicKey;
676     std::vector<uint64_t> templateIds;
677     const std::string deviceUdid = std::string(64, '0');
678 
679     for (i = 0; i < 3; i++) {
680         info.authType = static_cast<AuthType>(authType[i]);
681         info.executorRole = ExecutorRole::ALL_IN_ONE;
682         info.esl = ExecutorSecureLevel::ESL0;
683         info.publicKey.resize(32);
684 
685         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
686         EXPECT_EQ(g_service.BeginIdentification(contextId, static_cast<AuthType>(authType[i]), challenge,
687                                                 executorSensorHint, scheduleInfo),
688                   0);
689         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
690         EXPECT_EQ(g_service.Init(deviceUdid), 0);
691     }
692 }
693 /**
694  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_8000
695  * @tc.name  : testBeginIdentification011
696  * @tc.desc  : The AddExecutor function is called first to add the authentication actuator,
697  *              and then the BeginIdentification function is called to start the identification
698  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification011, Function | MediumTest | Level2)699 HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification011, Function | MediumTest | Level2)
700 {
701     uint32_t i = 0;
702     ExecutorRegisterInfo info = {};
703     uint64_t index = 0;
704     std::vector<uint8_t> publicKey;
705     std::vector<uint64_t> templateIds;
706     uint64_t contextId = 123456;
707     AuthType authType = AuthType::FACE;
708     std::vector<uint8_t> challenge;
709     uint32_t executorSensorHint[2] = {-1234, 1234};
710     ScheduleInfo scheduleInfo = {};
711 
712     for (i = 0; i < 2; i++) {
713         info.authType = AuthType::FACE;
714         info.executorRole = ExecutorRole::ALL_IN_ONE;
715         info.esl = ExecutorSecureLevel::ESL0;
716         info.publicKey.resize(32);
717         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
718         EXPECT_NE(g_service.BeginIdentification(contextId, authType, challenge, executorSensorHint[i], scheduleInfo),
719                   0);
720         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
721     }
722 }
723 /**
724  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_8200
725  * @tc.name  : testBeginIdentification013
726  * @tc.desc  : The AddExecutor function is called to add the authentication actuator,
727  *              and then the BeginIdentification function is called 50 times to start the identification
728  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification013, Function | MediumTest | Level2)729 HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification013, Function | MediumTest | Level2)
730 {
731     int i = 0;
732     ExecutorRegisterInfo info = {};
733     info.authType = AuthType::FACE;
734     info.executorRole = ExecutorRole::ALL_IN_ONE;
735     info.esl = ExecutorSecureLevel::ESL0;
736     info.publicKey.resize(32);
737     uint64_t index = 0;
738     std::vector<uint8_t> publicKey;
739     std::vector<uint64_t> templateIds;
740     EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
741 
742     uint64_t contextId = 123456;
743     AuthType authType = AuthType::FACE;
744     std::vector<uint8_t> challenge;
745     uint32_t executorSensorHint = 0;
746     ScheduleInfo scheduleInfo = {};
747     EXPECT_EQ(g_service.BeginIdentification(contextId, authType, challenge, executorSensorHint, scheduleInfo), 0);
748     while (i < 50) {
749         EXPECT_NE(g_service.BeginIdentification(contextId, authType, challenge, executorSensorHint, scheduleInfo), 0);
750         cout << "i = " << i << endl;
751         i++;
752     }
753     EXPECT_EQ(g_service.DeleteExecutor(index), 0);
754 }
755 /**
756  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_8300
757  * @tc.name  : testUpdateIdentificationResult001
758  * @tc.desc  : Call the BeginIdentification function to start recognition,
759  *              and then call the UpdateIdenticationResult function to update the recognition result
760  */
HWTEST_F(UserIamUserAuthTestAdditional, testUpdateIdentificationResult001, Function | MediumTest | Level2)761 HWTEST_F(UserIamUserAuthTestAdditional, testUpdateIdentificationResult001, Function | MediumTest | Level2)
762 {
763     int size[2] = {0, 32};
764     uint32_t i = 0;
765     ExecutorRegisterInfo info = {};
766     uint64_t index = 0;
767     std::vector<uint8_t> publicKey;
768     std::vector<uint64_t> templateIds;
769     uint64_t contextId = 123456;
770     std::vector<uint8_t> scheduleResult;
771     std::vector<uint8_t> challenge;
772     uint32_t executorSensorHint = 0;
773     ScheduleInfo scheduleInfo = {};
774     AuthType authType = AuthType::FACE;
775     IdentifyResultInfo identityResultInfo = {};
776     const std::string deviceUdid = std::string(64, '0');
777 
778     for (i = 0; i < 2; i++) {
779         info.authType = AuthType::FACE;
780         info.executorRole = ExecutorRole::ALL_IN_ONE;
781         info.esl = ExecutorSecureLevel::ESL0;
782         info.publicKey.resize(32);
783         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
784         EXPECT_EQ(g_service.BeginIdentification(contextId, authType, challenge, executorSensorHint, scheduleInfo), 0);
785 
786         scheduleResult.resize(size[i]);
787         EXPECT_NE(g_service.UpdateIdentificationResult(contextId, scheduleResult, identityResultInfo), 0);
788         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
789         EXPECT_EQ(g_service.Init(deviceUdid), 0);
790     }
791 }
792 /**
793  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_8800
794  * @tc.name  : testCancelIdentification003
795  * @tc.desc  : Cancel by calling the CancelIdentification function directly
796  */
HWTEST_F(UserIamUserAuthTestAdditional, testCancelIdentification003, Function | MediumTest | Level2)797 HWTEST_F(UserIamUserAuthTestAdditional, testCancelIdentification003, Function | MediumTest | Level2)
798 {
799     uint64_t contextId = 1000;
800     EXPECT_NE(g_service.CancelIdentification(contextId), 0);
801 }
802 /**
803  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_8900
804  * @tc.name  : testCancelIdentification004
805  * @tc.desc  : Cancel by calling the CancelIdentification function directly
806  */
HWTEST_F(UserIamUserAuthTestAdditional, testCancelIdentification004, Function | MediumTest | Level2)807 HWTEST_F(UserIamUserAuthTestAdditional, testCancelIdentification004, Function | MediumTest | Level2)
808 {
809     uint64_t contextId = 123456;
810     AuthType authType = AuthType::FACE;
811     std::vector<uint8_t> challenge;
812     uint32_t executorSensorHint = 0;
813     ScheduleInfo scheduleInfo = {};
814     EXPECT_NE(g_service.BeginIdentification(contextId, authType, challenge, executorSensorHint, scheduleInfo), 0);
815     EXPECT_NE(g_service.CancelIdentification(contextId), 0);
816 }
817 /**
818  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_9000
819  * @tc.name  : testGetAvailableStatus001
820  * @tc.desc  : Directly call the GetAvailableStatus  function, with the first input parameter
821  *              being userId=1000 and the second input parameter being all authType
822  */
HWTEST_F(UserIamUserAuthTestAdditional, testGetAvailableStatus001, Function | MediumTest | Level2)823 HWTEST_F(UserIamUserAuthTestAdditional, testGetAvailableStatus001, Function | MediumTest | Level2)
824 {
825     uint32_t i = 0;
826     int32_t userId = 1000;
827     uint32_t authType[] = {0, 1, 2, 4};
828     uint32_t authTrustLevel = 0;
829     int32_t checkResult = 0;
830     for (i = 0; i < 4; i++) {
831         g_service.GetAvailableStatus(userId, static_cast<AuthType>(authType[i]), authTrustLevel,
832             checkResult);
833         EXPECT_NE(checkResult, 0);
834     }
835 }
836 /**
837  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_9400
838  * @tc.name  : testGetAvailableStatus005
839  * @tc.desc  : Call the BeginEnrollment function without calling the UpdateEnrollmentResult function to update and
840  *              enroll the result, and then call the GetAvailableStatus  function,
841  *              with the first entry being userId = 12345. The second entry is authType = PIN
842  */
HWTEST_F(UserIamUserAuthTestAdditional, testGetAvailableStatus005, Function | MediumTest | Level2)843 HWTEST_F(UserIamUserAuthTestAdditional, testGetAvailableStatus005, Function | MediumTest | Level2)
844 {
845     int32_t userId = 12345;
846     std::vector<uint8_t> challenge;
847     EXPECT_EQ(g_service.OpenSession(userId, challenge), 0);
848 
849     ExecutorRegisterInfo info = {};
850     info.authType = AuthType::PIN;
851     info.executorRole = ExecutorRole::ALL_IN_ONE;
852     info.esl = ExecutorSecureLevel::ESL0;
853     info.publicKey.resize(32);
854     uint64_t index = 0;
855     std::vector<uint8_t> publicKey;
856     std::vector<uint64_t> templateIds;
857     EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
858 
859     std::vector<uint8_t> authToken;
860     EnrollParam param = {};
861     param.userId = userId;
862     param.authType = AuthType::PIN;
863     ScheduleInfo scheduleInfo = {};
864     EXPECT_EQ(g_service.BeginEnrollment(authToken, param, scheduleInfo), 0);
865 
866     AuthType authType = AuthType::PIN;
867     uint32_t authTrustLevel = 0;
868     int32_t checkResult = 0;
869     g_service.GetAvailableStatus(userId, authType, authTrustLevel, checkResult);
870     EXPECT_NE(checkResult, 0);
871     EXPECT_EQ(g_service.CancelEnrollment(userId), 0);
872     EXPECT_EQ(g_service.DeleteExecutor(index), 0);
873     EXPECT_EQ(g_service.CloseSession(userId), 0);
874 }
875 /**
876  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_9500
877  * @tc.name  : testBeginEnrollmentV1_1_001
878  * @tc.desc  : Call the HDI-encapsulated BeginEnrollmentV1_1 function, and use a loop to assign the parameters
879  *              in the HdiBeginEnrollmentV1_1List struct to the BeginEnrollmentV1_1 function
880  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginEnrollmentV1_1_001, Function | MediumTest | Level2)881 HWTEST_F(UserIamUserAuthTestAdditional, testBeginEnrollmentV1_1_001, Function | MediumTest | Level2)
882 {
883     uint32_t i = 0;
884     HdiBeginEnrollmentList g_hdiBeginEnrollmentV1_1List;
885     uint32_t userId = g_hdiBeginEnrollmentV1_1List.userId[i];
886     std::vector<uint8_t> challenge;
887     EXPECT_EQ(g_service.OpenSession(userId, challenge), 0);
888 
889     ExecutorRegisterInfo info = {};
890     info.executorRole = ExecutorRole::ALL_IN_ONE;
891     info.esl = ExecutorSecureLevel::ESL0;
892     info.publicKey.resize(32);
893     uint64_t index = 0;
894     std::vector<uint8_t> publicKey;
895     std::vector<uint64_t> templateIds;
896 
897     std::vector<uint8_t> authToken;
898     EnrollParam param = {};
899     ScheduleInfo scheduleInfo = {};
900 
901     for (i = 0; i < 4; i++) {
902         info.authType = static_cast<AuthType>(g_hdiBeginEnrollmentV1_1List.authType[i]);
903         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
904 
905         param.authType = static_cast<AuthType>(g_hdiBeginEnrollmentV1_1List.authType[i]);
906         param.executorSensorHint = g_hdiBeginEnrollmentV1_1List.executorSensorHint[i];
907         param.userId = g_hdiBeginEnrollmentV1_1List.userId[i];
908         if (i == 0) {
909             EXPECT_EQ(g_service.BeginEnrollment(authToken, param, scheduleInfo), 0);
910         } else {
911             EXPECT_NE(g_service.BeginEnrollment(authToken, param, scheduleInfo), 0);
912         }
913 
914         EXPECT_EQ(g_service.CancelEnrollment(userId), 0);
915         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
916     }
917     EXPECT_EQ(g_service.CloseSession(userId), 0);
918 }
919 /**
920  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_0250
921  * @tc.name  : testBeginAuthenticationV1_1_001
922  * @tc.desc  : Call the HDI-encapsulated BeginAuthenticationV1_1 function, and use a loop to assign the parameters
923  *              in the HdiBeginAuthenticationV1_1List structure to the BeginAuthenticationV1_1 function
924  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginAuthenticationV1_1_001, Function | MediumTest | Level2)925 HWTEST_F(UserIamUserAuthTestAdditional, testBeginAuthenticationV1_1_001, Function | MediumTest | Level2)
926 {
927     uint32_t i = 0;
928     uint32_t j;
929     HdiBeginAuthenticationList g_hdiBeginAuthenticationV1_1List;
930     uint32_t userId = g_hdiBeginAuthenticationV1_1List.userId[i];
931     std::vector<uint8_t> challenge;
932     EXPECT_EQ(g_service.OpenSession(userId, challenge), 0);
933 
934     ExecutorRegisterInfo info = {};
935     info.esl = ExecutorSecureLevel::ESL0;
936     info.publicKey.resize(32);
937     std::vector<uint8_t> publicKey;
938     std::vector<uint64_t> templateIds;
939     uint64_t index = 0;
940 
941     uint64_t contextId = 1;
942     AuthParam authParam = {};
943     authParam.baseParam.authTrustLevel = 0;
944     authParam.baseParam.executorSensorHint = 0;
945     authParam.baseParam.challenge = challenge;
946     std::vector<ScheduleInfo> scheduleInfos;
947 
948     for (i = 0; i < 4; i++) {
949         info.authType = static_cast<AuthType>(g_hdiBeginAuthenticationV1_1List.authType[i]);
950         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
951         for (j = 4; j > 0; j--) {
952             authParam.baseParam.userId = g_hdiBeginAuthenticationV1_1List.userId[0];
953             authParam.authType = static_cast<AuthType>(g_hdiBeginAuthenticationV1_1List.authType[j - 1]);
954             EXPECT_NE(g_service.BeginAuthentication(contextId, authParam, scheduleInfos), 0);
955         }
956         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
957     }
958 
959     for (i = 1; i < 2; i++) {
960         info.authType = static_cast<AuthType>(g_hdiBeginAuthenticationV1_1List.authType[i]);
961         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
962 
963         authParam.baseParam.userId = g_hdiBeginAuthenticationV1_1List.userId[i];
964         authParam.authType = static_cast<AuthType>(g_hdiBeginAuthenticationV1_1List.authType[i]);
965         EXPECT_NE(g_service.BeginAuthentication(contextId, authParam, scheduleInfos), 0);
966     }
967     EXPECT_EQ(g_service.CloseSession(userId), 0);
968 }
969 /**
970  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_0550
971  * @tc.name  : testBeginIdentificationV1_1_001
972  * @tc.desc  : The AddExecutor function is called first to add the authentication actuator,
973  *              and then the BeginIdentificationV1_1 function is called to start the identification
974  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentificationV1_1_001, Function | MediumTest | Level2)975 HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentificationV1_1_001, Function | MediumTest | Level2)
976 {
977     uint32_t i = 0;
978     uint32_t j = 0;
979     HdiBeginIdentificationList g_hdiBeginIdentificationV1_1List;
980 
981     ExecutorRegisterInfo info = {};
982     info.authType = AuthType::FACE;
983     info.executorRole = ExecutorRole::ALL_IN_ONE;
984     info.esl = ExecutorSecureLevel::ESL0;
985     info.publicKey.resize(32);
986     uint64_t index = 0;
987     std::vector<uint8_t> publicKey;
988     std::vector<uint64_t> templateIds;
989 
990     uint64_t contextId = 123456;
991     AuthType authType = AuthType::FACE;
992     std::vector<uint8_t> challenge;
993     uint32_t executorSensorHint = 0;
994     ScheduleInfo scheduleInfo = {};
995 
996     for (i = 0; i < 2; i++) {
997         for (j = 0; j < 4; j++) {
998             authType = static_cast<AuthType>(g_hdiBeginIdentificationV1_1List.authType[j]);
999             if (i == 1 && authType == AuthType::FACE) {
1000                 EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
1001                 EXPECT_EQ(
1002                     g_service.BeginIdentification(contextId, authType, challenge, executorSensorHint, scheduleInfo),
1003                     0);
1004             } else {
1005                 EXPECT_NE(
1006                     g_service.BeginIdentification(contextId, authType, challenge, executorSensorHint, scheduleInfo),
1007                     0);
1008             }
1009         }
1010     }
1011 }
1012 /**
1013  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_0890
1014  * @tc.name  : testGetAllUserInfo001
1015  * @tc.desc  : Call the GetAllUserInfo function to get the information
1016  */
HWTEST_F(UserIamUserAuthTestAdditional, testGetAllUserInfo001, Function | MediumTest | Level1)1017 HWTEST_F(UserIamUserAuthTestAdditional, testGetAllUserInfo001, Function | MediumTest | Level1)
1018 {
1019     std::vector<UserInfo> userInfos;
1020     EXPECT_EQ(g_service.GetAllUserInfo(userInfos), 0);
1021 }
1022 /**
1023  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_0910
1024  * @tc.name  : testInit001
1025  * @tc.desc  : Call the Init function for initialization
1026  */
HWTEST_F(UserIamUserAuthTestAdditional, testInit001, Function | MediumTest | Level1)1027 HWTEST_F(UserIamUserAuthTestAdditional, testInit001, Function | MediumTest | Level1)
1028 {
1029     cout << "start Init" << endl;
1030     const std::string deviceUdid = std::string(64, '0');
1031     EXPECT_EQ(g_service.Init(deviceUdid), 0);
1032 }
1033 /**
1034  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_0920
1035  * @tc.name  : testBeginIdentification014
1036  * @tc.desc  : Verify that the function BeginIdentification returns a failure when the first entry structure of the
1037  *              function AddExecutor is ExecutorRegisterInfo->executorRole = COLLECTOR/VERIFIER/ALL_IN_ONE
1038  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification014, Function | MediumTest | Level2)1039 HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification014, Function | MediumTest | Level2)
1040 {
1041     uint32_t i = 0;
1042     uint64_t index = 0;
1043     std::vector<uint8_t> publicKey;
1044     std::vector<uint64_t> templateIds;
1045     uint32_t executorRole[3] = {1, 2, 3};
1046     ExecutorRegisterInfo info = {};
1047     uint64_t contextId = 123456;
1048     std::vector<uint8_t> challenge;
1049     uint32_t executorSensorHint = 0;
1050     ScheduleInfo scheduleInfo = {};
1051 
1052     for (i = 0; i < 3; i++) {
1053         info.authType = AuthType::FACE;
1054         info.executorRole = static_cast<ExecutorRole>(executorRole[i]);
1055         info.esl = ExecutorSecureLevel::ESL0;
1056         info.publicKey.resize(32);
1057         if (executorRole[i] == ExecutorRole::ALL_IN_ONE) {
1058             EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
1059             EXPECT_EQ(
1060                 g_service.BeginIdentification(contextId, AuthType::FACE, challenge, executorSensorHint, scheduleInfo),
1061                 0);
1062             EXPECT_EQ(g_service.DeleteExecutor(index), 0);
1063         } else {
1064             EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
1065             EXPECT_NE(
1066                 g_service.BeginIdentification(contextId, AuthType::FACE, challenge, executorSensorHint, scheduleInfo),
1067                 0);
1068             EXPECT_EQ(g_service.DeleteExecutor(index), 0);
1069         }
1070     }
1071 }
1072 /**
1073  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_0940
1074  * @tc.name  : testBeginIdentification016
1075  * @tc.desc  : Verify that the function BeginIdentification returns a success when the first entry structure of the
1076  *              function AddExecutor is ExecutorRegisterInfo->esl = ESL0\ESL1\ESL2\ESL3
1077  */
HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification016, Function | MediumTest | Level1)1078 HWTEST_F(UserIamUserAuthTestAdditional, testBeginIdentification016, Function | MediumTest | Level1)
1079 {
1080     uint32_t i = 0;
1081     uint64_t index = 0;
1082     std::vector<uint8_t> publicKey;
1083     std::vector<uint64_t> templateIds;
1084     uint32_t esl[4] = {0, 1, 2, 3};
1085     ExecutorRegisterInfo info = {};
1086     uint64_t contextId = 123456;
1087     std::vector<uint8_t> challenge;
1088     uint32_t executorSensorHint = 0;
1089     ScheduleInfo scheduleInfo = {};
1090     const std::string deviceUdid = std::string(64, '0');
1091 
1092     for (i = 0; i < 4; i++) {
1093         info.authType = AuthType::FACE;
1094         info.executorRole = ExecutorRole::ALL_IN_ONE;
1095         info.esl = static_cast<ExecutorSecureLevel>(esl[i]);
1096         info.publicKey.resize(32);
1097 
1098         EXPECT_EQ(g_service.AddExecutor(info, index, publicKey, templateIds), 0);
1099         EXPECT_EQ(g_service.BeginIdentification(contextId, AuthType::FACE, challenge, executorSensorHint, scheduleInfo),
1100                   0);
1101         EXPECT_EQ(g_service.DeleteExecutor(index), 0);
1102         EXPECT_EQ(g_service.Init(deviceUdid), 0);
1103     }
1104 }
1105 /**
1106  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_1110
1107  * @tc.name  : testGetValidSolution001
1108  * @tc.desc  : Call the GetValidSolution function to get the the authentication information
1109  */
HWTEST_F(UserIamUserAuthTestAdditional, testGetValidSolution001, Function | MediumTest | Level2)1110 HWTEST_F(UserIamUserAuthTestAdditional, testGetValidSolution001, Function | MediumTest | Level2)
1111 {
1112     int32_t userId = parcel.ReadInt32();
1113     std::vector<int32_t> authTypes = {AuthType::ALL, AuthType::PIN, AuthType::FACE, AuthType::FINGERPRINT};
1114     uint32_t authTrustLevel = 0;
1115     std::vector<int32_t> validTypes;
1116     EXPECT_NE(g_service.GetValidSolution(userId, authTypes, authTrustLevel, validTypes), 0);
1117 }
1118 /**
1119  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_1120
1120  * @tc.name  : testDeleteCredential001
1121  * @tc.desc  : Call the DeleteCredential function to deletes credential information
1122  */
HWTEST_F(UserIamUserAuthTestAdditional, testDeleteCredential001, Function | MediumTest | Level2)1123 HWTEST_F(UserIamUserAuthTestAdditional, testDeleteCredential001, Function | MediumTest | Level2)
1124 {
1125     int32_t userId = parcel.ReadInt32();
1126     uint64_t credentialId = parcel.ReadUint64();
1127     std::vector<uint8_t> authToken;
1128     CredentialInfo info;
1129     EXPECT_NE(g_service.DeleteCredential(userId, credentialId, authToken, info), 0);
1130 }
1131 /**
1132  * @tc.number: SUB_Security_IAM_UserAuth_HDI_FUNC_1130
1133  * @tc.name  : testUpdateEnrollmentResult001
1134  * @tc.desc  : Call the UpdateEnrollmentResult function directly to update and enroll the result
1135  */
HWTEST_F(UserIamUserAuthTestAdditional, testUpdateEnrollmentResult001, Function | MediumTest | Level2)1136 HWTEST_F(UserIamUserAuthTestAdditional, testUpdateEnrollmentResult001, Function | MediumTest | Level2)
1137 {
1138     int32_t userId = 12345;
1139     std::vector<uint8_t> challenge;
1140     EXPECT_EQ(g_service.OpenSession(userId, challenge), 0);
1141 
1142     std::vector<uint8_t> scheduleResult(1);
1143     scheduleResult[0] = 1;
1144     EnrollResultInfo enrolledResultInfo = {};
1145     EXPECT_NE(g_service.UpdateEnrollmentResult(userId, scheduleResult, enrolledResultInfo), 0);
1146 
1147     EXPECT_EQ(g_service.CloseSession(userId), 0);
1148 }