diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index 70f3bf7e2f9aeed6f20994feecbdbddb342bc7e6..f8e29894a29f61d629835121e94da85ad9a86cd7 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -43,11 +43,77 @@ std::string NEGOTIATE_TIMEOUT_TASK = "negotiateTimeoutTask"; std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; +std::string WAIT_NEGOTIATE_TIMEOUT_TASK = "waitNegotiateTimeoutTask"; +std::string WAIT_REQUEST_TIMEOUT_TASK = "waitRequestTimeoutTask"; std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr hiChainConnector_ = std::make_shared(); +/** + * @tc.name: DmAuthManager::AuthenticateDevice_001 + * @tc.desc: Whether the return value of calling AuthenticateDevice is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateDevice_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = nullptr; + authManager->authResponseState_ = std::make_shared(); + std::string pkgName = "pkgName"; + int32_t authType = 1; + std::string deviceId = "222"; + softbusConnector->discoveryDeviceInfoMap_[deviceId] = std::make_shared(); + std::string extra = "333"; + int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::AuthenticateDevice_002 + * @tc.desc: authRequestState_ != nullptr || authResponseState_ != nullptr; + * Whether the return value of calling AuthenticateDevice is DM_AUTH_BUSINESS_BUSY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateDevice_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); + std::string pkgName = "pkgName"; + int32_t authType = 1; + std::string deviceId = "222"; + softbusConnector->discoveryDeviceInfoMap_[deviceId] = std::make_shared(); + std::string extra = "333"; + int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); + ASSERT_EQ(ret, DM_AUTH_BUSINESS_BUSY); +} + +/** + * @tc.name: DmAuthManager::AuthenticateDevice_003 + * @tc.desc: extra.empty(); Whether the return value of calling AuthenticateDevice is DM_AUTH_BUSINESS_BUSY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateDevice_003, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = nullptr; + authManager->authResponseState_ = std::make_shared(); + std::string pkgName = "pkgName"; + int32_t authType = 1; + std::string deviceId = "222"; + softbusConnector->discoveryDeviceInfoMap_[deviceId] = std::make_shared(); + std::string extra = ""; + int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); + ASSERT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + /** * @tc.name: DmAuthManager::UnAuthenticateDevice_001 * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_ FAILED @@ -66,6 +132,231 @@ HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Lev ASSERT_EQ(ret, DM_FAILED); } +/** + * @tc.name: DmAuthManager::VerifyAuthentication_001 + * @tc.desc: Whether the return value of calling VerifyAuthentication is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, VerifyAuthentication_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + std::shared_ptr inputStartTimer = std::make_shared(INPUT_TIMEOUT_TASK); + authManager->timerMap_[INPUT_TIMEOUT_TASK] = inputStartTimer; + authManager->authResponseContext_->authType = 1; + std::string authParam = "{\"pinCode\":\"1\"}"; + int32_t ret = authManager->VerifyAuthentication(authParam); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::VerifyAuthentication_002 + * @tc.desc: authResponseContext_ == nullptr; Whether the return value of calling VerifyAuthentication is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, VerifyAuthentication_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = nullptr; + std::string authParam = "{\"pinCode\":\"1\"}"; + int32_t ret = authManager->VerifyAuthentication(authParam); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::OnSessionOpened_001 + * @tc.desc: sessionSide = AUTH_SESSION_SIDE_SERVER; Call OnSessionOpened to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnSessionOpened_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t sessionId = 111; + int32_t sessionSide = AUTH_SESSION_SIDE_SERVER; + int32_t result = 222; + authManager->authResponseState_ = nullptr; + authManager->authRequestState_ = nullptr; + authManager->timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] = nullptr; + authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = nullptr; + authManager->OnSessionOpened(sessionId, sessionSide, result); + ASSERT_TRUE(authManager->timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] != nullptr); + ASSERT_TRUE(authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] != nullptr); +} + +/** + * @tc.name: DmAuthManager::OnSessionOpened_002 + * @tc.desc: sessionSide = AUTH_SESSION_SIDE_CLIENT; Call OnSessionOpened to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnSessionOpened_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t sessionId = 111; + int32_t sessionSide = AUTH_SESSION_SIDE_CLIENT; + int32_t result = 222; + authManager->authResponseState_ = nullptr; + authManager->authRequestState_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + authManager->authRequestContext_->sessionId = 0; + authManager->OnSessionOpened(sessionId, sessionSide, result); + ASSERT_EQ(sessionId, authManager->authRequestContext_->sessionId); +} + +/** + * @tc.name: DmAuthManager::OnSessionClosed_001 + * @tc.desc: Call OnSessionClosed to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnSessionClosed_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t sessionId = 111; + authManager->OnSessionClosed(sessionId); +} + +/** + * @tc.name: DmAuthManager::OnDataReceived_001 + * @tc.desc: authRequestState_ == nullptr && authResponseState_ == nullptr; + * @Call OnDataReceived to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnDataReceived_001, testing::ext::TestSize.Level0) +{ std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); + authManager->authMessageProcessor_ = std::make_shared(authManager); + authManager->authResponseContext_->msgType = MSG_TYPE_REQ_AUTH_TERMINATE; + int32_t sessionId = 111; + std::string message = "{\"groupId\":\"1\"}"; + authManager->isFinishOfLocal_ = true; + authManager->OnDataReceived(sessionId, message); + ASSERT_EQ(false, authManager->isFinishOfLocal_); +} + +/** + * @tc.name: DmAuthManager::OnDataReceived_002 + * @tc.desc: authResponseContext_->msgType = MSG_TYPE_REQ_AUTH_TERMINATE; + * @Call OnDataReceived to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnDataReceived_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = nullptr; + authManager->authResponseState_ = nullptr; + authManager->authResponseContext_ = std::make_shared(); + int32_t sessionId = 111; + std::string message = "{\"groupId\":\"1\"}"; + authManager->authResponseContext_->sessionId = 0; + authManager->OnDataReceived(sessionId, message); + ASSERT_NE(sessionId, authManager->authResponseContext_->sessionId); +} + +/** + * @tc.name: DmAuthManager::OnGroupCreated_001 + * @tc.desc: groupId = "{\"id\":\"1\"}"; Call OnGroupCreated to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnGroupCreated_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); + authManager->authMessageProcessor_ = std::make_shared(authManager); + int64_t requestId = 111; + std::string groupId = "{\"groupId\":\"1\"}"; + authManager->authResponseContext_->groupId = "{}"; + authManager->OnGroupCreated(requestId, groupId); + ASSERT_STREQ(groupId.c_str(), authManager->authResponseContext_->groupId.c_str()); +} + +/** + * @tc.name: DmAuthManager::OnGroupCreated_002 + * @tc.desc: groupId == "{}"; Call OnGroupCreated to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnGroupCreated_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); + authManager->authMessageProcessor_ = std::make_shared(authManager); + int64_t requestId = 111; + std::string groupId = "{}"; + authManager->authResponseContext_->reply = DM_HICHAIN_FAILED; + authManager->OnGroupCreated(requestId, groupId); + ASSERT_EQ(DM_HICHAIN_GROUP_CREATE_FAILED, authManager->authResponseContext_->reply); +} + +/** + * @tc.name: DmAuthManager::OnMemberJoin_001 + * @tc.desc: status = DM_TIME_OUT; Call OnMemberJoin to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnMemberJoin_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); + authManager->timerMap_[ADD_TIMEOUT_TASK] = joinStartTimer; + int64_t requestId = 111; + int32_t status = DM_TIME_OUT; + authManager->authResponseContext_->requestId = 222; + authManager->authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; + authManager->authRequestContext_->reason = DM_OK; + authManager->OnMemberJoin(requestId, status); + ASSERT_EQ(AuthState::AUTH_REQUEST_JOIN, authManager->authResponseContext_->state); + ASSERT_EQ(DM_AUTH_INPUT_FAILED, authManager->authRequestContext_->reason); +} + +/** + * @tc.name: DmAuthManager::OnMemberJoin_002 + * @tc.desc: status = DM_OK; Call OnMemberJoin to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnMemberJoin_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); + authManager->timerMap_[ADD_TIMEOUT_TASK] = joinStartTimer; + int64_t requestId = 111; + int32_t status = DM_OK; + authManager->authResponseContext_->requestId = requestId; + authManager->authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; + authManager->authRequestContext_->reason = DM_OK; + authManager->OnMemberJoin(requestId, status); + ASSERT_EQ(AuthState::AUTH_REQUEST_INIT, authManager->authResponseContext_->state); + ASSERT_EQ(DM_OK, authManager->authRequestContext_->reason); +} + /** * @tc.name: DmAuthManager::HandleAuthenticateTimeout_001 * @tc.desc: authResponseContext_= nullptr; Call handleauthenticatemeout to check whether the return value is DM_FAILED @@ -125,6 +416,85 @@ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Lev ASSERT_EQ(ret, DM_OK); } +/** + * @tc.name: DmAuthManager::StartNegotiate_001 + * @tc.desc: Call StartNegotiate to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, StartNegotiate_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + authManager->authMessageProcessor_ = std::make_shared(authManager); + authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = nullptr; + int32_t sessionId = 111; + authManager->StartNegotiate(sessionId); + std::shared_ptr negotiateStartTimer = authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK]; + ASSERT_TRUE(negotiateStartTimer != nullptr); +} + +/** + * @tc.name: DmAuthManager::RespNegotiate_001 + * @tc.desc: Call RespNegotiate to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, RespNegotiate_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); + authManager->timerMap_[WAIT_REQUEST_TIMEOUT_TASK] = nullptr; + int32_t sessionId = 111; + authManager->RespNegotiate(sessionId); + std::shared_ptr waitStartTimer = authManager->timerMap_[WAIT_REQUEST_TIMEOUT_TASK]; + ASSERT_TRUE(waitStartTimer != nullptr); +} + +/** + * @tc.name: DmAuthManager::SendAuthRequest_001 + * @tc.desc: Call SendAuthRequest to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SendAuthRequest_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr negotiateStartTimer = std::make_shared(CONFIRM_TIMEOUT_TASK); + authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = negotiateStartTimer; + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); + authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = nullptr; + int32_t sessionId = 111; + authManager->SendAuthRequest(sessionId); + std::shared_ptr confirmStartTimer = authManager->timerMap_[CONFIRM_TIMEOUT_TASK]; + ASSERT_TRUE(confirmStartTimer != nullptr); +} + +/** + * @tc.name: DmAuthManager::SendAuthRequest_002 + * @tc.desc: timerMap_[NEGOTIATE_TIMEOUT_TASK] = nullptr; Call SendAuthRequest to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SendAuthRequest_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = nullptr; + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); + authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = nullptr; + int32_t sessionId = 111; + authManager->SendAuthRequest(sessionId); + std::shared_ptr confirmStartTimer = authManager->timerMap_[CONFIRM_TIMEOUT_TASK]; + ASSERT_TRUE(confirmStartTimer == nullptr); +} + /** * @tc.name: DmAuthManager::StartAuthProcess_001 * @tc.desc: Whether the return value of calling startauthprocess is DM_FAILED @@ -169,6 +539,29 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } +/** + * @tc.name: DmAuthManager::StartRespAuthProcess_001 + * @tc.desc: Call StartRespAuthProcess to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, StartRespAuthProcess_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr confirmStartTimer = std::make_shared(CONFIRM_TIMEOUT_TASK); + authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = confirmStartTimer; + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseContext_->reply = USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT; + authManager->authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; + authManager->authRequestContext_->reason = DM_AUTH_NOT_AUTH; + authManager->StartRespAuthProcess(); + ASSERT_EQ(AuthState::AUTH_REQUEST_REPLY, authManager->authResponseContext_->state); + ASSERT_EQ(DM_AUTH_PEER_REJECT, authManager->authRequestContext_->reason); +} + /** * @tc.name: DmAuthManager::CreateGroup_001 * @tc.desc: Whether the return value of calling creategroup is DM_ OK @@ -220,6 +613,21 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_FAILED); } +/** + * @tc.name: DmAuthManager::GetConnectAddr_001 + * @tc.desc: Whether the return value of calling GetConnectAddr is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetConnectAddr_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::string deviceId = "123"; + std::string ret = authManager->GetConnectAddr(deviceId); + ASSERT_STRNE(ret.c_str(), ""); +} + /** * @tc.name: DmAuthManager::JoinNetwork_001 * @tc.desc: Whether the return value of calling joinnetwork is DM_ OK @@ -242,6 +650,133 @@ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } +/** + * @tc.name: DmAuthManager::AuthenticateFinish_001 + * @tc.desc: authResponseState_ != nullptr; Call AuthenticateFinish to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateFinish_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseState_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + authManager->authMessageProcessor_ = std::make_shared(authManager); + authManager->isFinishOfLocal_ = false; + authManager->AuthenticateFinish(); + ASSERT_TRUE(nullptr != authManager->authRequestContext_); +} + +/** + * @tc.name: DmAuthManager::AuthenticateFinish_002 + * @tc.desc: authResponseState_ == nullptr; Call AuthenticateFinish to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateFinish_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseState_ = nullptr; + authManager->authRequestContext_ = std::make_shared(); + authManager->authMessageProcessor_ = std::make_shared(authManager); + authManager->isFinishOfLocal_ = false; + authManager->AuthenticateFinish(); + ASSERT_TRUE(nullptr == authManager->authRequestContext_); +} + +/** + * @tc.name: DmAuthManager::CancelDisplay_001 + * @tc.desc: Call CancelDisplay to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, CancelDisplay_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->CancelDisplay(); +} + +/** + * @tc.name: DmAuthManager::GeneratePincode_001 + * @tc.desc: Whether the return value of calling GeneratePincode is between MIN_PIN_CODE and MAX_PIN_CODE + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GeneratePincode_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t ret = authManager->GeneratePincode(); + ASSERT_LE(ret, MAX_PIN_CODE); + ASSERT_GT(ret, MIN_PIN_CODE); +} + +/** + * @tc.name: DmAuthManager::GenerateGroupName_001 + * @tc.desc: Whether the return value of calling GenerateGroupName is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GenerateGroupName_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + std::string ret = authManager->GenerateGroupName(); + ASSERT_STRNE(ret.c_str(), ""); +} + +/** + * @tc.name: DmAuthManager::GetIsCryptoSupport_001 + * @tc.desc: Whether the return value of calling GetIsCryptoSupport is true + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr authResponseState = std::make_shared(); + authManager->SetAuthResponseState(authResponseState); + std::shared_ptr authRequestState = std::make_shared(); + authManager->SetAuthRequestState(authRequestState); + bool ret = authManager->GetIsCryptoSupport(); + ASSERT_EQ(ret, true); +} + +/** + * @tc.name: DmAuthManager::GetIsCryptoSupport_002 + * @tc.desc: Whether the return value of calling GetIsCryptoSupport is false + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->SetAuthResponseState(nullptr); + bool ret = authManager->GetIsCryptoSupport(); + ASSERT_EQ(ret, false); +} + +/** + * @tc.name: DmAuthManager::SetAuthRequestState_001 + * @tc.desc: Whether the return value of calling SetAuthRequestState is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetAuthRequestState_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr authRequestState = std::make_shared(); + int32_t ret = authManager->SetAuthRequestState(authRequestState); + ASSERT_EQ(ret, DM_OK); +} + /** * @tc.name: DmAuthManager::SetAuthResponseState_001 * @tc.desc: Is the authresponsestate assignment successful @@ -273,6 +808,190 @@ HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) int32_t ret = authManager->GetPinCode(); ASSERT_EQ(ret, DM_FAILED); } + +/** + * @tc.name: DmAuthManager::ShowConfigDialog_001 + * @tc.desc: Call ShowConfigDialog to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, ShowConfigDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->ShowConfigDialog(); +} + +/** + * @tc.name: DmAuthManager::ShowAuthInfoDialog_001 + * @tc.desc: Call ShowAuthInfoDialog to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, ShowAuthInfoDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->ShowAuthInfoDialog(); +} + +/** + * @tc.name: DmAuthManager::ShowStartAuthDialog_001 + * @tc.desc: Call ShowStartAuthDialog to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, ShowStartAuthDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->ShowStartAuthDialog(); +} + +/** + * @tc.name: DmAuthManager::GetAuthenticationParam_001 + * @tc.desc: Whether the return value of calling GetAuthenticationParam is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetAuthenticationParam_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + authManager->dmAbilityMgr_ = std::make_shared(); + DmAuthParam authParam = {0}; + int32_t ret = authManager->GetAuthenticationParam(authParam); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::GetAuthenticationParam_002 + * @tc.desc: Whether the return value of calling GetAuthenticationParam is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetAuthenticationParam_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + DmAuthParam authParam = {0}; + int32_t ret = authManager->GetAuthenticationParam(authParam); + ASSERT_EQ(ret, DM_POINT_NULL); +} + +/** + * @tc.name: DmAuthManager::GetAuthenticationParam_003 + * @tc.desc: Whether the return value of calling GetAuthenticationParam is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetAuthenticationParam_003, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->dmAbilityMgr_ = std::make_shared(); + DmAuthParam authParam = {0}; + int32_t ret = authManager->GetAuthenticationParam(authParam); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::OnUserOperation_001 + * @tc.desc: Whether the return value of calling OnUserOperation is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnUserOperation_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + int32_t action = FaAction::USER_OPERATION_TYPE_ALLOW_AUTH; + int32_t ret = authManager->OnUserOperation(action); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::OnUserOperation_002 + * @tc.desc: Whether the return value of calling OnUserOperation is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnUserOperation_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t action = FaAction::USER_OPERATION_TYPE_ALLOW_AUTH; + int32_t ret = authManager->OnUserOperation(action); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::UserSwitchEventCallback_001 + * @tc.desc: Call UserSwitchEventCallback to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, UserSwitchEventCallback_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t userId = 1; + authManager->UserSwitchEventCallback(userId); +} + +/** + * @tc.name: DmAuthManager::SetPageId_001 + * @tc.desc: Call SetPageId to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetPageId_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + int32_t pageId = 1; + int32_t ret = authManager->SetPageId(pageId); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::SetReason_001 + * @tc.desc: reason = AuthState::AUTH_REQUEST_INIT; + * @Call SetReason to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetReason_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + int32_t reason = AuthState::AUTH_REQUEST_INIT; + int32_t state = 222; + int32_t ret = authManager->SetReason(reason, state); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::SetReason_002 + * @tc.desc: reason = AuthState::AUTH_REQUEST_FINISH; + * @Call SetReason to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetReason_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t reason = AuthState::AUTH_REQUEST_FINISH; + int32_t state = 222; + authManager->authResponseContext_ = std::make_shared(); + int32_t ret = authManager->SetReason(reason, state); + ASSERT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS