179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License. 579a732c7Sopenharmony_ci * You may obtain a copy of the License at 679a732c7Sopenharmony_ci * 779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 879a732c7Sopenharmony_ci * 979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and 1379a732c7Sopenharmony_ci * limitations under the License. 1479a732c7Sopenharmony_ci */ 1579a732c7Sopenharmony_ci 1679a732c7Sopenharmony_ci#include "UTTest_auth_request_state.h" 1779a732c7Sopenharmony_ci 1879a732c7Sopenharmony_ci#include "auth_message_processor.h" 1979a732c7Sopenharmony_ci#include "dm_auth_manager.h" 2079a732c7Sopenharmony_ci#include "dm_constants.h" 2179a732c7Sopenharmony_ci#include "device_manager_service_listener.h" 2279a732c7Sopenharmony_ci 2379a732c7Sopenharmony_cinamespace OHOS { 2479a732c7Sopenharmony_cinamespace DistributedHardware { 2579a732c7Sopenharmony_civoid AuthRequestStateTest::SetUp() 2679a732c7Sopenharmony_ci{ 2779a732c7Sopenharmony_ci} 2879a732c7Sopenharmony_civoid AuthRequestStateTest::TearDown() 2979a732c7Sopenharmony_ci{ 3079a732c7Sopenharmony_ci} 3179a732c7Sopenharmony_civoid AuthRequestStateTest::SetUpTestCase() 3279a732c7Sopenharmony_ci{ 3379a732c7Sopenharmony_ci} 3479a732c7Sopenharmony_civoid AuthRequestStateTest::TearDownTestCase() 3579a732c7Sopenharmony_ci{ 3679a732c7Sopenharmony_ci} 3779a732c7Sopenharmony_ci 3879a732c7Sopenharmony_cinamespace { 3979a732c7Sopenharmony_cistd::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>(); 4079a732c7Sopenharmony_cistd::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>(); 4179a732c7Sopenharmony_cistd::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>(); 4279a732c7Sopenharmony_cistd::shared_ptr<HiChainAuthConnector> hiChainAuthConnector = std::make_shared<HiChainAuthConnector>(); 4379a732c7Sopenharmony_ci 4479a732c7Sopenharmony_ci/** 4579a732c7Sopenharmony_ci * @tc.name: AuthResponseInitState::Leave_001 4679a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 4779a732c7Sopenharmony_ci * 2 call AuthResponseInitState::Leave with authManager != null 4879a732c7Sopenharmony_ci * 3 check ret is authResponseState->authManager_.use_count() 4979a732c7Sopenharmony_ci * @tc.type: FUNC 5079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 5179a732c7Sopenharmony_ci */ 5279a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Leave_001, testing::ext::TestSize.Level0) 5379a732c7Sopenharmony_ci{ 5479a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 5579a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 5679a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 5779a732c7Sopenharmony_ci int32_t ret = authRequestState->Leave(); 5879a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 5979a732c7Sopenharmony_ci} 6079a732c7Sopenharmony_ci 6179a732c7Sopenharmony_ci/** 6279a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::SetAuthContext_001 6379a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 6479a732c7Sopenharmony_ci * 2 call AuthRequestInitState::SetAuthManager with authManager != null 6579a732c7Sopenharmony_ci * 3 check ret is authResponseState->authManager_.use_count() 6679a732c7Sopenharmony_ci * @tc.type: FUNC 6779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 6879a732c7Sopenharmony_ci */ 6979a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, SetAuthContext_001, testing::ext::TestSize.Level0) 7079a732c7Sopenharmony_ci{ 7179a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 7279a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 7379a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 7479a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 7579a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 7679a732c7Sopenharmony_ci int32_t ret = authRequestState->context_.use_count(); 7779a732c7Sopenharmony_ci authRequestState->context_.reset(); 7879a732c7Sopenharmony_ci ASSERT_EQ(ret, 2); 7979a732c7Sopenharmony_ci} 8079a732c7Sopenharmony_ci 8179a732c7Sopenharmony_ci/** 8279a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::SetAuthManager_002 8379a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 8479a732c7Sopenharmony_ci * 2 call AuthRequestInitState::SetAuthManager with authManager = null 8579a732c7Sopenharmony_ci * 3 check ret is authResponseState->authManager_.use_count() 8679a732c7Sopenharmony_ci * @tc.type: FUNC 8779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 8879a732c7Sopenharmony_ci */ 8979a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, SetAuthContext_002, testing::ext::TestSize.Level0) 9079a732c7Sopenharmony_ci{ 9179a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 9279a732c7Sopenharmony_ci authRequestState->SetAuthContext(nullptr); 9379a732c7Sopenharmony_ci int32_t ret = authRequestState->authManager_.use_count(); 9479a732c7Sopenharmony_ci authRequestState->authManager_.reset(); 9579a732c7Sopenharmony_ci ASSERT_EQ(ret, 0); 9679a732c7Sopenharmony_ci} 9779a732c7Sopenharmony_ci 9879a732c7Sopenharmony_ci/** 9979a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::GetAuthContext_001 10079a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 10179a732c7Sopenharmony_ci * 2 call AuthRequestInitState::GetAuthContext with authManager != null 10279a732c7Sopenharmony_ci * 3 check ret is authResponseState->authManager_.use_count() 10379a732c7Sopenharmony_ci * @tc.type: FUNC 10479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 10579a732c7Sopenharmony_ci */ 10679a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetAuthContext_001, testing::ext::TestSize.Level0) 10779a732c7Sopenharmony_ci{ 10879a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 10979a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 11079a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 11179a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 11279a732c7Sopenharmony_ci authRequestState->GetAuthContext(); 11379a732c7Sopenharmony_ci int32_t ret = authRequestState->context_.use_count(); 11479a732c7Sopenharmony_ci authRequestState->context_.reset(); 11579a732c7Sopenharmony_ci ASSERT_EQ(ret, 0); 11679a732c7Sopenharmony_ci} 11779a732c7Sopenharmony_ci 11879a732c7Sopenharmony_ci/** 11979a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::SetAuthManager_001 12079a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 12179a732c7Sopenharmony_ci * 2 call AuthRequestInitState::SetAuthManager with authManager != null 12279a732c7Sopenharmony_ci * 3 check ret is authResponseState->authManager_.use_count() 12379a732c7Sopenharmony_ci * @tc.type: FUNC 12479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 12579a732c7Sopenharmony_ci */ 12679a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, SetAuthManager_001, testing::ext::TestSize.Level0) 12779a732c7Sopenharmony_ci{ 12879a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 12979a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 13079a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 13179a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 13279a732c7Sopenharmony_ci int32_t ret = authRequestState->authManager_.use_count(); 13379a732c7Sopenharmony_ci authRequestState->authManager_.reset(); 13479a732c7Sopenharmony_ci ASSERT_EQ(ret, 1); 13579a732c7Sopenharmony_ci} 13679a732c7Sopenharmony_ci 13779a732c7Sopenharmony_ci/** 13879a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::SetAuthManager_002 13979a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 14079a732c7Sopenharmony_ci * 2 call AuthRequestInitState::SetAuthManager with authManager = null 14179a732c7Sopenharmony_ci * 3 check ret is authResponseState->authManager_.use_count() 14279a732c7Sopenharmony_ci * @tc.type: FUNC 14379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 14479a732c7Sopenharmony_ci */ 14579a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, SetAuthManager_002, testing::ext::TestSize.Level0) 14679a732c7Sopenharmony_ci{ 14779a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 14879a732c7Sopenharmony_ci authRequestState->SetAuthManager(nullptr); 14979a732c7Sopenharmony_ci int32_t ret = authRequestState->authManager_.use_count(); 15079a732c7Sopenharmony_ci authRequestState->authManager_.reset(); 15179a732c7Sopenharmony_ci ASSERT_EQ(ret, 0); 15279a732c7Sopenharmony_ci} 15379a732c7Sopenharmony_ci 15479a732c7Sopenharmony_ci/** 15579a732c7Sopenharmony_ci * @tc.name: AuthRequestNegotiateState::TransitionTo_001 15679a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 15779a732c7Sopenharmony_ci * 2 call AuthRequestInitState::TransitionTo with authManager = null 15879a732c7Sopenharmony_ci * 4 check ret is ERR_DM_FAILED 15979a732c7Sopenharmony_ci * @tc.type: FUNC 16079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 16179a732c7Sopenharmony_ci */ 16279a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, TransitionTo_001, testing::ext::TestSize.Level0) 16379a732c7Sopenharmony_ci{ 16479a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 16579a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 16679a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 16779a732c7Sopenharmony_ci authManager = nullptr; 16879a732c7Sopenharmony_ci authRequestState->authManager_ = authManager; 16979a732c7Sopenharmony_ci int32_t ret = authRequestState->TransitionTo(std::make_shared<AuthRequestNegotiateState>()); 17079a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 17179a732c7Sopenharmony_ci} 17279a732c7Sopenharmony_ci 17379a732c7Sopenharmony_ci/** 17479a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::TransitionTo_002 17579a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 17679a732c7Sopenharmony_ci * 2 call AuthRequestInitState::TransitionTo with authManager != null 17779a732c7Sopenharmony_ci * 4 check ret is DM_OK 17879a732c7Sopenharmony_ci * @tc.type: FUNC 17979a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 18079a732c7Sopenharmony_ci */ 18179a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) 18279a732c7Sopenharmony_ci{ 18379a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 18479a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 18579a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 18679a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateDoneState>(); 18779a732c7Sopenharmony_ci authManager->timer_ = std::make_shared<DmTimer>(); 18879a732c7Sopenharmony_ci authManager->authRequestState_ = std::make_shared<AuthRequestNegotiateDoneState>(); 18979a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 19079a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 19179a732c7Sopenharmony_ci authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager); 19279a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); 19379a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); 19479a732c7Sopenharmony_ci context->sessionId = 123456; 19579a732c7Sopenharmony_ci authManager->SetAuthRequestState(authRequestState); 19679a732c7Sopenharmony_ci authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); 19779a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 19879a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 19979a732c7Sopenharmony_ci int32_t ret = authRequestState->TransitionTo(std::make_shared<AuthRequestNegotiateDoneState>()); 20079a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 20179a732c7Sopenharmony_ci} 20279a732c7Sopenharmony_ci 20379a732c7Sopenharmony_ci/** 20479a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::GetStateType_001 20579a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestInitState::GetStateType 20679a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_RESPONSE_INIT 20779a732c7Sopenharmony_ci * @tc.type: FUNC 20879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 20979a732c7Sopenharmony_ci */ 21079a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_001, testing::ext::TestSize.Level0) 21179a732c7Sopenharmony_ci{ 21279a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 21379a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 21479a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INIT); 21579a732c7Sopenharmony_ci} 21679a732c7Sopenharmony_ci 21779a732c7Sopenharmony_ci/** 21879a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::Enter_001 21979a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 22079a732c7Sopenharmony_ci * 2 call AuthRequestInitState::Enter with authManager = null 22179a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 22279a732c7Sopenharmony_ci * @tc.type: FUNC 22379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 22479a732c7Sopenharmony_ci */ 22579a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_001, testing::ext::TestSize.Level0) 22679a732c7Sopenharmony_ci{ 22779a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 22879a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 22979a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 23079a732c7Sopenharmony_ci authManager = nullptr; 23179a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 23279a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 23379a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 23479a732c7Sopenharmony_ci} 23579a732c7Sopenharmony_ci 23679a732c7Sopenharmony_ci/** 23779a732c7Sopenharmony_ci * @tc.name: AuthRequestInitState::Enter_002 23879a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 23979a732c7Sopenharmony_ci * 2 call AuthRequestInitState::Enter with authManager != null 24079a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 24179a732c7Sopenharmony_ci * @tc.type: FUNC 24279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 24379a732c7Sopenharmony_ci */ 24479a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0) 24579a732c7Sopenharmony_ci{ 24679a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 24779a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 24879a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestInitState>(); 24979a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 25079a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 25179a732c7Sopenharmony_ci authManager->authRequestState_ = std::make_shared<AuthRequestInitState>(); 25279a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 25379a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 25479a732c7Sopenharmony_ci context->deviceId = "123456"; 25579a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 25679a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 25779a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 25879a732c7Sopenharmony_ci} 25979a732c7Sopenharmony_ci 26079a732c7Sopenharmony_ci/** 26179a732c7Sopenharmony_ci * @tc.name: AuthRequestNegotiateState::GetStateType_002 26279a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestNegotiateState::GetStateType 26379a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_RESPONSE_NEGOTIATE 26479a732c7Sopenharmony_ci * @tc.type: FUNC 26579a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 26679a732c7Sopenharmony_ci */ 26779a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_002, testing::ext::TestSize.Level0) 26879a732c7Sopenharmony_ci{ 26979a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateState>(); 27079a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 27179a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE); 27279a732c7Sopenharmony_ci} 27379a732c7Sopenharmony_ci 27479a732c7Sopenharmony_ci/** 27579a732c7Sopenharmony_ci * @tc.name: AuthRequestNegotiateState::Enter_001 27679a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 27779a732c7Sopenharmony_ci * 2 call AuthRequestNegotiateState::Enter with authManager = null 27879a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 27979a732c7Sopenharmony_ci * @tc.type: FUNC 28079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 28179a732c7Sopenharmony_ci */ 28279a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0) 28379a732c7Sopenharmony_ci{ 28479a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 28579a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 28679a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateState>(); 28779a732c7Sopenharmony_ci authRequestState->SetAuthManager(nullptr); 28879a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 28979a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 29079a732c7Sopenharmony_ci} 29179a732c7Sopenharmony_ci 29279a732c7Sopenharmony_ci/** 29379a732c7Sopenharmony_ci * @tc.name: AuthRequestNegotiateState::Enter_004 29479a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 29579a732c7Sopenharmony_ci * 2 call AuthRequestNegotiateState::Enter with authManager != null 29679a732c7Sopenharmony_ci * 3 check ret is DM_OK 29779a732c7Sopenharmony_ci * @tc.type: FUNC 29879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 29979a732c7Sopenharmony_ci */ 30079a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) 30179a732c7Sopenharmony_ci{ 30279a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 30379a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 30479a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateState>(); 30579a732c7Sopenharmony_ci authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager); 30679a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 30779a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 30879a732c7Sopenharmony_ci authManager->authRequestState_ = std::make_shared<AuthRequestNegotiateState>(); 30979a732c7Sopenharmony_ci authManager->authRequestContext_->deviceId = "111"; 31079a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); 31179a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); 31279a732c7Sopenharmony_ci authManager->timer_ = std::make_shared<DmTimer>(); 31379a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 31479a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 31579a732c7Sopenharmony_ci context->deviceId = "123456"; 31679a732c7Sopenharmony_ci context->sessionId = 22222; 31779a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 31879a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 31979a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 32079a732c7Sopenharmony_ci} 32179a732c7Sopenharmony_ci 32279a732c7Sopenharmony_ci/** 32379a732c7Sopenharmony_ci * @tc.name: AuthRequestNegotiateDoneState::GetStateType_003 32479a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestNegotiateDoneState::GetStateType 32579a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_REQUEST_NEGOTIATE_DONE 32679a732c7Sopenharmony_ci * @tc.type: FUNC 32779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 32879a732c7Sopenharmony_ci */ 32979a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_003, testing::ext::TestSize.Level0) 33079a732c7Sopenharmony_ci{ 33179a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateDoneState>(); 33279a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 33379a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE_DONE); 33479a732c7Sopenharmony_ci} 33579a732c7Sopenharmony_ci 33679a732c7Sopenharmony_ci/** 33779a732c7Sopenharmony_ci * @tc.name: AuthRequestNegotiateDoneState::Enter_005 33879a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 33979a732c7Sopenharmony_ci * 2 call AuthRequestNegotiateDoneState::Enter with authManager = null 34079a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 34179a732c7Sopenharmony_ci * @tc.type: FUNC 34279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 34379a732c7Sopenharmony_ci */ 34479a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_005, testing::ext::TestSize.Level0) 34579a732c7Sopenharmony_ci{ 34679a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 34779a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 34879a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateDoneState>(); 34979a732c7Sopenharmony_ci authRequestState->SetAuthManager(nullptr); 35079a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 35179a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 35279a732c7Sopenharmony_ci} 35379a732c7Sopenharmony_ci 35479a732c7Sopenharmony_ci/** 35579a732c7Sopenharmony_ci * @tc.name: AuthRequestNegotiateDoneState::Enter_006 35679a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 35779a732c7Sopenharmony_ci * 2 call AuthRequestNegotiateDoneState::Enter with authManager != null 35879a732c7Sopenharmony_ci * 3 check ret is DM_OK 35979a732c7Sopenharmony_ci * @tc.type: FUNC 36079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 36179a732c7Sopenharmony_ci */ 36279a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) 36379a732c7Sopenharmony_ci{ 36479a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 36579a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 36679a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNegotiateDoneState>(); 36779a732c7Sopenharmony_ci authManager->timer_ = std::make_shared<DmTimer>(); 36879a732c7Sopenharmony_ci authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager); 36979a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 37079a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 37179a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); 37279a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); 37379a732c7Sopenharmony_ci authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); 37479a732c7Sopenharmony_ci authManager->SetAuthRequestState(authRequestState); 37579a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 37679a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 37779a732c7Sopenharmony_ci context->sessionId = 333333; 37879a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 37979a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 38079a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 38179a732c7Sopenharmony_ci} 38279a732c7Sopenharmony_ci 38379a732c7Sopenharmony_ci/** 38479a732c7Sopenharmony_ci * @tc.name: AuthRequestReplyState::GetStateType_004 38579a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestReplyState::GetStateType 38679a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_REQUEST_REPLY 38779a732c7Sopenharmony_ci * @tc.type: FUNC 38879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 38979a732c7Sopenharmony_ci */ 39079a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_004, testing::ext::TestSize.Level0) 39179a732c7Sopenharmony_ci{ 39279a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestReplyState>(); 39379a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 39479a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_REPLY); 39579a732c7Sopenharmony_ci} 39679a732c7Sopenharmony_ci 39779a732c7Sopenharmony_ci/** 39879a732c7Sopenharmony_ci * @tc.name: AuthRequestReplyState::Enter_007 39979a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 40079a732c7Sopenharmony_ci * 2 call AuthRequestReplyState::Enter with authManager = null 40179a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 40279a732c7Sopenharmony_ci * @tc.type: FUNC 40379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 40479a732c7Sopenharmony_ci */ 40579a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_007, testing::ext::TestSize.Level0) 40679a732c7Sopenharmony_ci{ 40779a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 40879a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 40979a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestReplyState>(); 41079a732c7Sopenharmony_ci authRequestState->SetAuthManager(nullptr); 41179a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 41279a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 41379a732c7Sopenharmony_ci} 41479a732c7Sopenharmony_ci 41579a732c7Sopenharmony_ci/** 41679a732c7Sopenharmony_ci * @tc.name: AuthRequestReplyState::Enter_008 41779a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 41879a732c7Sopenharmony_ci * 2 call AuthRequestReplyState::Enter with authManager != null 41979a732c7Sopenharmony_ci * 3 check ret is DM_OK 42079a732c7Sopenharmony_ci * @tc.type: FUNC 42179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 42279a732c7Sopenharmony_ci */ 42379a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) 42479a732c7Sopenharmony_ci{ 42579a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 42679a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 42779a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestReplyState>(); 42879a732c7Sopenharmony_ci authManager->timer_ = std::make_shared<DmTimer>(); 42979a732c7Sopenharmony_ci authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager); 43079a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 43179a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 43279a732c7Sopenharmony_ci authManager->authRequestState_ = std::make_shared<AuthRequestReplyState>(); 43379a732c7Sopenharmony_ci authManager->authResponseContext_->sessionId = 1; 43479a732c7Sopenharmony_ci authManager->authPtr_ = authManager->authenticationMap_[1]; 43579a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); 43679a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); 43779a732c7Sopenharmony_ci authManager->SetAuthRequestState(authRequestState); 43879a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 43979a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 44079a732c7Sopenharmony_ci context->sessionId = 333333; 44179a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 44279a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 44379a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 44479a732c7Sopenharmony_ci} 44579a732c7Sopenharmony_ci 44679a732c7Sopenharmony_ci/** 44779a732c7Sopenharmony_ci * @tc.name: AuthRequestJoinState::GetStateType_006 44879a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestJoinState::GetStateType 44979a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_REQUEST_JOIN 45079a732c7Sopenharmony_ci * @tc.type: FUNC 45179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 45279a732c7Sopenharmony_ci */ 45379a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_006, testing::ext::TestSize.Level0) 45479a732c7Sopenharmony_ci{ 45579a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestJoinState>(); 45679a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 45779a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_JOIN); 45879a732c7Sopenharmony_ci} 45979a732c7Sopenharmony_ci 46079a732c7Sopenharmony_ci/** 46179a732c7Sopenharmony_ci * @tc.name: AuthRequestJoinState::Enter_011 46279a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 46379a732c7Sopenharmony_ci * 2 call AuthRequestJoinState::Enter with authManager = null 46479a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 46579a732c7Sopenharmony_ci * @tc.type: FUNC 46679a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 46779a732c7Sopenharmony_ci */ 46879a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0) 46979a732c7Sopenharmony_ci{ 47079a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 47179a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 47279a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestJoinState>(); 47379a732c7Sopenharmony_ci authRequestState->SetAuthManager(nullptr); 47479a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 47579a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 47679a732c7Sopenharmony_ci} 47779a732c7Sopenharmony_ci 47879a732c7Sopenharmony_ci/** 47979a732c7Sopenharmony_ci * @tc.name: AuthRequestJoinState::Enter_012 48079a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 48179a732c7Sopenharmony_ci * 2 call AuthRequestJoinState::Enter with authManager != null 48279a732c7Sopenharmony_ci * 3 check ret is DM_OK 48379a732c7Sopenharmony_ci * @tc.type: FUNC 48479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 48579a732c7Sopenharmony_ci */ 48679a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) 48779a732c7Sopenharmony_ci{ 48879a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 48979a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 49079a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestJoinState>(); 49179a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 49279a732c7Sopenharmony_ci authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager); 49379a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 49479a732c7Sopenharmony_ci authManager->authPtr_ = authManager->authenticationMap_[1]; 49579a732c7Sopenharmony_ci authManager->authResponseContext_->groupId = "111"; 49679a732c7Sopenharmony_ci authManager->authResponseContext_->groupName = "222"; 49779a732c7Sopenharmony_ci authManager->authResponseContext_->code = 123; 49879a732c7Sopenharmony_ci authManager->authResponseContext_->requestId = 234; 49979a732c7Sopenharmony_ci authManager->authResponseContext_->deviceId = "234"; 50079a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 50179a732c7Sopenharmony_ci authManager->timer_ = std::make_shared<DmTimer>(); 50279a732c7Sopenharmony_ci authManager->SetAuthRequestState(authRequestState); 50379a732c7Sopenharmony_ci authManager->hiChainConnector_->RegisterHiChainCallback(authManager); 50479a732c7Sopenharmony_ci authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); 50579a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 50679a732c7Sopenharmony_ci context->deviceId = "44444"; 50779a732c7Sopenharmony_ci context->sessionId = 55555; 50879a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 50979a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 51079a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 51179a732c7Sopenharmony_ci} 51279a732c7Sopenharmony_ci 51379a732c7Sopenharmony_ci/** 51479a732c7Sopenharmony_ci * @tc.name: AuthRequestNetworkState::GetStateType_007 51579a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestNetworkState::GetStateType 51679a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_REQUEST_NETWORK 51779a732c7Sopenharmony_ci * @tc.type: FUNC 51879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 51979a732c7Sopenharmony_ci */ 52079a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_007, testing::ext::TestSize.Level0) 52179a732c7Sopenharmony_ci{ 52279a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNetworkState>(); 52379a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 52479a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NETWORK); 52579a732c7Sopenharmony_ci} 52679a732c7Sopenharmony_ci 52779a732c7Sopenharmony_ci/** 52879a732c7Sopenharmony_ci * @tc.name: AuthRequestNetworkState::Enter_013 52979a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 53079a732c7Sopenharmony_ci * 2 call AuthRequestNetworkState::Enter with authManager = null 53179a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 53279a732c7Sopenharmony_ci * @tc.type: FUNC 53379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 53479a732c7Sopenharmony_ci */ 53579a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0) 53679a732c7Sopenharmony_ci{ 53779a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 53879a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 53979a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNetworkState>(); 54079a732c7Sopenharmony_ci authRequestState->SetAuthManager(nullptr); 54179a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 54279a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 54379a732c7Sopenharmony_ci} 54479a732c7Sopenharmony_ci 54579a732c7Sopenharmony_ci/** 54679a732c7Sopenharmony_ci * @tc.name: AuthRequestNetworkState::Enter_014 54779a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 54879a732c7Sopenharmony_ci * 2 call AuthRequestNetworkState::Enter with authManager != null 54979a732c7Sopenharmony_ci * 3 check ret is DM_OK 55079a732c7Sopenharmony_ci * @tc.type: FUNC 55179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 55279a732c7Sopenharmony_ci */ 55379a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) 55479a732c7Sopenharmony_ci{ 55579a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 55679a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 55779a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNetworkState>(); 55879a732c7Sopenharmony_ci authManager->timer_ = std::make_shared<DmTimer>(); 55979a732c7Sopenharmony_ci authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager); 56079a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 56179a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 56279a732c7Sopenharmony_ci authManager->authRequestState_ = std::make_shared<AuthRequestNetworkState>(); 56379a732c7Sopenharmony_ci authManager->authPtr_ = authManager->authenticationMap_[1]; 56479a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); 56579a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); 56679a732c7Sopenharmony_ci authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); 56779a732c7Sopenharmony_ci authManager->SetAuthRequestState(authRequestState); 56879a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 56979a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 57079a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 57179a732c7Sopenharmony_ci} 57279a732c7Sopenharmony_ci 57379a732c7Sopenharmony_ci/** 57479a732c7Sopenharmony_ci * @tc.name: AuthRequestFinishState::GetStateType_008 57579a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestFinishState::GetStateType 57679a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_REQUEST_FINISH 57779a732c7Sopenharmony_ci * @tc.type: FUNC 57879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 57979a732c7Sopenharmony_ci */ 58079a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_008, testing::ext::TestSize.Level0) 58179a732c7Sopenharmony_ci{ 58279a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>(); 58379a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 58479a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_FINISH); 58579a732c7Sopenharmony_ci} 58679a732c7Sopenharmony_ci 58779a732c7Sopenharmony_ci/** 58879a732c7Sopenharmony_ci * @tc.name: AuthRequestFinishState::Enter_015 58979a732c7Sopenharmony_ci * @tc.desc: 1 set authManager to null 59079a732c7Sopenharmony_ci * 2 call AuthRequestFinishState::Enter with authManager = null 59179a732c7Sopenharmony_ci * 3 check ret is ERR_DM_FAILED 59279a732c7Sopenharmony_ci * @tc.type: FUNC 59379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 59479a732c7Sopenharmony_ci */ 59579a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_015, testing::ext::TestSize.Level0) 59679a732c7Sopenharmony_ci{ 59779a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 59879a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 59979a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>(); 60079a732c7Sopenharmony_ci authRequestState->SetAuthManager(nullptr); 60179a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 60279a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 60379a732c7Sopenharmony_ci} 60479a732c7Sopenharmony_ci 60579a732c7Sopenharmony_ci/** 60679a732c7Sopenharmony_ci * @tc.name: AuthRequestFinishState::Enter_016 60779a732c7Sopenharmony_ci * @tc.desc: 1 set authManager not null 60879a732c7Sopenharmony_ci * 2 call AuthRequestNetworkState::Enter with authManager != null 60979a732c7Sopenharmony_ci * 3 check ret is DM_OK 61079a732c7Sopenharmony_ci * @tc.type: FUNC 61179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 61279a732c7Sopenharmony_ci */ 61379a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) 61479a732c7Sopenharmony_ci{ 61579a732c7Sopenharmony_ci std::shared_ptr<DmAuthManager> authManager = 61679a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 61779a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>(); 61879a732c7Sopenharmony_ci authManager->timer_ = std::make_shared<DmTimer>(); 61979a732c7Sopenharmony_ci authManager->authPtr_ = authManager->authenticationMap_[1]; 62079a732c7Sopenharmony_ci authManager->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager); 62179a732c7Sopenharmony_ci authManager->authResponseContext_ = std::make_shared<DmAuthResponseContext>(); 62279a732c7Sopenharmony_ci authManager->authRequestContext_ = std::make_shared<DmAuthRequestContext>(); 62379a732c7Sopenharmony_ci authManager->authResponseState_ = std::make_shared<AuthResponseFinishState>(); 62479a732c7Sopenharmony_ci authManager->authRequestState_ = std::make_shared<AuthRequestFinishState>(); 62579a732c7Sopenharmony_ci authManager->authResponseContext_->sessionId = 1; 62679a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); 62779a732c7Sopenharmony_ci authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); 62879a732c7Sopenharmony_ci authManager->SetAuthRequestState(authRequestState); 62979a732c7Sopenharmony_ci authRequestState->SetAuthManager(authManager); 63079a732c7Sopenharmony_ci std::shared_ptr<DmAuthRequestContext> context = std::make_shared<DmAuthRequestContext>(); 63179a732c7Sopenharmony_ci context->sessionId = 333333; 63279a732c7Sopenharmony_ci authRequestState->SetAuthContext(context); 63379a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 63479a732c7Sopenharmony_ci ASSERT_EQ(ret, DM_OK); 63579a732c7Sopenharmony_ci} 63679a732c7Sopenharmony_ci 63779a732c7Sopenharmony_ci/** 63879a732c7Sopenharmony_ci * @tc.name: AuthRequestCredential::GetStateType_005 63979a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestCredential::GetStateType 64079a732c7Sopenharmony_ci * 2 check ret is AuthState::AUTH_REQUEST_CREDENTIAL 64179a732c7Sopenharmony_ci * @tc.type: FUNC 64279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 64379a732c7Sopenharmony_ci */ 64479a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) 64579a732c7Sopenharmony_ci{ 64679a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestCredential>(); 64779a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 64879a732c7Sopenharmony_ci ASSERT_EQ(ret, AuthState::AUTH_REQUEST_CREDENTIAL); 64979a732c7Sopenharmony_ci} 65079a732c7Sopenharmony_ci 65179a732c7Sopenharmony_ci/** 65279a732c7Sopenharmony_ci * @tc.name: AuthRequestCredential::Enter_009 65379a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestCredential::Enter 65479a732c7Sopenharmony_ci * 2 check ret is ERR_DM_FAILED 65579a732c7Sopenharmony_ci * @tc.type: FUNC 65679a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 65779a732c7Sopenharmony_ci */ 65879a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) 65979a732c7Sopenharmony_ci{ 66079a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestCredential>(); 66179a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 66279a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 66379a732c7Sopenharmony_ci} 66479a732c7Sopenharmony_ci 66579a732c7Sopenharmony_ci/** 66679a732c7Sopenharmony_ci * @tc.name: AuthRequestCredentialDone::GetStateType_009 66779a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestCredentialDone::GetStateType 66879a732c7Sopenharmony_ci * 2 check ret is AUTH_REQUEST_CREDENTIAL_DONE 66979a732c7Sopenharmony_ci * @tc.type: FUNC 67079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 67179a732c7Sopenharmony_ci */ 67279a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, GetStateType_009, testing::ext::TestSize.Level0) 67379a732c7Sopenharmony_ci{ 67479a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestCredentialDone>(); 67579a732c7Sopenharmony_ci int32_t ret = authRequestState->GetStateType(); 67679a732c7Sopenharmony_ci ASSERT_EQ(ret, AUTH_REQUEST_CREDENTIAL_DONE); 67779a732c7Sopenharmony_ci} 67879a732c7Sopenharmony_ci 67979a732c7Sopenharmony_ci/** 68079a732c7Sopenharmony_ci * @tc.name: AuthRequestCredentialDone::Enter_010 68179a732c7Sopenharmony_ci * @tc.desc: 1 call AuthRequestCredentialDone::Enter 68279a732c7Sopenharmony_ci * 2 check ret is ERR_DM_FAILED 68379a732c7Sopenharmony_ci * @tc.type: FUNC 68479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 68579a732c7Sopenharmony_ci */ 68679a732c7Sopenharmony_ciHWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0) 68779a732c7Sopenharmony_ci{ 68879a732c7Sopenharmony_ci std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestCredentialDone>(); 68979a732c7Sopenharmony_ci int32_t ret = authRequestState->Enter(); 69079a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 69179a732c7Sopenharmony_ci} 69279a732c7Sopenharmony_ci} // namespace 69379a732c7Sopenharmony_ci} // namespace DistributedHardware 69479a732c7Sopenharmony_ci} // namespace OHOS 695