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