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