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