• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "UTTest_auth_message_processor.h"
17 
18 #include "dm_log.h"
19 #include "dm_constants.h"
20 #include "auth_message_processor.h"
21 #include "softbus_connector.h"
22 #include "softbus_session.h"
23 #include "dm_auth_manager.h"
24 #include "device_manager_service_listener.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
SetUp()28 void AuthMessageProcessorTest::SetUp()
29 {
30 }
TearDown()31 void AuthMessageProcessorTest::TearDown()
32 {
33 }
SetUpTestCase()34 void AuthMessageProcessorTest::SetUpTestCase()
35 {
36 }
TearDownTestCase()37 void AuthMessageProcessorTest::TearDownTestCase()
38 {
39 }
40 
41 namespace {
42 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
43 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
44 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
45 /**
46  * @tc.name: AuthMessageProcessor::AuthMessageProcessor_001
47  * @tc.desc: 1 set cryptoAdapter_ to null
48  *           2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr
49  *           3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
50  * @tc.type: FUNC
51  * @tc.require: AR000GHSJK
52  */
53 HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_001, testing::ext::TestSize.Level0)
54 {
55     std::shared_ptr<DmAuthManager> Test =
56         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
57     ASSERT_NE(Test, nullptr);
58 }
59 
60 /**
61  * @tc.name: AuthMessageProcessor::AuthMessageProcessor_001
62  * @tc.desc: 1 set cryptoAdapter_ to null
63  *           2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr
64  *           3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
65  * @tc.type: FUNC
66  * @tc.require: AR000GHSJK
67  */
68 HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_002, testing::ext::TestSize.Level0)
69 {
70     std::shared_ptr<DmAuthManager> Test =
71         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
72     Test.reset();
73     EXPECT_EQ(Test, nullptr);
74 }
75 
76 /**
77  * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001
78  * @tc.desc: 1 set cryptoAdapter_ to null
79  *           2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr
80  *           3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
81  * @tc.type: FUNC
82  * @tc.require: AR000GHSJK
83  */
84 HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::TestSize.Level0)
85 {
86     std::shared_ptr<DmAuthManager> data =
87         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
88     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
89     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
90     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
91     int32_t msgType = MSG_TYPE_NEGOTIATE;
92     nlohmann::json jsonObj;
93     jsonObj[TAG_VER] = DM_ITF_VER;
94     jsonObj[TAG_MSG_TYPE] = msgType;
95     jsonObj[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
96     authMessageProcessor->SetResponseContext(authResponseContext);
97     authMessageProcessor->cryptoAdapter_ = nullptr;
98     authMessageProcessor->CreateNegotiateMessage(jsonObj);
99     std::string str1 = jsonObj.dump();
100 
101     nlohmann::json jsonObject;
102     jsonObject[TAG_VER] = DM_ITF_VER;
103     jsonObject[TAG_MSG_TYPE] = msgType;
104     jsonObject[TAG_CRYPTO_SUPPORT] = false;
105     jsonObject[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
106     jsonObject[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
107     jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId;
108     std::string str2 = jsonObject.dump();
109     ASSERT_EQ(str1, str2);
110 }
111 
112 /**
113  * @tc.name: AuthMessageProcessor::CreateSyncGroupMessage_001
114  * @tc.desc: Compare JSON before and after assignment
115  * @tc.type: FUNC
116  * @tc.require: AR000GHSJK
117  */
118 HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::TestSize.Level0)
119 {
120     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
121     std::shared_ptr<DmAuthManager> data =
122         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
123     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
124     authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
125     nlohmann::json jsona;
126     nlohmann::json jsonObj;
127     authMessageProcessor->authRequestContext_->deviceId = "132416546";
128     std::vector<std::string> syncGroupList;
129     syncGroupList.push_back("1111");
130     authMessageProcessor->authRequestContext_->syncGroupList = syncGroupList;
131     jsona[TAG_DEVICE_ID] = authMessageProcessor->authRequestContext_->deviceId;
132     jsona[TAG_GROUPIDS] = authMessageProcessor->authRequestContext_->syncGroupList;
133     authMessageProcessor->CreateSyncGroupMessage(jsonObj);
134     std::string str1 = jsona.dump();
135     std::string str2 = jsonObj.dump();
136     ASSERT_EQ(str1, str2);
137 }
138 
139 /**
140  * @tc.name: AuthMessageProcessor::CreateResponseAuthMessage_001
141  * @tc.desc: Compare JSON before and after assignment
142  * @tc.type: FUNC
143  * @tc.require: AR000GHSJK
144  */
145 HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext::TestSize.Level0)
146 {
147     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
148     std::shared_ptr<DmAuthManager> data =
149         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
150     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
151     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
152     nlohmann::json jsona;
153     nlohmann::json jsonObj;
154     authMessageProcessor->authResponseContext_->reply = 0;
155     authMessageProcessor->authResponseContext_->deviceId = "132416546";
156     authMessageProcessor->authResponseContext_->token = "11";
157     nlohmann::json jsonb;
158     jsonb[TAG_GROUP_ID] = "123456";
159     authMessageProcessor->authResponseContext_->groupId = jsonb.dump();
160     authMessageProcessor->authResponseContext_->authToken = "123456";
161     authMessageProcessor->authResponseContext_->networkId = "11112222";
162     authMessageProcessor->authResponseContext_->requestId = 222222;
163     authMessageProcessor->authResponseContext_->groupName = "333333";
164     jsona[TAG_TOKEN] = authMessageProcessor->authResponseContext_->token;
165     jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
166     jsona[TAG_DEVICE_ID] = authMessageProcessor->authResponseContext_->deviceId;
167     jsona[TAG_AUTH_TOKEN] = authMessageProcessor->authResponseContext_->authToken;
168     jsona[TAG_NET_ID] = authMessageProcessor->authResponseContext_->networkId;
169     jsona[TAG_REQUEST_ID] = authMessageProcessor->authResponseContext_->requestId;
170     jsona[TAG_GROUP_ID] = "123456";
171     jsona[TAG_GROUP_NAME] = authMessageProcessor->authResponseContext_->groupName;
172     authMessageProcessor->CreateResponseAuthMessage(jsonObj);
173     std::string str1 = jsona.dump();
174     std::string str2 = jsonObj.dump();
175     ASSERT_EQ(str1, str2);
176 }
177 
178 /**
179  * @tc.name: AuthMessageProcessor::CreateResponseFinishMessage_001
180  * @tc.desc: Compare JSON before and after assignment
181  * @tc.type: FUNC
182  * @tc.require: AR000GHSJK
183  */
184 HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext::TestSize.Level0)
185 {
186     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
187     std::shared_ptr<DmAuthManager> data =
188         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
189     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
190     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
191     nlohmann::json jsona;
192     nlohmann::json jsonObj;
193     authMessageProcessor->authResponseContext_->reply = 1;
194     jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
195     authMessageProcessor->CreateResponseFinishMessage(jsonObj);
196     std::string str1 = jsona.dump();
197     std::string str2 = jsonObj.dump();
198     ASSERT_EQ(str1, str2);
199 }
200 
201 /**
202  * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_001
203  * @tc.desc: Compare JSON before and after assignment
204  * @tc.type: FUNC
205  * @tc.require: AR000GHSJK
206  */
207 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext::TestSize.Level0)
208 {
209     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
210     std::shared_ptr<DmAuthManager> data =
211         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
212     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
213     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
214     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
215     nlohmann::json jsonObj;
216     authMessageProcessor->authResponseContext_->reply = 1;
217     jsonObj[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
218     authMessageProcessor->SetResponseContext(authResponseContext);
219     authMessageProcessor->ParseResponseFinishMessage(jsonObj);
220     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
221 }
222 
223 /**
224  * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_001
225  * @tc.desc: Compare JSON before and after assi gnment
226  * @tc.type: FUNC
227  * @tc.require: AR000GHSJK
228  */
229 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::TestSize.Level0)
230 {
231     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
232     std::shared_ptr<DmAuthManager> data =
233         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
234     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
235     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
236     nlohmann::json jsona;
237     authResponseContext->reply = 0;
238     authResponseContext->deviceId = "11111";
239     authResponseContext->authToken = "123456";
240     authResponseContext->networkId = "12345";
241     authResponseContext->requestId = 2;
242     authResponseContext->groupId = "23456";
243     authResponseContext->groupName = "34567";
244     authResponseContext->token = "11123";
245     jsona[TAG_TOKEN] = authResponseContext->token;
246     jsona[TAG_REPLY] = authResponseContext->reply;
247     jsona[TAG_DEVICE_ID] = authResponseContext->deviceId;
248     jsona[TAG_AUTH_TOKEN] = authResponseContext->authToken;
249     jsona[TAG_NET_ID] = authResponseContext->networkId;
250     jsona[TAG_REQUEST_ID] = authResponseContext->requestId;
251     jsona[TAG_GROUP_ID] = authResponseContext->groupId;
252     jsona[TAG_GROUP_NAME] = authResponseContext->groupName;
253     authMessageProcessor->SetResponseContext(authResponseContext);
254     authMessageProcessor->ParseAuthResponseMessage(jsona);
255     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
256 }
257 
258 /**
259  * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_001
260  * @tc.desc: Compare JSON before and after assignment
261  * @tc.type: FUNC
262  * @tc.require: AR000GHSJK
263  */
264 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::TestSize.Level0)
265 {
266     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
267     std::shared_ptr<DmAuthManager> data =
268         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
269     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
270     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
271     authMessageProcessor->SetResponseContext(authResponseContext);
272     nlohmann::json jsonThumbnail;
273     authResponseContext->deviceId = "123";
274     authResponseContext->reply = 0;
275     authResponseContext->authType = 222;
276     authResponseContext->networkId = "234";
277     authResponseContext->groupId = "345";
278     authResponseContext->groupName = "456";
279     authResponseContext->requestId = 2333;
280     jsonThumbnail[TAG_DEVICE_ID] = authResponseContext->deviceId;
281     jsonThumbnail[TAG_REPLY] = authResponseContext->reply;
282     jsonThumbnail[TAG_AUTH_TYPE] = authResponseContext->authType;
283     jsonThumbnail[TAG_NET_ID] = authResponseContext->networkId;
284     jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId;
285     jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName;
286     jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId;
287     int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
288     ASSERT_EQ(ret, ERR_DM_FAILED);
289 }
290 
291 /**
292  * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_002
293  * @tc.desc: Compare JSON before and after assignment
294  * @tc.type: FUNC
295  * @tc.require: AR000GHSJK
296  */
297 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::TestSize.Level0)
298 {
299     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
300     std::shared_ptr<DmAuthManager> data =
301         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
302     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
303     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
304     authMessageProcessor->SetResponseContext(authResponseContext);
305     nlohmann::json jsonThumbnail;
306     jsonThumbnail[TAG_SLICE_NUM] = 1;
307     jsonThumbnail[TAG_INDEX] = 0;
308     jsonThumbnail[TAG_DEVICE_ID] = "123";
309     jsonThumbnail[TAG_AUTH_TYPE] = 1;
310     jsonThumbnail[TAG_APP_DESCRIPTION] = "123";
311     jsonThumbnail[TAG_TOKEN] = "1234";
312     jsonThumbnail[TAG_TARGET] = "12345";
313     jsonThumbnail[TAG_APP_NAME] = "123456";
314     jsonThumbnail[TAG_LOCAL_DEVICE_ID] = "localdeviceTest";
315     int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
316     ASSERT_EQ(ret, DM_OK);
317 }
318 
319 /**
320  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_001
321  * @tc.desc: Compare authResponseContext before and after assignment
322  * @tc.type: FUNC
323  * @tc.require: AR000GHSJK
324  */
325 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::TestSize.Level0)
326 {
327     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
328     std::shared_ptr<DmAuthManager> data =
329         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
330     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
331     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
332     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
333     nlohmann::json jsonObj;
334     jsonObj[TAG_CRYPTO_SUPPORT] = "CRYPTOSUPPORT";
335     jsonObj[TAG_CRYPTO_SUPPORT] = authMessageProcessor->authResponseContext_->cryptoSupport;
336     authResponseContext->localDeviceId = "22";
337     authResponseContext->authType = 1;
338     authResponseContext->reply = 33;
339     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
340     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
341     jsonObj[TAG_REPLY] = authResponseContext->reply;
342     authMessageProcessor->SetResponseContext(authResponseContext);
343     authMessageProcessor->ParseNegotiateMessage(jsonObj);
344     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
345 }
346 
347 /**
348  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_002
349  * @tc.desc: Compare authResponseContext before and after assignment
350  * @tc.type: FUNC
351  * @tc.require: AR000GHSJK
352  */
353 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::TestSize.Level0)
354 {
355     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
356     std::shared_ptr<DmAuthManager> data =
357         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
358     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
359     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
360     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
361     nlohmann::json jsonObj;
362     authResponseContext->localDeviceId = "22";
363     authResponseContext->authType = 1;
364     authResponseContext->reply = 33;
365     jsonObj[TAG_CRYPTO_NAME] = "CRYPTONAME";
366     jsonObj[TAG_CRYPTO_NAME] = authResponseContext->cryptoSupport;
367     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
368     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
369     jsonObj[TAG_REPLY] = authResponseContext->reply;
370     authMessageProcessor->SetResponseContext(authResponseContext);
371     authMessageProcessor->ParseNegotiateMessage(jsonObj);
372     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
373 }
374 
375 /**
376  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_003
377  * @tc.desc: Compare authResponseContext before and after assignment
378  * @tc.type: FUNC
379  * @tc.require: AR000GHSJK
380  */
381 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::TestSize.Level0)
382 {
383     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
384     std::shared_ptr<DmAuthManager> data =
385         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
386     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
387     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
388     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
389     nlohmann::json jsonObj;
390     authResponseContext->localDeviceId = "22";
391     authResponseContext->authType = 1;
392     authResponseContext->reply = 33;
393     jsonObj[TAG_CRYPTO_VERSION] = "CRYPTOVERSION";
394     jsonObj[TAG_CRYPTO_VERSION] = authResponseContext->cryptoSupport;
395     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
396     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
397     jsonObj[TAG_REPLY] = authResponseContext->reply;
398     authMessageProcessor->SetResponseContext(authResponseContext);
399     authMessageProcessor->ParseNegotiateMessage(jsonObj);
400     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
401 }
402 
403 /**
404  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_004
405  * @tc.desc: Compare authResponseContext before and after assignment
406  * @tc.type: FUNC
407  * @tc.require: AR000GHSJK
408  */
409 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::TestSize.Level0)
410 {
411     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
412     std::shared_ptr<DmAuthManager> data =
413         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
414     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
415     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
416     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
417     nlohmann::json jsonObj;
418     authResponseContext->localDeviceId = "22";
419     authResponseContext->authType = 1;
420     authResponseContext->reply = 33;
421     jsonObj[TAG_DEVICE_ID] = "DEVICEID";
422     jsonObj[TAG_DEVICE_ID] = authResponseContext->deviceId;
423     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
424     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
425     jsonObj[TAG_REPLY] = authResponseContext->reply;
426     authMessageProcessor->SetResponseContext(authResponseContext);
427     authMessageProcessor->ParseNegotiateMessage(jsonObj);
428     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
429 }
430 
431 /**
432  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_005
433  * @tc.desc: Compare authResponseContext before and after assignment
434  * @tc.type: FUNC
435  * @tc.require: AR000GHSJK
436  */
437 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::TestSize.Level0)
438 {
439     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
440     std::shared_ptr<DmAuthManager> data =
441         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
442     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
443     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
444     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
445     nlohmann::json jsonObj;
446     authResponseContext->localDeviceId = "22";
447     authResponseContext->authType = 1;
448     authResponseContext->reply = 33;
449     jsonObj[TAG_LOCAL_DEVICE_ID] = "LOCALDEVICEID";
450     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
451     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
452     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
453     jsonObj[TAG_REPLY] = authResponseContext->reply;
454     authMessageProcessor->SetResponseContext(authResponseContext);
455     authMessageProcessor->ParseNegotiateMessage(jsonObj);
456     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
457 }
458 
459 /**
460  * @tc.name: AuthMessageProcessor::SetRequestContext_001
461  * @tc.desc: Compare authResponseContext before and after assignment
462  * @tc.type: FUNC
463  * @tc.require: AR000GHSJK
464  */
465 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize.Level0)
466 {
467     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
468     std::shared_ptr<DmAuthManager> data =
469         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
470     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
471     std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
472     authMessageProcessor->SetRequestContext(authRequestContext);
473     ASSERT_EQ(authMessageProcessor->authRequestContext_, authRequestContext);
474 }
475 
476 /**
477  * @tc.name: AuthMessageProcessor::SetRequestContext_002
478  * @tc.desc: Judge whether authrequestcontext is empty
479  * @tc.type: FUNC
480  * @tc.require: AR000GHSJK
481  */
482 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize.Level0)
483 {
484     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
485     std::shared_ptr<DmAuthManager> data =
486         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
487     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
488     std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
489     authMessageProcessor->SetRequestContext(nullptr);
490     ASSERT_EQ(authMessageProcessor->authRequestContext_, nullptr);
491 }
492 
493 /**
494  * @tc.name: AuthMessageProcessor::SetResponseContext_001
495  * @tc.desc: Compare authResponseContext before and after assignment
496  * @tc.type: FUNC
497  * @tc.require: AR000GHSJK
498  */
499 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSize.Level0)
500 {
501     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
502     std::shared_ptr<DmAuthManager> data =
503         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
504     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
505     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
506     authMessageProcessor->SetResponseContext(authResponseContext);
507     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
508 }
509 
510 /**
511  * @tc.name: AuthMessageProcessor::SetResponseContext_002
512  * @tc.desc: Judge whether authrequestcontext is empty
513  * @tc.type: FUNC
514  * @tc.require: AR000GHSJK
515  */
516 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSize.Level0)
517 {
518     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
519     std::shared_ptr<DmAuthManager> data =
520         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
521     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
522     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
523     authMessageProcessor->SetResponseContext(nullptr);
524     ASSERT_EQ(authMessageProcessor->authResponseContext_, nullptr);
525 }
526 
527 /**
528  * @tc.name: AuthMessageProcessor::GetResponseContext_001
529  * @tc.desc: Compare authResponseContext before and after assignment
530  * @tc.type: FUNC
531  * @tc.require: AR000GHSJK
532  */
533 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSize.Level0)
534 {
535     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
536     std::shared_ptr<DmAuthManager> data =
537         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
538     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
539     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
540     std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
541     ASSERT_EQ(authResponseContext, authMessageProcessor->authResponseContext_);
542 }
543 
544 /**
545  * @tc.name: AuthMessageProcessor::GetResponseContext_002
546  * @tc.desc: Judge whether authrequestcontext is empty
547  * @tc.type: FUNC
548  * @tc.require: AR000GHSJK
549  */
550 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_002, testing::ext::TestSize.Level0)
551 {
552     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
553     std::shared_ptr<DmAuthManager> data =
554         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
555     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
556     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
557     std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
558     ASSERT_NE(authResponseContext, nullptr);
559 }
560 
561 /**
562  * @tc.name: AuthMessageProcessor::CreateSimpleMessage_001
563  * @tc.desc: return the length of string is empty
564  * @tc.type: FUNC
565  * @tc.require: AR000GHSJK
566  */
567 HWTEST_F(AuthMessageProcessorTest, CreateSimpleMessage_001, testing::ext::TestSize.Level0)
568 {
569     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
570     std::shared_ptr<DmAuthManager> data =
571         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
572     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
573     authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
574     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
575     int32_t msgType = MSG_TYPE_SYNC_GROUP;
576     std::string ret = authMessageProcessor->CreateSimpleMessage(msgType);
577     ASSERT_NE(ret.size(), 0);
578     msgType = MSG_TYPE_RESP_AUTH;
579     ret = authMessageProcessor->CreateSimpleMessage(msgType);
580     ASSERT_NE(ret.size(), 0);
581     msgType = MSG_TYPE_REQ_AUTH_TERMINATE;
582     ret = authMessageProcessor->CreateSimpleMessage(msgType);
583     ASSERT_NE(ret.size(), 0);
584 }
585 
586 /**
587  * @tc.name: AuthMessageProcessor::GetRequestContext_001
588  * @tc.desc: Compare authRequestContext before and after assignment
589  * @tc.type: FUNC
590  * @tc.require: AR000GHSJK
591  */
592 HWTEST_F(AuthMessageProcessorTest, GetRequestContext_001, testing::ext::TestSize.Level0)
593 {
594     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
595     std::shared_ptr<DmAuthManager> data =
596         std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
597     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
598     std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
599     authMessageProcessor->SetRequestContext(authRequestContext);
600     auto ret = authMessageProcessor->GetRequestContext();
601     ASSERT_EQ(authMessageProcessor->authRequestContext_, ret);
602 }
603 } // namespace
604 } // namespace DistributedHardware
605 } // namespace OHOS
606