1 /*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "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
31 class CryptoAdapterTest : public ICryptoAdapter {
32 public:
CryptoAdapterTest()33 CryptoAdapterTest() {}
~CryptoAdapterTest()34 virtual ~CryptoAdapterTest() {}
GetName()35 std::string GetName() override
36 {
37 return "";
38 }
GetVersion()39 std::string GetVersion() override
40 {
41 return "";
42 }
MbedTlsEncrypt(const uint8_t * plainText,int32_t plainTextLen,uint8_t * cipherText,int32_t cipherTextLen,int32_t * outLen)43 int32_t MbedTlsEncrypt(const uint8_t *plainText, int32_t plainTextLen, uint8_t *cipherText, int32_t cipherTextLen,
44 int32_t *outLen) override
45 {
46 (void)plainText;
47 (void)plainTextLen;
48 (void)cipherText;
49 (void)cipherTextLen;
50 return DM_OK;
51 }
MbedTlsDecrypt(const uint8_t * cipherText,int32_t cipherTextLen,uint8_t * plainText,int32_t plainTextLen,int32_t * outLen)52 int32_t MbedTlsDecrypt(const uint8_t *cipherText, int32_t cipherTextLen, uint8_t *plainText, int32_t plainTextLen,
53 int32_t *outLen) override
54 {
55 (void)cipherText;
56 (void)cipherTextLen;
57 (void)plainText;
58 (void)plainTextLen;
59 return DM_OK;
60 }
61 };
62
SetUp()63 void AuthMessageProcessorTest::SetUp()
64 {
65 }
TearDown()66 void AuthMessageProcessorTest::TearDown()
67 {
68 }
SetUpTestCase()69 void AuthMessageProcessorTest::SetUpTestCase()
70 {
71 }
TearDownTestCase()72 void AuthMessageProcessorTest::TearDownTestCase()
73 {
74 }
75
76 namespace {
77 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
78 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
79 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
80 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector = std::make_shared<HiChainAuthConnector>();
81 /**
82 * @tc.name: AuthMessageProcessor::AuthMessageProcessor_001
83 * @tc.desc: 1 set cryptoAdapter_ to null
84 * 2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr
85 * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
86 * @tc.type: FUNC
87 * @tc.require: AR000GHSJK
88 */
89 HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_001, testing::ext::TestSize.Level0)
90 {
91 std::shared_ptr<DmAuthManager> Test =
92 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
93 ASSERT_NE(Test, nullptr);
94 }
95
96 /**
97 * @tc.name: AuthMessageProcessor::AuthMessageProcessor_001
98 * @tc.desc: 1 set cryptoAdapter_ to null
99 * 2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr
100 * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
101 * @tc.type: FUNC
102 * @tc.require: AR000GHSJK
103 */
104 HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_002, testing::ext::TestSize.Level0)
105 {
106 std::shared_ptr<DmAuthManager> Test =
107 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
108 Test.reset();
109 EXPECT_EQ(Test, nullptr);
110 }
111
112 /**
113 * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001
114 * @tc.desc: 1 set cryptoAdapter_ to null
115 * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr
116 * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
117 * @tc.type: FUNC
118 * @tc.require: AR000GHSJK
119 */
120 HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::TestSize.Level0)
121 {
122 std::shared_ptr<DmAuthManager> data =
123 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
124 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
125 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
126 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
127 int32_t msgType = MSG_TYPE_NEGOTIATE;
128 nlohmann::json jsonObj;
129 jsonObj[TAG_VER] = DM_ITF_VER;
130 jsonObj[TAG_MSG_TYPE] = msgType;
131 jsonObj[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
132 authMessageProcessor->SetResponseContext(authResponseContext);
133 authMessageProcessor->cryptoAdapter_ = nullptr;
134 authMessageProcessor->CreateNegotiateMessage(jsonObj);
135 std::string str1 = jsonObj.dump();
136 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
137 authMessageProcessor->CreateNegotiateMessage(jsonObj);
138
139 nlohmann::json jsonObject;
140 jsonObject[TAG_ACCOUNT_GROUPID] = "";
141 jsonObject[TAG_VER] = DM_ITF_VER;
142 jsonObject[TAG_MSG_TYPE] = msgType;
143 jsonObject[TAG_CRYPTO_SUPPORT] = false;
144 jsonObject[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
145 jsonObject[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
146 jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId;
147 jsonObject[TAG_HOST] = "";
148 std::string str2 = jsonObject.dump();
149 ASSERT_NE(str1, str2);
150 }
151
152 /**
153 * @tc.name: AuthMessageProcessor::CreateSyncGroupMessage_001
154 * @tc.desc: Compare JSON before and after assignment
155 * @tc.type: FUNC
156 * @tc.require: AR000GHSJK
157 */
158 HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::TestSize.Level0)
159 {
160 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
161 std::shared_ptr<DmAuthManager> data =
162 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
163 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
164 authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
165 nlohmann::json jsona;
166 nlohmann::json jsonObj;
167 authMessageProcessor->authRequestContext_->deviceId = "132416546";
168 std::vector<std::string> syncGroupList;
169 syncGroupList.push_back("1111");
170 authMessageProcessor->authRequestContext_->syncGroupList = syncGroupList;
171 jsona[TAG_DEVICE_ID] = authMessageProcessor->authRequestContext_->deviceId;
172 jsona[TAG_GROUPIDS] = authMessageProcessor->authRequestContext_->syncGroupList;
173 authMessageProcessor->CreateSyncGroupMessage(jsonObj);
174 std::string str1 = jsona.dump();
175 std::string str2 = jsonObj.dump();
176 ASSERT_EQ(str1, str2);
177 }
178
179 /**
180 * @tc.name: AuthMessageProcessor::CreateResponseAuthMessage_001
181 * @tc.desc: Compare JSON before and after assignment
182 * @tc.type: FUNC
183 * @tc.require: AR000GHSJK
184 */
185 HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext::TestSize.Level0)
186 {
187 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
188 std::shared_ptr<DmAuthManager> data =
189 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
190 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
191 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
192 nlohmann::json jsona;
193 nlohmann::json jsonObj;
194 authMessageProcessor->authResponseContext_->reply = 0;
195 authMessageProcessor->authResponseContext_->deviceId = "132416546";
196 authMessageProcessor->authResponseContext_->token = "11";
197 nlohmann::json jsonb;
198 jsonb[TAG_GROUP_ID] = "123456";
199 authMessageProcessor->authResponseContext_->groupId = jsonb.dump();
200 authMessageProcessor->authResponseContext_->authToken = "123456";
201 authMessageProcessor->authResponseContext_->networkId = "11112222";
202 authMessageProcessor->authResponseContext_->requestId = 222222;
203 authMessageProcessor->authResponseContext_->groupName = "333333";
204 jsona[TAG_TOKEN] = authMessageProcessor->authResponseContext_->token;
205 jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
206 jsona[TAG_DEVICE_ID] = authMessageProcessor->authResponseContext_->deviceId;
207 jsona[TAG_AUTH_TOKEN] = authMessageProcessor->authResponseContext_->authToken;
208 jsona[TAG_NET_ID] = authMessageProcessor->authResponseContext_->networkId;
209 jsona[TAG_REQUEST_ID] = authMessageProcessor->authResponseContext_->requestId;
210 jsona[TAG_GROUP_ID] = "123456";
211 jsona[TAG_GROUP_NAME] = authMessageProcessor->authResponseContext_->groupName;
212 authMessageProcessor->CreateResponseAuthMessage(jsonObj);
213 std::string str1 = jsona.dump();
214 std::string str2 = jsonObj.dump();
215 ASSERT_EQ(str1, str2);
216 }
217
218 /**
219 * @tc.name: AuthMessageProcessor::CreateResponseFinishMessage_001
220 * @tc.desc: Compare JSON before and after assignment
221 * @tc.type: FUNC
222 * @tc.require: AR000GHSJK
223 */
224 HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext::TestSize.Level0)
225 {
226 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
227 std::shared_ptr<DmAuthManager> data =
228 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
229 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
230 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
231 nlohmann::json jsona;
232 nlohmann::json jsonObj;
233 authMessageProcessor->authResponseContext_->reply = 1;
234 jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
235 jsona[TAG_AUTH_FINISH] = authMessageProcessor->authResponseContext_->isFinish;
236 authMessageProcessor->CreateResponseFinishMessage(jsonObj);
237 std::string str1 = jsona.dump();
238 std::string str2 = jsonObj.dump();
239 ASSERT_EQ(str1, str2);
240 }
241
242 /**
243 * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_001
244 * @tc.desc: Compare JSON before and after assignment
245 * @tc.type: FUNC
246 * @tc.require: AR000GHSJK
247 */
248 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext::TestSize.Level0)
249 {
250 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
251 std::shared_ptr<DmAuthManager> data =
252 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
253 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
254 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
255 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
256 nlohmann::json jsonObj;
257 authMessageProcessor->authResponseContext_->reply = 1;
258 jsonObj[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
259 authMessageProcessor->SetResponseContext(authResponseContext);
260 authMessageProcessor->ParseResponseFinishMessage(jsonObj);
261 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
262 }
263
264 /**
265 * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_002
266 * @tc.desc: Compare JSON before and after assignment
267 * @tc.type: FUNC
268 * @tc.require: AR000GHSJK
269 */
270 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_002, testing::ext::TestSize.Level0)
271 {
272 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
273 std::shared_ptr<DmAuthManager> data =
274 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
275 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
276 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
277 nlohmann::json jsonObj;
278 jsonObj[TAG_REPLY] = 22;
279 jsonObj[TAG_AUTH_FINISH] = true;
280 authMessageProcessor->ParseResponseFinishMessage(jsonObj);
281 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, jsonObj[TAG_REPLY]);
282 }
283
284 /**
285 * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_003
286 * @tc.desc: Compare JSON before and after assignment
287 * @tc.type: FUNC
288 * @tc.require: AR000GHSJK
289 */
290 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_003, testing::ext::TestSize.Level0)
291 {
292 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
293 std::shared_ptr<DmAuthManager> data =
294 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
295 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
296 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
297 std::string str = R"(
298 {
299 "REPLY" : "30000000000"
300 }
301 )";
302 nlohmann::json jsonObj = nlohmann::json::parse(str, nullptr, false);
303 authMessageProcessor->ParseResponseFinishMessage(jsonObj);
304 ASSERT_NE(authMessageProcessor->authResponseContext_->reply, jsonObj[TAG_REPLY]);
305 }
306
307 /**
308 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_001
309 * @tc.desc: Compare JSON before and after assi gnment
310 * @tc.type: FUNC
311 * @tc.require: AR000GHSJK
312 */
313 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::TestSize.Level0)
314 {
315 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
316 std::shared_ptr<DmAuthManager> data =
317 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
318 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
319 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
320 nlohmann::json jsona;
321 authResponseContext->reply = 0;
322 authResponseContext->deviceId = "11111";
323 authResponseContext->authToken = "123456";
324 authResponseContext->networkId = "12345";
325 authResponseContext->requestId = 2;
326 authResponseContext->groupId = "23456";
327 authResponseContext->groupName = "34567";
328 authResponseContext->token = "11123";
329 jsona[TAG_TOKEN] = authResponseContext->token;
330 jsona[TAG_REPLY] = authResponseContext->reply;
331 jsona[TAG_DEVICE_ID] = authResponseContext->deviceId;
332 jsona[TAG_AUTH_TOKEN] = authResponseContext->authToken;
333 jsona[TAG_NET_ID] = authResponseContext->networkId;
334 jsona[TAG_REQUEST_ID] = authResponseContext->requestId;
335 jsona[TAG_GROUP_ID] = authResponseContext->groupId;
336 jsona[TAG_GROUP_NAME] = authResponseContext->groupName;
337 authMessageProcessor->SetResponseContext(authResponseContext);
338 authMessageProcessor->ParseAuthResponseMessage(jsona);
339 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
340 }
341
342 /**
343 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_002
344 * @tc.desc: Compare JSON before and after assi gnment
345 * @tc.type: FUNC
346 * @tc.require: AR000GHSJK
347 */
348 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_002, testing::ext::TestSize.Level0)
349 {
350 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
351 std::shared_ptr<DmAuthManager> data =
352 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
353 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
354 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
355 nlohmann::json jsona;
356 jsona[TAG_REPLY] = "12";
357 authMessageProcessor->ParseAuthResponseMessage(jsona);
358 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
359 }
360
361 /**
362 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_003
363 * @tc.desc: Compare JSON before and after assi gnment
364 * @tc.type: FUNC
365 * @tc.require: AR000GHSJK
366 */
367 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_003, testing::ext::TestSize.Level0)
368 {
369 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
370 std::shared_ptr<DmAuthManager> data =
371 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
372 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
373 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
374 nlohmann::json jsona;
375 jsona[TAG_REPLY] = 0;
376 jsona[TAG_DEVICE_ID] = 0;
377 authMessageProcessor->ParseAuthResponseMessage(jsona);
378 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
379 }
380
381 /**
382 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_004
383 * @tc.desc: Compare JSON before and after assi gnment
384 * @tc.type: FUNC
385 * @tc.require: AR000GHSJK
386 */
387 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_004, testing::ext::TestSize.Level0)
388 {
389 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
390 std::shared_ptr<DmAuthManager> data =
391 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
392 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
393 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
394 nlohmann::json jsona;
395 jsona[TAG_REPLY] = 0;
396 jsona[TAG_DEVICE_ID] = "4153125";
397 authMessageProcessor->ParseAuthResponseMessage(jsona);
398 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
399 }
400
401 /**
402 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_005
403 * @tc.desc: Compare JSON before and after assi gnment
404 * @tc.type: FUNC
405 * @tc.require: AR000GHSJK
406 */
407 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_005, testing::ext::TestSize.Level0)
408 {
409 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
410 std::shared_ptr<DmAuthManager> data =
411 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
412 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
413 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
414 nlohmann::json jsona;
415 jsona[TAG_REPLY] = 0;
416 jsona[TAG_DEVICE_ID] = "4153125";
417 jsona[TAG_TOKEN] = 1513;
418 authMessageProcessor->ParseAuthResponseMessage(jsona);
419 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
420 }
421
422 /**
423 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_006
424 * @tc.desc: Compare JSON before and after assi gnment
425 * @tc.type: FUNC
426 * @tc.require: AR000GHSJK
427 */
428 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_006, testing::ext::TestSize.Level0)
429 {
430 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
431 std::shared_ptr<DmAuthManager> data =
432 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
433 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
434 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
435 nlohmann::json jsona;
436 jsona[TAG_REPLY] = 0;
437 jsona[TAG_DEVICE_ID] = "4153125";
438 jsona[TAG_TOKEN] = "1513";
439 jsona[TAG_REQUEST_ID] = 1513;
440 jsona[TAG_GROUP_ID] = "4521201";
441 jsona[TAG_GROUP_NAME] = "4521201";
442 jsona[TAG_AUTH_TOKEN] = "4521201";
443 jsona[TAG_AUTH_TOKEN] = "1513152";
444 authMessageProcessor->ParseAuthResponseMessage(jsona);
445 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
446 }
447
448 /**
449 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_007
450 * @tc.desc: Compare JSON before and after assi gnment
451 * @tc.type: FUNC
452 * @tc.require: AR000GHSJK
453 */
454 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_007, testing::ext::TestSize.Level0)
455 {
456 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
457 std::shared_ptr<DmAuthManager> data =
458 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
459 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
460 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
461 nlohmann::json jsona;
462 jsona[TAG_REPLY] = 0;
463 jsona[TAG_DEVICE_ID] = "4153125";
464 jsona[TAG_TOKEN] = "1513";
465 jsona[TAG_REQUEST_ID] = "1513";
466 jsona[TAG_GROUP_ID] = 4521201;
467 jsona[TAG_GROUP_NAME] = "4521201";
468 jsona[TAG_AUTH_TOKEN] = "4521201";
469 jsona[TAG_AUTH_TOKEN] = "1513152";
470 authMessageProcessor->ParseAuthResponseMessage(jsona);
471 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
472 }
473
474 /**
475 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_008
476 * @tc.desc: Compare JSON before and after assi gnment
477 * @tc.type: FUNC
478 * @tc.require: AR000GHSJK
479 */
480 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_008, testing::ext::TestSize.Level0)
481 {
482 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
483 std::shared_ptr<DmAuthManager> data =
484 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
485 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
486 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
487 nlohmann::json jsona;
488 jsona[TAG_REPLY] = 0;
489 jsona[TAG_DEVICE_ID] = "4153125";
490 jsona[TAG_TOKEN] = "1513";
491 jsona[TAG_REQUEST_ID] = "1513";
492 jsona[TAG_GROUP_ID] = "4521201";
493 jsona[TAG_GROUP_NAME] = 4521201;
494 jsona[TAG_AUTH_TOKEN] = "4521201";
495 jsona[TAG_AUTH_TOKEN] = "1513152";
496 authMessageProcessor->ParseAuthResponseMessage(jsona);
497 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
498 }
499
500 /**
501 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_009
502 * @tc.desc: Compare JSON before and after assi gnment
503 * @tc.type: FUNC
504 * @tc.require: AR000GHSJK
505 */
506 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_009, testing::ext::TestSize.Level0)
507 {
508 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
509 std::shared_ptr<DmAuthManager> data =
510 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
511 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
512 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
513 nlohmann::json jsona;
514 jsona[TAG_REPLY] = 0;
515 jsona[TAG_DEVICE_ID] = "4153125";
516 jsona[TAG_TOKEN] = "1513";
517 jsona[TAG_REQUEST_ID] = "1513";
518 jsona[TAG_GROUP_ID] = "4521201";
519 jsona[TAG_GROUP_NAME] = "4521201";
520 jsona[TAG_AUTH_TOKEN] = 4521201;
521 jsona[TAG_AUTH_TOKEN] = "1513152";
522 authMessageProcessor->ParseAuthResponseMessage(jsona);
523 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
524 }
525
526 /**
527 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_0010
528 * @tc.desc: Compare JSON before and after assi gnment
529 * @tc.type: FUNC
530 * @tc.require: AR000GHSJK
531 */
532 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_0010, testing::ext::TestSize.Level0)
533 {
534 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
535 std::shared_ptr<DmAuthManager> data =
536 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
537 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
538 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
539 nlohmann::json jsona;
540 jsona[TAG_REPLY] = 0;
541 jsona[TAG_DEVICE_ID] = "4153125";
542 jsona[TAG_TOKEN] = "1513";
543 jsona[TAG_REQUEST_ID] = "1513";
544 jsona[TAG_GROUP_ID] = "4521201";
545 jsona[TAG_GROUP_NAME] = "4521201";
546 jsona[TAG_AUTH_TOKEN] = "4521201";
547 jsona[TAG_AUTH_TOKEN] = 1513152;
548 authMessageProcessor->ParseAuthResponseMessage(jsona);
549 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, DM_OK);
550 }
551
552 /**
553 * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_001
554 * @tc.desc: Compare JSON before and after assignment
555 * @tc.type: FUNC
556 * @tc.require: AR000GHSJK
557 */
558 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::TestSize.Level0)
559 {
560 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
561 std::shared_ptr<DmAuthManager> data =
562 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
563 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
564 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
565 authMessageProcessor->SetResponseContext(authResponseContext);
566 nlohmann::json jsonThumbnail;
567 authResponseContext->deviceId = "123";
568 authResponseContext->reply = 0;
569 authResponseContext->authType = 222;
570 authResponseContext->networkId = "234";
571 authResponseContext->groupId = "345";
572 authResponseContext->groupName = "456";
573 authResponseContext->requestId = 2333;
574 jsonThumbnail[TAG_DEVICE_ID] = authResponseContext->deviceId;
575 jsonThumbnail[TAG_REPLY] = authResponseContext->reply;
576 jsonThumbnail[TAG_AUTH_TYPE] = authResponseContext->authType;
577 jsonThumbnail[TAG_NET_ID] = authResponseContext->networkId;
578 jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId;
579 jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName;
580 jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId;
581 int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
582 ASSERT_EQ(ret, ERR_DM_FAILED);
583 }
584
585 /**
586 * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_002
587 * @tc.desc: Compare JSON before and after assignment
588 * @tc.type: FUNC
589 * @tc.require: AR000GHSJK
590 */
591 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::TestSize.Level0)
592 {
593 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
594 std::shared_ptr<DmAuthManager> data =
595 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
596 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
597 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
598 authMessageProcessor->SetResponseContext(authResponseContext);
599 nlohmann::json jsonThumbnail;
600 jsonThumbnail[TAG_SLICE_NUM] = 1;
601 jsonThumbnail[TAG_INDEX] = 0;
602 jsonThumbnail[TAG_DEVICE_ID] = "123";
603 jsonThumbnail[TAG_AUTH_TYPE] = 1;
604 jsonThumbnail[TAG_CUSTOM_DESCRIPTION] = "123";
605 jsonThumbnail[TAG_TOKEN] = "1234";
606 jsonThumbnail[TAG_TARGET] = "12345";
607 jsonThumbnail[TAG_APP_OPERATION] = "123456";
608 jsonThumbnail[TAG_LOCAL_DEVICE_ID] = "localdeviceTest";
609 jsonThumbnail[TAG_REQUESTER] = "AJ125S25S3E65F1A24T";
610 jsonThumbnail[TAG_DEVICE_TYPE] = 1;
611 int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
612 ASSERT_EQ(ret, DM_OK);
613 jsonThumbnail[TAG_INDEX] = 1;
614 ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
615 ASSERT_EQ(ret, DM_OK);
616 jsonThumbnail[TAG_SLICE_NUM] = 10;
617 ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
618 ASSERT_EQ(ret, DM_OK);
619 jsonThumbnail[TAG_SLICE_NUM] = 1;
620 jsonThumbnail[TAG_IS_SHOW_DIALOG] = true;
621 ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
622 ASSERT_EQ(ret, DM_OK);
623 jsonThumbnail[TAG_BIND_TYPE_SIZE] = 10001;
624 ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
625 ASSERT_EQ(ret, ERR_DM_FAILED);
626 jsonThumbnail[TAG_BIND_TYPE_SIZE] = 1;
627 ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
628 ASSERT_EQ(ret, DM_OK);
629 }
630
631 /**
632 * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_003
633 * @tc.desc: Compare JSON before and after assignment
634 * @tc.type: FUNC
635 * @tc.require: AR000GHSJK
636 */
637 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_003, testing::ext::TestSize.Level0)
638 {
639 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
640 std::shared_ptr<DmAuthManager> data =
641 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
642 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
643 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
644 authMessageProcessor->SetResponseContext(authResponseContext);
645 nlohmann::json jsonThumbnail;
646 jsonThumbnail[TAG_SLICE_NUM] = 1;
647 jsonThumbnail[TAG_INDEX] = 0;
648 jsonThumbnail[TAG_DEVICE_ID] = 123;
649 jsonThumbnail[TAG_AUTH_TYPE] = 1;
650 jsonThumbnail[TAG_CUSTOM_DESCRIPTION] = "123";
651 jsonThumbnail[TAG_TOKEN] = "1234";
652 jsonThumbnail[TAG_TARGET] = "12345";
653 jsonThumbnail[TAG_APP_OPERATION] = "123456";
654 int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
655 ASSERT_EQ(ret, DM_OK);
656 }
657
658 /**
659 * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_004
660 * @tc.desc: Compare JSON before and after assignment
661 * @tc.type: FUNC
662 * @tc.require: AR000GHSJK
663 */
664 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_004, 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(authResponseContext);
672 nlohmann::json jsonThumbnail;
673 jsonThumbnail[TAG_SLICE_NUM] = 1;
674 jsonThumbnail[TAG_INDEX] = 0;
675 jsonThumbnail[TAG_DEVICE_ID] = "123";
676 jsonThumbnail[TAG_AUTH_TYPE] = 1;
677 jsonThumbnail[TAG_CUSTOM_DESCRIPTION] = "123";
678 jsonThumbnail[TAG_TOKEN] = "1234";
679 jsonThumbnail[TAG_TARGET] = "12345";
680 jsonThumbnail[TAG_APP_OPERATION] = "123456";
681 jsonThumbnail[TAG_APP_THUMBNAIL] = "jsontest";
682 jsonThumbnail[TAG_LOCAL_DEVICE_ID] = "localdeviceTest";
683 jsonThumbnail[TAG_REQUESTER] = "iknbghkkj266SSjsjjdan21526";
684 jsonThumbnail[TAG_DEVICE_TYPE] = 1;
685 int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail);
686 ASSERT_EQ(ret, ERR_DM_AUTH_MESSAGE_INCOMPLETE);
687 }
688
689 /**
690 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_001
691 * @tc.desc: Compare authResponseContext before and after assignment
692 * @tc.type: FUNC
693 * @tc.require: AR000GHSJK
694 */
695 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::TestSize.Level0)
696 {
697 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
698 std::shared_ptr<DmAuthManager> data =
699 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
700 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
701 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
702 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
703 nlohmann::json jsonObj;
704 jsonObj[TAG_CRYPTO_SUPPORT] = "CRYPTOSUPPORT";
705 jsonObj[TAG_CRYPTO_SUPPORT] = authMessageProcessor->authResponseContext_->cryptoSupport;
706 authResponseContext->localDeviceId = "22";
707 authResponseContext->authType = 1;
708 authResponseContext->reply = 33;
709 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
710 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
711 jsonObj[TAG_REPLY] = authResponseContext->reply;
712 authMessageProcessor->SetResponseContext(authResponseContext);
713 authMessageProcessor->ParseNegotiateMessage(jsonObj);
714 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
715 }
716
717 /**
718 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_002
719 * @tc.desc: Compare authResponseContext before and after assignment
720 * @tc.type: FUNC
721 * @tc.require: AR000GHSJK
722 */
723 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::TestSize.Level0)
724 {
725 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
726 std::shared_ptr<DmAuthManager> data =
727 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
728 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
729 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
730 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
731 nlohmann::json jsonObj;
732 authResponseContext->localDeviceId = "22";
733 authResponseContext->authType = 1;
734 authResponseContext->reply = 33;
735 jsonObj[TAG_CRYPTO_NAME] = "CRYPTONAME";
736 jsonObj[TAG_CRYPTO_NAME] = authResponseContext->cryptoSupport;
737 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
738 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
739 jsonObj[TAG_REPLY] = authResponseContext->reply;
740 authMessageProcessor->SetResponseContext(authResponseContext);
741 authMessageProcessor->ParseNegotiateMessage(jsonObj);
742 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
743 }
744
745 /**
746 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_003
747 * @tc.desc: Compare authResponseContext before and after assignment
748 * @tc.type: FUNC
749 * @tc.require: AR000GHSJK
750 */
751 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::TestSize.Level0)
752 {
753 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
754 std::shared_ptr<DmAuthManager> data =
755 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
756 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
757 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
758 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
759 nlohmann::json jsonObj;
760 authResponseContext->localDeviceId = "22";
761 authResponseContext->authType = 1;
762 authResponseContext->reply = 33;
763 jsonObj[TAG_CRYPTO_VERSION] = "CRYPTOVERSION";
764 jsonObj[TAG_CRYPTO_VERSION] = authResponseContext->cryptoSupport;
765 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
766 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
767 jsonObj[TAG_REPLY] = authResponseContext->reply;
768 authMessageProcessor->SetResponseContext(authResponseContext);
769 authMessageProcessor->ParseNegotiateMessage(jsonObj);
770 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
771 }
772
773 /**
774 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_004
775 * @tc.desc: Compare authResponseContext before and after assignment
776 * @tc.type: FUNC
777 * @tc.require: AR000GHSJK
778 */
779 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::TestSize.Level0)
780 {
781 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
782 std::shared_ptr<DmAuthManager> data =
783 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
784 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
785 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
786 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
787 nlohmann::json jsonObj;
788 authResponseContext->localDeviceId = "22";
789 authResponseContext->authType = 1;
790 authResponseContext->reply = 33;
791 jsonObj[TAG_DEVICE_ID] = "DEVICEID";
792 jsonObj[TAG_DEVICE_ID] = authResponseContext->deviceId;
793 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
794 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
795 jsonObj[TAG_REPLY] = authResponseContext->reply;
796 authMessageProcessor->SetResponseContext(authResponseContext);
797 authMessageProcessor->ParseNegotiateMessage(jsonObj);
798 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
799 }
800
801 /**
802 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_005
803 * @tc.desc: Compare authResponseContext before and after assignment
804 * @tc.type: FUNC
805 * @tc.require: AR000GHSJK
806 */
807 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::TestSize.Level0)
808 {
809 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
810 std::shared_ptr<DmAuthManager> data =
811 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
812 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
813 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
814 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
815 nlohmann::json jsonObj;
816 authResponseContext->localDeviceId = "22";
817 authResponseContext->authType = 1;
818 authResponseContext->reply = 33;
819 jsonObj[TAG_LOCAL_DEVICE_ID] = "LOCALDEVICEID";
820 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
821 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
822 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
823 jsonObj[TAG_REPLY] = authResponseContext->reply;
824 authMessageProcessor->SetResponseContext(authResponseContext);
825 authMessageProcessor->ParseNegotiateMessage(jsonObj);
826 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
827 }
828
829 /**
830 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_006
831 * @tc.desc: Compare authResponseContext before and after assignment
832 * @tc.type: FUNC
833 * @tc.require: AR000GHSJK
834 */
835 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_006, testing::ext::TestSize.Level0)
836 {
837 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
838 std::shared_ptr<DmAuthManager> data =
839 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
840 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
841 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
842 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
843 nlohmann::json jsonObj;
844 authResponseContext->localDeviceId = "22";
845 authResponseContext->authType = 1;
846 authResponseContext->reply = 33;
847 jsonObj[TAG_LOCAL_DEVICE_ID] = "LOCALDEVICEID";
848 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
849 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
850 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
851 jsonObj[TAG_REPLY] = authResponseContext->reply;
852 jsonObj[TAG_CRYPTO_SUPPORT] = true;
853 jsonObj[TAG_CRYPTO_NAME] = "NAMETEST";
854 jsonObj[TAG_CRYPTO_VERSION] = "1.0";
855 jsonObj[TAG_ACCOUNT_GROUPID] = "GROUPID";
856 authMessageProcessor->ParseNegotiateMessage(jsonObj);
857 jsonObj[TAG_ACCOUNT_GROUPID] = 12;
858 jsonObj[TAG_HOST] = "12";
859 jsonObj[TAG_AUTH_TYPE] = "12";
860 authMessageProcessor->SetResponseContext(authResponseContext);
861 authMessageProcessor->ParseNegotiateMessage(jsonObj);
862 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
863 }
864
865 /**
866 * @tc.name: AuthMessageProcessor::ParseRespNegotiateMessage_001
867 * @tc.desc: return true
868 * @tc.type: FUNC
869 * @tc.require: AR000GHSJK
870 */
871 HWTEST_F(AuthMessageProcessorTest, ParseRespNegotiateMessage_001, testing::ext::TestSize.Level0)
872 {
873 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
874 std::shared_ptr<DmAuthManager> data =
875 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
876 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
877 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
878 authMessageProcessor->SetResponseContext(authResponseContext);
879 nlohmann::json jsonObj;
880 jsonObj[TAG_IDENTICAL_ACCOUNT] = false;
881 authMessageProcessor->ParseRespNegotiateMessage(jsonObj);
882 ASSERT_EQ(authMessageProcessor->authResponseContext_->isIdenticalAccount, jsonObj[TAG_IDENTICAL_ACCOUNT]);
883 }
884
885 /**
886 * @tc.name: AuthMessageProcessor::ParseRespNegotiateMessage_002
887 * @tc.desc: return true
888 * @tc.type: FUNC
889 * @tc.require: AR000GHSJK
890 */
891 HWTEST_F(AuthMessageProcessorTest, ParseRespNegotiateMessage_002, testing::ext::TestSize.Level0)
892 {
893 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
894 std::shared_ptr<DmAuthManager> data =
895 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
896 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
897 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
898 authMessageProcessor->SetResponseContext(authResponseContext);
899 nlohmann::json jsonObj;
900 jsonObj[TAG_IDENTICAL_ACCOUNT] = "test";
901 authMessageProcessor->ParseRespNegotiateMessage(jsonObj);
902 ASSERT_NE(authMessageProcessor->authResponseContext_->isIdenticalAccount, jsonObj[TAG_IDENTICAL_ACCOUNT]);
903 }
904
905 /**
906 * @tc.name: AuthMessageProcessor::ParseRespNegotiateMessage_003
907 * @tc.desc: return true
908 * @tc.type: FUNC
909 * @tc.require: AR000GHSJK
910 */
911 HWTEST_F(AuthMessageProcessorTest, ParseRespNegotiateMessage_003, testing::ext::TestSize.Level0)
912 {
913 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
914 std::shared_ptr<DmAuthManager> data =
915 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
916 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
917 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
918 nlohmann::json jsonObj;
919 jsonObj[TAG_IDENTICAL_ACCOUNT] = true;
920 jsonObj[TAG_REPLY] = 1231;
921 jsonObj[TAG_LOCAL_DEVICE_ID] = "1212";
922 jsonObj[TAG_IS_AUTH_CODE_READY] = true;
923 jsonObj[TAG_ACCOUNT_GROUPID] = "1212";
924 jsonObj[TAG_NET_ID] = "1212";
925 jsonObj[TAG_TOKENID] = "1212";
926 jsonObj[TAG_TARGET_DEVICE_NAME] = "1212";
927 jsonObj[TAG_IMPORT_AUTH_CODE] = "1212";
928 authMessageProcessor->ParseRespNegotiateMessage(jsonObj);
929 ASSERT_EQ(authMessageProcessor->authResponseContext_->isIdenticalAccount, true);
930 }
931
932 /**
933 * @tc.name: AuthMessageProcessor::ParseRespNegotiateMessage_004
934 * @tc.desc: return true
935 * @tc.type: FUNC
936 * @tc.require: AR000GHSJK
937 */
938 HWTEST_F(AuthMessageProcessorTest, ParseRespNegotiateMessage_004, testing::ext::TestSize.Level0)
939 {
940 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
941 std::shared_ptr<DmAuthManager> data =
942 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
943 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
944 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
945 nlohmann::json jsonObj;
946 jsonObj[TAG_IDENTICAL_ACCOUNT] = 112;
947 jsonObj[TAG_REPLY] = "1231";
948 jsonObj[TAG_LOCAL_DEVICE_ID] = 1212;
949 jsonObj[TAG_IS_AUTH_CODE_READY] = 1212;
950 jsonObj[TAG_ACCOUNT_GROUPID] = 1212;
951 jsonObj[TAG_NET_ID] = 1212;
952 jsonObj[TAG_TOKENID] = 1212;
953 jsonObj[TAG_TARGET_DEVICE_NAME] = 1212;
954 authMessageProcessor->ParseRespNegotiateMessage(jsonObj);
955 ASSERT_NE(authMessageProcessor->authResponseContext_->isIdenticalAccount, jsonObj[TAG_IDENTICAL_ACCOUNT]);
956 }
957 /**
958 * @tc.name: AuthMessageProcessor::SetRequestContext_001
959 * @tc.desc: Compare authResponseContext before and after assignment
960 * @tc.type: FUNC
961 * @tc.require: AR000GHSJK
962 */
963 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize.Level0)
964 {
965 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
966 std::shared_ptr<DmAuthManager> data =
967 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
968 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
969 std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
970 authMessageProcessor->SetRequestContext(authRequestContext);
971 ASSERT_EQ(authMessageProcessor->authRequestContext_, authRequestContext);
972 }
973
974 /**
975 * @tc.name: AuthMessageProcessor::SetRequestContext_002
976 * @tc.desc: Judge whether authrequestcontext is empty
977 * @tc.type: FUNC
978 * @tc.require: AR000GHSJK
979 */
980 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize.Level0)
981 {
982 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
983 std::shared_ptr<DmAuthManager> data =
984 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
985 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
986 std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
987 authMessageProcessor->SetRequestContext(nullptr);
988 ASSERT_EQ(authMessageProcessor->authRequestContext_, nullptr);
989 }
990
991 /**
992 * @tc.name: AuthMessageProcessor::SetResponseContext_001
993 * @tc.desc: Compare authResponseContext before and after assignment
994 * @tc.type: FUNC
995 * @tc.require: AR000GHSJK
996 */
997 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSize.Level0)
998 {
999 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1000 std::shared_ptr<DmAuthManager> data =
1001 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1002 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1003 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1004 authMessageProcessor->SetResponseContext(authResponseContext);
1005 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
1006 }
1007
1008 /**
1009 * @tc.name: AuthMessageProcessor::SetResponseContext_002
1010 * @tc.desc: Judge whether authrequestcontext is empty
1011 * @tc.type: FUNC
1012 * @tc.require: AR000GHSJK
1013 */
1014 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSize.Level0)
1015 {
1016 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1017 std::shared_ptr<DmAuthManager> data =
1018 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1019 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1020 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1021 authMessageProcessor->SetResponseContext(nullptr);
1022 ASSERT_EQ(authMessageProcessor->authResponseContext_, nullptr);
1023 }
1024
1025 /**
1026 * @tc.name: AuthMessageProcessor::GetResponseContext_001
1027 * @tc.desc: Compare authResponseContext before and after assignment
1028 * @tc.type: FUNC
1029 * @tc.require: AR000GHSJK
1030 */
1031 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSize.Level0)
1032 {
1033 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1034 std::shared_ptr<DmAuthManager> data =
1035 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1036 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1037 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1038 std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
1039 ASSERT_EQ(authResponseContext, authMessageProcessor->authResponseContext_);
1040 }
1041
1042 /**
1043 * @tc.name: AuthMessageProcessor::GetResponseContext_002
1044 * @tc.desc: Judge whether authrequestcontext is empty
1045 * @tc.type: FUNC
1046 * @tc.require: AR000GHSJK
1047 */
1048 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_002, testing::ext::TestSize.Level0)
1049 {
1050 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1051 std::shared_ptr<DmAuthManager> data =
1052 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1053 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1054 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1055 std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
1056 ASSERT_NE(authResponseContext, nullptr);
1057 }
1058
1059 /**
1060 * @tc.name: AuthMessageProcessor::CreateSimpleMessage_001
1061 * @tc.desc: return the length of string is empty
1062 * @tc.type: FUNC
1063 * @tc.require: AR000GHSJK
1064 */
1065 HWTEST_F(AuthMessageProcessorTest, CreateSimpleMessage_001, testing::ext::TestSize.Level0)
1066 {
1067 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1068 std::shared_ptr<DmAuthManager> data =
1069 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1070 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1071 authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
1072 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1073 int32_t msgType = MSG_TYPE_SYNC_GROUP;
1074 std::string ret = authMessageProcessor->CreateSimpleMessage(msgType);
1075 ASSERT_NE(ret.size(), 0);
1076 msgType = MSG_TYPE_RESP_AUTH;
1077 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1078 ASSERT_NE(ret.size(), 0);
1079 msgType = MSG_TYPE_REQ_AUTH_TERMINATE;
1080 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1081 ASSERT_NE(ret.size(), 0);
1082 msgType = MSG_TYPE_RESP_AUTH_EXT;
1083 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1084 ASSERT_NE(ret.size(), 0);
1085 msgType = MSG_TYPE_REQ_PUBLICKEY;
1086 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1087 ASSERT_NE(ret.size(), 0);
1088 msgType = MSG_TYPE_REQ_SYNC_DELETE;
1089 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1090 ASSERT_NE(ret.size(), 0);
1091 msgType = MSG_TYPE_NEGOTIATE;
1092 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1093 ASSERT_NE(ret.size(), 0);
1094 msgType = MSG_TYPE_RESP_NEGOTIATE;
1095 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1096 ASSERT_NE(ret.size(), 0);
1097 msgType = MSG_TYPE_UNKNOWN;
1098 ret = authMessageProcessor->CreateSimpleMessage(msgType);
1099 ASSERT_NE(ret.size(), 0);
1100 }
1101
1102 /**
1103 * @tc.name: AuthMessageProcessor::GetRequestContext_001
1104 * @tc.desc: Compare authRequestContext before and after assignment
1105 * @tc.type: FUNC
1106 * @tc.require: AR000GHSJK
1107 */
1108 HWTEST_F(AuthMessageProcessorTest, GetRequestContext_001, testing::ext::TestSize.Level0)
1109 {
1110 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1111 std::shared_ptr<DmAuthManager> data =
1112 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1113 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1114 std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
1115 authMessageProcessor->SetRequestContext(authRequestContext);
1116 auto ret = authMessageProcessor->GetRequestContext();
1117 ASSERT_EQ(authMessageProcessor->authRequestContext_, ret);
1118 }
1119
1120 /**
1121 * @tc.name: AuthMessageProcessor::ParseMessage_001
1122 * @tc.desc: Return DM_OK
1123 * @tc.type: FUNC
1124 * @tc.require: AR000GHSJK
1125 */
1126 HWTEST_F(AuthMessageProcessorTest, ParseMessage_001, testing::ext::TestSize.Level0)
1127 {
1128 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1129 std::shared_ptr<DmAuthManager> data =
1130 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1131 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1132 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1133 authMessageProcessor->SetResponseContext(authResponseContext);
1134 std::string message = R"(
1135 {
1136 "AUTHTYPE": 1,
1137 "CRYPTOSUPPORT": false,
1138 "ITF_VER": "1.1",
1139 "LOCALDEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
1140 "MSG_TYPE": 80,
1141 "REPLY": 2016
1142 }
1143 )";
1144 int32_t ret = authMessageProcessor->ParseMessage(message);
1145 ASSERT_EQ(ret, DM_OK);
1146 }
1147
1148 /**
1149 * @tc.name: AuthMessageProcessor::ParseMessage_002
1150 * @tc.desc: Return DM_OK
1151 * @tc.type: FUNC
1152 * @tc.require: AR000GHSJK
1153 */
1154 HWTEST_F(AuthMessageProcessorTest, ParseMessage_002, testing::ext::TestSize.Level0)
1155 {
1156 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1157 std::shared_ptr<DmAuthManager> data =
1158 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1159 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1160 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1161 authMessageProcessor->SetResponseContext(authResponseContext);
1162 std::string message = R"(
1163 {
1164 "AUTHTYPE": 1,
1165 "CRYPTOSUPPORT": false,
1166 "ITF_VER": "1.1",
1167 "LOCALDEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
1168 "MSG_TYPE": 90,
1169 "REPLY": 2016
1170 }
1171 )";
1172 int32_t ret = authMessageProcessor->ParseMessage(message);
1173 ASSERT_EQ(ret, DM_OK);
1174 }
1175
1176 /**
1177 * @tc.name: AuthMessageProcessor::ParseMessage_003
1178 * @tc.desc: Return DM_OK
1179 * @tc.type: FUNC
1180 * @tc.require: AR000GHSJK
1181 */
1182 HWTEST_F(AuthMessageProcessorTest, ParseMessage_003, testing::ext::TestSize.Level0)
1183 {
1184 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1185 std::shared_ptr<DmAuthManager> data =
1186 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1187 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1188 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1189 authMessageProcessor->SetResponseContext(authResponseContext);
1190 std::string message = R"(
1191 {
1192 "APPDESC": "Distributed Calc",
1193 "CUSTOMDESC": "customDescription",
1194 "APPICON": "",
1195 "APPNAME": "Distributed Calc",
1196 "APPOPERATION": "appoperrationTest",
1197 "AUTHTYPE":1,
1198 "DEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
1199 "LOCALDEVICEID": "test0b9186386e87487564b02etest1f904eb9517f262721c9ada090477etest",
1200 "DEVICETYPE": 1,
1201 "HOST": "com.example.distributedcalc",
1202 "INDEX": 0,
1203 "ITF_VER": "1.1",
1204 "MSG_TYPE": 100,
1205 "REQUESTER": "test0b9186386e87487564b02etest1f904eb9517f262721c9ada090477etest",
1206 "SLICE": 1,
1207 "TARGET": "com.example.distributedcalc",
1208 "THUMSIZE": 0,
1209 "TOKEN": "73141022",
1210 "VISIBILITY": 0
1211 }
1212 )";
1213 int32_t ret = authMessageProcessor->ParseMessage(message);
1214 ASSERT_EQ(ret, DM_OK);
1215 }
1216
1217 /**
1218 * @tc.name: AuthMessageProcessor::ParseMessage_004
1219 * @tc.desc: Return DM_OK
1220 * @tc.type: FUNC
1221 * @tc.require: AR000GHSJK
1222 */
1223 HWTEST_F(AuthMessageProcessorTest, ParseMessage_004, testing::ext::TestSize.Level0)
1224 {
1225 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1226 std::shared_ptr<DmAuthManager> data =
1227 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1228 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1229 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1230 authMessageProcessor->SetResponseContext(authResponseContext);
1231 std::string message = R"(
1232 {
1233 "REPLY": 0,
1234 "DEVICEID": "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5",
1235 "TOKEN": "7314",
1236 "GROUPNAME": "com.example.test",
1237 "ITF_VER": "1.1",
1238 "MSG_TYPE": 200,
1239 "NETID": "147258963",
1240 "REQUESTID": 8448,
1241 "authToken": "com.example.distributedcalc62063A65EC8540074FF01413BDC3B6D7",
1242 "groupId" : "e68f0b9186386e87487564b02e91421f904eb9517f262721c9ada090477e35f5"
1243 }
1244 )";
1245 int32_t ret = authMessageProcessor->ParseMessage(message);
1246 ASSERT_EQ(ret, DM_OK);
1247 }
1248
1249 /**
1250 * @tc.name: AuthMessageProcessor::ParseMessage_005
1251 * @tc.desc: Return DM_OK
1252 * @tc.type: FUNC
1253 * @tc.require: AR000GHSJK
1254 */
1255 HWTEST_F(AuthMessageProcessorTest, ParseMessage_005, testing::ext::TestSize.Level0)
1256 {
1257 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1258 std::shared_ptr<DmAuthManager> data =
1259 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1260 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1261 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1262 authMessageProcessor->SetResponseContext(authResponseContext);
1263 std::string message = R"(
1264 {
1265 "REPLY": 0,
1266 "ITF_VER": "1.1",
1267 "MSG_TYPE": 104
1268 }
1269 )";
1270 int32_t ret = authMessageProcessor->ParseMessage(message);
1271 ASSERT_EQ(ret, DM_OK);
1272 }
1273
1274 /**
1275 * @tc.name: AuthMessageProcessor::ParseMessage_006
1276 * @tc.desc: Return ERR_DM_FAILED
1277 * @tc.type: FUNC
1278 * @tc.require: AR000GHSJK
1279 */
1280 HWTEST_F(AuthMessageProcessorTest, ParseMessage_006, testing::ext::TestSize.Level0)
1281 {
1282 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1283 std::shared_ptr<DmAuthManager> data =
1284 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1285 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1286 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1287 authMessageProcessor->SetResponseContext(authResponseContext);
1288 std::string message = R"(
1289 {
1290 "REPLY": 1,
1291 "ITF_VER": "1.1.2",
1292 "MSG_TYPE": "104"
1293 }
1294 )";
1295 int32_t ret = authMessageProcessor->ParseMessage(message);
1296 ASSERT_EQ(ret, ERR_DM_FAILED);
1297 }
1298
1299 HWTEST_F(AuthMessageProcessorTest, ParseMessage_007, testing::ext::TestSize.Level0)
1300 {
1301 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1302 std::shared_ptr<DmAuthManager> data =
1303 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1304 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1305 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1306 authMessageProcessor->SetResponseContext(authResponseContext);
1307 std::string message = R"(
1308 {
1309 "REPLY": 1,
1310 "LOCALDEVICEID": "devId_4655198_test",
1311 "hostPkgname": "pkgname_dm_test"
1312 "MSG_TYPE": "501",
1313 }
1314 )";
1315 int32_t ret = authMessageProcessor->ParseMessage(message);
1316 ASSERT_EQ(ret, ERR_DM_FAILED);
1317 }
1318
1319 HWTEST_F(AuthMessageProcessorTest, ParseMessage_008, testing::ext::TestSize.Level0)
1320 {
1321 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1322 std::shared_ptr<DmAuthManager> data =
1323 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1324 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1325 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1326 authMessageProcessor->SetResponseContext(authResponseContext);
1327 std::string message = R"(
1328 {
1329 "publicKey": "publicKey_test",
1330 "MSG_TYPE": "502",
1331 }
1332 )";
1333 int32_t ret = authMessageProcessor->ParseMessage(message);
1334 std::string message1 = R"(
1335 {
1336 "publicKey": "publicKey_test",
1337 "MSG_TYPE": "503",
1338 }
1339 )";
1340 ret = authMessageProcessor->ParseMessage(message);
1341 std::string message2 = R"(
1342 {
1343 "publicKey": "publicKey_test",
1344 "MSG_TYPE": "504",
1345 }
1346 )";
1347 ret = authMessageProcessor->ParseMessage(message2);
1348 std::string message3 = R"(
1349 {
1350 "publicKey": "publicKey_test",
1351 "MSG_TYPE": "600",
1352 }
1353 )";
1354 ret = authMessageProcessor->ParseMessage(message3);
1355 ASSERT_EQ(ret, ERR_DM_FAILED);
1356 }
1357
1358 HWTEST_F(AuthMessageProcessorTest, ParseMessage_009, testing::ext::TestSize.Level0)
1359 {
1360 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1361 std::shared_ptr<DmAuthManager> data =
1362 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1363 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1364 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
1365 authMessageProcessor->SetResponseContext(authResponseContext);
1366 std::string message = R"(
1367 {
1368 "REPLY": 1,
1369 "tokenId": "tokenId_123_test",
1370 "confirmOperation": "1",
1371 "REQUESTID": "1",
1372 "MSG_TYPE": "501",
1373 }
1374 )";
1375 int32_t ret = authMessageProcessor->ParseMessage(message);
1376 ASSERT_EQ(ret, ERR_DM_FAILED);
1377
1378 nlohmann::json jsonObj;
1379 jsonObj[TAG_LOCAL_ACCOUNTID] = "local_accountId_123";
1380 jsonObj[TAG_LOCAL_USERID] = 1;
1381 jsonObj[TAG_BIND_LEVEL] = 1;
1382 jsonObj[TAG_ISONLINE] = true;
1383 jsonObj[TAG_IDENTICAL_ACCOUNT] = true;
1384 jsonObj[TAG_AUTHED] = true;
1385 jsonObj[TAG_TOKENID] = 100;
1386 jsonObj[TAG_DMVERSION] = "1.1.1";
1387 jsonObj[TAG_HAVECREDENTIAL] = true;
1388 jsonObj[TAG_BIND_TYPE_SIZE] = 5;
1389 authMessageProcessor->ParsePkgNegotiateMessage(jsonObj);
1390 }
1391
1392 HWTEST_F(AuthMessageProcessorTest, GetJsonObj_001, testing::ext::TestSize.Level0)
1393 {
1394 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1395 std::shared_ptr<DmAuthManager> data =
1396 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1397 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1398 authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
1399 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1400 authMessageProcessor->authRequestContext_->groupVisibility = 0;
1401 authMessageProcessor->authRequestContext_->authType = 5;
1402 int32_t param = 1;
1403 authMessageProcessor->authRequestContext_->bindType.push_back(param);
1404 nlohmann::json jsonObj;
1405 authMessageProcessor->GetJsonObj(jsonObj);
1406 ASSERT_EQ(jsonObj[TAG_IS_SHOW_DIALOG], false);
1407 }
1408
1409 HWTEST_F(AuthMessageProcessorTest, GetJsonObj_002, testing::ext::TestSize.Level0)
1410 {
1411 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1412 std::shared_ptr<DmAuthManager> data =
1413 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1414 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1415 authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
1416 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1417 authMessageProcessor->authRequestContext_->groupVisibility = 0;
1418 authMessageProcessor->authRequestContext_->authType = 1;
1419 int32_t param = 1;
1420 authMessageProcessor->authRequestContext_->bindType.push_back(param);
1421 nlohmann::json jsonObj;
1422 authMessageProcessor->GetJsonObj(jsonObj);
1423 ASSERT_EQ(jsonObj[TAG_IS_SHOW_DIALOG], true);
1424 }
1425
1426 HWTEST_F(AuthMessageProcessorTest, CreateSyncDeleteMessageExt_001, testing::ext::TestSize.Level0)
1427 {
1428 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1429 std::shared_ptr<DmAuthManager> data =
1430 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1431 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1432 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1433 authMessageProcessor->authResponseContext_->localDeviceId = "13213521";
1434 authMessageProcessor->authResponseContext_->hostPkgName = "ohos_test";
1435 nlohmann::json jsonObj;
1436 authMessageProcessor->CreateSyncDeleteMessageExt(jsonObj);
1437 ASSERT_EQ(jsonObj[TAG_REPLY], DM_OK);
1438 }
1439
1440 HWTEST_F(AuthMessageProcessorTest, CreatePublicKeyMessageExt_001, testing::ext::TestSize.Level0)
1441 {
1442 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1443 std::shared_ptr<DmAuthManager> data =
1444 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1445 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1446 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1447 authMessageProcessor->authResponseContext_->publicKey = "13213521";
1448 nlohmann::json jsonObj;
1449 authMessageProcessor->CreatePublicKeyMessageExt(jsonObj);
1450 ASSERT_EQ(jsonObj[TAG_PUBLICKEY], authMessageProcessor->authResponseContext_->publicKey);
1451 }
1452
1453 HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessageExt_001, testing::ext::TestSize.Level0)
1454 {
1455 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1456 std::shared_ptr<DmAuthManager> data =
1457 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1458 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1459 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1460 authMessageProcessor->authResponseContext_->reply = 123;
1461 authMessageProcessor->authResponseContext_->token = "13213521";
1462 authMessageProcessor->authResponseContext_->confirmOperation = 456;
1463 authMessageProcessor->authResponseContext_->requestId = 521;
1464 nlohmann::json jsonObj;
1465 authMessageProcessor->CreateResponseAuthMessageExt(jsonObj);
1466 ASSERT_EQ(jsonObj[TAG_REPLY], authMessageProcessor->authResponseContext_->reply);
1467 }
1468
1469 HWTEST_F(AuthMessageProcessorTest, CreateRespNegotiateMessage_001, testing::ext::TestSize.Level0)
1470 {
1471 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1472 std::shared_ptr<DmAuthManager> data =
1473 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1474 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1475 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1476 authMessageProcessor->cryptoAdapter_ = nullptr;
1477 nlohmann::json jsonObj;
1478 authMessageProcessor->CreateRespNegotiateMessage(jsonObj);
1479 ASSERT_EQ(jsonObj[TAG_CRYPTO_SUPPORT], false);
1480 }
1481
1482 HWTEST_F(AuthMessageProcessorTest, CreateRespNegotiateMessage_002, testing::ext::TestSize.Level0)
1483 {
1484 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1485 std::shared_ptr<DmAuthManager> data =
1486 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1487 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1488 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1489 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
1490 nlohmann::json jsonObj;
1491 authMessageProcessor->CreateRespNegotiateMessage(jsonObj);
1492 ASSERT_EQ(jsonObj[TAG_CRYPTO_SUPPORT], true);
1493 }
1494
1495 HWTEST_F(AuthMessageProcessorTest, ParseSyncDeleteMessageExt_001, testing::ext::TestSize.Level0)
1496 {
1497 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1498 std::shared_ptr<DmAuthManager> data =
1499 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1500 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1501 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1502 nlohmann::json jsonObj;
1503 jsonObj[TAG_LOCAL_DEVICE_ID] = "12121213";
1504 jsonObj[TAG_HOST_PKGNAME] = "hostPkgname";
1505 jsonObj[TAG_REPLY] = 1212;
1506 authMessageProcessor->ParseSyncDeleteMessageExt(jsonObj);
1507 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, 1212);
1508 }
1509
1510 HWTEST_F(AuthMessageProcessorTest, ParseSyncDeleteMessageExt_002, testing::ext::TestSize.Level0)
1511 {
1512 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1513 std::shared_ptr<DmAuthManager> data =
1514 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1515 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1516 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1517 nlohmann::json jsonObj;
1518 jsonObj[TAG_LOCAL_DEVICE_ID] = 2121;
1519 jsonObj[TAG_HOST_PKGNAME] = 1231;
1520 jsonObj[TAG_REPLY] = "1212";
1521 authMessageProcessor->ParseSyncDeleteMessageExt(jsonObj);
1522 ASSERT_NE(authMessageProcessor->authResponseContext_->reply, 1212);
1523 }
1524
1525 HWTEST_F(AuthMessageProcessorTest, ParsePublicKeyMessageExt_001, testing::ext::TestSize.Level0)
1526 {
1527 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1528 std::shared_ptr<DmAuthManager> data =
1529 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1530 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1531 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1532 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
1533 nlohmann::json jsonObj;
1534 jsonObj[TAG_PUBLICKEY] = 2121;
1535 authMessageProcessor->ParsePublicKeyMessageExt(jsonObj);
1536 ASSERT_EQ(authMessageProcessor->authResponseContext_->publicKey.empty(), true);
1537 }
1538
1539 HWTEST_F(AuthMessageProcessorTest, ParsePublicKeyMessageExt_002, testing::ext::TestSize.Level0)
1540 {
1541 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1542 std::shared_ptr<DmAuthManager> data =
1543 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1544 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1545 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1546 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
1547 nlohmann::json jsonObj;
1548 jsonObj[TAG_PUBLICKEY] = "2121";
1549 authMessageProcessor->ParsePublicKeyMessageExt(jsonObj);
1550 ASSERT_EQ(authMessageProcessor->authResponseContext_->publicKey.empty(), false);
1551 }
1552
1553 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessageExt_001, testing::ext::TestSize.Level0)
1554 {
1555 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1556 std::shared_ptr<DmAuthManager> data =
1557 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1558 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1559 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1560 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
1561 nlohmann::json jsonObj;
1562 jsonObj[TAG_REPLY] = 2121;
1563 jsonObj[TAG_TOKEN] = "1231";
1564 jsonObj[TAG_CONFIRM_OPERATION] = 1212;
1565 jsonObj[TAG_REQUEST_ID] = 1212;
1566 authMessageProcessor->ParseAuthResponseMessageExt(jsonObj);
1567 ASSERT_EQ(authMessageProcessor->authResponseContext_->reply, 2121);
1568 }
1569
1570 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessageExt_002, testing::ext::TestSize.Level0)
1571 {
1572 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1573 std::shared_ptr<DmAuthManager> data =
1574 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1575 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1576 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1577 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
1578 nlohmann::json jsonObj;
1579 jsonObj[TAG_REPLY] = "2121";
1580 jsonObj[TAG_TOKEN] = 1231;
1581 jsonObj[TAG_CONFIRM_OPERATION] = "1212";
1582 jsonObj[TAG_REQUEST_ID] = "1212";
1583 authMessageProcessor->ParseAuthResponseMessageExt(jsonObj);
1584 ASSERT_NE(authMessageProcessor->authResponseContext_->reply, 2121);
1585 }
1586
1587 HWTEST_F(AuthMessageProcessorTest, GetAuthReqMessage_001, testing::ext::TestSize.Level0)
1588 {
1589 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1590 std::shared_ptr<DmAuthManager> data =
1591 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1592 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1593 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1594 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
1595 nlohmann::json jsonObj;
1596 jsonObj[TAG_AUTH_TYPE] = 21;
1597 jsonObj[TAG_TOKEN] = "1231";
1598 jsonObj[TAG_DEVICE_ID] = "1212";
1599 jsonObj[TAG_TARGET] = "1212";
1600 jsonObj[TAG_LOCAL_DEVICE_ID] = "2121";
1601 jsonObj[TAG_APP_OPERATION] = "1231";
1602 jsonObj[TAG_CUSTOM_DESCRIPTION] = "1212";
1603 jsonObj[TAG_REQUESTER] = "1212";
1604 jsonObj[TAG_LOCAL_DEVICE_TYPE] = "2121";
1605 jsonObj[TAG_INDEX] = 1212;
1606 authMessageProcessor->GetAuthReqMessage(jsonObj);
1607 ASSERT_EQ(authMessageProcessor->authResponseContext_->authType, 21);
1608 }
1609
1610 HWTEST_F(AuthMessageProcessorTest, GetAuthReqMessage_002, testing::ext::TestSize.Level0)
1611 {
1612 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1613 std::shared_ptr<DmAuthManager> data =
1614 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1615 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1616 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1617 authMessageProcessor->cryptoAdapter_ = std::make_shared<CryptoAdapterTest>();
1618 nlohmann::json jsonObj;
1619 jsonObj[TAG_AUTH_TYPE] = "21";
1620 jsonObj[TAG_TOKEN] = 1231;
1621 jsonObj[TAG_DEVICE_ID] = 1212;
1622 jsonObj[TAG_TARGET] = 1212;
1623 jsonObj[TAG_LOCAL_DEVICE_ID] = 2121;
1624 jsonObj[TAG_APP_OPERATION] = 1231;
1625 jsonObj[TAG_CUSTOM_DESCRIPTION] = 1212;
1626 jsonObj[TAG_REQUESTER] = 1212;
1627 jsonObj[TAG_LOCAL_DEVICE_TYPE] = 2121;
1628 jsonObj[TAG_INDEX] = "1212";
1629 authMessageProcessor->GetAuthReqMessage(jsonObj);
1630 ASSERT_NE(authMessageProcessor->authResponseContext_->authType, 21);
1631 }
1632
1633 HWTEST_F(AuthMessageProcessorTest, ParsePkgNegotiateMessage_001, testing::ext::TestSize.Level0)
1634 {
1635 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1636 std::shared_ptr<DmAuthManager> data =
1637 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1638 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1639 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1640 nlohmann::json jsonObj;
1641 jsonObj[TAG_LOCAL_ACCOUNTID] = "21";
1642 jsonObj[TAG_LOCAL_USERID] = 1231;
1643 jsonObj[TAG_BIND_LEVEL] = 1212;
1644 jsonObj[TAG_ISONLINE] = true;
1645 jsonObj[TAG_IDENTICAL_ACCOUNT] = true;
1646 jsonObj[TAG_AUTHED] = true;
1647 jsonObj[TAG_TOKENID] = 1212;
1648 jsonObj[TAG_DMVERSION] = "1212";
1649 jsonObj[TAG_HAVECREDENTIAL] = true;
1650 jsonObj[TAG_BIND_TYPE_SIZE] = 5;
1651 authMessageProcessor->ParsePkgNegotiateMessage(jsonObj);
1652 ASSERT_NE(authMessageProcessor->authResponseContext_->authType, 21);
1653 }
1654
1655 HWTEST_F(AuthMessageProcessorTest, ParsePkgNegotiateMessage_002, testing::ext::TestSize.Level0)
1656 {
1657 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1658 std::shared_ptr<DmAuthManager> data =
1659 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1660 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1661 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1662 nlohmann::json jsonObj;
1663 jsonObj[TAG_LOCAL_ACCOUNTID] = 21;
1664 jsonObj[TAG_LOCAL_USERID] = "1231";
1665 jsonObj[TAG_BIND_LEVEL] = "1212";
1666 jsonObj[TAG_ISONLINE] = "1212";
1667 jsonObj[TAG_IDENTICAL_ACCOUNT] = "1212";
1668 jsonObj[TAG_AUTHED] = "1212";
1669 jsonObj[TAG_TOKENID] = "1212";
1670 jsonObj[TAG_DMVERSION] = 1212;
1671 jsonObj[TAG_HAVECREDENTIAL] = "1212";
1672 jsonObj[TAG_BIND_TYPE_SIZE] = "1212";
1673 authMessageProcessor->ParsePkgNegotiateMessage(jsonObj);
1674 jsonObj[TAG_BIND_TYPE_SIZE] = 1212;
1675 jsonObj[TAG_HOST_PKGLABEL] = "1212";
1676 authMessageProcessor->ParsePkgNegotiateMessage(jsonObj);
1677 ASSERT_NE(authMessageProcessor->authResponseContext_->authType, 21);
1678 }
1679
1680 HWTEST_F(AuthMessageProcessorTest, CreateDeviceAuthMessage_001, testing::ext::TestSize.Level0)
1681 {
1682 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
1683 std::shared_ptr<DmAuthManager> data =
1684 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector_, listener, hiChainAuthConnector);
1685 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
1686 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1687 int32_t msgType = 1;
1688 uint8_t param = 0;
1689 uint32_t dataLen = 0;
1690 std::string str = "1324213";
1691 std::string ret = authMessageProcessor->CreateDeviceAuthMessage(msgType, ¶m, dataLen);
1692 ASSERT_EQ(ret.empty(), false);
1693 }
1694 } // namespace
1695 } // namespace DistributedHardware
1696 } // namespace OHOS
1697