1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "gtest/gtest.h"
17
18 #include "hdf_base.h"
19 #include "iam_logger.h"
20 #include "iam_ptr.h"
21
22 #include "face_auth_all_in_one_executor_hdi.h"
23 #include "face_auth_defines.h"
24 #include "mock_iall_in_one_executor.h"
25 #include "mock_iexecute_callback.h"
26
27 #define LOG_TAG "FACE_AUTH_SA"
28
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace OHOS::UserIam::Common;
32
33 namespace OHOS {
34 namespace UserIam {
35 namespace FaceAuth {
36 using IamResultCode = OHOS::UserIam::UserAuth::ResultCode;
37 using IamExecutorRole = OHOS::UserIam::UserAuth::ExecutorRole;
38 using IamExecutorInfo = OHOS::UserIam::UserAuth::ExecutorInfo;
39 using IamAuthType = OHOS::UserIam::UserAuth::AuthType;
40 using IamExecutorSecureLevel = OHOS::UserIam::UserAuth::ExecutorSecureLevel;
41 using IamPropertyMode = OHOS::UserIam::UserAuth::PropertyMode;
42 namespace {
43 static const std::map<HDF_STATUS, IamResultCode> RESULT_CODE_MAP = {
44 { HDF_SUCCESS, IamResultCode::SUCCESS },
45 { HDF_FAILURE, IamResultCode::GENERAL_ERROR },
46 { HDF_ERR_TIMEOUT, IamResultCode::TIMEOUT },
47 { HDF_ERR_QUEUE_FULL, IamResultCode::BUSY },
48 { HDF_ERR_DEVICE_BUSY, IamResultCode::BUSY },
49 { static_cast<HDF_STATUS>(HDF_ERR_DEVICE_BUSY - 1), IamResultCode::GENERAL_ERROR },
50 { static_cast<HDF_STATUS>(HDF_SUCCESS + 1), IamResultCode::GENERAL_ERROR },
51 };
52 }
53
54 class FaceAuthAllInOneExecutorHdiUnitTest : public testing::Test {
55 public:
56 static void SetUpTestCase();
57 static void TearDownTestCase();
58 void SetUp();
59 void TearDown();
60 };
61
SetUpTestCase()62 void FaceAuthAllInOneExecutorHdiUnitTest::SetUpTestCase()
63 {
64 }
65
TearDownTestCase()66 void FaceAuthAllInOneExecutorHdiUnitTest::TearDownTestCase()
67 {
68 }
69
SetUp()70 void FaceAuthAllInOneExecutorHdiUnitTest::SetUp()
71 {
72 }
73
TearDown()74 void FaceAuthAllInOneExecutorHdiUnitTest::TearDown()
75 {
76 }
77
78 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetExecutorInfo_001, TestSize.Level0)
79 {
80 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
81 ASSERT_TRUE(executorProxy != nullptr);
__anon39d8fe9d0202(ExecutorInfo &info) 82 EXPECT_CALL(*executorProxy, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([](ExecutorInfo &info) {
83 info = {
84 .executorRole = ExecutorRole::ALL_IN_ONE,
85 .authType = AuthType::FACE,
86 .esl = ExecutorSecureLevel::ESL0,
87 };
88 return HDF_SUCCESS;
89 });
90 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
91 IamExecutorInfo info = {};
92 auto ret = executorHdi->GetExecutorInfo(info);
93 EXPECT_TRUE(info.executorRole == IamExecutorRole::ALL_IN_ONE);
94 EXPECT_TRUE(info.authType == IamAuthType::FACE);
95 EXPECT_TRUE(info.esl == IamExecutorSecureLevel::ESL0);
96 EXPECT_TRUE(ret == IamResultCode::SUCCESS);
97 }
98
99 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetExecutorInfo_002, TestSize.Level0)
100 {
101 for (const auto &pair : RESULT_CODE_MAP) {
102 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
103 ASSERT_TRUE(executorProxy != nullptr);
__anon39d8fe9d0302(ExecutorInfo &info) 104 EXPECT_CALL(*executorProxy, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([&pair](ExecutorInfo &info) {
105 info = {
106 .executorRole = ExecutorRole::ALL_IN_ONE,
107 .authType = AuthType::FACE,
108 .esl = ExecutorSecureLevel::ESL0,
109 };
110 return static_cast<int32_t>(pair.first);
111 });
112 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
113 IamExecutorInfo info = {};
114 auto ret = executorHdi->GetExecutorInfo(info);
115 EXPECT_TRUE(ret == pair.second);
116 }
117 }
118
119 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetExecutorInfo_003, TestSize.Level0)
120 {
121 static const std::map<AuthType, pair<IamAuthType, IamResultCode>> data = {
122 { AuthType::FACE, { IamAuthType::FACE, IamResultCode::SUCCESS } },
123 { static_cast<AuthType>(AuthType::FACE + 1), { IamAuthType::FACE, IamResultCode::GENERAL_ERROR } },
124 { static_cast<AuthType>(AuthType::FACE - 1), { IamAuthType::FACE, IamResultCode::GENERAL_ERROR } },
125 };
126 for (const auto &pair : data) {
127 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
128 ASSERT_TRUE(executorProxy != nullptr);
__anon39d8fe9d0402(ExecutorInfo &info) 129 EXPECT_CALL(*executorProxy, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([&pair](ExecutorInfo &info) {
130 info = {
131 .executorRole = ExecutorRole::ALL_IN_ONE,
132 .authType = pair.first,
133 .esl = ExecutorSecureLevel::ESL0,
134 };
135 return HDF_SUCCESS;
136 });
137 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
138 IamExecutorInfo info = {};
139 auto ret = executorHdi->GetExecutorInfo(info);
140 EXPECT_TRUE(ret == pair.second.second);
141 if (ret == IamResultCode::SUCCESS) {
142 EXPECT_TRUE(info.authType == pair.second.first);
143 }
144 }
145 }
146
147 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetExecutorInfo_004, TestSize.Level0)
148 {
149 static const std::map<ExecutorRole, pair<IamExecutorRole, IamResultCode>> data = {
150 { ExecutorRole::COLLECTOR, { IamExecutorRole::COLLECTOR, IamResultCode::SUCCESS } },
151 { ExecutorRole::VERIFIER, { IamExecutorRole::VERIFIER, IamResultCode::SUCCESS } },
152 { ExecutorRole::ALL_IN_ONE, { IamExecutorRole::ALL_IN_ONE, IamResultCode::SUCCESS } },
153 { static_cast<ExecutorRole>(ExecutorRole::COLLECTOR - 1),
154 { IamExecutorRole::ALL_IN_ONE, IamResultCode::GENERAL_ERROR } },
155 { static_cast<ExecutorRole>(ExecutorRole::ALL_IN_ONE + 1),
156 { IamExecutorRole::ALL_IN_ONE, IamResultCode::GENERAL_ERROR } },
157 };
158 for (const auto &pair : data) {
159 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
160 ASSERT_TRUE(executorProxy != nullptr);
__anon39d8fe9d0502(ExecutorInfo &info) 161 EXPECT_CALL(*executorProxy, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([&pair](ExecutorInfo &info) {
162 info = {
163 .executorRole = pair.first,
164 .authType = AuthType::FACE,
165 .esl = ExecutorSecureLevel::ESL0,
166 };
167 return HDF_SUCCESS;
168 });
169 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
170 IamExecutorInfo info = {};
171 auto ret = executorHdi->GetExecutorInfo(info);
172 EXPECT_TRUE(ret == pair.second.second);
173 if (ret == IamResultCode::SUCCESS) {
174 EXPECT_TRUE(info.executorRole == pair.second.first);
175 }
176 }
177 }
178
179 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetExecutorInfo_005, TestSize.Level0)
180 {
181 static const std::map<ExecutorSecureLevel, pair<IamExecutorSecureLevel, IamResultCode>> data = {
182 { ExecutorSecureLevel::ESL0, { IamExecutorSecureLevel::ESL0, IamResultCode::SUCCESS } },
183 { ExecutorSecureLevel::ESL1, { IamExecutorSecureLevel::ESL1, IamResultCode::SUCCESS } },
184 { ExecutorSecureLevel::ESL2, { IamExecutorSecureLevel::ESL2, IamResultCode::SUCCESS } },
185 { ExecutorSecureLevel::ESL3, { IamExecutorSecureLevel::ESL3, IamResultCode::SUCCESS } },
186 { static_cast<ExecutorSecureLevel>(ExecutorSecureLevel::ESL0 - 1),
187 { IamExecutorSecureLevel::ESL3, IamResultCode::GENERAL_ERROR } },
188 { static_cast<ExecutorSecureLevel>(ExecutorSecureLevel::ESL3 + 1),
189 { IamExecutorSecureLevel::ESL3, IamResultCode::GENERAL_ERROR } },
190 };
191 for (const auto &pair : data) {
192 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
193 ASSERT_TRUE(executorProxy != nullptr);
__anon39d8fe9d0602(ExecutorInfo &info) 194 EXPECT_CALL(*executorProxy, GetExecutorInfo(_)).Times(Exactly(1)).WillOnce([&pair](ExecutorInfo &info) {
195 info = {
196 .executorRole = ExecutorRole::ALL_IN_ONE,
197 .authType = AuthType::FACE,
198 .esl = pair.first,
199 };
200 return HDF_SUCCESS;
201 });
202 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
203 IamExecutorInfo info = {};
204 auto ret = executorHdi->GetExecutorInfo(info);
205 EXPECT_TRUE(ret == pair.second.second);
206 if (ret == IamResultCode::SUCCESS) {
207 EXPECT_TRUE(info.esl == pair.second.first);
208 }
209 }
210 }
211
212 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetExecutorInfo_006, TestSize.Level0)
213 {
214 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
215 IamExecutorInfo info = {};
216 auto ret = executorHdi->GetExecutorInfo(info);
217 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
218 }
219
220 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_OnRegisterFinish_001, TestSize.Level0)
221 {
222 for (const auto &pair : RESULT_CODE_MAP) {
223 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
224 ASSERT_TRUE(executorProxy != nullptr);
225 EXPECT_CALL(*executorProxy, RegisterSaCommandCallback(_))
__anon39d8fe9d0702(const sptr<ISaCommandCallback> &callbackObj) 226 .WillRepeatedly([](const sptr<ISaCommandCallback> &callbackObj) { return HDF_SUCCESS; });
227
228 EXPECT_CALL(*executorProxy, OnRegisterFinish(_, _, _))
229 .Times(Exactly(1))
230 .WillOnce(
231 [&pair](const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey,
__anon39d8fe9d0802(const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) 232 const std::vector<uint8_t> &extraInfo) { return pair.first; });
233 if (pair.first == HDF_SUCCESS) {
234 EXPECT_CALL(*executorProxy, RegisterSaCommandCallback(_))
235 .Times(Exactly(1))
__anon39d8fe9d0902(const sptr<ISaCommandCallback> &callbackObj) 236 .WillOnce([](const sptr<ISaCommandCallback> &callbackObj) { return HDF_SUCCESS; });
237 }
238 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
239 auto ret =
240 executorHdi->OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
241 EXPECT_TRUE(ret == pair.second);
242 }
243 }
244
245 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_OnRegisterFinish_002, TestSize.Level0)
246 {
247 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
248 auto ret = executorHdi->OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
249 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
250 }
251
252 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_OnRegisterFinish_003, TestSize.Level0)
253 {
254 for (const auto &pair : RESULT_CODE_MAP) {
255 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
256 ASSERT_TRUE(executorProxy != nullptr);
257 EXPECT_CALL(*executorProxy, OnRegisterFinish(_, _, _))
258 .Times(Exactly(1))
259 .WillOnce([](const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey,
__anon39d8fe9d0a02(const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) 260 const std::vector<uint8_t> &extraInfo) { return HDF_SUCCESS; });
261 EXPECT_CALL(*executorProxy, RegisterSaCommandCallback(_))
262 .Times(Exactly(1))
__anon39d8fe9d0b02(const sptr<ISaCommandCallback> &callbackObj) 263 .WillOnce([&pair](const sptr<ISaCommandCallback> &callbackObj) { return pair.first; });
264 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
265 auto ret =
266 executorHdi->OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
267 EXPECT_TRUE(ret == pair.second);
268 }
269 }
270
271 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Enroll_001, TestSize.Level0)
272 {
273 for (const auto &pair : RESULT_CODE_MAP) {
274 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
275 ASSERT_TRUE(executorProxy != nullptr);
276 EXPECT_CALL(*executorProxy, Enroll(_, _, _))
277 .Times(Exactly(1))
278 .WillOnce([&pair](uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
__anon39d8fe9d0c02(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 279 const sptr<IExecutorCallback> &callbackObj) { return pair.first; });
280 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
281 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
282 ASSERT_TRUE(executeCallback != nullptr);
283 auto ret = executorHdi->Enroll(0, UserAuth::EnrollParam { 0, std::vector<uint8_t>() }, executeCallback);
284 EXPECT_TRUE(ret == pair.second);
285 }
286 }
287
288 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Enroll_002, TestSize.Level0)
289 {
290 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
291 ASSERT_TRUE(executorProxy != nullptr);
292 EXPECT_CALL(*executorProxy, Enroll(_, _, _)).Times(Exactly(0));
293 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
294 auto ret = executorHdi->Enroll(0, UserAuth::EnrollParam { 0, std::vector<uint8_t>() }, nullptr);
295 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
296 }
297
298 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Enroll_003, TestSize.Level0)
299 {
300 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
301 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
302 ASSERT_TRUE(executeCallback != nullptr);
303 auto ret = executorHdi->Enroll(0, UserAuth::EnrollParam { 0, std::vector<uint8_t>() }, executeCallback);
304 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
305 }
306
307 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Authenticate_001, TestSize.Level0)
308 {
309 for (const auto &pair : RESULT_CODE_MAP) {
310 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
311 ASSERT_TRUE(executorProxy != nullptr);
312 EXPECT_CALL(*executorProxy, Authenticate(_, _, _, _))
313 .Times(Exactly(1))
314 .WillOnce([&pair](uint64_t scheduleId, const std::vector<uint64_t> &templateIdList,
315 const std::vector<uint8_t> &extraInfo,
__anon39d8fe9d0d02(uint64_t scheduleId, const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 316 const sptr<IExecutorCallback> &callbackObj) { return pair.first; });
317 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
318 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
319 ASSERT_TRUE(executeCallback != nullptr);
320 auto ret = executorHdi->Authenticate(0,
321 UserAuth::AuthenticateParam { 0, std::vector<uint64_t>(), std::vector<uint8_t>(), false }, executeCallback);
322 EXPECT_TRUE(ret == pair.second);
323 }
324 }
325
326 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Authenticate_002, TestSize.Level0)
327 {
328 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
329 ASSERT_TRUE(executorProxy != nullptr);
330 EXPECT_CALL(*executorProxy, Authenticate(_, _, _, _)).Times(Exactly(0));
331 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
332 auto ret = executorHdi->Authenticate(0,
333 UserAuth::AuthenticateParam { 0, std::vector<uint64_t>(), std::vector<uint8_t>(), false }, nullptr);
334 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
335 }
336
337 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Authenticate_003, TestSize.Level0)
338 {
339 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
340 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
341 ASSERT_TRUE(executeCallback != nullptr);
342 auto ret = executorHdi->Authenticate(0,
343 UserAuth::AuthenticateParam { 0, std::vector<uint64_t>(), std::vector<uint8_t>(), false }, executeCallback);
344 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
345 }
346 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Identify_001, TestSize.Level0)
347 {
348 for (const auto &pair : RESULT_CODE_MAP) {
349 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
350 ASSERT_TRUE(executorProxy != nullptr);
351 EXPECT_CALL(*executorProxy, Identify(_, _, _))
352 .Times(Exactly(1))
353 .WillOnce([&pair](uint64_t scheduleId, const std::vector<uint8_t> &extraInfo,
__anon39d8fe9d0e02(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 354 const sptr<IExecutorCallback> &callbackObj) { return pair.first; });
355 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
356 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
357 ASSERT_TRUE(executeCallback != nullptr);
358 auto ret = executorHdi->Identify(0, UserAuth::IdentifyParam { 0, std::vector<uint8_t>() }, executeCallback);
359 EXPECT_TRUE(ret == pair.second);
360 }
361 }
362
363 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Identify_002, TestSize.Level0)
364 {
365 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
366 ASSERT_TRUE(executorProxy != nullptr);
367 EXPECT_CALL(*executorProxy, Identify(_, _, _)).Times(Exactly(0));
368 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
369 auto ret = executorHdi->Identify(0, UserAuth::IdentifyParam { 0, std::vector<uint8_t>() }, nullptr);
370 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
371 }
372
373 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Identify_003, TestSize.Level0)
374 {
375 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
376 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
377 ASSERT_TRUE(executeCallback != nullptr);
378 auto ret = executorHdi->Identify(0, UserAuth::IdentifyParam { 0, std::vector<uint8_t>() }, executeCallback);
379 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
380 }
381
382 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Delete_001, TestSize.Level0)
383 {
384 for (const auto &pair : RESULT_CODE_MAP) {
385 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
386 ASSERT_TRUE(executorProxy != nullptr);
387 EXPECT_CALL(*executorProxy, Delete(_))
388 .Times(Exactly(1))
__anon39d8fe9d0f02(const std::vector<uint64_t> &templateIdList) 389 .WillOnce([&pair](const std::vector<uint64_t> &templateIdList) { return pair.first; });
390 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
391 auto ret = executorHdi->Delete(std::vector<uint64_t>());
392 EXPECT_TRUE(ret == pair.second);
393 }
394 }
395
396 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Delete_002, TestSize.Level0)
397 {
398 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
399 auto ret = executorHdi->Delete(std::vector<uint64_t>());
400 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
401 }
402
403 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Cancel_001, TestSize.Level0)
404 {
405 for (const auto &pair : RESULT_CODE_MAP) {
406 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
407 ASSERT_TRUE(executorProxy != nullptr);
__anon39d8fe9d1002(uint64_t scheduleId) 408 EXPECT_CALL(*executorProxy, Cancel(_)).Times(Exactly(1)).WillOnce([&pair](uint64_t scheduleId) {
409 return pair.first;
410 });
411 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
412 auto ret = executorHdi->Cancel(0);
413 EXPECT_TRUE(ret == pair.second);
414 }
415 }
416
417 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_Cancel_002, TestSize.Level0)
418 {
419 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
420 auto ret = executorHdi->Cancel(0);
421 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
422 }
423
424 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SendCommand_001, TestSize.Level0)
425 {
426 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
427 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
428 ASSERT_TRUE(executeCallback != nullptr);
429 auto ret = executorHdi->SendCommand(IamPropertyMode::PROPERTY_MODE_FREEZE, std::vector<uint8_t>(), executeCallback);
430 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
431 }
432
433 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SendCommand_002, TestSize.Level0)
434 {
435 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
436 ASSERT_TRUE(executorProxy != nullptr);
437 EXPECT_CALL(*executorProxy, SendCommand(_, _, _)).Times(Exactly(0));
438 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
439
440 auto ret = executorHdi->SendCommand(IamPropertyMode::PROPERTY_MODE_FREEZE, std::vector<uint8_t>(), nullptr);
441 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
442 }
443
444 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SendCommand_003, TestSize.Level0)
445 {
446 static const std::map<IamPropertyMode, pair<DriverCommandId, IamResultCode>> data = {
447 { IamPropertyMode::PROPERTY_INIT_ALGORITHM, { DriverCommandId::INIT_ALGORITHM, IamResultCode::SUCCESS } },
448 { IamPropertyMode::PROPERTY_MODE_FREEZE, { DriverCommandId::LOCK_TEMPLATE, IamResultCode::SUCCESS } },
449 { IamPropertyMode::PROPERTY_MODE_UNFREEZE, { DriverCommandId::UNLOCK_TEMPLATE, IamResultCode::SUCCESS } },
450 { static_cast<IamPropertyMode>(IamPropertyMode::PROPERTY_MODE_FREEZE - 1),
451 { DriverCommandId::UNLOCK_TEMPLATE, IamResultCode::INVALID_PARAMETERS } },
452 { static_cast<IamPropertyMode>(IamPropertyMode::PROPERTY_MODE_UNFREEZE + 1),
453 { DriverCommandId::UNLOCK_TEMPLATE, IamResultCode::INVALID_PARAMETERS } },
454 { static_cast<IamPropertyMode>(DriverCommandId::VENDOR_COMMAND_BEGIN),
455 { DriverCommandId::UNLOCK_TEMPLATE, IamResultCode::INVALID_PARAMETERS } },
456 { static_cast<IamPropertyMode>(DriverCommandId::VENDOR_COMMAND_BEGIN + 1),
457 { static_cast<DriverCommandId>(DriverCommandId::VENDOR_COMMAND_BEGIN + 1), IamResultCode::SUCCESS } }
458 };
459 for (const auto &pair : data) {
460 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
461 ASSERT_TRUE(executorProxy != nullptr);
462 if (pair.second.second == IamResultCode::SUCCESS) {
463 EXPECT_CALL(*executorProxy, SendCommand(_, _, _))
464 .Times(Exactly(1))
465 .WillOnce([&pair](int32_t commandId, const std::vector<uint8_t> &extraInfo,
__anon39d8fe9d1102(int32_t commandId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 466 const sptr<IExecutorCallback> &callbackObj) {
467 EXPECT_TRUE(commandId == pair.second.first);
468 return HDF_SUCCESS;
469 });
470 } else {
471 EXPECT_CALL(*executorProxy, SendCommand(_, _, _)).Times(Exactly(0));
472 }
473 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
474 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
475 ASSERT_TRUE(executeCallback != nullptr);
476 auto ret = executorHdi->SendCommand(pair.first, std::vector<uint8_t>(), executeCallback);
477 EXPECT_TRUE(ret == pair.second.second);
478 }
479 }
480
481 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SendCommand_004, TestSize.Level0)
482 {
483 for (const auto &pair : RESULT_CODE_MAP) {
484 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
485 ASSERT_TRUE(executorProxy != nullptr);
486 EXPECT_CALL(*executorProxy, SendCommand(_, _, _))
487 .Times(Exactly(1))
488 .WillOnce([&pair](int32_t commandId, const std::vector<uint8_t> &extraInfo,
__anon39d8fe9d1202(int32_t commandId, const std::vector<uint8_t> &extraInfo, const sptr<IExecutorCallback> &callbackObj) 489 const sptr<IExecutorCallback> &callbackObj) { return pair.first; });
490 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
491 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
492 ASSERT_TRUE(executeCallback != nullptr);
493 auto ret =
494 executorHdi->SendCommand(IamPropertyMode::PROPERTY_MODE_FREEZE, std::vector<uint8_t>(), executeCallback);
495 EXPECT_TRUE(ret == pair.second);
496 }
497 }
498
499 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SendMessage_001, TestSize.Level0)
500 {
501 for (const auto &pair : RESULT_CODE_MAP) {
502 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
503 ASSERT_TRUE(executorProxy != nullptr);
504 EXPECT_CALL(*executorProxy, SendMessage(_, _, _))
505 .Times(Exactly(1))
506 .WillOnce(Return(pair.first));
507 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
508 auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
509 ASSERT_TRUE(executeCallback != nullptr);
510 std::vector<uint8_t> data;
511 auto ret =
512 executorHdi->SendMessage(1, 1, data);
513 EXPECT_TRUE(ret == pair.second);
514 }
515 }
516
517 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetProperty_001, TestSize.Level0)
518 {
519 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
520 ASSERT_TRUE(executorHdi != nullptr);
521 std::vector<uint64_t> templateIdList;
522 std::vector<UserAuth::Attributes::AttributeKey> keys;
523 UserAuth::Property property = {};
524 auto ret = executorHdi->GetProperty(templateIdList, keys, property);
525 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
526 }
527
528 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetProperty_002, TestSize.Level0)
529 {
530 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
531 ASSERT_TRUE(executorProxy != nullptr);
532 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
533 ASSERT_TRUE(executorHdi != nullptr);
534 std::vector<uint64_t> templateIdList;
535 std::vector<UserAuth::Attributes::AttributeKey> keys = { UserAuth::Attributes::ATTR_SIGNATURE };
536 UserAuth::Property property = {};
537 auto ret = executorHdi->GetProperty(templateIdList, keys, property);
538 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
539 }
540
541 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_GetProperty_003, TestSize.Level0)
542 {
543 for (const auto &pair : RESULT_CODE_MAP) {
544 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
545 ASSERT_TRUE(executorProxy != nullptr);
546 EXPECT_CALL(*executorProxy, GetProperty(_, _, _))
547 .Times(Exactly(1))
548 .WillOnce([&pair](const std::vector<uint64_t> &templateIdList, const std::vector<int32_t> &propertyTypes,
__anon39d8fe9d1302(const std::vector<uint64_t> &templateIdList, const std::vector<int32_t> &propertyTypes, Property &property) 549 Property &property) { return pair.first; });
550 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
551 ASSERT_TRUE(executorHdi != nullptr);
552 std::vector<uint64_t> templateIdList;
553 std::vector<UserAuth::Attributes::AttributeKey> keys;
554 if (pair.first != HDF_SUCCESS) {
555 keys.push_back(UserAuth::Attributes::ATTR_PIN_SUB_TYPE);
556 }
557 UserAuth::Property property = {};
558 auto ret = executorHdi->GetProperty(templateIdList, keys, property);
559 EXPECT_TRUE(ret == pair.second);
560 }
561 }
562
563 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SetCachedTemplates_001, TestSize.Level0)
564 {
565 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
566 ASSERT_TRUE(executorHdi != nullptr);
567 std::vector<uint64_t> templateIdList;
568 auto ret = executorHdi->SetCachedTemplates(templateIdList);
569 EXPECT_TRUE(ret == IamResultCode::GENERAL_ERROR);
570 }
571
572 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SetCachedTemplates_002, TestSize.Level0)
573 {
574 for (const auto &pair : RESULT_CODE_MAP) {
575 auto executorProxy = new (std::nothrow) MockIAllInOneExecutor();
576 ASSERT_TRUE(executorProxy != nullptr);
577 EXPECT_CALL(*executorProxy, SetCachedTemplates(_))
578 .Times(Exactly(1))
__anon39d8fe9d1402(const std::vector<uint64_t> &templateIdList) 579 .WillOnce([&pair](const std::vector<uint64_t> &templateIdList) { return pair.first; });
580 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
581 ASSERT_TRUE(executorHdi != nullptr);
582 std::vector<uint64_t> templateIdList;
583 auto ret = executorHdi->SetCachedTemplates(templateIdList);
584 EXPECT_TRUE(ret == pair.second);
585 }
586 }
587
588 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_OnHdiDisconnect_001, TestSize.Level0)
589 {
590 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(nullptr);
591 ASSERT_TRUE(executorHdi != nullptr);
592 executorHdi->OnHdiDisconnect();
593 }
594
595 HWTEST_F(FaceAuthAllInOneExecutorHdiUnitTest, FaceAuthAllInOneExecutorHdi_SaCommandCallback_OnSaCommands_001,
596 TestSize.Level0)
597 {
598 sptr<MockIAllInOneExecutor> executorProxy(new (std::nothrow) MockIAllInOneExecutor());
599 ASSERT_TRUE(executorProxy != nullptr);
600 EXPECT_CALL(*executorProxy, OnRegisterFinish(_, _, _))
601 .Times(Exactly(1))
602 .WillOnce([](const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey,
__anon39d8fe9d1502(const std::vector<uint64_t> &templateIdList, const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo) 603 const std::vector<uint8_t> &extraInfo) { return HDF_SUCCESS; });
604 EXPECT_CALL(*executorProxy, RegisterSaCommandCallback(_))
605 .Times(Exactly(1))
__anon39d8fe9d1602(const sptr<ISaCommandCallback> &callbackObj) 606 .WillOnce([](const sptr<ISaCommandCallback> &callbackObj) {
607 std::vector<SaCommand> commands;
608 callbackObj->OnSaCommands(commands);
609 return HDF_SUCCESS;
610 });
611 auto executorHdi = MakeShared<FaceAuthAllInOneExecutorHdi>(executorProxy);
612 auto ret = executorHdi->OnRegisterFinish(std::vector<uint64_t>(), std::vector<uint8_t>(), std::vector<uint8_t>());
613 EXPECT_TRUE(ret == IamResultCode::SUCCESS);
614 }
615 } // namespace FaceAuth
616 } // namespace UserIam
617 } // namespace OHOS
618