1 /*
2 * Copyright (c) 2021 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 "dm_log.h"
17 #include "dm_constants.h"
18 #include "auth_message_processor.h"
19 #include "softbus_connector.h"
20 #include "softbus_session.h"
21 #include "dm_auth_manager.h"
22 #include "UTTest_auth_message_processor.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
SetUp()26 void AuthMessageProcessorTest::SetUp()
27 {
28 }
TearDown()29 void AuthMessageProcessorTest::TearDown()
30 {
31 }
SetUpTestCase()32 void AuthMessageProcessorTest::SetUpTestCase()
33 {
34 }
TearDownTestCase()35 void AuthMessageProcessorTest::TearDownTestCase()
36 {
37 }
38
39 namespace {
40 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
41 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
42 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
43 /**
44 * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001
45 * @tc.desc: 1 set cryptoAdapter_ to null
46 * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr
47 * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj);
48 * @tc.type: FUNC
49 * @tc.require: AR000GHSJK
50 */
51 HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::TestSize.Level0)
52 {
53 std::shared_ptr<DmAuthManager> data =
54 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
55 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
56 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
57 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
58 int32_t msgType = MSG_TYPE_NEGOTIATE;
59 nlohmann::json jsonObj;
60 jsonObj[TAG_VER] = DM_ITF_VER;
61 jsonObj[TAG_TYPE] = msgType;
62 jsonObj[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
63 authMessageProcessor->SetResponseContext(authResponseContext);
64 authMessageProcessor->cryptoAdapter_ = nullptr;
65 authMessageProcessor->CreateNegotiateMessage(jsonObj);
66 std::string str1 = jsonObj.dump();
67
68 nlohmann::json jsonObject;
69 jsonObject[TAG_VER] = DM_ITF_VER;
70 jsonObject[TAG_TYPE] = msgType;
71 jsonObject[TAG_CRYPTO_SUPPORT] = false;
72 jsonObject[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType;
73 jsonObject[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
74 jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId;
75 std::string str2 = jsonObject.dump();
76 ASSERT_EQ(str1, str2);
77 }
78
79 /**
80 * @tc.name: AuthMessageProcessor::CreateSyncGroupMessage_001
81 * @tc.desc: Compare JSON before and after assignment
82 * @tc.type: FUNC
83 * @tc.require: AR000GHSJK
84 */
85 HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::TestSize.Level0)
86 {
87 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
88 std::shared_ptr<DmAuthManager> data =
89 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
90 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
91 authMessageProcessor->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
92 nlohmann::json jsona;
93 nlohmann::json jsonObj;
94 authMessageProcessor->authRequestContext_->deviceId = "132416546";
95 std::vector<std::string> syncGroupList;
96 syncGroupList.push_back("1111");
97 authMessageProcessor->authRequestContext_->syncGroupList = syncGroupList;
98 jsona[TAG_DEVICE_ID] = authMessageProcessor->authRequestContext_->deviceId;
99 jsona[TAG_GROUPIDS] = authMessageProcessor->authRequestContext_->syncGroupList;
100 authMessageProcessor->CreateSyncGroupMessage(jsonObj);
101 std::string str1 = jsona.dump();
102 std::string str2 = jsonObj.dump();
103 ASSERT_EQ(str1, str2);
104 }
105
106 /**
107 * @tc.name: AuthMessageProcessor::CreateResponseAuthMessage_001
108 * @tc.desc: Compare JSON before and after assignment
109 * @tc.type: FUNC
110 * @tc.require: AR000GHSJK
111 */
112 HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext::TestSize.Level0)
113 {
114 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
115 std::shared_ptr<DmAuthManager> data =
116 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
117 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
118 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
119 nlohmann::json jsona;
120 nlohmann::json jsonObj;
121 authMessageProcessor->authResponseContext_->reply = 0;
122 authMessageProcessor->authResponseContext_->deviceId = "132416546";
123 authMessageProcessor->authResponseContext_->token = "11";
124 nlohmann::json jsonb;
125 jsonb[TAG_GROUP_ID] = "123456";
126 authMessageProcessor->authResponseContext_->groupId = jsonb.dump();
127 authMessageProcessor->authResponseContext_->authToken = "123456";
128 authMessageProcessor->authResponseContext_->networkId = "11112222";
129 authMessageProcessor->authResponseContext_->requestId = 222222;
130 authMessageProcessor->authResponseContext_->groupName = "333333";
131 jsona[TAG_TOKEN] = authMessageProcessor->authResponseContext_->token;
132 jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
133 jsona[TAG_DEVICE_ID] = authMessageProcessor->authResponseContext_->deviceId;
134 jsona[TAG_AUTH_TOKEN] = authMessageProcessor->authResponseContext_->authToken;
135 jsona[TAG_NET_ID] = authMessageProcessor->authResponseContext_->networkId;
136 jsona[TAG_REQUEST_ID] = authMessageProcessor->authResponseContext_->requestId;
137 jsona[TAG_GROUP_ID] = "123456";
138 jsona[TAG_GROUP_NAME] = authMessageProcessor->authResponseContext_->groupName;
139 authMessageProcessor->CreateResponseAuthMessage(jsonObj);
140 std::string str1 = jsona.dump();
141 std::string str2 = jsonObj.dump();
142 ASSERT_EQ(str1, str2);
143 }
144
145 /**
146 * @tc.name: AuthMessageProcessor::CreateResponseFinishMessage_001
147 * @tc.desc: Compare JSON before and after assignment
148 * @tc.type: FUNC
149 * @tc.require: AR000GHSJK
150 */
151 HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext::TestSize.Level0)
152 {
153 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
154 std::shared_ptr<DmAuthManager> data =
155 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
156 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
157 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
158 nlohmann::json jsona;
159 nlohmann::json jsonObj;
160 authMessageProcessor->authResponseContext_->reply = 1;
161 jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
162 authMessageProcessor->CreateResponseFinishMessage(jsonObj);
163 std::string str1 = jsona.dump();
164 std::string str2 = jsonObj.dump();
165 ASSERT_EQ(str1, str2);
166 }
167
168 /**
169 * @tc.name: AuthMessageProcessor::ParseResponseFinishMessage_001
170 * @tc.desc: Compare JSON before and after assignment
171 * @tc.type: FUNC
172 * @tc.require: AR000GHSJK
173 */
174 HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext::TestSize.Level0)
175 {
176 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
177 std::shared_ptr<DmAuthManager> data =
178 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
179 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
180 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
181 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
182 nlohmann::json jsonObj;
183 authMessageProcessor->authResponseContext_->reply = 1;
184 jsonObj[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply;
185 authMessageProcessor->SetResponseContext(authResponseContext);
186 authMessageProcessor->ParseResponseFinishMessage(jsonObj);
187 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
188 }
189
190 /**
191 * @tc.name: AuthMessageProcessor::ParseAuthResponseMessage_001
192 * @tc.desc: Compare JSON before and after assi gnment
193 * @tc.type: FUNC
194 * @tc.require: AR000GHSJK
195 */
196 HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::TestSize.Level0)
197 {
198 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
199 std::shared_ptr<DmAuthManager> data =
200 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
201 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
202 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
203 nlohmann::json jsona;
204 authResponseContext->reply = 0;
205 authResponseContext->deviceId = "11111";
206 authResponseContext->authToken = "123456";
207 authResponseContext->networkId = "12345";
208 authResponseContext->requestId = 2;
209 authResponseContext->groupId = "23456";
210 authResponseContext->groupName = "34567";
211 authResponseContext->token = "11123";
212 jsona[TAG_TOKEN] = authResponseContext->token;
213 jsona[TAG_REPLY] = authResponseContext->reply;
214 jsona[TAG_DEVICE_ID] = authResponseContext->deviceId;
215 jsona[TAG_AUTH_TOKEN] = authResponseContext->authToken;
216 jsona[TAG_NET_ID] = authResponseContext->networkId;
217 jsona[TAG_REQUEST_ID] = authResponseContext->requestId;
218 jsona[TAG_GROUP_ID] = authResponseContext->groupId;
219 jsona[TAG_GROUP_NAME] = authResponseContext->groupName;
220 authMessageProcessor->SetResponseContext(authResponseContext);
221 authMessageProcessor->ParseAuthResponseMessage(jsona);
222 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
223 }
224
225 /**
226 * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_001
227 * @tc.desc: Compare JSON before and after assignment
228 * @tc.type: FUNC
229 * @tc.require: AR000GHSJK
230 */
231 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::TestSize.Level0)
232 {
233 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
234 std::shared_ptr<DmAuthManager> data =
235 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
236 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
237 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
238 authMessageProcessor->SetResponseContext(authResponseContext);
239 nlohmann::json json;
240 nlohmann::json jsonThumbnail;
241 authResponseContext->deviceId = "123";
242 authResponseContext->reply = 0;
243 authResponseContext->authType = 222;
244 authResponseContext->networkId = "234";
245 authResponseContext->groupId = "345";
246 authResponseContext->groupName = "456";
247 authResponseContext->requestId = 2333;
248 jsonThumbnail[TAG_DEVICE_ID] = authResponseContext->deviceId;
249 jsonThumbnail[TAG_REPLY] = authResponseContext->reply;
250 jsonThumbnail[TAG_AUTH_TYPE] = authResponseContext->authType;
251 jsonThumbnail[TAG_NET_ID] = authResponseContext->networkId;
252 jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId;
253 jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName;
254 jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId;
255 authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail);
256 int32_t ret = authMessageProcessor->ParseAuthRequestMessage();
257 ASSERT_EQ(ret, DM_FAILED);
258 }
259
260 /**
261 * @tc.name: AuthMessageProcessor::ParseAuthRequestMessage_002
262 * @tc.desc: Compare JSON before and after assignment
263 * @tc.type: FUNC
264 * @tc.require: AR000GHSJK
265 */
266 HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::TestSize.Level0)
267 {
268 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
269 std::shared_ptr<DmAuthManager> data =
270 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
271 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
272 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
273 authMessageProcessor->SetResponseContext(authResponseContext);
274 nlohmann::json json;
275 nlohmann::json jsonThumbnail;
276 authResponseContext->deviceId = "123";
277 authResponseContext->reply = 1;
278 authResponseContext->authType = 222;
279 authResponseContext->networkId = "234";
280 authResponseContext->groupId = "345";
281 authResponseContext->groupName = "456";
282 authResponseContext->requestId = 2333;
283 jsonThumbnail[TAG_DEVICE_ID] = authResponseContext->deviceId;
284 jsonThumbnail[TAG_REPLY] = authResponseContext->reply;
285 jsonThumbnail[TAG_AUTH_TYPE] = authResponseContext->authType;
286 jsonThumbnail[TAG_NET_ID] = authResponseContext->networkId;
287 jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId;
288 jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName;
289 jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId;
290 authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail);
291 int32_t ret = authMessageProcessor->ParseAuthRequestMessage();
292 ASSERT_EQ(ret, DM_OK);
293 }
294
295 /**
296 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_001
297 * @tc.desc: Compare authResponseContext before and after assignment
298 * @tc.type: FUNC
299 * @tc.require: AR000GHSJK
300 */
301 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::TestSize.Level0)
302 {
303 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
304 std::shared_ptr<DmAuthManager> data =
305 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
306 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
307 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
308 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
309 nlohmann::json jsonObj;
310 jsonObj[TAG_CRYPTO_SUPPORT] = "CRYPTOSUPPORT";
311 jsonObj[TAG_CRYPTO_SUPPORT] = authMessageProcessor->authResponseContext_->cryptoSupport;
312 authResponseContext->localDeviceId = "22";
313 authResponseContext->authType = 1;
314 authResponseContext->reply = 33;
315 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
316 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
317 jsonObj[TAG_REPLY] = authResponseContext->reply;
318 authMessageProcessor->SetResponseContext(authResponseContext);
319 authMessageProcessor->ParseNegotiateMessage(jsonObj);
320 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
321 }
322
323 /**
324 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_002
325 * @tc.desc: Compare authResponseContext before and after assignment
326 * @tc.type: FUNC
327 * @tc.require: AR000GHSJK
328 */
329 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::TestSize.Level0)
330 {
331 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
332 std::shared_ptr<DmAuthManager> data =
333 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
334 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
335 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
336 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
337 nlohmann::json jsonObj;
338 authResponseContext->localDeviceId = "22";
339 authResponseContext->authType = 1;
340 authResponseContext->reply = 33;
341 jsonObj[TAG_CRYPTO_NAME] = "CRYPTONAME";
342 jsonObj[TAG_CRYPTO_NAME] = authResponseContext->cryptoSupport;
343 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
344 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
345 jsonObj[TAG_REPLY] = authResponseContext->reply;
346 authMessageProcessor->SetResponseContext(authResponseContext);
347 authMessageProcessor->ParseNegotiateMessage(jsonObj);
348 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
349 }
350
351 /**
352 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_003
353 * @tc.desc: Compare authResponseContext before and after assignment
354 * @tc.type: FUNC
355 * @tc.require: AR000GHSJK
356 */
357 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::TestSize.Level0)
358 {
359 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
360 std::shared_ptr<DmAuthManager> data =
361 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
362 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
363 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
364 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
365 nlohmann::json jsonObj;
366 authResponseContext->localDeviceId = "22";
367 authResponseContext->authType = 1;
368 authResponseContext->reply = 33;
369 jsonObj[TAG_CRYPTO_VERSION] = "CRYPTOVERSION";
370 jsonObj[TAG_CRYPTO_VERSION] = authResponseContext->cryptoSupport;
371 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
372 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
373 jsonObj[TAG_REPLY] = authResponseContext->reply;
374 authMessageProcessor->SetResponseContext(authResponseContext);
375 authMessageProcessor->ParseNegotiateMessage(jsonObj);
376 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
377 }
378
379 /**
380 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_004
381 * @tc.desc: Compare authResponseContext before and after assignment
382 * @tc.type: FUNC
383 * @tc.require: AR000GHSJK
384 */
385 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::TestSize.Level0)
386 {
387 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
388 std::shared_ptr<DmAuthManager> data =
389 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
390 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
391 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
392 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
393 nlohmann::json jsonObj;
394 authResponseContext->localDeviceId = "22";
395 authResponseContext->authType = 1;
396 authResponseContext->reply = 33;
397 jsonObj[TAG_DEVICE_ID] = "DEVICEID";
398 jsonObj[TAG_DEVICE_ID] = authResponseContext->deviceId;
399 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
400 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
401 jsonObj[TAG_REPLY] = authResponseContext->reply;
402 authMessageProcessor->SetResponseContext(authResponseContext);
403 authMessageProcessor->ParseNegotiateMessage(jsonObj);
404 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
405 }
406
407 /**
408 * @tc.name: AuthMessageProcessor::ParseNegotiateMessage_005
409 * @tc.desc: Compare authResponseContext before and after assignment
410 * @tc.type: FUNC
411 * @tc.require: AR000GHSJK
412 */
413 HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::TestSize.Level0)
414 {
415 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
416 std::shared_ptr<DmAuthManager> data =
417 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
418 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
419 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
420 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
421 nlohmann::json jsonObj;
422 authResponseContext->localDeviceId = "22";
423 authResponseContext->authType = 1;
424 authResponseContext->reply = 33;
425 jsonObj[TAG_LOCAL_DEVICE_ID] = "LOCALDEVICEID";
426 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
427 jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType;
428 jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId;
429 jsonObj[TAG_REPLY] = authResponseContext->reply;
430 authMessageProcessor->SetResponseContext(authResponseContext);
431 authMessageProcessor->ParseNegotiateMessage(jsonObj);
432 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
433 }
434
435 /**
436 * @tc.name: AuthMessageProcessor::SetRequestContext_001
437 * @tc.desc: Compare authResponseContext before and after assignment
438 * @tc.type: FUNC
439 * @tc.require: AR000GHSJK
440 */
441 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize.Level0)
442 {
443 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
444 std::shared_ptr<DmAuthManager> data =
445 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
446 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
447 std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
448 authMessageProcessor->SetRequestContext(authRequestContext);
449 ASSERT_EQ(authMessageProcessor->authRequestContext_, authRequestContext);
450 }
451
452 /**
453 * @tc.name: AuthMessageProcessor::SetRequestContext_002
454 * @tc.desc: Judge whether authrequestcontext is empty
455 * @tc.type: FUNC
456 * @tc.require: AR000GHSJK
457 */
458 HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize.Level0)
459 {
460 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
461 std::shared_ptr<DmAuthManager> data =
462 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
463 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
464 std::shared_ptr<DmAuthRequestContext> authRequestContext = std::make_shared<DmAuthRequestContext>();
465 authMessageProcessor->SetRequestContext(nullptr);
466 ASSERT_EQ(authMessageProcessor->authRequestContext_, nullptr);
467 }
468
469 /**
470 * @tc.name: AuthMessageProcessor::SetResponseContext_001
471 * @tc.desc: Compare authResponseContext before and after assignment
472 * @tc.type: FUNC
473 * @tc.require: AR000GHSJK
474 */
475 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSize.Level0)
476 {
477 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
478 std::shared_ptr<DmAuthManager> data =
479 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
480 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
481 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
482 authMessageProcessor->SetResponseContext(authResponseContext);
483 ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext);
484 }
485
486 /**
487 * @tc.name: AuthMessageProcessor::SetResponseContext_002
488 * @tc.desc: Judge whether authrequestcontext is empty
489 * @tc.type: FUNC
490 * @tc.require: AR000GHSJK
491 */
492 HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSize.Level0)
493 {
494 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
495 std::shared_ptr<DmAuthManager> data =
496 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
497 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
498 std::shared_ptr<DmAuthResponseContext> authResponseContext = std::make_shared<DmAuthResponseContext>();
499 authMessageProcessor->SetResponseContext(nullptr);
500 ASSERT_EQ(authMessageProcessor->authResponseContext_, nullptr);
501 }
502
503 /**
504 * @tc.name: AuthMessageProcessor::GetResponseContext_001
505 * @tc.desc: Compare authResponseContext before and after assignment
506 * @tc.type: FUNC
507 * @tc.require: AR000GHSJK
508 */
509 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSize.Level0)
510 {
511 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
512 std::shared_ptr<DmAuthManager> data =
513 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
514 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
515 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
516 std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
517 ASSERT_EQ(authResponseContext, authMessageProcessor->authResponseContext_);
518 }
519
520 /**
521 * @tc.name: AuthMessageProcessor::GetResponseContext_002
522 * @tc.desc: Judge whether authrequestcontext is empty
523 * @tc.type: FUNC
524 * @tc.require: AR000GHSJK
525 */
526 HWTEST_F(AuthMessageProcessorTest, GetResponseContext_002, testing::ext::TestSize.Level0)
527 {
528 std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>();
529 std::shared_ptr<DmAuthManager> data =
530 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector_);
531 std::shared_ptr<AuthMessageProcessor> authMessageProcessor = std::make_shared<AuthMessageProcessor>(data);
532 authMessageProcessor->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
533 std::shared_ptr<DmAuthResponseContext> authResponseContext = authMessageProcessor->GetResponseContext();
534 ASSERT_NE(authResponseContext, nullptr);
535 }
536 } // namespace
537 } // namespace DistributedHardware
538 } // namespace OHOS
539