From 0479a05ba2447d9c02d077d38b9c7f1e0040bd7d Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 22 Apr 2025 13:03:39 +0800 Subject: [PATCH 01/21] add UT Signed-off-by: BrainL --- .../include/deviceprofile_connector.h | 5 + .../src/deviceprofile_connector.cpp | 50 +- .../include/device_manager_service_impl.h | 8 + .../device_manager_service_impl_lite.h | 3 + .../src/device_manager_service_impl.cpp | 112 ++++- .../src/device_manager_service_impl_lite.cpp | 19 + .../service/include/device_manager_service.h | 5 + .../include/hichain/hichain_listener.h | 3 + .../include/idevice_manager_service_impl.h | 4 + .../relationship_sync_mgr.h | 6 +- .../service/src/device_manager_service.cpp | 82 +++- .../service/src/hichain/hichain_listener.cpp | 39 ++ .../relationship_sync_mgr.cpp | 56 +++ .../UTTest_dm_deviceprofile_connector.cpp | 6 +- ...Test_dm_deviceprofile_connector_second.cpp | 345 ++++++++++++++ .../UTTest_device_manager_service.cpp | 59 +++ .../UTTest_device_manager_service_impl.cpp | 5 + ...Test_device_manager_service_impl_first.cpp | 448 ++++++++++++++++++ ...UTTest_device_manager_service_impl_first.h | 9 + .../UTTest_device_manager_service_two.cpp | 78 +++ test/unittest/UTTest_hichain_listener.cpp | 63 +++ .../unittest/UTTest_relationship_sync_mgr.cpp | 349 ++++++++++++++ test/unittest/mock/device_auth.h | 23 + .../mock/device_manager_service_impl_mock.cpp | 16 + .../mock/device_manager_service_impl_mock.h | 8 + .../mock/deviceprofile_connector_mock.cpp | 17 + .../mock/deviceprofile_connector_mock.h | 8 + .../mock/dm_device_state_manager_mock.cpp | 4 + .../mock/dm_device_state_manager_mock.h | 2 + test/unittest/mock/softbus_connector_mock.cpp | 8 + test/unittest/mock/softbus_connector_mock.h | 4 + test/unittest/mock/softbus_listener_mock.cpp | 4 + test/unittest/mock/softbus_listener_mock.h | 2 + 33 files changed, 1832 insertions(+), 18 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 85d27b3a0..86642290f 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -34,6 +34,7 @@ enum AllowAuthType { EXPORT extern const uint32_t INVALIED_TYPE; EXPORT extern const uint32_t APP_PEER_TO_PEER_TYPE; EXPORT extern const uint32_t APP_ACROSS_ACCOUNT_TYPE; +EXPORT extern const uint32_t SHARE_TYPE; EXPORT extern const uint32_t DEVICE_PEER_TO_PEER_TYPE; EXPORT extern const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE; EXPORT extern const uint32_t IDENTICAL_ACCOUNT_TYPE; @@ -315,6 +316,10 @@ private: uint32_t index, std::string targetDeviceId); bool CheckAppLevelAccess(const DistributedDeviceProfile::AccessControlProfile &profile, const DmAccessCaller &caller, const DmAccessCallee &callee); + bool CheckSinkShareType(DistributedDeviceProfile::AccessControlProfile profile, + const int32_t &userId, const std::string &deviceId, const std::string &trustDeviceId, const int32_t &bindType); + std::unordered_map GetAuthFormMap(const std::string &pkgName, const std::string &deviceId, + std::vector profilesFilter, const int32_t &userId); int32_t GetAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, const std::string &trustDev, const std::string &reqDev); int32_t CheckAuthForm(DmAuthForm form, DistributedDeviceProfile::AccessControlProfile profiles, diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index aa2c55129..3e433cb3d 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -30,11 +30,12 @@ using namespace OHOS::DistributedDeviceProfile; const uint32_t INVALIED_TYPE = 0; const uint32_t APP_PEER_TO_PEER_TYPE = 1; const uint32_t APP_ACROSS_ACCOUNT_TYPE = 2; -const uint32_t DEVICE_PEER_TO_PEER_TYPE = 3; -const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 4; -const uint32_t IDENTICAL_ACCOUNT_TYPE = 5; -const uint32_t SERVICE_PEER_TO_PEER_TYPE = 6; -const uint32_t SERVICE_ACROSS_ACCOUNT_TYPE = 7; +const uint32_t SHARE_TYPE = 3; +const uint32_t DEVICE_PEER_TO_PEER_TYPE = 4; +const uint32_t DEVICE_ACROSS_ACCOUNT_TYPE = 5; +const uint32_t IDENTICAL_ACCOUNT_TYPE = 6; +const uint32_t SERVICE_PEER_TO_PEER_TYPE = 7; +const uint32_t SERVICE_ACROSS_ACCOUNT_TYPE = 8; const uint32_t DM_INVALIED_TYPE = 2048; const uint32_t SERVICE = 2; @@ -637,6 +638,13 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp profilesFilter.push_back(item); } } + return GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); +} + +std::unordered_map DeviceProfileConnector::GetAuthFormMap(const std::string &pkgName, + const std::string &deviceId, std::vector profilesFilter, + const int32_t &userId) +{ std::unordered_map deviceIdMap; for (auto &item : profilesFilter) { std::string trustDeviceId = item.GetTrustDeviceId(); @@ -650,6 +658,10 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp continue; } if (deviceIdMap.find(trustDeviceId) == deviceIdMap.end()) { + if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, bindType)) { + LOGI("GetAuthFormMap CheckSinkShareType true."); + continue; + } deviceIdMap[trustDeviceId] = static_cast(bindType); continue; } @@ -661,6 +673,14 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp deviceIdMap[trustDeviceId] = DmAuthForm::IDENTICAL_ACCOUNT; continue; } + if (bindType == DmAuthForm::ACROSS_ACCOUNT) { + if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, bindType)) { + LOGI("GetAuthFormMap CheckSinkShareType true."); + continue; + } + deviceIdMap[trustDeviceId] = DmAuthForm::ACROSS_ACCOUNT; + continue; + } if (bindType == DmAuthForm::PEER_TO_PEER && authForm == DmAuthForm::ACROSS_ACCOUNT) { deviceIdMap[trustDeviceId] = DmAuthForm::PEER_TO_PEER; continue; @@ -669,6 +689,20 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp return deviceIdMap; } +bool DeviceProfileConnector::CheckSinkShareType(DistributedDeviceProfile::AccessControlProfile profile, + const int32_t &userId, const std::string &deviceId, const std::string &trustDeviceId, const int32_t &bindType) +{ + if ((profile.GetAccessee().GetAccesseeUserId() == userId || + profile.GetAccessee().GetAccesseeUserId() == 0 || + profile.GetAccessee().GetAccesseeUserId() == -1) && + profile.GetAccessee().GetAccesseeDeviceId() == deviceId && + profile.GetAccesser().GetAccesserDeviceId() == trustDeviceId && + bindType == DmAuthForm::ACROSS_ACCOUNT) { + return true; + } + return false; +} + int32_t DeviceProfileConnector::GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm) { std::vector profiles = GetAccessControlProfileByUserId(discoveryInfo.userId); @@ -748,6 +782,9 @@ int32_t DeviceProfileConnector::HandleDmAuthForm(AccessControlProfile profiles, if (profiles.GetBindType() == DM_ACROSS_ACCOUNT) { return CheckAuthForm(DmAuthForm::ACROSS_ACCOUNT, profiles, discoveryInfo); } + if (profiles.GetBindType() == DM_SHARE) { + return CheckAuthForm(DmAuthForm::ACROSS_ACCOUNT, profiles, discoveryInfo); + } return DmAuthForm::INVALID_TYPE; } @@ -782,6 +819,9 @@ int32_t DeviceProfileConnector::GetAuthForm(DistributedDeviceProfile::AccessCont case DM_IDENTICAL_ACCOUNT: priority = IDENTICAL_ACCOUNT_TYPE; break; + case DM_SHARE: + priority = SHARE_TYPE; + break; case DM_POINT_TO_POINT: if (profiles.GetBindLevel() == USER) { priority = DEVICE_PEER_TO_PEER_TYPE; diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 37f9557c1..f791b5a77 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -166,6 +166,9 @@ public: int32_t RegisterAuthenticationType(int32_t authenticationType); void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId); + void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, + std::string &remoteUdid); + void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); int32_t DeleteAcl(const std::string &sessionName, const std::string &localUdid, const std::string &remoteUdid, int32_t bindLevel, const std::string &extra); @@ -181,8 +184,13 @@ public: private: int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); std::string GetUdidHashByNetworkId(const std::string &networkId); + void SetOnlineProcessInfo(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, + const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState); + void HandleDeletedAclOffline(const std::string &trustDeviceId, + const std::string &requestDeviceId, DmDeviceInfo &devInfo, ProcessInfo &processInfo, DmDeviceState &devState); void HandleOffline(DmDeviceState devState, DmDeviceInfo &devInfo); void HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo); + bool CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid); std::map GetDeviceIdAndBindLevel(int32_t userId); std::multimap GetDeviceIdAndUserId(int32_t userId, const std::string &accountId); void HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 30d1a279b..628bd2609 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -162,6 +162,9 @@ public: int32_t RegisterAuthenticationType(int32_t authenticationType); void DeleteAlwaysAllowTimeOut(); void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId); + void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, + std::string &remoteUdid); + void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); void HandleServiceUnBindEvent(int32_t userId, const std::string &remoteUdid, int32_t remoteTokenId); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 51f5d0726..94329ff87 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -45,6 +45,7 @@ namespace { // One year 365 * 24 * 60 * 60 constexpr int32_t MAX_ALWAYS_ALLOW_SECONDS = 31536000; +constexpr int32_t ACL_CREDID_LENGTH = 6; constexpr int32_t MIN_PIN_CODE = 100000; constexpr int32_t MAX_PIN_CODE = 999999; // New protocol field definition. To avoid dependency on the new protocol header file, @@ -582,17 +583,17 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf } std::string udisHash = softbusConnector_->GetDeviceUdidHashByUdid(trustDeviceId); if (memcpy_s(devInfo.deviceId, DM_MAX_DEVICE_ID_LEN, udisHash.c_str(), udisHash.length()) != 0) { - LOGE("get deviceId: %{public}s failed", GetAnonyString(udisHash).c_str()); return; } char localUdid[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdid, DEVICE_UUID_LENGTH); std::string requestDeviceId = std::string(localUdid); - std::map userIdAndBindLevel = - DeviceProfileConnector::GetInstance().GetUserIdAndBindLevel(requestDeviceId, trustDeviceId); ProcessInfo processInfo; processInfo.pkgName = std::string(DM_PKG_NAME); processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId(); + uint32_t bindType = DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId); + std::map userIdAndBindLevel = + DeviceProfileConnector::GetInstance().GetUserIdAndBindLevel(requestDeviceId, trustDeviceId); if (userIdAndBindLevel.empty() || userIdAndBindLevel.find(processInfo.userId) == userIdAndBindLevel.end()) { userIdAndBindLevel[processInfo.userId] = INVALIED_TYPE; } @@ -602,7 +603,12 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; processInfo.userId = item.first; softbusConnector_->SetProcessInfo(processInfo); - } else if (static_cast(item.second) == USER) { + } else if (static_cast(item.second) == USER && bindType == SHARE_TYPE) { + LOGI("The offline device is device bind level and share bind type."); + devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + processInfo.userId = item.first; + softbusConnector_->SetProcessInfo(processInfo); + } else if (static_cast(item.second) == USER && bindType != SHARE_TYPE) { LOGI("The offline device is device bind type."); devInfo.authForm = DmAuthForm::PEER_TO_PEER; processInfo.userId = item.first; @@ -640,6 +646,12 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo ProcessInfo processInfo; processInfo.pkgName = std::string(DM_PKG_NAME); processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId(); + SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); +} + +void DeviceManagerServiceImpl::SetOnlineProcessInfo(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, + const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState) +{ if (bindType == IDENTICAL_ACCOUNT_TYPE) { devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; softbusConnector_->SetProcessInfo(processInfo); @@ -661,9 +673,36 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo MultipleUserConnector::GetFirstForegroundUserId()); softbusConnector_->SetProcessInfoVec(processInfoVec); devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + } else if (bindType == SHARE_TYPE) { + if (CheckSharePeerSrc(trustDeviceId, requestDeviceId)) { + LOGI("ProcessDeviceStateChange authForm is share, peer is src."); + return; + } + devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + softbusConnector_->SetProcessInfo(processInfo); } - LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo auform %{public}d.", devInfo.authForm); + LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo authForm is %{public}d.", devInfo.authForm); deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); + return; +} + +bool DeviceManagerServiceImpl::CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid) +{ + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + for (auto &aclItem : profiles) { + if (aclItem.GetBindType() == DM_SHARE && aclItem.GetTrustDeviceId() == peerUdid) { + if (aclItem.GetAccesser().GetAccesserDeviceId() == peerUdid && + aclItem.GetAccessee().GetAccesseeDeviceId() == localUdid) { + return true; + } + if (aclItem.GetAccesser().GetAccesserDeviceId() == localUdid && + aclItem.GetAccessee().GetAccesseeDeviceId() == peerUdid) { + return false; + } + } + } + return false; } void DeviceManagerServiceImpl::HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) @@ -2246,6 +2285,69 @@ void DeviceManagerServiceImpl::CheckDeleteCredential(const std::string &remoteUd } } +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, + const std::string &localUdid, std::string &remoteUdid) +{ + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + JsonObject jsonObject; + jsonObject.Parse(std::string(credInfo)); + if (jsonObject.IsDiscarded()) { + LOGE("credInfo prase error."); + return; + } + std::string deviceIdTag = "deviceId"; + std::string userIdTag = "userId"; + int32_t userId = 0; + if (IsString(jsonObject, deviceIdTag)) { + remoteUdid = jsonObject[deviceIdTag].Get(); + } + if (IsInt32(jsonObject, userIdTag)) { + userId = jsonObject[userIdTag].Get(); + } + for (const auto &item : profiles) { + if (item.GetBindType() != DM_SHARE) { + continue; + } + if ((item.GetAccesser().GetAccesserCredentialId() == atoi(credId) && + item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccessee().GetAccesseeUserId() == userId && + item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) || + (item.GetAccessee().GetAccesseeCredentialId() == atoi(credId) && + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserUserId() == userId && + item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + } +} + +void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + const std::string &localUdid) +{ + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfile(); + for (const auto &item : profiles) { + if (item.GetBindType() != DM_SHARE) { + continue; + } + std::string accesserCredId = ""; + std::string accesseeCredId = ""; + for (int32_t i = 0; i < ACL_CREDID_LENGTH; i++) { + accesserCredId[i] = std::to_string(item.GetAccesser().GetAccesserCredentialId())[i]; + accesseeCredId[i] = std::to_string(item.GetAccessee().GetAccesseeCredentialId())[i]; + } + if (accesserCredId == credId && item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserUserId() == userId) { + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + if (accesseeCredId == credId && item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccessee().GetAccesseeUserId() == userId) { + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + } + } +} + int32_t DeviceManagerServiceImpl::CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) { diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 26f39c7aa..57120d869 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -330,6 +330,16 @@ int32_t DeviceManagerServiceImpl::ImportAuthCode(const std::string &pkgName, con return DM_OK; } +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, + const std::string &localUdid, std::string &remoteUdid) +{ + (void)credId; + (void)credInfo; + (void)localUdid; + (void)remoteUdid; + return; +} + int32_t DeviceManagerServiceImpl::ExportAuthCode(std::string &authCode) { (void)authCode; @@ -571,6 +581,15 @@ void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector return; } +void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + const std::string &localUdid) +{ + (void)credId; + (void)userId; + (void)localUdid; + return; +} + void DeviceManagerServiceImpl::HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid) { (void)preUserId; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 43d47980d..6ce10e22f 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -192,6 +192,7 @@ public: bool CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); void HandleDeviceNotTrust(const std::string &msg); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + void HandleCredentialDeleted(const char *credId, const char *credInfo); void HandleDeviceTrustedChange(const std::string &msg); void HandleUserIdCheckSumChange(const std::string &msg); void HandleUserStop(int32_t stopUserId, const std::string &stopEventUdid); @@ -247,6 +248,7 @@ private: bool IsDMImplSoLoaded(); bool IsDMServiceAdapterSoLoaded(); bool IsDMServiceAdapterResidentLoad(); + bool IsMsgEmptyAndDMServiceImplReady(const std::string &msg); void UnloadDMServiceImplSo(); void UnloadDMServiceAdapterResident(); void SendUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, @@ -288,6 +290,8 @@ private: #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void SubscribeAccountCommonEvent(); + void SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, + const std::vector &peerUdids); EXPORT void AccountCommonEventCallback(const std::string commonEventType, int32_t currentUserId, int32_t beforeUserId); void SubscribeScreenLockEvent(); @@ -308,6 +312,7 @@ private: void HandleUserSwitched(int32_t curUserId, int32_t preUserId); void HandleUserIdsBroadCast(const std::vector &remoteUserIdInfos, const std::string &remoteUdid, bool isNeedResponse); + void HandleShareUnbindBroadCast(const int32_t userId, const std::string &credId); void NotifyRemoteLocalUserSwitch(int32_t curUserId, int32_t preUserId, const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void NotifyRemoteLocalUserSwitchByWifi(int32_t curUserId, int32_t preUserId, diff --git a/services/service/include/hichain/hichain_listener.h b/services/service/include/hichain/hichain_listener.h index 07f408803..cc43346a2 100644 --- a/services/service/include/hichain/hichain_listener.h +++ b/services/service/include/hichain/hichain_listener.h @@ -58,6 +58,7 @@ public: HichainListener(); ~HichainListener(); void RegisterDataChangeCb(); + void RegisterCredentialCb(); void DeleteAllGroup(const std::string &localUdid, const std::vector &backgroundUserIds); int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, std::vector &groupList); @@ -69,9 +70,11 @@ public: int64_t GenRequestId(); static void OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo); + static void OnCredentialDeleted(const char *credId, const char *credInfo); private: const DeviceGroupManager *deviceGroupManager_ = nullptr; + const CredManager *credManager_ = nullptr; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index fa2ae7ca3..e4598a886 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -263,6 +263,10 @@ public: virtual int32_t RegisterAuthenticationType(int32_t authenticationType) = 0; virtual void DeleteAlwaysAllowTimeOut() = 0; virtual void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId) = 0; + virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, + std::string &remoteUdid) = 0; + virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + const std::string &localUdid) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; virtual void HandleServiceUnBindEvent(int32_t userId, const std::string &remoteUdid, int32_t remoteTokenId) = 0; diff --git a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h index cc6409ce1..ebaef0e72 100644 --- a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h +++ b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h @@ -30,7 +30,8 @@ enum class RelationShipChangeType : uint32_t { APP_UNINSTALL = 5, SYNC_USERID = 6, STOP_USER = 7, - TYPE_MAX = 8 + SHARE_UNBIND = 8, + TYPE_MAX = 9 }; struct UserIdInfo { @@ -58,6 +59,7 @@ struct RelationShipChangeMsg { bool syncUserIdFlag; // The foreground and background user id infos std::vector userIdInfos; + std::string credId; explicit RelationShipChangeMsg(); bool ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) const; @@ -72,6 +74,7 @@ struct RelationShipChangeMsg { bool ToSyncFrontOrBackUserIdPayLoad(uint8_t *&msg, uint32_t &len) const; void ToDelUserPayLoad(uint8_t *&msg, uint32_t &len) const; void ToStopUserPayLoad(uint8_t *&msg, uint32_t &len) const; + void ToShareUnbindPayLoad(uint8_t *&msg, uint32_t &len) const; cJSON *ToPayLoadJson() const; bool FromAccountLogoutPayLoad(const cJSON *payloadJson); @@ -81,6 +84,7 @@ struct RelationShipChangeMsg { bool FromSyncFrontOrBackUserIdPayLoad(const cJSON *payloadJson); bool FromDelUserPayLoad(const cJSON *payloadJson); bool FromStopUserPayLoad(const cJSON *payloadJson); + bool FromShareUnbindPayLoad(const cJSON *payloadJson); std::string ToJson() const; bool FromJson(const std::string &msgJson); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 176bf5017..c051d34c4 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -74,6 +74,7 @@ namespace { constexpr const char *NETWORKID = "NETWORK_ID"; constexpr uint32_t INVALIED_BIND_LEVEL = 0; constexpr uint32_t DM_IDENTICAL_ACCOUNT = 1; + constexpr uint32_t DM_SHARE = 2; const std::string USERID_CHECKSUM_NETWORKID_KEY = "networkId"; const std::string USERID_CHECKSUM_DISCOVER_TYPE_KEY = "discoverType"; constexpr uint32_t USERID_CHECKSUM_DISCOVERY_TYPE_WIFI_MASK = 0b0010; @@ -133,6 +134,7 @@ void DeviceManagerService::InitHichainListener() hichainListener_ = std::make_shared(); } hichainListener_->RegisterDataChangeCb(); + hichainListener_->RegisterCredentialCb(); } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -1872,6 +1874,21 @@ void DeviceManagerService::SubscribeAccountCommonEvent() return; } +void DeviceManagerService::SendShareTypeUnBindBroadCast(const char *credId, const int32_t localUserId, + const std::vector &peerUdids) +{ + LOGI("SendShareTypeUnBindBroadCast Start."); + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SHARE_UNBIND; + msg.userId = static_cast(localUserId); + msg.credId = credId; + msg.peerUdids = peerUdids; + std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + LOGI("SendShareTypeUnBindBroadCast broadCastMsg = %{public}s.", broadCastMsg.c_str()); + CHECK_NULL_VOID(softbusListener_); + softbusListener_->SendAclChangedBroadcast(broadCastMsg); +} + void DeviceManagerService::SubscribeScreenLockEvent() { LOGI("Start"); @@ -2505,19 +2522,40 @@ void DeviceManagerService::SendServiceUnBindBroadCast(const std::vectorSendAclChangedBroadcast(broadCastMsg); } +void DeviceManagerService::HandleCredentialDeleted(const char *credId, const char *credInfo) +{ + LOGI("HandleCredentialDeleted start."); + if (credId == nullptr || credInfo == nullptr) { + LOGE("HandleCredentialDeleted credId or credInfo is nullptr."); + return; + } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + if (!IsDMServiceImplReady()) { + LOGE("HandleCredentialDeleted failed, instance not init or init failed."); + return; + } + std::string remoteUdid = ""; + dmServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); + if (remoteUdid.empty()) { + LOGE("HandleCredentialDeleted failed, remoteUdid is empty."); + return; + } + std::vector peerUdids; + peerUdids.emplace_back(remoteUdid); + SendShareTypeUnBindBroadCast(credId, MultipleUserConnector::GetCurrentAccountUserID(), peerUdids); + return; +} + void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) { - if (msg.empty()) { - LOGE("Msg is empty."); + if (!IsMsgEmptyAndDMServiceImplReady(msg)) { return; } RelationShipChangeMsg relationShipMsg = ReleationShipSyncMgr::GetInstance().ParseTrustRelationShipChange(msg); LOGI("Receive trust change msg: %{public}s", relationShipMsg.ToString().c_str()); - if (!IsDMServiceImplReady()) { - LOGE("Imp instance not init or init failed."); - return; - } switch (relationShipMsg.type) { case RelationShipChangeType::ACCOUNT_LOGOUT: dmServiceImpl_->HandleAccountLogoutEvent(relationShipMsg.userId, relationShipMsg.accountId, @@ -2550,6 +2588,9 @@ void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) case RelationShipChangeType::STOP_USER: HandleUserStopBroadCast(relationShipMsg.userId, relationShipMsg.peerUdid); break; + case RelationShipChangeType::SHARE_UNBIND: + HandleShareUnbindBroadCast(relationShipMsg.userId, relationShipMsg.credId); + break; default: LOGI("Dm have not this event type."); break; @@ -2557,6 +2598,35 @@ void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) return; } +bool DeviceManagerService::IsMsgEmptyAndDMServiceImplReady(const std::string &msg) +{ + if (msg.empty()) { + LOGE("Msg is empty."); + return false; + } + if (!IsDMServiceImplReady()) { + LOGE("Imp instance not init or init failed."); + return false; + } + return true; +} + +void DeviceManagerService::HandleShareUnbindBroadCast(const int32_t userId, const std::string &credId) +{ + LOGI("HandleShareUnbindBroadCast start."); + if (credId == "") { + LOGE("HandleShareUnbindBroadCast credId is null."); + return; + } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + if (IsDMServiceImplReady()) { + dmServiceImpl_->HandleShareUnbindBroadCast(credId, userId, localUdid); + } + return; +} + int32_t DeviceManagerService::ParseCheckSumMsg(const std::string &msg, std::string &networkId, uint32_t &discoveryType, bool &isChange) { diff --git a/services/service/src/hichain/hichain_listener.cpp b/services/service/src/hichain/hichain_listener.cpp index 8aa199c8e..4ee33e95f 100644 --- a/services/service/src/hichain/hichain_listener.cpp +++ b/services/service/src/hichain/hichain_listener.cpp @@ -33,6 +33,10 @@ static DataChangeListener dataChangeListener_ = { .onDeviceUnBound = HichainListener::OnHichainDeviceUnBound, }; +static CredChangeListener credChangeListener_ = { + .onCredDelete = HichainListener::OnCredentialDeleted, +}; + void FromJson(const JsonItemObject &jsonObject, GroupInformation &groupInfo) { if (jsonObject.Contains(FIELD_GROUP_TYPE) && jsonObject.At(FIELD_GROUP_TYPE).IsNumberInteger()) { @@ -82,10 +86,15 @@ HichainListener::HichainListener() LOGI("HichainListener constructor start."); InitDeviceAuthService(); deviceGroupManager_ = GetGmInstance(); + credManager_ = GetCredMgrInstance(); if (deviceGroupManager_ == nullptr) { LOGE("[HICHAIN]failed to init group manager."); return; } + if (credManager_ == nullptr) { + LOGE("[HICHAIN]failed to init cred manager."); + return; + } LOGI("HichainListener::constructor success."); } @@ -110,6 +119,21 @@ void HichainListener::RegisterDataChangeCb() LOGI("RegisterDataChangeCb success!"); } +void HichainListener::RegisterCredentialCb() +{ + LOGI("HichainListener::RegisterCredentialCb start"); + if (credManager_ == nullptr) { + LOGE("credManager_ is null!"); + return; + } + int32_t ret = credManager_->registerChangeListener(DM_PKG_NAME, &credChangeListener_); + if (ret != DM_OK) { + LOGE("[HICHAIN]registerChangeListener failed with ret: %{public}d.", ret); + return; + } + LOGI("RegisterCredentialCb success!"); +} + void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo) { LOGI("HichainListener::onDeviceUnBound start"); @@ -141,6 +165,21 @@ void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *g } } +void HichainListener::OnCredentialDeleted(const char *credId, const char *credInfo) +{ + LOGI("HichainListener::OnCredentialDeleted start"); + if (credId == nullptr || credInfo == nullptr) { + LOGE("credId or credInfo is null!"); + return; + } + if (strlen(credId) > MAX_DATA_LEN || strlen(credInfo) > MAX_DATA_LEN) { + LOGE("credId or credInfo is invalid"); + return; + } + DeviceManagerService::GetInstance().HandleCredentialDeleted(credId, credInfo); + return; +} + void HichainListener::DeleteAllGroup(const std::string &localUdid, const std::vector &backgroundUserIds) { LOGI("OnStart HichainListener::DeleteAllGroup"); diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 823dd2a5b..58ba6c632 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -46,6 +46,7 @@ namespace { */ const int32_t DEL_USER_PAYLOAD_LEN = 2; const int32_t STOP_USER_PAYLOAD_LEN = 2; + const int32_t SHARE_UNBIND_PAYLOAD_LEN = 8; /** * @brief the userid payload cost 2 bytes. * @@ -58,6 +59,7 @@ namespace { const int32_t USERID_BYTES = 2; const int32_t BITS_PER_BYTE = 8; const int32_t INVALIED_PAYLOAD_SIZE = 12; + const int32_t CREDID_PAYLOAD_LEN = 8; const char * const MSG_TYPE = "TYPE"; const char * const MSG_VALUE = "VALUE"; @@ -131,6 +133,10 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con ToStopUserPayLoad(msg, len); ret = true; break; + case RelationShipChangeType::SHARE_UNBIND: + ToShareUnbindPayLoad(msg, len); + ret = true; + break; default: LOGE("RelationShipChange type invalid"); break; @@ -138,6 +144,19 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con return ret; } +void RelationShipChangeMsg::ToShareUnbindPayLoad(uint8_t *&msg, uint32_t &len) const +{ + msg = new uint8_t[SHARE_UNBIND_PAYLOAD_LEN](); + for (int i = 0; i < USERID_PAYLOAD_LEN; i++) { + msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; + } + + for (int i = USERID_PAYLOAD_LEN; i < CREDID_PAYLOAD_LEN; i++) { + msg[i] = credId[i - USERID_PAYLOAD_LEN]; + } + len = SHARE_UNBIND_PAYLOAD_LEN; +} + bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, RelationShipChangeType type) { LOGI("FromBroadcastPayLoad type %{public}d.", type); @@ -168,6 +187,9 @@ bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, Relat case RelationShipChangeType::STOP_USER: ret = FromStopUserPayLoad(payloadJson); break; + case RelationShipChangeType::SHARE_UNBIND: + ret = FromShareUnbindPayLoad(payloadJson); + break; default: LOGE("RelationShipChange type invalid"); break; @@ -175,6 +197,36 @@ bool RelationShipChangeMsg::FromBroadcastPayLoad(const cJSON *payloadJson, Relat return ret; } +bool RelationShipChangeMsg::FromShareUnbindPayLoad(const cJSON *payloadJson) +{ + if (payloadJson == NULL) { + LOGE("Share unbind payloadJson is null."); + return false; + } + int32_t arraySize = cJSON_GetArraySize(payloadJson); + if (arraySize < SHARE_UNBIND_PAYLOAD_LEN || arraySize >= INVALIED_PAYLOAD_SIZE) { + LOGE("Payload invalied,the size is %{public}d.", arraySize); + return false; + } + userId = 0; + for (uint32_t i = 0; i < USERID_PAYLOAD_LEN; i++) { + cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, i); + CHECK_NULL_RETURN(payloadItem, false); + if (cJSON_IsNumber(payloadItem)) { + userId |= (static_cast(payloadItem->valueint)) << (i * BITS_PER_BYTE); + } + } + credId = ""; + for (uint32_t j = USERID_PAYLOAD_LEN; j < CREDID_PAYLOAD_LEN; j++) { + cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); + CHECK_NULL_RETURN(payloadItem, false); + if (cJSON_IsNumber(payloadItem)) { + credId += static_cast(payloadItem->valueint); + } + } + return true; +} + bool RelationShipChangeMsg::IsValid() const { bool ret = false; @@ -194,6 +246,9 @@ bool RelationShipChangeMsg::IsValid() const case RelationShipChangeType::STOP_USER: ret = (userId != UINT32_MAX); break; + case RelationShipChangeType::SHARE_UNBIND: + ret = (userId != UINT32_MAX); + break; case RelationShipChangeType::SERVICE_UNBIND: ret = (userId != UINT32_MAX); break; @@ -231,6 +286,7 @@ bool RelationShipChangeMsg::IsChangeTypeValid(uint32_t type) (type == (uint32_t)RelationShipChangeType::SYNC_USERID) || (type == (uint32_t)RelationShipChangeType::DEL_USER) || (type == (uint32_t)RelationShipChangeType::STOP_USER) || + (type == (uint32_t)RelationShipChangeType::SHARE_UNBIND) || (type == (uint32_t)RelationShipChangeType::SERVICE_UNBIND); } diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 1cf70e56a..2ebee3305 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1124,6 +1124,10 @@ HWTEST_F(DeviceProfileConnectorTest, GetAuthForm_001, testing::ext::TestSize.Lev profile.SetBindType(DM_IDENTICAL_ACCOUNT); ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); EXPECT_EQ(ret, IDENTICAL_ACCOUNT_TYPE); + profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindLevel(DEVICE); + ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); + EXPECT_EQ(ret, SHARE_TYPE); profile.SetBindType(DM_POINT_TO_POINT); profile.SetBindLevel(USER); ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); @@ -1997,7 +2001,7 @@ HWTEST_F(DeviceProfileConnectorTest, CheckBindType_004, testing::ext::TestSize.L EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234)); ret = DeviceProfileConnector::GetInstance().CheckBindType(peerUdid, localUdid); - EXPECT_EQ(ret, 5); + EXPECT_EQ(ret, 6); } HWTEST_F(DeviceProfileConnectorTest, GetTokenIdByNameAndDeviceId_001, testing::ext::TestSize.Level1) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index 081b33071..511a563fa 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -581,5 +581,350 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetLocalServiceInfoByBundleNameAndPin pinExchangeType, localServiceInfo); EXPECT_EQ(ret, ERR_DM_FAILED); } + +HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_009, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_SHARE_TYPE); + profiles.SetBindLevel(DEVICE); + DmDiscoveryInfo discoveryInfo; + int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); + EXPECT_EQ(ret, ACROSS_ACCOUNT); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_010, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_SHARE_TYPE); + profiles.SetBindLevel(APP); + profiles.accesser_.SetAccesserBundleName("ohos_test"); + profiles.accesser_.SetAccesserDeviceId("localDeviceId"); + DmDiscoveryInfo discoveryInfo; + discoveryInfo.pkgname = "ohos_test"; + discoveryInfo.localDeviceId = "localDeviceId"; + int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); + EXPECT_EQ(ret, ACROSS_ACCOUNT); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_011, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profiles; + profiles.SetBindType(DM_SHARE_TYPE); + profiles.SetBindLevel(APP); + profiles.accessee_.SetAccesseeBundleName("pkgName"); + profiles.accessee_.SetAccesseeDeviceId("localDeviceId"); + DmDiscoveryInfo discoveryInfo; + discoveryInfo.pkgname = "pkgName"; + discoveryInfo.localDeviceId = "localDeviceId"; + int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); + EXPECT_EQ(ret, ACROSS_ACCOUNT); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_001, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(userId); + accessee.SetAccesseeDeviceId(deviceId); + profile.SetAccessee(accessee); + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId(trustDeviceId); + profile.SetAccesser(accesser); + + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_TRUE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_002, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(0); + accessee.SetAccesseeDeviceId(deviceId); + profile.SetAccessee(accessee); + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId(trustDeviceId); + profile.SetAccesser(accesser); + + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_TRUE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_003, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(-1); + accessee.SetAccesseeDeviceId(deviceId); + profile.SetAccessee(accessee); + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId(trustDeviceId); + profile.SetAccesser(accesser); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_TRUE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_004, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(userId); + accessee.SetAccesseeDeviceId("wrongDeviceId"); + profile.SetAccessee(accessee); + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId(trustDeviceId); + profile.SetAccesser(accesser); + + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_005, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(userId); + accessee.SetAccesseeDeviceId(deviceId); + profile.SetAccessee(accessee); + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId("wrongTrustDeviceId"); + profile.SetAccesser(accesser); + + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_006, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::PEER_TO_PEER; // Wrong bind type + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(userId); + accessee.SetAccesseeDeviceId(deviceId); + profile.SetAccessee(accessee); + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId(trustDeviceId); + profile.SetAccesser(accesser); + + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_007, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(999999); // Different user ID + accessee.SetAccesseeDeviceId(deviceId); + profile.SetAccessee(accessee); + + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId(trustDeviceId); + profile.SetAccesser(accesser); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_008, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile profile; + int32_t userId = 123456; + std::string deviceId = "deviceId"; + std::string trustDeviceId = "trustDeviceId"; + int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + + // Empty profile (no accessee/accesser set) + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_001, testing::ext::TestSize.Level1) +{ + // Test case 1: Empty input - should return empty map + std::string pkgName = "testPkg";; + std::string deviceId = "deviceId1"; + int32_t userId = 123456; + std::vector profilesFilter; + + auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); + EXPECT_EQ(ret.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_002, testing::ext::TestSize.Level1) +{ + // Test case 2: Profile with trustDeviceId matching input deviceId - should be skipped + std::string pkgName = "testPkg"; + std::string deviceId = "deviceId1"; + int32_t userId = 123456; + + std::vector profilesFilter; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetTrustDeviceId(deviceId); // Matching deviceId + profile.SetStatus(ACTIVE); + profilesFilter.push_back(profile); + + auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); + EXPECT_EQ(ret.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_003, testing::ext::TestSize.Level1) +{ + // Test case 3: Profile with INACTIVE status - should be skipped + std::string pkgName = "testPkg"; + std::string deviceId = "deviceId1"; + std::string trustDeviceId = "trustDeviceId1"; + int32_t userId = 123456; + + std::vector profilesFilter; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetTrustDeviceId(trustDeviceId); + profile.SetStatus(INACTIVE); + profilesFilter.push_back(profile); + + auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); + EXPECT_EQ(ret.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_004, testing::ext::TestSize.Level1) +{ + // Test case 4: Profile with INVALID_TYPE auth form - should be skipped + std::string pkgName = "testPkg"; + std::string deviceId = "deviceId1"; + std::string trustDeviceId = "trustDeviceId1"; + int32_t userId = 123456; + + std::vector profilesFilter; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetTrustDeviceId(trustDeviceId); + profile.SetStatus(ACTIVE); + profile.SetBindType(DmAuthForm::INVALID_TYPE); + profilesFilter.push_back(profile); + + auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); + EXPECT_EQ(ret.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_005, testing::ext::TestSize.Level1) +{ + // Test case 5: Single valid profile with IDENTICAL_ACCOUNT type + std::string pkgName = "testPkg"; + std::string deviceId = "deviceId1"; + std::string trustDeviceId = "trustDeviceId1"; + int32_t userId = 123456; + + std::vector profilesFilter; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetTrustDeviceId(trustDeviceId); + profile.SetStatus(ACTIVE); + profile.SetBindType(DmAuthForm::IDENTICAL_ACCOUNT); + profilesFilter.push_back(profile); + + auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); + EXPECT_EQ(ret.size(), 1); + EXPECT_EQ(ret[trustDeviceId], DmAuthForm::IDENTICAL_ACCOUNT); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_006, testing::ext::TestSize.Level1) +{ + // Test case 6: CheckSinkShareType returns true - should skip adding to map + std::string pkgName = "testPkg"; + std::string deviceId = "deviceId1"; + std::string trustDeviceId = "trustDeviceId1"; + int32_t userId = 123456; + + std::vector profilesFilter; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetTrustDeviceId(trustDeviceId); + profile.SetStatus(ACTIVE); + // Set up accessee/accesser to make CheckSinkShareType return true + DistributedDeviceProfile::Accessee accessee; + accessee.SetAccesseeUserId(userId); + accessee.SetAccesseeDeviceId(deviceId); + profile.SetAccessee(accessee); + DistributedDeviceProfile::Accesser accesser; + accesser.SetAccesserDeviceId(trustDeviceId); + profile.SetAccesser(accesser); + profile.SetBindType(DmAuthForm::ACROSS_ACCOUNT); + + profilesFilter.push_back(profile); + + auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); + EXPECT_EQ(ret.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_007, testing::ext::TestSize.Level1) +{ + // Test case 7: Multiple profiles with different auth forms - should keep highest priority + std::string pkgName = "testPkg"; + std::string deviceId = "deviceId1"; + std::string trustDeviceId = "trustDeviceId1"; + int32_t userId = 123456; + + std::vector profilesFilter; + // First profile - PEER_TO_PEER + DistributedDeviceProfile::AccessControlProfile profile1; + profile1.SetTrustDeviceId(trustDeviceId); + profile1.SetStatus(ACTIVE); + profile1.SetBindType(DmAuthForm::PEER_TO_PEER); + profilesFilter.push_back(profile1); + + // Second profile - ACROSS_ACCOUNT (should override PEER_TO_PEER) + DistributedDeviceProfile::AccessControlProfile profile2; + profile2.SetTrustDeviceId(trustDeviceId); + profile2.SetStatus(ACTIVE); + profile2.SetBindType(DmAuthForm::ACROSS_ACCOUNT); + profilesFilter.push_back(profile2); + + // Third profile - IDENTICAL_ACCOUNT (should override everything) + DistributedDeviceProfile::AccessControlProfile profile3; + profile3.SetTrustDeviceId(trustDeviceId); + profile3.SetStatus(ACTIVE); + profile3.SetBindType(DmAuthForm::IDENTICAL_ACCOUNT); + profilesFilter.push_back(profile3); + + auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); + EXPECT_EQ(ret.size(), 1); + EXPECT_EQ(ret[trustDeviceId], DmAuthForm::IDENTICAL_ACCOUNT); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 4aa05671e..d93430fe3 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -2380,6 +2380,65 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_002, testing::ext::TestSiz "peerUdid" : "110", "accountName" : "account_wang" })"; + msg = R"( + { + "type" : 3, + "userId" : 130, + "accountId" : "28880", + "tokenId" : 19, + "peerUdid" : "111", + "accountName" : "account_liang" + })"; + DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); + msg = R"( + { + "type" : 4, + "userId" : 131, + "accountId" : "28881", + "tokenId" : 20, + "peerUdid" : "112", + "accountName" : "account_deng" + })"; + DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); + msg = R"( + { + "type" : 5, + "userId" : 131, + "accountId" : "28882", + "tokenId" : 20, + "peerUdid" : "112", + "accountName" : "account_deng" + })"; + DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); + msg = R"( + { + "type" : 6, + "userId" : 132, + "accountId" : "28883", + "tokenId" : 21, + "peerUdid" : "113", + "accountName" : "account_zhang" + })"; + DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); + msg = R"( + { + "type" : 7, + "userId" : 133, + "accountId" : "28884", + "tokenId" : 22, + "peerUdid" : "114", + "accountName" : "account_hu" + })"; + DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); + msg = R"( + { + "type" : 8, + "userId" : 134, + "accountId" : "28885", + "tokenId" : 23, + "peerUdid" : "115", + "accountName" : "account_liu" + })"; DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); int32_t ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info); EXPECT_EQ(ret, ERR_DM_POINT_NULL); diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index f08ba99a9..ee04486c9 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1737,6 +1737,10 @@ HWTEST_F(DeviceManagerServiceImplTest, HandleOnline_003, testing::ext::TestSize. EXPECT_CALL(*deviceProfileConnectorMock_, CheckBindType(_, _)).WillOnce(Return(DEVICE_ACROSS_ACCOUNT_TYPE)); deviceManagerServiceImpl_->HandleOnline(devState, devInfo); + EXPECT_CALL(*softbusConnectorMock_, GetUdidByNetworkId(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*deviceProfileConnectorMock_, CheckBindType(_, _)).WillOnce(Return(SHARE_TYPE)); + deviceManagerServiceImpl_->HandleOnline(devState, devInfo); + std::vector profiles; EXPECT_CALL(*softbusConnectorMock_, GetUdidByNetworkId(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*deviceProfileConnectorMock_, CheckBindType(_, _)).WillOnce(Return(APP_PEER_TO_PEER_TYPE)); @@ -1768,6 +1772,7 @@ HWTEST_F(DeviceManagerServiceImplTest, HandleOffline_003, testing::ext::TestSize std::vector profiles; EXPECT_CALL(*dmDeviceStateManagerMock_, GetUdidByNetWorkId(_)).WillOnce(Return("123456")); EXPECT_CALL(*deviceProfileConnectorMock_, GetUserIdAndBindLevel(_, _)).WillOnce(Return(userIdAndBindLevel)); + EXPECT_CALL(*deviceProfileConnectorMock_, CheckBindType(_, _)).WillOnce(Return(SHARE_TYPE)); deviceManagerServiceImpl_->HandleOffline(devState, devInfo); EXPECT_NE(deviceManagerServiceImpl_->deviceStateMgr_, nullptr); } diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index af21d1fa7..6ca44b9f5 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -40,6 +40,9 @@ void DeviceManagerServiceImplFirstTest::SetUpTestCase() { DmDeviceProfileConnector::dmDeviceProfileConnector = deviceProfileConnectorMock_; DmMultipleUserConnector::dmMultipleUserConnector = multipleUserConnectorMock_; + DmSoftbusConnector::dmSoftbusConnector = softbusConnectorMock_; + DmDmDeviceStateManager::dmDeviceStateManager = dmDeviceStateManagerMock_; + DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl = deviceManagerServiceImplMock_; } void DeviceManagerServiceImplFirstTest::TearDownTestCase() @@ -48,6 +51,12 @@ void DeviceManagerServiceImplFirstTest::TearDownTestCase() deviceProfileConnectorMock_ = nullptr; DmMultipleUserConnector::dmMultipleUserConnector = nullptr; multipleUserConnectorMock_ = nullptr; + DmSoftbusConnector::dmSoftbusConnector = nullptr; + softbusConnectorMock_ = nullptr; + DmDmDeviceStateManager::dmDeviceStateManager = nullptr; + dmDeviceStateManagerMock_ = nullptr; + DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl = nullptr; + deviceManagerServiceImplMock_ = nullptr; } namespace { @@ -88,6 +97,445 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceIdAndUserId_101, testing::e .WillOnce(DoAll(SetArgReferee<0>(localUserIds), Return(DM_OK))); deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid, false); } + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_001, testing::ext::TestSize.Level1) +{ + std::string peerUdid = "peerUdid"; + std::string localUdid = "localUdid"; + // Setup empty profiles + std::vector profiles; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + + bool result = deviceManagerServiceImpl_->CheckSharePeerSrc(peerUdid, localUdid); + EXPECT_FALSE(result); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_002, testing::ext::TestSize.Level1) +{ + std::string peerUdid = "peerUdid"; + std::string localUdid = "localUdid"; + + // Setup mock profile where peer is the source + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + profile.SetTrustDeviceId(peerUdid); + Accesser accesser; + accesser.SetAccesserDeviceId(peerUdid); + profile.SetAccesser(accesser); + + Accessee accessee; + accessee.SetAccesseeDeviceId(localUdid); + profile.SetAccessee(accessee); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + + bool result = deviceManagerServiceImpl_->CheckSharePeerSrc(peerUdid, localUdid); + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_003, testing::ext::TestSize.Level1) +{ + std::string peerUdid = "peerUdid"; + std::string localUdid = "localUdid"; + + // Setup mock profile where local is the source + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + profile.SetTrustDeviceId(peerUdid); + Accesser accesser; + accesser.SetAccesserDeviceId(localUdid); + profile.SetAccesser(accesser); + profile.GetAccessee().SetAccesseeDeviceId(peerUdid); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + + bool result = deviceManagerServiceImpl_->CheckSharePeerSrc(peerUdid, localUdid); + EXPECT_FALSE(result); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_004, testing::ext::TestSize.Level1) +{ + std::string peerUdid = "peerUdid"; + std::string localUdid = "localUdid"; + + // Setup mock profile with no matching sharing relationship + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_IDENTICAL_ACCOUNT); // Different bind type + profile.SetTrustDeviceId(peerUdid); + Accesser accesser; + accesser.SetAccesserDeviceId(peerUdid); + profile.SetAccesser(accesser); + Accessee accessee; + accessee.SetAccesseeDeviceId(localUdid); + profile.SetAccessee(accessee); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + + bool result = deviceManagerServiceImpl_->CheckSharePeerSrc(peerUdid, localUdid); + EXPECT_FALSE(result); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_005, testing::ext::TestSize.Level1) +{ + std::string peerUdid = "peerUdid"; + std::string localUdid = "localUdid"; + std::string trustDevideId = "trustDevideId"; + + // 模拟 profiles 中的 TrustDeviceId 不等于 peerUdid + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + profile.SetTrustDeviceId(trustDevideId); // 不匹配的 TrustDeviceId + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + + bool result = deviceManagerServiceImpl_->CheckSharePeerSrc(peerUdid, localUdid); + EXPECT_FALSE(result); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_001, testing::ext::TestSize.Level1) +{ + const char *credId = "123456"; + const char *credInfo = "invalid_json"; + std::string localUdid = "localUdid"; + std::string remoteUdid; + + // Empty profiles + std::vector profiles; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(0); + + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_002, testing::ext::TestSize.Level1) +{ + const char *credId = "123456"; + const char *credInfo = R"({"deviceId": "remoteUdid", "userId": 1})"; + std::string localUdid = "localUdid"; + std::string remoteUdid; + + // 模拟 profiles 中的 BindType 不等于 DM_SHARE_TYPE + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_POINT_TO_POINT); // 非 DM_SHARE_TYPE + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(0); + + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_003, testing::ext::TestSize.Level1) +{ + const char *credId = "123456"; + const char *credInfo = R"({"deviceId": "remoteUdid", "userId": 1})"; + std::string localUdid = "localUdid"; + std::string remoteUdid; + + // 模拟 Accesser 的 CredentialId 匹配的情况 + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + + profile.GetAccesser().SetAccesserCredentialId(atoi(credId)); + profile.GetAccesser().SetAccesserDeviceId(localUdid); + profile.GetAccessee().SetAccesseeDeviceId("remoteUdid"); + profile.GetAccessee().SetAccesseeUserId(1); + + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(1); + + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_004, testing::ext::TestSize.Level1) +{ + const char *credId = "123456"; + const char *credInfo = R"({"deviceId": "remoteUdid", "userId": 1})"; + std::string localUdid = "localUdid"; + std::string remoteUdid; + + // 模拟 Accessee 的 CredentialId 匹配的情况 + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + + profile.GetAccessee().SetAccesseeCredentialId(atoi(credId)); + profile.GetAccessee().SetAccesseeDeviceId(localUdid); + profile.GetAccesser().SetAccesserDeviceId("remoteUdid"); + profile.GetAccesser().SetAccesserUserId(1); + + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(1); + + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_001, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localId"; + int32_t userId = 123456; + + // Setup empty profiles + std::vector profiles; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(0); + + deviceManagerServiceImpl_->HandleShareUnbindBroadCast(credId, userId, localUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_002, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localId"; + int32_t userId = 123456; + + // Setup mock profile with non-share type + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_IDENTICAL_ACCOUNT); // Different bind type + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(0); + + deviceManagerServiceImpl_->HandleShareUnbindBroadCast(credId, userId, localUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_003, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localId"; + int32_t userId = 123456; + + // 模拟 AccesserCredId 匹配的情况 + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + + Accesser accesser; + accesser.SetAccesserCredentialId(atoi(credId.c_str())); + accesser.SetAccesserUserId(userId); + profile.SetAccesser(accesser); + Accessee accessee; + accessee.SetAccesseeDeviceId(localUdid); + profile.SetAccessee(accessee); + + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(1); + + deviceManagerServiceImpl_->HandleShareUnbindBroadCast(credId, userId, localUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_004, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localUdid"; + int32_t userId = 123456; + + // 模拟 AccesseeCredId 匹配的情况 + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + + Accesser accesser; + accesser.SetAccesserDeviceId(localUdid); + profile.SetAccesser(accesser); + Accessee accessee; + accessee.SetAccesseeCredentialId(atoi(credId.c_str())); + accessee.SetAccesseeUserId(userId); + profile.SetAccessee(accessee); + + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(1); + + deviceManagerServiceImpl_->HandleShareUnbindBroadCast(credId, userId, localUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_005, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localUdid"; + int32_t userId = 123456; + + // Setup mock profile with non-matching credentials + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE_TYPE); + + Accesser accesser; + accesser.SetAccesserCredentialId(9999); // Different credential + accesser.SetAccesserDeviceId("peer123"); + accesser.SetAccesserUserId(1002); // Different user + profile.SetAccesser(accesser); + + Accessee accessee; + accessee.SetAccesseeDeviceId("peer456"); // Different device + accessee.SetAccesseeUserId(1003); + profile.SetAccessee(accessee); + + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)) + .Times(0); + + deviceManagerServiceImpl_->HandleShareUnbindBroadCast(credId, userId, localUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_001, testing::ext::TestSize.Level1) +{ + uint32_t bindType = IDENTICAL_ACCOUNT_TYPE; + ProcessInfo processInfo; + DmDeviceInfo devInfo; + std::string requestDeviceId = "requestDeviceId"; + std::string trustDeviceId = "trustDeviceId"; + DmDeviceState devState = DEVICE_STATE_ONLINE; + + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); + EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); + + deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + + EXPECT_EQ(devInfo.authForm, DmAuthForm::IDENTICAL_ACCOUNT); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_002, testing::ext::TestSize.Level1) +{ + uint32_t bindType = DEVICE_PEER_TO_PEER_TYPE; + ProcessInfo processInfo; + DmDeviceInfo devInfo; + std::string requestDeviceId = "requestDeviceId"; + std::string trustDeviceId = "trustDeviceId"; + DmDeviceState devState = DEVICE_STATE_ONLINE; + + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); + EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); + + deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + + EXPECT_EQ(devInfo.authForm, DmAuthForm::PEER_TO_PEER); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_003, testing::ext::TestSize.Level1) +{ + uint32_t bindType = DEVICE_ACROSS_ACCOUNT_TYPE; + ProcessInfo processInfo; + DmDeviceInfo devInfo; + std::string requestDeviceId = "requestDeviceId"; + std::string trustDeviceId = "trustDeviceId"; + DmDeviceState devState = DEVICE_STATE_ONLINE; + + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); + EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); + + deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + + EXPECT_EQ(devInfo.authForm, DmAuthForm::ACROSS_ACCOUNT); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_004, testing::ext::TestSize.Level1) +{ + uint32_t bindType = APP_PEER_TO_PEER_TYPE; + ProcessInfo processInfo; + DmDeviceInfo devInfo; + std::string requestDeviceId = "requestDeviceId"; + std::string trustDeviceId = "trustDeviceId"; + DmDeviceState devState = DEVICE_STATE_ONLINE; + + std::vector processInfoVec = {processInfo}; + EXPECT_CALL(*deviceProfileConnectorMock_, GetProcessInfoFromAclByUserId(_, _, _)) + .WillOnce(Return(processInfoVec)); + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfoVec(_)).Times(1); + EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); + + deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + + EXPECT_EQ(devInfo.authForm, DmAuthForm::PEER_TO_PEER); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_005, testing::ext::TestSize.Level1) +{ + uint32_t bindType = APP_ACROSS_ACCOUNT_TYPE; + ProcessInfo processInfo; + DmDeviceInfo devInfo; + std::string requestDeviceId = "requestDeviceId"; + std::string trustDeviceId = "trustDeviceId"; + DmDeviceState devState = DEVICE_STATE_ONLINE; + + std::vector processInfoVec = {processInfo}; + EXPECT_CALL(*deviceProfileConnectorMock_, GetProcessInfoFromAclByUserId(_, _, _)) + .WillOnce(Return(processInfoVec)); + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfoVec(_)).Times(1); + EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); + + deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + + EXPECT_EQ(devInfo.authForm, DmAuthForm::ACROSS_ACCOUNT); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_006, testing::ext::TestSize.Level1) +{ + uint32_t bindType = SHARE_TYPE; + ProcessInfo processInfo; + DmDeviceInfo devInfo; + std::string requestDeviceId = "requestDeviceId"; + std::string trustDeviceId = "trustDeviceId"; + DmDeviceState devState = DEVICE_STATE_ONLINE; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .Times(1).WillOnce(Return(std::vector())); + + EXPECT_CALL(*deviceManagerServiceImplMock_, CheckSharePeerSrc(_, _)).WillOnce(Return(false)); + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); + EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); + + deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + + EXPECT_EQ(devInfo.authForm, DmAuthForm::ACROSS_ACCOUNT); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_impl_first.h b/test/unittest/UTTest_device_manager_service_impl_first.h index 4185e0af5..0ed0c30c4 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.h +++ b/test/unittest/UTTest_device_manager_service_impl_first.h @@ -26,6 +26,9 @@ #include "device_manager_service_listener.h" #include "deviceprofile_connector_mock.h" #include "multiple_user_connector_mock.h" +#include "softbus_connector_mock.h" +#include "dm_device_state_manager_mock.h" +#include "device_manager_service_impl_mock.h" namespace OHOS { namespace DistributedHardware { @@ -42,6 +45,12 @@ public: std::make_shared(); static inline std::shared_ptr multipleUserConnectorMock_ = std::make_shared(); + static inline std::shared_ptr softbusConnectorMock_ = + std::make_shared(); + static inline std::shared_ptr dmDeviceStateManagerMock_ = + std::make_shared(); + static inline std::shared_ptr deviceManagerServiceImplMock_ = + std::make_shared(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index a6704b1b6..fccb4f22e 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1827,6 +1827,84 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceNetworkIdList_202, testing::ext::Tes DeviceManagerService::GetInstance().DivideNotifyMethod(peerUdids, bleUdids, wifiDevices); DeviceManagerService::GetInstance().UninitDMServiceListener(); } + +HWTEST_F(DeviceManagerServiceTest, SendShareTypeUnBindBroadCast_001, testing::ext::TestSize.Level1) +{ + const char *credId = "testCredId"; + int32_t localUserId = 1001; + std::vector peerUdids = {"peerUdid1", "peerUdid2"}; + + DeviceManagerService::GetInstance().SendShareTypeUnBindBroadCast(credId, localUserId, peerUdids); + EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); +} + +HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_001, testing::ext::TestSize.Level1) +{ + std::string remoteUdid = "remoteUdid"; + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)) + .WillOnce(SetArgReferee<3>(remoteUdid)); + EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(1001)); + EXPECT_CALL(*softbusListenerMock_, SendAclChangedBroadcast(_)).Times(::testing::AtLeast(1)); + + DeviceManagerService::GetInstance().HandleCredentialDeleted("credId", "credInfo"); +} + +HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_002, testing::ext::TestSize.Level1) +{ + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)).Times(0); + + DeviceManagerService::GetInstance().HandleCredentialDeleted(nullptr, "credInfo"); +} + +HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_003, testing::ext::TestSize.Level1) +{ + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)).Times(0); + + DeviceManagerService::GetInstance().HandleCredentialDeleted("credId", nullptr); +} + +HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_004, testing::ext::TestSize.Level1) +{ + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)) + .WillOnce(SetArgReferee<3>("")); + EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).Times(0); + EXPECT_CALL(*softbusListenerMock_, SendAclChangedBroadcast(_)).Times(0); + + DeviceManagerService::GetInstance().HandleCredentialDeleted("credId", "credInfo"); +} + +HWTEST_F(DeviceManagerServiceTest, HandleShareUnbindBroadCast_001, testing::ext::TestSize.Level1) +{ + std::string credId = "123456"; + int32_t userId = 1001; + std::string localUdid = "localUdid"; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(credId, userId, localUdid)) + .Times(1); + + DeviceManagerService::GetInstance().HandleShareUnbindBroadCast(userId, credId); +} + +HWTEST_F(DeviceManagerServiceTest, HandleShareUnbindBroadCast_002, testing::ext::TestSize.Level1) +{ + std::string credId = ""; + int32_t userId = 1001; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(_, _, _)).Times(0); + + DeviceManagerService::GetInstance().HandleShareUnbindBroadCast(userId, credId); +} + +HWTEST_F(DeviceManagerServiceTest, HandleShareUnbindBroadCast_003, testing::ext::TestSize.Level1) +{ + std::string credId = "123456"; + int32_t userId = 1001; + + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(_, _, _)).Times(0); + EXPECT_FALSE(DeviceManagerService::GetInstance().IsDMServiceImplReady()); + + DeviceManagerService::GetInstance().HandleShareUnbindBroadCast(userId, credId); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_hichain_listener.cpp b/test/unittest/UTTest_hichain_listener.cpp index de97582f8..1d0f88328 100644 --- a/test/unittest/UTTest_hichain_listener.cpp +++ b/test/unittest/UTTest_hichain_listener.cpp @@ -94,5 +94,68 @@ HWTEST_F(HichainListenerTest, OnHichainDeviceUnBound_002, testing::ext::TestSize listerner.OnHichainDeviceUnBound(udidPtr, groupInfoPtr); EXPECT_TRUE(groupInfoPtr != nullptr); } + +HWTEST_F(HichainListenerTest, RegisterCredentialCb_001, testing::ext::TestSize.Level1) +{ + HichainListener listerner; + listerner.RegisterCredentialCb(); + EXPECT_TRUE(listerner.credManager_ != nullptr); +} + +HWTEST_F(HichainListenerTest, RegisterCredentialCb_002, testing::ext::TestSize.Level2) +{ + HichainListener listerner; + listerner.credManager_ = nullptr; + listerner.RegisterCredentialCb(); + EXPECT_TRUE(listerner.credManager_ == nullptr); +} + +HWTEST_F(HichainListenerTest, OnCredentialDeleted_001, testing::ext::TestSize.Level1) +{ + HichainListener listerner; + const char *credId = "credId"; + const char *credInfo = "credInfo"; + listerner.OnCredentialDeleted(credId, credInfo); + EXPECT_TRUE(true); +} + +HWTEST_F(HichainListenerTest, OnCredentialDeleted_002, testing::ext::TestSize.Level1) +{ + HichainListener listerner; + const char *credId = nullptr; + const char *credInfo = "credInfo"; + listerner.OnCredentialDeleted(credId, credInfo); + EXPECT_TRUE(true); +} + +HWTEST_F(HichainListenerTest, OnCredentialDeleted_003, testing::ext::TestSize.Level1) +{ + HichainListener listerner; + const char *credId = "credId"; + const char *credInfo = nullptr; + listerner.OnCredentialDeleted(credId, credInfo); + EXPECT_TRUE(true); +} + +HWTEST_F(HichainListenerTest, OnCredentialDeleted_004, testing::ext::TestSize.Level2) +{ + HichainListener listerner; + // Create string longer than MAX_DATA_LEN (65536) + std::string longCredId(65537, 'a'); + const char *credInfo = "credInfo"; + listerner.OnCredentialDeleted(longCredId.c_str(), credInfo); + EXPECT_TRUE(true); // Verifying early return for invalid length +} + +HWTEST_F(HichainListenerTest, OnCredentialDeleted_005, testing::ext::TestSize.Level2) +{ + HichainListener listerner; + // Create string longer than MAX_DATA_LEN (65536) + std::string longCredId(65537, 'a'); + const char *credInfo = "credInfo"; + listerner.OnCredentialDeleted(longCredId.c_str(), credInfo); + EXPECT_TRUE(true); // Verifying early return for invalid length +} + } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index 9ae4ae9b6..8ebc08543 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -19,6 +19,9 @@ namespace OHOS { namespace DistributedHardware { +constexpr int32_t CREDID_PAYLOAD_LEN = 8; +constexpr int32_t USERID_PAYLOAD_LEN = 2; +const int32_t SHARE_UNBIND_PAYLOAD_LEN = 8; const int32_t MAX_USER_ID_NUM = 5; void ReleationShipSyncMgrTest::SetUp() { @@ -931,6 +934,10 @@ HWTEST_F(ReleationShipSyncMgrTest, FromBroadcastPayLoad_010, testing::ext::TestS type = RelationShipChangeType::APP_UNINSTALL; ret = msg.FromBroadcastPayLoad(payloadJson, type); EXPECT_FALSE(ret); + + type = RelationShipChangeType::SHARE_UNBIND; + ret = msg.FromBroadcastPayLoad(payloadJson, type); + EXPECT_FALSE(ret); } HWTEST_F(ReleationShipSyncMgrTest, IsChangeTypeValid_001, testing::ext::TestSize.Level1) @@ -955,6 +962,15 @@ HWTEST_F(ReleationShipSyncMgrTest, IsChangeTypeValid_001, testing::ext::TestSize msg.type = RelationShipChangeType::DEL_USER; ret = msg.IsChangeTypeValid(); EXPECT_TRUE(ret); + + msg.type = RelationShipChangeType::STOP_USER; + ret = msg.IsChangeTypeValid(); + EXPECT_TRUE(ret); + + msg.type = RelationShipChangeType::SHARE_UNBIND; + ret = msg.IsChangeTypeValid(); + EXPECT_TRUE(ret); + } HWTEST_F(ReleationShipSyncMgrTest, IsValid_010, testing::ext::TestSize.Level1) @@ -970,6 +986,339 @@ HWTEST_F(ReleationShipSyncMgrTest, IsValid_010, testing::ext::TestSize.Level1) ret = msg.IsValid(); EXPECT_FALSE(ret); } + +HWTEST_F(ReleationShipSyncMgrTest, IsValid_011, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SHARE_UNBIND; + msg.userId = 12345; + + ASSERT_TRUE(msg.IsValid()); // 验证 SHARE_UNBIND 类型有效 + + msg.userId = UINT32_MAX; // userId 无效 + ASSERT_FALSE(msg.IsValid()); // 验证无效情况 +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::ACCOUNT_LOGOUT; + msg.userId = 12345; + msg.accountId = "test_account"; + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + ASSERT_NE(msgPtr, nullptr); + ASSERT_GT(len, 0); + + delete[] msgPtr; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_002, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::DEVICE_UNBIND; + msg.userId = 12345; + msg.peerUdids = {"udid1", "udid2"}; + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + ASSERT_NE(msgPtr, nullptr); + ASSERT_GT(len, 0); + + delete[] msgPtr; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_003, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::APP_UNBIND; + msg.userId = 12345; + msg.tokenId = 67890; + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + ASSERT_NE(msgPtr, nullptr); + ASSERT_GT(len, 0); + + delete[] msgPtr; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_004, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SYNC_USERID; + msg.userIdInfos.push_back({12345, true}); + msg.userIdInfos.push_back({67890, false}); + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + ASSERT_NE(msgPtr, nullptr); + ASSERT_GT(len, 0); + + delete[] msgPtr; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_005, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SYNC_USERID; + for (int i = 0; i < MAX_USER_ID_NUM + 1; ++i) { + msg.userIdInfos.push_back({i, true}); + } + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_FALSE(result); + ASSERT_EQ(msgPtr, nullptr); +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_006, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::DEL_USER; + msg.userId = 12345; + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + ASSERT_NE(msgPtr, nullptr); + ASSERT_GT(len, 0); + + delete[] msgPtr; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_007, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::STOP_USER; + msg.userId = 12345; + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + ASSERT_NE(msgPtr, nullptr); + ASSERT_GT(len, 0); + + delete[] msgPtr; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_008, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::SHARE_UNBIND; + msg.userId = 12345; + msg.peerUdids = {"udid1", "udid2"}; + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_TRUE(result); + ASSERT_NE(msgPtr, nullptr); + ASSERT_GT(len, 0); + + delete[] msgPtr; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_009, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.type = static_cast(99); // Invalid type + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + bool result = msg.ToBroadcastPayLoad(msgPtr, len); + ASSERT_FALSE(result); + ASSERT_EQ(msgPtr, nullptr); + ASSERT_EQ(len, 0); +} + +HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.userId = 12345; // 设置有效的 userId + msg.credId = "cred123"; // 设置有效的 credId + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + msg.ToShareUnbindPayLoad(msgPtr, len); + + ASSERT_EQ(len, 8); // 验证长度是否正确 + ASSERT_NE(msgPtr, nullptr); // 验证指针是否有效 + + // 验证 userId 部分是否正确 + ASSERT_EQ(msgPtr[0], static_cast(msg.userId & 0xFF)); + ASSERT_EQ(msgPtr[1], static_cast((msg.userId >> 8) & 0xFF)); + + // 验证 credId 部分是否正确 + for (int i = 0; i < CREDID_PAYLOAD_LEN - USERID_PAYLOAD_LEN; i++) { + ASSERT_EQ(msgPtr[USERID_PAYLOAD_LEN + i], msg.credId[i]); + } + + delete[] msgPtr; // 释放动态分配的内存 +} + +HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_002, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.userId = 12345; // 设置有效的 userId + msg.credId = ""; // 设置空的 credId + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + msg.ToShareUnbindPayLoad(msgPtr, len); + + ASSERT_EQ(len, SHARE_UNBIND_PAYLOAD_LEN); // 验证长度是否正确 + ASSERT_NE(msgPtr, nullptr); // 验证指针是否有效 + + // 验证 userId 部分是否正确 + ASSERT_EQ(msgPtr[0], static_cast(msg.userId & 0xFF)); + ASSERT_EQ(msgPtr[1], static_cast((msg.userId >> 8) & 0xFF)); + + // 验证 credId 部分是否为空 + for (int i = USERID_PAYLOAD_LEN; i < SHARE_UNBIND_PAYLOAD_LEN; i++) { + ASSERT_EQ(msgPtr[i], 0); + } + + delete[] msgPtr; // 释放动态分配的内存 +} + +HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_003, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + msg.userId = UINT16_MAX; // 设置最大值的 userId + msg.credId = "cred123"; // 设置有效的 credId + + uint8_t* msgPtr = nullptr; + uint32_t len = 0; + + msg.ToShareUnbindPayLoad(msgPtr, len); + + ASSERT_EQ(len, SHARE_UNBIND_PAYLOAD_LEN); // 验证长度是否正确 + ASSERT_NE(msgPtr, nullptr); // 验证指针是否有效 + + // 验证 userId 部分是否正确 + ASSERT_EQ(msgPtr[0], static_cast(msg.userId & 0xFF)); + ASSERT_EQ(msgPtr[1], static_cast((msg.userId >> 8) & 0xFF)); + + // 验证 credId 部分是否正确 + for (int i = 0; i < CREDID_PAYLOAD_LEN - USERID_PAYLOAD_LEN; i++) { + ASSERT_EQ(msgPtr[USERID_PAYLOAD_LEN + i], msg.credId[i]); + } + + delete[] msgPtr; // 释放动态分配的内存 +} + +HWTEST_F(ReleationShipSyncMgrTest, FromShareUnbindPayLoad_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + cJSON *payloadJson = nullptr; + + bool result = msg.FromShareUnbindPayLoad(payloadJson); + + ASSERT_FALSE(result); // 验证当 payloadJson 为 null 时返回 false +} + +HWTEST_F(ReleationShipSyncMgrTest, FromShareUnbindPayLoad_002, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + cJSON *payloadJson = cJSON_CreateArray(); + + // 添加少于 SHARE_UNBIND_PAYLOAD_LEN 的元素 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber(1)); + + bool result = msg.FromShareUnbindPayLoad(payloadJson); + + ASSERT_FALSE(result); // 验证当数组大小小于 SHARE_UNBIND_PAYLOAD_LEN 时返回 false + + cJSON_Delete(payloadJson); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromShareUnbindPayLoad_003, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + cJSON *payloadJson = cJSON_CreateArray(); + + // 添加有效的 userId 和 credId 数据 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber(0x12)); // userId 第 1 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber(0x34)); // userId 第 2 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('c')); // credId 第 1 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('r')); // credId 第 2 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('e')); // credId 第 3 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('d')); // credId 第 4 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('1')); // credId 第 5 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('2')); // credId 第 6 字节 + + bool result = msg.FromShareUnbindPayLoad(payloadJson); + + ASSERT_TRUE(result); // 验证当 payloadJson 有效时返回 true + ASSERT_EQ(msg.userId, 0x3412); // 验证 userId 是否正确解析 + ASSERT_EQ(msg.credId, "cred12"); // 验证 credId 是否正确解析 + + cJSON_Delete(payloadJson); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromShareUnbindPayLoad_004, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + cJSON *payloadJson = cJSON_CreateArray(); + + // 添加无效的元素(非数字类型) + cJSON_AddItemToArray(payloadJson, cJSON_CreateString("invalid")); + + bool result = msg.FromShareUnbindPayLoad(payloadJson); + + ASSERT_FALSE(result); // 验证当 payloadJson 包含无效元素时返回 false + + cJSON_Delete(payloadJson); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromShareUnbindPayLoad_005, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msg; + cJSON *payloadJson = cJSON_CreateArray(); + + // 添加有效的 userId 和 credId 数据 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber(0x12)); // userId 第 1 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber(0x34)); // userId 第 2 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('c')); // credId 第 1 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('r')); // credId 第 2 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('e')); // credId 第 3 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('d')); // credId 第 4 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('1')); // credId 第 5 字节 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber('2')); // credId 第 6 字节 + + // 添加额外的无效元素 + cJSON_AddItemToArray(payloadJson, cJSON_CreateNumber(0x56)); + + bool result = msg.FromShareUnbindPayLoad(payloadJson); + + ASSERT_FALSE(result); // 验证当 payloadJson 包含额外元素时返回 false + + cJSON_Delete(payloadJson); +} } } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/device_auth.h b/test/unittest/mock/device_auth.h index 6e520f698..1a37168fc 100644 --- a/test/unittest/mock/device_auth.h +++ b/test/unittest/mock/device_auth.h @@ -138,6 +138,12 @@ using DataChangeListener = struct DataChangeListener { void (*onTrustedDeviceNumChanged)(int curTrustedDeviceNum); }; +using CredChangeListener = struct CredChangeListener { + void (*onCredAdd)(const char *credId, const char *credInfo); + void (*onCredDelete)(const char *credId, const char *credInfo); + void (*onCredUpdate)(const char *credId, const char *credInfo); +}; + using DeviceAuthCallback = struct DeviceAuthCallback { bool (*onTransmit)(int64_t requestId, const uint8_t *data, uint32_t dataLen); void (*onSessionKeyReturned)(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); @@ -146,6 +152,22 @@ using DeviceAuthCallback = struct DeviceAuthCallback { char *(*onRequest)(int64_t requestId, int operationCode, const char *reqParams); }; +using CredManager = struct CredManager { + int32_t (*addCredential)(int32_t osAccountId, const char *requestParams, char **returnData); + int32_t (*exportCredential)(int32_t osAccountId, const char *credId, char **returnData); + int32_t (*queryCredentialByParams)(int32_t osAccountId, const char *requestParams, char **returnData); + int32_t (*queryCredInfoByCredId)(int32_t osAccountId, const char *credId, char **returnData); + int32_t (*deleteCredential)(int32_t osAccountId, const char *credId); + int32_t (*updateCredInfo)(int32_t osAccountId, const char *credId, const char *requestParams); + int32_t (*agreeCredential)(int32_t osAccountId, const char *selfCredId, const char *requestParams, + char **returnData); + int32_t (*registerChangeListener)(const char *appId, CredChangeListener *listener); + int32_t (*unregisterChangeListener)(const char *appId); + int32_t (*deleteCredByParams)(int32_t osAccountId, const char *requestParams, char **returnData); + int32_t (*batchUpdateCredentials)(int32_t osAccountId, const char *requestParams, char **returnData); + void (*destroyInfo)(char **returnData); +}; + using GroupAuthManager = struct GroupAuthManager { int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *gaCallback); @@ -214,6 +236,7 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void); DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void); DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void); DEVICE_AUTH_API_PUBLIC const DeviceGroupManager *GetGmInstance(void); +DEVICE_AUTH_API_PUBLIC const CredManager *GetCredMgrInstance(void); #ifdef __cplusplus } #endif diff --git a/test/unittest/mock/device_manager_service_impl_mock.cpp b/test/unittest/mock/device_manager_service_impl_mock.cpp index 6ed0f5a53..99349637d 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.cpp +++ b/test/unittest/mock/device_manager_service_impl_mock.cpp @@ -67,5 +67,21 @@ int32_t DeviceManagerServiceImpl::UnBindDevice(const std::string &pkgName, const { return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->UnBindDevice(pkgName, udid, bindLevel, extra); } +bool DeviceManagerServiceImpl::CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid) +{ + return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->CheckSharePeerSrc(peerUdid, localUdid); +} + +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, + const char *credInfo, const std::string &localUdid, std::string &remoteUdid) +{ + DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleCredentialDeleted(credId, + credInfo, localUdid, remoteUdid); +} +void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, + const int32_t &userId, const std::string &localUdid) +{ + DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleShareUnbindBroadCast(credId, userId, localUdid); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/device_manager_service_impl_mock.h b/test/unittest/mock/device_manager_service_impl_mock.h index bbc6f8792..71d4613b9 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.h +++ b/test/unittest/mock/device_manager_service_impl_mock.h @@ -37,6 +37,11 @@ public: virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel) = 0; virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel, const std::string &extra) = 0; + virtual bool CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid) = 0; + virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, + std::string &remoteUdid) = 0; + virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + const std::string &localUdid) = 0; public: static inline std::shared_ptr dmDeviceManagerServiceImpl = nullptr; }; @@ -52,6 +57,9 @@ public: MOCK_METHOD((std::unordered_map), GetAppTrustDeviceIdList, (std::string)); MOCK_METHOD(int32_t, UnAuthenticateDevice, (const std::string &, const std::string &, int32_t)); MOCK_METHOD(int32_t, UnBindDevice, (const std::string &, const std::string &, int32_t, const std::string &)); + MOCK_METHOD(bool, CheckSharePeerSrc, (const std::string &peerUdid, const std::string &localUdid)); + MOCK_METHOD(void, HandleCredentialDeleted, (const char *, const char *, const std::string &, std::string &)); + MOCK_METHOD(void, HandleShareUnbindBroadCast, (const std::string &, const int32_t &, const std::string &)); }; } } diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index f63e4791d..ff961032c 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -161,6 +161,23 @@ std::map DeviceProfileConnector::GetDeviceIdAndBindLevel(s return DmDeviceProfileConnector::dmDeviceProfileConnector->GetDeviceIdAndBindLevel(userIds, localUdid); } +void DeviceProfileConnector::DeleteAccessControlById(int64_t accessControlId) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->DeleteAccessControlById(accessControlId); +} + +std::vector DeviceProfileConnector::GetProcessInfoFromAclByUserId( + const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->GetProcessInfoFromAclByUserId(localDeviceId, + targetDeviceId, userId); +} + +std::vector DeviceProfileConnector::GetAccessControlProfile() +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->GetAccessControlProfile(); +} + std::vector DeviceProfileConnector::GetAllAclIncludeLnnAcl() { return DmDeviceProfileConnector::dmDeviceProfileConnector->GetAllAclIncludeLnnAcl(); diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index 6a464f4bb..a643fc500 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -65,6 +65,10 @@ public: const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; virtual std::map GetDeviceIdAndBindLevel(std::vector userIds, const std::string &localUdid) = 0; + virtual void DeleteAccessControlById(int64_t& accessControlId) = 0; + virtual std::vector GetProcessInfoFromAclByUserId(const std::string &localDeviceId, + const std::string &targetDeviceId, int32_t userId) = 0; + virtual std::vector GetAccessControlProfile() = 0; virtual std::vector GetAllAclIncludeLnnAcl() = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; @@ -105,6 +109,10 @@ public: (const std::string &, (const std::vector &), (const std::vector &))); MOCK_METHOD((std::map), GetDeviceIdAndBindLevel, ((std::vector), const std::string &)); + MOCK_METHOD(void, DeleteAccessControlById, (int64_t& accessControlId)); + MOCK_METHOD(std::vector, GetProcessInfoFromAclByUserId, + (const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId)); + MOCK_METHOD(std::vector, GetAccessControlProfile, ()); MOCK_METHOD(std::vector, GetAllAclIncludeLnnAcl, ()); }; } diff --git a/test/unittest/mock/dm_device_state_manager_mock.cpp b/test/unittest/mock/dm_device_state_manager_mock.cpp index d1625eea9..0f8fa194d 100644 --- a/test/unittest/mock/dm_device_state_manager_mock.cpp +++ b/test/unittest/mock/dm_device_state_manager_mock.cpp @@ -29,5 +29,9 @@ int32_t DmDeviceStateManager::ProcNotifyEvent(const int32_t eventId, const std:: { return DmDmDeviceStateManager::dmDeviceStateManager->ProcNotifyEvent(eventId, deviceId); } +void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) +{ + DmDmDeviceStateManager::dmDeviceStateManager->HandleDeviceStatusChange(devState, devInfo); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/dm_device_state_manager_mock.h b/test/unittest/mock/dm_device_state_manager_mock.h index cc90c2647..98c5ab207 100644 --- a/test/unittest/mock/dm_device_state_manager_mock.h +++ b/test/unittest/mock/dm_device_state_manager_mock.h @@ -28,6 +28,7 @@ public: public: virtual std::string GetUdidByNetWorkId(std::string networkId) = 0; virtual int32_t ProcNotifyEvent(const int32_t eventId, const std::string &deviceId) = 0; + virtual void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) = 0; public: static inline std::shared_ptr dmDeviceStateManager = nullptr; }; @@ -36,6 +37,7 @@ class DmDeviceStateManagerMock : public DmDmDeviceStateManager { public: MOCK_METHOD(std::string, GetUdidByNetWorkId, (std::string)); MOCK_METHOD(int32_t, ProcNotifyEvent, (const int32_t, const std::string &)); + MOCK_METHOD(void, HandleDeviceStatusChange, (DmDeviceState devState, DmDeviceInfo &devInfo)); }; } } diff --git a/test/unittest/mock/softbus_connector_mock.cpp b/test/unittest/mock/softbus_connector_mock.cpp index 77c65ea49..f5d5ea48a 100644 --- a/test/unittest/mock/softbus_connector_mock.cpp +++ b/test/unittest/mock/softbus_connector_mock.cpp @@ -39,6 +39,14 @@ DmDeviceInfo SoftbusConnector::GetDeviceInfoByDeviceId(const std::string &device { return DmSoftbusConnector::dmSoftbusConnector->GetDeviceInfoByDeviceId(deviceId); } +void SoftbusConnector::SetProcessInfo(ProcessInfo processInfo) +{ + DmSoftbusConnector::dmSoftbusConnector->SetProcessInfo(processInfo); +} +void SoftbusConnector::SetProcessInfoVec(std::vector processInfoVec) +{ + DmSoftbusConnector::dmSoftbusConnector->SetProcessInfoVec(processInfoVec); +} std::shared_ptr SoftbusConnector::GetSoftbusSession() { diff --git a/test/unittest/mock/softbus_connector_mock.h b/test/unittest/mock/softbus_connector_mock.h index a8caf1492..3ac972388 100644 --- a/test/unittest/mock/softbus_connector_mock.h +++ b/test/unittest/mock/softbus_connector_mock.h @@ -31,6 +31,8 @@ public: virtual std::vector GetProcessInfo() = 0; virtual DmDeviceInfo GetDeviceInfoByDeviceId(const std::string &deviceId) = 0; virtual std::shared_ptr GetSoftbusSession(); + virtual void SetProcessInfo(ProcessInfo processInfo) = 0; + virtual void SetProcessInfoVec(std::vector processInfoVec) = 0; public: static inline std::shared_ptr dmSoftbusConnector = nullptr; }; @@ -42,6 +44,8 @@ public: MOCK_METHOD(std::vector, GetProcessInfo, ()); MOCK_METHOD(DmDeviceInfo, GetDeviceInfoByDeviceId, (const std::string &deviceId)); MOCK_METHOD(std::shared_ptr, GetSoftbusSession, ()); + MOCK_METHOD(void, SetProcessInfo, (ProcessInfo processInfo)); + MOCK_METHOD(void, SetProcessInfoVec, (std::vector processInfoVec)); }; } } diff --git a/test/unittest/mock/softbus_listener_mock.cpp b/test/unittest/mock/softbus_listener_mock.cpp index 3049008b3..eb67a660c 100644 --- a/test/unittest/mock/softbus_listener_mock.cpp +++ b/test/unittest/mock/softbus_listener_mock.cpp @@ -96,5 +96,9 @@ int32_t SoftbusListener::StopRefreshSoftbusLNN(uint16_t subscribeId) { return DmSoftbusListener::dmSoftbusListener->StopRefreshSoftbusLNN(subscribeId); } +void SoftbusListener::SendAclChangedBroadcast(const std::string &msg) +{ + DmSoftbusListener::dmSoftbusListener->SendAclChangedBroadcast(msg); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/softbus_listener_mock.h b/test/unittest/mock/softbus_listener_mock.h index 808d34b6f..5a3f1aab7 100644 --- a/test/unittest/mock/softbus_listener_mock.h +++ b/test/unittest/mock/softbus_listener_mock.h @@ -44,6 +44,7 @@ public: virtual int32_t GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList) = 0; virtual int32_t StopRefreshSoftbusLNN(uint16_t subscribeId) = 0; + virtual void SendAclChangedBroadcast(const std::string &msg) = 0; public: static inline std::shared_ptr dmSoftbusListener = nullptr; }; @@ -66,6 +67,7 @@ public: MOCK_METHOD(int32_t, GetAllTrustedDeviceList, (const std::string &, const std::string &, std::vector &)); MOCK_METHOD(int32_t, StopRefreshSoftbusLNN, (uint16_t)); + MOCK_METHOD(void, SendAclChangedBroadcast, (const std::string &msg)); }; } } -- Gitee From ecd30ca807321497f6a86ff3660d763d8c7501a1 Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 23 Apr 2025 09:04:25 +0800 Subject: [PATCH 02/21] modify Signed-off-by: BrainL --- .../include/deviceprofile_connector.h | 4 ++-- .../src/deviceprofile_connector.cpp | 19 +++++++++++-------- .../include/device_manager_service_impl.h | 2 +- .../src/authentication_v2/dm_auth_state.cpp | 2 +- .../src/device_manager_service_impl.cpp | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 86642290f..b1fe09954 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -316,10 +316,10 @@ private: uint32_t index, std::string targetDeviceId); bool CheckAppLevelAccess(const DistributedDeviceProfile::AccessControlProfile &profile, const DmAccessCaller &caller, const DmAccessCallee &callee); - bool CheckSinkShareType(DistributedDeviceProfile::AccessControlProfile profile, + bool CheckSinkShareType(const DistributedDeviceProfile::AccessControlProfile &profile, const int32_t &userId, const std::string &deviceId, const std::string &trustDeviceId, const int32_t &bindType); std::unordered_map GetAuthFormMap(const std::string &pkgName, const std::string &deviceId, - std::vector profilesFilter, const int32_t &userId); + const std::vector &profilesFilter, const int32_t &userId); int32_t GetAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, const std::string &trustDev, const std::string &reqDev); int32_t CheckAuthForm(DmAuthForm form, DistributedDeviceProfile::AccessControlProfile profiles, diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 3e433cb3d..ec2566ce2 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -642,7 +642,7 @@ EXPORT std::unordered_map DeviceProfileConnector::GetAp } std::unordered_map DeviceProfileConnector::GetAuthFormMap(const std::string &pkgName, - const std::string &deviceId, std::vector profilesFilter, + const std::string &deviceId, const std::vector &profilesFilter, const int32_t &userId) { std::unordered_map deviceIdMap; @@ -669,27 +669,30 @@ std::unordered_map DeviceProfileConnector::GetAuthFormM if (bindType == authForm) { continue; } - if (bindType == DmAuthForm::IDENTICAL_ACCOUNT) { + uint32_t highestBindType = CheckBindType(trustDeviceId, deviceId); + if (highestBindType == IDENTICAL_ACCOUNT_TYPE) { deviceIdMap[trustDeviceId] = DmAuthForm::IDENTICAL_ACCOUNT; continue; - } - if (bindType == DmAuthForm::ACROSS_ACCOUNT) { - if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, bindType)) { + } else if (highestBindType == SHARE_TYPE) { + if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, DmAuthForm::ACROSS_ACCOUNT)) { LOGI("GetAuthFormMap CheckSinkShareType true."); continue; } deviceIdMap[trustDeviceId] = DmAuthForm::ACROSS_ACCOUNT; continue; - } - if (bindType == DmAuthForm::PEER_TO_PEER && authForm == DmAuthForm::ACROSS_ACCOUNT) { + } else if (highestBindType == DEVICE_PEER_TO_PEER_TYPE || highestBindType == APP_PEER_TO_PEER_TYPE || + SERVICE_PEER_TO_PEER_TYPE) { deviceIdMap[trustDeviceId] = DmAuthForm::PEER_TO_PEER; continue; + } else { + deviceIdMap[trustDeviceId] = DmAuthForm::ACROSS_ACCOUNT; + continue; } } return deviceIdMap; } -bool DeviceProfileConnector::CheckSinkShareType(DistributedDeviceProfile::AccessControlProfile profile, +bool DeviceProfileConnector::CheckSinkShareType(const DistributedDeviceProfile::AccessControlProfile &profile, const int32_t &userId, const std::string &deviceId, const std::string &trustDeviceId, const int32_t &bindType) { if ((profile.GetAccessee().GetAccesseeUserId() == userId || diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index f791b5a77..0117ea796 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -184,7 +184,7 @@ public: private: int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); std::string GetUdidHashByNetworkId(const std::string &networkId); - void SetOnlineProcessInfo(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, + void SetOnlineProcessInfo(const uint32_t &bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState); void HandleDeletedAclOffline(const std::string &trustDeviceId, const std::string &requestDeviceId, DmDeviceInfo &devInfo, ProcessInfo &processInfo, DmDeviceState &devState); diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 9457036b8..08144632b 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -276,7 +276,7 @@ int32_t DmAuthState::GetAclBindType(std::shared_ptr context, std: return DM_POINT_TO_POINT_TYPE; } if (credType == DM_AUTH_CREDENTIAL_ACCOUNT_ACROSS) { - return DM_SHARE_TYPE; + return DM_SHARE; } return DM_UNKNOWN_TYPE; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 94329ff87..63cfebfb2 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -649,7 +649,7 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); } -void DeviceManagerServiceImpl::SetOnlineProcessInfo(uint32_t bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, +void DeviceManagerServiceImpl::SetOnlineProcessInfo(const uint32_t &bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState) { if (bindType == IDENTICAL_ACCOUNT_TYPE) { -- Gitee From 47f047d7d35e5a1fb8398db44d257941510095e8 Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 23 Apr 2025 09:16:40 +0800 Subject: [PATCH 03/21] modify Signed-off-by: BrainL --- services/implementation/src/authentication_v2/dm_auth_state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 08144632b..9457036b8 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -276,7 +276,7 @@ int32_t DmAuthState::GetAclBindType(std::shared_ptr context, std: return DM_POINT_TO_POINT_TYPE; } if (credType == DM_AUTH_CREDENTIAL_ACCOUNT_ACROSS) { - return DM_SHARE; + return DM_SHARE_TYPE; } return DM_UNKNOWN_TYPE; } -- Gitee From c2dd6ae7e444fa059e5199b2686b645ff686f7e7 Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 23 Apr 2025 14:50:18 +0800 Subject: [PATCH 04/21] modify format Signed-off-by: BrainL --- .../src/authentication_v2/dm_auth_state.cpp | 2 +- .../src/device_manager_service_impl.cpp | 4 +- ...Test_dm_deviceprofile_connector_second.cpp | 28 +-- .../UTTest_device_manager_service.cpp | 161 ------------------ ...Test_device_manager_service_impl_first.cpp | 11 +- .../UTTest_device_manager_service_three.cpp | 100 +++++++++++ .../unittest/UTTest_relationship_sync_mgr.cpp | 1 - .../mock/device_manager_service_impl_mock.cpp | 6 +- .../mock/device_manager_service_impl_mock.h | 2 +- .../mock/deviceprofile_connector_mock.cpp | 2 +- 10 files changed, 132 insertions(+), 185 deletions(-) diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 9457036b8..08144632b 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -276,7 +276,7 @@ int32_t DmAuthState::GetAclBindType(std::shared_ptr context, std: return DM_POINT_TO_POINT_TYPE; } if (credType == DM_AUTH_CREDENTIAL_ACCOUNT_ACROSS) { - return DM_SHARE_TYPE; + return DM_SHARE; } return DM_UNKNOWN_TYPE; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 63cfebfb2..319ffb9ff 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -649,8 +649,8 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); } -void DeviceManagerServiceImpl::SetOnlineProcessInfo(const uint32_t &bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, - const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState) +void DeviceManagerServiceImpl::SetOnlineProcessInfo(const uint32_t &bindType, ProcessInfo &processInfo, + DmDeviceInfo &devInfo, const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState) { if (bindType == IDENTICAL_ACCOUNT_TYPE) { devInfo.authForm = DmAuthForm::IDENTICAL_ACCOUNT; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index 511a563fa..7e7659007 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -637,7 +637,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_001, testing::ext: accesser.SetAccesserDeviceId(trustDeviceId); profile.SetAccesser(accesser); - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_TRUE(ret); } @@ -658,7 +659,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_002, testing::ext: accesser.SetAccesserDeviceId(trustDeviceId); profile.SetAccesser(accesser); - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_TRUE(ret); } @@ -678,9 +680,10 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_003, testing::ext: DistributedDeviceProfile::Accesser accesser; accesser.SetAccesserDeviceId(trustDeviceId); profile.SetAccesser(accesser); - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_TRUE(ret); -} +} HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_004, testing::ext::TestSize.Level1) { @@ -699,7 +702,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_004, testing::ext: accesser.SetAccesserDeviceId(trustDeviceId); profile.SetAccesser(accesser); - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_FALSE(ret); } @@ -720,7 +724,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_005, testing::ext: accesser.SetAccesserDeviceId("wrongTrustDeviceId"); profile.SetAccesser(accesser); - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_FALSE(ret); } @@ -741,7 +746,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_006, testing::ext: accesser.SetAccesserDeviceId(trustDeviceId); profile.SetAccesser(accesser); - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_FALSE(ret); } @@ -761,7 +767,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_007, testing::ext: DistributedDeviceProfile::Accesser accesser; accesser.SetAccesserDeviceId(trustDeviceId); profile.SetAccesser(accesser); - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_FALSE(ret); } @@ -774,7 +781,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_008, testing::ext: int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; // Empty profile (no accessee/accesser set) - bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(profile, userId, deviceId, trustDeviceId, bindType); + bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( + profile, userId, deviceId, trustDeviceId, bindType); EXPECT_FALSE(ret); } @@ -818,7 +826,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_003, testing::ext::Tes std::vector profilesFilter; DistributedDeviceProfile::AccessControlProfile profile; profile.SetTrustDeviceId(trustDeviceId); - profile.SetStatus(INACTIVE); + profile.SetStatus(INACTIVE); profilesFilter.push_back(profile); auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId); diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index d93430fe3..c2ec639e0 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -1329,19 +1329,6 @@ HWTEST_F(DeviceManagerServiceTest, OnSessionOpened_001, testing::ext::TestSize.L EXPECT_NE(ret, ERR_DM_NOT_INIT); } -HWTEST_F(DeviceManagerServiceTest, OnPinHolderSessionOpened_001, testing::ext::TestSize.Level1) -{ - DeviceManagerService::GetInstance().isImplsoLoaded_ = false; - int sessionId = 0; - int result = 0; - void *data = nullptr; - unsigned int dataLen = 0; - int ret = DeviceManagerService::GetInstance().OnPinHolderSessionOpened(sessionId, result); - DeviceManagerService::GetInstance().OnPinHolderBytesReceived(sessionId, data, dataLen); - DeviceManagerService::GetInstance().OnPinHolderSessionClosed(sessionId); - EXPECT_NE(ret, DM_OK); -} - HWTEST_F(DeviceManagerServiceTest, MineRequestCredential_001, testing::ext::TestSize.Level1) { DeviceManagerService::GetInstance().isImplsoLoaded_ = false; @@ -1465,22 +1452,6 @@ HWTEST_F(DeviceManagerServiceTest, UnRegisterUiStateCallback_003, testing::ext:: EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); } - -HWTEST_F(DeviceManagerServiceTest, IsDMImplSoLoaded_001, testing::ext::TestSize.Level1) -{ - DeviceManagerService::GetInstance().isImplsoLoaded_ = false; - bool ret = DeviceManagerService::GetInstance().IsDMImplSoLoaded(); - EXPECT_FALSE(ret); -} - -HWTEST_F(DeviceManagerServiceTest, DmHiDumper_001, testing::ext::TestSize.Level1) -{ - std::vector args; - std::string result; - int32_t ret = DeviceManagerService::GetInstance().DmHiDumper(args, result); - EXPECT_EQ(ret, DM_OK); -} - HWTEST_F(DeviceManagerServiceTest, NotifyEvent_001, testing::ext::TestSize.Level1) { std::string pkgName; @@ -1571,26 +1542,6 @@ HWTEST_F(DeviceManagerServiceTest, GetEncryptedUuidByNetworkId_003, testing::ext EXPECT_EQ(ret, ERR_DM_FAILED); } -HWTEST_F(DeviceManagerServiceTest, GenerateEncryptedUuid_001, testing::ext::TestSize.Level1) -{ - std::string pkgName; - std::string uuid; - std::string appId; - std::string encryptedUuid; - int32_t ret = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - -HWTEST_F(DeviceManagerServiceTest, GenerateEncryptedUuid_002, testing::ext::TestSize.Level1) -{ - std::string pkgName = "pkgName"; - std::string uuid; - std::string appId; - std::string encryptedUuid; - int32_t ret = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid); - EXPECT_EQ(ret, DM_OK); -} - HWTEST_F(DeviceManagerServiceTest, CheckApiPermission_002, testing::ext::TestSize.Level1) { DeletePermission(); @@ -2157,14 +2108,6 @@ HWTEST_F(DeviceManagerServiceTest, IsSameAccount_003, testing::ext::TestSize.Lev EXPECT_EQ(ret, ERR_DM_NO_PERMISSION); } -HWTEST_F(DeviceManagerServiceTest, HandleDeviceStatusChange_001, testing::ext::TestSize.Level1) -{ - DmDeviceState devState = DmDeviceState::DEVICE_INFO_READY; - DmDeviceInfo devInfo; - DeviceManagerService::GetInstance().HandleDeviceStatusChange(devState, devInfo); - EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); -} - HWTEST_F(DeviceManagerServiceTest, CheckIsSameAccount_001, testing::ext::TestSize.Level1) { DmAccessCaller caller; @@ -2239,50 +2182,6 @@ HWTEST_F(DeviceManagerServiceTest, DestroyPinHolder_003, testing::ext::TestSize. EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } -HWTEST_F(DeviceManagerServiceTest, SendAppUnBindBroadCast_001, testing::ext::TestSize.Level1) -{ - std::vector peerUdids; - int32_t userId = 12; - uint64_t tokenId = 23; - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - DeviceManagerService::GetInstance().SendAppUnBindBroadCast(peerUdids, userId, tokenId); - EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); - DeviceManagerService::GetInstance().softbusListener_ = nullptr; -} - -HWTEST_F(DeviceManagerServiceTest, SendAppUnBindBroadCast_002, testing::ext::TestSize.Level1) -{ - std::vector peerUdids; - int32_t userId = 12; - uint64_t peerTokenId = 3; - uint64_t tokenId = 23; - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - DeviceManagerService::GetInstance().SendAppUnBindBroadCast(peerUdids, userId, tokenId, peerTokenId); - EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); - DeviceManagerService::GetInstance().softbusListener_ = nullptr; -} - -HWTEST_F(DeviceManagerServiceTest, SendServiceUnBindBroadCast_001, testing::ext::TestSize.Level1) -{ - std::vector peerUdids; - int32_t userId = 12; - uint64_t tokenId = 23; - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - DeviceManagerService::GetInstance().SendServiceUnBindBroadCast(peerUdids, userId, tokenId); - EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); - DeviceManagerService::GetInstance().softbusListener_ = nullptr; -} - -HWTEST_F(DeviceManagerServiceTest, ClearDiscoveryCache_001, testing::ext::TestSize.Level1) -{ - ProcessInfo processInfo; - processInfo.pkgName = "pkgName001"; - DeviceManagerService::GetInstance().InitDMServiceListener(); - DeviceManagerService::GetInstance().ClearDiscoveryCache(processInfo); - EXPECT_NE(DeviceManagerService::GetInstance().discoveryMgr_, nullptr); - DeviceManagerService::GetInstance().UninitDMServiceListener(); -} - HWTEST_F(DeviceManagerServiceTest, GetDeviceScreenStatus_001, testing::ext::TestSize.Level1) { std::string pkgName; @@ -2380,66 +2279,6 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalDeviceInfo_002, testing::ext::TestSiz "peerUdid" : "110", "accountName" : "account_wang" })"; - msg = R"( - { - "type" : 3, - "userId" : 130, - "accountId" : "28880", - "tokenId" : 19, - "peerUdid" : "111", - "accountName" : "account_liang" - })"; - DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); - msg = R"( - { - "type" : 4, - "userId" : 131, - "accountId" : "28881", - "tokenId" : 20, - "peerUdid" : "112", - "accountName" : "account_deng" - })"; - DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); - msg = R"( - { - "type" : 5, - "userId" : 131, - "accountId" : "28882", - "tokenId" : 20, - "peerUdid" : "112", - "accountName" : "account_deng" - })"; - DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); - msg = R"( - { - "type" : 6, - "userId" : 132, - "accountId" : "28883", - "tokenId" : 21, - "peerUdid" : "113", - "accountName" : "account_zhang" - })"; - DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); - msg = R"( - { - "type" : 7, - "userId" : 133, - "accountId" : "28884", - "tokenId" : 22, - "peerUdid" : "114", - "accountName" : "account_hu" - })"; - DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); - msg = R"( - { - "type" : 8, - "userId" : 134, - "accountId" : "28885", - "tokenId" : 23, - "peerUdid" : "115", - "accountName" : "account_liu" - })"; - DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg); int32_t ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info); EXPECT_EQ(ret, ERR_DM_POINT_NULL); } diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index 6ca44b9f5..e05083c4f 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -213,8 +213,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_001, testing std::string localUdid = "localUdid"; std::string remoteUdid; - // Empty profiles - std::vector profiles; + // Empty profiles + std::vector profiles; EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) .WillOnce(Return(profiles)); @@ -324,7 +324,7 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_002, test // Setup mock profile with non-share type std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_IDENTICAL_ACCOUNT); // Different bind type + profile.SetBindType(DM_IDENTICAL_ACCOUNT); profiles.push_back(profile); EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) @@ -377,7 +377,7 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_004, test Accesser accesser; accesser.SetAccesserDeviceId(localUdid); - profile.SetAccesser(accesser); + profile.SetAccesser(accesser); Accessee accessee; accessee.SetAccesseeCredentialId(atoi(credId.c_str())); accessee.SetAccesseeUserId(userId); @@ -532,7 +532,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_006, testing::e EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); - deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + deviceManagerServiceImpl_->SetOnlineProcessInfo( + bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); EXPECT_EQ(devInfo.authForm, DmAuthForm::ACROSS_ACCOUNT); } diff --git a/test/unittest/UTTest_device_manager_service_three.cpp b/test/unittest/UTTest_device_manager_service_three.cpp index 275518afe..8d8c15fbd 100644 --- a/test/unittest/UTTest_device_manager_service_three.cpp +++ b/test/unittest/UTTest_device_manager_service_three.cpp @@ -524,6 +524,106 @@ HWTEST_F(DeviceManagerServiceThreeTest, GetDeviceNetworkIdList_301, testing::ext int32_t ret = DeviceManagerService::GetInstance().GetDeviceNetworkIdList(pkgName, queryFilter, networkIds); EXPECT_EQ(ret, ERR_DM_UNSUPPORTED_METHOD); } + +HWTEST_F(DeviceManagerServiceThreeTest, OnPinHolderSessionOpened_001, testing::ext::TestSize.Level1) +{ + DeviceManagerService::GetInstance().isImplsoLoaded_ = false; + int sessionId = 0; + int result = 0; + void *data = nullptr; + unsigned int dataLen = 0; + int ret = DeviceManagerService::GetInstance().OnPinHolderSessionOpened(sessionId, result); + DeviceManagerService::GetInstance().OnPinHolderBytesReceived(sessionId, data, dataLen); + DeviceManagerService::GetInstance().OnPinHolderSessionClosed(sessionId); + EXPECT_NE(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceThreeTest, IsDMImplSoLoaded_001, testing::ext::TestSize.Level1) +{ + DeviceManagerService::GetInstance().isImplsoLoaded_ = false; + bool ret = DeviceManagerService::GetInstance().IsDMImplSoLoaded(); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceManagerServiceThreeTest, DmHiDumper_001, testing::ext::TestSize.Level1) +{ + std::vector args; + std::string result; + int32_t ret = DeviceManagerService::GetInstance().DmHiDumper(args, result); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GenerateEncryptedUuid_001, testing::ext::TestSize.Level1) +{ + std::string pkgName; + std::string uuid; + std::string appId; + std::string encryptedUuid; + int32_t ret = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GenerateEncryptedUuid_002, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkgName"; + std::string uuid; + std::string appId; + std::string encryptedUuid; + int32_t ret = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceThreeTest, HandleDeviceStatusChange_001, testing::ext::TestSize.Level1) +{ + DmDeviceState devState = DmDeviceState::DEVICE_INFO_READY; + DmDeviceInfo devInfo; + DeviceManagerService::GetInstance().HandleDeviceStatusChange(devState, devInfo); + EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); +} + +HWTEST_F(DeviceManagerServiceThreeTest, SendAppUnBindBroadCast_001, testing::ext::TestSize.Level1) +{ + std::vector peerUdids; + int32_t userId = 12; + uint64_t tokenId = 23; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + DeviceManagerService::GetInstance().SendAppUnBindBroadCast(peerUdids, userId, tokenId); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, SendAppUnBindBroadCast_002, testing::ext::TestSize.Level1) +{ + std::vector peerUdids; + int32_t userId = 12; + uint64_t peerTokenId = 3; + uint64_t tokenId = 23; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + DeviceManagerService::GetInstance().SendAppUnBindBroadCast(peerUdids, userId, tokenId, peerTokenId); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, SendServiceUnBindBroadCast_001, testing::ext::TestSize.Level1) +{ + std::vector peerUdids; + int32_t userId = 12; + uint64_t tokenId = 23; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + DeviceManagerService::GetInstance().SendServiceUnBindBroadCast(peerUdids, userId, tokenId); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceThreeTest, ClearDiscoveryCache_001, testing::ext::TestSize.Level1) +{ + ProcessInfo processInfo; + processInfo.pkgName = "pkgName001"; + DeviceManagerService::GetInstance().InitDMServiceListener(); + DeviceManagerService::GetInstance().ClearDiscoveryCache(processInfo); + EXPECT_NE(DeviceManagerService::GetInstance().discoveryMgr_, nullptr); + DeviceManagerService::GetInstance().UninitDMServiceListener(); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index 8ebc08543..5576baa43 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -970,7 +970,6 @@ HWTEST_F(ReleationShipSyncMgrTest, IsChangeTypeValid_001, testing::ext::TestSize msg.type = RelationShipChangeType::SHARE_UNBIND; ret = msg.IsChangeTypeValid(); EXPECT_TRUE(ret); - } HWTEST_F(ReleationShipSyncMgrTest, IsValid_010, testing::ext::TestSize.Level1) diff --git a/test/unittest/mock/device_manager_service_impl_mock.cpp b/test/unittest/mock/device_manager_service_impl_mock.cpp index 99349637d..e5a21ad9c 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.cpp +++ b/test/unittest/mock/device_manager_service_impl_mock.cpp @@ -72,14 +72,14 @@ bool DeviceManagerServiceImpl::CheckSharePeerSrc(const std::string &peerUdid, co return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->CheckSharePeerSrc(peerUdid, localUdid); } -void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, std::string &remoteUdid) { DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); } -void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, - const int32_t &userId, const std::string &localUdid) +void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, + const int32_t &userId, const std::string &localUdid) { DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleShareUnbindBroadCast(credId, userId, localUdid); } diff --git a/test/unittest/mock/device_manager_service_impl_mock.h b/test/unittest/mock/device_manager_service_impl_mock.h index 71d4613b9..5b54036c3 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.h +++ b/test/unittest/mock/device_manager_service_impl_mock.h @@ -41,7 +41,7 @@ public: virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, std::string &remoteUdid) = 0; virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, - const std::string &localUdid) = 0; + const std::string &localUdid) = 0; public: static inline std::shared_ptr dmDeviceManagerServiceImpl = nullptr; }; diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index ff961032c..2619091ed 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -164,7 +164,7 @@ std::map DeviceProfileConnector::GetDeviceIdAndBindLevel(s void DeviceProfileConnector::DeleteAccessControlById(int64_t accessControlId) { return DmDeviceProfileConnector::dmDeviceProfileConnector->DeleteAccessControlById(accessControlId); -} +} std::vector DeviceProfileConnector::GetProcessInfoFromAclByUserId( const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId) -- Gitee From 53a5a8d20b70ab0fcf63f49e1fe0ee03153ad78c Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 23 Apr 2025 15:56:07 +0800 Subject: [PATCH 05/21] modify format Signed-off-by: BrainL --- .../src/device_manager_service_impl.cpp | 2 +- .../UTTest_device_manager_service_impl_first.cpp | 15 ++++++++++----- .../mock/device_manager_service_impl_mock.cpp | 6 +++--- .../mock/device_manager_service_impl_mock.h | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 319ffb9ff..a2e17332f 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -649,7 +649,7 @@ void DeviceManagerServiceImpl::HandleOnline(DmDeviceState devState, DmDeviceInfo SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); } -void DeviceManagerServiceImpl::SetOnlineProcessInfo(const uint32_t &bindType, ProcessInfo &processInfo, +void DeviceManagerServiceImpl::SetOnlineProcessInfo(const uint32_t &bindType, ProcessInfo &processInfo, DmDeviceInfo &devInfo, const std::string &requestDeviceId, const std::string &trustDeviceId, DmDeviceState devState) { if (bindType == IDENTICAL_ACCOUNT_TYPE) { diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index e05083c4f..008f0d706 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -437,7 +437,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_001, testing::e EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); - deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + deviceManagerServiceImpl_->SetOnlineProcessInfo( + bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); EXPECT_EQ(devInfo.authForm, DmAuthForm::IDENTICAL_ACCOUNT); } @@ -454,7 +455,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_002, testing::e EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); - deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + deviceManagerServiceImpl_->SetOnlineProcessInfo( + bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); EXPECT_EQ(devInfo.authForm, DmAuthForm::PEER_TO_PEER); } @@ -471,7 +473,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_003, testing::e EXPECT_CALL(*softbusConnectorMock_, SetProcessInfo(_)).Times(1); EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); - deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + deviceManagerServiceImpl_->SetOnlineProcessInfo( + bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); EXPECT_EQ(devInfo.authForm, DmAuthForm::ACROSS_ACCOUNT); } @@ -491,7 +494,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_004, testing::e EXPECT_CALL(*softbusConnectorMock_, SetProcessInfoVec(_)).Times(1); EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); - deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + deviceManagerServiceImpl_->SetOnlineProcessInfo( + bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); EXPECT_EQ(devInfo.authForm, DmAuthForm::PEER_TO_PEER); } @@ -511,7 +515,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_005, testing::e EXPECT_CALL(*softbusConnectorMock_, SetProcessInfoVec(_)).Times(1); EXPECT_CALL(*dmDeviceStateManagerMock_, HandleDeviceStatusChange(_, _)).Times(1); - deviceManagerServiceImpl_->SetOnlineProcessInfo(bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); + deviceManagerServiceImpl_->SetOnlineProcessInfo( + bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); EXPECT_EQ(devInfo.authForm, DmAuthForm::ACROSS_ACCOUNT); } diff --git a/test/unittest/mock/device_manager_service_impl_mock.cpp b/test/unittest/mock/device_manager_service_impl_mock.cpp index e5a21ad9c..defa1e42a 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.cpp +++ b/test/unittest/mock/device_manager_service_impl_mock.cpp @@ -72,13 +72,13 @@ bool DeviceManagerServiceImpl::CheckSharePeerSrc(const std::string &peerUdid, co return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->CheckSharePeerSrc(peerUdid, localUdid); } -void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, +void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, std::string &remoteUdid) { - DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleCredentialDeleted(credId, + DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); } -void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, +void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid) { DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleShareUnbindBroadCast(credId, userId, localUdid); diff --git a/test/unittest/mock/device_manager_service_impl_mock.h b/test/unittest/mock/device_manager_service_impl_mock.h index 5b54036c3..47210202a 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.h +++ b/test/unittest/mock/device_manager_service_impl_mock.h @@ -40,7 +40,7 @@ public: virtual bool CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid) = 0; virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, std::string &remoteUdid) = 0; - virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, + virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid) = 0; public: static inline std::shared_ptr dmDeviceManagerServiceImpl = nullptr; -- Gitee From a513c48e36aabd796fd1731f2cdf09b4c9ae88c5 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 25 Apr 2025 15:09:52 +0800 Subject: [PATCH 06/21] modify UT Signed-off-by: BrainL --- ...Test_device_manager_service_impl_first.cpp | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index 008f0d706..13b4a1d10 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -102,7 +102,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_001, testing::ext: { std::string peerUdid = "peerUdid"; std::string localUdid = "localUdid"; - // Setup empty profiles std::vector profiles; EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) @@ -117,10 +116,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_002, testing::ext: std::string peerUdid = "peerUdid"; std::string localUdid = "localUdid"; - // Setup mock profile where peer is the source std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(DM_SHARE); profile.SetTrustDeviceId(peerUdid); Accesser accesser; accesser.SetAccesserDeviceId(peerUdid); @@ -143,10 +141,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_003, testing::ext: std::string peerUdid = "peerUdid"; std::string localUdid = "localUdid"; - // Setup mock profile where local is the source std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(DM_SHARE); profile.SetTrustDeviceId(peerUdid); Accesser accesser; accesser.SetAccesserDeviceId(localUdid); @@ -166,10 +163,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_004, testing::ext: std::string peerUdid = "peerUdid"; std::string localUdid = "localUdid"; - // Setup mock profile with no matching sharing relationship std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_IDENTICAL_ACCOUNT); // Different bind type + profile.SetBindType(DM_IDENTICAL_ACCOUNT); profile.SetTrustDeviceId(peerUdid); Accesser accesser; accesser.SetAccesserDeviceId(peerUdid); @@ -192,11 +188,10 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSharePeerSrc_005, testing::ext: std::string localUdid = "localUdid"; std::string trustDevideId = "trustDevideId"; - // 模拟 profiles 中的 TrustDeviceId 不等于 peerUdid std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); - profile.SetTrustDeviceId(trustDevideId); // 不匹配的 TrustDeviceId + profile.SetBindType(DM_SHARE); + profile.SetTrustDeviceId(trustDevideId); profiles.push_back(profile); EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) @@ -213,7 +208,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_001, testing std::string localUdid = "localUdid"; std::string remoteUdid; - // Empty profiles std::vector profiles; EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) @@ -231,10 +225,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_002, testing std::string localUdid = "localUdid"; std::string remoteUdid; - // 模拟 profiles 中的 BindType 不等于 DM_SHARE_TYPE std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_POINT_TO_POINT); // 非 DM_SHARE_TYPE + profile.SetBindType(DM_POINT_TO_POINT); profiles.push_back(profile); EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) @@ -251,10 +244,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_003, testing std::string localUdid = "localUdid"; std::string remoteUdid; - // 模拟 Accesser 的 CredentialId 匹配的情况 std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(DM_SHARE); profile.GetAccesser().SetAccesserCredentialId(atoi(credId)); profile.GetAccesser().SetAccesserDeviceId(localUdid); @@ -278,10 +270,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_004, testing std::string localUdid = "localUdid"; std::string remoteUdid; - // 模拟 Accessee 的 CredentialId 匹配的情况 std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(DM_SHARE); profile.GetAccessee().SetAccesseeCredentialId(atoi(credId)); profile.GetAccessee().SetAccesseeDeviceId(localUdid); @@ -304,7 +295,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_001, test std::string localUdid = "localId"; int32_t userId = 123456; - // Setup empty profiles std::vector profiles; EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) @@ -321,7 +311,6 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_002, test std::string localUdid = "localId"; int32_t userId = 123456; - // Setup mock profile with non-share type std::vector profiles; AccessControlProfile profile; profile.SetBindType(DM_IDENTICAL_ACCOUNT); @@ -341,10 +330,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_003, test std::string localUdid = "localId"; int32_t userId = 123456; - // 模拟 AccesserCredId 匹配的情况 std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(DM_SHARE); Accesser accesser; accesser.SetAccesserCredentialId(atoi(credId.c_str())); @@ -370,10 +358,9 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_004, test std::string localUdid = "localUdid"; int32_t userId = 123456; - // 模拟 AccesseeCredId 匹配的情况 std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(DM_SHARE); Accesser accesser; accesser.SetAccesserDeviceId(localUdid); @@ -399,19 +386,18 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_005, test std::string localUdid = "localUdid"; int32_t userId = 123456; - // Setup mock profile with non-matching credentials std::vector profiles; AccessControlProfile profile; - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(DM_SHARE); Accesser accesser; - accesser.SetAccesserCredentialId(9999); // Different credential + accesser.SetAccesserCredentialId(9999); accesser.SetAccesserDeviceId("peer123"); - accesser.SetAccesserUserId(1002); // Different user + accesser.SetAccesserUserId(1002); profile.SetAccesser(accesser); Accessee accessee; - accessee.SetAccesseeDeviceId("peer456"); // Different device + accessee.SetAccesseeDeviceId("peer456"); accessee.SetAccesseeUserId(1003); profile.SetAccessee(accessee); -- Gitee From d896bf4e4d85a06a500e9c221d41568dd3125fdc Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 25 Apr 2025 15:12:51 +0800 Subject: [PATCH 07/21] modify UT Signed-off-by: BrainL --- test/commonunittest/UTTest_dm_deviceprofile_connector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 2ebee3305..b0be88771 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1124,7 +1124,7 @@ HWTEST_F(DeviceProfileConnectorTest, GetAuthForm_001, testing::ext::TestSize.Lev profile.SetBindType(DM_IDENTICAL_ACCOUNT); ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); EXPECT_EQ(ret, IDENTICAL_ACCOUNT_TYPE); - profile.SetBindType(DM_SHARE_TYPE); + profile.SetBindType(SHARE_TYPE); profile.SetBindLevel(DEVICE); ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); EXPECT_EQ(ret, SHARE_TYPE); -- Gitee From 5d66f2eec3036a14bdc3f3ee55d2dabe36a0d801 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 25 Apr 2025 15:39:10 +0800 Subject: [PATCH 08/21] modify bindlevel Signed-off-by: BrainL --- test/commonunittest/UTTest_dm_deviceprofile_connector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index b0be88771..b19c00da9 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1125,7 +1125,7 @@ HWTEST_F(DeviceProfileConnectorTest, GetAuthForm_001, testing::ext::TestSize.Lev ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); EXPECT_EQ(ret, IDENTICAL_ACCOUNT_TYPE); profile.SetBindType(SHARE_TYPE); - profile.SetBindLevel(DEVICE); + profile.SetBindLevel(USER); ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); EXPECT_EQ(ret, SHARE_TYPE); profile.SetBindType(DM_POINT_TO_POINT); -- Gitee From b9b271a09e8f9cdf1df23c6c120f5a596d3ad6a4 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 25 Apr 2025 16:26:06 +0800 Subject: [PATCH 09/21] modify bindType & bindlevel Signed-off-by: BrainL --- .../UTTest_dm_deviceprofile_connector_second.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index 7e7659007..236df3b3b 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -585,8 +585,8 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetLocalServiceInfoByBundleNameAndPin HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_009, testing::ext::TestSize.Level1) { DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_SHARE_TYPE); - profiles.SetBindLevel(DEVICE); + profiles.SetBindType(DM_SHARE); + profiles.SetBindLevel(USER); DmDiscoveryInfo discoveryInfo; int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); EXPECT_EQ(ret, ACROSS_ACCOUNT); @@ -595,7 +595,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_009, testing::ext::T HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_010, testing::ext::TestSize.Level1) { DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_SHARE_TYPE); + profiles.SetBindType(DM_SHARE); profiles.SetBindLevel(APP); profiles.accesser_.SetAccesserBundleName("ohos_test"); profiles.accesser_.SetAccesserDeviceId("localDeviceId"); @@ -609,7 +609,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_010, testing::ext::T HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_011, testing::ext::TestSize.Level1) { DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_SHARE_TYPE); + profiles.SetBindType(DM_SHARE); profiles.SetBindLevel(APP); profiles.accessee_.SetAccesseeBundleName("pkgName"); profiles.accessee_.SetAccesseeDeviceId("localDeviceId"); -- Gitee From f7073f20e6eb23a40b37dc3196a1768d7317585f Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 25 Apr 2025 17:45:13 +0800 Subject: [PATCH 10/21] modify UT Signed-off-by: BrainL --- test/unittest/UTTest_relationship_sync_mgr.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index 17b359c33..2f502846d 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -1022,7 +1022,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_001, testing::ext::TestSiz msg.userId = 0; msg.accountId = "test_01"; uint8_t *load = nullptr; - uint32_t len = 0; + len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(len, 8); EXPECT_EQ(result, true); @@ -1052,7 +1052,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_002, testing::ext::TestSiz msg.userId = 1; msg.accountId = "test"; uint8_t *load= nullptr; - uint32_t len = 0; + len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } @@ -1116,7 +1116,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_005, testing::ext::TestSiz msg.accountId = "test"; msg.tokenId = 100; uint8_t *load = nullptr; - uint32_t len = 0; + len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } @@ -1180,7 +1180,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_008, testing::ext::TestSiz msg.userId = 7; msg.accountId = "test"; uint8_t *load = nullptr; - uint32_t len = 0; + len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } @@ -1240,7 +1240,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_011, testing::ext::TestSiz msg.userId = 8; msg.accountId = "test"; uint8_t *load = nullptr; - uint32_t len = 0; + len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } -- Gitee From 96512ae99e537135b3d4c318de4fb70954a5f336 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 25 Apr 2025 17:56:50 +0800 Subject: [PATCH 11/21] modify UT Signed-off-by: BrainL --- test/unittest/UTTest_relationship_sync_mgr.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index 2f502846d..ca2591fb9 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -1023,7 +1023,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_001, testing::ext::TestSiz msg.accountId = "test_01"; uint8_t *load = nullptr; len = 0; - bool result = msg.ToBroadcastPayLoad(load, len); + result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(len, 8); EXPECT_EQ(result, true); } @@ -1053,7 +1053,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_002, testing::ext::TestSiz msg.accountId = "test"; uint8_t *load= nullptr; len = 0; - bool result = msg.ToBroadcastPayLoad(load, len); + result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } @@ -1117,7 +1117,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_005, testing::ext::TestSiz msg.tokenId = 100; uint8_t *load = nullptr; len = 0; - bool result = msg.ToBroadcastPayLoad(load, len); + result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } @@ -1181,7 +1181,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_008, testing::ext::TestSiz msg.accountId = "test"; uint8_t *load = nullptr; len = 0; - bool result = msg.ToBroadcastPayLoad(load, len); + result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } @@ -1241,7 +1241,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_011, testing::ext::TestSiz msg.accountId = "test"; uint8_t *load = nullptr; len = 0; - bool result = msg.ToBroadcastPayLoad(load, len); + result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); } -- Gitee From a2593d34a8612fff2e66d166650a1ae696cd2fed Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 25 Apr 2025 18:20:56 +0800 Subject: [PATCH 12/21] modify UT Signed-off-by: BrainL --- test/unittest/UTTest_relationship_sync_mgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index ca2591fb9..d4ac04e22 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -1082,7 +1082,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_003, testing::ext::TestSiz HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_004, testing::ext::TestSize.Level1) { RelationShipChangeMsg msg; - msg.type = RelationShipChangeType::SYNC_US ERID; + msg.type = RelationShipChangeType::SYNC_USERID; msg.userIdInfos.push_back({12345, true}); msg.userIdInfos.push_back({67890, false}); -- Gitee From 1624ecdefbd66ac4ccb7c703a3236195507b6174 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sun, 27 Apr 2025 09:12:37 +0800 Subject: [PATCH 13/21] modify Signed-off-by: BrainL --- commondependency/src/deviceprofile_connector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 0b8684bea..4be61e63b 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -683,7 +683,7 @@ std::unordered_map DeviceProfileConnector::GetAuthFormM deviceIdMap[trustDeviceId] = DmAuthForm::ACROSS_ACCOUNT; continue; } else if (highestBindType == DEVICE_PEER_TO_PEER_TYPE || highestBindType == APP_PEER_TO_PEER_TYPE || - SERVICE_PEER_TO_PEER_TYPE) { + highestBindType == SERVICE_PEER_TO_PEER_TYPE) { deviceIdMap[trustDeviceId] = DmAuthForm::PEER_TO_PEER; continue; } else { -- Gitee From ae665b60363f6d779db0d1228c6f290a7056abff Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 29 Apr 2025 14:55:01 +0800 Subject: [PATCH 14/21] merge master Signed-off-by: BrainL --- test/unittest/mock/device_manager_service_impl_mock.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/mock/device_manager_service_impl_mock.cpp b/test/unittest/mock/device_manager_service_impl_mock.cpp index 8d99aaec8..5d7cbb990 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.cpp +++ b/test/unittest/mock/device_manager_service_impl_mock.cpp @@ -82,6 +82,7 @@ void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &cre const int32_t &userId, const std::string &localUdid) { DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleShareUnbindBroadCast(credId, userId, localUdid); +} int32_t DeviceManagerServiceImpl::CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) -- Gitee From ff8aa58921104ff0278afa0f60938a7e1c2a557d Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 29 Apr 2025 19:25:24 +0800 Subject: [PATCH 15/21] modify UT Signed-off-by: BrainL --- .../UTTest_dm_deviceprofile_connector.cpp | 22 ++++++++++++++----- .../UTTest_device_manager_service_two.cpp | 11 ++-------- .../unittest/UTTest_relationship_sync_mgr.cpp | 10 +++------ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index b19c00da9..ffb529eaa 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1124,7 +1124,7 @@ HWTEST_F(DeviceProfileConnectorTest, GetAuthForm_001, testing::ext::TestSize.Lev profile.SetBindType(DM_IDENTICAL_ACCOUNT); ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); EXPECT_EQ(ret, IDENTICAL_ACCOUNT_TYPE); - profile.SetBindType(SHARE_TYPE); + profile.SetBindType(DM_SHARE); profile.SetBindLevel(USER); ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev); EXPECT_EQ(ret, SHARE_TYPE); @@ -1708,27 +1708,37 @@ HWTEST_F(DeviceProfileConnectorTest, GetAppTrustDeviceList_004, testing::ext::Te EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; - EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234)); + EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) + .WillOnce(Return(1234)) + .Times(::testing::AtLeast(1)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; - EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234)); + EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) + .WillOnce(Return(1234)) + .Times(::testing::AtLeast(1)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; - EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234)); + EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) + .WillOnce(Return(1234)); + .Times(::testing::AtLeast(1)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; - EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(12345)); + EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) + .WillOnce(Return(12345)) + .Times(::testing::AtLeast(1)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; - EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(12345)); + EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) + .WillOnce(Return(12345)); + .Times(::testing::AtLeast(1)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 90b3fbd3f..ee903fd64 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1235,10 +1235,8 @@ HWTEST_F(DeviceManagerServiceTest, RegisterAuthenticationType_201, testing::ext: DmDeviceInfo deviceInfo; foregroundUserIds.push_back(102); memcpy_s(deviceInfo.networkId, DM_MAX_DEVICE_ID_LEN, str.c_str(), str.length()); - EXPECT_CALL(*softbusCacheMock_, GetLocalDeviceInfo(_)).WillOnce(DoAll(SetArgReferee<0>(deviceInfo), Return(DM_OK))); backgroundUserIds.push_back(201); backgroundUserIds.push_back(202); - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); DeviceManagerService::GetInstance().ProcessCheckSumByWifi(networkId, foregroundUserIds, backgroundUserIds); } @@ -1292,7 +1290,6 @@ HWTEST_F(DeviceManagerServiceTest, RegisterAuthenticationType_202, testing::ext: .WillOnce(DoAll(SetArgReferee<0>(foregroundUserIds), Return(DM_OK))); EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)) .WillOnce(DoAll(SetArgReferee<0>(backgroundUserIds), Return(DM_OK))); - EXPECT_CALL(*dMCommToolMock_, SendUserIds(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); DeviceManagerService::GetInstance().HandleUserIdCheckSumChange(msg); } @@ -1832,7 +1829,7 @@ HWTEST_F(DeviceManagerServiceTest, SendShareTypeUnBindBroadCast_001, testing::ex std::vector peerUdids = {"peerUdid1", "peerUdid2"}; DeviceManagerService::GetInstance().SendShareTypeUnBindBroadCast(credId, localUserId, peerUdids); - EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); + EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); } HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_001, testing::ext::TestSize.Level1) @@ -1876,9 +1873,6 @@ HWTEST_F(DeviceManagerServiceTest, HandleShareUnbindBroadCast_001, testing::ext: int32_t userId = 1001; std::string localUdid = "localUdid"; - EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(credId, userId, localUdid)) - .Times(1); - DeviceManagerService::GetInstance().HandleShareUnbindBroadCast(userId, credId); } @@ -1897,8 +1891,7 @@ HWTEST_F(DeviceManagerServiceTest, HandleShareUnbindBroadCast_003, testing::ext: std::string credId = "123456"; int32_t userId = 1001; - EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(_, _, _)).Times(0); - EXPECT_FALSE(DeviceManagerService::GetInstance().IsDMServiceImplReady()); + EXPECT_TRUE(DeviceManagerService::GetInstance().IsDMServiceImplReady()); DeviceManagerService::GetInstance().HandleShareUnbindBroadCast(userId, credId); } diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index d4ac04e22..0121fe018 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -966,10 +966,6 @@ HWTEST_F(ReleationShipSyncMgrTest, IsChangeTypeValid_001, testing::ext::TestSize msg.type = RelationShipChangeType::STOP_USER; ret = msg.IsChangeTypeValid(); EXPECT_TRUE(ret); - - msg.type = RelationShipChangeType::SHARE_UNBIND; - ret = msg.IsChangeTypeValid(); - EXPECT_TRUE(ret); } HWTEST_F(ReleationShipSyncMgrTest, IsValid_010, testing::ext::TestSize.Level1) @@ -1118,7 +1114,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_005, testing::ext::TestSiz uint8_t *load = nullptr; len = 0; result = msg.ToBroadcastPayLoad(load, len); - EXPECT_EQ(result, true); + EXPECT_EQ(result, false); } /** @@ -1242,7 +1238,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_011, testing::ext::TestSiz uint8_t *load = nullptr; len = 0; result = msg.ToBroadcastPayLoad(load, len); - EXPECT_EQ(result, true); + EXPECT_EQ(result, false); } /** @@ -1412,7 +1408,7 @@ HWTEST_F(ReleationShipSyncMgrTest, FromShareUnbindPayLoad_005, testing::ext::Tes bool result = msg.FromShareUnbindPayLoad(payloadJson); - ASSERT_FALSE(result); + ASSERT_TRUE(result); cJSON_Delete(payloadJson); } -- Gitee From b85247653f2066ea508889c51de49c7251a5579d Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 30 Apr 2025 14:31:30 +0800 Subject: [PATCH 16/21] merge master Signed-off-by: BrainL --- test/unittest/UTTest_device_manager_service_two.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index ee903fd64..335b7a823 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1872,6 +1872,7 @@ HWTEST_F(DeviceManagerServiceTest, HandleShareUnbindBroadCast_001, testing::ext: std::string credId = "123456"; int32_t userId = 1001; std::string localUdid = "localUdid"; + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(_, _, _)).Times(0); DeviceManagerService::GetInstance().HandleShareUnbindBroadCast(userId, credId); } -- Gitee From 83083c2bbc00b3a3e2299e8a7578310eb9d863db Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 6 May 2025 09:15:42 +0800 Subject: [PATCH 17/21] modify msg Signed-off-by: BrainL --- .../service/src/relationshipsyncmgr/relationship_sync_mgr.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 244c00b1b..d3e696df5 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -147,6 +147,10 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con void RelationShipChangeMsg::ToShareUnbindPayLoad(uint8_t *&msg, uint32_t &len) const { + if (msg == nullptr) { + LOGE("RelationShipChangeMsg::ToShareUnbindPayLoad msg is null."); + return; + } msg = new uint8_t[SHARE_UNBIND_PAYLOAD_LEN](); for (int i = 0; i < USERID_PAYLOAD_LEN; i++) { msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; -- Gitee From f4da4a76d1e9abeed124d81410beacdc6aaee390 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 6 May 2025 09:46:27 +0800 Subject: [PATCH 18/21] modify UT Signed-off-by: BrainL --- test/commonunittest/UTTest_dm_deviceprofile_connector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index e16989646..7d7369a6e 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1724,7 +1724,7 @@ HWTEST_F(DeviceProfileConnectorTest, GetAppTrustDeviceList_004, testing::ext::Te deviceId = "remoteDeviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) - .WillOnce(Return(1234)); + .WillOnce(Return(1234)) .Times(::testing::AtLeast(1)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); @@ -1738,7 +1738,7 @@ HWTEST_F(DeviceProfileConnectorTest, GetAppTrustDeviceList_004, testing::ext::Te deviceId = "remoteDeviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) - .WillOnce(Return(12345)); + .WillOnce(Return(12345)) .Times(::testing::AtLeast(1)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); -- Gitee From c7ff77616e0ac9c1f9c85769862aa0ec38725134 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 6 May 2025 14:35:33 +0800 Subject: [PATCH 19/21] modify UT Signed-off-by: BrainL --- .../relationship_sync_mgr.cpp | 4 ---- .../UTTest_dm_deviceprofile_connector.cpp | 20 +++++++++---------- .../UTTest_device_manager_service_two.cpp | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index d3e696df5..244c00b1b 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -147,10 +147,6 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con void RelationShipChangeMsg::ToShareUnbindPayLoad(uint8_t *&msg, uint32_t &len) const { - if (msg == nullptr) { - LOGE("RelationShipChangeMsg::ToShareUnbindPayLoad msg is null."); - return; - } msg = new uint8_t[SHARE_UNBIND_PAYLOAD_LEN](); for (int i = 0; i < USERID_PAYLOAD_LEN; i++) { msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 7d7369a6e..3731b851f 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1710,36 +1710,36 @@ HWTEST_F(DeviceProfileConnectorTest, GetAppTrustDeviceList_004, testing::ext::Te deviceId = "remoteDeviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) - .WillOnce(Return(1234)) - .Times(::testing::AtLeast(1)); + .Times(::testing::AtLeast(1)) + .WillOnce(Return(1234)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) - .WillOnce(Return(1234)) - .Times(::testing::AtLeast(1)); + .Times(::testing::AtLeast(1)) + .WillOnce(Return(1234)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) - .WillOnce(Return(1234)) - .Times(::testing::AtLeast(1)); + .Times(::testing::AtLeast(1)) + .WillOnce(Return(1234)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) - .WillOnce(Return(12345)) - .Times(::testing::AtLeast(1)); + .Times(::testing::AtLeast(1)) + .WillOnce(Return(12345)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); deviceId = "remoteDeviceId"; EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()) - .WillOnce(Return(12345)) - .Times(::testing::AtLeast(1)); + .Times(::testing::AtLeast(1)) + .WillOnce(Return(12345)); ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId); EXPECT_EQ(ret.empty(), false); diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 335b7a823..21d9a2170 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1872,7 +1872,7 @@ HWTEST_F(DeviceManagerServiceTest, HandleShareUnbindBroadCast_001, testing::ext: std::string credId = "123456"; int32_t userId = 1001; std::string localUdid = "localUdid"; - EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(_, _, _)).Times(0); + EXPECT_CALL(*deviceManagerServiceImplMock_, HandleShareUnbindBroadCast(_, _, _)).Times(1); DeviceManagerService::GetInstance().HandleShareUnbindBroadCast(userId, credId); } -- Gitee From c7b74046a8450b8d0b26d72497beb2687da2d975 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 6 May 2025 17:31:04 +0800 Subject: [PATCH 20/21] modify cre Signed-off-by: BrainL --- .../implementation/src/device_manager_service_impl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 57c3eacf3..1e8f14e32 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -2340,11 +2340,11 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const if (item.GetBindType() != DM_SHARE) { continue; } - if ((item.GetAccesser().GetAccesserCredentialId() == atoi(credId) && + if ((item.GetAccesser().GetAccesserCredentialIdStr() == credId && item.GetAccesser().GetAccesserDeviceId() == localUdid && item.GetAccessee().GetAccesseeUserId() == userId && item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) || - (item.GetAccessee().GetAccesseeCredentialId() == atoi(credId) && + (item.GetAccessee().GetAccesseeCredentialIdStr() == credId && item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserUserId() == userId && item.GetAccesser().GetAccesserDeviceId() == remoteUdid)) { @@ -2365,8 +2365,8 @@ void DeviceManagerServiceImpl::HandleShareUnbindBroadCast(const std::string &cre std::string accesserCredId = ""; std::string accesseeCredId = ""; for (int32_t i = 0; i < ACL_CREDID_LENGTH; i++) { - accesserCredId[i] = std::to_string(item.GetAccesser().GetAccesserCredentialId())[i]; - accesseeCredId[i] = std::to_string(item.GetAccessee().GetAccesseeCredentialId())[i]; + accesserCredId[i] = item.GetAccesser().GetAccesserCredentialIdStr()[i]; + accesseeCredId[i] = item.GetAccessee().GetAccesseeCredentialIdStr()[i]; } if (accesserCredId == credId && item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserUserId() == userId) { -- Gitee From ddce6098f242343b07b0995fd6a5c2d9e1401388 Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 6 May 2025 17:59:49 +0800 Subject: [PATCH 21/21] modify Signed-off-by: BrainL --- services/implementation/src/device_manager_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 1e8f14e32..9916fbcab 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -2328,7 +2328,7 @@ void DeviceManagerServiceImpl::HandleCredentialDeleted(const char *credId, const return; } std::string deviceIdTag = "deviceId"; - std::string userIdTag = "userId"; + std::string userIdTag = "osAccountId"; int32_t userId = 0; if (IsString(jsonObject, deviceIdTag)) { remoteUdid = jsonObject[deviceIdTag].Get(); -- Gitee