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::V3_0;
24 using Property = OHOS::HDI::PinAuth::V3_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
OnResult(int32_t result,const std::vector<uint8_t> & extraInfo)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
OnGetData(const std::vector<uint8_t> & algoParameter,uint64_t authSubType,uint32_t algoVersion,const std::vector<uint8_t> & challenge,const std::string & complexityReg)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
OnTip(int32_t tip,const std::vector<uint8_t> & extraInfo)66 int32_t OnTip(int32_t tip, const std::vector<uint8_t>& extraInfo) override
67 {
68 return onTipResult_;
69 }
70
OnMessage(int32_t destRole,const std::vector<uint8_t> & msg)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 */
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 */
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 */
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 */
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 */
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 uint32_t pinLength = parcel.ReadUint32();;
202 int32_t resultCode = 0;
203 int32_t ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
204 cout << "ret is" << ret << endl;
205 EXPECT_NE(ret, 0);
206 scheduleId = 0x7FFFFFFFFFFFFFFF;
207 ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
208 cout << "ret is" << ret << endl;
209 EXPECT_NE(ret, 0);
210 scheduleId = 0xFFFFFFFFFFFFFFFF;
211
212 ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
213 cout << "ret is" << ret << endl;
214 EXPECT_NE(ret, 0);
215 }
216 /**
217 * @tc.number SUB_Security_Iam_PinAuth_HDI_OnSetData_0500
218 * @tc.name testPinAuthTestOnSetData004
219 * @tc.desc test OnSetData authSubType
220 */
221 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData004, Function | MediumTest | Level2)
222 {
223 cout << "start SetData" << endl;
224 uint64_t scheduleId = parcel.ReadUint64();
225 uint64_t authSubType = 0;
226 std::vector<uint8_t> data;
227 FillTestUint8Vector(parcel, data);
228 uint32_t pinLength = parcel.ReadUint32();;
229 int32_t resultCode = 0;
230 int32_t ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
231 cout << "ret is" << ret << endl;
232 EXPECT_NE(ret, 0);
233 authSubType = 0x7FFFFFFFFFFFFFFF;
234 ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
235 cout << "ret is" << ret << endl;
236 EXPECT_NE(ret, 0);
237 authSubType = 0xFFFFFFFFFFFFFFFF;
238 ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
239 cout << "ret is" << ret << endl;
240 EXPECT_NE(ret, 0);
241 }
242 /**
243 * @tc.number SUB_Security_Iam_PinAuth_HDI_OnSetData_0800
244 * @tc.name testPinAuthTestOnSetData007
245 * @tc.desc test OnSetData data
246 */
247 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData007, Function | MediumTest | Level2)
248 {
249 cout << "start SetData" << endl;
250 uint64_t scheduleId = parcel.ReadUint64();
251 uint64_t authSubType = parcel.ReadUint64();
252 std::vector<uint8_t> data;
253 uint32_t pinLength = parcel.ReadUint32();;
254 int32_t resultCode = 0;
255 int32_t ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
256 cout << "ret is" << ret << endl;
257 EXPECT_NE(ret, 0);
258 for (int32_t i = 0; i < 1000; i++) {
259 data.push_back(i);
260 }
261 ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
262 cout << "ret is" << ret << endl;
263 EXPECT_NE(ret, 0);
264 }
265 /**
266 * @tc.number SUB_Security_Iam_PinAuth_HDI_OnSetData_1000
267 * @tc.name testPinAuthTestOnSetData009
268 * @tc.desc test OnSetData 1000 times
269 */
270 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnSetData009, Function | MediumTest | Level2)
271 {
272 cout << "start SetData" << endl;
273 uint64_t scheduleId = parcel.ReadUint64();
274 uint64_t authSubType = parcel.ReadUint64();
275 std::vector<uint8_t> data;
276 uint32_t pinLength = parcel.ReadUint32();
277 FillTestUint8Vector(parcel, data);
278 int32_t ret = 0;
279 for (int32_t i = 0; i < 1000; i++) {
280 int32_t resultCode = 0;
281 ret = g_executorImpl.SetData(scheduleId, authSubType, data, pinLength, resultCode);
282 cout << "ret is" << ret << endl;
283 EXPECT_NE(ret, 0);
284 }
285 }
286
287 /**
288 * @tc.number SUB_Security_Iam_PinAuth_HDI_Enroll_0200
289 * @tc.name testPinAuthTestEnroll001
290 * @tc.desc test Enroll scheduleId
291 */
292 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll001, Function | MediumTest | Level1)
293 {
294 cout << "start test testPinAuthTestEnroll001" << endl;
295 uint64_t scheduleId = 0;
296 std::vector<uint8_t> extraInfo;
297 FillTestUint8Vector(parcel, extraInfo);
298 sptr<IExecutorCallback> callbackObj;
299 FillTestIExecutorCallback(parcel, callbackObj);
300 int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
301 cout << "ret is" << ret << endl;
302 EXPECT_EQ(ret, 0);
303 scheduleId = 0x7FFFFFFFFFFFFFFF;
304 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
305 cout << "ret is " << ret << endl;
306 EXPECT_EQ(ret, 0);
307 scheduleId = 0xFFFFFFFFFFFFFFFF;
308 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
309 cout << "ret is " << ret << endl;
310 EXPECT_EQ(ret, 0);
311 }
312 /**
313 * @tc.number SUB_Security_Iam_PinAuth_HDI_Enroll_0500
314 * @tc.name testPinAuthTestEnroll004
315 * @tc.desc test Enroll extraInfo empty
316 */
317 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll004, Function | MediumTest | Level1)
318 {
319 cout << "start test testPinAuthTestEnroll004" << endl;
320 uint64_t scheduleId = 0x7FFFFFFFFFFFFFFF;
321 std::vector<uint8_t> extraInfo;
322 sptr<IExecutorCallback> callbackObj;
323 FillTestIExecutorCallback(parcel, callbackObj);
324 int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
325 cout << "ret is" << ret << endl;
326 EXPECT_EQ(ret, 0);
327 ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
328 cout << "ret is " << ret << endl;
329 EXPECT_NE(ret, 0);
330 FillTestUint8Vector(parcel, extraInfo);
331 ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
332 cout << "ret is " << ret << endl;
333 EXPECT_NE(ret, 0);
334 }
335 /**
336 * @tc.number SUB_Security_Iam_PinAuth_HDI_Enroll_0800
337 * @tc.name testPinAuthTestEnroll007
338 * @tc.desc test Enroll 1000 times
339 */
340 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll007, Function | MediumTest | Level1)
341 {
342 cout << "start test testPinAuthTestEnroll007" << endl;
343 uint64_t scheduleId = 0x7FFFFFFFFFFFFFFF;
344 std::vector<uint8_t> extraInfo;
345 FillTestUint8Vector(parcel, extraInfo);
346 sptr<IExecutorCallback> callbackObj;
347 FillTestIExecutorCallback(parcel, callbackObj);
348 int32_t ret = 0;
349 for (int32_t i = 0; i < 1000; i++) {
350 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
351 cout << "ret" << i << "is" << ret << endl;
352 EXPECT_EQ(ret, 0);
353 }
354 }
355 /**
356 * @tc.number SUB_Security_Iam_PinAuth_HDI_Authenticate_0200
357 * @tc.name testPinAuthTestAuthenticate001
358 * @tc.desc test Authenticate scheduleId
359 */
360 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate001, Function | MediumTest | Level1)
361 {
362 cout << "start testPinAuthTestAuthenticate001" << endl;
363 uint64_t scheduleId = 0;
364 uint64_t templateId = parcel.ReadUint64();
365 std::vector<uint64_t> templateIdList;
366 templateIdList.push_back(templateId);
367 std::vector<uint8_t> extraInfo;
368 FillTestUint8Vector(parcel, extraInfo);
369 sptr<IExecutorCallback> callbackObj;
370 FillTestIExecutorCallback(parcel, callbackObj);
371 int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
372 cout << "ret is" << ret << endl;
373 EXPECT_EQ(ret, 0);
374 scheduleId = 0xFFFFFFFFFFFFFFFF;
375 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
376 cout << "ret is " << ret << endl;
377 EXPECT_EQ(ret, 0);
378 scheduleId = 0x7FFFFFFFFFFFFFFF;
379 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
380 cout << "ret is " << ret << endl;
381 EXPECT_EQ(ret, 0);
382 }
383 /**
384 * @tc.number SUB_Security_Iam_PinAuth_HDI_Authenticate_0500
385 * @tc.name testPinAuthTestAuthenticate004
386 * @tc.desc test Authenticate templateId
387 */
388 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate004, Function | MediumTest | Level1)
389 {
390 cout << "start testPinAuthTestAuthenticate004" << endl;
391 uint64_t scheduleId = parcel.ReadUint64();
392 uint64_t templateId = parcel.ReadUint64();
393 std::vector<uint64_t> templateIdList;
394 templateIdList.push_back(templateId);
395 std::vector<uint8_t> extraInfo;
396 FillTestUint8Vector(parcel, extraInfo);
397 sptr<IExecutorCallback> callbackObj;
398 FillTestIExecutorCallback(parcel, callbackObj);
399 int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
400 cout << "ret is" << ret << endl;
401 EXPECT_EQ(ret, 0);
402 templateIdList.resize(0);
403 templateIdList.push_back(0xFFFFFFFFFFFFFFFF);
404 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
405 cout << "ret is" << ret << endl;
406 EXPECT_EQ(ret, 0);
407 templateIdList.resize(0);
408 templateIdList.push_back(0x7FFFFFFFFFFFFFFF);
409 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
410 cout << "ret is" << ret << endl;
411 EXPECT_EQ(ret, 0);
412 }
413 /**
414 * @tc.number SUB_Security_Iam_PinAuth_HDI_Authenticate_0800
415 * @tc.name testPinAuthTestAuthenticate007
416 * @tc.desc test Authenticate empty
417 */
418 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate007, Function | MediumTest | Level1)
419 {
420 cout << "start testPinAuthTestAuthenticate007" << endl;
421 uint64_t scheduleId = parcel.ReadUint64();
422 uint64_t templateId = parcel.ReadUint64();
423 std::vector<uint64_t> templateIdList;
424 templateIdList.push_back(templateId);
425 std::vector<uint8_t> extraInfo;
426 sptr<IExecutorCallback> callbackObj;
427 FillTestIExecutorCallback(parcel, callbackObj);
428 int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
429 cout << "ret is" << ret << endl;
430 EXPECT_EQ(ret, 0);
431 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
432 cout << "ret is" << ret << endl;
433 EXPECT_NE(ret, 0);
434 FillTestUint8Vector(parcel, extraInfo);
435 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
436 cout << "ret is" << ret << endl;
437 EXPECT_EQ(ret, 0);
438 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
439 cout << "ret is" << ret << endl;
440 EXPECT_NE(ret, 0);
441 }
442 /**
443 * @tc.number SUB_Security_Iam_PinAuth_HDI_Authenticate_1100
444 * @tc.name testPinAuthTestAuthenticate010
445 * @tc.desc test Authenticate 1000 times
446 */
447 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate010, Function | MediumTest | Level1)
448 {
449 cout << "start testPinAuthTestAuthenticate010" << endl;
450 uint64_t scheduleId = parcel.ReadUint64();
451 uint64_t templateId = parcel.ReadUint64();
452 std::vector<uint64_t> templateIdList;
453 templateIdList.push_back(templateId);
454 std::vector<uint8_t> extraInfo;
455 FillTestUint8Vector(parcel, extraInfo);
456 sptr<IExecutorCallback> callbackObj;
457 FillTestIExecutorCallback(parcel, callbackObj);
458 int32_t ret = 0;
459 for (int32_t i = 0; i < 1000; i++) {
460 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
461 cout << "ret is" << ret << endl;
462 EXPECT_EQ(ret, 0);
463 }
464 }
465 /**
466 * @tc.number SUB_Security_Iam_PinAuth_HDI_Delete_0200
467 * @tc.name testPinAuthTestDelete001
468 * @tc.desc test Delete templateId 0
469 */
470 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestDelete001, Function | MediumTest | Level2)
471 {
472 cout << "start Delete" << endl;
473 uint64_t templateId = 0;
474 int32_t ret = g_executorImpl.Delete(templateId);
475 cout << "ret is " << ret << endl;
476 EXPECT_NE(ret, 0);
477 templateId = 0x7FFFFFFFFFFFFFFF;
478 ret = g_executorImpl.Delete(templateId);
479 cout << "ret is " << ret << endl;
480 EXPECT_NE(ret, 0);
481 templateId = 0xFFFFFFFFFFFFFFFF;
482 ret = g_executorImpl.Delete(templateId);
483 cout << "ret is " << ret << endl;
484 EXPECT_NE(ret, 0);
485 templateId = 0;
486 for (int32_t i = 0; i < 1000; i++) {
487 ret = g_executorImpl.Delete(templateId);
488 cout << "ret is " << ret << endl;
489 EXPECT_NE(ret, 0);
490 }
491 }
492 /**
493 * @tc.number SUB_Security_Iam_PinAuth_HDI_Cancel_0200
494 * @tc.name testPinAuthTestCancel001
495 * @tc.desc test Cancel scheduleId
496 */
497 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestCancel001, Function | MediumTest | Level1)
498 {
499 cout << "start Cancel" << endl;
500 uint64_t scheduleId = 0;
501 int32_t ret = g_executorImpl.Cancel(scheduleId);
502 cout << "ret is " << ret << endl;
503 EXPECT_EQ(ret, 0);
504 scheduleId = 0x7FFFFFFFFFFFFFFF;
505 ret = g_executorImpl.Cancel(scheduleId);
506 cout << "ret is " << ret << endl;
507 EXPECT_EQ(ret, 0);
508 scheduleId = 0xFFFFFFFFFFFFFFFF;
509 ret = g_executorImpl.Cancel(scheduleId);
510 cout << "ret is " << ret << endl;
511 EXPECT_EQ(ret, 0);
512 }
513 /**
514 * @tc.number SUB_Security_Iam_PinAuth_HDI_Cancel_0500
515 * @tc.name testPinAuthTestCancel004
516 * @tc.desc test Cancel 1000 times
517 */
518 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestCancel004, Function | MediumTest | Level1)
519 {
520 cout << "start Cancel" << endl;
521 uint64_t scheduleId = parcel.ReadUint64();
522 std::vector<uint8_t> extraInfo;
523 FillTestUint8Vector(parcel, extraInfo);
524 sptr<IExecutorCallback> callbackObj;
525 FillTestIExecutorCallback(parcel, callbackObj);
526
527 int32_t ret = 0;
528 for (int32_t i = 0; i < 1000; i++) {
529 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
530 ret = g_executorImpl.Cancel(scheduleId);
531 cout << "ret is " << ret << endl;
532 EXPECT_EQ(ret, 0);
533 }
534 }
535
536 /**
537 * @tc.number SUB_Security_Iam_PinAuth_HDI_GetProperty_0200
538 * @tc.name testPinAuthTestGetProperty001
539 * @tc.desc test GetProperty
540 */
541 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetProperty001, Function | MediumTest | Level2)
542 {
543 cout << "start GetProperty" << endl;
544 std::vector<uint64_t> templateIdList;
545 std::vector<int32_t> propertyTypes;
546 Property property;
547 int32_t ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
548 cout << "ret is " << ret << endl;
549 EXPECT_NE(ret, 0);
550 FillTestUint64Vector(parcel, templateIdList);
551 ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
552 cout << "ret is " << ret << endl;
553 EXPECT_NE(ret, 0);
554 propertyTypes.push_back(OHOS::HDI::PinAuth::V3_0::AUTH_SUB_TYPE);
555 propertyTypes.push_back(OHOS::HDI::PinAuth::V3_0::LOCKOUT_DURATION);
556 propertyTypes.push_back(OHOS::HDI::PinAuth::V3_0::REMAIN_ATTEMPTS);
557 ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
558 cout << "ret is " << ret << endl;
559 EXPECT_NE(ret, 0);
560 }
561 /**
562 * @tc.number SUB_Security_Iam_PinAuth_HDI_GetProperty_0700
563 * @tc.name testPinAuthTestGetProperty006
564 * @tc.desc test GetProperty 1000 times
565 */
566 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetProperty006, Function | MediumTest | Level2)
567 {
568 cout << "start GetProperty" << endl;
569 std::vector<uint64_t> templateIdList;
570 FillTestUint64Vector(parcel, templateIdList);
571 std::vector<int32_t> propertyTypes;
572 propertyTypes.push_back(OHOS::HDI::PinAuth::V3_0::AUTH_SUB_TYPE);
573 Property property;
574
575 int32_t ret = 0;
576 for (int32_t i = 0; i < 1000; i++) {
577 ret = g_executorImpl.GetProperty(templateIdList, propertyTypes, property);
578
579 cout << "ret is " << ret << endl;
580 EXPECT_NE(ret, 0);
581 }
582 }
583 /**
584 * @tc.number SUB_Security_Iam_PinAuth_HDI_EnrollV1_1_0100
585 * @tc.name testPinAuthTestEnrollV1_1001
586 * @tc.desc test EnrollV1_1 scheduleId
587 */
588 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_001, Function | MediumTest | Level1)
589 {
590 cout << "start test EnrollV1_1" << endl;
591 uint64_t scheduleId = 0;
592 std::vector<uint8_t> extraInfo;
593 FillTestUint8Vector(parcel, extraInfo);
594 sptr<IExecutorCallback> callbackObj;
595 FillTestIExecutorCallback(parcel, callbackObj);
596 int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
597 cout << "ret is" << ret << endl;
598 EXPECT_EQ(ret, 0);
599 scheduleId = 0x7FFFFFFFFFFFFFFF;
600 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
601 cout << "ret is" << ret << endl;
602 EXPECT_EQ(ret, 0);
603 scheduleId = 0xFFFFFFFFFFFFFFFF;
604 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
605 cout << "ret is" << ret << endl;
606 EXPECT_EQ(ret, 0);
607 }
608 /**
609 * @tc.number SUB_Security_Iam_PinAuth_HDI_EnrollV1_1_0400
610 * @tc.name testPinAuthTestEnrollV1_1004
611 * @tc.desc test EnrollV1_1 empty
612 */
613 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_004, Function | MediumTest | Level1)
614 {
615 cout << "start test EnrollV1_1" << endl;
616 uint64_t scheduleId = 0;
617 std::vector<uint8_t> extraInfo;
618 sptr<IExecutorCallback> callbackObj;
619 FillTestIExecutorCallback(parcel, callbackObj);
620 int32_t ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
621 cout << "ret is" << ret << endl;
622 EXPECT_EQ(ret, 0);
623 ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
624 cout << "ret is" << ret << endl;
625 EXPECT_NE(ret, 0);
626 FillTestUint8Vector(parcel, extraInfo);
627 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
628 cout << "ret is" << ret << endl;
629 EXPECT_EQ(ret, 0);
630 ret = g_executorImpl.Enroll(scheduleId, extraInfo, nullptr);
631 cout << "ret is" << ret << endl;
632 EXPECT_NE(ret, 0);
633 }
634 /**
635 * @tc.number SUB_Security_Iam_PinAuth_HDI_EnrollV1_1_0700
636 * @tc.name testPinAuthTestEnrollV1_1007
637 * @tc.desc test EnrollV1_1 1000 times
638 */
639 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestEnroll_007, Function | MediumTest | Level1)
640 {
641 cout << "start test EnrollV1_1" << endl;
642 uint64_t scheduleId = 0;
643 std::vector<uint8_t> extraInfo;
644 FillTestUint8Vector(parcel, extraInfo);
645 sptr<IExecutorCallback> callbackObj;
646 FillTestIExecutorCallback(parcel, callbackObj);
647 int32_t ret = 0;
648 for (int32_t i = 0; i < 1000; i++) {
649 ret = g_executorImpl.Enroll(scheduleId, extraInfo, callbackObj);
650 cout << "ret is" << ret << endl;
651 EXPECT_EQ(ret, 0);
652 }
653 }
654 /**
655 * @tc.number SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_0100
656 * @tc.name testPinAuthTestAuthenticateV1_1001
657 * @tc.desc test AuthenticateV1_1 scheduleId 0
658 */
659 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_001, Function | MediumTest | Level2)
660 {
661 cout << "start AuthenticateV1_1" << endl;
662
663 uint64_t scheduleId = 0;
664 uint64_t templateId = parcel.ReadUint64();
665 std::vector<uint64_t> templateIdList;
666 templateIdList.push_back(templateId);
667 std::vector<uint8_t> extraInfo;
668 FillTestUint8Vector(parcel, extraInfo);
669 sptr<IExecutorCallback> callbackObj;
670 FillTestIExecutorCallback(parcel, callbackObj);
671 int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
672 cout << "ret is " << ret << endl;
673 EXPECT_EQ(ret, 0);
674 scheduleId = 0xFFFFFFFFFFFFFFFF;
675 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
676 cout << "ret is " << ret << endl;
677 EXPECT_EQ(ret, 0);
678 scheduleId = 0x7FFFFFFFFFFFFFFF;
679 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
680 cout << "ret is " << ret << endl;
681 EXPECT_EQ(ret, 0);
682 }
683 /**
684 * @tc.number SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_0400
685 * @tc.name testPinAuthTestAuthenticateV1_1004
686 * @tc.desc test AuthenticateV1_1 templateId 0
687 */
688 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_004, Function | MediumTest | Level2)
689 {
690 cout << "start AuthenticateV1_1" << endl;
691
692 uint64_t scheduleId = parcel.ReadUint64();
693 uint64_t templateId = parcel.ReadUint64();
694 std::vector<uint64_t> templateIdList;
695 templateIdList.push_back(templateId);
696 std::vector<uint8_t> extraInfo;
697 FillTestUint8Vector(parcel, extraInfo);
698 sptr<IExecutorCallback> callbackObj;
699 FillTestIExecutorCallback(parcel, callbackObj);
700 int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
701 cout << "ret is " << ret << endl;
702 EXPECT_EQ(ret, 0);
703 templateIdList.resize(0);
704 templateIdList.push_back(0xFFFFFFFFFFFFFFFF);
705 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
706 cout << "ret is " << ret << endl;
707 EXPECT_EQ(ret, 0);
708 templateIdList.resize(0);
709 templateIdList.push_back(0x7FFFFFFFFFFFFFFF);
710 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
711 cout << "ret is " << ret << endl;
712 EXPECT_EQ(ret, 0);
713 }
714 /**
715 * @tc.number SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_0700
716 * @tc.name testPinAuthTestAuthenticateV1_1007
717 * @tc.desc test AuthenticateV1_1 extraInfo empty
718 */
719 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_007, Function | MediumTest | Level2)
720 {
721 cout << "start AuthenticateV1_1" << endl;
722
723 uint64_t scheduleId = parcel.ReadUint64();
724 uint64_t templateId = parcel.ReadUint64();
725 std::vector<uint64_t> templateIdList;
726 templateIdList.push_back(templateId);
727 std::vector<uint8_t> extraInfo;
728 sptr<IExecutorCallback> callbackObj;
729 FillTestIExecutorCallback(parcel, callbackObj);
730 int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
731 cout << "ret is " << ret << endl;
732 EXPECT_EQ(ret, 0);
733 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
734 cout << "ret is " << ret << endl;
735 EXPECT_NE(ret, 0);
736 FillTestUint8Vector(parcel, extraInfo);
737 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
738 cout << "ret is " << ret << endl;
739 EXPECT_EQ(ret, 0);
740 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, nullptr);
741 cout << "ret is " << ret << endl;
742 EXPECT_NE(ret, 0);
743 }
744 /**
745 * @tc.number SUB_Security_Iam_PinAuth_HDI_AuthenticateV1_1_1000
746 * @tc.name testPinAuthTestAuthenticateV1_1010
747 * @tc.desc test AuthenticateV1_1 1000 times
748 */
749 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestAuthenticate_010, Function | MediumTest | Level2)
750 {
751 cout << "start AuthenticateV1_1" << endl;
752
753 uint64_t scheduleId = parcel.ReadUint64();
754 uint64_t templateId = parcel.ReadUint64();
755 std::vector<uint64_t> templateIdList;
756 templateIdList.push_back(templateId);
757 std::vector<uint8_t> extraInfo;
758 FillTestUint8Vector(parcel, extraInfo);
759 sptr<IExecutorCallback> callbackObj;
760 FillTestIExecutorCallback(parcel, callbackObj);
761 int32_t ret = 0;
762 for (int32_t i = 0; i < 1000; i++) {
763 ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
764
765 cout << "ret is " << ret << endl;
766 EXPECT_EQ(ret, 0);
767 }
768 }
769 /**
770 * @tc.number SUB_Security_Iam_PinAuth_HDI_GetExecutorList_0200
771 * @tc.name testPinAuthTestGetExecutorList001
772 * @tc.desc test GetExecutorList 1000 times
773 */
774 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorList001, Function | MediumTest | Level1)
775 {
776 cout << "start GetExecutorList" << endl;
777 PinAuthInterfaceService g_pinAuthInterFaceService;
778 std::vector<sptr<IAllInOneExecutor>> allInOneExecutors;
779 std::vector<sptr<IVerifier>> verifiers;
780 std::vector<sptr<ICollector>> collectors;
781 int32_t ret = 0;
782 for (int32_t i = 0; i < 1000; i++) {
783 ret = g_pinAuthInterFaceService.GetExecutorList(allInOneExecutors, verifiers, collectors);
784 cout << "ret is " << ret << endl;
785 EXPECT_EQ(ret, 0);
786 }
787 }
788 /**
789 * @tc.number SUB_Security_Iam_PinAuth_HDI_GetExecutorListV1_1_0200
790 * @tc.name testPinAuthTestGetExecutorListV1_1001
791 * @tc.desc test GetExecutorListV1_1 1000 times
792 */
793 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestGetExecutorList_001, Function | MediumTest | Level1)
794 {
795 cout << "start GetExecutorList" << endl;
796 std::vector<sptr<IAllInOneExecutor>> allInOneExecutors;
797 std::vector<sptr<IVerifier>> verifiers;
798 std::vector<sptr<ICollector>> collectors;
799 PinAuthInterfaceService pin_Interface;
800
801 int32_t ret = 0;
802 for (int32_t i = 0; i < 1000; i++) {
803 ret = pin_Interface.GetExecutorList(allInOneExecutors, verifiers, collectors);
804
805 cout << "ret is " << ret << endl;
806 EXPECT_EQ(ret, 0);
807 }
808 }
809
810 /**
811 * @tc.number SUB_Security_Iam_PinAuth_HDI_OnGetData_0100
812 * @tc.name testPinAuthTestOnGetData001
813 * @tc.desc test OnGetData
814 */
815 HWTEST_F(UserIamPinAuthTestAdditional, testPinAuthTestOnGetData_001, Function | MediumTest | Level1)
816 {
817 cout << "start Authenticate" << endl;
818 uint64_t scheduleId = parcel.ReadUint64();
819 uint64_t templateId = parcel.ReadUint64();
820 std::vector<uint64_t> templateIdList;
821 templateIdList.push_back(templateId);
822 std::vector<uint8_t> extraInfo;
823 FillTestUint8Vector(parcel, extraInfo);
824 sptr<IExecutorCallback> callbackObj;
825 FillTestIExecutorCallback(parcel, callbackObj);
826 int32_t ret = g_executorImpl.Authenticate(scheduleId, templateIdList, extraInfo, callbackObj);
827 cout << "ret is " << ret << endl;
828 EXPECT_EQ(g_onGetDataFlag, false);
829 }
830