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