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 "UTTest_auth_request_state.h"
17
18 #include "auth_message_processor.h"
19 #include "dm_auth_manager.h"
20 #include "dm_constants.h"
21
22 namespace OHOS {
23 namespace DistributedHardware {
SetUp()24 void AuthRequestStateTest::SetUp()
25 {
26 }
TearDown()27 void AuthRequestStateTest::TearDown()
28 {
29 }
SetUpTestCase()30 void AuthRequestStateTest::SetUpTestCase()
31 {
32 }
TearDownTestCase()33 void AuthRequestStateTest::TearDownTestCase()
34 {
35 }
36
37 namespace {
38 std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask";
39 std::string ADD_TIMEOUT_TASK = "addTimeoutTask";
40
41 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
42 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
43 std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
44 /**
45 * @tc.name: AuthRequestInitState::SetAuthManager_001
46 * @tc.desc: 1 set authManager not null
47 * 2 call AuthRequestInitState::SetAuthManager with authManager != null
48 * 3 check ret is authResponseState->authManager_.use_count()
49 * @tc.type: FUNC
50 * @tc.require: AR000GHSJK
51 */
52 HWTEST_F(AuthRequestStateTest, SetAuthManager_001, testing::ext::TestSize.Level0)
53 {
54 std::shared_ptr<DmAuthManager> authManager =
55 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
56 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>();
57 authRequestState->SetAuthManager(authManager);
58 int32_t ret = authRequestState->authManager_.use_count();
59 authRequestState->authManager_.reset();
60 ASSERT_EQ(ret, 1);
61 }
62
63 /**
64 * @tc.name: AuthRequestInitState::SetAuthManager_002
65 * @tc.desc: 1 set authManager to null
66 * 2 call AuthRequestInitState::SetAuthManager with authManager = null
67 * 3 check ret is authResponseState->authManager_.use_count()
68 * @tc.type: FUNC
69 * @tc.require: AR000GHSJK
70 */
71 HWTEST_F(AuthRequestStateTest, SetAuthManager_002, testing::ext::TestSize.Level0)
72 {
73 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>();
74 authRequestState->SetAuthManager(nullptr);
75 int32_t ret = authRequestState->authManager_.use_count();
76 authRequestState->authManager_.reset();
77 ASSERT_EQ(ret, 0);
78 }
79
80 /**
81 * @tc.name: AuthRequestNegotiateState::TransitionTo_001
82 * @tc.desc: 1 set authManager to null
83 * 2 call AuthRequestInitState::TransitionTo with authManager = null
84 * 4 check ret is DM_FAILED
85 * @tc.type: FUNC
86 * @tc.require: AR000GHSJK
87 */
88 HWTEST_F(AuthRequestStateTest, TransitionTo_001, testing::ext::TestSize.Level0)
89 {
90 std::shared_ptr<DmAuthManager> authManager =
91 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
92 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>();
93 authManager = nullptr;
94 authRequestState->authManager_ = authManager;
95 int32_t ret = authRequestState->TransitionTo(std::make_shared<AuthRequestNegotiateState>());
96 ASSERT_EQ(ret, DM_FAILED);
97 }
98
99 /**
100 * @tc.name: AuthRequestInitState::TransitionTo_002
101 * @tc.desc: 1 set authManager not null
102 * 2 call AuthRequestInitState::TransitionTo with authManager != null
103 * 4 check ret is DM_OK
104 * @tc.type: FUNC
105 * @tc.require: AR000GHSJK
106 */
107 HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0)
108 {
109 std::shared_ptr<DmAuthManager> authManager =
110 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
111 std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>();
112 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateDoneState>();
113 authManager->timer_ = std::make_shared<DmTimer>();
114 authManager->authRequestState_ = std::make_shared<AuthRequestNegotiateDoneState>();
115 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
116 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
117 authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager);
118 authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_);
119 authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_);
120 context->sessionId = 123456;
121 authManager->SetAuthRequestState(authRequestState);
122 authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager);
123 authRequestState->SetAuthContext(context);
124 authRequestState->SetAuthManager(authManager);
125 int32_t ret = authRequestState->TransitionTo(std::make_shared<AuthRequestNegotiateDoneState>());
126 ASSERT_EQ(ret, DM_OK);
127 }
128
129 /**
130 * @tc.name: AuthRequestInitState::GetStateType_001
131 * @tc.desc: 1 call AuthRequestInitState::GetStateType
132 * 2 check ret is AuthState::AUTH_RESPONSE_INIT
133 * @tc.type: FUNC
134 * @tc.require: AR000GHSJK
135 */
136 HWTEST_F(AuthRequestStateTest, GetStateType_001, testing::ext::TestSize.Level0)
137 {
138 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>();
139 int32_t ret = authRequestState->GetStateType();
140 ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INIT);
141 }
142
143 /**
144 * @tc.name: AuthRequestInitState::Enter_001
145 * @tc.desc: 1 set authManager to null
146 * 2 call AuthRequestInitState::Enter with authManager = null
147 * 3 check ret is DM_FAILED
148 * @tc.type: FUNC
149 * @tc.require: AR000GHSJK
150 */
151 HWTEST_F(AuthRequestStateTest, Enter_001, testing::ext::TestSize.Level0)
152 {
153 std::shared_ptr<DmAuthManager> authManager =
154 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
155 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>();
156 authManager = nullptr;
157 authRequestState->SetAuthManager(authManager);
158 int32_t ret = authRequestState->Enter();
159 ASSERT_EQ(ret, DM_FAILED);
160 }
161
162 /**
163 * @tc.name: AuthRequestInitState::Enter_002
164 * @tc.desc: 1 set authManager not null
165 * 2 call AuthRequestInitState::Enter with authManager != null
166 * 3 check ret is DM_FAILED
167 * @tc.type: FUNC
168 * @tc.require: AR000GHSJK
169 */
170 HWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0)
171 {
172 std::shared_ptr<DmAuthManager> authManager =
173 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
174 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>();
175 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
176 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
177 authManager->authRequestState_ = std::make_shared<AuthRequestInitState>();
178 authRequestState->SetAuthManager(authManager);
179 std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>();
180 context->deviceId = "123456";
181 authRequestState->SetAuthContext(context);
182 int32_t ret = authRequestState->Enter();
183 ASSERT_EQ(ret, DM_OK);
184 }
185
186 /**
187 * @tc.name: AuthRequestNegotiateState::GetStateType_002
188 * @tc.desc: 1 call AuthRequestNegotiateState::GetStateType
189 * 2 check ret is AuthState::AUTH_RESPONSE_NEGOTIATE
190 * @tc.type: FUNC
191 * @tc.require: AR000GHSJK
192 */
193 HWTEST_F(AuthRequestStateTest, GetStateType_002, testing::ext::TestSize.Level0)
194 {
195 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateState>();
196 int32_t ret = authRequestState->GetStateType();
197 ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE);
198 }
199
200 /**
201 * @tc.name: AuthRequestNegotiateState::Enter_001
202 * @tc.desc: 1 set authManager to null
203 * 2 call AuthRequestNegotiateState::Enter with authManager = null
204 * 3 check ret is DM_FAILED
205 * @tc.type: FUNC
206 * @tc.require: AR000GHSJK
207 */
208 HWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0)
209 {
210 std::shared_ptr<DmAuthManager> authManager =
211 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
212 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateState>();
213 authRequestState->SetAuthManager(nullptr);
214 int32_t ret = authRequestState->Enter();
215 ASSERT_EQ(ret, DM_FAILED);
216 }
217
218 /**
219 * @tc.name: AuthRequestNegotiateState::Enter_004
220 * @tc.desc: 1 set authManager not null
221 * 2 call AuthRequestNegotiateState::Enter with authManager != null
222 * 3 check ret is DM_OK
223 * @tc.type: FUNC
224 * @tc.require: AR000GHSJK
225 */
226 HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0)
227 {
228 std::shared_ptr<DmAuthManager> authManager =
229 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
230 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateState>();
231 authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager);
232 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
233 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
234 authManager->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
235 authManager->authRequestContext_->deviceId = "111";
236 authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_);
237 authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_);
238 authManager->timer_ = std::make_shared<DmTimer>();
239 authRequestState->SetAuthManager(authManager);
240 std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>();
241 context->deviceId = "123456";
242 context->sessionId = 22222;
243 authRequestState->SetAuthContext(context);
244 int32_t ret = authRequestState->Enter();
245 ASSERT_EQ(ret, DM_OK);
246 }
247
248 /**
249 * @tc.name: AuthRequestNegotiateDoneState::GetStateType_003
250 * @tc.desc: 1 call AuthRequestNegotiateDoneState::GetStateType
251 * 2 check ret is AuthState::AUTH_REQUEST_NEGOTIATE_DONE
252 * @tc.type: FUNC
253 * @tc.require: AR000GHSJK
254 */
255 HWTEST_F(AuthRequestStateTest, GetStateType_003, testing::ext::TestSize.Level0)
256 {
257 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateDoneState>();
258 int32_t ret = authRequestState->GetStateType();
259 ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE_DONE);
260 }
261
262 /**
263 * @tc.name: AuthRequestNegotiateDoneState::Enter_006
264 * @tc.desc: 1 set authManager not null
265 * 2 call AuthRequestNegotiateDoneState::Enter with authManager != null
266 * 3 check ret is DM_OK
267 * @tc.type: FUNC
268 * @tc.require: AR000GHSJK
269 */
270 HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0)
271 {
272 std::shared_ptr<DmAuthManager> authManager =
273 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
274 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateDoneState>();
275 authManager->timer_ = std::make_shared<DmTimer>();
276 authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager);
277 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
278 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
279 authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_);
280 authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_);
281 authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager);
282 authManager->SetAuthRequestState(authRequestState);
283 authRequestState->SetAuthManager(authManager);
284 std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>();
285 context->sessionId = 333333;
286 authRequestState->SetAuthContext(context);
287 int32_t ret = authRequestState->Enter();
288 ASSERT_EQ(ret, DM_OK);
289 }
290
291 /**
292 * @tc.name: AuthRequestReplyState::GetStateType_004
293 * @tc.desc: 1 call AuthRequestReplyState::GetStateType
294 * 2 check ret is AuthState::AUTH_REQUEST_REPLY
295 * @tc.type: FUNC
296 * @tc.require: AR000GHSJK
297 */
298 HWTEST_F(AuthRequestStateTest, GetStateType_004, testing::ext::TestSize.Level0)
299 {
300 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestReplyState>();
301 int32_t ret = authRequestState->GetStateType();
302 ASSERT_EQ(ret, AuthState::AUTH_REQUEST_REPLY);
303 }
304
305 /**
306 * @tc.name: AuthRequestReplyState::Enter_007
307 * @tc.desc: 1 set authManager to null
308 * 2 call AuthRequestReplyState::Enter with authManager = null
309 * 3 check ret is DM_FAILED
310 * @tc.type: FUNC
311 * @tc.require: AR000GHSJK
312 */
313 HWTEST_F(AuthRequestStateTest, Enter_007, testing::ext::TestSize.Level0)
314 {
315 std::shared_ptr<DmAuthManager> authManager =
316 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
317 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestReplyState>();
318 authRequestState->SetAuthManager(nullptr);
319 int32_t ret = authRequestState->Enter();
320 ASSERT_EQ(ret, DM_FAILED);
321 }
322
323 /**
324 * @tc.name: AuthRequestReplyState::Enter_008
325 * @tc.desc: 1 set authManager not null
326 * 2 call AuthRequestReplyState::Enter with authManager != null
327 * 3 check ret is DM_OK
328 * @tc.type: FUNC
329 * @tc.require: AR000GHSJK
330 */
331 HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0)
332 {
333 std::shared_ptr<DmAuthManager> authManager =
334 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
335 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestReplyState>();
336 authManager->timer_ = std::make_shared<DmTimer>();
337 authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager);
338 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
339 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
340 authManager->authRequestState_ = std::make_shared<AuthRequestReplyState>();
341 authManager->authResponseContext_->sessionId = 1;
342 authManager->authPtr_ = authManager->authenticationMap_[1];
343 authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_);
344 authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_);
345 authManager->SetAuthRequestState(authRequestState);
346 authRequestState->SetAuthManager(authManager);
347 std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>();
348 context->sessionId = 333333;
349 authRequestState->SetAuthContext(context);
350 int32_t ret = authRequestState->Enter();
351 ASSERT_EQ(ret, DM_OK);
352 }
353
354 /**
355 * @tc.name: AuthRequestJoinState::GetStateType_006
356 * @tc.desc: 1 call AuthRequestJoinState::GetStateType
357 * 2 check ret is AuthState::AUTH_REQUEST_JOIN
358 * @tc.type: FUNC
359 * @tc.require: AR000GHSJK
360 */
361 HWTEST_F(AuthRequestStateTest, GetStateType_006, testing::ext::TestSize.Level0)
362 {
363 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestJoinState>();
364 int32_t ret = authRequestState->GetStateType();
365 ASSERT_EQ(ret, AuthState::AUTH_REQUEST_JOIN);
366 }
367
368 /**
369 * @tc.name: AuthRequestJoinState::Enter_011
370 * @tc.desc: 1 set authManager to null
371 * 2 call AuthRequestJoinState::Enter with authManager = null
372 * 3 check ret is DM_FAILED
373 * @tc.type: FUNC
374 * @tc.require: AR000GHSJK
375 */
376 HWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0)
377 {
378 std::shared_ptr<DmAuthManager> authManager =
379 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
380 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestJoinState>();
381 authRequestState->SetAuthManager(nullptr);
382 int32_t ret = authRequestState->Enter();
383 ASSERT_EQ(ret, DM_FAILED);
384 }
385
386 /**
387 * @tc.name: AuthRequestJoinState::Enter_012
388 * @tc.desc: 1 set authManager not null
389 * 2 call AuthRequestJoinState::Enter with authManager != null
390 * 3 check ret is DM_OK
391 * @tc.type: FUNC
392 * @tc.require: AR000GHSJK
393 */
394 HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0)
395 {
396 std::shared_ptr<DmAuthManager> authManager =
397 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
398 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestJoinState>();
399 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
400 authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager);
401 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
402 authManager->authPtr_ = authManager->authenticationMap_[1];
403 authManager->authResponseContext_->groupId = "111";
404 authManager->authResponseContext_->groupName = "222";
405 authManager->authResponseContext_->code = 123;
406 authManager->authResponseContext_->requestId = 234;
407 authManager->authResponseContext_->deviceId = "234";
408 authRequestState->SetAuthManager(authManager);
409 authManager->timer_ = std::make_shared<DmTimer>();
410 authManager->SetAuthRequestState(authRequestState);
411 authManager->hiChainConnector_->RegisterHiChainCallback(authManager);
412 authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager);
413 std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>();
414 context->deviceId = "44444";
415 context->sessionId = 55555;
416 authRequestState->SetAuthContext(context);
417 int32_t ret = authRequestState->Enter();
418 ASSERT_EQ(ret, DM_OK);
419 }
420
421 /**
422 * @tc.name: AuthRequestNetworkState::GetStateType_007
423 * @tc.desc: 1 call AuthRequestNetworkState::GetStateType
424 * 2 check ret is AuthState::AUTH_REQUEST_NETWORK
425 * @tc.type: FUNC
426 * @tc.require: AR000GHSJK
427 */
428 HWTEST_F(AuthRequestStateTest, GetStateType_007, testing::ext::TestSize.Level0)
429 {
430 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNetworkState>();
431 int32_t ret = authRequestState->GetStateType();
432 ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NETWORK);
433 }
434
435 /**
436 * @tc.name: AuthRequestNetworkState::Enter_013
437 * @tc.desc: 1 set authManager to null
438 * 2 call AuthRequestNetworkState::Enter with authManager = null
439 * 3 check ret is DM_FAILED
440 * @tc.type: FUNC
441 * @tc.require: AR000GHSJK
442 */
443 HWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0)
444 {
445 std::shared_ptr<DmAuthManager> authManager =
446 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
447 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNetworkState>();
448 authRequestState->SetAuthManager(nullptr);
449 int32_t ret = authRequestState->Enter();
450 ASSERT_EQ(ret, DM_FAILED);
451 }
452
453 /**
454 * @tc.name: AuthRequestNetworkState::Enter_014
455 * @tc.desc: 1 set authManager not null
456 * 2 call AuthRequestNetworkState::Enter with authManager != null
457 * 3 check ret is DM_OK
458 * @tc.type: FUNC
459 * @tc.require: AR000GHSJK
460 */
461 HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0)
462 {
463 std::shared_ptr<DmAuthManager> authManager =
464 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
465 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNetworkState>();
466 authManager->timer_ = std::make_shared<DmTimer>();
467 authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager);
468 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
469 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
470 authManager->authRequestState_ = std::make_shared<AuthRequestNetworkState>();
471 authManager->authPtr_ = authManager->authenticationMap_[1];
472 authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_);
473 authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_);
474 authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager);
475 authManager->SetAuthRequestState(authRequestState);
476 authRequestState->SetAuthManager(authManager);
477 int32_t ret = authRequestState->Enter();
478 ASSERT_EQ(ret, DM_OK);
479 }
480
481 /**
482 * @tc.name: AuthRequestFinishState::GetStateType_008
483 * @tc.desc: 1 call AuthRequestFinishState::GetStateType
484 * 2 check ret is AuthState::AUTH_REQUEST_FINISH
485 * @tc.type: FUNC
486 * @tc.require: AR000GHSJK
487 */
488 HWTEST_F(AuthRequestStateTest, GetStateType_008, testing::ext::TestSize.Level0)
489 {
490 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>();
491 int32_t ret = authRequestState->GetStateType();
492 ASSERT_EQ(ret, AuthState::AUTH_REQUEST_FINISH);
493 }
494
495 /**
496 * @tc.name: AuthRequestFinishState::Enter_015
497 * @tc.desc: 1 set authManager to null
498 * 2 call AuthRequestFinishState::Enter with authManager = null
499 * 3 check ret is DM_FAILED
500 * @tc.type: FUNC
501 * @tc.require: AR000GHSJK
502 */
503 HWTEST_F(AuthRequestStateTest, Enter_015, testing::ext::TestSize.Level0)
504 {
505 std::shared_ptr<DmAuthManager> authManager =
506 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
507 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>();
508 authRequestState->SetAuthManager(nullptr);
509 int32_t ret = authRequestState->Enter();
510 ASSERT_EQ(ret, DM_FAILED);
511 }
512
513 /**
514 * @tc.name: AuthRequestFinishState::Enter_016
515 * @tc.desc: 1 set authManager not null
516 * 2 call AuthRequestNetworkState::Enter with authManager != null
517 * 3 check ret is DM_OK
518 * @tc.type: FUNC
519 * @tc.require: AR000GHSJK
520 */
521 HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0)
522 {
523 std::shared_ptr<DmAuthManager> authManager =
524 std::make_shared<DmAuthManager>(softbusConnector, listener, hiChainConnector);
525 std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>();
526 authManager->timer_ = std::make_shared<DmTimer>();
527 authManager->authPtr_ = authManager->authenticationMap_[1];
528 authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager);
529 authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
530 authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
531 authManager->authResponseState_ = std::make_shared<AuthResponseFinishState>();
532 authManager->authRequestState_ = std::make_shared<AuthRequestFinishState>();
533 authManager->authResponseContext_->sessionId = 1;
534 authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_);
535 authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_);
536 authManager->SetAuthRequestState(authRequestState);
537 authRequestState->SetAuthManager(authManager);
538 std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>();
539 context->sessionId = 333333;
540 authRequestState->SetAuthContext(context);
541 int32_t ret = authRequestState->Enter();
542 ASSERT_EQ(ret, DM_OK);
543 }
544 } // namespace
545 } // namespace DistributedHardware
546 } // namespace OHOS
547