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