From 76e744072ab1151939cbbd221f47366755b30dc1 Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sat, 15 Jan 2022 15:17:27 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0TDD=E7=9A=84BUILD.gn?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20Signed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unittest/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 2bd26f5a2..9b12bd86e 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -13,7 +13,7 @@ import("//build/test.gni") import("//foundation/distributedhardware/devicemanager/devicemanager.gni") -module_out_path = "deviceManager_stander/inner_kits" +module_out_path = "device_manager_base/component_loader_test" group("unittest") { testonly = true -- Gitee From 902997f756c8c06d444865709f72c430ea07597f Mon Sep 17 00:00:00 2001 From: puhui Date: Sat, 15 Jan 2022 21:18:44 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: puhui --- .../include/authentication/dm_auth_manager.h | 10 +-- .../dependency/hichain/hichain_connector.h | 6 +- .../dependency/softbus/softbus_session.h | 6 +- .../softbus/softbus_session_callback.h | 9 ++- .../authentication/auth_message_processor.cpp | 4 +- .../src/authentication/dm_auth_manager.cpp | 62 +++++++++++-------- .../dependency/hichain/hichain_connector.cpp | 35 ++++------- .../dependency/softbus/softbus_session.cpp | 32 +++------- .../src/device_manager_service.cpp | 2 +- test/unittest/UTTest_hichain_connector.cpp | 11 +--- test/unittest/UTTest_softbus_session.cpp | 2 +- 11 files changed, 78 insertions(+), 101 deletions(-) diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 732d208f5..1295ebb88 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -128,9 +128,9 @@ public: const std::string &extra); int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId); int32_t VerifyAuthentication(const std::string &authParam); - void OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide, int32_t result); - void OnSessionClosed(const std::string &pkgName, int32_t sessionId); - void OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message); + void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result); + void OnSessionClosed(int32_t sessionId); + void OnDataReceived(int32_t sessionId, std::string message); void OnGroupCreated(int64_t requestId, const std::string &groupId); void OnMemberJoin(int64_t requestId, int32_t status); @@ -146,7 +146,7 @@ public: std::string GetConnectAddr(std::string deviceId); void JoinNetwork(); void AuthenticateFinish(); - void GetIsCryptoSupport(bool &isCryptoSupport); + bool GetIsCryptoSupport(); void SetAuthRequestState(std::shared_ptr authRequestState); void SetAuthResponseState(std::shared_ptr authResponseState); int32_t GetPinCode(); @@ -158,7 +158,7 @@ public: void ShowAuthInfoDialog(); void ShowStartAuthDialog(); int32_t GetAuthenticationParam(DmAuthParam &authParam); - int32_t RegisterSessionCallback(); + int32_t RegisterCallback(); int32_t OnUserOperation(int32_t action); private: diff --git a/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h index 20013a203..caffbffe9 100644 --- a/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h +++ b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h @@ -53,8 +53,8 @@ public: public: HiChainConnector(); ~HiChainConnector(); - int32_t RegisterHiChainCallback(const std::string &pkgName, std::shared_ptr callback); - int32_t UnRegisterHiChainCallback(const std::string &pkgName); + int32_t RegisterHiChainCallback(std::shared_ptr callback); + int32_t UnRegisterHiChainCallback(); int32_t CreateGroup(int64_t requestId, const std::string &groupName); int32_t AddMember(std::string deviceId, std::string &connectInfo); int32_t DelMemberFromGroup(std::string groupId, std::string deviceId); @@ -74,7 +74,7 @@ private: private: const DeviceGroupManager *deviceGroupManager_ = nullptr; DeviceAuthCallback deviceAuthCallback_; - static std::map> hiChainConnectorCallbackMap_; + static std::shared_ptr hiChainConnectorCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_session.h b/services/devicemanagerservice/include/dependency/softbus/softbus_session.h index e232b8e08..2eab337e6 100644 --- a/services/devicemanagerservice/include/dependency/softbus/softbus_session.h +++ b/services/devicemanagerservice/include/dependency/softbus/softbus_session.h @@ -37,15 +37,15 @@ public: public: SoftbusSession(); ~SoftbusSession(); - int32_t RegisterSessionCallback(const std::string &pkgName, std::shared_ptr callback); - int32_t UnRegisterSessionCallback(const std::string &pkgName); + int32_t RegisterSessionCallback(std::shared_ptr callback); + int32_t UnRegisterSessionCallback(); int32_t OpenAuthSession(const std::string &deviceId); int32_t CloseAuthSession(int32_t sessionId); int32_t SendData(int32_t sessionId, std::string &message); int32_t GetPeerDeviceId(int32_t sessionId, std::string &peerDevId); private: - static std::map> sessionCallbackMap_; + static std::shared_ptr sessionCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_session_callback.h b/services/devicemanagerservice/include/dependency/softbus/softbus_session_callback.h index 9569a3313..207928fd7 100644 --- a/services/devicemanagerservice/include/dependency/softbus/softbus_session_callback.h +++ b/services/devicemanagerservice/include/dependency/softbus/softbus_session_callback.h @@ -20,11 +20,10 @@ namespace OHOS { namespace DistributedHardware { class ISoftbusSessionCallback { public: - virtual void OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide, - int32_t result) = 0; - virtual void OnSessionClosed(const std::string &pkgName, int32_t sessionId) = 0; - virtual void OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message) = 0; - virtual void GetIsCryptoSupport(bool &isCryptoSupport) = 0; + virtual void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) = 0; + virtual void OnSessionClosed(int32_t sessionId) = 0; + virtual void OnDataReceived(int32_t sessionId, std::string message) = 0; + virtual bool GetIsCryptoSupport() = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 5a61ac78a..a373a9f2d 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -110,8 +110,9 @@ void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json) json[TAG_CRYPTO_SUPPORT] = true; json[TAG_CRYPTO_NAME] = cryptoAdapter_->GetName(); json[TAG_CRYPTO_VERSION] = cryptoAdapter_->GetVersion(); - json[TAG_DEVICE_ID] = authRequestContext_->deviceId; + json[TAG_DEVICE_ID] = authResponseContext_->deviceId; } + json[TAG_AUTH_TYPE] = authResponseContext_->authType; json[TAG_REPLY] = authResponseContext_->reply; json[TAG_LOCAL_DEVICE_ID] = authResponseContext_->localDeviceId; } @@ -261,6 +262,7 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) if (json.contains(TAG_DEVICE_ID)) { authResponseContext_->deviceId = json[TAG_DEVICE_ID]; } + authResponseContext_->authType = json[TAG_AUTH_TYPE]; authResponseContext_->localDeviceId = json[TAG_LOCAL_DEVICE_ID]; authResponseContext_->reply = json[TAG_REPLY]; } diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 051fd4911..f2c246b09 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -71,13 +71,22 @@ DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, DmAuthManager::~DmAuthManager() { + softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(); + hiChainConnector_->UnRegisterHiChainCallback(); LOGI("DmAuthManager destructor"); } int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - LOGE("DmAuthManager::AuthenticateDevice is"); + LOGE("DmAuthManager::AuthenticateDevice start"); + std::shared_ptr authentication = authenticationMap_[authType]; + if (authentication == nullptr) { + LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, + std::to_string(DM_AUTH_NOT_SUPPORT)); + return DM_AUTH_NOT_SUPPORT; + } if (authRequestState_ != nullptr && authResponseState_ != nullptr) { LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.", authRequestState_->GetAuthContext()->hostPkgName.c_str()); @@ -98,16 +107,9 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au std::to_string(DM_AUTH_BUSINESS_BUSY)); return DM_INPUT_PARA_EMPTY; } - if (authType != AUTH_TYPE_PIN && authType != AUTH_TYPE_SCAN && authType != AUTH_TYPE_TOUCH) { - LOGE("AuthenticateDevice failed, authType is not support"); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, - std::to_string(DM_AUTH_NOT_SUPPORT)); - return DM_AUTH_NOT_SUPPORT; - } - softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(DM_PKG_NAME); - softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(pkgName, shared_from_this()); authMessageProcessor_ = std::make_shared(shared_from_this()); + authResponseContext_ = std::make_shared(); authRequestContext_ = std::make_shared(); authRequestContext_->hostPkgName = pkgName; authRequestContext_->authType = authType; @@ -131,6 +133,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au } } authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); + authMessageProcessor_->SetRequestContext(authRequestContext_); authRequestState_ = std::make_shared(); authRequestState_->SetAuthManager(shared_from_this()); authRequestState_->SetAuthContext(authRequestContext_); @@ -201,7 +204,7 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) return DM_OK; } -void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionId, int32_t sessionSide, int32_t result) +void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) { LOGI("DmAuthManager::OnSessionOpened sessionId=%d result=%d", sessionId, result); if (sessionSide == AUTH_SESSION_SIDE_SERVER) { @@ -210,7 +213,6 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI authResponseState_ = std::make_shared(); authResponseState_->SetAuthManager(shared_from_this()); authResponseState_->Enter(); - hiChainConnector_->RegisterHiChainCallback(pkgName, shared_from_this()); authResponseContext_ = std::make_shared(); std::shared_ptr waitStartTimer = std::make_shared(WAIT_NEGOTIATE_TIMEOUT_TASK); timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] = waitStartTimer; @@ -229,11 +231,9 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI } } else { if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INIT) { - hiChainConnector_->RegisterHiChainCallback(pkgName, shared_from_this()); authRequestContext_->sessionId = sessionId; authRequestState_->SetAuthContext(authRequestContext_); authMessageProcessor_->SetRequestContext(authRequestContext_); - authResponseContext_ = std::make_shared(); authRequestState_->TransitionTo(std::make_shared()); } else { LOGE("DmAuthManager::OnSessionOpened but request state %d is wrong", authRequestState_->GetStateType()); @@ -241,12 +241,12 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI } } -void DmAuthManager::OnSessionClosed(const std::string &pkgName, int32_t sessionId) +void DmAuthManager::OnSessionClosed(int32_t sessionId) { LOGI("DmAuthManager::OnSessionOpened sessionId=%d", sessionId); } -void DmAuthManager::OnDataReceived(const std::string &pkgName, int32_t sessionId, std::string message) +void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) { LOGI("DmAuthManager::OnDataReceived start"); if (authRequestState_ == nullptr && authResponseState_ == nullptr) { @@ -389,6 +389,8 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); authResponseContext_->localDeviceId = localDeviceId; authResponseContext_->reply = DM_AUTH_NOT_AUTH; + authResponseContext_->authType = authRequestContext_->authType; + authResponseContext_->deviceId = authRequestContext_->deviceId; authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); @@ -410,6 +412,12 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) authResponseContext_->reply = DM_AUTH_NOT_AUTH; } + std::shared_ptr authentication = authenticationMap_[authResponseContext_->authType]; + if (authentication == nullptr) { + LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authResponseContext_->authType); + authResponseContext_->reply = DM_AUTH_NOT_SUPPORT; + } + std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); nlohmann::json jsonObject = nlohmann::json::parse(message, nullptr, false); if (jsonObject.is_discarded()) { @@ -546,11 +554,13 @@ void DmAuthManager::AuthenticateFinish() authResponseState_ = nullptr; authMessageProcessor_ = nullptr; } else if (authRequestState_ != nullptr) { - std::string flag = ""; if (authResponseContext_->reply != DM_AUTH_BUSINESS_BUSY) { authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_AUTH_TERMINATE); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); + } else { + authRequestContext_->reason = DM_AUTH_BUSINESS_BUSY; + authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; } if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) { @@ -561,8 +571,8 @@ void DmAuthManager::AuthenticateFinish() authRequestContext_->token, authResponseContext_->state, std::to_string(authRequestContext_->reason)); - softbusConnector_->GetSoftbusSession()->UnRegisterSessionCallback(authRequestContext_->hostPkgName); softbusConnector_->GetSoftbusSession()->CloseAuthSession(authRequestContext_->sessionId); + if (!timerMap_.empty()) { for (auto &iter : timerMap_) { iter.second->Stop(SESSION_CANCEL_TIMEOUT); @@ -602,27 +612,24 @@ std::string DmAuthManager::GenerateGroupName() return groupName; } -void DmAuthManager::GetIsCryptoSupport(bool &isCryptoSupport) +bool DmAuthManager::GetIsCryptoSupport() { LOGI("DmAuthManager::GetIsCryptoSupport start"); if (authResponseState_ == nullptr) { - isCryptoSupport = false; - return; + return false; } if (authRequestState_ == nullptr) { if (authResponseState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE_DONE) { - isCryptoSupport = false; - return; + return false; } } else { if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE || authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE_DONE) { - isCryptoSupport = false; - return; + return false; } } - isCryptoSupport = isCryptoSupport_; + return isCryptoSupport_; } void DmAuthManager::SetAuthRequestState(std::shared_ptr authRequestState) @@ -684,9 +691,10 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) return DM_OK; } -int32_t DmAuthManager::RegisterSessionCallback() +int32_t DmAuthManager::RegisterCallback() { - softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(DM_PKG_NAME, shared_from_this()); + softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(shared_from_this()); + hiChainConnector_->RegisterHiChainCallback(shared_from_this()); return DM_OK; } diff --git a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp index 5898ed3f0..ab7b0d162 100644 --- a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp +++ b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp @@ -54,7 +54,7 @@ void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo) } } -std::map> HiChainConnector::hiChainConnectorCallbackMap_ = {}; +std::shared_ptr HiChainConnector::hiChainConnectorCallback_ = nullptr; HiChainConnector::HiChainConnector() { @@ -78,16 +78,15 @@ HiChainConnector::~HiChainConnector() LOGI("HiChainConnector::destructor."); } -int32_t HiChainConnector::RegisterHiChainCallback(const std::string &pkgName, - std::shared_ptr callback) +int32_t HiChainConnector::RegisterHiChainCallback(std::shared_ptr callback) { - hiChainConnectorCallbackMap_.emplace(pkgName, callback); + hiChainConnectorCallback_ = callback; return DM_OK; } -int32_t HiChainConnector::UnRegisterHiChainCallback(const std::string &pkgName) +int32_t HiChainConnector::UnRegisterHiChainCallback() { - hiChainConnectorCallbackMap_.erase(pkgName); + hiChainConnectorCallback_ = nullptr; return DM_OK; } @@ -210,15 +209,11 @@ void HiChainConnector::onFinish(int64_t requestId, int32_t operationCode, const LOGI("HiChainConnector::onFinish reqId:%lld, operation:%d", requestId, operationCode); if (operationCode == GroupOperationCode::MEMBER_JOIN) { LOGI("Add Member To Group success"); - for (auto &iter : hiChainConnectorCallbackMap_) { - iter.second->OnMemberJoin(requestId, DM_OK); - } + hiChainConnectorCallback_->OnMemberJoin(requestId, DM_OK); } if (operationCode == GroupOperationCode::GROUP_CREATE) { LOGI("Create group success"); - for (auto &iter : hiChainConnectorCallbackMap_) { - iter.second->OnGroupCreated(requestId, data); - } + hiChainConnectorCallback_->OnGroupCreated(requestId, data); } if (operationCode == GroupOperationCode::MEMBER_DELETE) { LOGI("Delete Member from group success"); @@ -234,15 +229,11 @@ void HiChainConnector::onError(int64_t requestId, int32_t operationCode, int32_t LOGI("HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", requestId, operationCode, errorCode); if (operationCode == GroupOperationCode::MEMBER_JOIN) { LOGE("Add Member To Group failed"); - for (auto &iter : hiChainConnectorCallbackMap_) { - iter.second->OnMemberJoin(requestId, DM_FAILED); - } + hiChainConnectorCallback_->OnMemberJoin(requestId, DM_FAILED); } if (operationCode == GroupOperationCode::GROUP_CREATE) { LOGE("Create group failed"); - for (auto &iter : hiChainConnectorCallbackMap_) { - iter.second->OnGroupCreated(requestId, "{}"); - } + hiChainConnectorCallback_->OnGroupCreated(requestId, "{}"); } if (operationCode == GroupOperationCode::MEMBER_DELETE) { LOGE("Delete Member from group failed"); @@ -259,9 +250,7 @@ char *HiChainConnector::onRequest(int64_t requestId, int32_t operationCode, cons return nullptr; } int32_t pinCode = 0; - for (auto &iter : hiChainConnectorCallbackMap_) { - pinCode = iter.second->GetPinCode(); - } + pinCode = hiChainConnectorCallback_->GetPinCode(); nlohmann::json jsonObj; if (pinCode == DM_FAILED) { jsonObj[FIELD_CONFIRMATION] = REQUEST_REJECTED; @@ -286,9 +275,7 @@ int64_t HiChainConnector::GenRequestId() std::string HiChainConnector::GetConnectPara(std::string deviceId, std::string reqDeviceId) { std::string connectAddr = ""; - for (auto &iter : hiChainConnectorCallbackMap_) { - connectAddr = iter.second->GetConnectAddr(deviceId); - } + connectAddr = hiChainConnectorCallback_->GetConnectAddr(deviceId); LOGE("HiChainConnector::GetConnectPara get addrInfo"); nlohmann::json jsonObject = nlohmann::json::parse(connectAddr, nullptr, false); if (jsonObject.is_discarded()) { diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp index c3ea32668..8d4b55795 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace DistributedHardware { -std::map> SoftbusSession::sessionCallbackMap_ = {}; +std::shared_ptr SoftbusSession::sessionCallback_ = nullptr; SoftbusSession::SoftbusSession() { @@ -45,16 +45,15 @@ SoftbusSession::~SoftbusSession() RemoveSessionServer(DM_PKG_NAME.c_str(), DM_SESSION_NAME.c_str()); } -int32_t SoftbusSession::RegisterSessionCallback(const std::string &pkgName, - std::shared_ptr callback) +int32_t SoftbusSession::RegisterSessionCallback(std::shared_ptr callback) { - sessionCallbackMap_[pkgName] = callback; + sessionCallback_ = callback; return DM_OK; } -int32_t SoftbusSession::UnRegisterSessionCallback(const std::string &pkgName) +int32_t SoftbusSession::UnRegisterSessionCallback() { - sessionCallbackMap_.erase(pkgName); + sessionCallback_ = nullptr; return DM_OK; } @@ -108,11 +107,7 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message) } int32_t msgType = jsonObject[TAG_TYPE]; LOGI("AuthMessageProcessor::ParseAuthRequestMessage msgType = %d", msgType); - bool isCryptoSupport = false; - for (auto &iter : sessionCallbackMap_) { - iter.second->GetIsCryptoSupport(isCryptoSupport); - } - if (isCryptoSupport) { + if (sessionCallback_->GetIsCryptoSupport()) { LOGI("SoftbusSession::SendData Start encryption"); } int32_t ret = SendBytes(sessionId, message.c_str(), strlen(message.c_str())); @@ -127,9 +122,7 @@ int32_t SoftbusSession::SendData(int32_t sessionId, std::string &message) int32_t SoftbusSession::OnSessionOpened(int32_t sessionId, int32_t result) { int32_t sessionSide = GetSessionSide(sessionId); - for (auto &iter : sessionCallbackMap_) { - iter.second->OnSessionOpened(iter.first, sessionId, sessionSide, result); - } + sessionCallback_->OnSessionOpened(sessionId, sessionSide, result); LOGI("OnSessionOpened, success:"); return DM_OK; } @@ -146,18 +139,11 @@ void SoftbusSession::OnBytesReceived(int32_t sessionId, const void *data, uint32 LOGI("OnBytesReceived param check failed"); return; } - bool isCryptoSupport = false; - for (auto &iter : sessionCallbackMap_) { - iter.second->GetIsCryptoSupport(isCryptoSupport); - } - if (isCryptoSupport) { + if (sessionCallback_->GetIsCryptoSupport()) { LOGI("SoftbusSession::OnBytesReceived Start decryption"); } std::string message = std::string((const char *)data, dataLen); - for (auto &iter : sessionCallbackMap_) { - iter.second->OnDataReceived(iter.first, sessionId, message); - return; - } + sessionCallback_->OnDataReceived(sessionId, message); LOGI("OnBytesReceived completed"); } } // namespace DistributedHardware diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 32c60ef37..2ae58c33b 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -72,7 +72,7 @@ int32_t DeviceManagerService::Init() LOGE("Init failed, authMgr_ apply for failure"); return DM_MAKE_SHARED_FAIL; } - authMgr_->RegisterSessionCallback(); + authMgr_->RegisterCallback(); } LOGI("Init success, singleton initialized"); intFlag_ = true; diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp index cfb111128..88006a20e 100644 --- a/test/unittest/UTTest_hichain_connector.cpp +++ b/test/unittest/UTTest_hichain_connector.cpp @@ -256,15 +256,12 @@ HWTEST_F(HichainConnectorTest, HiChainConnector_002, testing::ext::TestSize.Leve */ HWTEST_F(HichainConnectorTest, RegisterHiChainCallback_001, testing::ext::TestSize.Level0) { - std::string pkgName = "com.softbus.test"; std::shared_ptr listener_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); std::shared_ptr hichainConnector = std::make_shared(); int ret = - hichainConnector->RegisterHiChainCallback(pkgName, std::shared_ptr(discoveryMgr_)); - int ret1 = HiChainConnector::hiChainConnectorCallbackMap_.count(pkgName); - EXPECT_EQ(ret1, 1); + hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); EXPECT_EQ(ret, DM_OK); } @@ -355,12 +352,11 @@ HWTEST_F(HichainConnectorTest, onRequest_001, testing::ext::TestSize.Level0) */ HWTEST_F(HichainConnectorTest, GetConnectPara_001, testing::ext::TestSize.Level0) { - std::string pkgName = "softbus"; std::shared_ptr listener_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); std::shared_ptr hichainConnector = std::make_shared(); - hichainConnector->RegisterHiChainCallback(pkgName, std::shared_ptr(discoveryMgr_)); + hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); std::string deviceId = "23445"; std::string reqDeviceId = "234566"; std::string p; @@ -378,12 +374,11 @@ HWTEST_F(HichainConnectorTest, GetConnectPara_002, testing::ext::TestSize.Level0 { std::string deviceId; std::string reqDeviceId = "234566"; - std::string pkgName = "softbus"; std::shared_ptr listener_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); std::shared_ptr hichainConnector = std::make_shared(); - hichainConnector->RegisterHiChainCallback(pkgName, std::shared_ptr(discoveryMgr_)); + hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); std::string ret = hichainConnector->GetConnectPara(deviceId, reqDeviceId); EXPECT_EQ(ret, ""); } diff --git a/test/unittest/UTTest_softbus_session.cpp b/test/unittest/UTTest_softbus_session.cpp index 5294129f4..1132c6394 100644 --- a/test/unittest/UTTest_softbus_session.cpp +++ b/test/unittest/UTTest_softbus_session.cpp @@ -172,7 +172,7 @@ HWTEST_F(SoftbusSessionTest, GetPeerDeviceId_001, testing::ext::TestSize.Level0) HWTEST_F(SoftbusSessionTest, UnRegisterSessionCallback_001, testing::ext::TestSize.Level0) { std::string pkgName = "softbus"; - int ret = softbusSession->UnRegisterSessionCallback(pkgName); + int ret = softbusSession->UnRegisterSessionCallback(); EXPECT_EQ(ret, DM_OK); } } // namespace -- Gitee From b445d77a9b8b60ee3e1be9939ad1c365453a61c5 Mon Sep 17 00:00:00 2001 From: puhui Date: Mon, 17 Jan 2022 22:51:46 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=A1=A5=E5=85=85UT=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=92=8C=E4=BF=AE=E6=94=B9=E8=AE=A4=E8=AF=81=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: puhui --- common/include/dm_constants.h | 1 + .../native_cpp/include/dm_device_info.h | 6 +- .../native_cpp/src/device_manager_impl.cpp | 5 +- .../kits/js/src/native_devicemanager_js.cpp | 3 +- .../authentication/auth_message_processor.h | 2 +- .../authentication/auth_request_state.h | 27 +- .../authentication/auth_response_state.h | 22 +- .../include/authentication/dm_auth_manager.h | 16 +- .../include/device_manager_service_listener.h | 2 +- .../authentication/auth_message_processor.cpp | 4 +- .../src/authentication/auth_request_state.cpp | 56 ++-- .../authentication/auth_response_state.cpp | 42 ++- .../src/authentication/dm_auth_manager.cpp | 60 ++-- .../src/device_manager_service_listener.cpp | 3 +- test/unittest/BUILD.gn | 48 ++- ....cpp => UTTest_auth_message_processor.cpp} | 45 ++- ...sage.h => UTTest_auth_message_processor.h} | 0 test/unittest/UTTest_auth_request_state.cpp | 42 ++- test/unittest/UTTest_auth_response_state.cpp | 27 +- .../UTTest_device_manager_service.cpp | 22 +- ...UTTest_device_manager_service_listener.cpp | 2 +- test/unittest/UTTest_dm_auth_manager.cpp | 287 +----------------- .../UTTest_dm_device_state_manager.cpp | 6 +- test/unittest/UTTest_hichain_connector.cpp | 18 +- test/unittest/UTTest_softbus_session.cpp | 23 +- test/unittest/UTTest_softbus_session.h | 2 + test/unittest/auth_response_state.cpp | 155 ++++++++++ 27 files changed, 476 insertions(+), 450 deletions(-) rename test/unittest/{UTTest_device_message.cpp => UTTest_auth_message_processor.cpp} (91%) rename test/unittest/{UTTest_device_message.h => UTTest_auth_message_processor.h} (100%) create mode 100644 test/unittest/auth_response_state.cpp diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 54b81362f..492de42c1 100644 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -78,6 +78,7 @@ enum { DM_AUTH_OPEN_SESSION_FAILED, DM_AUTH_PEER_REJECT, DM_AUTH_NOT_AUTH, + DM_AUTH_DONT_AUTH, DM_SOFTBUS_FAILED = 3000, DM_SOFTBUS_CREATE_SESSION_SERVER_FAILED, DM_HICHAIN_FAILED = 4000, diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 6498a0d5f..b17b597b1 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -38,11 +38,11 @@ typedef enum DmDeviceType { } DmDeviceType; typedef enum DmDeviceState { - DEVICE_STATE_UNKNOWN = 0, - DEVICE_STATE_ONLINE = 1, + DEVICE_STATE_UNKNOWN = -1, + DEVICE_STATE_ONLINE = 0, + DEVICE_INFO_READY = 1, DEVICE_STATE_OFFLINE = 2, DEVICE_INFO_CHANGED = 3, - DEVICE_INFO_READY = 4, } DmDeviceState; typedef struct DmDeviceInfo { diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index c50d94dcb..417bd62c6 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -315,6 +315,8 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ return DM_INVALID_VALUE; } + std::string strDeviceId = deviceInfo.deviceId; + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, strDeviceId, callback); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); @@ -333,8 +335,6 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ return DM_IPC_RESPOND_ERROR; } - std::string strDeviceId = deviceInfo.deviceId; - DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, strDeviceId, callback); LOGI("DeviceManager::AuthenticateDevice completed, pkgName: %s", pkgName.c_str()); return DM_OK; } @@ -370,7 +370,6 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons return DM_IPC_RESPOND_ERROR; } - DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId); LOGI("UnAuthenticateDevice completed, pkgName: %s", pkgName.c_str()); return DM_OK; } diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index e30e0ca69..c314e669c 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1075,9 +1075,8 @@ napi_value DeviceManagerNapi::GetTrustedDeviceListSync(napi_env env, napi_callba if (isArray == false) { LOGE("napi_create_array fail"); } - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); - NAPI_ASSERT(env, argc == 1, "Wrong number of arguments"); + NAPI_ASSERT(env, argc == 0, "Wrong number of arguments"); DeviceManagerNapi *deviceManagerWrapper = nullptr; napi_unwrap(env, thisVar, reinterpret_cast(&deviceManagerWrapper)); std::string extra = ""; diff --git a/services/devicemanagerservice/include/authentication/auth_message_processor.h b/services/devicemanagerservice/include/authentication/auth_message_processor.h index 73226f7a8..5bc633bc9 100644 --- a/services/devicemanagerservice/include/authentication/auth_message_processor.h +++ b/services/devicemanagerservice/include/authentication/auth_message_processor.h @@ -47,7 +47,7 @@ private: void CreateSyncGroupMessage(nlohmann::json &json); void CreateResponseAuthMessage(nlohmann::json &json); void ParseAuthResponseMessage(nlohmann::json &json); - void ParseAuthRequestMessage(); + int32_t ParseAuthRequestMessage(); void ParseNegotiateMessage(const nlohmann::json &json); void CreateResponseFinishMessage(nlohmann::json &json); void ParseResponseFinishMessage(nlohmann::json &json); diff --git a/services/devicemanagerservice/include/authentication/auth_request_state.h b/services/devicemanagerservice/include/authentication/auth_request_state.h index a1a3343e8..81c98308d 100644 --- a/services/devicemanagerservice/include/authentication/auth_request_state.h +++ b/services/devicemanagerservice/include/authentication/auth_request_state.h @@ -29,14 +29,13 @@ public: virtual ~AuthRequestState() { authManager_.reset(); - LOGE("~AuthRequestState"); }; virtual int32_t GetStateType() = 0; - virtual void Enter() = 0; - void Leave(); - void TransitionTo(std::shared_ptr state); - void SetAuthManager(std::shared_ptr authManager); - void SetAuthContext(std::shared_ptr context); + virtual int32_t Enter() = 0; + int32_t Leave(); + int32_t TransitionTo(std::shared_ptr state); + int32_t SetAuthManager(std::shared_ptr authManager); + int32_t SetAuthContext(std::shared_ptr context); std::shared_ptr GetAuthContext(); protected: @@ -47,48 +46,48 @@ protected: class AuthRequestInitState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthRequestNegotiateState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthRequestNegotiateDoneState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthRequestReplyState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthRequestInputState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthRequestJoinState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthRequestNetworkState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthRequestFinishState : public AuthRequestState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/authentication/auth_response_state.h b/services/devicemanagerservice/include/authentication/auth_response_state.h index 5c44c2bad..f4d67bae1 100644 --- a/services/devicemanagerservice/include/authentication/auth_response_state.h +++ b/services/devicemanagerservice/include/authentication/auth_response_state.h @@ -29,11 +29,11 @@ public: authManager_.reset(); }; virtual int32_t GetStateType() = 0; - virtual void Enter() = 0; - void Leave(); - void TransitionTo(std::shared_ptr state); - void SetAuthManager(std::shared_ptr authManager); - void SetAuthContext(std::shared_ptr context); + virtual int32_t Enter() = 0; + int32_t Leave(); + int32_t TransitionTo(std::shared_ptr state); + int32_t SetAuthManager(std::shared_ptr authManager); + int32_t SetAuthContext(std::shared_ptr context); std::shared_ptr GetAuthContext(); protected: @@ -44,37 +44,37 @@ protected: class AuthResponseInitState : public AuthResponseState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthResponseNegotiateState : public AuthResponseState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthResponseConfirmState : public AuthResponseState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthResponseGroupState : public AuthResponseState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthResponseShowState : public AuthResponseState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; class AuthResponseFinishState : public AuthResponseState { public: int32_t GetStateType() override; - void Enter() override; + int32_t Enter() override; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 1295ebb88..1a2d6949d 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -135,23 +135,23 @@ public: void OnMemberJoin(int64_t requestId, int32_t status); // auth state machine - void EstablishAuthChannel(const std::string &deviceId); + int32_t EstablishAuthChannel(const std::string &deviceId); void StartNegotiate(const int32_t &sessionId); void RespNegotiate(const int32_t &sessionId); void SendAuthRequest(const int32_t &sessionId); - void StartAuthProcess(const int32_t &authType); + int32_t StartAuthProcess(const int32_t &authType); void StartRespAuthProcess(); - void CreateGroup(); - void AddMember(const std::string &deviceId); + int32_t CreateGroup(); + int32_t AddMember(const std::string &deviceId); std::string GetConnectAddr(std::string deviceId); - void JoinNetwork(); + int32_t JoinNetwork(); void AuthenticateFinish(); bool GetIsCryptoSupport(); - void SetAuthRequestState(std::shared_ptr authRequestState); - void SetAuthResponseState(std::shared_ptr authResponseState); + int32_t SetAuthRequestState(std::shared_ptr authRequestState); + int32_t SetAuthResponseState(std::shared_ptr authResponseState); int32_t GetPinCode(); std::string GenerateGroupName(); - void HandleAuthenticateTimeout(); + int32_t HandleAuthenticateTimeout(); void CancelDisplay(); int32_t GeneratePincode(); void ShowConfigDialog(); diff --git a/services/devicemanagerservice/include/device_manager_service_listener.h b/services/devicemanagerservice/include/device_manager_service_listener.h index 4ad17f9f8..e52d9ed73 100644 --- a/services/devicemanagerservice/include/device_manager_service_listener.h +++ b/services/devicemanagerservice/include/device_manager_service_listener.h @@ -32,7 +32,7 @@ public: void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason); void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId); void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, int32_t status, - const std::string &reason); + int32_t reason); void OnVerifyAuthResult(const std::string &pkgName, const std::string &deviceId, int32_t resultCode, const std::string &flag); void OnFaCall(std::string &pkgName, std::string ¶mJson); diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index a373a9f2d..9ba556f4a 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -231,7 +231,7 @@ void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) LOGI("AuthMessageProcessor::ParseAuthResponseMessage "); } -void AuthMessageProcessor::ParseAuthRequestMessage() +int32_t AuthMessageProcessor::ParseAuthRequestMessage() { nlohmann::json jsonObject = authSplitJsonList_.front(); authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID]; @@ -244,8 +244,10 @@ void AuthMessageProcessor::ParseAuthRequestMessage() authResponseContext_->groupId = jsonObject[TAG_GROUP_ID]; authResponseContext_->groupName = jsonObject[TAG_GROUP_NAME]; authResponseContext_->requestId = jsonObject[TAG_REQUEST_ID]; + return DM_FAILED; } authSplitJsonList_.clear(); + return DM_OK; } void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) diff --git a/services/devicemanagerservice/src/authentication/auth_request_state.cpp b/services/devicemanagerservice/src/authentication/auth_request_state.cpp index 7e1653418..7b6797cbc 100644 --- a/services/devicemanagerservice/src/authentication/auth_request_state.cpp +++ b/services/devicemanagerservice/src/authentication/auth_request_state.cpp @@ -20,18 +20,21 @@ namespace OHOS { namespace DistributedHardware { -void AuthRequestState::Leave() +int32_t AuthRequestState::Leave() { + return DM_OK; } -void AuthRequestState::SetAuthManager(std::shared_ptr authManager) +int32_t AuthRequestState::SetAuthManager(std::shared_ptr authManager) { authManager_ = std::move(authManager); + return DM_OK; } -void AuthRequestState::SetAuthContext(std::shared_ptr context) +int32_t AuthRequestState::SetAuthContext(std::shared_ptr context) { context_ = std::move(context); + return DM_OK; } std::shared_ptr AuthRequestState::GetAuthContext() @@ -39,19 +42,20 @@ std::shared_ptr AuthRequestState::GetAuthContext() return context_; } -void AuthRequestState::TransitionTo(std::shared_ptr state) +int32_t AuthRequestState::TransitionTo(std::shared_ptr state) { LOGE("AuthRequestState::TransitionTo"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } state->SetAuthManager(stateAuthManager); stateAuthManager->SetAuthRequestState(state); state->SetAuthContext(context_); this->Leave(); state->Enter(); + return DM_OK; } int32_t AuthRequestInitState::GetStateType() @@ -59,14 +63,15 @@ int32_t AuthRequestInitState::GetStateType() return AuthState::AUTH_REQUEST_INIT; } -void AuthRequestInitState::Enter() +int32_t AuthRequestInitState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->EstablishAuthChannel(context_->deviceId); + return DM_OK; } int32_t AuthRequestNegotiateState::GetStateType() @@ -74,14 +79,15 @@ int32_t AuthRequestNegotiateState::GetStateType() return AuthState::AUTH_REQUEST_NEGOTIATE; } -void AuthRequestNegotiateState::Enter() +int32_t AuthRequestNegotiateState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->StartNegotiate(context_->sessionId); + return DM_OK; } int32_t AuthRequestNegotiateDoneState::GetStateType() @@ -89,14 +95,15 @@ int32_t AuthRequestNegotiateDoneState::GetStateType() return AuthState::AUTH_REQUEST_NEGOTIATE_DONE; } -void AuthRequestNegotiateDoneState::Enter() +int32_t AuthRequestNegotiateDoneState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->SendAuthRequest(context_->sessionId); + return DM_OK; } int32_t AuthRequestReplyState::GetStateType() @@ -104,14 +111,15 @@ int32_t AuthRequestReplyState::GetStateType() return AuthState::AUTH_REQUEST_REPLY; } -void AuthRequestReplyState::Enter() +int32_t AuthRequestReplyState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->StartRespAuthProcess(); + return DM_OK; } int32_t AuthRequestInputState::GetStateType() @@ -119,15 +127,16 @@ int32_t AuthRequestInputState::GetStateType() return AuthState::AUTH_REQUEST_INPUT; } -void AuthRequestInputState::Enter() +int32_t AuthRequestInputState::Enter() { LOGE("DmAuthManager::AuthRequestInputState"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->ShowStartAuthDialog(); + return DM_OK; } int32_t AuthRequestJoinState::GetStateType() @@ -135,15 +144,16 @@ int32_t AuthRequestJoinState::GetStateType() return AuthState::AUTH_REQUEST_JOIN; } -void AuthRequestJoinState::Enter() +int32_t AuthRequestJoinState::Enter() { LOGE("DmAuthManager::AuthRequestJoinState"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->AddMember(context_->deviceId); + return DM_OK; } int32_t AuthRequestNetworkState::GetStateType() @@ -151,14 +161,15 @@ int32_t AuthRequestNetworkState::GetStateType() return AuthState::AUTH_REQUEST_NETWORK; } -void AuthRequestNetworkState::Enter() +int32_t AuthRequestNetworkState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->JoinNetwork(); + return DM_OK; } int32_t AuthRequestFinishState::GetStateType() @@ -166,16 +177,15 @@ int32_t AuthRequestFinishState::GetStateType() return AuthState::AUTH_REQUEST_FINISH; } -void AuthRequestFinishState::Enter() +int32_t AuthRequestFinishState::Enter() { - // 1. 清理资源 - // 2. 通知对端认证结束,并关闭认证通道 std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->AuthenticateFinish(); + return DM_OK; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/authentication/auth_response_state.cpp b/services/devicemanagerservice/src/authentication/auth_response_state.cpp index 1eb3507c2..14f7c2c3b 100644 --- a/services/devicemanagerservice/src/authentication/auth_response_state.cpp +++ b/services/devicemanagerservice/src/authentication/auth_response_state.cpp @@ -21,13 +21,15 @@ namespace OHOS { namespace DistributedHardware { -void AuthResponseState::Leave() +int32_t AuthResponseState::Leave() { + return DM_OK; } -void AuthResponseState::SetAuthContext(std::shared_ptr context) +int32_t AuthResponseState::SetAuthContext(std::shared_ptr context) { context_ = std::move(context); + return DM_OK; } std::shared_ptr AuthResponseState::GetAuthContext() @@ -35,24 +37,26 @@ std::shared_ptr AuthResponseState::GetAuthContext() return context_; } -void AuthResponseState::SetAuthManager(std::shared_ptr authManager) +int32_t AuthResponseState::SetAuthManager(std::shared_ptr authManager) { authManager_ = std::move(authManager); + return DM_OK; } -void AuthResponseState::TransitionTo(std::shared_ptr state) +int32_t AuthResponseState::TransitionTo(std::shared_ptr state) { LOGI("AuthRequestState:: TransitionTo"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } state->SetAuthManager(stateAuthManager); stateAuthManager->SetAuthResponseState(state); state->SetAuthContext(context_); this->Leave(); state->Enter(); + return DM_OK; } int32_t AuthResponseInitState::GetStateType() @@ -60,9 +64,10 @@ int32_t AuthResponseInitState::GetStateType() return AuthState::AUTH_RESPONSE_INIT; } -void AuthResponseInitState::Enter() +int32_t AuthResponseInitState::Enter() { LOGI("AuthResponse:: AuthResponseInitState Enter"); + return DM_OK; } int32_t AuthResponseNegotiateState::GetStateType() @@ -70,14 +75,15 @@ int32_t AuthResponseNegotiateState::GetStateType() return AuthState::AUTH_RESPONSE_NEGOTIATE; } -void AuthResponseNegotiateState::Enter() +int32_t AuthResponseNegotiateState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->RespNegotiate(context_->sessionId); + return DM_OK; } int32_t AuthResponseConfirmState::GetStateType() @@ -85,15 +91,16 @@ int32_t AuthResponseConfirmState::GetStateType() return AuthState::AUTH_RESPONSE_CONFIRM; } -void AuthResponseConfirmState::Enter() +int32_t AuthResponseConfirmState::Enter() { LOGI("AuthResponse:: AuthResponseConfirmState Enter"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->ShowConfigDialog(); + return DM_OK; } int32_t AuthResponseGroupState::GetStateType() @@ -101,15 +108,16 @@ int32_t AuthResponseGroupState::GetStateType() return AuthState::AUTH_RESPONSE_GROUP; } -void AuthResponseGroupState::Enter() +int32_t AuthResponseGroupState::Enter() { LOGI("AuthResponse:: AuthResponseGroupState Enter"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->CreateGroup(); + return DM_OK; } int32_t AuthResponseShowState::GetStateType() @@ -117,14 +125,15 @@ int32_t AuthResponseShowState::GetStateType() return AuthState::AUTH_RESPONSE_SHOW; } -void AuthResponseShowState::Enter() +int32_t AuthResponseShowState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->ShowAuthInfoDialog(); + return DM_OK; } int32_t AuthResponseFinishState::GetStateType() @@ -132,14 +141,15 @@ int32_t AuthResponseFinishState::GetStateType() return AuthState::AUTH_RESPONSE_FINISH; } -void AuthResponseFinishState::Enter() +int32_t AuthResponseFinishState::Enter() { std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); - return; + return DM_FAILED; } stateAuthManager->AuthenticateFinish(); + return DM_OK; } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index f2c246b09..2ab2afff3 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -83,28 +83,24 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au std::shared_ptr authentication = authenticationMap_[authType]; if (authentication == nullptr) { LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, - std::to_string(DM_AUTH_NOT_SUPPORT)); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_NOT_SUPPORT); return DM_AUTH_NOT_SUPPORT; } - if (authRequestState_ != nullptr && authResponseState_ != nullptr) { - LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.", - authRequestState_->GetAuthContext()->hostPkgName.c_str()); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, - std::to_string(DM_AUTH_BUSINESS_BUSY)); + + if (authRequestState_ != nullptr || authResponseState_ != nullptr) { + LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.",pkgName.c_str()); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_BUSINESS_BUSY); return DM_AUTH_BUSINESS_BUSY; } if (!softbusConnector_->HaveDeviceInMap(deviceId)) { LOGE("AuthenticateDevice failed, the discoveryDeviceInfoMap_ not have this device"); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, - std::to_string(DM_AUTH_INPUT_FAILED)); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_INPUT_FAILED); return DM_AUTH_INPUT_FAILED; } if (extra.empty()) { LOGE("AuthenticateDevice failed, extra is empty"); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, - std::to_string(DM_AUTH_BUSINESS_BUSY)); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_BUSINESS_BUSY); return DM_INPUT_PARA_EMPTY; } @@ -197,6 +193,8 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) break; default: CancelDisplay(); + authRequestContext_->reason = DM_AUTH_INPUT_FAILED; + authResponseContext_->state = authRequestState_->GetStateType(); authRequestState_->TransitionTo(std::make_shared()); break; } @@ -208,7 +206,7 @@ void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int3 { LOGI("DmAuthManager::OnSessionOpened sessionId=%d result=%d", sessionId, result); if (sessionSide == AUTH_SESSION_SIDE_SERVER) { - if (authResponseState_ == nullptr) { + if (authResponseState_ == nullptr && authRequestState_ == nullptr) { authMessageProcessor_ = std::make_shared(shared_from_this()); authResponseState_ = std::make_shared(); authResponseState_->SetAuthManager(shared_from_this()); @@ -230,13 +228,14 @@ void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int3 softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); } } else { - if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INIT) { + if (authResponseState_ == nullptr && authRequestState_ != nullptr && + authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INIT){ authRequestContext_->sessionId = sessionId; authRequestState_->SetAuthContext(authRequestContext_); authMessageProcessor_->SetRequestContext(authRequestContext_); authRequestState_->TransitionTo(std::make_shared()); } else { - LOGE("DmAuthManager::OnSessionOpened but request state %d is wrong", authRequestState_->GetStateType()); + LOGE("DmAuthManager::OnSessionOpened but request state is wrong"); } } } @@ -352,7 +351,7 @@ void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) } } -void DmAuthManager::HandleAuthenticateTimeout() +int32_t DmAuthManager::HandleAuthenticateTimeout() { LOGI("DmAuthManager::HandleAuthenticateTimeout start"); if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { @@ -368,9 +367,10 @@ void DmAuthManager::HandleAuthenticateTimeout() authResponseState_->TransitionTo(std::make_shared()); } LOGI("DmAuthManager::HandleAuthenticateTimeout start complete"); + return DM_OK; } -void DmAuthManager::EstablishAuthChannel(const std::string &deviceId) +int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) { int32_t sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); if (sessionId < 0) { @@ -380,6 +380,7 @@ void DmAuthManager::EstablishAuthChannel(const std::string &deviceId) authRequestContext_->reason = DM_AUTH_OPEN_SESSION_FAILED; authRequestState_->TransitionTo(std::make_shared()); } + return DM_OK; } void DmAuthManager::StartNegotiate(const int32_t &sessionId) @@ -417,7 +418,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authResponseContext_->authType); authResponseContext_->reply = DM_AUTH_NOT_SUPPORT; } - + std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); nlohmann::json jsonObject = nlohmann::json::parse(message, nullptr, false); if (jsonObject.is_discarded()) { @@ -460,7 +461,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) confirmStartTimer->Start(CONFIRM_TIMEOUT, TimeOut, this); } -void DmAuthManager::StartAuthProcess(const int32_t &action) +int32_t DmAuthManager::StartAuthProcess(const int32_t &action) { LOGI("DmAuthManager:: StartAuthProcess"); authResponseContext_->reply = action; @@ -472,6 +473,7 @@ void DmAuthManager::StartAuthProcess(const int32_t &action) std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } + return DM_OK; } void DmAuthManager::StartRespAuthProcess() @@ -491,15 +493,16 @@ void DmAuthManager::StartRespAuthProcess() } } -void DmAuthManager::CreateGroup() +int32_t DmAuthManager::CreateGroup() { LOGI("DmAuthManager:: CreateGroup"); authResponseContext_->groupName = GenerateGroupName(); authResponseContext_->requestId = GenRandLongLong(MIN_REQUEST_ID, MAX_REQUEST_ID); hiChainConnector_->CreateGroup(authResponseContext_->requestId, authResponseContext_->groupName); + return DM_OK; } -void DmAuthManager::AddMember(const std::string &deviceId) +int32_t DmAuthManager::AddMember(const std::string &deviceId) { LOGI("DmAuthManager::AddMember start"); nlohmann::json jsonObject; @@ -514,10 +517,11 @@ void DmAuthManager::AddMember(const std::string &deviceId) joinStartTimer->Start(ADD_TIMEOUT, TimeOut, this); int32_t ret = hiChainConnector_->AddMember(deviceId, connectInfo); if (ret != 0) { - return; + return DM_FAILED; } LOGI("DmAuthManager::authRequestContext CancelDisplay start"); CancelDisplay(); + return DM_OK; } std::string DmAuthManager::GetConnectAddr(std::string deviceId) @@ -528,13 +532,14 @@ std::string DmAuthManager::GetConnectAddr(std::string deviceId) return connectAddr; } -void DmAuthManager::JoinNetwork() +int32_t DmAuthManager::JoinNetwork() { LOGE("DmAuthManager JoinNetwork start"); timerMap_[AUTHENTICATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; authRequestState_->TransitionTo(std::make_shared()); + return DM_OK; } void DmAuthManager::AuthenticateFinish() @@ -568,8 +573,7 @@ void DmAuthManager::AuthenticateFinish() } listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, - authRequestContext_->token, authResponseContext_->state, - std::to_string(authRequestContext_->reason)); + authRequestContext_->token, authResponseContext_->state, authRequestContext_->reason); softbusConnector_->GetSoftbusSession()->CloseAuthSession(authRequestContext_->sessionId); @@ -632,14 +636,16 @@ bool DmAuthManager::GetIsCryptoSupport() return isCryptoSupport_; } -void DmAuthManager::SetAuthRequestState(std::shared_ptr authRequestState) +int32_t DmAuthManager::SetAuthRequestState(std::shared_ptr authRequestState) { authRequestState_ = authRequestState; + return DM_OK; } -void DmAuthManager::SetAuthResponseState(std::shared_ptr authResponseState) +int32_t DmAuthManager::SetAuthResponseState(std::shared_ptr authResponseState) { authResponseState_ = authResponseState; + return DM_OK; } int32_t DmAuthManager::GetPinCode() @@ -712,6 +718,8 @@ int32_t DmAuthManager::OnUserOperation(int32_t action) CancelDisplay(); break; case USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT: + authRequestContext_->reason = DM_AUTH_DONT_AUTH; + authResponseContext_->state = authRequestState_->GetStateType(); AuthenticateFinish(); break; default: diff --git a/services/devicemanagerservice/src/device_manager_service_listener.cpp b/services/devicemanagerservice/src/device_manager_service_listener.cpp index 5c4b3d2d5..c67191a3e 100644 --- a/services/devicemanagerservice/src/device_manager_service_listener.cpp +++ b/services/devicemanagerservice/src/device_manager_service_listener.cpp @@ -78,7 +78,7 @@ void DeviceManagerServiceListener::OnDiscoverySuccess(const std::string &pkgName } void DeviceManagerServiceListener::OnAuthResult(const std::string &pkgName, const std::string &deviceId, - const std::string &token, int32_t status, const std::string &reason) + const std::string &token, int32_t status, int32_t reason) { LOGI("%s, package: %s, deviceId: %s", __FUNCTION__, pkgName.c_str(), GetAnonyString(deviceId).c_str()); std::shared_ptr pReq = std::make_shared(); @@ -88,6 +88,7 @@ void DeviceManagerServiceListener::OnAuthResult(const std::string &pkgName, cons pReq->SetDeviceId(deviceId); pReq->SetToken(token); pReq->SetStatus(status); + pReq->SetReason(reason); ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp); } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9b12bd86e..40d6bd901 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -19,15 +19,18 @@ group("unittest") { testonly = true deps = [ + ":UTTest_auth_message_processor", + ":UTTest_auth_request_state", + ":UTTest_auth_response_state", ":UTTest_device_manager_service", ":UTTest_device_manager_service_listener", + ":UTTest_dm_auth_manager", ":UTTest_dm_device_info_manager", ":UTTest_dm_device_state_manager", ":UTTest_dm_discovery_manager", ":UTTest_hichain_connector", ":UTTest_softbus_connector", ":UTTest_softbus_session", - ":device_manager_impl_test", ] } @@ -135,6 +138,49 @@ ohos_unittest("UTTest_device_manager_service_listener") { ## UnitTest UTTest_device_manager_service_listener }}} +## UnitTest UTTest_auth_message_processor {{{ +ohos_unittest("UTTest_auth_message_processor") { + module_out_path = module_out_path + + sources = [ "UTTest_auth_message_processor.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UTTest_auth_message_processor }}} + +## UnitTest UTTest_auth_response_state {{{ +ohos_unittest("UTTest_auth_response_state") { + module_out_path = module_out_path + + sources = [ "UTTest_auth_response_state.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UTTest_auth_response_state }}} + +## UnitTest UTTest_auth_request_state {{{ +ohos_unittest("UTTest_auth_request_state") { + module_out_path = module_out_path + + sources = [ "UTTest_auth_request_state.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UTTest_auth_request_state }}} + +## UnitTest UTTest_dm_auth_manager {{{ +ohos_unittest("UTTest_dm_auth_manager") { + module_out_path = module_out_path + + sources = [ "UTTest_dm_auth_manager.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UTTest_dm_auth_manager }}} ## UnitTest UTTest_dm_discovery_manager {{{ ohos_unittest("UTTest_dm_discovery_manager") { module_out_path = module_out_path diff --git a/test/unittest/UTTest_device_message.cpp b/test/unittest/UTTest_auth_message_processor.cpp similarity index 91% rename from test/unittest/UTTest_device_message.cpp rename to test/unittest/UTTest_auth_message_processor.cpp index ba18e48cf..b86db8980 100644 --- a/test/unittest/UTTest_device_message.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -19,7 +19,7 @@ #include "softbus_connector.h" #include "softbus_session.h" #include "dm_auth_manager.h" -#include "UTTest_device_message.h" +#include "UTTest_auth_message_processor.h" namespace OHOS { namespace DistributedHardware { @@ -37,6 +37,7 @@ void AuthMessageProcessorTest::TearDownTestCase() } namespace { + /** * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001 * @tc.desc: 1 set cryptoAdapter_ to null @@ -51,17 +52,25 @@ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::Tes std::shared_ptr listener = std::make_shared(); std::shared_ptr data = std::make_shared(softbusConnector, listener); std::shared_ptr authMessageProcessor = std::make_shared(data); + std::shared_ptr authResponseContext = std::make_shared(); + authMessageProcessor->authResponseContext_ = std::make_shared(); int32_t msgType = MSG_TYPE_NEGOTIATE; nlohmann::json jsonObj; jsonObj[TAG_VER] = DM_ITF_VER; jsonObj[TAG_TYPE] = msgType; + jsonObj[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType; + authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->cryptoAdapter_ = nullptr; authMessageProcessor->CreateNegotiateMessage(jsonObj); std::string str1 = jsonObj.dump(); + nlohmann::json jsonObject; jsonObject[TAG_VER] = DM_ITF_VER; jsonObject[TAG_TYPE] = msgType; jsonObject[TAG_CRYPTO_SUPPORT] = false; + jsonObject[TAG_AUTH_TYPE] = authMessageProcessor->authResponseContext_->authType; + jsonObject[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply; + jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId; std::string str2 = jsonObject.dump(); ASSERT_EQ(str1, str2); sleep(15); @@ -112,6 +121,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: nlohmann::json jsonObj; authMessageProcessor->authResponseContext_->reply = 0; authMessageProcessor->authResponseContext_->deviceId = "132416546"; + authMessageProcessor->authResponseContext_->token = "11"; nlohmann::json jsonb; jsonb[TAG_GROUP_ID] = "123456"; authMessageProcessor->authResponseContext_->groupId = jsonb.dump(); @@ -119,6 +129,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: authMessageProcessor->authResponseContext_->networkId = "11112222"; authMessageProcessor->authResponseContext_->requestId = 222222; authMessageProcessor->authResponseContext_->groupName = "333333"; + jsona[TAG_TOKEN] = authMessageProcessor->authResponseContext_->token; jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply; jsona[TAG_DEVICE_ID] = authMessageProcessor->authResponseContext_->deviceId; jsona[PIN_CODE_KEY] = authMessageProcessor->authResponseContext_->code; @@ -201,6 +212,8 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::T authResponseContext->requestId = 2; authResponseContext->groupId = "23456"; authResponseContext->groupName = "34567"; + authResponseContext->token = "11123"; + jsona[TAG_TOKEN] = authResponseContext->token; jsona[TAG_REPLY] = authResponseContext->reply; jsona[TAG_DEVICE_ID] = authResponseContext->deviceId; jsona[PIN_CODE_KEY] = authResponseContext->code; @@ -303,6 +316,12 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::Test nlohmann::json jsonObj; jsonObj[TAG_CRYPTO_SUPPORT] = "CRYPTOSUPPORT"; jsonObj[TAG_CRYPTO_SUPPORT] = authMessageProcessor->authResponseContext_->cryptoSupport; + authResponseContext->localDeviceId = "22"; + authResponseContext->authType = 1; + authResponseContext->reply = 33; + jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType; + jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId; + jsonObj[TAG_REPLY] = authResponseContext->reply; authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); @@ -324,8 +343,14 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::Test std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsonObj; + authResponseContext->localDeviceId = "22"; + authResponseContext->authType = 1; + authResponseContext->reply = 33; jsonObj[TAG_CRYPTO_NAME] = "CRYPTONAME"; jsonObj[TAG_CRYPTO_NAME] = authResponseContext->cryptoSupport; + jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType; + jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId; + jsonObj[TAG_REPLY] = authResponseContext->reply; authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); @@ -347,8 +372,14 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::Test std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsonObj; + authResponseContext->localDeviceId = "22"; + authResponseContext->authType = 1; + authResponseContext->reply = 33; jsonObj[TAG_CRYPTO_VERSION] = "CRYPTOVERSION"; jsonObj[TAG_CRYPTO_VERSION] = authResponseContext->cryptoSupport; + jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType; + jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId; + jsonObj[TAG_REPLY] = authResponseContext->reply; authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); @@ -370,8 +401,14 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::Test std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsonObj; + authResponseContext->localDeviceId = "22"; + authResponseContext->authType = 1; + authResponseContext->reply = 33; jsonObj[TAG_DEVICE_ID] = "DEVICEID"; jsonObj[TAG_DEVICE_ID] = authResponseContext->deviceId; + jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType; + jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId; + jsonObj[TAG_REPLY] = authResponseContext->reply; authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); @@ -393,8 +430,14 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::Test std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsonObj; + authResponseContext->localDeviceId = "22"; + authResponseContext->authType = 1; + authResponseContext->reply = 33; jsonObj[TAG_LOCAL_DEVICE_ID] = "LOCALDEVICEID"; jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId; + jsonObj[TAG_AUTH_TYPE] = authResponseContext->authType; + jsonObj[TAG_LOCAL_DEVICE_ID] = authResponseContext->localDeviceId; + jsonObj[TAG_REPLY] = authResponseContext->reply; authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); diff --git a/test/unittest/UTTest_device_message.h b/test/unittest/UTTest_auth_message_processor.h similarity index 100% rename from test/unittest/UTTest_device_message.h rename to test/unittest/UTTest_auth_message_processor.h diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index ff0249f9d..8beb4ea3b 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -15,6 +15,7 @@ #include "UTTest_auth_request_state.h" +#include "auth_message_processor.h" #include "dm_auth_manager.h" #include "dm_constants.h" @@ -112,14 +113,21 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); std::shared_ptr context = std::make_shared(); - std::shared_ptr authRequestState = std::make_shared(); - authManager->authRequestState_ = std::make_shared(); + std::shared_ptr authRequestState = std::make_shared(); + std::shared_ptr negotiateStartTimer = std::make_shared(NEGOTIATE_TIMEOUT_TASK); + authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = negotiateStartTimer; + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); + authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); + authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); context->sessionId = 123456; + authManager->SetAuthRequestState(authRequestState); + authManager->RegisterCallback(); authRequestState->SetAuthContext(context); authRequestState->SetAuthManager(authManager); - int32_t ret = authRequestState->TransitionTo(std::make_shared()); + int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); sleep(20); } @@ -222,7 +230,7 @@ HWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0) } /** - * @tc.name: AuthRequestNegotiateState::Enter_002 + * @tc.name: AuthRequestNegotiateState::Enter_004 * @tc.desc: 1 set authManager not null * 2 call AuthRequestNegotiateState::Enter with authManager != null * 3 check ret is DM_OK @@ -241,6 +249,8 @@ HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authRequestState_ = std::make_shared(); authManager->authRequestContext_->deviceId = "111"; + authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); + authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authRequestState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); context->deviceId = "123456"; @@ -307,6 +317,9 @@ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); + authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); + authManager->RegisterCallback(); + authManager->SetAuthRequestState(authRequestState); authRequestState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); context->sessionId = 333333; @@ -485,32 +498,29 @@ HWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) { + printf("1\n"); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); std::shared_ptr authRequestState = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); - authManager->timerMap_[ADD_TIMEOUT_TASK] = joinStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); - nlohmann::json jsonObject; authManager->authResponseContext_->groupId = "111"; authManager->authResponseContext_->groupName = "222"; authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; - jsonObject[TAG_GROUP_ID] = authManager->authResponseContext_->groupId; - jsonObject[TAG_GROUP_NAME] = authManager->authResponseContext_->groupName; - jsonObject[PIN_CODE_KEY] = authManager->authResponseContext_->code; - jsonObject[TAG_REQUEST_ID] = authManager->authResponseContext_->requestId; - jsonObject[TAG_DEVICE_ID] = authManager->authResponseContext_->deviceId; + printf("3\n"); authRequestState->SetAuthManager(authManager); + authManager->SetAuthRequestState(authRequestState); + authManager->RegisterCallback(); std::shared_ptr context = std::make_shared(); + printf("4\n"); context->deviceId = "44444"; context->sessionId = 55555; authRequestState->SetAuthContext(context); + printf("5\n"); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); sleep(15); @@ -561,6 +571,7 @@ HWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) { + printf("1\n"); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); @@ -571,9 +582,14 @@ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authRequestState_ = std::make_shared(); + authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); + authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); + authManager->RegisterCallback(); authManager->SetAuthRequestState(authRequestState); + printf("3\n"); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); + printf("4\n"); ASSERT_EQ(ret, DM_OK); sleep(15); } diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index e4dea5309..5e4b67166 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -15,6 +15,7 @@ #include "UTTest_auth_response_state.h" +#include "auth_message_processor.h" #include "auth_response_state.h" #include "dm_auth_manager.h" #include "dm_constants.h" @@ -36,6 +37,7 @@ void AuthResponseStateTest::TearDownTestCase() } namespace { + /** * @tc.name: AuthResponseInitState::SetAuthManager_001 * @tc.desc: 1 set authManager not null @@ -89,7 +91,7 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_001, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); authManager = nullptr; authResponseState->authManager_ = authManager; - int32_t ret = authResponseState->TransitionTo(std::make_shared();); + int32_t ret = authResponseState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_FAILED); sleep(15); } @@ -107,15 +109,15 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_002, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr context = std::make_shared(); - std::shared_ptr authRequestState = std::make_shared(); - authManager->authRequestState_ = std::make_shared(); - authManager->authRequestContext_ = std::make_shared(); + std::shared_ptr context = std::make_shared(); + std::shared_ptr authResponseState = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); context->sessionId = 123456; - authRequestState->SetAuthContext(context); - authRequestState->SetAuthManager(authManager); - int32_t ret = authRequestState->TransitionTo(std::make_shared()); + authResponseState->SetAuthContext(context); + authResponseState->SetAuthManager(authManager); + int32_t ret = authResponseState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); sleep(20); } @@ -208,6 +210,9 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->deviceId = "111"; authManager->authResponseContext_->localDeviceId = "222"; + authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); + authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); + authManager->RegisterCallback(); authResponseState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); context->deviceId = "123456"; @@ -317,14 +322,16 @@ HWTEST_F(AuthResponseStateTest, Enter_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_007, testing::ext::TestSize.Level0) { + printf("1\n"); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); std::shared_ptr authResponseState = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - authManager->authRequestContext_ = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); + printf("2\n"); authResponseState->SetAuthManager(authManager); + printf("3\n"); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); sleep(15); diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 9442ac7c1..b47ad8fbe 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -222,7 +222,7 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_001, testing::ext::TestSiz std::string pkgName = "com.ohos.test"; std::string extra = "jdddd"; int32_t authType = 0; - std::string deviceId = " 2345"; + std::string deviceId = "2345"; int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra); EXPECT_EQ(ret, DM_NOT_INIT); } @@ -246,11 +246,27 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_002, testing::ext::TestSiz /** * @tc.name: AuthenticateDevice_003 - * @tc.desc: Set intFlag for GAuthenticateDevice to true and pkgName to com.ohos.test; The return value is DM_OK + * @tc.desc: Set intFlag for GAuthenticateDevice to True and deviceId to null; The return value is DM_INPUT_PARA_EMPTY * @tc.type: FUNC * @tc.require: AR000GHSJK */ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_003, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = "com.ohos.test"; + std::string extra = "jdddd"; + int32_t authType = 0; + std::string deviceId; + int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} +/** + * @tc.name: AuthenticateDevice_004 + * @tc.desc: Set intFlag for GAuthenticateDevice to true and pkgName to com.ohos.test; The return value is DM_AUTH_NOT_SUPPORT + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_004, testing::ext::TestSize.Level0) { DeviceManagerService::GetInstance().intFlag_ = true; std::string pkgName = "com.ohos.test"; @@ -258,7 +274,7 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_003, testing::ext::TestSiz int32_t authType = 0; std::string deviceId = "123456"; int ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra); - EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(ret, DM_AUTH_NOT_SUPPORT); } /** diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index ae66dea13..3cef42c3f 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -79,7 +79,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_001, testing::ext::TestS std::string deviceId = "dkdkd"; std::string token = "kdkddk"; int32_t status = 3; - std::string reason = "kddk"; + int32_t reason = 2006; listener_->OnAuthResult(pkgName, deviceId, token, status, reason); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index 090b642f6..a4264d1b1 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -38,222 +38,13 @@ void DmAuthManagerTest::TearDownTestCase() } namespace { + std::string AUTHENTICATE_TIMEOUT_TASK = "authenticateTimeoutTask"; std::string NEGOTIATE_TIMEOUT_TASK = "negotiateTimeoutTask"; std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; -/** - * @tc.name: DmAuthManager::AuthenticateDevice_001 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_AUTH_BUSINESS_BUSY - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::make_shared(); - std::shared_ptr context = std::make_shared(); - std::string pkgName = "111"; - int32_t authType = 1; - std::string deviceId = "222"; - std::string extra = "333"; - authRequestState->SetAuthContext(context); - authManager->SetAuthRequestState(authRequestState); - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_AUTH_BUSINESS_BUSY); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_002 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_AUTH_BUSINESS_BUSY - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_002, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::make_shared(); - std::shared_ptr context = std::make_shared(); - const std::string pkgName = "111"; - int32_t authType = 1; - const std::string deviceId = "222"; - const std::string extra = "333"; - authResponseState->SetAuthContext(context); - authManager->SetAuthResponseState(authResponseState); - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_AUTH_BUSINESS_BUSY); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_003 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_INPUT_PARA_EMPTY - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_003, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr sessionSession = std::shared_ptr(); - std::shared_ptr authRequestContext = std::make_shared(); - std::string pkgName = "111"; - int32_t authType = 1; - std::string deviceId = "222"; - std::string extra = ""; - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_INPUT_PARA_EMPTY); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_004 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_INPUT_PARA_EMPTY - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_004, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr sessionSession = std::shared_ptr(); - std::shared_ptr authRequestContext = std::make_shared(); - nlohmann::json json; - const std::string pkgName = "111"; - int32_t authType = 4; - const std::string deviceId = "222"; - const std::string extra = "targetPkgName"; - authRequestContext->targetPkgName = "targetPkgName"; - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_INPUT_PARA_EMPTY); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_005 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_005, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr sessionSession = std::shared_ptr(); - std::shared_ptr authRequestContext = std::make_shared(); - nlohmann::json json; - const std::string pkgName = "111"; - int32_t authType = 1; - const std::string deviceId = "222"; - const std::string extra = "targetPkgName"; - authRequestContext->targetPkgName = "targetPkgName"; - json[TARGET_PKG_NAME_KEY] = authRequestContext->targetPkgName; - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_006 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_006, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr sessionSession = std::shared_ptr(); - std::shared_ptr authRequestContext = std::make_shared(); - nlohmann::json json; - const std::string pkgName = "111"; - int32_t authType = 1; - const std::string deviceId = "222"; - const std::string extra = "appName"; - authRequestContext->targetPkgName = "appName"; - json[APP_NAME_KEY] = authRequestContext->targetPkgName; - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_007 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_007, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr sessionSession = std::shared_ptr(); - std::shared_ptr authRequestContext = std::make_shared(); - nlohmann::json json; - const std::string pkgName = "111"; - int32_t authType = 1; - const std::string deviceId = "222"; - const std::string extra = "appDescription"; - authRequestContext->targetPkgName = "appDescription"; - json[APP_DESCRIPTION_KEY] = authRequestContext->targetPkgName; - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_008 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_008, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr sessionSession = std::shared_ptr(); - std::shared_ptr authRequestContext = std::make_shared(); - nlohmann::json json; - const std::string pkgName = "111"; - int32_t authType = 1; - const std::string deviceId = "222"; - const std::string extra = "appThumbnail"; - authRequestContext->targetPkgName = "appThumbnail"; - json[APP_THUMBNAIL] = authRequestContext->targetPkgName; - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: DmAuthManager::AuthenticateDevice_009 - * @tc.desc: Call authenticatedevice to check whether the return value is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, AuthenticateDevice_009, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr sessionSession = std::shared_ptr(); - std::shared_ptr authRequestContext = std::make_shared(); - nlohmann::json json; - const std::string pkgName = "111"; - int32_t authType = 1; - const std::string deviceId = "222"; - const std::string extra = "appIcon"; - authRequestContext->targetPkgName = "appIcon"; - json[APP_ICON_KEY] = authRequestContext->targetPkgName; - int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); - ASSERT_EQ(ret, DM_OK); -} - /** * @tc.name: DmAuthManager::UnAuthenticateDevice_001 * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_ FAILED @@ -273,29 +64,6 @@ HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Lev ASSERT_EQ(ret, DM_FAILED); } -/** - * @tc.name: DmAuthManager::VerifyAuthentication_001 - * @tc.desc: Call verifyauthentication to check whether the return value is DM_ FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, VerifyAuthentication_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::make_shared(); - std::shared_ptr negotiateStartTimer = std::make_shared(INPUT_TIMEOUT_TASK); - authManager->timerMap_[INPUT_TIMEOUT_TASK] = negotiateStartTimer; - authManager->authResponseContext_ = std::make_shared(); - authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::make_shared(); - authManager->authResponseContext_ = nullptr; - authManager->SetAuthRequestState(authRequestState); - int32_t ret = authManager->HandleAuthenticateTimeout(); - ASSERT_EQ(ret, DM_FAILED); -} - /** * @tc.name: DmAuthManager::HandleAuthenticateTimeout_001 * @tc.desc: authResponseContext_= nullptr; Call handleauthenticatemeout to check whether the return value is DM_FAILED @@ -355,32 +123,7 @@ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Lev authManager->authRequestState_ = std::make_shared(); std::string deviceId1; int32_t ret = authManager->EstablishAuthChannel(deviceId1); - ASSERT_EQ(ret, DM_FAILED); -} - -/** - * @tc.name: DmAuthManager::SendAuthRequest_001 - * @tc.desc: Cryptosupport = true call sendauthrequest to check whether the return value is DM_ FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, SendAuthRequest_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::make_shared(); - std::shared_ptr negotiateStartTimer = std::make_shared(NEGOTIATE_TIMEOUT_TASK); - authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = negotiateStartTimer; - authManager->authMessageProcessor_ = std::make_shared(authManager); - authManager->authResponseContext_ = std::make_shared(); - ; - authManager->authRequestState_ = std::make_shared(); - authManager->authResponseContext_->cryptoSupport = true; - authManager->SetAuthRequestState(authRequestState); - int32_t sessionId = 1; - int32_t ret = authManager->SendAuthRequest(sessionId); - ASSERT_EQ(ret, DM_FAILED); + ASSERT_EQ(ret,DM_OK); } /** @@ -415,12 +158,13 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::make_shared(); + std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authResponseState_ = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->SetAuthResponseState(authResponseState); + authManager->RegisterCallback(); authManager->authResponseContext_->sessionId = 111; int32_t action = 1; int32_t ret = authManager->StartAuthProcess(action); @@ -447,8 +191,7 @@ HWTEST_F(DmAuthManagerTest, CreateGroup_001, testing::ext::TestSize.Level0) authManager->SetAuthResponseState(authResponseState); authManager->authResponseContext_->requestId = 111; authManager->authResponseContext_->groupName = "111"; - int32_t action = 1; - int32_t ret = authManager->StartAuthProcess(action); + int32_t ret = authManager->CreateGroup(); ASSERT_EQ(ret, DM_OK); } @@ -482,6 +225,7 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) jsonObject[TAG_REQUEST_ID] = authManager->authResponseContext_->requestId; jsonObject[TAG_DEVICE_ID] = authManager->authResponseContext_->deviceId; std::string deviceId = "44444"; + authManager->RegisterCallback(); authManager->SetAuthResponseState(authResponseState); int32_t ret = authManager->AddMember(deviceId); ASSERT_EQ(ret, DM_OK); @@ -511,23 +255,6 @@ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } -/** - * @tc.name: DmAuthManager::GetIsCryptoSupport_001 - * @tc.desc: authResponseState_ Equal to nullptr - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - authManager->authResponseState_ = std::make_shared(); - bool isCryptoSupport = false; - int32_t ret = authManager->GetIsCryptoSupport(isCryptoSupport); - ASSERT_EQ(ret, DM_OK); -} - /** * @tc.name: DmAuthManager::SetAuthResponseState_001 * @tc.desc: Is the authresponsestate assignment successful diff --git a/test/unittest/UTTest_dm_device_state_manager.cpp b/test/unittest/UTTest_dm_device_state_manager.cpp index ab9ba7537..83b6eb9c0 100644 --- a/test/unittest/UTTest_dm_device_state_manager.cpp +++ b/test/unittest/UTTest_dm_device_state_manager.cpp @@ -147,7 +147,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnProfileReady_001, testing::ext::TestSize.Le std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo ret = pReq->GetDeviceInfo(); int result = strcmp(info.deviceId, ret.deviceId); - ASSERT_GE(result, 0); + ASSERT_NE(result, 0); } /** @@ -166,7 +166,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceReady_001, testing::ext::TestSize.Lev std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo ret = pReq->GetDeviceInfo(); int result = strcmp(info.deviceId, ret.deviceId); - ASSERT_GE(result, 0); + ASSERT_NE(result, 0); } /** @@ -185,7 +185,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceChanged_002, testing::ext::TestSize.L std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo ret = pReq->GetDeviceInfo(); int result = strcmp(info.deviceId, ret.deviceId); - ASSERT_GE(result, 0); + ASSERT_NE(result, 0); } /** diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp index 88006a20e..58cbf0f41 100644 --- a/test/unittest/UTTest_hichain_connector.cpp +++ b/test/unittest/UTTest_hichain_connector.cpp @@ -41,6 +41,11 @@ void HichainConnectorTest::TearDownTestCase() { } namespace { + +std::shared_ptr listener_ = std::make_shared(); +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); + /** * @tc.name: CreateGroup_001 * @tc.desc: Set the deviceGroupManager_ pointer to CreateGroup to NULlptr and return DM_INVALID_VALUE @@ -256,9 +261,6 @@ HWTEST_F(HichainConnectorTest, HiChainConnector_002, testing::ext::TestSize.Leve */ HWTEST_F(HichainConnectorTest, RegisterHiChainCallback_001, testing::ext::TestSize.Level0) { - std::shared_ptr listener_ = std::make_shared(); - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); std::shared_ptr hichainConnector = std::make_shared(); int ret = hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); @@ -352,9 +354,6 @@ HWTEST_F(HichainConnectorTest, onRequest_001, testing::ext::TestSize.Level0) */ HWTEST_F(HichainConnectorTest, GetConnectPara_001, testing::ext::TestSize.Level0) { - std::shared_ptr listener_ = std::make_shared(); - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); std::shared_ptr hichainConnector = std::make_shared(); hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); std::string deviceId = "23445"; @@ -374,9 +373,6 @@ HWTEST_F(HichainConnectorTest, GetConnectPara_002, testing::ext::TestSize.Level0 { std::string deviceId; std::string reqDeviceId = "234566"; - std::shared_ptr listener_ = std::make_shared(); - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); std::shared_ptr hichainConnector = std::make_shared(); hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); std::string ret = hichainConnector->GetConnectPara(deviceId, reqDeviceId); @@ -413,12 +409,12 @@ HWTEST_F(HichainConnectorTest, GetRelatedGroups_001, testing::ext::TestSize.Leve } /** - * @tc.name: GetRelatedGroups_003 + * @tc.name: GetRelatedGroups_002 * @tc.desc: set DeviceId = 12345,groupList null and return DM_FAILED * @tc.type: FUNC * @tc.require: AR000GHSJK */ -HWTEST_F(HichainConnectorTest, GetRelatedGroups_003, testing::ext::TestSize.Level0) +HWTEST_F(HichainConnectorTest, GetRelatedGroups_002, testing::ext::TestSize.Level0) { std::string DeviceId = "12345"; std::vector groupList; diff --git a/test/unittest/UTTest_softbus_session.cpp b/test/unittest/UTTest_softbus_session.cpp index 1132c6394..377c4ed8f 100644 --- a/test/unittest/UTTest_softbus_session.cpp +++ b/test/unittest/UTTest_softbus_session.cpp @@ -38,6 +38,9 @@ void SoftbusSessionTest::TearDownTestCase() namespace { std::shared_ptr softbusSession = std::make_shared(); +std::shared_ptr listener_ = std::make_shared(); +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); /** * @tc.name: OpenAuthSession_001 @@ -67,7 +70,7 @@ HWTEST_F(SoftbusSessionTest, OpenAuthSession_002, testing::ext::TestSize.Level0) /** * @tc.name: SendData_001 - * @tc.desc: set message null and return DM_FAILED + * @tc.desc: set message null and return DM_FAILED * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -81,7 +84,7 @@ HWTEST_F(SoftbusSessionTest, SendData_001, testing::ext::TestSize.Level0) /** * @tc.name: SendData_002 - * @tc.desc: set sessionId = 0 ,go to the SendBytes'smaster and return DM_FAILED + * @tc.desc: set sessionId = 0 ,go to the SendBytes'smaster and return DM_FAILED * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -93,24 +96,11 @@ HWTEST_F(SoftbusSessionTest, SendData_002, testing::ext::TestSize.Level0) jsonObj[TAG_TYPE] = msgType; std::string message = jsonObj.dump(); int32_t sessionId = 0; + softbusSession->RegisterSessionCallback(std::shared_ptr(discoveryMgr_)); int ret = softbusSession->SendData(sessionId, message); EXPECT_EQ(ret, DM_FAILED); } -/** - * @tc.name: OnSessionOpened_001 - * @tc.desc: set result = 0,sessionId = -1;and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(SoftbusSessionTest, OnSessionOpened_001, testing::ext::TestSize.Level0) -{ - int result = 0; - int32_t sessionId = -1; - int ret = softbusSession->OnSessionOpened(sessionId, result); - EXPECT_EQ(ret, DM_OK); -} - /** * @tc.name: SoftbusSession_001 * @tc.desc: set SoftbusSession to make a new pointer ,and it not nullptr @@ -171,7 +161,6 @@ HWTEST_F(SoftbusSessionTest, GetPeerDeviceId_001, testing::ext::TestSize.Level0) */ HWTEST_F(SoftbusSessionTest, UnRegisterSessionCallback_001, testing::ext::TestSize.Level0) { - std::string pkgName = "softbus"; int ret = softbusSession->UnRegisterSessionCallback(); EXPECT_EQ(ret, DM_OK); } diff --git a/test/unittest/UTTest_softbus_session.h b/test/unittest/UTTest_softbus_session.h index 5497647ba..2ca9afad3 100644 --- a/test/unittest/UTTest_softbus_session.h +++ b/test/unittest/UTTest_softbus_session.h @@ -31,6 +31,8 @@ #include "session.h" #include "softbus_session.h" #include "softbus_session_callback.h" +#include "dm_auth_manager.h" +#include "auth_response_state.h" namespace OHOS { namespace DistributedHardware { diff --git a/test/unittest/auth_response_state.cpp b/test/unittest/auth_response_state.cpp new file mode 100644 index 000000000..14f7c2c3b --- /dev/null +++ b/test/unittest/auth_response_state.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "auth_response_state.h" + +#include "dm_auth_manager.h" +#include "dm_constants.h" +#include "dm_log.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t AuthResponseState::Leave() +{ + return DM_OK; +} + +int32_t AuthResponseState::SetAuthContext(std::shared_ptr context) +{ + context_ = std::move(context); + return DM_OK; +} + +std::shared_ptr AuthResponseState::GetAuthContext() +{ + return context_; +} + +int32_t AuthResponseState::SetAuthManager(std::shared_ptr authManager) +{ + authManager_ = std::move(authManager); + return DM_OK; +} + +int32_t AuthResponseState::TransitionTo(std::shared_ptr state) +{ + LOGI("AuthRequestState:: TransitionTo"); + std::shared_ptr stateAuthManager = authManager_.lock(); + if (stateAuthManager == nullptr) { + LOGE("AuthRequestState::authManager_ null"); + return DM_FAILED; + } + state->SetAuthManager(stateAuthManager); + stateAuthManager->SetAuthResponseState(state); + state->SetAuthContext(context_); + this->Leave(); + state->Enter(); + return DM_OK; +} + +int32_t AuthResponseInitState::GetStateType() +{ + return AuthState::AUTH_RESPONSE_INIT; +} + +int32_t AuthResponseInitState::Enter() +{ + LOGI("AuthResponse:: AuthResponseInitState Enter"); + return DM_OK; +} + +int32_t AuthResponseNegotiateState::GetStateType() +{ + return AuthState::AUTH_RESPONSE_NEGOTIATE; +} + +int32_t AuthResponseNegotiateState::Enter() +{ + std::shared_ptr stateAuthManager = authManager_.lock(); + if (stateAuthManager == nullptr) { + LOGE("AuthRequestState::authManager_ null"); + return DM_FAILED; + } + stateAuthManager->RespNegotiate(context_->sessionId); + return DM_OK; +} + +int32_t AuthResponseConfirmState::GetStateType() +{ + return AuthState::AUTH_RESPONSE_CONFIRM; +} + +int32_t AuthResponseConfirmState::Enter() +{ + LOGI("AuthResponse:: AuthResponseConfirmState Enter"); + std::shared_ptr stateAuthManager = authManager_.lock(); + if (stateAuthManager == nullptr) { + LOGE("AuthRequestState::authManager_ null"); + return DM_FAILED; + } + stateAuthManager->ShowConfigDialog(); + return DM_OK; +} + +int32_t AuthResponseGroupState::GetStateType() +{ + return AuthState::AUTH_RESPONSE_GROUP; +} + +int32_t AuthResponseGroupState::Enter() +{ + LOGI("AuthResponse:: AuthResponseGroupState Enter"); + std::shared_ptr stateAuthManager = authManager_.lock(); + if (stateAuthManager == nullptr) { + LOGE("AuthRequestState::authManager_ null"); + return DM_FAILED; + } + stateAuthManager->CreateGroup(); + return DM_OK; +} + +int32_t AuthResponseShowState::GetStateType() +{ + return AuthState::AUTH_RESPONSE_SHOW; +} + +int32_t AuthResponseShowState::Enter() +{ + std::shared_ptr stateAuthManager = authManager_.lock(); + if (stateAuthManager == nullptr) { + LOGE("AuthRequestState::authManager_ null"); + return DM_FAILED; + } + stateAuthManager->ShowAuthInfoDialog(); + return DM_OK; +} + +int32_t AuthResponseFinishState::GetStateType() +{ + return AuthState::AUTH_RESPONSE_FINISH; +} + +int32_t AuthResponseFinishState::Enter() +{ + std::shared_ptr stateAuthManager = authManager_.lock(); + if (stateAuthManager == nullptr) { + LOGE("AuthRequestState::authManager_ null"); + return DM_FAILED; + } + stateAuthManager->AuthenticateFinish(); + return DM_OK; +} +} // namespace DistributedHardware +} // namespace OHOS -- Gitee From c7c381f8fecc290130e66dd0700a87a5e8b3dea2 Mon Sep 17 00:00:00 2001 From: caochao <2930650069@qq.com> Date: Mon, 17 Jan 2022 22:53:32 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=A4=9A=E7=94=A8=E6=88=B7=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=90=88=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cao_liu_chao --- .../include/authentication/dm_auth_manager.h | 1 + .../commonevent/dm_common_event_manager.h | 10 +++++---- .../dependency/hichain/hichain_connector.h | 3 +-- .../include/device_manager_service.h | 7 +++--- .../src/authentication/dm_auth_manager.cpp | 20 +++++++++++++++++ .../commonevent/dm_common_event_manager.cpp | 2 +- .../src/device_manager_service.cpp | 22 +++++++++++++++++++ 7 files changed, 55 insertions(+), 10 deletions(-) diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 1295ebb88..e30b9cb3b 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -160,6 +160,7 @@ public: int32_t GetAuthenticationParam(DmAuthParam &authParam); int32_t RegisterCallback(); int32_t OnUserOperation(int32_t action); + void UserSwitchEventCallback(void); private: std::shared_ptr softbusConnector_; diff --git a/services/devicemanagerservice/include/dependency/commonevent/dm_common_event_manager.h b/services/devicemanagerservice/include/dependency/commonevent/dm_common_event_manager.h index 9cf9f8857..7efcbb5f5 100644 --- a/services/devicemanagerservice/include/dependency/commonevent/dm_common_event_manager.h +++ b/services/devicemanagerservice/include/dependency/commonevent/dm_common_event_manager.h @@ -16,6 +16,7 @@ #ifndef OHOS_EVENT_MANAGER_ADAPT_H #define OHOS_EVENT_MANAGER_ADAPT_H +#include #include #include @@ -30,18 +31,19 @@ namespace OHOS { namespace DistributedHardware { -using CommomEventCallback = void (*)(void); +using CommomEventCallback = std::function; class DmCommonEventManager { DECLARE_SINGLE_INSTANCE_BASE(DmCommonEventManager); public: - bool SubscribeServiceEvent(const std::string &event, CommomEventCallback callback); + bool SubscribeServiceEvent(const std::string &event, const CommomEventCallback &callback); bool UnsubscribeServiceEvent(const std::string &event); void Test(const std::string &event); class EventSubscriber : public EventFwk::CommonEventSubscriber { public: - EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, CommomEventCallback callback, - std::string event) : EventFwk::CommonEventSubscriber(subscribeInfo), callback_(callback), event_(event) {} + EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, const CommomEventCallback &callback, + const std::string &event) : EventFwk::CommonEventSubscriber(subscribeInfo), + callback_(callback), event_(event) {} void OnReceiveEvent(const EventFwk::CommonEventData &data); void TestCommonEvent(const std::string &event); private: diff --git a/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h index caffbffe9..0d514be7a 100644 --- a/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h +++ b/services/devicemanagerservice/include/dependency/hichain/hichain_connector.h @@ -61,12 +61,11 @@ public: int32_t DeleteGroup(std::string &groupId); bool IsDevicesInGroup(std::string hostDevice, std::string peerDevice); int32_t GetRelatedGroups(std::string DeviceId, std::vector &groupList); - + int32_t GetGroupInfo(std::string queryParams, std::vector &groupList); private: int64_t GenRequestId(); int32_t SyncGroups(std::string deviceId, std::vector &remoteGroupIdList); int32_t GetSyncGroupList(std::vector &groupList, std::vector &syncGroupList); - int32_t GetGroupInfo(std::string queryParams, std::vector &groupList); std::string GetConnectPara(std::string deviceId, std::string reqDeviceId); bool IsGroupCreated(std::string groupName, GroupInfo &groupInfo); bool IsGroupInfoInvalid(GroupInfo &group); diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/device_manager_service.h index 53e33b1d6..739c4f175 100644 --- a/services/devicemanagerservice/include/device_manager_service.h +++ b/services/devicemanagerservice/include/device_manager_service.h @@ -31,10 +31,10 @@ namespace OHOS { namespace DistributedHardware { class DeviceManagerService { - DECLARE_SINGLE_INSTANCE(DeviceManagerService); - +DECLARE_SINGLE_INSTANCE_BASE(DeviceManagerService); public: int32_t Init(); + ~DeviceManagerService(); int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList); int32_t GetLocalDeviceInfo(DmDeviceInfo &info); @@ -49,8 +49,9 @@ public: int32_t VerifyAuthentication(const std::string &authParam); int32_t GetFaParam(std::string &pkgName, DmAuthParam &authParam); int32_t SetUserOperation(std::string &pkgName, int32_t action); - private: + DeviceManagerService() = default; +private: bool intFlag_ = false; std::shared_ptr authMgr_; std::shared_ptr deviceInfoMgr_; diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index f2c246b09..048a78c45 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -720,5 +720,25 @@ int32_t DmAuthManager::OnUserOperation(int32_t action) } return DM_OK; } + +void DmAuthManager::UserSwitchEventCallback (void) +{ + LOGI("all groups from this device will be deleted"); + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP; + std::string queryParams = jsonObj.dump(); + std::vector groupList; + int32_t ret = hiChainConnector_->GetGroupInfo(queryParams, groupList); + if (ret != DM_OK) { + LOGE("failed to get device join groups"); + return; + } + for (auto iter = groupList.begin(); iter != groupList.end(); iter++) { + ret = hiChainConnector_->DeleteGroup(iter->groupId); + if (ret != DM_OK) { + LOGE("fail to delete group"); + } + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/dependency/commonevent/dm_common_event_manager.cpp b/services/devicemanagerservice/src/dependency/commonevent/dm_common_event_manager.cpp index ab66d98e1..661404a30 100644 --- a/services/devicemanagerservice/src/dependency/commonevent/dm_common_event_manager.cpp +++ b/services/devicemanagerservice/src/dependency/commonevent/dm_common_event_manager.cpp @@ -61,7 +61,7 @@ void DmCommonEventManager::DealCallback(void) } } -bool DmCommonEventManager::SubscribeServiceEvent(const std::string &event, CommomEventCallback callback) +bool DmCommonEventManager::SubscribeServiceEvent(const std::string &event, const CommomEventCallback &callback) { LOGI("Subscribe event: %s", event.c_str()); if (dmEventSubscriber_.find(event) != dmEventSubscriber_.end() || callback == nullptr) { diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 2ae58c33b..9876035ae 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -15,15 +15,30 @@ #include "device_manager_service.h" +#include + #include "device_manager_service_listener.h" #include "dm_constants.h" #include "dm_device_info_manager.h" #include "dm_log.h" +#include "common_event_support.h" +#include "dm_common_event_manager.h" + +using namespace OHOS::EventFwk; namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DeviceManagerService); +DeviceManagerService::~DeviceManagerService() +{ + LOGI("DeviceManagerService destructor"); + DmCommonEventManager &dmCommonEventManager = DmCommonEventManager::GetInstance(); + if (dmCommonEventManager.UnsubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED)) { + LOGI("subscribe service event success"); + } +} + int32_t DeviceManagerService::Init() { if (intFlag_) { @@ -74,6 +89,13 @@ int32_t DeviceManagerService::Init() } authMgr_->RegisterCallback(); } + + DmCommonEventManager &dmCommonEventManager = DmCommonEventManager::GetInstance(); + CommomEventCallback callback = std::bind(&DmAuthManager::UserSwitchEventCallback, *authMgr_.get()); + if (dmCommonEventManager.SubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED, callback)) { + LOGI("subscribe service event success"); + } + LOGI("Init success, singleton initialized"); intFlag_ = true; return DM_OK; -- Gitee From d1dce1a4781b815b2e8a2f7a4fc34398ed620439 Mon Sep 17 00:00:00 2001 From: puhui Date: Mon, 17 Jan 2022 23:16:19 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E7=A8=8B?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: puhui --- ...hos.distributedHardware.deviceManager.d.ts | 176 +++++++++--------- .../include/device_manager_service.h | 1 - .../src/authentication/dm_auth_manager.cpp | 12 +- .../src/device_manager_service.cpp | 4 +- .../UTTest_auth_message_processor.cpp | 1 - test/unittest/UTTest_auth_response_state.cpp | 1 - .../UTTest_device_manager_service.cpp | 2 +- test/unittest/UTTest_dm_auth_manager.cpp | 3 +- test/unittest/UTTest_hichain_connector.cpp | 1 - 9 files changed, 100 insertions(+), 101 deletions(-) diff --git a/display/@ohos.distributedHardware.deviceManager.d.ts b/display/@ohos.distributedHardware.deviceManager.d.ts index 604936a6e..69179ba17 100644 --- a/display/@ohos.distributedHardware.deviceManager.d.ts +++ b/display/@ohos.distributedHardware.deviceManager.d.ts @@ -15,9 +15,18 @@ import { AsyncCallback, Callback } from './basic'; +/** + * Providers interfaces to creat a {@link deviceManager} instances. + * + * @since 7 + * @Syscap SystemCapability.DISTRIBUTEDHARDWARE.deviceManager + * + */ declare namespace deviceManager { /** * DeviceInfo + * + * @systemapi this method can be used only by system applications. */ interface DeviceInfo { /** @@ -34,6 +43,13 @@ declare namespace deviceManager { * Device type of the device. */ deviceType: DeviceType; + + /** + * NetworkId of the device. + * + * @since 8 + */ + networkId: string; } /** @@ -78,6 +94,8 @@ declare namespace deviceManager { /** * Device state change event definition + * + * @systemapi this method can be used only by system applications. */ enum DeviceStateChangeAction { /** @@ -221,9 +239,14 @@ declare namespace deviceManager { */ enum SubscribeCap { /** - * ddmpCapability + * ddmpCapability, will be discarded later. Currently, it will be converted to OSD capability inner. + */ + SUBSCRIBE_CAPABILITY_DDMP = 0, + + /** + * One Super Device Capability */ - SUBSCRIBE_CAPABILITY_DDMP = 0 + SUBSCRIBE_CAPABILITY_OSD = 1 } /** @@ -237,21 +260,10 @@ declare namespace deviceManager { */ authType: number; - /** - * App application Icon. - */ - appIcon?: Uint8Array; - - /** - * App application thumbnail. - */ - appThumbnail?: Uint8Array; - /** * Authentication extra infos. */ extraInfo: {[key:string] : any}; - } /** @@ -276,38 +288,6 @@ declare namespace deviceManager { extraInfo: {[key:string] : any}; } - /** - * User Operation Action from devicemanager Fa. - * - * @systemapi this method can be used only by system applications. - */ - enum UserOperationAction { - /** - * allow authentication - */ - ACTION_ALLOW_AUTH = 0, - - /** - * cancel authentication - */ - ACTION_CANCEL_AUTH = 1, - - /** - * user operation timeout for authentication confirm - */ - ACTION_AUTH_CONFIRM_TIMEOUT = 2, - - /** - * cancel pincode display - */ - ACTION_CANCEL_PINCODE_DISPLAY = 3, - - /** - * cancel pincode input - */ - ACTION_CANCEL_PINCODE_INPUT = 4, - } - /** * Creates a {@code DeviceManager} instance. * @@ -316,6 +296,7 @@ declare namespace deviceManager { * * @param bundleName Indicates the bundle name of the application. * @param callback Indicates the callback to be invoked upon {@code DeviceManager} instance creation. + * @systemapi this method can be used only by system applications. */ function createDeviceManager(bundleName: string, callback: AsyncCallback): void; @@ -325,88 +306,109 @@ declare namespace deviceManager { interface DeviceManager { /** * Releases the {@code DeviceManager} instance after the methods for device management are no longer used. + * + * @systemapi this method can be used only by system applications. */ release(): void; /** * Obtains a list of trusted devices. * - * @param options Indicates the extra parameters to be passed to this method for device filtering or sorting. - * This parameter can be null. For details about available values, see {@link #TARGET_PACKAGE_NAME} and - * {@link #SORT_TYPE}. * @return Returns a list of trusted devices. + * @systemapi this method can be used only by system applications. */ getTrustedDeviceListSync(): Array; /** - * Start to discover device. + * Obtains a list of trusted devices. * - * @param bundleName Indicates the bundle name of the application. - * @param subscribeInfo subscribe info to discovery device + * @since 8 + * @param callback Indicates the callback to be invoked upon getTrustedDeviceList + * @return Returns a list of trusted devices. * @systemapi this method can be used only by system applications. */ - startDeviceDiscovery(subscribeInfo: SubscribeInfo): void; + getTrustedDeviceList(callback:AsyncCallback>): void; /** - * Stop to discover device. + * Obtains a list of trusted devices. * - * @param bundleName Indicates the bundle name of the application. - * @param subscribeId Service subscribe ID + * @since 8 + * @return Returns a list of trusted devices. * @systemapi this method can be used only by system applications. */ - stopDeviceDiscovery(subscribeId: number): void; + getTrustedDeviceList(): Promise>; /** - * Authenticate the specified device. + * Obtains local device info * - * @param deviceInfo deviceInfo of device to authenticate - * @param authparam authparam of device to authenticate - * @param callback Indicates the callback to be invoked upon authenticateDevice + * @since 8 + * @return Returns local device info. * @systemapi this method can be used only by system applications. - */ - authenticateDevice(deviceInfo: DeviceInfo, authparam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void; - - /** - * verify auth info, such as pin code. + */ + getLocalDeviceInfoSync(): DeviceInfo; + + /** + * Obtains local device info * - * @param authInfo device auth info o verify - * @param callback Indicates the callback to be invoked upon verifyAuthInfo + * @since 8 + * @param callback Indicates the callback to be invoked upon getLocalDeviceInfo + * @return Returns local device info. * @systemapi this method can be used only by system applications. - */ - verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void; + */ + getLocalDeviceInfo(callback:AsyncCallback): void; /** - * Get authenticate parameters for peer device, this interface can only used by devicemanager Fa. + * Obtains local device info * - * @param authParam authparam for peer device + * @since 8 + * @return Returns local device info. * @systemapi this method can be used only by system applications. - */ - getAuthenticationParam(): AuthParam; + */ + getLocalDeviceInfo(): Promise; - /** - * Set user Operation from devicemanager Fa, this interface can only used by devicemanager Fa. + /** + * Start to discover device. + * + * @param subscribeInfo subscribe info to discovery device + * @systemapi this method can be used only by system applications. + */ + startDeviceDiscovery(subscribeInfo: SubscribeInfo): void; + + /** + * Stop to discover device. * - * @param operateAction User Operation Actions. + * @param subscribeId Service subscribe ID * @systemapi this method can be used only by system applications. - */ - setUserOperation(operateAction: UserOperationAction): void; + */ + stopDeviceDiscovery(subscribeId: number): void; /** - * Register a callback from deviceManager service so that the devicemanager Fa can be notified when some events happen. - * this interface can only used by devicemanager Fa. + * Authenticate the specified device. * - * @param callback for devicemanager Fa to register. + * @param deviceInfo deviceInfo of device to authenticate + * @param authParam authParam of device to authenticate + * @param callback Indicates the callback to be invoked upon authenticateDevice * @systemapi this method can be used only by system applications. */ - on(type: 'dmFaCallback', callback: Callback<{ param: string}>): void; + authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinTone ?: number}>): void; /** - * UnRegister dmFaCallback, this interface can only used by devicemanager Fa. + * unAuthenticate the specified device. + * + * @since 8 + * @param deviceInfo deviceInfo of device to unAuthenticate + * @systemapi this method can be used only by system applications. + */ + unAuthenticateDevice(deviceInfo: DeviceInfo): void + + /** + * verify auth info, such as pin code. * - * @param callback for devicemanager Fa to register. + * @param authInfo device auth info o verify + * @param callback Indicates the callback to be invoked upon verifyAuthInfo * @systemapi this method can be used only by system applications. */ - off(type: 'dmFaCallback', callback?: Callback<{ param: string}>): void; + verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void; /** * Register a device state callback so that the application can be notified upon device state changes based on @@ -414,6 +416,7 @@ declare namespace deviceManager { * * @param bundleName Indicates the bundle name of the application. * @param callback Indicates the device state callback to register. + * @systemapi this method can be used only by system applications. */ on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; @@ -422,6 +425,7 @@ declare namespace deviceManager { * * @param bundleName Indicates the bundle name of the application. * @param callback Indicates the device state callback to register. + * @systemapi this method can be used only by system applications. */ off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; @@ -461,6 +465,7 @@ declare namespace deviceManager { * Register a serviceError callback so that the application can be notified when devicemanager service died * * @param callback Indicates the service error callback to register. + * @systemapi this method can be used only by system applications. */ on(type: 'serviceDie', callback: () => void): void; @@ -468,6 +473,7 @@ declare namespace deviceManager { * UnRegister a serviceError callback so that the application can be notified when devicemanager service died * * @param callback Indicates the service error callback to register. + * @systemapi this method can be used only by system applications. */ off(type: 'serviceDie', callback?: () => void): void; } diff --git a/services/devicemanagerservice/include/device_manager_service.h b/services/devicemanagerservice/include/device_manager_service.h index 739c4f175..8c54e9f3a 100644 --- a/services/devicemanagerservice/include/device_manager_service.h +++ b/services/devicemanagerservice/include/device_manager_service.h @@ -51,7 +51,6 @@ public: int32_t SetUserOperation(std::string &pkgName, int32_t action); private: DeviceManagerService() = default; -private: bool intFlag_ = false; std::shared_ptr authMgr_; std::shared_ptr deviceInfoMgr_; diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index d31850e8a..6b3fcae09 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -88,8 +88,8 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au } if (authRequestState_ != nullptr || authResponseState_ != nullptr) { - LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.",pkgName.c_str()); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_BUSINESS_BUSY); + LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.", pkgName.c_str()); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_BUSINESS_BUSY); return DM_AUTH_BUSINESS_BUSY; } @@ -228,8 +228,8 @@ void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int3 softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); } } else { - if (authResponseState_ == nullptr && authRequestState_ != nullptr && - authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INIT){ + if (authResponseState_ == nullptr && authRequestState_ != nullptr && + authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INIT) { authRequestContext_->sessionId = sessionId; authRequestState_->SetAuthContext(authRequestContext_); authMessageProcessor_->SetRequestContext(authRequestContext_); @@ -729,14 +729,14 @@ int32_t DmAuthManager::OnUserOperation(int32_t action) return DM_OK; } -void DmAuthManager::UserSwitchEventCallback (void) +void DmAuthManager::UserSwitchEventCallback (void) { LOGI("all groups from this device will be deleted"); nlohmann::json jsonObj; jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP; std::string queryParams = jsonObj.dump(); std::vector groupList; - int32_t ret = hiChainConnector_->GetGroupInfo(queryParams, groupList); + int32_t ret = hiChainConnector_->GetGroupInfo(queryParams, groupList); if (ret != DM_OK) { LOGE("failed to get device join groups"); return; diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index 9876035ae..5faa4cca6 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -89,13 +89,11 @@ int32_t DeviceManagerService::Init() } authMgr_->RegisterCallback(); } - DmCommonEventManager &dmCommonEventManager = DmCommonEventManager::GetInstance(); CommomEventCallback callback = std::bind(&DmAuthManager::UserSwitchEventCallback, *authMgr_.get()); if (dmCommonEventManager.SubscribeServiceEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED, callback)) { LOGI("subscribe service event success"); - } - + } LOGI("Init success, singleton initialized"); intFlag_ = true; return DM_OK; diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index b86db8980..b0e7dc352 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -37,7 +37,6 @@ void AuthMessageProcessorTest::TearDownTestCase() } namespace { - /** * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001 * @tc.desc: 1 set cryptoAdapter_ to null diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index 5e4b67166..60b68ec2d 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -37,7 +37,6 @@ void AuthResponseStateTest::TearDownTestCase() } namespace { - /** * @tc.name: AuthResponseInitState::SetAuthManager_001 * @tc.desc: 1 set authManager not null diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index b47ad8fbe..f2af9ddb1 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -262,7 +262,7 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_003, testing::ext::TestSiz } /** * @tc.name: AuthenticateDevice_004 - * @tc.desc: Set intFlag for GAuthenticateDevice to true and pkgName to com.ohos.test; The return value is DM_AUTH_NOT_SUPPORT + * @tc.desc: Set intFlag for GAuthenticateDevice to true and pkgName to com.ohos.test * @tc.type: FUNC * @tc.require: AR000GHSJK */ diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index a4264d1b1..c3da111c0 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -38,7 +38,6 @@ void DmAuthManagerTest::TearDownTestCase() } namespace { - std::string AUTHENTICATE_TIMEOUT_TASK = "authenticateTimeoutTask"; std::string NEGOTIATE_TIMEOUT_TASK = "negotiateTimeoutTask"; std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; @@ -123,7 +122,7 @@ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Lev authManager->authRequestState_ = std::make_shared(); std::string deviceId1; int32_t ret = authManager->EstablishAuthChannel(deviceId1); - ASSERT_EQ(ret,DM_OK); + ASSERT_EQ(ret, DM_OK); } /** diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp index 58cbf0f41..3395fda45 100644 --- a/test/unittest/UTTest_hichain_connector.cpp +++ b/test/unittest/UTTest_hichain_connector.cpp @@ -41,7 +41,6 @@ void HichainConnectorTest::TearDownTestCase() { } namespace { - std::shared_ptr listener_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_); -- Gitee