• 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 {
28 constexpr const char* TAG_APP_THUMBNAIL = "APPTHUM";
29 constexpr const char* TAG_HOST = "HOST";
30 
SetUp()31 void AuthMessageProcessorTest::SetUp()
32 {
33 }
TearDown()34 void AuthMessageProcessorTest::TearDown()
35 {
36 }
SetUpTestCase()37 void AuthMessageProcessorTest::SetUpTestCase()
38 {
39 }
TearDownTestCase()40 void AuthMessageProcessorTest::TearDownTestCase()
41 {
42 }
43 
44 namespace {
45 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
46 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
47 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
48 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector = std::make_shared<HiChainAuthConnector>();
49 /**
50  * @tc.name: AuthMessageProcessor::AuthMessageProcessor_001
51  * @tc.desc: 1 set cryptoAdapter_ to null
52  *           2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr
53  *           3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
54  * @tc.type: FUNC
55  * @tc.require: AR000GHSJK
56  */
57 HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_001, testing::ext::TestSize.Level0)
58 {
59     std::shared_ptr<DmAuthManager> Test =
60         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
61     ASSERT_NE(Test, nullptr);
62 }
63 
64 /**
65  * @tc.name: AuthMessageProcessor::AuthMessageProcessor_001
66  * @tc.desc: 1 set cryptoAdapter_ to null
67  *           2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr
68  *           3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
69  * @tc.type: FUNC
70  * @tc.require: AR000GHSJK
71  */
72 HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_002, testing::ext::TestSize.Level0)
73 {
74     std::shared_ptr<DmAuthManager> Test =
75         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
76     Test.reset();
77     EXPECT_EQ(Test, nullptr);
78 }
79 
80 /**
81  * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001
82  * @tc.desc: 1 set cryptoAdapter_ to null
83  *           2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr
84  *           3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
85  * @tc.type: FUNC
86  * @tc.require: AR000GHSJK
87  */
88 HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::TestSize.Level0)
89 {
90     std::shared_ptr<DmAuthManager> data =
91         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
92     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
93     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
94     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
95     int32_t msgType = MSG_TYPE_NEGOTIATE;
96     nlohmann::json jsonObj;
97     jsonObj[TAG_VER] = DM_ITF_VER;
98     jsonObj[TAG_MSG_TYPE] = msgType;
99     jsonObj[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
100     authMessageProcessor->SetResponseContext(authResponseContext);
101     authMessageProcessor->cryptoAdapter_ = nullptr;
102     authMessageProcessor->CreateNegotiateMessage(jsonObj);
103     std::string str1 = jsonObj.dump();
104 
105     nlohmann::json jsonObject;
106     jsonObject[TAG_ACCOUNT_GROUPID] = "";
107     jsonObject[TAG_VER] = DM_ITF_VER;
108     jsonObject[TAG_MSG_TYPE] = msgType;
109     jsonObject[TAG_CRYPTO_SUPPORT] = false;
110     jsonObject[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
111     jsonObject[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
112     jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId;
113     jsonObject[TAG_HOST] = "";
114     std::string str2 = jsonObject.dump();
115     ASSERT_NE(str1, str2);
116 }
117 
118 /**
119  * @tc.name: AuthMessageProcessor::CreateSyncGroupMessage_001
120  * @tc.desc: Compare JSON before and after assignment
121  * @tc.type: FUNC
122  * @tc.require: AR000GHSJK
123  */
124 HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::TestSize.Level0)
125 {
126     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
127     std::shared_ptr<DmAuthManager> data =
128         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
129     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
130     authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
131     nlohmann::json jsona;
132     nlohmann::json jsonObj;
133     authMessageProcessor->authRequestContext_->deviceId = "132416546";
134     std::vector<std::string> syncGroupList;
135     syncGroupList.push_back("1111");
136     authMessageProcessor->authRequestContext_->syncGroupList = syncGroupList;
137     jsona[TAG_DEVICE_ID] = authMessageProcessor->authRequestContext_->deviceId;
138     jsona[TAG_GROUPIDS] = authMessageProcessor->authRequestContext_->syncGroupList;
139     authMessageProcessor->CreateSyncGroupMessage(jsonObj);
140     std::string str1 = jsona.dump();
141     std::string str2 = jsonObj.dump();
142     ASSERT_EQ(str1, str2);
143 }
144 
145 /**
146  * @tc.name: AuthMessageProcessor::CreateResponseAuthMessage_001
147  * @tc.desc: Compare JSON before and after assignment
148  * @tc.type: FUNC
149  * @tc.require: AR000GHSJK
150  */
151 HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext::TestSize.Level0)
152 {
153     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
154     std::shared_ptr<DmAuthManager> data =
155         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
156     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
157     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
158     nlohmann::json jsona;
159     nlohmann::json jsonObj;
160     authMessageProcessor->authResponseContext_->reply = 0;
161     authMessageProcessor->authResponseContext_->deviceId = "132416546";
162     authMessageProcessor->authResponseContext_->token = "11";
163     nlohmann::json jsonb;
164     jsonb[TAG_GROUP_ID] = "123456";
165     authMessageProcessor->authResponseContext_->groupId = jsonb.dump();
166     authMessageProcessor->authResponseContext_->authToken = "123456";
167     authMessageProcessor->authResponseContext_->networkId = "11112222";
168     authMessageProcessor->authResponseContext_->requestId = 222222;
169     authMessageProcessor->authResponseContext_->groupName = "333333";
170     jsona[TAG_TOKEN] = authMessageProcessor->authResponseContext_->token;
171     jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
172     jsona[TAG_DEVICE_ID] = authMessageProcessor->authResponseContext_->deviceId;
173     jsona[TAG_AUTH_TOKEN] = authMessageProcessor->authResponseContext_->authToken;
174     jsona[TAG_NET_ID] = authMessageProcessor->authResponseContext_->networkId;
175     jsona[TAG_REQUEST_ID] = authMessageProcessor->authResponseContext_->requestId;
176     jsona[TAG_GROUP_ID] = "123456";
177     jsona[TAG_GROUP_NAME] = authMessageProcessor->authResponseContext_->groupName;
178     authMessageProcessor->CreateResponseAuthMessage(jsonObj);
179     std::string str1 = jsona.dump();
180     std::string str2 = jsonObj.dump();
181     ASSERT_EQ(str1, str2);
182 }
183 
184 /**
185  * @tc.name: AuthMessageProcessor::CreateResponseFinishMessage_001
186  * @tc.desc: Compare JSON before and after assignment
187  * @tc.type: FUNC
188  * @tc.require: AR000GHSJK
189  */
190 HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext::TestSize.Level0)
191 {
192     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
193     std::shared_ptr<DmAuthManager> data =
194         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
195     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
196     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
197     nlohmann::json jsona;
198     nlohmann::json jsonObj;
199     authMessageProcessor->authResponseContext_->reply = 1;
200     jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
201     authMessageProcessor->CreateResponseFinishMessage(jsonObj);
202     std::string str1 = jsona.dump();
203     std::string str2 = jsonObj.dump();
204     ASSERT_EQ(str1, str2);
205 }
206 
207 /**
208  * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_001
209  * @tc.desc: Compare JSON before and after assignment
210  * @tc.type: FUNC
211  * @tc.require: AR000GHSJK
212  */
213 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext::TestSize.Level0)
214 {
215     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
216     std::shared_ptr<DmAuthManager> data =
217         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
218     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
219     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
220     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
221     nlohmann::json jsonObj;
222     authMessageProcessor->authResponseContext_->reply = 1;
223     jsonObj[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
224     authMessageProcessor->SetResponseContext(authResponseContext);
225     authMessageProcessor->ParseResponseFinishMessage(jsonObj);
226     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
227 }
228 
229 /**
230  * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_002
231  * @tc.desc: Compare JSON before and after assignment
232  * @tc.type: FUNC
233  * @tc.require: AR000GHSJK
234  */
235 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_002, testing::ext::TestSize.Level0)
236 {
237     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
238     std::shared_ptr<DmAuthManager> data =
239         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
240     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
241     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
242     nlohmann::json jsonObj;
243     jsonObj[TAG_REPLY] = 22;
244     authMessageProcessor->ParseResponseFinishMessage(jsonObj);
245     ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, jsonObj[TAG_REPLY]);
246 }
247 
248 /**
249  * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_003
250  * @tc.desc: Compare JSON before and after assignment
251  * @tc.type: FUNC
252  * @tc.require: AR000GHSJK
253  */
254 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_003, testing::ext::TestSize.Level0)
255 {
256     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
257     std::shared_ptr<DmAuthManager> data =
258         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
259     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
260     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
261     std::string str = R"(
262     {
263         "REPLY" : "30000000000"
264     }
265     )";
266     nlohmann::json jsonObj = nlohmann::json::parse(str, nullptr, false);
267     authMessageProcessor->ParseResponseFinishMessage(jsonObj);
268     ASSERT_NE(authMessageProcessor->authResponseContext_->reply, jsonObj[TAG_REPLY]);
269 }
270 
271 /**
272  * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_001
273  * @tc.desc: Compare JSON before and after assi gnment
274  * @tc.type: FUNC
275  * @tc.require: AR000GHSJK
276  */
277 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::TestSize.Level0)
278 {
279     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
280     std::shared_ptr<DmAuthManager> data =
281         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
282     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
283     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
284     nlohmann::json jsona;
285     authResponseContext->reply = 0;
286     authResponseContext->deviceId = "11111";
287     authResponseContext->authToken = "123456";
288     authResponseContext->networkId = "12345";
289     authResponseContext->requestId = 2;
290     authResponseContext->groupId = "23456";
291     authResponseContext->groupName = "34567";
292     authResponseContext->token = "11123";
293     jsona[TAG_TOKEN] = authResponseContext->token;
294     jsona[TAG_REPLY] = authResponseContext->reply;
295     jsona[TAG_DEVICE_ID] = authResponseContext->deviceId;
296     jsona[TAG_AUTH_TOKEN] = authResponseContext->authToken;
297     jsona[TAG_NET_ID] = authResponseContext->networkId;
298     jsona[TAG_REQUEST_ID] = authResponseContext->requestId;
299     jsona[TAG_GROUP_ID] = authResponseContext->groupId;
300     jsona[TAG_GROUP_NAME] = authResponseContext->groupName;
301     authMessageProcessor->SetResponseContext(authResponseContext);
302     authMessageProcessor->ParseAuthResponseMessage(jsona);
303     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
304 }
305 
306 /**
307  * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_001
308  * @tc.desc: Compare JSON before and after assignment
309  * @tc.type: FUNC
310  * @tc.require: AR000GHSJK
311  */
312 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::TestSize.Level0)
313 {
314     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
315     std::shared_ptr<DmAuthManager> data =
316         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
317     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
318     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
319     authMessageProcessor->SetResponseContext(authResponseContext);
320     nlohmann::json jsonThumbnail;
321     authResponseContext->deviceId = "123";
322     authResponseContext->reply = 0;
323     authResponseContext->authType = 222;
324     authResponseContext->networkId = "234";
325     authResponseContext->groupId = "345";
326     authResponseContext->groupName = "456";
327     authResponseContext->requestId = 2333;
328     jsonThumbnail[TAG_DEVICE_ID] = authResponseContext->deviceId;
329     jsonThumbnail[TAG_REPLY] = authResponseContext->reply;
330     jsonThumbnail[TAG_AUTH_TYPE] = authResponseContext->authType;
331     jsonThumbnail[TAG_NET_ID] = authResponseContext->networkId;
332     jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId;
333     jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName;
334     jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId;
335     int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
336     ASSERT_EQ(ret, ERR_DM_FAILED);
337 }
338 
339 /**
340  * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_002
341  * @tc.desc: Compare JSON before and after assignment
342  * @tc.type: FUNC
343  * @tc.require: AR000GHSJK
344  */
345 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::TestSize.Level0)
346 {
347     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
348     std::shared_ptr<DmAuthManager> data =
349         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
350     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
351     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
352     authMessageProcessor->SetResponseContext(authResponseContext);
353     nlohmann::json jsonThumbnail;
354     jsonThumbnail[TAG_SLICE_NUM] = 1;
355     jsonThumbnail[TAG_INDEX] = 0;
356     jsonThumbnail[TAG_DEVICE_ID] = "123";
357     jsonThumbnail[TAG_AUTH_TYPE] = 1;
358     jsonThumbnail[TAG_CUSTOM_DESCRIPTION] = "123";
359     jsonThumbnail[TAG_TOKEN] = "1234";
360     jsonThumbnail[TAG_TARGET] = "12345";
361     jsonThumbnail[TAG_APP_OPERATION] = "123456";
362     jsonThumbnail[TAG_LOCAL_DEVICE_ID] = "localdeviceTest";
363     jsonThumbnail[TAG_REQUESTER] = "AJ125S25S3E65F1A24T";
364     jsonThumbnail[TAG_DEVICE_TYPE] = 1;
365     int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
366     ASSERT_EQ(ret, DM_OK);
367 }
368 
369 /**
370  * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_003
371  * @tc.desc: Compare JSON before and after assignment
372  * @tc.type: FUNC
373  * @tc.require: AR000GHSJK
374  */
375 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_003, testing::ext::TestSize.Level0)
376 {
377     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
378     std::shared_ptr<DmAuthManager> data =
379         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
380     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
381     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
382     authMessageProcessor->SetResponseContext(authResponseContext);
383     nlohmann::json jsonThumbnail;
384     jsonThumbnail[TAG_SLICE_NUM] = 1;
385     jsonThumbnail[TAG_INDEX] = 0;
386     jsonThumbnail[TAG_DEVICE_ID] = 123;
387     jsonThumbnail[TAG_AUTH_TYPE] = 1;
388     jsonThumbnail[TAG_CUSTOM_DESCRIPTION] = "123";
389     jsonThumbnail[TAG_TOKEN] = "1234";
390     jsonThumbnail[TAG_TARGET] = "12345";
391     jsonThumbnail[TAG_APP_OPERATION] = "123456";
392     int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
393     ASSERT_EQ(ret, DM_OK);
394 }
395 
396 /**
397  * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_004
398  * @tc.desc: Compare JSON before and after assignment
399  * @tc.type: FUNC
400  * @tc.require: AR000GHSJK
401  */
402 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_004, testing::ext::TestSize.Level0)
403 {
404     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
405     std::shared_ptr<DmAuthManager> data =
406         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
407     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
408     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
409     authMessageProcessor->SetResponseContext(authResponseContext);
410     nlohmann::json jsonThumbnail;
411     jsonThumbnail[TAG_SLICE_NUM] = 1;
412     jsonThumbnail[TAG_INDEX] = 0;
413     jsonThumbnail[TAG_DEVICE_ID] = "123";
414     jsonThumbnail[TAG_AUTH_TYPE] = 1;
415     jsonThumbnail[TAG_CUSTOM_DESCRIPTION] = "123";
416     jsonThumbnail[TAG_TOKEN] = "1234";
417     jsonThumbnail[TAG_TARGET] = "12345";
418     jsonThumbnail[TAG_APP_OPERATION] = "123456";
419     jsonThumbnail[TAG_APP_THUMBNAIL] = "jsontest";
420     jsonThumbnail[TAG_LOCAL_DEVICE_ID] = "localdeviceTest";
421     jsonThumbnail[TAG_REQUESTER] = "iknbghkkj266SSjsjjdan21526";
422     jsonThumbnail[TAG_DEVICE_TYPE] = 1;
423     int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
424     ASSERT_EQ(ret, ERR_DM_AUTH_MESSAGE_INCOMPLETE);
425 }
426 
427 /**
428  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_001
429  * @tc.desc: Compare authResponseContext before and after assignment
430  * @tc.type: FUNC
431  * @tc.require: AR000GHSJK
432  */
433 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::TestSize.Level0)
434 {
435     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
436     std::shared_ptr<DmAuthManager> data =
437         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
438     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
439     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
440     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
441     nlohmann::json jsonObj;
442     jsonObj[TAG_CRYPTO_SUPPORT] = "CRYPTOSUPPORT";
443     jsonObj[TAG_CRYPTO_SUPPORT] = authMessageProcessor->authResponseContext_->cryptoSupport;
444     authResponseContext->localDeviceId = "22";
445     authResponseContext->authType = 1;
446     authResponseContext->reply = 33;
447     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
448     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
449     jsonObj[TAG_REPLY] = authResponseContext->reply;
450     authMessageProcessor->SetResponseContext(authResponseContext);
451     authMessageProcessor->ParseNegotiateMessage(jsonObj);
452     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
453 }
454 
455 /**
456  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_002
457  * @tc.desc: Compare authResponseContext before and after assignment
458  * @tc.type: FUNC
459  * @tc.require: AR000GHSJK
460  */
461 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::TestSize.Level0)
462 {
463     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
464     std::shared_ptr<DmAuthManager> data =
465         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
466     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
467     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
468     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
469     nlohmann::json jsonObj;
470     authResponseContext->localDeviceId = "22";
471     authResponseContext->authType = 1;
472     authResponseContext->reply = 33;
473     jsonObj[TAG_CRYPTO_NAME] = "CRYPTONAME";
474     jsonObj[TAG_CRYPTO_NAME] = authResponseContext->cryptoSupport;
475     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
476     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
477     jsonObj[TAG_REPLY] = authResponseContext->reply;
478     authMessageProcessor->SetResponseContext(authResponseContext);
479     authMessageProcessor->ParseNegotiateMessage(jsonObj);
480     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
481 }
482 
483 /**
484  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_003
485  * @tc.desc: Compare authResponseContext before and after assignment
486  * @tc.type: FUNC
487  * @tc.require: AR000GHSJK
488  */
489 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::TestSize.Level0)
490 {
491     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
492     std::shared_ptr<DmAuthManager> data =
493         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
494     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
495     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
496     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
497     nlohmann::json jsonObj;
498     authResponseContext->localDeviceId = "22";
499     authResponseContext->authType = 1;
500     authResponseContext->reply = 33;
501     jsonObj[TAG_CRYPTO_VERSION] = "CRYPTOVERSION";
502     jsonObj[TAG_CRYPTO_VERSION] = authResponseContext->cryptoSupport;
503     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
504     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
505     jsonObj[TAG_REPLY] = authResponseContext->reply;
506     authMessageProcessor->SetResponseContext(authResponseContext);
507     authMessageProcessor->ParseNegotiateMessage(jsonObj);
508     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
509 }
510 
511 /**
512  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_004
513  * @tc.desc: Compare authResponseContext before and after assignment
514  * @tc.type: FUNC
515  * @tc.require: AR000GHSJK
516  */
517 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::TestSize.Level0)
518 {
519     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
520     std::shared_ptr<DmAuthManager> data =
521         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
522     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
523     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
524     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
525     nlohmann::json jsonObj;
526     authResponseContext->localDeviceId = "22";
527     authResponseContext->authType = 1;
528     authResponseContext->reply = 33;
529     jsonObj[TAG_DEVICE_ID] = "DEVICEID";
530     jsonObj[TAG_DEVICE_ID] = authResponseContext->deviceId;
531     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
532     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
533     jsonObj[TAG_REPLY] = authResponseContext->reply;
534     authMessageProcessor->SetResponseContext(authResponseContext);
535     authMessageProcessor->ParseNegotiateMessage(jsonObj);
536     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
537 }
538 
539 /**
540  * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_005
541  * @tc.desc: Compare authResponseContext before and after assignment
542  * @tc.type: FUNC
543  * @tc.require: AR000GHSJK
544  */
545 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::TestSize.Level0)
546 {
547     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
548     std::shared_ptr<DmAuthManager> data =
549         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
550     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
551     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
552     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
553     nlohmann::json jsonObj;
554     authResponseContext->localDeviceId = "22";
555     authResponseContext->authType = 1;
556     authResponseContext->reply = 33;
557     jsonObj[TAG_LOCAL_DEVICE_ID] = "LOCALDEVICEID";
558     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
559     jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
560     jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
561     jsonObj[TAG_REPLY] = authResponseContext->reply;
562     authMessageProcessor->SetResponseContext(authResponseContext);
563     authMessageProcessor->ParseNegotiateMessage(jsonObj);
564     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
565 }
566 
567 /**
568  * @tc.name: AuthMessageProcessor::ParseRespNegotiateMessage_001
569  * @tc.desc: return true
570  * @tc.type: FUNC
571  * @tc.require: AR000GHSJK
572  */
573 HWTEST_F(AuthMessageProcessorTest, ParseRespNegotiateMessage_001, testing::ext::TestSize.Level0)
574 {
575     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
576     std::shared_ptr<DmAuthManager> data =
577         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
578     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
579     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
580     authMessageProcessor->SetResponseContext(authResponseContext);
581     nlohmann::json jsonObj;
582     jsonObj[TAG_IDENTICAL_ACCOUNT] = false;
583     authMessageProcessor->ParseRespNegotiateMessage(jsonObj);
584     ASSERT_EQ(authMessageProcessor->authResponseContext_->isIdenticalAccount, jsonObj[TAG_IDENTICAL_ACCOUNT]);
585 }
586 
587 /**
588  * @tc.name: AuthMessageProcessor::ParseRespNegotiateMessage_002
589  * @tc.desc: return true
590  * @tc.type: FUNC
591  * @tc.require: AR000GHSJK
592  */
593 HWTEST_F(AuthMessageProcessorTest, ParseRespNegotiateMessage_002, testing::ext::TestSize.Level0)
594 {
595     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
596     std::shared_ptr<DmAuthManager> data =
597         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
598     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
599     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
600     authMessageProcessor->SetResponseContext(authResponseContext);
601     nlohmann::json jsonObj;
602     jsonObj[TAG_IDENTICAL_ACCOUNT] = "test";
603     authMessageProcessor->ParseRespNegotiateMessage(jsonObj);
604     ASSERT_NE(authMessageProcessor->authResponseContext_->isIdenticalAccount, jsonObj[TAG_IDENTICAL_ACCOUNT]);
605 }
606 
607 /**
608  * @tc.name: AuthMessageProcessor::SetRequestContext_001
609  * @tc.desc: Compare authResponseContext before and after assignment
610  * @tc.type: FUNC
611  * @tc.require: AR000GHSJK
612  */
613 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize.Level0)
614 {
615     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
616     std::shared_ptr<DmAuthManager> data =
617         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
618     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
619     std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
620     authMessageProcessor->SetRequestContext(authRequestContext);
621     ASSERT_EQ(authMessageProcessor->authRequestContext_, authRequestContext);
622 }
623 
624 /**
625  * @tc.name: AuthMessageProcessor::SetRequestContext_002
626  * @tc.desc: Judge whether authrequestcontext is empty
627  * @tc.type: FUNC
628  * @tc.require: AR000GHSJK
629  */
630 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize.Level0)
631 {
632     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
633     std::shared_ptr<DmAuthManager> data =
634         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
635     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
636     std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
637     authMessageProcessor->SetRequestContext(nullptr);
638     ASSERT_EQ(authMessageProcessor->authRequestContext_, nullptr);
639 }
640 
641 /**
642  * @tc.name: AuthMessageProcessor::SetResponseContext_001
643  * @tc.desc: Compare authResponseContext before and after assignment
644  * @tc.type: FUNC
645  * @tc.require: AR000GHSJK
646  */
647 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSize.Level0)
648 {
649     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
650     std::shared_ptr<DmAuthManager> data =
651         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
652     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
653     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
654     authMessageProcessor->SetResponseContext(authResponseContext);
655     ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
656 }
657 
658 /**
659  * @tc.name: AuthMessageProcessor::SetResponseContext_002
660  * @tc.desc: Judge whether authrequestcontext is empty
661  * @tc.type: FUNC
662  * @tc.require: AR000GHSJK
663  */
664 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSize.Level0)
665 {
666     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
667     std::shared_ptr<DmAuthManager> data =
668         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
669     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
670     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
671     authMessageProcessor->SetResponseContext(nullptr);
672     ASSERT_EQ(authMessageProcessor->authResponseContext_, nullptr);
673 }
674 
675 /**
676  * @tc.name: AuthMessageProcessor::GetResponseContext_001
677  * @tc.desc: Compare authResponseContext before and after assignment
678  * @tc.type: FUNC
679  * @tc.require: AR000GHSJK
680  */
681 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSize.Level0)
682 {
683     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
684     std::shared_ptr<DmAuthManager> data =
685         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
686     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
687     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
688     std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
689     ASSERT_EQ(authResponseContext, authMessageProcessor->authResponseContext_);
690 }
691 
692 /**
693  * @tc.name: AuthMessageProcessor::GetResponseContext_002
694  * @tc.desc: Judge whether authrequestcontext is empty
695  * @tc.type: FUNC
696  * @tc.require: AR000GHSJK
697  */
698 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_002, testing::ext::TestSize.Level0)
699 {
700     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
701     std::shared_ptr<DmAuthManager> data =
702         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
703     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
704     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
705     std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
706     ASSERT_NE(authResponseContext, nullptr);
707 }
708 
709 /**
710  * @tc.name: AuthMessageProcessor::CreateSimpleMessage_001
711  * @tc.desc: return the length of string is empty
712  * @tc.type: FUNC
713  * @tc.require: AR000GHSJK
714  */
715 HWTEST_F(AuthMessageProcessorTest, CreateSimpleMessage_001, testing::ext::TestSize.Level0)
716 {
717     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
718     std::shared_ptr<DmAuthManager> data =
719         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
720     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
721     authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
722     authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
723     int32_t msgType = MSG_TYPE_SYNC_GROUP;
724     std::string ret = authMessageProcessor->CreateSimpleMessage(msgType);
725     ASSERT_NE(ret.size(), 0);
726     msgType = MSG_TYPE_RESP_AUTH;
727     ret = authMessageProcessor->CreateSimpleMessage(msgType);
728     ASSERT_NE(ret.size(), 0);
729     msgType = MSG_TYPE_REQ_AUTH_TERMINATE;
730     ret = authMessageProcessor->CreateSimpleMessage(msgType);
731     ASSERT_NE(ret.size(), 0);
732     msgType = MSG_TYPE_RESP_AUTH_EXT;
733     ret = authMessageProcessor->CreateSimpleMessage(msgType);
734     ASSERT_NE(ret.size(), 0);
735     msgType = MSG_TYPE_REQ_PUBLICKEY;
736     ret = authMessageProcessor->CreateSimpleMessage(msgType);
737     ASSERT_NE(ret.size(), 0);
738     msgType = MSG_TYPE_REQ_SYNC_DELETE;
739     ret = authMessageProcessor->CreateSimpleMessage(msgType);
740     ASSERT_NE(ret.size(), 0);
741     msgType = MSG_TYPE_NEGOTIATE;
742     ret = authMessageProcessor->CreateSimpleMessage(msgType);
743     ASSERT_NE(ret.size(), 0);
744     msgType = MSG_TYPE_RESP_NEGOTIATE;
745     ret = authMessageProcessor->CreateSimpleMessage(msgType);
746     ASSERT_NE(ret.size(), 0);
747 }
748 
749 /**
750  * @tc.name: AuthMessageProcessor::GetRequestContext_001
751  * @tc.desc: Compare authRequestContext before and after assignment
752  * @tc.type: FUNC
753  * @tc.require: AR000GHSJK
754  */
755 HWTEST_F(AuthMessageProcessorTest, GetRequestContext_001, testing::ext::TestSize.Level0)
756 {
757     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
758     std::shared_ptr<DmAuthManager> data =
759         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
760     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
761     std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
762     authMessageProcessor->SetRequestContext(authRequestContext);
763     auto ret = authMessageProcessor->GetRequestContext();
764     ASSERT_EQ(authMessageProcessor->authRequestContext_, ret);
765 }
766 
767 /**
768  * @tc.name: AuthMessageProcessor::ParseMessage_001
769  * @tc.desc: Return DM_OK
770  * @tc.type: FUNC
771  * @tc.require: AR000GHSJK
772  */
773 HWTEST_F(AuthMessageProcessorTest, ParseMessage_001, testing::ext::TestSize.Level0)
774 {
775     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
776     std::shared_ptr<DmAuthManager> data =
777         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
778     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
779     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
780     authMessageProcessor->SetResponseContext(authResponseContext);
781     std::string message = R"(
782     {
783         "AUTHTYPE": 1,
784         "CRYPTOSUPPORT": false,
785         "ITF_VER": "1.1",
786         "LOCALDEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
787         "MSG_TYPE": 80,
788         "REPLY": 2016
789     }
790     )";
791     int32_t ret = authMessageProcessor->ParseMessage(message);
792     ASSERT_EQ(ret, DM_OK);
793 }
794 
795 /**
796  * @tc.name: AuthMessageProcessor::ParseMessage_002
797  * @tc.desc: Return DM_OK
798  * @tc.type: FUNC
799  * @tc.require: AR000GHSJK
800  */
801 HWTEST_F(AuthMessageProcessorTest, ParseMessage_002, testing::ext::TestSize.Level0)
802 {
803     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
804     std::shared_ptr<DmAuthManager> data =
805         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
806     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
807     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
808     authMessageProcessor->SetResponseContext(authResponseContext);
809     std::string message = R"(
810     {
811         "AUTHTYPE": 1,
812         "CRYPTOSUPPORT": false,
813         "ITF_VER": "1.1",
814         "LOCALDEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
815         "MSG_TYPE": 90,
816         "REPLY": 2016
817     }
818     )";
819     int32_t ret = authMessageProcessor->ParseMessage(message);
820     ASSERT_EQ(ret, DM_OK);
821 }
822 
823 /**
824  * @tc.name: AuthMessageProcessor::ParseMessage_003
825  * @tc.desc: Return DM_OK
826  * @tc.type: FUNC
827  * @tc.require: AR000GHSJK
828  */
829 HWTEST_F(AuthMessageProcessorTest, ParseMessage_003, testing::ext::TestSize.Level0)
830 {
831     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
832     std::shared_ptr<DmAuthManager> data =
833         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
834     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
835     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
836     authMessageProcessor->SetResponseContext(authResponseContext);
837     std::string message = R"(
838     {
839         "APPDESC": "Distributed Calc",
840         "CUSTOMDESC": "customDescription",
841         "APPICON": "",
842         "APPNAME": "Distributed Calc",
843         "APPOPERATION": "appoperrationTest",
844         "AUTHTYPE":1,
845         "DEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
846         "LOCALDEVICEID": "test0b9186386e87487564b02etest1f904eb9517f262721c9ada090477etest",
847         "DEVICETYPE": 1,
848         "HOST": "com.example.distributedcalc",
849         "INDEX": 0,
850         "ITF_VER": "1.1",
851         "MSG_TYPE": 100,
852         "REQUESTER": "test0b9186386e87487564b02etest1f904eb9517f262721c9ada090477etest",
853         "SLICE": 1,
854         "TARGET": "com.example.distributedcalc",
855         "THUMSIZE": 0,
856         "TOKEN": "73141022",
857         "VISIBILITY": 0
858     }
859     )";
860     int32_t ret = authMessageProcessor->ParseMessage(message);
861     ASSERT_EQ(ret, DM_OK);
862 }
863 
864 /**
865  * @tc.name: AuthMessageProcessor::ParseMessage_004
866  * @tc.desc: Return DM_OK
867  * @tc.type: FUNC
868  * @tc.require: AR000GHSJK
869  */
870 HWTEST_F(AuthMessageProcessorTest, ParseMessage_004, testing::ext::TestSize.Level0)
871 {
872     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
873     std::shared_ptr<DmAuthManager> data =
874         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
875     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
876     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
877     authMessageProcessor->SetResponseContext(authResponseContext);
878     std::string message = R"(
879     {
880         "REPLY": 0,
881         "DEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
882         "TOKEN": "7314",
883         "GROUPNAME": "com.example.test",
884         "ITF_VER": "1.1",
885         "MSG_TYPE": 200,
886         "NETID": "147258963",
887         "REQUESTID": 8448,
888         "authToken": "com.example.distributedcalc62063A65EC8540074FF01413BDC3B6D7",
889         "groupId" : "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5"
890     }
891     )";
892     int32_t ret = authMessageProcessor->ParseMessage(message);
893     ASSERT_EQ(ret, DM_OK);
894 }
895 
896 /**
897  * @tc.name: AuthMessageProcessor::ParseMessage_005
898  * @tc.desc: Return DM_OK
899  * @tc.type: FUNC
900  * @tc.require: AR000GHSJK
901  */
902 HWTEST_F(AuthMessageProcessorTest, ParseMessage_005, testing::ext::TestSize.Level0)
903 {
904     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
905     std::shared_ptr<DmAuthManager> data =
906         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
907     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
908     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
909     authMessageProcessor->SetResponseContext(authResponseContext);
910     std::string message = R"(
911     {
912         "REPLY": 0,
913         "ITF_VER": "1.1",
914         "MSG_TYPE": 104
915     }
916     )";
917     int32_t ret = authMessageProcessor->ParseMessage(message);
918     ASSERT_EQ(ret, DM_OK);
919 }
920 
921 /**
922  * @tc.name: AuthMessageProcessor::ParseMessage_006
923  * @tc.desc: Return ERR_DM_FAILED
924  * @tc.type: FUNC
925  * @tc.require: AR000GHSJK
926  */
927 HWTEST_F(AuthMessageProcessorTest, ParseMessage_006, testing::ext::TestSize.Level0)
928 {
929     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
930     std::shared_ptr<DmAuthManager> data =
931         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
932     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
933     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
934     authMessageProcessor->SetResponseContext(authResponseContext);
935     std::string message = R"(
936     {
937         "REPLY": 1,
938         "ITF_VER": "1.1.2",
939         "MSG_TYPE": "104"
940     }
941     )";
942     int32_t ret = authMessageProcessor->ParseMessage(message);
943     ASSERT_EQ(ret, ERR_DM_FAILED);
944 }
945 
946 HWTEST_F(AuthMessageProcessorTest, ParseMessage_007, testing::ext::TestSize.Level0)
947 {
948     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
949     std::shared_ptr<DmAuthManager> data =
950         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
951     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
952     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
953     authMessageProcessor->SetResponseContext(authResponseContext);
954     std::string message = R"(
955     {
956         "REPLY": 1,
957         "LOCALDEVICEID": "devId_4655198_test",
958         "hostPkgname": "pkgname_dm_test"
959         "MSG_TYPE": "501",
960     }
961     )";
962     int32_t ret = authMessageProcessor->ParseMessage(message);
963     ASSERT_EQ(ret, ERR_DM_FAILED);
964 }
965 
966 HWTEST_F(AuthMessageProcessorTest, ParseMessage_008, testing::ext::TestSize.Level0)
967 {
968     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
969     std::shared_ptr<DmAuthManager> data =
970         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
971     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
972     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
973     authMessageProcessor->SetResponseContext(authResponseContext);
974     std::string message = R"(
975     {
976         "publicKey": "publicKey_test",
977         "MSG_TYPE": "502",
978     }
979     )";
980     int32_t ret = authMessageProcessor->ParseMessage(message);
981     ASSERT_EQ(ret, ERR_DM_FAILED);
982 }
983 
984 HWTEST_F(AuthMessageProcessorTest, ParseMessage_009, testing::ext::TestSize.Level0)
985 {
986     std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
987     std::shared_ptr<DmAuthManager> data =
988         std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
989     std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
990     std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
991     authMessageProcessor->SetResponseContext(authResponseContext);
992     std::string message = R"(
993     {
994         "REPLY": 1,
995         "tokenId": "tokenId_123_test",
996         "confirmOperation": "1",
997         "REQUESTID": "1",
998         "MSG_TYPE": "501",
999     }
1000     )";
1001     int32_t ret = authMessageProcessor->ParseMessage(message);
1002     ASSERT_EQ(ret, ERR_DM_FAILED);
1003 
1004     nlohmann::json jsonObj;
1005     jsonObj[TAG_LOCAL_ACCOUNTID] = "local_accountId_123";
1006     jsonObj[TAG_LOCAL_USERID] = 1;
1007     jsonObj[TAG_BIND_LEVEL] = 1;
1008     jsonObj[TAG_ISONLINE] = true;
1009     jsonObj[TAG_IDENTICAL_ACCOUNT] = true;
1010     jsonObj[TAG_AUTHED] = true;
1011     jsonObj[TAG_TOKENID] = 100;
1012         jsonObj[TAG_DMVERSION] = "1.1.1";
1013     jsonObj[TAG_HAVECREDENTIAL] = true;
1014     jsonObj[TAG_BIND_TYPE_SIZE] = 5;
1015     authMessageProcessor->ParsePkgNegotiateMessage(jsonObj);
1016 }
1017 } // namespace
1018 } // namespace DistributedHardware
1019 } // namespace OHOS
1020