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