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 "pin_auth_hdi_test.h"
17 #include "iam_hat_test.h"
18 
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS::UserIam::Common;
22 using namespace OHOS::HDI::PinAuth;
23 using namespace OHOS::HDI::PinAuth::V2_0;
24 using Property = OHOS::HDI::PinAuth::V2_0::Property;
25 
26 static AllInOneImpl g_executorImpl(make_shared<OHOS::UserIam::PinAuth::PinAuth>());
27 static OHOS::Parcel parcel;
28 int32_t Expectedvalue = 0;
29 bool g_onResultFlag = false;
30 bool g_onGetDataFlag = false;
31 bool g_onGetDataV11Flag = false;
32 
SetUpTestCase()33 void UserIamPinAuthTestAdditional::SetUpTestCase() {}
34 
TearDownTestCase()35 void UserIamPinAuthTestAdditional::TearDownTestCase() {}
36 
SetUp()37 void UserIamPinAuthTestAdditional::SetUp() {}
38 
TearDown()39 void UserIamPinAuthTestAdditional::TearDown() {}
40 
41 class DummyIExecutorCallback : public IExecutorCallback {
42 public:
DummyIExecutorCallback(int32_t onResultResult, int32_t onGetDataResult, int32_t onGetDataV1Result, int32_t onTipResult, int32_t onMessageResult)43     DummyIExecutorCallback(int32_t onResultResult, int32_t onGetDataResult, int32_t onGetDataV1Result,
44         int32_t onTipResult, int32_t onMessageResult)
45         : onResultResult_(onResultResult), onGetDataResult_(onGetDataResult), onTipResult_(onTipResult),
46         onMessageResult_(onMessageResult)
47     {
48     }
49 
50     int32_t OnResult(int32_t result, const std::vector<uint8_t> &extraInfo) override
51     {
52         cout << "result is " << result << " extraInfo len is " << extraInfo.size() << endl;
53         g_onResultFlag = true;
54         return onResultResult_;
55     }
56 
57     int32_t OnGetData(const std::vector<uint8_t>& algoParameter, uint64_t authSubType, uint32_t algoVersion,
58          const std::vector<uint8_t>& challenge, const std::string &complexityReg) override
59     {
60         cout << "algoVersion is " << algoVersion << endl;
61         cout << " algoParameter len is " << algoParameter.size() << endl;
62         cout << " authSubType is " << authSubType << endl;
63         return onGetDataResult_;
64     }
65 
66     int32_t OnTip(int32_t tip, const std::vector<uint8_t>& extraInfo) override
67     {
68         return onTipResult_;
69     }
70 
71     int32_t OnMessage(int32_t destRole, const std::vector<uint8_t>& msg) override
72     {
73         return onMessageResult_;
74     }
75 
76 private:
77     int32_t onResultResult_;
78     int32_t onGetDataResult_;
79     int32_t onTipResult_;
80     int32_t onMessageResult_;
81 };
82 
FillTestIExecutorCallback(Parcel &parcel, sptr<IExecutorCallback> &callbackObj)83 static void FillTestIExecutorCallback(Parcel &parcel, sptr<IExecutorCallback> &callbackObj)
84 {
85     bool isNull = parcel.ReadBool();
86     if (isNull) {
87         callbackObj = nullptr;
88     } else {
89         callbackObj =
90             new (std::nothrow) DummyIExecutorCallback(parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadInt32(),
91                 parcel.ReadInt32(), parcel.ReadInt32());
92         if (callbackObj == nullptr) {
93             cout << "callbackObj construct fail" << endl;
94         }
95     }
96 }
97 
FillTestGetPropertyTypeVector(Parcel &parcel, std::vector<HdiGetPropertyType> &types)98 void FillTestGetPropertyTypeVector(Parcel &parcel, std::vector<HdiGetPropertyType> &types)
99 {
100     std::vector<uint32_t> propertyTypeUint32;
101     FillTestUint32Vector(parcel, propertyTypeUint32);
102     for (const auto &val : propertyTypeUint32) {
103         types.push_back(static_cast<HdiGetPropertyType>(val));
104     }
105 
106     cout << "success" << endl;
107 }
108 /**
109  * @tc.number  SUB_Security_Iam_PinAuth_HDI_GetExecutorInfo_0200
110  * @tc.name  testPinAuthTestGetExecutorInfo001
111  * @tc.desc  test GetExecutorInfo executorInfo not empty
112  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorInfo001, Function | MediumTest | Level2)113 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorInfo001, Function | MediumTest | Level2)
114 {
115     cout << "start test testPinAuthTestGetExecutorInfo001" << endl;
116     ExecutorInfo executorInfo;
117     int32_t ret = g_executorImpl.GetExecutorInfo(executorInfo);
118     cout << "ret is" << ret << endl;
119     EXPECT_NE(ret, 0);
120 }
121 /**
122  * @tc.number  SUB_Security_Iam_PinAuth_HDI_GetExecutorInfo_0300
123  * @tc.name  testPinAuthTestGetExecutorInfo002
124  * @tc.desc  test GetExecutorInfo 1000 times
125  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorInfo002, Function | MediumTest | Level2)126 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorInfo002, Function | MediumTest | Level2)
127 {
128     cout << "start test testPinAuthTestGetExecutorInfo002" << endl;
129     ExecutorInfo executorInfo;
130     int32_t ret = 0;
131     for (int32_t i = 0; i < 1000; i++) {
132         ret = g_executorImpl.GetExecutorInfo(executorInfo);
133         cout << "ret" << i << "is" << ret << endl;
134         EXPECT_NE(ret, 0);
135     }
136 }
137 
138 /**
139  * @tc.number  SUB_Security_Iam_PinAuth_HDI_OnRegisterFinish_0200
140  * @tc.name  testPinAuthTestOnRegisterFinish001
141  * @tc.desc  test OnRegisterFinish empty
142  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnRegisterFinish001, Function | MediumTest | Level1)143 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnRegisterFinish001, Function | MediumTest | Level1)
144 {
145     cout << "start test testPinAuthTestOnRegisterFinish001" << endl;
146     std::vector<uint64_t> templateIdList;
147     std::vector<uint8_t> frameworkPublicKey(32);
148     std::vector<uint8_t> extraInfo;
149     int32_t ret = g_executorImpl.OnRegisterFinish(templateIdList, frameworkPublicKey, extraInfo);
150     cout << "ret is" << ret << endl;
151     EXPECT_EQ(ret, 0);
152     FillTestUint64Vector(parcel, templateIdList);
153     ret = g_executorImpl.OnRegisterFinish(templateIdList, frameworkPublicKey, extraInfo);
154     cout << "ret is " << ret << endl;
155     EXPECT_EQ(ret, 0);
156     FillTestUint8Vector(parcel, frameworkPublicKey);
157     frameworkPublicKey.resize(32);
158     ret = g_executorImpl.OnRegisterFinish(templateIdList, frameworkPublicKey, extraInfo);
159     cout << "ret is " << ret << endl;
160     EXPECT_EQ(ret, 0);
161     FillTestUint8Vector(parcel, extraInfo);
162     frameworkPublicKey.resize(32);
163     ret = g_executorImpl.OnRegisterFinish(templateIdList, frameworkPublicKey, extraInfo);
164     cout << "ret is " << ret << endl;
165     EXPECT_EQ(ret, 0);
166 }
167 /**
168  * @tc.number  SUB_Security_Iam_PinAuth_HDI_OnRegisterFinish_0900
169  * @tc.name  testPinAuthTestOnRegisterFinish008
170  * @tc.desc  test OnRegisterFinish 1000 times
171  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnRegisterFinish008, Function | MediumTest | Level1)172 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnRegisterFinish008, Function | MediumTest | Level1)
173 {
174     cout << "start test testPinAuthTestOnRegisterFinish008" << endl;
175     std::vector<uint64_t> templateIdList;
176     FillTestUint64Vector(parcel, templateIdList);
177     std::vector<uint8_t> frameworkPublicKey;
178     FillTestUint8Vector(parcel, frameworkPublicKey);
179     frameworkPublicKey.resize(32);
180     std::vector<uint8_t> extraInfo;
181     FillTestUint8Vector(parcel, extraInfo);
182     int32_t ret = 0;
183     for (int32_t i = 0; i < 1000; i++) {
184         ret = g_executorImpl.OnRegisterFinish(templateIdList, frameworkPublicKey, extraInfo);
185         cout << "ret" << i << "is" << ret << endl;
186         EXPECT_EQ(ret, 0);
187     }
188 }
189 /**
190  * @tc.number  SUB_Security_Iam_PinAuth_HDI_OnSetData_0200
191  * @tc.name  testPinAuthTestOnSetData001
192  * @tc.desc  test OnSetData scheduleId
193  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData001, Function | MediumTest | Level2)194 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData001, Function | MediumTest | Level2)
195 {
196     cout << "start SetData" << endl;
197     uint64_t scheduleId = 0;
198     uint64_t authSubType = parcel.ReadUint64();
199     std::vector<uint8_t> data;
200     FillTestUint8Vector(parcel, data);
201     int32_t resultCode = 0;
202     int32_t ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
203     cout << "ret is" << ret << endl;
204     EXPECT_NE(ret, 0);
205     scheduleId = 0x7FFFFFFFFFFFFFFF;
206     ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
207     cout << "ret is" << ret << endl;
208     EXPECT_NE(ret, 0);
209     scheduleId = 0xFFFFFFFFFFFFFFFF;
210 
211     ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
212     cout << "ret is" << ret << endl;
213     EXPECT_NE(ret, 0);
214 }
215 /**
216  * @tc.number  SUB_Security_Iam_PinAuth_HDI_OnSetData_0500
217  * @tc.name  testPinAuthTestOnSetData004
218  * @tc.desc  test OnSetData authSubType
219  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData004, Function | MediumTest | Level2)220 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData004, Function | MediumTest | Level2)
221 {
222     cout << "start SetData" << endl;
223     uint64_t scheduleId = parcel.ReadUint64();
224     uint64_t authSubType = 0;
225     std::vector<uint8_t> data;
226     FillTestUint8Vector(parcel, data);
227     int32_t resultCode = 0;
228     int32_t ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
229     cout << "ret is" << ret << endl;
230     EXPECT_NE(ret, 0);
231     authSubType = 0x7FFFFFFFFFFFFFFF;
232     ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
233     cout << "ret is" << ret << endl;
234     EXPECT_NE(ret, 0);
235     authSubType = 0xFFFFFFFFFFFFFFFF;
236     ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
237     cout << "ret is" << ret << endl;
238     EXPECT_NE(ret, 0);
239 }
240 /**
241  * @tc.number  SUB_Security_Iam_PinAuth_HDI_OnSetData_0800
242  * @tc.name  testPinAuthTestOnSetData007
243  * @tc.desc  test OnSetData data
244  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData007, Function | MediumTest | Level2)245 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData007, Function | MediumTest | Level2)
246 {
247     cout << "start SetData" << endl;
248     uint64_t scheduleId = parcel.ReadUint64();
249     uint64_t authSubType = parcel.ReadUint64();
250     std::vector<uint8_t> data;
251     int32_t resultCode = 0;
252     int32_t ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
253     cout << "ret is" << ret << endl;
254     EXPECT_NE(ret, 0);
255     for (int32_t i = 0; i < 1000; i++) {
256         data.push_back(i);
257     }
258     ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
259     cout << "ret is" << ret << endl;
260     EXPECT_NE(ret, 0);
261 }
262 /**
263  * @tc.number  SUB_Security_Iam_PinAuth_HDI_OnSetData_1000
264  * @tc.name  testPinAuthTestOnSetData009
265  * @tc.desc  test OnSetData 1000 times
266  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData009, Function | MediumTest | Level2)267 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData009, Function | MediumTest | Level2)
268 {
269     cout << "start SetData" << endl;
270     uint64_t scheduleId = parcel.ReadUint64();
271     uint64_t authSubType = parcel.ReadUint64();
272     std::vector<uint8_t> data;
273     FillTestUint8Vector(parcel, data);
274     int32_t ret = 0;
275     for (int32_t i = 0; i < 1000; i++) {
276         int32_t resultCode = 0;
277         ret = g_executorImpl.SetData(scheduleId, authSubType, data, resultCode);
278         cout << "ret is" << ret << endl;
279         EXPECT_NE(ret, 0);
280     }
281 }
282 
283 /**
284  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Enroll_0200
285  * @tc.name  testPinAuthTestEnroll001
286  * @tc.desc  test Enroll scheduleId
287  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll001, Function | MediumTest | Level1)288 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll001, Function | MediumTest | Level1)
289 {
290     cout << "start test testPinAuthTestEnroll001" << endl;
291     uint64_t scheduleId = 0;
292     std::vector<uint8_t> extraInfo;
293     FillTestUint8Vector(parcel, extraInfo);
294     sptr<IExecutorCallback> callbackObj;
295     FillTestIExecutorCallback(parcel, callbackObj);
296     int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
297     cout << "ret is" << ret << endl;
298     EXPECT_EQ(ret, 0);
299     scheduleId = 0x7FFFFFFFFFFFFFFF;
300     ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
301     cout << "ret is " << ret << endl;
302     EXPECT_EQ(ret, 0);
303     scheduleId = 0xFFFFFFFFFFFFFFFF;
304     ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
305     cout << "ret is " << ret << endl;
306     EXPECT_EQ(ret, 0);
307 }
308 /**
309  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Enroll_0500
310  * @tc.name  testPinAuthTestEnroll004
311  * @tc.desc  test Enroll extraInfo empty
312  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll004, Function | MediumTest | Level1)313 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll004, Function | MediumTest | Level1)
314 {
315     cout << "start test testPinAuthTestEnroll004" << endl;
316     uint64_t scheduleId = 0x7FFFFFFFFFFFFFFF;
317     std::vector<uint8_t> extraInfo;
318     sptr<IExecutorCallback> callbackObj;
319     FillTestIExecutorCallback(parcel, callbackObj);
320     int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
321     cout << "ret is" << ret << endl;
322     EXPECT_EQ(ret, 0);
323     ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
324     cout << "ret is " << ret << endl;
325     EXPECT_NE(ret, 0);
326     FillTestUint8Vector(parcel, extraInfo);
327     ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
328     cout << "ret is " << ret << endl;
329     EXPECT_NE(ret, 0);
330 }
331 /**
332  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Enroll_0800
333  * @tc.name  testPinAuthTestEnroll007
334  * @tc.desc  test Enroll 1000 times
335  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll007, Function | MediumTest | Level1)336 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll007, Function | MediumTest | Level1)
337 {
338     cout << "start test testPinAuthTestEnroll007" << endl;
339     uint64_t scheduleId = 0x7FFFFFFFFFFFFFFF;
340     std::vector<uint8_t> extraInfo;
341     FillTestUint8Vector(parcel, extraInfo);
342     sptr<IExecutorCallback> callbackObj;
343     FillTestIExecutorCallback(parcel, callbackObj);
344     int32_t ret = 0;
345     for (int32_t i = 0; i < 1000; i++) {
346         ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
347         cout << "ret" << i << "is" << ret << endl;
348         EXPECT_EQ(ret, 0);
349     }
350 }
351 /**
352  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Authenticate_0200
353  * @tc.name  testPinAuthTestAuthenticate001
354  * @tc.desc  test Authenticate scheduleId
355  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate001, Function | MediumTest | Level1)356 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate001, Function | MediumTest | Level1)
357 {
358     cout << "start testPinAuthTestAuthenticate001" << endl;
359     uint64_t scheduleId = 0;
360     uint64_t templateId = parcel.ReadUint64();
361     std::vector<uint64_t> templateIdList;
362     templateIdList.push_back(templateId);
363     std::vector<uint8_t> extraInfo;
364     FillTestUint8Vector(parcel, extraInfo);
365     sptr<IExecutorCallback> callbackObj;
366     FillTestIExecutorCallback(parcel, callbackObj);
367     int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
368     cout << "ret is" << ret << endl;
369     EXPECT_EQ(ret, 0);
370     scheduleId = 0xFFFFFFFFFFFFFFFF;
371     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
372     cout << "ret is " << ret << endl;
373     EXPECT_EQ(ret, 0);
374     scheduleId = 0x7FFFFFFFFFFFFFFF;
375     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
376     cout << "ret is " << ret << endl;
377     EXPECT_EQ(ret, 0);
378 }
379 /**
380  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Authenticate_0500
381  * @tc.name  testPinAuthTestAuthenticate004
382  * @tc.desc  test Authenticate templateId
383  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate004, Function | MediumTest | Level1)384 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate004, Function | MediumTest | Level1)
385 {
386     cout << "start testPinAuthTestAuthenticate004" << endl;
387     uint64_t scheduleId = parcel.ReadUint64();
388     uint64_t templateId = parcel.ReadUint64();
389     std::vector<uint64_t> templateIdList;
390     templateIdList.push_back(templateId);
391     std::vector<uint8_t> extraInfo;
392     FillTestUint8Vector(parcel, extraInfo);
393     sptr<IExecutorCallback> callbackObj;
394     FillTestIExecutorCallback(parcel, callbackObj);
395     int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
396     cout << "ret is" << ret << endl;
397     EXPECT_EQ(ret, 0);
398     templateIdList.resize(0);
399     templateIdList.push_back(0xFFFFFFFFFFFFFFFF);
400     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
401     cout << "ret is" << ret << endl;
402     EXPECT_EQ(ret, 0);
403     templateIdList.resize(0);
404     templateIdList.push_back(0x7FFFFFFFFFFFFFFF);
405     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
406     cout << "ret is" << ret << endl;
407     EXPECT_EQ(ret, 0);
408 }
409 /**
410  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Authenticate_0800
411  * @tc.name  testPinAuthTestAuthenticate007
412  * @tc.desc  test Authenticate empty
413  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate007, Function | MediumTest | Level1)414 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate007, Function | MediumTest | Level1)
415 {
416     cout << "start testPinAuthTestAuthenticate007" << endl;
417     uint64_t scheduleId = parcel.ReadUint64();
418     uint64_t templateId = parcel.ReadUint64();
419     std::vector<uint64_t> templateIdList;
420     templateIdList.push_back(templateId);
421     std::vector<uint8_t> extraInfo;
422     sptr<IExecutorCallback> callbackObj;
423     FillTestIExecutorCallback(parcel, callbackObj);
424     int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
425     cout << "ret is" << ret << endl;
426     EXPECT_EQ(ret, 0);
427     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
428     cout << "ret is" << ret << endl;
429     EXPECT_NE(ret, 0);
430     FillTestUint8Vector(parcel, extraInfo);
431     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
432     cout << "ret is" << ret << endl;
433     EXPECT_EQ(ret, 0);
434     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
435     cout << "ret is" << ret << endl;
436     EXPECT_NE(ret, 0);
437 }
438 /**
439  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Authenticate_1100
440  * @tc.name  testPinAuthTestAuthenticate010
441  * @tc.desc  test Authenticate 1000 times
442  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate010, Function | MediumTest | Level1)443 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate010, Function | MediumTest | Level1)
444 {
445     cout << "start testPinAuthTestAuthenticate010" << endl;
446     uint64_t scheduleId = parcel.ReadUint64();
447     uint64_t templateId = parcel.ReadUint64();
448     std::vector<uint64_t> templateIdList;
449     templateIdList.push_back(templateId);
450     std::vector<uint8_t> extraInfo;
451     FillTestUint8Vector(parcel, extraInfo);
452     sptr<IExecutorCallback> callbackObj;
453     FillTestIExecutorCallback(parcel, callbackObj);
454     int32_t ret = 0;
455     for (int32_t i = 0; i < 1000; i++) {
456         ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
457         cout << "ret is" << ret << endl;
458         EXPECT_EQ(ret, 0);
459     }
460 }
461 /**
462  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Delete_0200
463  * @tc.name  testPinAuthTestDelete001
464  * @tc.desc  test Delete templateId 0
465  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestDelete001, Function | MediumTest | Level2)466 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestDelete001, Function | MediumTest | Level2)
467 {
468     cout << "start Delete" << endl;
469     uint64_t templateId = 0;
470     int32_t ret = g_executorImpl.Delete(templateId);
471     cout << "ret is " << ret << endl;
472     EXPECT_NE(ret, 0);
473     templateId = 0x7FFFFFFFFFFFFFFF;
474     ret = g_executorImpl.Delete(templateId);
475     cout << "ret is " << ret << endl;
476     EXPECT_NE(ret, 0);
477     templateId = 0xFFFFFFFFFFFFFFFF;
478     ret = g_executorImpl.Delete(templateId);
479     cout << "ret is " << ret << endl;
480     EXPECT_NE(ret, 0);
481     templateId = 0;
482     for (int32_t i = 0; i < 1000; i++) {
483         ret = g_executorImpl.Delete(templateId);
484         cout << "ret is " << ret << endl;
485         EXPECT_NE(ret, 0);
486     }
487 }
488 /**
489  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Cancel_0200
490  * @tc.name  testPinAuthTestCancel001
491  * @tc.desc  test Cancel scheduleId
492  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestCancel001, Function | MediumTest | Level1)493 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestCancel001, Function | MediumTest | Level1)
494 {
495     cout << "start Cancel" << endl;
496     uint64_t scheduleId = 0;
497     int32_t ret = g_executorImpl.Cancel(scheduleId);
498     cout << "ret is " << ret << endl;
499     EXPECT_EQ(ret, 0);
500     scheduleId = 0x7FFFFFFFFFFFFFFF;
501     ret = g_executorImpl.Cancel(scheduleId);
502     cout << "ret is " << ret << endl;
503     EXPECT_EQ(ret, 0);
504     scheduleId = 0xFFFFFFFFFFFFFFFF;
505     ret = g_executorImpl.Cancel(scheduleId);
506     cout << "ret is " << ret << endl;
507     EXPECT_EQ(ret, 0);
508 }
509 /**
510  * @tc.number  SUB_Security_Iam_PinAuth_HDI_Cancel_0500
511  * @tc.name  testPinAuthTestCancel004
512  * @tc.desc  test Cancel 1000 times
513  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestCancel004, Function | MediumTest | Level1)514 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestCancel004, Function | MediumTest | Level1)
515 {
516     cout << "start Cancel" << endl;
517     uint64_t scheduleId = parcel.ReadUint64();
518     std::vector<uint8_t> extraInfo;
519     FillTestUint8Vector(parcel, extraInfo);
520     sptr<IExecutorCallback> callbackObj;
521     FillTestIExecutorCallback(parcel, callbackObj);
522 
523     int32_t ret = 0;
524     for (int32_t i = 0; i < 1000; i++) {
525         ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
526         ret = g_executorImpl.Cancel(scheduleId);
527         cout << "ret is " << ret << endl;
528         EXPECT_EQ(ret, 0);
529     }
530 }
531 
532 /**
533  * @tc.number  SUB_Security_Iam_PinAuth_HDI_GetProperty_0200
534  * @tc.name  testPinAuthTestGetProperty001
535  * @tc.desc  test GetProperty
536  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetProperty001, Function | MediumTest | Level2)537 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetProperty001, Function | MediumTest | Level2)
538 {
539     cout << "start GetProperty" << endl;
540     std::vector<uint64_t> templateIdList;
541     std::vector<int32_t> propertyTypes;
542     Property property;
543     int32_t ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
544     cout << "ret is " << ret << endl;
545     EXPECT_NE(ret, 0);
546     FillTestUint64Vector(parcel, templateIdList);
547     ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
548     cout << "ret is " << ret << endl;
549     EXPECT_NE(ret, 0);
550     propertyTypes.push_back(OHOS::HDI::PinAuth::V2_0::AUTH_SUB_TYPE);
551     propertyTypes.push_back(OHOS::HDI::PinAuth::V2_0::LOCKOUT_DURATION);
552     propertyTypes.push_back(OHOS::HDI::PinAuth::V2_0::REMAIN_ATTEMPTS);
553     ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
554     cout << "ret is " << ret << endl;
555     EXPECT_NE(ret, 0);
556 }
557 /**
558  * @tc.number  SUB_Security_Iam_PinAuth_HDI_GetProperty_0700
559  * @tc.name  testPinAuthTestGetProperty006
560  * @tc.desc  test GetProperty 1000 times
561  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetProperty006, Function | MediumTest | Level2)562 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetProperty006, Function | MediumTest | Level2)
563 {
564     cout << "start GetProperty" << endl;
565     std::vector<uint64_t> templateIdList;
566     FillTestUint64Vector(parcel, templateIdList);
567     std::vector<int32_t> propertyTypes;
568     propertyTypes.push_back(OHOS::HDI::PinAuth::V2_0::AUTH_SUB_TYPE);
569     Property property;
570 
571     int32_t ret = 0;
572     for (int32_t i = 0; i < 1000; i++) {
573         ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
574 
575         cout << "ret is " << ret << endl;
576         EXPECT_NE(ret, 0);
577     }
578 }
579 /**
580  * @tc.number  SUB_Security_Iam_PinAuth_HDI_EnrollV1_1_0100
581  * @tc.name  testPinAuthTestEnrollV1_1001
582  * @tc.desc  test EnrollV1_1 scheduleId
583  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_001, Function | MediumTest | Level1)584 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_001, Function | MediumTest | Level1)
585 {
586     cout << "start test EnrollV1_1" << endl;
587     uint64_t scheduleId = 0;
588     std::vector<uint8_t> extraInfo;
589     FillTestUint8Vector(parcel, extraInfo);
590     sptr<IExecutorCallback> callbackObj;
591     FillTestIExecutorCallback(parcel, callbackObj);
592     int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
593     cout << "ret is" << ret << endl;
594     EXPECT_EQ(ret, 0);
595     scheduleId = 0x7FFFFFFFFFFFFFFF;
596     ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
597     cout << "ret is" << ret << endl;
598     EXPECT_EQ(ret, 0);
599     scheduleId = 0xFFFFFFFFFFFFFFFF;
600     ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
601     cout << "ret is" << ret << endl;
602     EXPECT_EQ(ret, 0);
603 }
604 /**
605  * @tc.number  SUB_Security_Iam_PinAuth_HDI_EnrollV1_1_0400
606  * @tc.name  testPinAuthTestEnrollV1_1004
607  * @tc.desc  test EnrollV1_1 empty
608  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_004, Function | MediumTest | Level1)609 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_004, Function | MediumTest | Level1)
610 {
611     cout << "start test EnrollV1_1" << endl;
612     uint64_t scheduleId = 0;
613     std::vector<uint8_t> extraInfo;
614     sptr<IExecutorCallback> callbackObj;
615     FillTestIExecutorCallback(parcel, callbackObj);
616     int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
617     cout << "ret is" << ret << endl;
618     EXPECT_EQ(ret, 0);
619     ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
620     cout << "ret is" << ret << endl;
621     EXPECT_NE(ret, 0);
622     FillTestUint8Vector(parcel, extraInfo);
623     ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
624     cout << "ret is" << ret << endl;
625     EXPECT_EQ(ret, 0);
626     ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
627     cout << "ret is" << ret << endl;
628     EXPECT_NE(ret, 0);
629 }
630 /**
631  * @tc.number  SUB_Security_Iam_PinAuth_HDI_EnrollV1_1_0700
632  * @tc.name  testPinAuthTestEnrollV1_1007
633  * @tc.desc  test EnrollV1_1 1000 times
634  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_007, Function | MediumTest | Level1)635 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_007, Function | MediumTest | Level1)
636 {
637     cout << "start test EnrollV1_1" << endl;
638     uint64_t scheduleId = 0;
639     std::vector<uint8_t> extraInfo;
640     FillTestUint8Vector(parcel, extraInfo);
641     sptr<IExecutorCallback> callbackObj;
642     FillTestIExecutorCallback(parcel, callbackObj);
643     int32_t ret = 0;
644     for (int32_t i = 0; i < 1000; i++) {
645         ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
646         cout << "ret is" << ret << endl;
647         EXPECT_EQ(ret, 0);
648     }
649 }
650 /**
651  * @tc.number  SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_0100
652  * @tc.name  testPinAuthTestAuthenticateV1_1001
653  * @tc.desc  test AuthenticateV1_1 scheduleId 0
654  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_001, Function | MediumTest | Level2)655 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_001, Function | MediumTest | Level2)
656 {
657     cout << "start AuthenticateV1_1" << endl;
658 
659     uint64_t scheduleId = 0;
660     uint64_t templateId = parcel.ReadUint64();
661     std::vector<uint64_t> templateIdList;
662     templateIdList.push_back(templateId);
663     std::vector<uint8_t> extraInfo;
664     FillTestUint8Vector(parcel, extraInfo);
665     sptr<IExecutorCallback> callbackObj;
666     FillTestIExecutorCallback(parcel, callbackObj);
667     int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
668     cout << "ret is " << ret << endl;
669     EXPECT_EQ(ret, 0);
670     scheduleId = 0xFFFFFFFFFFFFFFFF;
671     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
672     cout << "ret is " << ret << endl;
673     EXPECT_EQ(ret, 0);
674     scheduleId = 0x7FFFFFFFFFFFFFFF;
675     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
676     cout << "ret is " << ret << endl;
677     EXPECT_EQ(ret, 0);
678 }
679 /**
680  * @tc.number  SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_0400
681  * @tc.name  testPinAuthTestAuthenticateV1_1004
682  * @tc.desc  test AuthenticateV1_1 templateId 0
683  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_004, Function | MediumTest | Level2)684 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_004, Function | MediumTest | Level2)
685 {
686     cout << "start AuthenticateV1_1" << endl;
687 
688     uint64_t scheduleId = parcel.ReadUint64();
689     uint64_t templateId = parcel.ReadUint64();
690     std::vector<uint64_t> templateIdList;
691     templateIdList.push_back(templateId);
692     std::vector<uint8_t> extraInfo;
693     FillTestUint8Vector(parcel, extraInfo);
694     sptr<IExecutorCallback> callbackObj;
695     FillTestIExecutorCallback(parcel, callbackObj);
696     int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
697     cout << "ret is " << ret << endl;
698     EXPECT_EQ(ret, 0);
699     templateIdList.resize(0);
700     templateIdList.push_back(0xFFFFFFFFFFFFFFFF);
701     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
702     cout << "ret is " << ret << endl;
703     EXPECT_EQ(ret, 0);
704     templateIdList.resize(0);
705     templateIdList.push_back(0x7FFFFFFFFFFFFFFF);
706     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
707     cout << "ret is " << ret << endl;
708     EXPECT_EQ(ret, 0);
709 }
710 /**
711  * @tc.number  SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_0700
712  * @tc.name  testPinAuthTestAuthenticateV1_1007
713  * @tc.desc  test AuthenticateV1_1 extraInfo empty
714  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_007, Function | MediumTest | Level2)715 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_007, Function | MediumTest | Level2)
716 {
717     cout << "start AuthenticateV1_1" << endl;
718 
719     uint64_t scheduleId = parcel.ReadUint64();
720     uint64_t templateId = parcel.ReadUint64();
721     std::vector<uint64_t> templateIdList;
722     templateIdList.push_back(templateId);
723     std::vector<uint8_t> extraInfo;
724     sptr<IExecutorCallback> callbackObj;
725     FillTestIExecutorCallback(parcel, callbackObj);
726     int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
727     cout << "ret is " << ret << endl;
728     EXPECT_EQ(ret, 0);
729     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
730     cout << "ret is " << ret << endl;
731     EXPECT_NE(ret, 0);
732     FillTestUint8Vector(parcel, extraInfo);
733     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
734     cout << "ret is " << ret << endl;
735     EXPECT_EQ(ret, 0);
736     ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
737     cout << "ret is " << ret << endl;
738     EXPECT_NE(ret, 0);
739 }
740 /**
741  * @tc.number  SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_1000
742  * @tc.name  testPinAuthTestAuthenticateV1_1010
743  * @tc.desc  test AuthenticateV1_1 1000 times
744  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_010, Function | MediumTest | Level2)745 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_010, Function | MediumTest | Level2)
746 {
747     cout << "start AuthenticateV1_1" << endl;
748 
749     uint64_t scheduleId = parcel.ReadUint64();
750     uint64_t templateId = parcel.ReadUint64();
751     std::vector<uint64_t> templateIdList;
752     templateIdList.push_back(templateId);
753     std::vector<uint8_t> extraInfo;
754     FillTestUint8Vector(parcel, extraInfo);
755     sptr<IExecutorCallback> callbackObj;
756     FillTestIExecutorCallback(parcel, callbackObj);
757     int32_t ret = 0;
758     for (int32_t i = 0; i < 1000; i++) {
759         ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
760 
761         cout << "ret is " << ret << endl;
762         EXPECT_EQ(ret, 0);
763     }
764 }
765 /**
766  * @tc.number  SUB_Security_Iam_PinAuth_HDI_GetExecutorList_0200
767  * @tc.name  testPinAuthTestGetExecutorList001
768  * @tc.desc  test GetExecutorList 1000 times
769  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorList001, Function | MediumTest | Level1)770 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorList001, Function | MediumTest | Level1)
771 {
772     cout << "start GetExecutorList" << endl;
773     PinAuthInterfaceService g_pinAuthInterFaceService;
774     std::vector<sptr<IAllInOneExecutor>> allInOneExecutors;
775     std::vector<sptr<IVerifier>> verifiers;
776     std::vector<sptr<ICollector>> collectors;
777     int32_t ret = 0;
778     for (int32_t i = 0; i < 1000; i++) {
779         ret = g_pinAuthInterFaceService.GetExecutorList(allInOneExecutors, verifiers, collectors);
780         cout << "ret is " << ret << endl;
781         EXPECT_EQ(ret, 0);
782     }
783 }
784 /**
785  * @tc.number  SUB_Security_Iam_PinAuth_HDI_GetExecutorListV1_1_0200
786  * @tc.name  testPinAuthTestGetExecutorListV1_1001
787  * @tc.desc  test GetExecutorListV1_1 1000 times
788  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorList_001, Function | MediumTest | Level1)789 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorList_001, Function | MediumTest | Level1)
790 {
791     cout << "start GetExecutorList" << endl;
792     std::vector<sptr<IAllInOneExecutor>> allInOneExecutors;
793     std::vector<sptr<IVerifier>> verifiers;
794     std::vector<sptr<ICollector>> collectors;
795     PinAuthInterfaceService pin_Interface;
796 
797     int32_t ret = 0;
798     for (int32_t i = 0; i < 1000; i++) {
799         ret = pin_Interface.GetExecutorList(allInOneExecutors, verifiers, collectors);
800 
801         cout << "ret is " << ret << endl;
802         EXPECT_EQ(ret, 0);
803     }
804 }
805 
806 /**
807  * @tc.number  SUB_Security_Iam_PinAuth_HDI_OnGetData_0100
808  * @tc.name  testPinAuthTestOnGetData001
809  * @tc.desc  test OnGetData
810  */
HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnGetData_001, Function | MediumTest | Level1)811 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnGetData_001, Function | MediumTest | Level1)
812 {
813     cout << "start Authenticate" << endl;
814     uint64_t scheduleId = parcel.ReadUint64();
815     uint64_t templateId = parcel.ReadUint64();
816     std::vector<uint64_t> templateIdList;
817     templateIdList.push_back(templateId);
818     std::vector<uint8_t> extraInfo;
819     FillTestUint8Vector(parcel, extraInfo);
820     sptr<IExecutorCallback> callbackObj;
821     FillTestIExecutorCallback(parcel, callbackObj);
822     int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
823     cout << "ret is " << ret << endl;
824     EXPECT_EQ(g_onGetDataFlag, false);
825 }
826