• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "securec.h"
19 
20 #include "adaptor_memory.h"
21 #include "coauth.h"
22 #include "executor_message.h"
23 #include "idm_common.h"
24 
25 extern "C" {
26     extern LinkedList *g_poolList;
27     extern LinkedList *g_scheduleList;
28     extern LinkedList *g_userInfoList;
29     extern void DestroyUserInfoList(void);
30     extern ResultCode SignData(const Uint8Array *dataTlv, Uint8Array *signDataTlv);
31     extern ResultCode GetAttributeDataAndSignTlv(const Attribute *attribute, bool needSignature,
32         Uint8Array *retDataAndSignTlv);
33     extern ResultCode Ed25519VerifyData(uint64_t scheduleId, Uint8Array dataTlv, Uint8Array signTlv);
34     extern ResultCode VerifyDataTlvSignature(const Attribute *dataAndSignAttribute, const Uint8Array dataTlv);
35     extern Attribute *CreateAttributeFromDataAndSignTlv(const Uint8Array dataAndSignTlv, bool needVerifySignature);
36     extern Attribute *CreateAttributeFromExecutorMsg(const Uint8Array msg, bool needVerifySignature);
37     extern void GetRootSecretFromAttribute(const Attribute *attribute, ExecutorResultInfo *resultInfo);
38     extern ResultCode GetExecutorResultInfoFromAttribute(const Attribute *attribute, ExecutorResultInfo *resultInfo);
39     extern Buffer *CreateExecutorMsg(uint32_t authType, uint32_t authPropertyMode,
40         const Uint64Array *templateIds);
41     extern void DestoryExecutorMsg(void *data);
42     extern ResultCode GetExecutorTemplateList(
43         int32_t userId, const ExecutorInfoHal *executorNode, Uint64Array *templateIds);
44     extern ResultCode AssemblyMessage(
45         int32_t userId, const ExecutorInfoHal *executorNode, uint32_t authPropertyMode, LinkedList *executorMsg);
46     extern ResultCode TraverseExecutor(
47         int32_t userId, uint32_t executorRole, uint32_t authPropertyMode, LinkedList *executorMsg);
48 }
49 
50 namespace OHOS {
51 namespace UserIam {
52 namespace UserAuth {
53 using namespace testing;
54 using namespace testing::ext;
55 
56 class ExecutorMessageTest : public testing::Test {
57 public:
SetUpTestCase()58     static void SetUpTestCase() {};
59 
TearDownTestCase()60     static void TearDownTestCase() {};
61 
SetUp()62     void SetUp() {};
63 
TearDown()64     void TearDown() {};
65 };
66 
67 HWTEST_F(ExecutorMessageTest, TestSignData, TestSize.Level0)
68 {
69     constexpr uint32_t len = 32;
70     Uint8Array dataTlv = { (uint8_t *)Malloc(len), len };
71     Uint8Array signData = { (uint8_t *)Malloc(len), len };
72     dataTlv.len = 0;
73     ResultCode result = SignData(&dataTlv, &signData);
74     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
75     (void)memset_s(dataTlv.data, dataTlv.len, 1, dataTlv.len);
76     dataTlv.len = len;
77     result = SignData(&dataTlv, &signData);
78     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
79     Free(dataTlv.data);
80     Free(signData.data);
81 }
82 
83 HWTEST_F(ExecutorMessageTest, TestGetAttributeDataAndSignTlv, TestSize.Level0)
84 {
85     Uint8Array retData = { (uint8_t *)Malloc(MAX_EXECUTOR_MSG_LEN), MAX_EXECUTOR_MSG_LEN };
86     Attribute *attribute = CreateEmptyAttribute();
87     EXPECT_NE(attribute, nullptr);
88     ResultCode result = GetAttributeDataAndSignTlv(nullptr, false, &retData);
89     EXPECT_EQ(result, RESULT_BAD_PARAM);
90 
91     uint32_t testUint32 = 123;
92     int32_t testInt32 = 123;
93     uint64_t testUint64 = 456;
94     uint8_t testUint8Buffer[] = { 'a', 'b', 'c' };
95     uint64_t testUint64Buffer[] = { 123, 456, 789 };
96     Uint8Array testUint8Array = { testUint8Buffer, sizeof(testUint8Buffer) };
97     Uint64Array testUint64Array = { testUint64Buffer, sizeof(testUint64Buffer) };
98     result = SetAttributeUint32(attribute, AUTH_IDENTIFY_MODE, testUint32);
99     EXPECT_EQ(result, RESULT_SUCCESS);
100     result = SetAttributeInt32(attribute, AUTH_RESULT_CODE, testInt32);
101     EXPECT_EQ(result, RESULT_SUCCESS);
102     result = SetAttributeUint64(attribute, AUTH_SCHEDULE_ID, testUint64);
103     EXPECT_EQ(result, RESULT_SUCCESS);
104     result = SetAttributeUint8Array(attribute, AUTH_SIGNATURE, testUint8Array);
105     EXPECT_EQ(result, RESULT_SUCCESS);
106     result = SetAttributeUint64Array(attribute, AUTH_TEMPLATE_ID_LIST, testUint64Array);
107     EXPECT_EQ(result, RESULT_SUCCESS);
108 
109     result = GetAttributeDataAndSignTlv(attribute, false, &retData);
110     EXPECT_EQ(result, RESULT_SUCCESS);
111     result = GetAttributeDataAndSignTlv(attribute, true, &retData);
112     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
113     Free(retData.data);
114     FreeAttribute(&attribute);
115 }
116 
117 HWTEST_F(ExecutorMessageTest, TestGetAttributeExecutorMsg, TestSize.Level0)
118 {
119     Uint8Array retData = { (uint8_t *)Malloc(MAX_EXECUTOR_MSG_LEN), MAX_EXECUTOR_MSG_LEN };
120     Attribute *attribute = CreateEmptyAttribute();
121     EXPECT_NE(attribute, nullptr);
122     ResultCode result = GetAttributeExecutorMsg(nullptr, false, &retData);
123     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
124     result = GetAttributeExecutorMsg(attribute, false, nullptr);
125     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
126     retData.len = 0;
127     result = GetAttributeExecutorMsg(attribute, false, &retData);
128     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
129 
130     uint32_t testUint32 = 123;
131     int32_t testInt32 = 123;
132     uint64_t testUint64 = 456;
133     uint8_t testUint8Buffer[] = { 'a', 'b', 'c' };
134     uint64_t testUint64Buffer[] = { 123, 456, 789 };
135     Uint8Array testUint8Array = { testUint8Buffer, sizeof(testUint8Buffer) };
136     Uint64Array testUint64Array = { testUint64Buffer, sizeof(testUint64Buffer) };
137     result = SetAttributeUint32(attribute, AUTH_IDENTIFY_MODE, testUint32);
138     EXPECT_EQ(result, RESULT_SUCCESS);
139     result = SetAttributeInt32(attribute, AUTH_RESULT_CODE, testInt32);
140     EXPECT_EQ(result, RESULT_SUCCESS);
141     result = SetAttributeUint64(attribute, AUTH_SCHEDULE_ID, testUint64);
142     EXPECT_EQ(result, RESULT_SUCCESS);
143     result = SetAttributeUint8Array(attribute, AUTH_SIGNATURE, testUint8Array);
144     EXPECT_EQ(result, RESULT_SUCCESS);
145     result = SetAttributeUint64Array(attribute, AUTH_TEMPLATE_ID_LIST, testUint64Array);
146     EXPECT_EQ(result, RESULT_SUCCESS);
147 
148     result = GetAttributeExecutorMsg(attribute, false, &retData);
149     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
150     result = GetAttributeExecutorMsg(attribute, true, &retData);
151     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
152     Free(retData.data);
153     FreeAttribute(&attribute);
154 }
155 
156 HWTEST_F(ExecutorMessageTest, TestEd25519VerifyData, TestSize.Level0)
157 {
158     uint64_t scheduleId = 0;
159     uint8_t testUint8Buffer[] = { 'a', 'b', 'c' };
160     Uint8Array dataTlv = { testUint8Buffer, sizeof(testUint8Buffer) };
161     Uint8Array signData = { testUint8Buffer, sizeof(testUint8Buffer) };
162     ResultCode result = Ed25519VerifyData(scheduleId, dataTlv, signData);
163     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
164 }
165 
166 HWTEST_F(ExecutorMessageTest, TestVerifyDataTlvSignature, TestSize.Level0)
167 {
168     Attribute *attribute = CreateEmptyAttribute();
169     EXPECT_NE(attribute, nullptr);
170     constexpr uint32_t dataLen = 12;
171     uint8_t array[dataLen] = { 1, 2, 3, 4, 5, 6 };
172     Uint8Array dataTlv = { &array[0], dataLen };
173     ResultCode result = SetAttributeUint8Array(attribute, AUTH_SIGNATURE, dataTlv);
174     EXPECT_EQ(result, RESULT_SUCCESS);
175     result = SetAttributeUint8Array(attribute, AUTH_DATA, dataTlv);
176     EXPECT_EQ(result, RESULT_SUCCESS);
177     uint64_t scheduleId = 10;
178     result = SetAttributeUint64(attribute, AUTH_SCHEDULE_ID, scheduleId);
179     EXPECT_EQ(result, RESULT_SUCCESS);
180 
181     result = VerifyDataTlvSignature(nullptr, dataTlv);
182     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
183     FreeAttribute(&attribute);
184 }
185 
186 HWTEST_F(ExecutorMessageTest, TestCreateAttributeFromDataAndSignTlv, TestSize.Level0)
187 {
188     Uint8Array retInfo = { (uint8_t *)Malloc(MAX_EXECUTOR_SIZE), MAX_EXECUTOR_SIZE };
189     Attribute *retAttribute = CreateAttributeFromDataAndSignTlv(retInfo, true);
190     EXPECT_EQ(retAttribute, nullptr);
191     retInfo.len = 0;
192     retAttribute = CreateAttributeFromDataAndSignTlv(retInfo, true);
193     EXPECT_EQ(retAttribute, nullptr);
194     int32_t resultCode = 123;
195     int32_t authType = 1;
196     uint64_t templateId = 456;
197     Attribute *attribute = CreateEmptyAttribute();
198     EXPECT_NE(attribute, nullptr);
199     ResultCode result = SetAttributeInt32(attribute, AUTH_RESULT_CODE, resultCode);
200     EXPECT_EQ(result, RESULT_SUCCESS);
201     result = SetAttributeUint32(attribute, AUTH_TYPE, authType);
202     EXPECT_EQ(result, RESULT_SUCCESS);
203     result = SetAttributeUint64(attribute, AUTH_TEMPLATE_ID, templateId);
204     EXPECT_EQ(result, RESULT_SUCCESS);
205     result = GetAttributeExecutorMsg(attribute, true, &retInfo);
206     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
207 
208     Uint8Array dataAndSignTlv = { (uint8_t *)Malloc(MAX_EXECUTOR_MSG_LEN), MAX_EXECUTOR_MSG_LEN };
209     EXPECT_NE(dataAndSignTlv.data, nullptr);
210     Attribute *msgAttribute = CreateAttributeFromSerializedMsg(retInfo);
211     EXPECT_EQ(msgAttribute, nullptr);
212     result = GetAttributeUint8Array(msgAttribute, AUTH_ROOT, &dataAndSignTlv);
213     EXPECT_EQ(result, RESULT_BAD_PARAM);
214     retAttribute = CreateAttributeFromDataAndSignTlv(dataAndSignTlv, true);
215     EXPECT_EQ(retAttribute, nullptr);
216     retAttribute = CreateAttributeFromDataAndSignTlv(dataAndSignTlv, false);
217     EXPECT_EQ(retAttribute, nullptr);
218 
219     FreeAttribute(&retAttribute);
220     FreeAttribute(&msgAttribute);
221     Free(dataAndSignTlv.data);
222     FreeAttribute(&attribute);
223     Free(retInfo.data);
224 }
225 
226 HWTEST_F(ExecutorMessageTest, TestCreateAttributeFromExecutorMsg, TestSize.Level0)
227 {
228     Uint8Array msg = { (uint8_t *)Malloc(MAX_EXECUTOR_SIZE), MAX_EXECUTOR_SIZE };
229     Attribute *retAttribute = CreateAttributeFromExecutorMsg(msg, true);
230     EXPECT_EQ(retAttribute, nullptr);
231     int32_t resultCode = 1;
232     Attribute *attribute = CreateEmptyAttribute();
233     EXPECT_NE(attribute, nullptr);
234     ResultCode result = SetAttributeInt32(attribute, AUTH_RESULT_CODE, resultCode);
235     EXPECT_EQ(result, RESULT_SUCCESS);
236     result = GetAttributeExecutorMsg(attribute, true, &msg);
237     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
238 
239     retAttribute = CreateAttributeFromExecutorMsg(msg, false);
240     EXPECT_EQ(retAttribute, nullptr);
241     retAttribute = CreateAttributeFromExecutorMsg(msg, true);
242     EXPECT_EQ(retAttribute, nullptr);
243     int32_t retCode;
244     result = GetAttributeInt32(attribute, AUTH_RESULT_CODE, &retCode);
245     EXPECT_EQ(result, RESULT_SUCCESS);
246     EXPECT_EQ(retCode, resultCode);
247     FreeAttribute(&retAttribute);
248     FreeAttribute(&attribute);
249     Free(msg.data);
250 }
251 
252 HWTEST_F(ExecutorMessageTest, TestGetRootSecretFromAttribute, TestSize.Level0)
253 {
254     Attribute *attribute = CreateEmptyAttribute();
255     EXPECT_NE(attribute, nullptr);
256     ExecutorResultInfo resultInfo= {};
257     GetRootSecretFromAttribute(attribute, &resultInfo);
258     uint8_t testUint8Buffer[] = { 'a', 'b', 'c' };
259     Uint8Array rootSecret = { testUint8Buffer, sizeof(testUint8Buffer) };
260     ResultCode result = SetAttributeUint8Array(attribute, AUTH_ROOT_SECRET, rootSecret);
261     EXPECT_EQ(result, RESULT_SUCCESS);
262     GetRootSecretFromAttribute(attribute, &resultInfo);
263     FreeAttribute(&attribute);
264 }
265 
266 HWTEST_F(ExecutorMessageTest, TestGetExecutorResultInfoFromAttribute, TestSize.Level0)
267 {
268     Attribute *attribute = CreateEmptyAttribute();
269     EXPECT_NE(attribute, nullptr);
270     ExecutorResultInfo resultInfo= {};
271     ResultCode result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
272     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
273     constexpr int32_t resultCode = 0;
274     result = SetAttributeInt32(attribute, AUTH_RESULT_CODE, resultCode);
275     EXPECT_EQ(result, RESULT_SUCCESS);
276     result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
277     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
278     constexpr uint64_t templateId = 123;
279     result = SetAttributeUint64(attribute, AUTH_TEMPLATE_ID, templateId);
280     EXPECT_EQ(result, RESULT_SUCCESS);
281     result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
282     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
283     constexpr uint64_t scheduleId = 234;
284     result = SetAttributeUint64(attribute, AUTH_SCHEDULE_ID, scheduleId);
285     EXPECT_EQ(result, RESULT_SUCCESS);
286     result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
287     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
288     constexpr uint64_t authSubType = 0;
289     result = SetAttributeUint64(attribute, AUTH_SUB_TYPE, authSubType);
290     EXPECT_EQ(result, RESULT_SUCCESS);
291     result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
292     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
293     constexpr int32_t remainTimes = 10;
294     result = SetAttributeInt32(attribute, AUTH_REMAIN_COUNT, remainTimes);
295     EXPECT_EQ(result, RESULT_SUCCESS);
296     result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
297     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
298     constexpr int32_t freezingTime = 0;
299     result = SetAttributeInt32(attribute, AUTH_REMAIN_TIME, freezingTime);
300     EXPECT_EQ(result, RESULT_SUCCESS);
301     result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
302     EXPECT_EQ(result, RESULT_GENERAL_ERROR);
303     constexpr uint32_t capabilityLevel = 2;
304     result = SetAttributeUint32(attribute, AUTH_CAPABILITY_LEVEL, capabilityLevel);
305     EXPECT_EQ(result, RESULT_SUCCESS);
306     uint8_t testUint8Buffer[] = { 'a', 'b', 'c' };
307     Uint8Array rootSecret = { testUint8Buffer, sizeof(testUint8Buffer) };
308     result = SetAttributeUint8Array(attribute, AUTH_ROOT_SECRET, rootSecret);
309     EXPECT_EQ(result, RESULT_SUCCESS);
310     result = GetExecutorResultInfoFromAttribute(attribute, &resultInfo);
311     EXPECT_EQ(resultInfo.result, resultCode);
312     EXPECT_EQ(resultInfo.templateId, templateId);
313     EXPECT_EQ(resultInfo.remainTimes, remainTimes);
314     EXPECT_EQ(resultInfo.capabilityLevel, capabilityLevel);
315     FreeAttribute(&attribute);
316 }
317 
318 HWTEST_F(ExecutorMessageTest, TestCreateExecutorResultInfo, TestSize.Level0)
319 {
320     Buffer *tlv = NULL;
321     ExecutorResultInfo *resultInfo = CreateExecutorResultInfo(tlv);
322     EXPECT_EQ(resultInfo, nullptr);
323     Attribute *attribute = CreateEmptyAttribute();
324     EXPECT_NE(attribute, nullptr);
325     constexpr int32_t resultCode = 0;
326     ResultCode result = SetAttributeInt32(attribute, AUTH_RESULT_CODE, resultCode);
327     EXPECT_EQ(result, RESULT_SUCCESS);
328     constexpr uint64_t templateId = 123;
329     result = SetAttributeUint64(attribute, AUTH_TEMPLATE_ID, templateId);
330     EXPECT_EQ(result, RESULT_SUCCESS);
331     constexpr uint64_t scheduleId = 234;
332     result = SetAttributeUint64(attribute, AUTH_SCHEDULE_ID, scheduleId);
333     EXPECT_EQ(result, RESULT_SUCCESS);
334     constexpr uint64_t authSubType = 0;
335     result = SetAttributeUint64(attribute, AUTH_SUB_TYPE, authSubType);
336     EXPECT_EQ(result, RESULT_SUCCESS);
337     constexpr int32_t remainTimes = 10;
338     result = SetAttributeInt32(attribute, AUTH_REMAIN_COUNT, remainTimes);
339     EXPECT_EQ(result, RESULT_SUCCESS);
340     constexpr int32_t freezingTime = 0;
341     result = SetAttributeInt32(attribute, AUTH_REMAIN_TIME, freezingTime);
342     EXPECT_EQ(result, RESULT_SUCCESS);
343     constexpr uint32_t capabilityLevel = 2;
344     result = SetAttributeUint32(attribute, AUTH_CAPABILITY_LEVEL, capabilityLevel);
345     EXPECT_EQ(result, RESULT_SUCCESS);
346     std::vector<uint8_t> data;
347     data.resize(120);
348     Uint8Array retExtraInfo = { data.data(), data.size() };
349     result = GetAttributeExecutorMsg(attribute, false, &retExtraInfo);
350     EXPECT_EQ(result, RESULT_SUCCESS);
351     Buffer *buf = CreateBufferByData(retExtraInfo.data, retExtraInfo.len);
352     EXPECT_NE(buf, nullptr);
353     resultInfo = CreateExecutorResultInfo(buf);
354     EXPECT_EQ(resultInfo, nullptr);
355     DestoryBuffer(buf);
356     FreeAttribute(&attribute);
357 }
358 
359 HWTEST_F(ExecutorMessageTest, TestDestoryExecutorResultInfo, TestSize.Level0)
360 {
361     DestoryExecutorResultInfo(nullptr);
362     ExecutorResultInfo *info1 = new ExecutorResultInfo();
363     EXPECT_NE(info1, nullptr);
364     info1->rootSecret = CreateBufferBySize(10);
365     DestoryExecutorResultInfo(info1);
366     ExecutorResultInfo *info2 = new ExecutorResultInfo();
367     EXPECT_NE(info2, nullptr);
368     info2->rootSecret = nullptr;
369     DestoryExecutorResultInfo(info2);
370 }
371 
372 HWTEST_F(ExecutorMessageTest, TestCreateExecutorMsg, TestSize.Level0)
373 {
374     EXPECT_EQ(CreateExecutorMsg(1, 0, nullptr), nullptr);
375     Uint64Array array = {};
376     array.len = 1;
377     array.data = nullptr;
378     EXPECT_EQ(CreateExecutorMsg(1, 0, &array), nullptr);
379 }
380 
381 HWTEST_F(ExecutorMessageTest, TestDestoryExecutorMsg, TestSize.Level0)
382 {
383     DestoryExecutorMsg(nullptr);
384     ExecutorMsg *msg = (ExecutorMsg *)Malloc(sizeof(ExecutorMsg));
385     EXPECT_NE(msg, nullptr);
386     ASSERT_NE(msg, nullptr);
387     (void)memset_s(msg, sizeof(ExecutorMsg), 0, sizeof(ExecutorMsg));
388     DestoryExecutorMsg(msg);
389 }
390 
391 HWTEST_F(ExecutorMessageTest, TestGetExecutorTemplateList, TestSize.Level0)
392 {
393     g_userInfoList = nullptr;
394     ExecutorInfoHal info = {};
395     info.authType = 1;
396     info.executorSensorHint = 10;
397     Uint64Array array = {};
398     EXPECT_EQ(GetExecutorTemplateList(0, &info, &array), RESULT_UNKNOWN);
399     g_userInfoList = CreateLinkedList(DestroyUserInfoNode);
400     EXPECT_NE(g_userInfoList, nullptr);
401     UserInfo userInfo = {};
402     userInfo.credentialInfoList = CreateLinkedList(DestroyCredentialNode);
403     EXPECT_NE(userInfo.credentialInfoList, nullptr);
404     CredentialInfoHal credInfo = {};
405     credInfo.authType = 1;
406     credInfo.executorSensorHint = 10;
407     uint32_t credNum = 102;
408     for (uint32_t i = 0; i < credNum; ++i) {
409         userInfo.credentialInfoList->insert(userInfo.credentialInfoList, static_cast<void *>(&credInfo));
410     }
411     g_userInfoList->insert(g_userInfoList, static_cast<void *>(&userInfo));
412     EXPECT_EQ(GetExecutorTemplateList(0, &info, &array), RESULT_REACH_LIMIT);
413     info.authType = 2;
414     EXPECT_EQ(GetExecutorTemplateList(0, &info, &array), RESULT_SUCCESS);
415 }
416 
417 HWTEST_F(ExecutorMessageTest, TestAssemblyMessage_001, TestSize.Level0)
418 {
419     g_userInfoList = nullptr;
420     ExecutorInfoHal info = {};
421     info.authType = 1;
422     info.executorSensorHint = 10;
423     EXPECT_EQ(AssemblyMessage(0, &info, 2, nullptr), RESULT_UNKNOWN);
424 }
425 
426 HWTEST_F(ExecutorMessageTest, TestAssemblyMessage_002, TestSize.Level0)
427 {
428     g_userInfoList = CreateLinkedList(DestroyUserInfoNode);
429     EXPECT_NE(g_userInfoList, nullptr);
430     UserInfo *userInfo = static_cast<UserInfo *>(malloc(sizeof(UserInfo)));
431     EXPECT_NE(userInfo, nullptr);
432     static_cast<void>(memset_s(userInfo, sizeof(UserInfo), 0, sizeof(UserInfo)));
433     userInfo->credentialInfoList = CreateLinkedList(DestroyCredentialNode);
434     EXPECT_NE(userInfo->credentialInfoList, nullptr);
435     CredentialInfoHal *credInfo = static_cast<CredentialInfoHal *>(malloc(sizeof(CredentialInfoHal)));
436     EXPECT_NE(credInfo, nullptr);
437     static_cast<void>(memset_s(credInfo, sizeof(CredentialInfoHal), 0, sizeof(CredentialInfoHal)));
438     credInfo->authType = 1;
439     credInfo->executorSensorHint = 10;
440     userInfo->credentialInfoList->insert(userInfo->credentialInfoList, static_cast<void *>(credInfo));
441     g_userInfoList->insert(g_userInfoList, static_cast<void *>(userInfo));
442 
443     ExecutorInfoHal info = {};
444     info.authType = 1;
445     info.executorSensorHint = 20;
446     LinkedList *executorMsg = CreateLinkedList(DestoryExecutorMsg);
447     EXPECT_EQ(AssemblyMessage(0, &info, 2, executorMsg), RESULT_SUCCESS);
448     DestroyLinkedList(executorMsg);
449 
450     executorMsg = CreateLinkedList(DestoryExecutorMsg);
451     info.executorSensorHint = 10;
452     EXPECT_EQ(AssemblyMessage(0, &info, 2, executorMsg), RESULT_SUCCESS);
453     DestroyLinkedList(executorMsg);
454     DestroyUserInfoList();
455 }
456 
457 HWTEST_F(ExecutorMessageTest, TestTraverseExecutor, TestSize.Level0)
458 {
459     g_poolList = nullptr;
460     g_userInfoList = nullptr;
461     EXPECT_EQ(TraverseExecutor(0, 1, 0, nullptr), RESULT_UNKNOWN);
462     InitResourcePool();
463     ExecutorInfoHal info = {};
464     info.executorRole = VERIFIER;
465     info.authType = 2;
466     g_poolList->insert(g_poolList, static_cast<void *>(&info));
467     LinkedList *executorMsg = new LinkedList();
468     EXPECT_EQ(TraverseExecutor(0, 2, 0, executorMsg), RESULT_UNKNOWN);
469     delete executorMsg;
470 }
471 
472 HWTEST_F(ExecutorMessageTest, TestGetExecutorMsgList, TestSize.Level0)
473 {
474     g_poolList = nullptr;
475     g_userInfoList = nullptr;
476     EXPECT_EQ(GetExecutorMsgList(1, 2, nullptr), RESULT_BAD_PARAM);
477     LinkedList *executorMsg = nullptr;
478     EXPECT_EQ(GetExecutorMsgList(1, 0, &executorMsg), RESULT_UNKNOWN);
479     InitResourcePool();
480     ExecutorInfoHal info = {};
481     info.executorRole = VERIFIER;
482     info.authType = 1;
483     g_poolList->insert(g_poolList, static_cast<void *>(&info));
484     EXPECT_EQ(GetExecutorMsgList(1, 4, &executorMsg), RESULT_SUCCESS);
485 }
486 } // namespace UserAuth
487 } // namespace UserIam
488 } // namespace OHOS
489