• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <cinttypes>
17 #include <gtest/gtest.h>
18 #include <securec.h>
19 #include <sys/time.h>
20 
21 #include "auth_channel.h"
22 #include "auth_common.h"
23 #include "auth_connection.h"
24 #include "auth_hichain.h"
25 #include "auth_interface.c"
26 #include "auth_interface.h"
27 #include "auth_log.h"
28 #include "auth_manager.h"
29 #include "auth_request.h"
30 #include "auth_session_fsm.h"
31 #include "auth_session_key.h"
32 #include "auth_session_message.h"
33 #include "auth_tcp_connection.c"
34 #include "auth_tcp_connection.h"
35 #include "common_list.h"
36 #include "lnn_net_builder.h"
37 #include "softbus_access_token_test.h"
38 #include "softbus_adapter_crypto.h"
39 #include "softbus_adapter_mem.h"
40 #include "softbus_error_code.h"
41 #include "softbus_socket.h"
42 
43 namespace OHOS {
44 using namespace testing::ext;
45 constexpr uint32_t TEST_DATA_LEN = 10;
46 constexpr uint32_t CRYPT_DATA_LEN = 200;
47 constexpr uint32_t ENCRYPT_OVER_HEAD_LEN_TEST = 32;
48 constexpr char P2P_MAC[BT_MAC_LEN] = "01:02:03:04:05:06";
49 constexpr char P2P_MAC2[BT_MAC_LEN] = { 0 };
50 constexpr char UUID_TEST[UUID_BUF_LEN] = "0123456789ABC";
51 constexpr char UUID_TEST2[UUID_BUF_LEN] = { 0 };
52 static constexpr int32_t DEFALUT_USERID = 100;
53 
54 #define LINK_TYPE      10
55 #define CLIENT_PORT    6666
56 #define KEEPALIVE_TIME 601
57 
58 class AuthTest : public testing::Test {
59 public:
60     static void SetUpTestCase();
61     static void TearDownTestCase();
62     void SetUp();
63     void TearDown();
64 };
65 
SetUpTestCase()66 void AuthTest::SetUpTestCase()
67 {
68     SetAccessTokenPermission("AuthTest");
69 }
70 
TearDownTestCase()71 void AuthTest::TearDownTestCase() { }
72 
SetUp()73 void AuthTest::SetUp()
74 {
75     AUTH_LOGI(AUTH_TEST, "AuthTest start");
76 }
77 
OnGroupCreated(const char * groupId,int32_t groupType)78 static void OnGroupCreated(const char *groupId, int32_t groupType)
79 {
80     (void)groupId;
81     (void)groupType;
82     return;
83 }
84 
OnGroupDeleted(const char * groupId,int32_t groupType)85 static void OnGroupDeleted(const char *groupId, int32_t groupType)
86 {
87     (void)groupId;
88     (void)groupType;
89     return;
90 }
91 
OnDeviceNotTrusted(const char * udid,int32_t localUserId)92 static void OnDeviceNotTrusted(const char *udid, int32_t localUserId)
93 {
94     (void)udid;
95     (void)localUserId;
96     return;
97 }
98 
OnDeviceBound(const char * udid,const char * groupInfo)99 static void OnDeviceBound(const char *udid, const char *groupInfo)
100 {
101     (void)udid;
102     (void)groupInfo;
103     return;
104 }
105 
TearDown()106 void AuthTest::TearDown() { }
107 
108 /*
109  * @tc.name: AUTH_COMMON_Test_001
110  * @tc.desc: auth commone test
111  * @tc.type: FUNC
112  * @tc.require:
113  */
114 HWTEST_F(AuthTest, AUTH_COMMON_Test_001, TestSize.Level1)
115 {
116     int32_t ret = AuthCommonInit();
117     EXPECT_TRUE(ret == SOFTBUS_OK);
118 }
119 
120 /*
121  * @tc.name: REG_TRUST_DATA_CHANGE_LISTENER_Test_001
122  * @tc.desc: trust data change listener test
123  * @tc.type: FUNC
124  * @tc.require:
125  */
126 HWTEST_F(AuthTest, REG_TRUST_DATA_CHANGE_LISTENER_Test_001, TestSize.Level1)
127 {
128     int32_t ret;
129     const TrustDataChangeListener listener = {
130         .onGroupCreated = OnGroupCreated,
131         .onGroupDeleted = OnGroupDeleted,
132         .onDeviceNotTrusted = OnDeviceNotTrusted,
133         .onDeviceBound = OnDeviceBound,
134     };
135 
136     ret = RegTrustDataChangeListener(nullptr);
137     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
138     ret = RegTrustDataChangeListener(&listener);
139     EXPECT_TRUE(ret == SOFTBUS_OK || ret == SOFTBUS_AUTH_REG_DATA_FAIL);
140 }
141 
142 /*
143  * @tc.name: HICHAIN_START_AUTH_Test_001
144  * @tc.desc: hichain start auth test
145  * @tc.type: FUNC
146  * @tc.require:
147  */
148 HWTEST_F(AuthTest, HICHAIN_START_AUTH_Test_001, TestSize.Level1)
149 {
150     int64_t authSeq = 0;
151     const char *udid = "testdata";
152     const char *uid = "testdata";
153     int32_t ret;
154 
155     ret = HichainStartAuth(authSeq, nullptr, uid, DEFALUT_USERID);
156     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
157     ret = HichainStartAuth(authSeq, udid, nullptr, DEFALUT_USERID);
158     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
159     (void)HichainStartAuth(authSeq, udid, uid, DEFALUT_USERID);
160 }
161 
162 /*
163  * @tc.name: HICHAIN_PROCESS_DATA_Test_001
164  * @tc.desc: hichain process data test
165  * @tc.type: FUNC
166  * @tc.require:
167  */
168 HWTEST_F(AuthTest, HICHAIN_PROCESS_DATA_Test_001, TestSize.Level1)
169 {
170     int64_t authSeq = 0;
171     const uint8_t data[TEST_DATA_LEN] = { 0 };
172     uint32_t len = TEST_DATA_LEN;
173     int32_t ret;
174 
175     ret = HichainProcessData(authSeq, nullptr, len);
176     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
177     ret = HichainProcessData(authSeq, data, len);
178     EXPECT_NE(ret, SOFTBUS_OK);
179 }
180 
181 /*
182  * @tc.name: ADD_AUTH_REQUEST_Test_001
183  * @tc.desc: add auth request test
184  * @tc.type: FUNC
185  * @tc.require:
186  */
187 HWTEST_F(AuthTest, ADD_AUTH_REQUEST_Test_001, TestSize.Level1)
188 {
189     const AuthRequest request = { 0 };
190 
191     int32_t ret = AddAuthRequest(&request);
192     EXPECT_TRUE(ret == SOFTBUS_OK);
193 }
194 
195 /*
196  * @tc.name: GET_AUTH_REQUEST_Test_001
197  * @tc.desc: get auth request test
198  * @tc.type: FUNC
199  * @tc.require:
200  */
201 HWTEST_F(AuthTest, GET_AUTH_REQUEST_Test_001, TestSize.Level1)
202 {
203     uint32_t requestId = 1;
204     AuthRequest request = { 0 };
205 
206     int32_t ret = GetAuthRequest(requestId, &request);
207     EXPECT_TRUE(ret == SOFTBUS_NOT_FIND);
208 }
209 
210 /*
211  * @tc.name: AUTH_SESSION_PROCESS_DEVID_DATA_Test_001
212  * @tc.desc: auth session process devId data test
213  * @tc.type: FUNC
214  * @tc.require:
215  */
216 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEVID_DATA_Test_001, TestSize.Level1)
217 {
218     int64_t authSeq = 0;
219     uint32_t len = 1;
220     int32_t ret;
221 
222     ret = AuthSessionProcessDevIdData(authSeq, nullptr, len);
223     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
224 }
225 
226 /*
227  * @tc.name: AUTH_SESSION_POST_AUTH_DATA_Test_001
228  * @tc.desc: auth session post auth data test
229  * @tc.type: FUNC
230  * @tc.require:
231  */
232 HWTEST_F(AuthTest, AUTH_SESSION_POST_AUTH_DATA_Test_001, TestSize.Level1)
233 {
234     int64_t authSeq = -1;
235     uint32_t len = 1;
236     int32_t ret;
237 
238     ret = AuthSessionPostAuthData(authSeq, nullptr, len);
239     EXPECT_TRUE(ret != SOFTBUS_OK);
240 }
241 
242 /*
243  * @tc.name: AUTH_SESSION_PROCESS_AUTH_DATA_Test_001
244  * @tc.desc: auth session process auth data test
245  * @tc.type: FUNC
246  * @tc.require:
247  */
248 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_AUTH_DATA_Test_001, TestSize.Level1)
249 {
250     int64_t authSeq = 0;
251     uint32_t len = 1;
252     int32_t ret;
253 
254     ret = AuthSessionProcessAuthData(authSeq, nullptr, len);
255     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
256 }
257 
258 /*
259  * @tc.name: AUTH_SESSION_GET_UDID_Test_001
260  * @tc.desc: auth session get udid test
261  * @tc.type: FUNC
262  * @tc.require:
263  */
264 HWTEST_F(AuthTest, AUTH_SESSION_GET_UDID_Test_001, TestSize.Level1)
265 {
266     int64_t authSeq = 0;
267     char udid[UDID_BUF_LEN] = { 0 };
268     uint32_t size = UDID_BUF_LEN;
269     int32_t ret;
270 
271     ret = AuthSessionGetUdid(authSeq, nullptr, size);
272     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
273     authSeq = -1;
274     ret = AuthSessionGetUdid(authSeq, udid, size);
275     EXPECT_TRUE(ret != SOFTBUS_OK);
276 }
277 
278 /*
279  * @tc.name: AUTH_SESSION_SAVE_SESSIONKEY_Test_001
280  * @tc.desc: auth session save sessionKey test
281  * @tc.type: FUNC
282  * @tc.require:
283  */
284 HWTEST_F(AuthTest, AUTH_SESSION_SAVE_SESSIONKEY_Test_001, TestSize.Level1)
285 {
286     int64_t authSeq = 0;
287     uint32_t len = 1;
288     int32_t ret;
289 
290     ret = AuthSessionSaveSessionKey(authSeq, nullptr, len);
291     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
292 }
293 
294 /*
295  * @tc.name: AUTH_SESSION_PROCESS_DEVINFO_DATA_Test_001
296  * @tc.desc: auth session process devInfo data test
297  * @tc.type: FUNC
298  * @tc.require:
299  */
300 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEVINFO_DATA_Test_001, TestSize.Level1)
301 {
302     int64_t authSeq = 0;
303     uint32_t len = 1;
304     int32_t ret;
305 
306     ret = AuthSessionProcessDevInfoData(authSeq, nullptr, len);
307     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
308 }
309 
310 /*
311  * @tc.name: AUTH_SESSION_PROCESS_CLOSE_ACK_Test_001
312  * @tc.desc: auth session process close ack test
313  * @tc.type: FUNC
314  * @tc.require:
315  */
316 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_CLOSE_ACK_Test_001, TestSize.Level1)
317 {
318     int64_t authSeq = 0;
319     uint32_t len = 1;
320     int32_t ret;
321 
322     ret = AuthSessionProcessCloseAck(authSeq, nullptr, len);
323     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
324 }
325 
326 /*
327  * @tc.name: AUTH_SESSION_PROCESS_CLOSE_ACK_BY_CONNID_Test_001
328  * @tc.desc: auth session process close ack by connId test
329  * @tc.type: FUNC
330  * @tc.require:
331  */
332 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_CLOSE_ACK_BY_CONNID_Test_001, TestSize.Level1)
333 {
334     uint64_t connId = 0;
335     bool isServer = true;
336     const uint8_t data[TEST_DATA_LEN] = { 0 };
337     uint32_t len = TEST_DATA_LEN;
338     int32_t ret;
339 
340     ret = AuthSessionProcessCloseAckByConnId(connId, isServer, nullptr, len);
341     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
342     ret = AuthSessionProcessCloseAckByConnId(connId, isServer, data, len);
343     EXPECT_TRUE(ret != SOFTBUS_OK);
344 }
345 
346 /*
347  * @tc.name: AUTH_SESSION_PROCESS_CANCEL_AUTH_BY_CONNID_Test_001
348  * @tc.desc: auth session process cancel auth by connId test
349  * @tc.type: FUNC
350  * @tc.require:
351  */
352 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_CANCEL_AUTH_BY_CONNID_Test_001, TestSize.Level1)
353 {
354     uint64_t connId = 0;
355     bool isServer = true;
356     const uint8_t data[TEST_DATA_LEN] = { 0 };
357     uint32_t len = TEST_DATA_LEN;
358     int32_t ret;
359 
360     ret = AuthSessionProcessCancelAuthByConnId(connId, isServer, nullptr, len);
361     EXPECT_TRUE(ret == SOFTBUS_AUTH_GET_FSM_FAIL);
362     ret = AuthSessionProcessCancelAuthByConnId(connId, isServer, data, len);
363     EXPECT_TRUE(ret == SOFTBUS_AUTH_GET_FSM_FAIL);
364     ret = AuthSessionProcessCancelAuthByConnId(connId, !isServer, data, len);
365     EXPECT_TRUE(ret == SOFTBUS_AUTH_GET_FSM_FAIL);
366     ret = AuthSessionProcessCancelAuthByConnId(connId, !isServer, nullptr, len);
367     EXPECT_TRUE(ret == SOFTBUS_AUTH_GET_FSM_FAIL);
368 }
369 
370 /*
371  * @tc.name: AUTH_SESSION_HANDLE_DEVICE_NOT_TRUSTED_Test_001
372  * @tc.desc: auth session handle device not trusted test
373  * @tc.type: FUNC
374  * @tc.require:
375  */
376 HWTEST_F(AuthTest, AUTH_SESSION_HANDLE_DEVICE_NOT_TRUSTED_Test_001, TestSize.Level1)
377 {
378     const char *udid = "testdata";
379     int32_t ret;
380 
381     ret = AuthSessionHandleDeviceNotTrusted(nullptr);
382     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
383     ret = AuthSessionHandleDeviceNotTrusted(udid);
384     EXPECT_TRUE(ret == SOFTBUS_OK);
385     const char *udid1 = "";
386     ret = AuthSessionHandleDeviceNotTrusted(udid1);
387     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
388 }
389 
390 /*
391  * @tc.name: ENCRYPT_INNER_Test_001
392  * @tc.desc: encrypt inner test
393  * @tc.type: FUNC
394  * @tc.require:
395  */
396 HWTEST_F(AuthTest, ENCRYPT_INNER_Test_001, TestSize.Level1)
397 {
398     SessionKeyList list = { 0 };
399     SessionKey sessionKey = { { 0 }, TEST_DATA_LEN };
400     int64_t authSeq = 0;
401     const uint8_t inData[CRYPT_DATA_LEN] = { 0 };
402     uint8_t *outData = nullptr;
403     uint32_t outLen = 0;
404     int32_t ret;
405     InDataInfo inDataInfo = { .inData = nullptr, .inLen = CRYPT_DATA_LEN };
406     ret = EncryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, &outLen);
407     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
408     SoftBusFree(outData);
409     inDataInfo.inData = inData;
410     ret = EncryptInner(nullptr, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, &outLen);
411     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
412     SoftBusFree(outData);
413     ret = EncryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, nullptr, &outLen);
414     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
415     SoftBusFree(outData);
416     ret = EncryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, nullptr);
417     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
418     SoftBusFree(outData);
419     inDataInfo.inLen = 0;
420     ret = EncryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, nullptr);
421     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
422     SoftBusFree(outData);
423     ListInit(&list);
424     ret = AddSessionKey(&list, TO_INT32(authSeq), &sessionKey, AUTH_LINK_TYPE_WIFI, false);
425     EXPECT_TRUE(ret == SOFTBUS_OK);
426     inDataInfo.inLen = CRYPT_DATA_LEN;
427     ret = EncryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, &outLen);
428     EXPECT_TRUE(ret == SOFTBUS_ENCRYPT_ERR);
429     SoftBusFree(outData);
430 }
431 
432 /*
433  * @tc.name: DENCRYPT_INNER_Test_001
434  * @tc.desc: dencrypt inner test
435  * @tc.type: FUNC
436  * @tc.require:
437  */
438 HWTEST_F(AuthTest, DENCRYPT_INNER_Test_001, TestSize.Level1)
439 {
440     SessionKeyList list = { 0 };
441     SessionKey sessionKey = { { 0 }, TEST_DATA_LEN };
442     int64_t authSeq = 0;
443     const uint8_t inData[CRYPT_DATA_LEN] = { 0 };
444     uint8_t *outData = nullptr;
445     uint32_t outLen = 0;
446     int32_t ret;
447     InDataInfo inDataInfo = { .inData = nullptr, .inLen = CRYPT_DATA_LEN };
448     ret = DecryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, &outLen);
449     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
450     SoftBusFree(outData);
451     inDataInfo.inData = inData;
452     ret = DecryptInner(nullptr, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, &outLen);
453     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
454     SoftBusFree(outData);
455     ret = DecryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, nullptr, &outLen);
456     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
457     SoftBusFree(outData);
458     ret = DecryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, nullptr);
459     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
460     SoftBusFree(outData);
461     inDataInfo.inLen = 0;
462     ret = DecryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, &outLen);
463     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
464     SoftBusFree(outData);
465     ListInit(&list);
466     ret = AddSessionKey(&list, TO_INT32(authSeq), &sessionKey, AUTH_LINK_TYPE_WIFI, false);
467     EXPECT_TRUE(ret == SOFTBUS_OK);
468     inDataInfo.inLen = CRYPT_DATA_LEN;
469     ret = DecryptInner(&list, AUTH_LINK_TYPE_WIFI, &inDataInfo, &outData, &outLen);
470     EXPECT_TRUE(ret == SOFTBUS_DECRYPT_ERR);
471     SoftBusFree(outData);
472 }
473 
474 /*
475  * @tc.name: POST_DEVICEID_MESSAGE_Test_001
476  * @tc.desc: post deviceId message test
477  * @tc.type: FUNC
478  * @tc.require:
479  */
480 HWTEST_F(AuthTest, POST_DEVICEID_MESSAGE_Test_001, TestSize.Level1)
481 {
482     int64_t authSeq = 0;
483     int64_t errAuthSeq = -1;
484     const AuthSessionInfo info = { 0 };
485     int32_t ret;
486 
487     ret = PostDeviceIdMessage(errAuthSeq, &info);
488     EXPECT_TRUE(ret != SOFTBUS_OK);
489     ret = PostDeviceIdMessage(authSeq, &info);
490     EXPECT_TRUE(ret != SOFTBUS_OK);
491 }
492 
493 /*
494  * @tc.name: POST_DEVICE_INFO_MESSAGE_Test_001
495  * @tc.desc: post device info message test
496  * @tc.type: FUNC
497  * @tc.require:
498  */
499 HWTEST_F(AuthTest, POST_DEVICE_INFO_MESSAGE_Test_001, TestSize.Level1)
500 {
501     int64_t authSeq = 0;
502     int64_t errAuthSeq = -1;
503     const AuthSessionInfo info = { 0 };
504     int32_t ret;
505 
506     ret = PostDeviceInfoMessage(errAuthSeq, &info);
507     EXPECT_TRUE(ret != SOFTBUS_OK);
508     ret = PostDeviceInfoMessage(authSeq, &info);
509     EXPECT_TRUE(ret != SOFTBUS_OK);
510 }
511 
512 /*
513  * @tc.name: PROCESS_DEVICE_INFO_MESSAGE_Test_001
514  * @tc.desc: process device info message test
515  * @tc.type: FUNC
516  * @tc.require:
517  */
518 HWTEST_F(AuthTest, PROCESS_DEVICE_INFO_MESSAGE_Test_001, TestSize.Level1)
519 {
520     int64_t authSeq = 0;
521     AuthSessionInfo info = { 0 };
522     const uint8_t data[TEST_DATA_LEN] = { 0 };
523     uint32_t len = TEST_DATA_LEN;
524 
525     int32_t ret = ProcessDeviceInfoMessage(authSeq, &info, data, len);
526     EXPECT_TRUE(ret == SOFTBUS_DECRYPT_ERR);
527     info.normalizedType = NORMALIZED_SUPPORT;
528     ret = ProcessDeviceInfoMessage(authSeq, &info, data, len);
529     EXPECT_TRUE(ret == SOFTBUS_DECRYPT_ERR);
530     info.normalizedType = NORMALIZED_KEY_ERROR;
531     ret = ProcessDeviceInfoMessage(authSeq, &info, data, len);
532     EXPECT_TRUE(ret == SOFTBUS_DECRYPT_ERR);
533 }
534 
535 /*
536  * @tc.name: POST_CLOSE_ACK_MESSAGE_Test_001
537  * @tc.desc: post close ack message test
538  * @tc.type: FUNC
539  * @tc.require:
540  */
541 HWTEST_F(AuthTest, POST_CLOSE_ACK_MESSAGE_Test_001, TestSize.Level1)
542 {
543     int64_t authSeq = 0;
544     int64_t errAuthSeq = -1;
545     const AuthSessionInfo info = { 0 };
546     int32_t ret;
547 
548     ret = PostDeviceInfoMessage(errAuthSeq, &info);
549     EXPECT_TRUE(ret != SOFTBUS_OK);
550     ret = PostDeviceInfoMessage(authSeq, &info);
551     EXPECT_TRUE(ret != SOFTBUS_OK);
552 }
553 
554 /*
555  * @tc.name: POST_HICHAIN_AUTH_MESSAGE_Test_001
556  * @tc.desc: post hichain auth message test
557  * @tc.type: FUNC
558  * @tc.require:
559  */
560 HWTEST_F(AuthTest, POST_HICHAIN_AUTH_MESSAGE_Test_001, TestSize.Level1)
561 {
562     int64_t authSeq = 0;
563     const AuthSessionInfo info = { 0 };
564     const uint8_t data[TEST_DATA_LEN] = { 0 };
565     uint32_t len = TEST_DATA_LEN;
566 
567     int32_t ret = PostHichainAuthMessage(authSeq, &info, data, len);
568     EXPECT_TRUE(ret != SOFTBUS_OK);
569 }
570 
571 /*
572  * @tc.name: POST_DEVICE_MESSAGE_Test_001
573  * @tc.desc: post device message test
574  * @tc.type: FUNC
575  * @tc.require:
576  */
577 HWTEST_F(AuthTest, POST_DEVICE_MESSAGE_Test_001, TestSize.Level1)
578 {
579     AuthManager auth = { 0 };
580     int32_t flagRelay = 1;
581     DeviceMessageParse messageParse = { CODE_VERIFY_DEVICE, DEFAULT_FREQ_CYCLE };
582     InitSessionKeyList(&auth.sessionKeyList);
583     int32_t ret = PostDeviceMessage(&auth, flagRelay, AUTH_LINK_TYPE_WIFI, &messageParse);
584     EXPECT_TRUE(ret == SOFTBUS_ENCRYPT_ERR);
585     messageParse.messageType = CODE_TCP_KEEPALIVE;
586     ret = PostDeviceMessage(&auth, flagRelay, AUTH_LINK_TYPE_WIFI, &messageParse);
587     EXPECT_TRUE(ret == SOFTBUS_ENCRYPT_ERR);
588 }
589 
590 /*
591  * @tc.name: POST_DEVICE_MESSAGE_Test_002
592  * @tc.desc: post device message test
593  * @tc.type: FUNC
594  * @tc.require:
595  */
596 HWTEST_F(AuthTest, POST_DEVICE_MESSAGE_Test_002, TestSize.Level1)
597 {
598     const AuthManager *auth = nullptr;
599     AuthManager authManager;
600     int32_t flagRelay = 1;
601     int32_t type = 0;
602     DeviceMessageParse messageParse = { CODE_VERIFY_DEVICE, DEFAULT_FREQ_CYCLE };
603     (void)memset_s(&authManager, sizeof(AuthManager), 0, sizeof(AuthManager));
604     int32_t ret = PostDeviceMessage(auth, flagRelay, AUTH_LINK_TYPE_WIFI, &messageParse);
605     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
606     ret = PostDeviceMessage(&authManager, flagRelay, AuthLinkType(type), nullptr);
607     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
608     ret = PostDeviceMessage(&authManager, flagRelay, AuthLinkType(type), &messageParse);
609     EXPECT_NE(ret, SOFTBUS_OK);
610     type = LINK_TYPE;
611     ret = PostDeviceMessage(&authManager, flagRelay, AuthLinkType(type), &messageParse);
612     EXPECT_NE(ret, SOFTBUS_OK);
613 }
614 
615 /*
616  * @tc.name: START_SOCKET_LISTENING_Test_001
617  * @tc.desc: start socket listening test
618  * @tc.type: FUNC
619  * @tc.require:
620  */
621 HWTEST_F(AuthTest, START_SOCKET_LISTENING_Test_001, TestSize.Level1)
622 {
623     LocalListenerInfo info = {
624         .type = CONNECT_TCP,
625         .socketOption = {
626             .addr = "192.168.12.1",
627             .port = 22,
628             .moduleId = AUTH,
629             .protocol = LNN_PROTOCOL_IP,
630         },
631     };
632     int32_t ret = StartSocketListening(AUTH, &info);
633     EXPECT_NE(ret, SOFTBUS_OK);
634 }
635 
636 /*
637  * @tc.name: SOCKET_CONNECT_DEVICE_Test_001
638  * @tc.desc: socket connect device test
639  * @tc.type: FUNC
640  * @tc.require:
641  */
642 HWTEST_F(AuthTest, SOCKET_CONNECT_DEVICE_Test_001, TestSize.Level1)
643 {
644     const char *ip = "***.***.**.*";
645     int32_t port = 22;
646     bool isBlockMode = true;
647 
648     int32_t ret = SocketConnectDevice(ip, port, isBlockMode);
649     EXPECT_TRUE(ret == AUTH_INVALID_FD);
650 }
651 
652 /*
653  * @tc.name: SOCKER_POST_BYTES_Test_001
654  * @tc.desc: socket post bytes test
655  * @tc.type: FUNC
656  * @tc.require:
657  */
658 HWTEST_F(AuthTest, SOCKER_POST_BYTES_Test_001, TestSize.Level1)
659 {
660     int32_t fd = 1;
661     const AuthDataHead head = { 0 };
662     const uint8_t data[TEST_DATA_LEN] = { 0 };
663 
664     int32_t ret = SocketPostBytes(fd, &head, data);
665     EXPECT_NE(ret, SOFTBUS_OK);
666 }
667 
668 /*
669  * @tc.name: SOCKER_GET_CONN_INFO_Test_001
670  * @tc.desc: socket get conn info test
671  * @tc.type: FUNC
672  * @tc.require:
673  */
674 HWTEST_F(AuthTest, SOCKER_GET_CONN_INFO_Test_001, TestSize.Level1)
675 {
676     int32_t fd = 1;
677     AuthConnInfo connInfo;
678     bool isServer = true;
679 
680     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
681     int32_t ret = SocketGetConnInfo(fd, &connInfo, &isServer);
682     EXPECT_NE(ret, SOFTBUS_OK);
683 }
684 
685 /*
686  * @tc.name: REGAUTH_CHANNEL_LISTENER_Test_001
687  * @tc.desc: regauth channel listener test
688  * @tc.type: FUNC
689  * @tc.require:
690  */
691 HWTEST_F(AuthTest, REGAUTH_CHANNEL_LISTENER_Test_001, TestSize.Level1)
692 {
693     int32_t module = 0;
694     AuthChannelListener listener = { 0 };
695     int32_t ret;
696 
697     ret = RegAuthChannelListener(module, nullptr);
698     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
699     listener.onDataReceived = nullptr;
700     ret = RegAuthChannelListener(module, &listener);
701     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
702 }
703 
704 /*
705  * @tc.name: AUTH_OPRN_CHANNEL_Test_001
706  * @tc.desc: auth open channel test
707  * @tc.type: FUNC
708  * @tc.require:
709  */
710 HWTEST_F(AuthTest, AUTH_OPRN_CHANNEL_Test_001, TestSize.Level1)
711 {
712     const char *ip = "***.***.**.*";
713     int32_t port = 1;
714     int32_t ret;
715 
716     ret = AuthOpenChannel(nullptr, port);
717     EXPECT_TRUE(ret == INVALID_CHANNEL_ID);
718     port = 0;
719     ret = AuthOpenChannel(ip, port);
720     EXPECT_TRUE(ret == INVALID_CHANNEL_ID);
721 }
722 
723 /*
724  * @tc.name: AUTH_POST_CHANNEL_DATA_Test_001
725  * @tc.desc: auth post channel data test
726  * @tc.type: FUNC
727  * @tc.require:
728  */
729 HWTEST_F(AuthTest, AUTH_POST_CHANNEL_DATA_Test_001, TestSize.Level1)
730 {
731     int32_t channelId = -1;
732     const uint8_t testData[TEST_DATA_LEN] = { 0 };
733     AuthChannelData data = {
734         .module = 0,
735         .flag = 0,
736         .seq = 0,
737         .len = TEST_DATA_LEN,
738         .data = nullptr,
739     };
740     int32_t ret;
741 
742     ret = AuthPostChannelData(channelId, &data);
743     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
744     channelId = 0;
745     ret = AuthPostChannelData(channelId, nullptr);
746     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
747     data.len = 0;
748     ret = AuthPostChannelData(channelId, &data);
749     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
750     data.len = 0;
751     data.data = testData;
752     ret = AuthPostChannelData(channelId, &data);
753     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
754 }
755 
756 /*
757  * @tc.name: AUTH_MANAGER_SET_SESSION_KEY_Test_001
758  * @tc.desc: auth manager set session key test
759  * @tc.type: FUNC
760  * @tc.require:
761  */
762 HWTEST_F(AuthTest, AUTH_MANAGER_SET_SESSION_KEY_Test_001, TestSize.Level1)
763 {
764     int64_t authSeq = 0;
765     AuthSessionInfo info = { 0 };
766     const SessionKey sessionKey = { { 0 }, TEST_DATA_LEN };
767 
768     info.connInfo.type = AUTH_LINK_TYPE_BLE;
769     int32_t ret = AuthManagerSetSessionKey(authSeq, &info, &sessionKey, false, false);
770     EXPECT_TRUE(ret == SOFTBUS_OK);
771 }
772 
773 /*
774  * @tc.name: AUTH_MANAGER_GET_SESSION_KEY_Test_001
775  * @tc.desc: auth manager get session key test
776  * @tc.type: FUNC
777  * @tc.require:
778  */
779 HWTEST_F(AuthTest, AUTH_MANAGER_GET_SESSION_KEY_Test_001, TestSize.Level1)
780 {
781     int64_t authSeq = 0;
782     AuthSessionInfo info = { 0 };
783     SessionKey sessionKey = { { 0 }, TEST_DATA_LEN };
784 
785     info.connInfo.type = AUTH_LINK_TYPE_BLE;
786     int32_t ret = AuthManagerGetSessionKey(authSeq, &info, &sessionKey);
787     EXPECT_TRUE(ret == SOFTBUS_OK);
788 }
789 
790 /*
791  * @tc.name: REGAUTH_VERIFY_LISTENER_Test_001
792  * @tc.desc: regAuth verify listener test
793  * @tc.type: FUNC
794  * @tc.require:
795  */
796 HWTEST_F(AuthTest, REGAUTH_VERIFY_LISTENER_Test_001, TestSize.Level1)
797 {
798     int32_t ret = RegAuthVerifyListener(nullptr);
799     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
800 }
801 
802 /*
803  * @tc.name: AUTH_START_VERIFY_Test_001
804  * @tc.desc: auth start verify test
805  * @tc.type: FUNC
806  * @tc.require:
807  */
808 HWTEST_F(AuthTest, AUTH_START_VERIFY_Test_001, TestSize.Level1)
809 {
810     AuthConnInfo connInfo;
811     uint32_t requestId = 0;
812     const AuthVerifyCallback callback = { 0 };
813     int32_t ret;
814 
815     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
816     connInfo.type = AUTH_LINK_TYPE_BLE;
817     ret = AuthStartVerify(nullptr, requestId, &callback, AUTH_MODULE_LNN, true);
818     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
819     ret = AuthStartVerify(&connInfo, requestId, nullptr, AUTH_MODULE_LNN, true);
820     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
821 }
822 
823 /*
824  * @tc.name: AUTH_START_CONN_VERIFY_Test_001
825  * @tc.desc: auth start conn verify test
826  * @tc.type: FUNC
827  * @tc.require:
828  */
829 HWTEST_F(AuthTest, AUTH_START_CONN_VERIFY_Test_001, TestSize.Level1)
830 {
831     AuthConnInfo connInfo;
832     uint32_t requestId = 0;
833     const AuthConnCallback callback = { 0 };
834     int32_t ret;
835 
836     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
837     ret = AuthStartConnVerify(nullptr, requestId, &callback, AUTH_MODULE_LNN, true);
838     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
839     ret = AuthStartConnVerify(&connInfo, requestId, &callback, AUTH_MODULE_LNN, true);
840     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
841 }
842 
843 /*
844  * @tc.name: AUTH_FLUSH_DEVICE_Test_001
845  * @tc.desc: auth flush device test
846  * @tc.type: FUNC
847  * @tc.require:
848  */
849 HWTEST_F(AuthTest, AUTH_FLUSH_DEVICE_Test_001, TestSize.Level1)
850 {
851     char uuid[TEST_DATA_LEN] = "testdata";
852     int32_t ret;
853 
854     ret = AuthFlushDevice(nullptr);
855     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
856     uuid[0] = '\0';
857     ret = AuthFlushDevice(const_cast<const char *>(uuid));
858     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
859     uuid[0] = '1';
860     ret = AuthFlushDevice(const_cast<const char *>(uuid));
861     EXPECT_NE(ret, SOFTBUS_OK);
862 }
863 
864 /*
865  * @tc.name: AUTH_SEND_KEEPALIVE_OPTION_Test_001
866  * @tc.desc: auth send keepalive test
867  * @tc.type: FUNC
868  * @tc.require:
869  */
870 HWTEST_F(AuthTest, AUTH_SEND_KEEPALIVE_OPTION_Test_001, TestSize.Level1)
871 {
872     char uuid[TEST_DATA_LEN] = "testdata";
873     int32_t time = 0;
874     int32_t ret;
875 
876     ret = AuthSendKeepaliveOption(nullptr, HIGH_FREQ_CYCLE);
877     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
878     ret = AuthSendKeepaliveOption(uuid, (ModeCycle)time);
879     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
880     uuid[0] = '\0';
881     ret = AuthSendKeepaliveOption(const_cast<const char *>(uuid), HIGH_FREQ_CYCLE);
882     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
883     uuid[0] = '1';
884     ret = AuthSendKeepaliveOption(const_cast<const char *>(uuid), HIGH_FREQ_CYCLE);
885     EXPECT_NE(ret, SOFTBUS_OK);
886 }
887 
888 /*
889  * @tc.name: AUTH_DEVICE_GET_PREFER_CONN_INFO_Test_001
890  * @tc.desc: auth device get prefer conn info test
891  * @tc.type: FUNC
892  * @tc.require:
893  */
894 HWTEST_F(AuthTest, AUTH_DEVICE_GET_PREFER_CONN_INFO_Test_001, TestSize.Level1)
895 {
896     char uuid[TEST_DATA_LEN] = "testdata";
897     AuthConnInfo connInfo;
898     int32_t ret;
899 
900     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
901     ret = AuthDeviceGetPreferConnInfo(nullptr, &connInfo);
902     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
903     uuid[0] = '\0';
904     ret = AuthDeviceGetPreferConnInfo(const_cast<const char *>(uuid), &connInfo);
905     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
906     uuid[0] = '1';
907     ret = AuthDeviceGetPreferConnInfo(const_cast<const char *>(uuid), nullptr);
908     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
909     ret = AuthDeviceGetPreferConnInfo(const_cast<const char *>(uuid), &connInfo);
910     EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
911 }
912 
913 /*
914  * @tc.name: AUTH_DEVICE_POST_TRANS_DATA_Test_001
915  * @tc.desc: auth device post trans data test
916  * @tc.type: FUNC
917  * @tc.require:
918  */
919 HWTEST_F(AuthTest, AUTH_DEVICE_POST_TRANS_DATA_Test_001, TestSize.Level1)
920 {
921     int64_t authId = 0;
922     AuthHandle authHandle = { .authId = authId, .type = AUTH_LINK_TYPE_BLE };
923     int32_t ret;
924     const AuthTransData dataInfo = { 0 };
925     AuthSessionInfo info;
926 
927     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
928     info.isServer = true;
929     info.connInfo.type = AUTH_LINK_TYPE_BLE;
930 
931     AuthManager *auth = NewAuthManager(authId, &info);
932     EXPECT_TRUE(auth != nullptr);
933     ret = AuthDevicePostTransData(authHandle, nullptr);
934     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
935     ret = AuthDevicePostTransData(authHandle, &dataInfo);
936     EXPECT_TRUE(ret == SOFTBUS_ENCRYPT_ERR);
937     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
938 }
939 
940 /*
941  * @tc.name: AUTH_DEVICE_GET_ID_BY_CONN_INFO_Test_001
942  * @tc.desc: auth device get id by conn info test
943  * @tc.type: FUNC
944  * @tc.require:
945  */
946 HWTEST_F(AuthTest, AUTH_DEVICE_GET_ID_BY_CONN_INFO_Test_001, TestSize.Level1)
947 {
948     AuthConnInfo connInfo;
949     int64_t ret;
950 
951     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
952     ret = AuthDeviceGetIdByConnInfo(nullptr, true);
953     EXPECT_TRUE(ret == AUTH_INVALID_ID);
954     connInfo.type = AUTH_LINK_TYPE_BLE;
955     ret = AuthDeviceGetIdByConnInfo(&connInfo, true);
956     EXPECT_TRUE(ret == AUTH_INVALID_ID);
957 }
958 
959 /*
960  * @tc.name: AUTH_DEVICE_GET_ID_BY_P2P_MAC_Test_001
961  * @tc.desc: auth device get id by p2p mac test
962  * @tc.type: FUNC
963  * @tc.require:
964  */
965 HWTEST_F(AuthTest, AUTH_DEVICE_GET_ID_BY_P2P_MAC_Test_001, TestSize.Level1)
966 {
967     AuthLinkType type = AUTH_LINK_TYPE_WIFI;
968     bool isServer = true;
969     int64_t ret;
970     ret = AuthDeviceGetIdByUuid(nullptr, type, isServer);
971     EXPECT_TRUE(ret == AUTH_INVALID_ID);
972     ret = AuthDeviceGetIdByUuid(P2P_MAC2, type, isServer);
973     EXPECT_TRUE(ret == AUTH_INVALID_ID);
974     ret = AuthDeviceGetIdByUuid(P2P_MAC, type, isServer);
975     EXPECT_TRUE(ret == AUTH_INVALID_ID);
976 }
977 
AuthOnDataReceived(AuthHandle authHandle,const AuthTransData * data)978 static void AuthOnDataReceived(AuthHandle authHandle, const AuthTransData *data)
979 {
980     (void)authHandle;
981     (void)data;
982 }
983 
AuthOnDisconnected(AuthHandle authHandle)984 static void AuthOnDisconnected(AuthHandle authHandle)
985 {
986     (void)authHandle;
987 }
988 
989 /*
990  * @tc.name: REGAUTH_TRANS_LISTENER_Test_001
991  * @tc.desc: regAuth trans listener test
992  * @tc.type: FUNC
993  * @tc.require:
994  */
995 HWTEST_F(AuthTest, REGAUTH_TRANS_LISTENER_Test_001, TestSize.Level1)
996 {
997     int32_t module = 0;
998     AuthTransListener listener = {
999         .onDataReceived = AuthOnDataReceived,
1000         .onDisconnected = AuthOnDisconnected,
1001         .onException = nullptr,
1002     };
1003     int32_t ret;
1004     ret = RegAuthTransListener(module, nullptr);
1005     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1006     ret = RegAuthTransListener(module, &listener);
1007     EXPECT_TRUE(ret != SOFTBUS_OK);
1008     RegAuthTransListener(MODULE_UDP_INFO, &listener);
1009     UnregAuthTransListener(MODULE_UDP_INFO);
1010 }
1011 
1012 /*
1013  * @tc.name: AUTH_GET_PREFER_CONNINFO_Test_001
1014  * @tc.desc: auth get prefer connInfo test
1015  * @tc.type: FUNC
1016  * @tc.require:
1017  */
1018 HWTEST_F(AuthTest, AUTH_GET_PREFER_CONNINFO_Test_001, TestSize.Level1)
1019 {
1020     char uuid[TEST_DATA_LEN] = "testdata";
1021     AuthConnInfo connInfo;
1022     int32_t ret;
1023 
1024     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1025     ret = AuthGetPreferConnInfo(nullptr, &connInfo, false);
1026     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1027     ret = AuthGetPreferConnInfo(nullptr, &connInfo, true);
1028     EXPECT_TRUE(ret != SOFTBUS_OK);
1029     ret = AuthGetPreferConnInfo(const_cast<const char *>(uuid), nullptr, false);
1030     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1031     ret = AuthGetPreferConnInfo(const_cast<const char *>(uuid), nullptr, true);
1032     EXPECT_TRUE(ret != SOFTBUS_OK);
1033     uuid[0] = '\0';
1034     ret = AuthGetPreferConnInfo(const_cast<const char *>(uuid), &connInfo, false);
1035     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1036     ret = AuthGetPreferConnInfo(const_cast<const char *>(uuid), &connInfo, true);
1037     EXPECT_TRUE(ret != SOFTBUS_OK);
1038     uuid[0] = '1';
1039     ret = AuthGetPreferConnInfo(const_cast<const char *>(uuid), &connInfo, false);
1040     EXPECT_TRUE(ret != SOFTBUS_OK);
1041     ret = AuthGetPreferConnInfo(const_cast<const char *>(uuid), &connInfo, true);
1042     EXPECT_TRUE(ret != SOFTBUS_OK);
1043 }
1044 
1045 /*
1046  * @tc.name: AUTH_OPEN_CONN_Test_001
1047  * @tc.desc: auth open conn test
1048  * @tc.type: FUNC
1049  * @tc.require:
1050  */
1051 HWTEST_F(AuthTest, AUTH_OPEN_CONN_Test_001, TestSize.Level1)
1052 {
1053     AuthConnInfo info;
1054     uint32_t requestId = 0;
1055     const AuthConnCallback callback = { 0 };
1056     int32_t ret;
1057 
1058     (void)memset_s(&info, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1059     ret = AuthOpenConn(nullptr, requestId, &callback, false);
1060     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1061     ret = AuthOpenConn(&info, requestId, nullptr, false);
1062     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1063     ret = AuthOpenConn(nullptr, requestId, nullptr, false);
1064     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1065     ret = AuthOpenConn(&info, requestId, &callback, false);
1066     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1067     info.type = AUTH_LINK_TYPE_WIFI;
1068     ret = AuthOpenConn(&info, requestId, &callback, false);
1069     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1070     ret = AuthOpenConn(&info, requestId, &callback, true);
1071     EXPECT_TRUE(ret != SOFTBUS_OK);
1072 }
1073 
1074 /*
1075  * @tc.name: AUTH_POST_TRANS_DATA_Test_001
1076  * @tc.desc: auth post trans data test
1077  * @tc.type: FUNC
1078  * @tc.require:
1079  */
1080 HWTEST_F(AuthTest, AUTH_POST_TRANS_DATA_Test_001, TestSize.Level1)
1081 {
1082     int64_t authId = 0;
1083     int32_t ret;
1084     const AuthTransData dataInfo = { 0 };
1085     AuthSessionInfo info;
1086 
1087     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1088     info.isServer = true;
1089     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1090     AuthHandle authHandle = { .authId = 0, .type = info.connInfo.type };
1091 
1092     AuthManager *auth = NewAuthManager(authId, &info);
1093     EXPECT_TRUE(auth != nullptr);
1094     ret = AuthPostTransData(authHandle, nullptr);
1095     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1096     ret = AuthPostTransData(authHandle, &dataInfo);
1097     EXPECT_TRUE(ret == SOFTBUS_ENCRYPT_ERR);
1098     AuthCloseConn(authHandle);
1099     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1100 }
1101 
1102 /*
1103  * @tc.name: REG_GROUP_CHANGE_LISTENER_Test_001
1104  * @tc.desc: Reg Group Change Listener test
1105  * @tc.type: FUNC
1106  * @tc.require:
1107  */
1108 HWTEST_F(AuthTest, REG_GROUP_CHANGE_LISTENER_Test_001, TestSize.Level1)
1109 {
1110     int32_t ret = RegGroupChangeListener(nullptr);
1111     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1112 
1113     const GroupChangeListener listener = { 0 };
1114     ret = RegGroupChangeListener(&listener);
1115     EXPECT_TRUE(ret == SOFTBUS_OK);
1116     UnregGroupChangeListener();
1117 }
1118 
1119 /*
1120  * @tc.name: AUTH_GET_ID_BY_CONN_INFO_Test_001
1121  * @tc.desc: auth get id by conn info test
1122  * @tc.type: FUNC
1123  * @tc.require:
1124  */
1125 HWTEST_F(AuthTest, AUTH_GET_ID_BY_CONN_INFO_Test_001, TestSize.Level1)
1126 {
1127     int64_t ret;
1128 
1129     ret = AuthGetIdByConnInfo(nullptr, true, false);
1130     EXPECT_TRUE(ret == AUTH_INVALID_ID);
1131     ret = AuthGetIdByConnInfo(nullptr, true, true);
1132     EXPECT_TRUE(ret != SOFTBUS_OK);
1133 }
1134 
1135 /*
1136  * @tc.name: AUTH_GET_ID_BY_P2P_MAC_Test_001
1137  * @tc.desc: auth get id by p2p mac test
1138  * @tc.type: FUNC
1139  * @tc.require:
1140  */
1141 HWTEST_F(AuthTest, AUTH_GET_ID_BY_P2P_MAC_Test_001, TestSize.Level1)
1142 {
1143     AuthLinkType type;
1144     int64_t ret;
1145 
1146     type = AUTH_LINK_TYPE_BR;
1147     ret = AuthGetIdByUuid(nullptr, type, true, false);
1148     EXPECT_TRUE(ret == AUTH_INVALID_ID);
1149     ret = AuthGetIdByUuid(nullptr, type, true, true);
1150     EXPECT_TRUE(ret != SOFTBUS_OK);
1151     ret = AuthGetIdByUuid(UUID_TEST, type, true, false);
1152     EXPECT_TRUE(ret == AUTH_INVALID_ID);
1153     ret = AuthGetIdByUuid(UUID_TEST, type, true, true);
1154     EXPECT_TRUE(ret != SOFTBUS_OK);
1155     ret = AuthGetIdByUuid(UUID_TEST2, type, true, false);
1156     EXPECT_TRUE(ret == AUTH_INVALID_ID);
1157     ret = AuthGetIdByUuid(UUID_TEST2, type, true, true);
1158     EXPECT_TRUE(ret != SOFTBUS_OK);
1159 }
1160 
1161 /*
1162  * @tc.name: AUTH_ENCRYPT_Test_001
1163  * @tc.desc: auth encrypt test
1164  * @tc.type: FUNC
1165  * @tc.require:
1166  */
1167 HWTEST_F(AuthTest, AUTH_ENCRYPT_Test_001, TestSize.Level1)
1168 {
1169     int64_t authId = 0;
1170     const uint8_t inData[CRYPT_DATA_LEN] = { 0 };
1171     uint32_t inLen = CRYPT_DATA_LEN;
1172     uint8_t outData[CRYPT_DATA_LEN] = { 0 };
1173     uint32_t outLen = CRYPT_DATA_LEN;
1174     uint32_t errLen = 0;
1175     int32_t ret;
1176     AuthSessionInfo info;
1177 
1178     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1179     info.isServer = true;
1180     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1181     AuthHandle authHandle = { .authId = authId, .type = AUTH_LINK_TYPE_WIFI };
1182     AuthManager *auth = NewAuthManager(authId, &info);
1183     EXPECT_TRUE(auth != nullptr);
1184     ret = AuthEncrypt(&authHandle, nullptr, inLen, outData, &outLen);
1185     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1186     ret = AuthEncrypt(&authHandle, inData, inLen, nullptr, &outLen);
1187     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1188     ret = AuthEncrypt(&authHandle, inData, inLen, outData, nullptr);
1189     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1190     ret = AuthEncrypt(&authHandle, inData, errLen, outData, &outLen);
1191     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1192     ret = AuthEncrypt(&authHandle, inData, inLen, outData, &errLen);
1193     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1194     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1195 }
1196 
1197 /*
1198  * @tc.name: AUTH_DECRYPT_Test_001
1199  * @tc.desc: auth eecrypt test
1200  * @tc.type: FUNC
1201  * @tc.require:
1202  */
1203 HWTEST_F(AuthTest, AUTH_DECRYPT_Test_001, TestSize.Level1)
1204 {
1205     int64_t authId = 0;
1206     const uint8_t inData[CRYPT_DATA_LEN] = { 0 };
1207     uint32_t inLen = CRYPT_DATA_LEN;
1208     uint8_t outData[CRYPT_DATA_LEN] = { 0 };
1209     uint32_t outLen = CRYPT_DATA_LEN;
1210     uint32_t errLen = 0;
1211     int32_t ret;
1212     AuthSessionInfo info;
1213 
1214     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1215     info.isServer = true;
1216     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1217     AuthHandle authHandle = { .authId = authId, .type = AUTH_LINK_TYPE_WIFI };
1218     AuthManager *auth = NewAuthManager(authId, &info);
1219     EXPECT_TRUE(auth != nullptr);
1220     ret = AuthDecrypt(&authHandle, nullptr, inLen, outData, &outLen);
1221     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1222     ret = AuthDecrypt(&authHandle, inData, inLen, nullptr, &outLen);
1223     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1224     ret = AuthDecrypt(&authHandle, inData, inLen, outData, nullptr);
1225     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1226     ret = AuthDecrypt(&authHandle, inData, errLen, outData, &outLen);
1227     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1228     ret = AuthDecrypt(&authHandle, inData, inLen, outData, &errLen);
1229     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1230     ret = AuthDecrypt(&authHandle, inData, inLen, outData, &outLen);
1231     EXPECT_TRUE(ret == SOFTBUS_ENCRYPT_ERR);
1232     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1233 }
1234 
1235 /*
1236  * @tc.name: AUTH_SET_P2P_MAC_Test_001
1237  * @tc.desc: auth set p2p mac test
1238  * @tc.type: FUNC
1239  * @tc.require:
1240  */
1241 HWTEST_F(AuthTest, AUTH_SET_P2P_MAC_Test_001, TestSize.Level1)
1242 {
1243     int64_t authId = 0;
1244     int32_t ret;
1245     AuthSessionInfo info;
1246 
1247     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1248     info.isServer = true;
1249     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1250 
1251     AuthManager *auth = NewAuthManager(authId, &info);
1252     EXPECT_TRUE(auth != nullptr);
1253     ret = AuthSetP2pMac(authId, nullptr);
1254     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1255     ret = AuthSetP2pMac(authId, P2P_MAC);
1256     EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
1257     ret = AuthSetP2pMac(authId, P2P_MAC2);
1258     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1259     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1260 }
1261 
1262 /*
1263  * @tc.name: AUTH_GET_CONN_INFO_Test_001
1264  * @tc.desc: auth get conn info test
1265  * @tc.type: FUNC
1266  * @tc.require:
1267  */
1268 HWTEST_F(AuthTest, AUTH_GET_CONN_INFO_Test_001, TestSize.Level1)
1269 {
1270     int64_t authId = 0;
1271     int32_t ret;
1272     AuthSessionInfo info;
1273 
1274     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1275     info.isServer = true;
1276     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1277     AuthHandle authHandle = { .authId = authId, .type = info.connInfo.type };
1278     AuthManager *auth = NewAuthManager(authId, &info);
1279     EXPECT_TRUE(auth != nullptr);
1280     ret = AuthGetConnInfo(authHandle, nullptr);
1281     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1282     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1283 }
1284 
1285 /*
1286  * @tc.name: AUTH_GET_SERVER_SIDE_Test_001
1287  * @tc.desc: auth get server side test
1288  * @tc.type: FUNC
1289  * @tc.require:
1290  */
1291 HWTEST_F(AuthTest, AUTH_GET_SERVER_SIDE_Test_001, TestSize.Level1)
1292 {
1293     int64_t authId = 0;
1294     int32_t ret;
1295     AuthSessionInfo info;
1296 
1297     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1298     info.isServer = true;
1299     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1300 
1301     AuthManager *auth = NewAuthManager(authId, &info);
1302     EXPECT_TRUE(auth != nullptr);
1303     ret = AuthGetServerSide(authId, nullptr);
1304     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1305     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1306 }
1307 
1308 /*
1309  * @tc.name: AUTH_GET_META_TYPE_Test_001
1310  * @tc.desc: auth get meta type test
1311  * @tc.type: FUNC
1312  * @tc.require:
1313  */
1314 HWTEST_F(AuthTest, AUTH_GET_META_TYPE_Test_001, TestSize.Level1)
1315 {
1316     int64_t authId = 0;
1317     bool isMetaAuth = true;
1318     int32_t ret;
1319 
1320     ret = AuthGetMetaType(authId, nullptr);
1321     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1322     ret = AuthGetMetaType(authId, &isMetaAuth);
1323     EXPECT_TRUE(ret == SOFTBUS_OK);
1324 }
1325 
1326 /*
1327  * @tc.name: AUTH_GET_DEVICE_UUID_Test_001
1328  * @tc.desc: auth get device uuid test
1329  * @tc.type: FUNC
1330  * @tc.require:
1331  */
1332 HWTEST_F(AuthTest, AUTH_GET_DEVICE_UUID_Test_001, TestSize.Level1)
1333 {
1334     int64_t authId = 0;
1335     int32_t ret;
1336     char uuid[TEST_DATA_LEN] = "testdata";
1337     uint16_t size = TEST_DATA_LEN;
1338     AuthSessionInfo info;
1339 
1340     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1341     (void)strcpy_s(info.udid, TEST_DATA_LEN, uuid);
1342     info.isServer = true;
1343     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1344 
1345     AuthManager *auth = NewAuthManager(authId, &info);
1346     EXPECT_TRUE(auth != nullptr);
1347     ret = AuthGetDeviceUuid(authId, nullptr, size);
1348     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1349     ret = AuthGetDeviceUuid(authId, uuid, size);
1350     EXPECT_TRUE(ret == SOFTBUS_OK);
1351     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1352 }
1353 
1354 /*
1355  * @tc.name: AUTH_GET_VERSION_Test_001
1356  * @tc.desc: auth get version test
1357  * @tc.type: FUNC
1358  * @tc.require:
1359  */
1360 HWTEST_F(AuthTest, AUTH_GET_VERSION_Test_001, TestSize.Level1)
1361 {
1362     int64_t authId = 0;
1363     int32_t ret;
1364     SoftBusVersion version;
1365     AuthSessionInfo info;
1366     version = SOFTBUS_OLD_V1;
1367 
1368     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1369     info.isServer = true;
1370     info.connInfo.type = AUTH_LINK_TYPE_BLE;
1371 
1372     AuthManager *auth = NewAuthManager(authId, &info);
1373     EXPECT_TRUE(auth != nullptr);
1374     ret = AuthGetVersion(authId, nullptr);
1375     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1376     ret = AuthGetVersion(authId, &version);
1377     EXPECT_TRUE(ret == SOFTBUS_OK);
1378     DelAuthManager(auth, 0);
1379     DelAuthManager(auth, AUTH_LINK_TYPE_MAX + 1);
1380     DelAuthManager(auth, AUTH_LINK_TYPE_MAX);
1381 }
1382 
1383 /*
1384  * @tc.name: AUTH_INIT_Test_001
1385  * @tc.desc: auth init test
1386  * @tc.type: FUNC
1387  * @tc.require:
1388  */
1389 HWTEST_F(AuthTest, AUTH_INIT_Test_001, TestSize.Level1)
1390 {
1391     int32_t ret;
1392 
1393     ret = AuthInit();
1394     EXPECT_NE(ret, SOFTBUS_OK);
1395     AuthDeinit();
1396 }
1397 
AuthOnDataReceivedTest(AuthHandle authHandle,const AuthDataHead * head,const uint8_t * data,uint32_t len)1398 static void AuthOnDataReceivedTest(AuthHandle authHandle, const AuthDataHead *head, const uint8_t *data, uint32_t len)
1399 {
1400     (void)authHandle;
1401     (void)head;
1402     (void)data;
1403     (void)len;
1404 }
1405 
AuthOnDisconnectedTest(AuthHandle authHandle)1406 static void AuthOnDisconnectedTest(AuthHandle authHandle)
1407 {
1408     (void)authHandle;
1409 }
1410 
1411 /*
1412  * @tc.name: AUTH_INIT_Test_001
1413  * @tc.desc: auth init test
1414  * @tc.type: FUNC
1415  * @tc.require:
1416  */
1417 HWTEST_F(AuthTest, AUTH_DEVICE_INIT_Test_001, TestSize.Level1)
1418 {
1419     int32_t ret;
1420     AuthTransCallback callBack = {
1421         .onDataReceived = AuthOnDataReceivedTest,
1422         .onDisconnected = AuthOnDisconnectedTest,
1423         .onException = nullptr,
1424     };
1425     ret = AuthDeviceInit(&callBack);
1426     EXPECT_NE(ret, SOFTBUS_OK);
1427     ret = AuthDeviceInit(nullptr);
1428     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1429 }
1430 
1431 /*
1432  * @tc.name: POST_AUTH_EVENT_INIT_Test_001
1433  * @tc.desc: post suth event test
1434  * @tc.type: FUNC
1435  * @tc.require:
1436  */
1437 HWTEST_F(AuthTest, POST_AUTH_EVENT_INIT_Test_001, TestSize.Level1)
1438 {
1439     EventHandler handler = { 0 };
1440     const void *obj = "testdata";
1441     uint32_t size = TEST_DATA_LEN;
1442     uint64_t delayMs = 0;
1443     int32_t ret;
1444 
1445     ret = PostAuthEvent(EVENT_CONNECT_CMD, handler, obj, size, delayMs);
1446     EXPECT_TRUE(ret == SOFTBUS_NO_INIT);
1447 }
1448 
1449 /*
1450  * @tc.name: COMPARE_CONN_INFO_Test_001
1451  * @tc.desc: compare conn info test
1452  * @tc.type: FUNC
1453  * @tc.require:
1454  */
1455 HWTEST_F(AuthTest, COMPARE_CONN_INFO_Test_001, TestSize.Level1)
1456 {
1457     AuthConnInfo info1;
1458     AuthConnInfo info2;
1459     bool ret;
1460 
1461     (void)memset_s(&info1, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1462     (void)memset_s(&info2, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1463     info1.type = AUTH_LINK_TYPE_WIFI;
1464     info2.type = AUTH_LINK_TYPE_WIFI;
1465     ret = CompareConnInfo(&info1, &info2, false);
1466     EXPECT_TRUE(ret == true);
1467     info1.type = AUTH_LINK_TYPE_BR;
1468     info2.type = AUTH_LINK_TYPE_BR;
1469     ret = CompareConnInfo(&info1, &info2, false);
1470     EXPECT_TRUE(ret == true);
1471     info1.type = AUTH_LINK_TYPE_BLE;
1472     info2.type = AUTH_LINK_TYPE_BLE;
1473     ret = CompareConnInfo(&info1, &info2, false);
1474     EXPECT_TRUE(ret == true);
1475     info1.type = AUTH_LINK_TYPE_P2P;
1476     info2.type = AUTH_LINK_TYPE_P2P;
1477     ret = CompareConnInfo(&info1, &info2, false);
1478     EXPECT_TRUE(ret == true);
1479 }
1480 
1481 /*
1482  * @tc.name: CONVERT_TO_CONNECT_OPTION_Test_001
1483  * @tc.desc: convert to connect option test
1484  * @tc.type: FUNC
1485  * @tc.require:
1486  */
1487 HWTEST_F(AuthTest, CONVERT_TO_CONNECT_OPTION_Test_001, TestSize.Level1)
1488 {
1489     AuthConnInfo connInfo;
1490     ConnectOption option;
1491     int32_t ret;
1492 
1493     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1494     (void)memset_s(&option, sizeof(ConnectOption), 0, sizeof(ConnectOption));
1495     connInfo.type = AUTH_LINK_TYPE_BR;
1496     ret = ConvertToConnectOption(&connInfo, &option);
1497     EXPECT_TRUE(ret == SOFTBUS_OK);
1498     connInfo.type = AUTH_LINK_TYPE_BLE;
1499     ret = ConvertToConnectOption(&connInfo, &option);
1500     EXPECT_TRUE(ret == SOFTBUS_OK);
1501     connInfo.type = AUTH_LINK_TYPE_P2P;
1502     ret = ConvertToConnectOption(&connInfo, &option);
1503     EXPECT_TRUE(ret == SOFTBUS_OK);
1504 }
1505 
1506 /*
1507  * @tc.name: CONVERT_TO_AUTH_CONNINFO_Test_001
1508  * @tc.desc: convert to auth connInfo test
1509  * @tc.type: FUNC
1510  * @tc.require:
1511  */
1512 HWTEST_F(AuthTest, CONVERT_TO_AUTH_CONNINFO_Test_001, TestSize.Level1)
1513 {
1514     ConnectionInfo info;
1515     AuthConnInfo connInfo;
1516     int32_t ret;
1517 
1518     (void)memset_s(&info, sizeof(ConnectionInfo), 0, sizeof(ConnectionInfo));
1519     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1520     info.type = CONNECT_TCP;
1521     info.socketInfo.protocol = LNN_PROTOCOL_IP;
1522     ret = ConvertToAuthConnInfo(&info, &connInfo);
1523     EXPECT_TRUE(ret == SOFTBUS_OK);
1524     info.socketInfo.protocol = LNN_PROTOCOL_BR;
1525     ret = ConvertToAuthConnInfo(&info, &connInfo);
1526     EXPECT_NE(ret, SOFTBUS_OK);
1527     info.type = CONNECT_BR;
1528     ret = ConvertToAuthConnInfo(&info, &connInfo);
1529     EXPECT_TRUE(ret == SOFTBUS_OK);
1530     info.type = CONNECT_BLE;
1531     ret = ConvertToAuthConnInfo(&info, &connInfo);
1532     EXPECT_TRUE(ret == SOFTBUS_OK);
1533 }
1534 
1535 /*
1536  * @tc.name: AUTH_CONN_INIT_Test_001
1537  * @tc.desc: auth conn init test
1538  * @tc.type: FUNC
1539  * @tc.require:
1540  */
1541 HWTEST_F(AuthTest, AUTH_CONN_INIT_Test_001, TestSize.Level1)
1542 {
1543     AuthConnListener listener;
1544     (void)memset_s(&listener, sizeof(AuthConnListener), 0, sizeof(AuthConnListener));
1545     int32_t ret = AuthConnInit(nullptr);
1546     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1547     ret = AuthConnInit(&listener);
1548     EXPECT_TRUE(ret != SOFTBUS_OK);
1549 }
1550 
1551 /*
1552  * @tc.name: CONNECT_AUTH_DEVICE_Test_001
1553  * @tc.desc: connect auth device test
1554  * @tc.type: FUNC
1555  * @tc.require:
1556  */
1557 HWTEST_F(AuthTest, CONNECT_AUTH_DEVICE_Test_001, TestSize.Level1)
1558 {
1559     uint32_t requestId = 123;
1560     AuthConnInfo connInfo;
1561     ConnSideType sideType = CONN_SIDE_SERVER;
1562     int32_t ret;
1563 
1564     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1565     connInfo.type = AUTH_LINK_TYPE_WIFI;
1566     ret = ConnectAuthDevice(requestId, &connInfo, sideType);
1567     EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
1568     connInfo.type = AUTH_LINK_TYPE_P2P;
1569     ret = ConnectAuthDevice(requestId, &connInfo, sideType);
1570     EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
1571 }
1572 
1573 /*
1574  * @tc.name: AUTH_START_LISTENING_Test_001
1575  * @tc.desc: auth start listening test
1576  * @tc.type: FUNC
1577  * @tc.require:
1578  */
1579 HWTEST_F(AuthTest, AUTH_START_LISTENING_Test_001, TestSize.Level1)
1580 {
1581     const char *ip = "***.***.**.*";
1582     int32_t port = 22;
1583     int32_t ret;
1584 
1585     ret = AuthStartListening(AUTH_LINK_TYPE_WIFI, nullptr, port);
1586     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1587     ret = AuthStartListening(AUTH_LINK_TYPE_WIFI, ip, port);
1588     EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
1589     ret = AuthStartListening(AUTH_LINK_TYPE_P2P, ip, port);
1590     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM || ret == SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT);
1591 }
1592 
1593 /*
1594  * @tc.name: FIND_AUTH_REQUEST_BY_CONN_INFO_Test_001
1595  * @tc.desc: Find Auth Request By Conn Info test
1596  * @tc.type: FUNC
1597  * @tc.require:
1598  */
1599 HWTEST_F(AuthTest, FIND_AUTH_REQUEST_BY_CONN_INFO_Test_001, TestSize.Level1)
1600 {
1601     AuthConnInfo *authConnInfo = nullptr;
1602     AuthRequest *request = nullptr;
1603     AuthConnInfo authConnInfoValue;
1604     AuthRequest requestValue;
1605     (void)memset_s(&authConnInfoValue, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1606     (void)memset_s(&requestValue, sizeof(AuthRequest), 0, sizeof(AuthRequest));
1607     int32_t ret = FindAuthRequestByConnInfo(authConnInfo, request);
1608     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1609     ret = FindAuthRequestByConnInfo(&authConnInfoValue, request);
1610     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1611 }
1612 
1613 /*
1614  * @tc.name: CHECK_VERIFY_CALLBACK_Test_001
1615  * @tc.desc: Check Verify Callback test
1616  * @tc.type: FUNC
1617  * @tc.require:
1618  */
1619 HWTEST_F(AuthTest, CHECK_VERIFY_CALLBACK_Test_001, TestSize.Level1)
1620 {
1621     bool ret = CheckVerifyCallback(LnnGetVerifyCallback());
1622     EXPECT_TRUE(ret == true);
1623     ret = CheckVerifyCallback(nullptr);
1624     EXPECT_TRUE(ret == false);
1625     AuthVerifyCallback verifyCb = {
1626         .onVerifyPassed = nullptr,
1627         .onVerifyFailed = nullptr,
1628     };
1629     ret = CheckVerifyCallback(&verifyCb);
1630     EXPECT_TRUE(ret == false);
1631 
1632     uint32_t requestId = 0;
1633     AuthHandle authHandle = { .authId = 0, .type = AUTH_LINK_TYPE_MAX };
1634     NodeInfo nodeinfo;
1635     (void)memset_s(&nodeinfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
1636     PerformVerifyCallback(requestId, SOFTBUS_INVALID_PARAM, authHandle, &nodeinfo);
1637     authHandle.type = 0;
1638     PerformVerifyCallback(requestId, SOFTBUS_INVALID_PARAM, authHandle, &nodeinfo);
1639     authHandle.type = AUTH_LINK_TYPE_WIFI;
1640     PerformVerifyCallback(requestId, SOFTBUS_INVALID_PARAM, authHandle, &nodeinfo);
1641 }
1642 
OnConnOpenedTest(uint32_t requestId,AuthHandle authHandle)1643 static void OnConnOpenedTest(uint32_t requestId, AuthHandle authHandle)
1644 {
1645     AUTH_LOGI(AUTH_TEST, "requestId=%{public}d, authId=%{public}" PRId64, requestId, authHandle.authId);
1646 }
1647 
OnConnOpenFailedTest(uint32_t requestId,int32_t reason)1648 static void OnConnOpenFailedTest(uint32_t requestId, int32_t reason)
1649 {
1650     AUTH_LOGI(AUTH_TEST, "requestId=%{public}d, reason=%{public}d", requestId, reason);
1651 }
1652 /*
1653  * @tc.name: CHECK_AUTH_CONN_CALLBACK_Test_001
1654  * @tc.desc: Check Auth Conn Callback test
1655  * @tc.type: FUNC
1656  * @tc.require:
1657  */
1658 HWTEST_F(AuthTest, CHECK_AUTH_CONN_CALLBACK_Test_001, TestSize.Level1)
1659 {
1660     AuthConnCallback cb = {
1661         .onConnOpened = OnConnOpenedTest,
1662         .onConnOpenFailed = OnConnOpenFailedTest,
1663     };
1664     AuthConnCallback connCb = {
1665         .onConnOpened = nullptr,
1666         .onConnOpenFailed = nullptr,
1667     };
1668     bool ret = CheckAuthConnCallback(nullptr);
1669     EXPECT_TRUE(ret == false);
1670     ret = CheckAuthConnCallback(&connCb);
1671     EXPECT_TRUE(ret == false);
1672     ret = CheckAuthConnCallback(&cb);
1673     EXPECT_TRUE(ret == true);
1674 
1675     AuthRequest request = { 0 };
1676     uint32_t requestId = 0;
1677     int64_t authId = 0;
1678     PerformAuthConnCallback(requestId, SOFTBUS_OK, authId);
1679     request.connCb = cb;
1680     int32_t result = AddAuthRequest(&request);
1681     EXPECT_EQ(result, SOFTBUS_OK);
1682     PerformAuthConnCallback(requestId, SOFTBUS_OK, authId);
1683 }
1684 
1685 /*
1686  * @tc.name: AUTH_SESSION_START_AUTH_Test_001
1687  * @tc.desc: Auth Session Start Auth test
1688  * @tc.type: FUNC
1689  * @tc.require:
1690  */
1691 HWTEST_F(AuthTest, AUTH_SESSION_START_AUTH_Test_001, TestSize.Level1)
1692 {
1693     uint32_t requestId = 0;
1694     uint64_t connId = 0;
1695     AuthConnInfo *connInfo = nullptr;
1696     AuthParam authInfo = {
1697         .authSeq = GenSeq(false),
1698         .requestId = requestId,
1699         .connId = connId,
1700         .isServer = false,
1701         .isFastAuth = true,
1702     };
1703     int32_t ret = AuthSessionStartAuth(&authInfo, connInfo);
1704     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1705     AuthConnInfo authConnInfo;
1706     authConnInfo.type = AUTH_LINK_TYPE_WIFI;
1707     constexpr char NODE1_BR_MAC[] = "12345TTU";
1708     const char *ip = "***.***.**.*";
1709     (void)strcpy_s(authConnInfo.info.brInfo.brMac, BT_MAC_LEN, NODE1_BR_MAC);
1710     authConnInfo.info.ipInfo.port = 20;
1711     authConnInfo.info.ipInfo.authId = 1024;
1712     (void)strcpy_s(authConnInfo.info.ipInfo.ip, IP_LEN, ip);
1713     ret = AuthSessionStartAuth(&authInfo, &authConnInfo);
1714     EXPECT_TRUE(ret == SOFTBUS_LOCK_ERR);
1715 }
1716 
1717 /*
1718  * @tc.name: AUTH_SESSION_PROCESS_DEV_ID_DATA_Test_001
1719  * @tc.desc: Auth Session Process Dev Id Data test
1720  * @tc.type: FUNC
1721  * @tc.require:
1722  */
1723 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEV_ID_DATA_Test_001, TestSize.Level1)
1724 {
1725     int64_t authSeq = 0;
1726     uint8_t *data = nullptr;
1727     uint32_t len = 0;
1728     int32_t ret = AuthSessionProcessDevIdData(authSeq, data, len);
1729     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1730 }
1731 
1732 /*
1733  * @tc.name: AUTH_SESSION_SAVE_SESSION_KEY_Test_001
1734  * @tc.desc: Auth Session Save Session Key test
1735  * @tc.type: FUNC
1736  * @tc.require:
1737  */
1738 HWTEST_F(AuthTest, AUTH_SESSION_SAVE_SESSION_KEY_Test_001, TestSize.Level1)
1739 {
1740     int64_t authSeq = 0;
1741     uint8_t *key = nullptr;
1742     uint32_t len = 0;
1743     int32_t ret = AuthSessionSaveSessionKey(authSeq, key, len);
1744     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1745 }
1746 
1747 /*
1748  * @tc.name: AUTH_SESSION_PROCESS_DEV_INFO_DATA_Test_001
1749  * @tc.desc: Auth Session Process Dev Info Data test
1750  * @tc.type: FUNC
1751  * @tc.require:
1752  */
1753 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEV_INFO_DATA_Test_001, TestSize.Level1)
1754 {
1755     int64_t authSeq = 0;
1756     const uint8_t *data = nullptr;
1757     uint32_t len = 0;
1758     int32_t ret = AuthSessionProcessDevInfoData(authSeq, data, len);
1759     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1760 }
1761 
1762 /*
1763  * @tc.name: AUTH_SESSION_PROCESS_DEV_INFO_DATA_BY_CONN_ID_Test_001
1764  * @tc.desc: Auth Session Process Dev Info Data By Conn Id test
1765  * @tc.type: FUNC
1766  * @tc.require:
1767  */
1768 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_DEV_INFO_DATA_BY_CONN_ID_Test_001, TestSize.Level1)
1769 {
1770     int64_t connId = 0;
1771     bool isServer = false;
1772     const uint8_t *data = nullptr;
1773     uint32_t len = 0;
1774     int32_t ret = AuthSessionProcessDevInfoDataByConnId(connId, isServer, data, len);
1775     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1776 }
1777 
1778 /*
1779  * @tc.name: AUTH_SESSION_PROCESS_CLOSE_ACK_BY_CONN_ID_Test_001
1780  * @tc.desc: Auth Session Process Close Ack By Conn Id test
1781  * @tc.type: FUNC
1782  * @tc.require:
1783  */
1784 HWTEST_F(AuthTest, AUTH_SESSION_PROCESS_CLOSE_ACK_BY_CONN_ID_Test_001, TestSize.Level1)
1785 {
1786     int64_t connId = 0;
1787     bool isServer = false;
1788     const uint8_t *data = nullptr;
1789     uint32_t len = 0;
1790     int32_t ret = AuthSessionProcessCloseAckByConnId(connId, isServer, data, len);
1791     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1792 }
1793 
1794 /*
1795  * @tc.name: DUP_SESSION_KEY_LIST_Test_001
1796  * @tc.desc: Dup Session Key List test
1797  * @tc.type: FUNC
1798  * @tc.require:
1799  */
1800 HWTEST_F(AuthTest, DUP_SESSION_KEY_LIST_Test_001, TestSize.Level1)
1801 {
1802     SessionKeyList *srcList = nullptr;
1803     SessionKeyList *dstList = nullptr;
1804     int32_t ret = DupSessionKeyList(srcList, dstList);
1805     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1806 }
1807 
1808 /*
1809  * @tc.name: HAS_SESSION_KEY_Test_001
1810  * @tc.desc: Has Session Key test
1811  * @tc.type: FUNC
1812  * @tc.require:
1813  */
1814 HWTEST_F(AuthTest, HAS_SESSION_KEY_Test_001, TestSize.Level1)
1815 {
1816     SessionKeyList *list = nullptr;
1817     int32_t ret = HasSessionKey(list);
1818     EXPECT_TRUE(ret == false);
1819 }
1820 
1821 /*
1822  * @tc.name: ADD_SESSION_KEY_Test_001
1823  * @tc.desc: Add Session Key test
1824  * @tc.type: FUNC
1825  * @tc.require:
1826  */
1827 HWTEST_F(AuthTest, ADD_SESSION_KEY_Test_001, TestSize.Level1)
1828 {
1829     SessionKeyList *list = nullptr;
1830     int32_t index = 0;
1831     SessionKey *key = nullptr;
1832     SessionKey keyValue;
1833     SessionKeyList listValue;
1834     int32_t ret = AddSessionKey(list, index, key, AUTH_LINK_TYPE_WIFI, false);
1835     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1836     (void)memset_s(&keyValue, sizeof(SessionKey), 0, sizeof(SessionKey));
1837     (void)memset_s(&listValue, sizeof(SessionKeyList), 0, sizeof(SessionKeyList));
1838     ListInit(&listValue);
1839     ret = AddSessionKey(&listValue, index, &keyValue, AUTH_LINK_TYPE_WIFI, false);
1840     EXPECT_TRUE(ret == SOFTBUS_OK);
1841 }
1842 
1843 /*
1844  * @tc.name: ENCRYPT_DATA_Test_001
1845  * @tc.desc: Encrypt Data test
1846  * @tc.type: FUNC
1847  * @tc.require:
1848  */
1849 HWTEST_F(AuthTest, ENCRYPT_DATA_Test_001, TestSize.Level1)
1850 {
1851     SessionKeyList *list = nullptr;
1852     SessionKeyList listValue;
1853     (void)memset_s(&listValue, sizeof(SessionKeyList), 0, sizeof(SessionKeyList));
1854     uint8_t indata[TEST_DATA_LEN] = "1234";
1855     uint8_t outData[TEST_DATA_LEN];
1856     uint32_t outLen = TEST_DATA_LEN;
1857     InDataInfo inDataInfo = { .inData = indata, .inLen = TEST_DATA_LEN };
1858     int32_t ret = EncryptData(list, AUTH_LINK_TYPE_WIFI, &inDataInfo, outData, &outLen);
1859     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1860 }
1861 
1862 /*
1863  * @tc.name: DECRYPT_DATA_Test_001
1864  * @tc.desc: Decrypt Data test
1865  * @tc.type: FUNC
1866  * @tc.require:
1867  */
1868 HWTEST_F(AuthTest, DECRYPT_DATA_Test_001, TestSize.Level1)
1869 {
1870     SessionKeyList *list = nullptr;
1871     uint8_t indata[TEST_DATA_LEN] = "1234";
1872     uint8_t outData[TEST_DATA_LEN];
1873     uint32_t outLen = TEST_DATA_LEN;
1874     InDataInfo inDataInfo = { .inData = indata, .inLen = ENCRYPT_OVER_HEAD_LEN_TEST + 1 };
1875     int32_t ret = DecryptData(list, AUTH_LINK_TYPE_WIFI, &inDataInfo, outData, &outLen);
1876     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1877 }
1878 
1879 /*
1880  * @tc.name: UNPACK_DEVICE_INFO_MESSAGE_Test_001
1881  * @tc.desc: Unpack Device Info Message test
1882  * @tc.type: FUNC
1883  * @tc.require:
1884  */
1885 HWTEST_F(AuthTest, UNPACK_DEVICE_INFO_MESSAGE_Test_001, TestSize.Level1)
1886 {
1887     const char *msg = "";
1888     int32_t linkType = 1;
1889     SoftBusVersion version = SOFTBUS_OLD_V1;
1890     NodeInfo nodeInfo;
1891     AuthSessionInfo info;
1892     (void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
1893     (void)memset_s(&info, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1894     bool isMetaAuth = false;
1895     DevInfoData devInfo = { msg, 0, linkType, version };
1896     int32_t ret = UnpackDeviceInfoMessage(&devInfo, &nodeInfo, isMetaAuth, &info);
1897     EXPECT_NE(ret, SOFTBUS_OK);
1898 }
1899 
1900 /*
1901  * @tc.name: POST_DEVICE_ID_MESSAGE_Test_001
1902  * @tc.desc: Post Device Id Message test
1903  * @tc.type: FUNC
1904  * @tc.require:
1905  */
1906 HWTEST_F(AuthTest, POST_DEVICE_ID_MESSAGE_Test_001, TestSize.Level1)
1907 {
1908     AuthSessionInfo *info = nullptr;
1909     AuthSessionInfo infoValue;
1910     (void)memset_s(&infoValue, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1911     int32_t ret = PostDeviceIdMessage(GenSeq(false), info);
1912     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1913     ret = PostDeviceIdMessage(GenSeq(false), &infoValue);
1914     EXPECT_TRUE(ret != SOFTBUS_OK);
1915 }
1916 
1917 /*
1918  * @tc.name: PROCESS_DEVICE_ID_MESSAGE_Test_001
1919  * @tc.desc: Process Device Id Message test
1920  * @tc.type: FUNC
1921  * @tc.require:
1922  */
1923 HWTEST_F(AuthTest, PROCESS_DEVICE_ID_MESSAGE_Test_001, TestSize.Level1)
1924 {
1925     AuthSessionInfo *info = nullptr;
1926     AuthSessionInfo infoValue;
1927     (void)memset_s(&infoValue, sizeof(AuthSessionInfo), 0, sizeof(AuthSessionInfo));
1928     uint8_t data[TEST_DATA_LEN] = "123";
1929     int32_t ret = ProcessDeviceIdMessage(info, data, sizeof(data));
1930     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1931     ret = ProcessDeviceIdMessage(&infoValue, data, sizeof(data));
1932     EXPECT_TRUE(ret != SOFTBUS_OK);
1933 }
1934 
1935 /*
1936  * @tc.name: SET_SOCKET_CALLBACK_Test_001
1937  * @tc.desc: Set Socket Callback test
1938  * @tc.type: FUNC
1939  * @tc.require:
1940  */
1941 HWTEST_F(AuthTest, SET_SOCKET_CALLBACK_Test_001, TestSize.Level1)
1942 {
1943     const SocketCallback *cb = nullptr;
1944     int32_t ret = SetSocketCallback(cb);
1945     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1946 }
1947 
1948 /*
1949  * @tc.name: SOCKET_POST_BYTES_Test_001
1950  * @tc.desc: Socket Post Bytes test
1951  * @tc.type: FUNC
1952  * @tc.require:
1953  */
1954 HWTEST_F(AuthTest, SOCKET_POST_BYTES_Test_001, TestSize.Level1)
1955 {
1956     int32_t fd = 0;
1957     const AuthDataHead *head = nullptr;
1958     const uint8_t *data = nullptr;
1959     int32_t ret = SocketPostBytes(fd, head, data);
1960     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1961     AuthDataHead headValue;
1962     uint8_t dataValue[TEST_DATA_LEN] = "123";
1963     (void)memset_s(&headValue, sizeof(AuthDataHead), 0, sizeof(AuthDataHead));
1964     ret = SocketPostBytes(fd, &headValue, dataValue);
1965     EXPECT_NE(ret, SOFTBUS_OK);
1966 }
1967 
1968 /*
1969  * @tc.name: SOCKET_GET_CONN_INFO_Test_001
1970  * @tc.desc: Socket Get Conn Info test
1971  * @tc.type: FUNC
1972  * @tc.require:
1973  */
1974 HWTEST_F(AuthTest, SOCKET_GET_CONN_INFO_Test_001, TestSize.Level1)
1975 {
1976     int32_t fd = 0;
1977     AuthConnInfo *connInfo = nullptr;
1978     bool isServer = false;
1979     int32_t ret = SocketGetConnInfo(fd, connInfo, &isServer);
1980     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1981     AuthConnInfo connInfoValue;
1982     (void)memset_s(&connInfoValue, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1983     ret = SocketGetConnInfo(fd, &connInfoValue, &isServer);
1984     EXPECT_NE(ret, SOFTBUS_OK);
1985 }
1986 
1987 /*
1988  * @tc.name: REG_AUTH_CHANNEL_LISTENER_Test_001
1989  * @tc.desc: Reg Auth Channel Listener test
1990  * @tc.type: FUNC
1991  * @tc.require:
1992  */
1993 HWTEST_F(AuthTest, REG_AUTH_CHANNEL_LISTENER_Test_001, TestSize.Level1)
1994 {
1995     int32_t module = MODULE_AUTH_CHANNEL;
1996     const AuthChannelListener *listener = nullptr;
1997     int32_t ret = RegAuthChannelListener(module, listener);
1998     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
1999 }
2000 
2001 /*
2002  * @tc.name: AUTH_OPEN_CHANNEL_Test_001
2003  * @tc.desc: Auth Open Channel test
2004  * @tc.type: FUNC
2005  * @tc.require:
2006  */
2007 HWTEST_F(AuthTest, AUTH_OPEN_CHANNEL_Test_001, TestSize.Level1)
2008 {
2009     char *ip = nullptr;
2010     char ipValue[32] = "0";
2011     int32_t port = 22;
2012     int32_t ret = AuthOpenChannel(ip, port);
2013     EXPECT_TRUE(ret == INVALID_CHANNEL_ID);
2014     ret = AuthOpenChannel(ipValue, port);
2015     EXPECT_TRUE(ret == INVALID_CHANNEL_ID);
2016 }
2017 
2018 /*
2019  * @tc.name: AUTH_GET_DECRYPT_SIZE_Test_001
2020  * @tc.desc: Auth Get Decrypt Size test
2021  * @tc.type: FUNC
2022  * @tc.require:
2023  */
2024 HWTEST_F(AuthTest, AUTH_GET_DECRYPT_SIZE_Test_001, TestSize.Level1)
2025 {
2026     uint32_t inLen = OVERHEAD_LEN;
2027     uint32_t ret = AuthGetDecryptSize(inLen);
2028     EXPECT_TRUE(ret == OVERHEAD_LEN);
2029     inLen = OVERHEAD_LEN + 1;
2030     ret = AuthGetDecryptSize(inLen);
2031     EXPECT_TRUE(ret == (inLen - OVERHEAD_LEN));
2032 }
2033 
2034 /*
2035  * @tc.name: NOTIFY_TRANS_DATA_RECEIVED_Test_001
2036  * @tc.desc: Notify Trans Data Received test
2037  * @tc.type: FUNC
2038  * @tc.require:
2039  */
2040 HWTEST_F(AuthTest, NOTIFY_TRANS_DATA_RECEIVED_Test_001, TestSize.Level1)
2041 {
2042     AuthTransListener listener = {
2043         .onDataReceived = AuthOnDataReceived,
2044         .onDisconnected = AuthOnDisconnected,
2045         .onException = nullptr,
2046     };
2047     int32_t ret;
2048     ret = RegAuthTransListener(MODULE_UDP_INFO, &listener);
2049     EXPECT_TRUE(ret == SOFTBUS_OK);
2050     AuthHandle authHandle = { .authId = 0, .type = AUTH_LINK_TYPE_WIFI };
2051     AuthDataHead head = {
2052         .dataType = 0,
2053         .module = MODULE_UDP_INFO,
2054         .seq = 0,
2055         .flag = 0,
2056         .len = 20,
2057     };
2058     const char *data = "1111222233334444";
2059     uint32_t len = 0;
2060     NotifyTransDataReceived(authHandle, &head, reinterpret_cast<const uint8_t *>(data), len);
2061     NotifyTransDisconnected(authHandle);
2062     NotifyTransException(authHandle, SOFTBUS_INVALID_PARAM);
2063     UnregAuthTransListener(MODULE_UDP_INFO);
2064 }
2065 
2066 /*
2067  * @tc.name: AUTH_ON_CONNECT_EVENT_Test_001
2068  * @tc.desc: Auth On Connect Event test
2069  * @tc.type: FUNC
2070  * @tc.require:
2071  */
2072 HWTEST_F(AuthTest, AUTH_ON_CONNECT_EVENT_Test_001, TestSize.Level1)
2073 {
2074     ListenerModule module = AUTH;
2075     int32_t cfd = 0;
2076     ConnectOption option;
2077     (void)memset_s(&option, sizeof(ConnectOption), 0, sizeof(ConnectOption));
2078     int32_t ret = OnConnectEvent(module, cfd, &option);
2079     EXPECT_NE(ret, SOFTBUS_OK);
2080 }
2081 
2082 /*
2083  * @tc.name: GetLatestAvailableSessionKeyTimeTest
2084  * @tc.desc: set and get session key available sessionKey
2085  * @tc.type: FUNC
2086  * @tc.require:
2087  */
2088 HWTEST_F(AuthTest, AUTH_SET_AND_SET_SESSIONKEY_AVAILABLE_Test_001, TestSize.Level1)
2089 {
2090     SessionKeyList list = { 0 };
2091     SessionKey sessionKey = { { 0 }, TEST_DATA_LEN };
2092     int32_t index = 0;
2093     ListInit(&list);
2094     int32_t ret = AddSessionKey(&list, index, &sessionKey, AUTH_LINK_TYPE_WIFI, false);
2095     EXPECT_TRUE(ret == SOFTBUS_OK);
2096     uint64_t time = GetLatestAvailableSessionKeyTime(&list, AUTH_LINK_TYPE_WIFI);
2097     EXPECT_TRUE(time == 0);
2098     ret = SetSessionKeyAvailable(&list, 0);
2099     EXPECT_TRUE(ret == SOFTBUS_OK);
2100     time = GetLatestAvailableSessionKeyTime(&list, AUTH_LINK_TYPE_WIFI);
2101     EXPECT_TRUE(time != 0);
2102     DestroySessionKeyList(&list);
2103 }
2104 
2105 /*
2106  * @tc.name: AUTH_SET_TCP_KEEPALIVE_OPTION_Test_001
2107  * @tc.desc: Auth Set Tcp Keepalive option test
2108  * @tc.type: FUNC
2109  * @tc.require:
2110  */
2111 HWTEST_F(AuthTest, AUTH_SET_TCP_KEEPALIVE_OPTION_Test_001, TestSize.Level1)
2112 {
2113     int32_t fd = -1;
2114     int32_t cycle = 0;
2115 
2116     int32_t ret = AuthSetTcpKeepaliveOption(fd, HIGH_FREQ_CYCLE);
2117     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
2118     fd = 0;
2119     ret = AuthSetTcpKeepaliveOption(fd, HIGH_FREQ_CYCLE);
2120     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
2121     fd = 1;
2122     ret = AuthSetTcpKeepaliveOption(fd, (ModeCycle)cycle);
2123     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
2124     cycle = KEEPALIVE_TIME;
2125     ret = AuthSetTcpKeepaliveOption(fd, (ModeCycle)cycle);
2126     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
2127 }
2128 
2129 /*
2130  * @tc.name: AUTH_SET_TCP_KEEPALIVE_OPTION_Test_002
2131  * @tc.desc: Auth Set Tcp Keepalive option test
2132  * @tc.type: FUNC
2133  * @tc.require:
2134  */
2135 HWTEST_F(AuthTest, AUTH_SET_TCP_KEEPALIVE_OPTION_Test_002, TestSize.Level1)
2136 {
2137     int32_t fd = 1;
2138 
2139     int32_t ret = AuthSetTcpKeepaliveOption(fd, HIGH_FREQ_CYCLE);
2140     EXPECT_TRUE(ret == SOFTBUS_ADAPTER_ERR);
2141     ret = AuthSetTcpKeepaliveOption(fd, MID_FREQ_CYCLE);
2142     EXPECT_TRUE(ret == SOFTBUS_ADAPTER_ERR);
2143     ret = AuthSetTcpKeepaliveOption(fd, LOW_FREQ_CYCLE);
2144     EXPECT_TRUE(ret == SOFTBUS_ADAPTER_ERR);
2145     ret = AuthSetTcpKeepaliveOption(fd, DEFAULT_FREQ_CYCLE);
2146     EXPECT_TRUE(ret == SOFTBUS_ADAPTER_ERR);
2147 }
2148 
2149 /*
2150  * @tc.name: AUTH_SET_TCP_KEEPALIVE_OPTION_Test_003
2151  * @tc.desc: Auth Set Tcp Keepalive option test
2152  * @tc.type: FUNC
2153  * @tc.require:
2154  */
2155 HWTEST_F(AuthTest, AUTH_SET_TCP_KEEPALIVE_OPTION_Test_003, TestSize.Level1)
2156 {
2157     const SocketInterface *tcp = GetTcpProtocol();
2158     ASSERT_NE(tcp, nullptr);
2159 
2160     int32_t port = CLIENT_PORT;
2161     char ipAddress[] = "127.0.0.1";
2162     LocalListenerInfo info = {};
2163     info.type = CONNECT_TCP;
2164     info.socketOption.port = port;
2165     info.socketOption.moduleId = DIRECT_CHANNEL_SERVER_WIFI;
2166     info.socketOption.protocol = LNN_PROTOCOL_IP;
2167     (void)strcpy_s(info.socketOption.addr, sizeof(info.socketOption.addr), ipAddress);
2168     int32_t fd = tcp->OpenServerSocket(&info);
2169 
2170     int32_t ret = AuthSetTcpKeepaliveOption(fd, HIGH_FREQ_CYCLE);
2171     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
2172 }
2173 
2174 /*
2175  * @tc.name: GET_TCP_KEEPALIVE_OPTION_BY_CYCLE_Test_001
2176  * @tc.desc: Get Tcp Keepalive Option By Cycle test
2177  * @tc.type: FUNC
2178  * @tc.require:
2179  */
2180 HWTEST_F(AuthTest, GET_TCP_KEEPALIVE_OPTION_BY_CYCLE_Test_001, TestSize.Level1)
2181 {
2182     TcpKeepaliveOption tcpKeepaliveOption = { 0 };
2183 
2184     int32_t ret = GetTcpKeepaliveOptionByCycle(HIGH_FREQ_CYCLE, nullptr);
2185     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
2186     ret = GetTcpKeepaliveOptionByCycle((ModeCycle)tcpKeepaliveOption.keepaliveIdle, &tcpKeepaliveOption);
2187     EXPECT_NE(ret, SOFTBUS_OK);
2188 
2189     ret = GetTcpKeepaliveOptionByCycle(HIGH_FREQ_CYCLE, &tcpKeepaliveOption);
2190     EXPECT_TRUE(ret == SOFTBUS_OK);
2191     ret = GetTcpKeepaliveOptionByCycle(MID_FREQ_CYCLE, &tcpKeepaliveOption);
2192     EXPECT_TRUE(ret == SOFTBUS_OK);
2193     ret = GetTcpKeepaliveOptionByCycle(LOW_FREQ_CYCLE, &tcpKeepaliveOption);
2194     EXPECT_TRUE(ret == SOFTBUS_OK);
2195     ret = GetTcpKeepaliveOptionByCycle(DEFAULT_FREQ_CYCLE, &tcpKeepaliveOption);
2196     EXPECT_TRUE(ret == SOFTBUS_OK);
2197 }
2198 
2199 /*
2200  * @tc.name: IS_ENHANCE_P2P_MODULE_ID_Test_001
2201  * @tc.desc: IsEnhanceP2pModuleId test
2202  * @tc.type: FUNC
2203  * @tc.require:
2204  */
2205 HWTEST_F(AuthTest, IS_ENHANCE_P2P_MODULE_ID_Test_001, TestSize.Level1)
2206 {
2207     EXPECT_EQ(IsEnhanceP2pModuleId(AUTH_ENHANCED_P2P_START), true);
2208     EXPECT_EQ(IsEnhanceP2pModuleId(DIRECT_CHANNEL_SERVER_P2P), false);
2209     EXPECT_EQ(IsEnhanceP2pModuleId(AUTH_P2P), false);
2210 }
2211 
2212 /*
2213  * @tc.name: AUTH_GET_CONNINFO_BY_TYPE_Test_001
2214  * @tc.desc: AuthGetConnInfoByType test
2215  * @tc.type: FUNC
2216  * @tc.require:
2217  */
2218 HWTEST_F(AuthTest, AUTH_GET_CONNINFO_BY_TYPE_Test_001, TestSize.Level1)
2219 {
2220     const char *uuid = "12345678";
2221     AuthConnInfo connInfo;
2222 
2223     (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
2224     int32_t ret = AuthGetConnInfoByType(uuid, AUTH_LINK_TYPE_WIFI, &connInfo, true);
2225     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
2226     ret = AuthGetConnInfoByType(nullptr, AUTH_LINK_TYPE_WIFI, &connInfo, false);
2227     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
2228 }
2229 } // namespace OHOS
2230