diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index 3badcf2992de30ab7a6b0953da5f31fdb3e8f0a8..ef77c524b8cd48245d3d1fca80b0d22c9dc3a11f 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -44,6 +44,7 @@ void DeviceManagerServiceImplFirstTest::SetUpTestCase() DmDmDeviceStateManager::dmDeviceStateManager = dmDeviceStateManagerMock_; DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl = deviceManagerServiceImplMock_; DmHiChainConnector::dmHiChainConnector = hiChainConnectorMock_; + DmHiChainAuthConnector::dmHiChainAuthConnector = hiChainAuthConnectorMock_; } void DeviceManagerServiceImplFirstTest::TearDownTestCase() @@ -60,6 +61,8 @@ void DeviceManagerServiceImplFirstTest::TearDownTestCase() deviceManagerServiceImplMock_ = nullptr; DmHiChainConnector::dmHiChainConnector = nullptr; hiChainConnectorMock_ = nullptr; + DmHiChainAuthConnector::dmHiChainAuthConnector = nullptr; + hiChainAuthConnectorMock_ = nullptr; } namespace { @@ -784,6 +787,956 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByTokenId_002, testing::ext EXPECT_TRUE(delACLInfoVec.empty()); EXPECT_TRUE(userIdVec.empty()); } + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByTokenId_003, testing::ext::TestSize.Level1) +{ + int32_t accessTokenId = 1234; + std::vector profiles; + std::map delProfileMap; + std::vector> delACLInfoVec; + std::vector userIdVec; + + deviceManagerServiceImpl_->DeleteAclByTokenId(accessTokenId, profiles, delProfileMap, delACLInfoVec, userIdVec); + + EXPECT_TRUE(profiles.empty()); + EXPECT_TRUE(delProfileMap.empty()); + EXPECT_TRUE(delACLInfoVec.empty()); + EXPECT_TRUE(userIdVec.empty()); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByTokenId_004, testing::ext::TestSize.Level1) +{ + int32_t accessTokenId = 1234; + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(5678); + profile.GetAccessee().SetAccesseeTokenId(8765); + profiles.push_back(profile); + + std::map delProfileMap; + std::vector> delACLInfoVec; + std::vector userIdVec; + + deviceManagerServiceImpl_->DeleteAclByTokenId(accessTokenId, profiles, delProfileMap, delACLInfoVec, userIdVec); + + EXPECT_TRUE(delProfileMap.empty()); + EXPECT_TRUE(delACLInfoVec.empty()); + EXPECT_TRUE(userIdVec.empty()); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByTokenId_005, testing::ext::TestSize.Level1) +{ + int32_t accessTokenId = 1234; + std::vector profiles; + std::map delProfileMap; + std::vector> delACLInfoVec; + std::vector userIdVec; + + deviceManagerServiceImpl_->DeleteAclByTokenId(accessTokenId, profiles, delProfileMap, delACLInfoVec, userIdVec); + + EXPECT_TRUE(profiles.empty()); + EXPECT_TRUE(delProfileMap.empty()); + EXPECT_TRUE(delACLInfoVec.empty()); + EXPECT_TRUE(userIdVec.empty()); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByTokenId_006, testing::ext::TestSize.Level1) +{ + int32_t accessTokenId = 1234; + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserTokenId(5678); + profile.GetAccessee().SetAccesseeTokenId(8765); + profiles.push_back(profile); + + std::map delProfileMap; + std::vector> delACLInfoVec; + std::vector userIdVec; + + deviceManagerServiceImpl_->DeleteAclByTokenId(accessTokenId, profiles, delProfileMap, delACLInfoVec, userIdVec); + + EXPECT_TRUE(delProfileMap.empty()); + EXPECT_TRUE(delACLInfoVec.empty()); + EXPECT_TRUE(userIdVec.empty()); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckLnnAcl_001, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile p1, p2; + p1.GetAccesser().SetAccesserDeviceId("devA"); + p1.GetAccesser().SetAccesserUserId(1); + p1.GetAccessee().SetAccesseeDeviceId("devB"); + p1.GetAccessee().SetAccesseeUserId(2); + + p2.GetAccesser().SetAccesserDeviceId("devA"); + p2.GetAccesser().SetAccesserUserId(1); + p2.GetAccessee().SetAccesseeDeviceId("devB"); + p2.GetAccessee().SetAccesseeUserId(2); + + bool ret = deviceManagerServiceImpl_->CheckLnnAcl(p1, p2); + EXPECT_TRUE(ret); + + DistributedDeviceProfile::AccessControlProfile p3, p4; + p3.GetAccesser().SetAccesserDeviceId("devA"); + p3.GetAccesser().SetAccesserUserId(1); + p3.GetAccessee().SetAccesseeDeviceId("devB"); + p3.GetAccessee().SetAccesseeUserId(2); + + p4.GetAccesser().SetAccesserDeviceId("devB"); + p4.GetAccesser().SetAccesserUserId(2); + p4.GetAccessee().SetAccesseeDeviceId("devA"); + p4.GetAccessee().SetAccesseeUserId(1); + + EXPECT_TRUE(deviceManagerServiceImpl_->CheckLnnAcl(p3, p4)); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SaveOnlineDeviceInfo_001, testing::ext::TestSize.Level1) +{ + deviceManagerServiceImpl_->deviceStateMgr_ = nullptr; + std::vector deviceList; + int32_t ret = deviceManagerServiceImpl_->SaveOnlineDeviceInfo(deviceList); + EXPECT_EQ(ret, ERR_DM_POINT_NULL); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SaveOnlineDeviceInfo_002, testing::ext::TestSize.Level1) +{ + std::vector deviceList; + int32_t ret = deviceManagerServiceImpl_->SaveOnlineDeviceInfo(deviceList); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SaveOnlineDeviceInfo_003, testing::ext::TestSize.Level1) +{ + std::vector deviceList(2); + int32_t ret = deviceManagerServiceImpl_->SaveOnlineDeviceInfo(deviceList); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAlwaysAllowTimeOut_001, testing::ext::TestSize.Level1) +{ + size_t before = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile().size(); + deviceManagerServiceImpl_->DeleteAlwaysAllowTimeOut(); + size_t after = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile().size(); + EXPECT_EQ(before, after); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_005, testing::ext::TestSize.Level1) +{ + const char *credId = "123456"; + const char *credInfo = "invalid_json"; + std::string localUdid = "localUdid"; + std::string remoteUdid; + bool isShareType = false; + std::vector profiles; + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(0); + + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); + EXPECT_FALSE(isShareType); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCredentialDeleted_006, testing::ext::TestSize.Level1) +{ + const char *credId = "123456"; + const char *credInfo = R"({"deviceId": "remoteUdid", "osAccountId": 1})"; + std::string localUdid = "localUdid"; + std::string remoteUdid; + bool isShareType = false; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetBindType(DM_POINT_TO_POINT); + profiles.push_back(profile); + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfile()) + .Times(AtLeast(1)) + .WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(0); + + deviceManagerServiceImpl_->HandleCredentialDeleted(credId, credInfo, localUdid, remoteUdid); + EXPECT_FALSE(isShareType); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleShareUnbindBroadCast_006, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localId"; + int32_t userId = 123456; + + 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_007, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localId"; + int32_t userId = 123456; + + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_IDENTICAL_ACCOUNT); + 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_008, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localId"; + int32_t userId = 123456; + + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE); + + Accesser accesser; + accesser.SetAccesserCredentialId(atoi(credId.c_str())); + accesser.SetAccesserUserId(userId); + profile.SetAccesser(accesser); + + Accessee accessee; + accessee.SetAccesseeDeviceId(localUdid); + accessee.SetAccesseeUserId(MultipleUserConnector::GetCurrentAccountUserID()); + 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_009, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localUdid"; + int32_t userId = 123456; + + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE); + + 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_010, testing::ext::TestSize.Level1) +{ + std::string credId = "12345"; + std::string localUdid = "localUdid"; + int32_t userId = 123456; + + std::vector profiles; + AccessControlProfile profile; + profile.SetBindType(DM_SHARE); + + Accesser accesser; + accesser.SetAccesserCredentialId(9999); + accesser.SetAccesserDeviceId("peer123"); + accesser.SetAccesserUserId(1002); + profile.SetAccesser(accesser); + + Accessee accessee; + accessee.SetAccesseeDeviceId("peer456"); + 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, CheckDeviceInfoPermission_001, testing::ext::TestSize.Level1) +{ + std::string localUdid = "localUdid"; + std::string peerDeviceId = "peerDeviceId"; + + EXPECT_CALL(*deviceProfileConnectorMock_, CheckDeviceInfoPermission(localUdid, peerDeviceId)) + .WillOnce(Return(DM_OK)); + + int32_t ret = deviceManagerServiceImpl_->CheckDeviceInfoPermission(localUdid, peerDeviceId); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckDeviceInfoPermission_002, testing::ext::TestSize.Level1) +{ + std::string localUdid = "localUdid"; + std::string peerDeviceId = "peerDeviceId"; + + EXPECT_CALL(*deviceProfileConnectorMock_, CheckDeviceInfoPermission(localUdid, peerDeviceId)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = deviceManagerServiceImpl_->CheckDeviceInfoPermission(localUdid, peerDeviceId); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAcl_001, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkg"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + int32_t bindLevel = USER; + std::string extra = ""; + DmOfflineParam offlineParam; + offlineParam.bindType = INVALIED_TYPE; + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel, extra)) + .WillOnce(Return(offlineParam)); + + int32_t ret = deviceManagerServiceImpl_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAcl_002, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkg"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + int32_t bindLevel = APP; + std::string extra = ""; + + DmOfflineParam offlineParam; + offlineParam.bindType = APP; + offlineParam.leftAclNumber = 1; + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel, extra)) + .WillOnce(Return(offlineParam)); + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfoVec(_)).Times(1); + EXPECT_CALL(*softbusConnectorMock_, HandleDeviceOffline(remoteUdid)).Times(1); + + int32_t ret = deviceManagerServiceImpl_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAcl_003, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkg"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + int32_t bindLevel = APP; + std::string extra = ""; + + DmOfflineParam offlineParam; + offlineParam.bindType = APP; + offlineParam.leftAclNumber = 0; + offlineParam.peerUserId = 1001; + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel, extra)) + .WillOnce(Return(offlineParam)); + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfoVec(_)).Times(1); + + int32_t ret = deviceManagerServiceImpl_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAcl_004, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkg"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + int32_t bindLevel = USER; + std::string extra = ""; + + DmOfflineParam offlineParam; + offlineParam.bindType = USER; + offlineParam.leftAclNumber = 1; + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel, extra)) + .WillOnce(Return(offlineParam)); + + int32_t ret = deviceManagerServiceImpl_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAcl_005, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkg"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + int32_t bindLevel = USER; + std::string extra = ""; + + DmOfflineParam offlineParam; + offlineParam.bindType = USER; + offlineParam.leftAclNumber = 0; + offlineParam.peerUserId = 1002; + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel, extra)) + .WillOnce(Return(offlineParam)); + int32_t ret = deviceManagerServiceImpl_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAcl_006, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkg"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + int32_t bindLevel = 999; + std::string extra = ""; + + DmOfflineParam offlineParam; + offlineParam.bindType = 999; + offlineParam.leftAclNumber = 0; + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel, extra)) + .WillOnce(Return(offlineParam)); + + int32_t ret = deviceManagerServiceImpl_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteSkCredAndAcl_001, testing::ext::TestSize.Level1) +{ + std::vector acls; + int32_t ret = deviceManagerServiceImpl_->DeleteSkCredAndAcl(acls); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteSkCredAndAcl_002, testing::ext::TestSize.Level1) +{ + std::vector acls = { {"udid", 1, 2, 3, "cred"} }; + deviceManagerServiceImpl_->hiChainAuthConnector_ = nullptr; + int32_t ret = deviceManagerServiceImpl_->DeleteSkCredAndAcl(acls); + EXPECT_EQ(ret, ERR_DM_POINT_NULL); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteSkCredAndAcl_003, testing::ext::TestSize.Level1) +{ + std::vector acls = { {"udid3", 12, 23, 34, "credid3"} }; + + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteSessionKey(12, 34)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*hiChainAuthConnectorMock_, DeleteCredential(12, "credid3")).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(1); + + int32_t ret = deviceManagerServiceImpl_->DeleteSkCredAndAcl(acls); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclForProcV2_004, testing::ext::TestSize.Level1) +{ + DmAclIdParam aclParam = {"udid", 1, 2, 3, "credid"}; + DmOfflineParam offlineParam; + offlineParam.needDelAclInfos.push_back(aclParam); + + EXPECT_CALL(*deviceProfileConnectorMock_, FilterNeedDeleteACL(_, _, _, _)) + .WillOnce(Return(offlineParam)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteSessionKey(1, 3)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*hiChainAuthConnectorMock_, DeleteCredential(1, "credid")).WillOnce(Return(DM_OK)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(1); + + int32_t ret = deviceManagerServiceImpl_->DeleteAclForProcV2("localUdid", 100, "remoteUdid", 1, "extra", 10); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclForProcV2_005, testing::ext::TestSize.Level1) +{ + DmAclIdParam lnnAclParam = {"lnnudid", 2, 3, 4, "lnncred"}; + DmOfflineParam offlineParam; + offlineParam.allLnnAclInfos.push_back(lnnAclParam); + + EXPECT_CALL(*deviceProfileConnectorMock_, FilterNeedDeleteACL(_, _, _, _)) + .WillOnce(Return(offlineParam)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteSessionKey(2, 4)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*hiChainAuthConnectorMock_, DeleteCredential(2, "lnncred")).WillOnce(Return(DM_OK)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(1); + + int32_t ret = deviceManagerServiceImpl_->DeleteAclForProcV2("localUdid", 100, "remoteUdid", 1, "extra", 10); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclForProcV2_006, testing::ext::TestSize.Level1) +{ + DmAclIdParam appAclParam = {"appudid", 3, 4, 5, "appcred"}; + DmOfflineParam offlineParam; + offlineParam.allLeftAppOrSvrAclInfos.push_back(appAclParam); + + EXPECT_CALL(*deviceProfileConnectorMock_, FilterNeedDeleteACL(_, _, _, _)) + .WillOnce(Return(offlineParam)); + EXPECT_CALL(*softbusConnectorMock_, SetProcessInfoVec(_)).Times(1); + EXPECT_CALL(*softbusConnectorMock_, HandleDeviceOffline("remoteUdid")).Times(1); + + int32_t ret = deviceManagerServiceImpl_->DeleteAclForProcV2("localUdid", 100, "remoteUdid", 1, "extra", 10); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclForProcV2_007, testing::ext::TestSize.Level1) +{ + DmOfflineParam offlineParam; + DmOfflineParam outputParam; + outputParam.leftAclNumber = 0; + outputParam.bindType = 1; + EXPECT_CALL(*deviceProfileConnectorMock_, FilterNeedDeleteACL(_, _, _, _)) + .WillOnce(Return(offlineParam)); + int32_t ret = deviceManagerServiceImpl_->DeleteAclForProcV2("localUdid", 100, "remoteUdid", 1, "extra", 10); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclV2_001, testing::ext::TestSize.Level1) +{ + std::string pkgName = "pkg"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + int32_t bindLevel = 3; + std::string extra = "extra"; + DmOfflineParam outputParam; + outputParam.leftAclNumber = 0; + outputParam.bindType = 1; + + EXPECT_CALL(*deviceManagerServiceImplMock_, IsAuthNewVersion(bindLevel, localUdid, remoteUdid, _, _)) + .WillOnce(Return(true)); + EXPECT_CALL(*deviceManagerServiceImplMock_, DeleteAclForProcV2(localUdid, _, remoteUdid, bindLevel, extra, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)) + .WillOnce(Return(outputParam)); + + int32_t ret = deviceManagerServiceImpl_->DeleteAclV2(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCommonEventBroadCast_001, testing::ext::TestSize.Level1) +{ + std::vector foregroundUserIds = {1, 2}; + std::vector backgroundUserIds = {3, 4}; + std::string remoteUdid = "remoteUdid"; + + EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + deviceManagerServiceImpl_->HandleCommonEventBroadCast(foregroundUserIds, backgroundUserIds, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCommonEventBroadCast_002, testing::ext::TestSize.Level1) +{ + std::vector foregroundUserIds = {1, 2}; + std::vector backgroundUserIds = {3, 4}; + std::string remoteUdid = "remoteUdid"; + std::vector localUserIds = {10, 20}; + + EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) + .WillOnce(DoAll(SetArgReferee<0>(localUserIds), Return(DM_OK))); + + DmOfflineParam offlineParam; + EXPECT_CALL(*deviceProfileConnectorMock_, UpdateACL(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgReferee<5>(offlineParam), Return())); + + EXPECT_CALL(*deviceProfileConnectorMock_, HandleSyncBackgroundUserIdEvent(_, _, _, _)).Times(1); + EXPECT_CALL(*deviceProfileConnectorMock_, HandleSyncForegroundUserIdEvent(_, _, _, _)).Times(1); + + deviceManagerServiceImpl_->HandleCommonEventBroadCast(foregroundUserIds, backgroundUserIds, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, HandleCommonEventBroadCast_003, testing::ext::TestSize.Level1) +{ + std::vector foregroundUserIds = {1}; + std::vector backgroundUserIds = {2}; + std::string remoteUdid = "remoteUdid"; + std::vector localUserIds = {100}; + + EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)) + .WillOnce(DoAll(SetArgReferee<0>(localUserIds), Return(DM_OK))); + EXPECT_CALL(*multipleUserConnectorMock_, ClearLockedUser(localUserIds)).Times(1); + + DmOfflineParam offlineParam; + DmAclIdParam aclParam = {"udid", 1, 2, 3, "credid"}; + offlineParam.needDelAclInfos.push_back(aclParam); + EXPECT_CALL(*deviceProfileConnectorMock_, UpdateACL(_, _, _, _, _, _)) + .WillOnce(DoAll(SetArgReferee<5>(offlineParam), Return())); + + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteSessionKey(1, 3)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*hiChainAuthConnectorMock_, DeleteCredential(1, "credid")).WillOnce(Return(DM_OK)); + EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlById(_)).Times(1); + + EXPECT_CALL(*deviceProfileConnectorMock_, HandleSyncBackgroundUserIdEvent(_, _, _, _)).Times(1); + EXPECT_CALL(*deviceProfileConnectorMock_, HandleSyncForegroundUserIdEvent(_, _, _, _)).Times(1); + + deviceManagerServiceImpl_->HandleCommonEventBroadCast(foregroundUserIds, backgroundUserIds, remoteUdid); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetBindCallerInfo_001, testing::ext::TestSize.Level1) +{ + DmBindCallerInfo info; + std::string pkgName = "com.test.pkg"; + + EXPECT_CALL(*multipleUserConnectorMock_, GetCallerUserId(_)) + .WillOnce([](int32_t &userId) { userId = 123; }); + EXPECT_CALL(*multipleUserConnectorMock_, GetCallingTokenId(_)) + .WillOnce([](uint32_t &tokenId) { tokenId = 456; }); + + EXPECT_CALL(*deviceManagerServiceImplMock_, GetBundleLable(pkgName)) + .WillOnce(Return("label")); + + deviceManagerServiceImpl_->GetBindCallerInfo(info, pkgName); + + EXPECT_EQ(info.userId, 123); + EXPECT_EQ(info.tokenId, 456); + EXPECT_EQ(info.hostPkgLabel, "com.test.pkg"); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetBundleLable_001, testing::ext::TestSize.Level1) +{ + std::string bundleName = "test.bundle"; + std::string label = deviceManagerServiceImpl_->GetBundleLable(bundleName); + EXPECT_EQ(label, bundleName); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSrcAccessControl_001, testing::ext::TestSize.Level1) +{ + DmAccessCaller caller; + std::string srcUdid = "srcUdid"; + DmAccessCallee callee; + std::string sinkUdid = "sinkUdid"; + + EXPECT_CALL(*deviceProfileConnectorMock_, CheckSrcAccessControl(_, _, _, _)) + .WillOnce(Return(false)); + + bool ret = deviceManagerServiceImpl_->CheckSrcAccessControl(caller, srcUdid, callee, sinkUdid); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSinkAccessControl_001, testing::ext::TestSize.Level1) +{ + DmAccessCaller caller; + std::string srcUdid = "srcUdid"; + DmAccessCallee callee; + std::string sinkUdid = "sinkUdid"; + + EXPECT_CALL(*deviceProfileConnectorMock_, CheckSinkAccessControl(_, _, _, _)) + .WillOnce(Return(false)); + + bool ret = deviceManagerServiceImpl_->CheckSinkAccessControl(caller, srcUdid, callee, sinkUdid); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSrcIsSameAccount_001, testing::ext::TestSize.Level1) +{ + DmAccessCaller caller; + std::string srcUdid = "srcUdid"; + DmAccessCallee callee; + std::string sinkUdid = "sinkUdid"; + + EXPECT_CALL(*deviceProfileConnectorMock_, CheckSrcIsSameAccount(_, _, _, _)) + .WillOnce(Return(false)); + + bool ret = deviceManagerServiceImpl_->CheckSrcIsSameAccount(caller, srcUdid, callee, sinkUdid); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, CheckSinkIsSameAccount_002, testing::ext::TestSize.Level1) +{ + DmAccessCaller caller; + std::string srcUdid = "srcUdid"; + DmAccessCallee callee; + std::string sinkUdid = "sinkUdid"; + + EXPECT_CALL(*deviceProfileConnectorMock_, CheckSinkIsSameAccount(_, _, _, _)) + .WillOnce(Return(false)); + + bool ret = deviceManagerServiceImpl_->CheckSinkIsSameAccount(caller, srcUdid, callee, sinkUdid); + EXPECT_FALSE(ret); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetBindCallerInfoToBindParam_001, testing::ext::TestSize.Level1) +{ + std::map bindParam = { + {"key1", "value1"}, + {"key2", "value2"} + }; + std::map bindParamTmp; + DmBindCallerInfo bindCallerInfo; + bindCallerInfo.userId = 100; + bindCallerInfo.tokenId = 200; + bindCallerInfo.bindLevel = 2; + bindCallerInfo.bundleName = "bundle"; + bindCallerInfo.hostPkgLabel = "label"; + bindCallerInfo.processName = "proc"; + bindCallerInfo.isSystemSA = true; + + deviceManagerServiceImpl_->SetBindCallerInfoToBindParam(bindParam, bindParamTmp, bindCallerInfo); + + EXPECT_EQ(bindParamTmp["key1"], "value1"); + EXPECT_EQ(bindParamTmp["key2"], "value2"); + + EXPECT_EQ(bindParamTmp["bindCallerUserId"], "100"); + EXPECT_EQ(bindParamTmp["bindCallerTokenId"], "200"); + EXPECT_EQ(bindParamTmp["bindCallerBindLevel"], "2"); + EXPECT_EQ(bindParamTmp["bindCallerBundleName"], "bundle"); + EXPECT_EQ(bindParamTmp["bindCallerHostPkgLabel"], "label"); + EXPECT_EQ(bindParamTmp["bindCallerProcessName"], "proc"); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, TransferOldAuthMgr_001, testing::ext::TestSize.Level1) +{ + deviceManagerServiceImpl_->authMgr_ = nullptr; + int32_t msgtype = 80; + JsonObject jsonObject; + int32_t sessionId = 12345; + std::string deviceid = "LN0000"; + std::shared_ptr session = std::make_shared(sessionId, deviceid); + int32_t ret = deviceManagerServiceImpl_->TransferOldAuthMgr(msgtype, jsonObject, session); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetCurSession_001, testing::ext::TestSize.Level1) +{ + int sessionId = 123; + std::shared_ptr session = std::make_shared(sessionId, "devId"); + { + std::lock_guard lock(deviceManagerServiceImpl_->mapMutex_); + deviceManagerServiceImpl_->sessionsMap_[sessionId] = session; + } + auto result = deviceManagerServiceImpl_->GetCurSession(sessionId); + EXPECT_EQ(result, session); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetCurSession_002, testing::ext::TestSize.Level1) +{ + int sessionId = 456; + { + std::lock_guard lock(deviceManagerServiceImpl_->mapMutex_); + deviceManagerServiceImpl_->sessionsMap_.erase(sessionId); + } + auto result = deviceManagerServiceImpl_->GetCurSession(sessionId); + EXPECT_EQ(result, nullptr); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetBindCallerInfoToBindParam_002, testing::ext::TestSize.Level1) +{ + std::map bindParam; + std::map bindParamTmp; + DmBindCallerInfo bindCallerInfo; + bindCallerInfo.userId = 1; + bindCallerInfo.tokenId = 2; + bindCallerInfo.bindLevel = 3; + bindCallerInfo.bundleName = "bundle"; + bindCallerInfo.hostPkgLabel = "label"; + bindCallerInfo.processName = "proc"; + bindCallerInfo.isSystemSA = false; + + deviceManagerServiceImpl_->SetBindCallerInfoToBindParam(bindParam, bindParamTmp, bindCallerInfo); + + EXPECT_EQ(bindParamTmp["bindCallerUserId"], "1"); + EXPECT_EQ(bindParamTmp["bindCallerTokenId"], "2"); + EXPECT_EQ(bindParamTmp["bindCallerBindLevel"], "3"); + EXPECT_EQ(bindParamTmp["bindCallerBundleName"], "bundle"); + EXPECT_EQ(bindParamTmp["bindCallerHostPkgLabel"], "label"); + EXPECT_EQ(bindParamTmp["bindCallerProcessName"], "proc"); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, SetBindCallerInfoToBindParam_003, testing::ext::TestSize.Level1) +{ + std::map bindParam = { + {"originKey", "originValue"} + }; + std::map bindParamTmp; + DmBindCallerInfo bindCallerInfo; + bindCallerInfo.userId = 10; + bindCallerInfo.tokenId = 20; + bindCallerInfo.bindLevel = 30; + bindCallerInfo.bundleName = "bundle2"; + bindCallerInfo.hostPkgLabel = "label2"; + bindCallerInfo.processName = "proc2"; + bindCallerInfo.isSystemSA = true; + + deviceManagerServiceImpl_->SetBindCallerInfoToBindParam(bindParam, bindParamTmp, bindCallerInfo); + + EXPECT_EQ(bindParamTmp["originKey"], "originValue"); + EXPECT_EQ(bindParamTmp["bindCallerUserId"], "10"); + EXPECT_EQ(bindParamTmp["bindCallerTokenId"], "20"); + EXPECT_EQ(bindParamTmp["bindCallerBindLevel"], "30"); + EXPECT_EQ(bindParamTmp["bindCallerBundleName"], "bundle2"); + EXPECT_EQ(bindParamTmp["bindCallerHostPkgLabel"], "label2"); + EXPECT_EQ(bindParamTmp["bindCallerProcessName"], "proc2"); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, TransferSrcOldAuthMgr_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr session = std::make_shared(111, "devId"); + int32_t ret = deviceManagerServiceImpl_->TransferSrcOldAuthMgr(session); + EXPECT_EQ(ret, ERR_DM_AUTH_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ChangeUltrasonicTypeToPin_001, testing::ext::TestSize.Level1) +{ + std::map bindParam; + int32_t ret = deviceManagerServiceImpl_->ChangeUltrasonicTypeToPin(bindParam); + EXPECT_EQ(ret, ERR_DM_AUTH_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, ChangeUltrasonicTypeToPin_002, testing::ext::TestSize.Level1) +{ + + std::map bindParam; + bindParam[PARAM_KEY_AUTH_TYPE] = "6"; + int32_t ret = deviceManagerServiceImpl_->ChangeUltrasonicTypeToPin(bindParam); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(bindParam[PARAM_KEY_AUTH_TYPE], std::string("1")); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, TransferSrcOldAuthMgr_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr session = std::make_shared(222, "devId"); + uint64_t logicalSessionId = 1001; + uint64_t tokenId = 2002; + deviceManagerServiceImpl_->logicalSessionId2SessionIdMap_[logicalSessionId] = 222; + deviceManagerServiceImpl_->logicalSessionId2TokenIdMap_[logicalSessionId] = tokenId; + deviceManagerServiceImpl_->authMgrMap_.erase(tokenId); + + int32_t ret = deviceManagerServiceImpl_->TransferSrcOldAuthMgr(session); + EXPECT_EQ(ret, ERR_DM_POINT_NULL); + + deviceManagerServiceImpl_->logicalSessionId2SessionIdMap_.clear(); + deviceManagerServiceImpl_->logicalSessionId2TokenIdMap_.clear(); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, TransferOldAuthMgr_002, testing::ext::TestSize.Level1) +{ + int32_t msgType = 90; + JsonObject jsonObject; + jsonObject[TAG_EDITION] = "5.0.90"; + auto session = std::make_shared(2, "devId"); + deviceManagerServiceImpl_->authMgr_ = std::shared_ptr(); + + EXPECT_CALL(*deviceManagerServiceImplMock_, TransferSrcOldAuthMgr(_)).WillOnce(Return(123)); + + int32_t ret = deviceManagerServiceImpl_->TransferOldAuthMgr(msgType, jsonObject, session); + EXPECT_NE(ret, DM_OK); + deviceManagerServiceImpl_->authMgr_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, TransferOldAuthMgr_003, testing::ext::TestSize.Level1) +{ + int32_t msgType = 80; + JsonObject jsonObject; + jsonObject[TAG_DMVERSION] = "5.0.90"; + auto session = std::make_shared(3, "devId"); + deviceManagerServiceImpl_->authMgr_ = std::shared_ptr(); + + int32_t ret = deviceManagerServiceImpl_->TransferOldAuthMgr(msgType, jsonObject, session); + EXPECT_NE(ret, DM_OK); + deviceManagerServiceImpl_->authMgr_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceInfo_001, testing::ext::TestSize.Level1) +{ + PeerTargetId targetId; + targetId.wifiIp = "192.168.1.100"; + targetId.wifiPort = 12345; + std::string addrType = ""; + std::string deviceId; + auto deviceInfo = std::make_shared(); + int32_t index = 0; + + int32_t ret = deviceManagerServiceImpl_->GetDeviceInfo(targetId, addrType, deviceId, deviceInfo, index); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(deviceId, "192.168.1.100"); + EXPECT_EQ(deviceInfo->addr[0].type, ConnectionAddrType::CONNECTION_ADDR_WLAN); + EXPECT_EQ(deviceInfo->addr[0].info.ip.port, 12345); + EXPECT_EQ(index, 1); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceInfo_002, testing::ext::TestSize.Level1) +{ + PeerTargetId targetId; + targetId.wifiIp = "192.168.1.101"; + targetId.wifiPort = 54321; + std::string deviceId; + std::string addrType = std::to_string(ConnectionAddrType::CONNECTION_ADDR_BR); + auto deviceInfo = std::make_shared(); + int32_t index = 0; + + int32_t ret = deviceManagerServiceImpl_->GetDeviceInfo(targetId, addrType, deviceId, deviceInfo, index); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(deviceId, "192.168.1.101"); + EXPECT_EQ(deviceInfo->addr[0].type, ConnectionAddrType::CONNECTION_ADDR_BR); + EXPECT_EQ(deviceInfo->addr[0].info.ip.port, 54321); + EXPECT_EQ(index, 1); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceInfo_003, testing::ext::TestSize.Level1) +{ + PeerTargetId targetId; + targetId.brMac = "11:22:33:44:55:66"; + std::string addrType = ""; + std::string deviceId; + auto deviceInfo = std::make_shared(); + int32_t index = 0; + + int32_t ret = deviceManagerServiceImpl_->GetDeviceInfo(targetId, addrType, deviceId, deviceInfo, index); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(deviceId, "11:22:33:44:55:66"); + EXPECT_EQ(deviceInfo->addr[0].type, ConnectionAddrType::CONNECTION_ADDR_BR); + EXPECT_EQ(index, 1); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceInfo_004, testing::ext::TestSize.Level1) +{ + PeerTargetId targetId; + targetId.bleMac = "AA:BB:CC:DD:EE:FF"; + targetId.deviceId = "12345678"; + std::string addrType = ""; + std::string deviceId; + auto deviceInfo = std::make_shared(); + int32_t index = 0; + + int32_t ret = deviceManagerServiceImpl_->GetDeviceInfo(targetId, addrType, deviceId, deviceInfo, index); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(deviceId, "AA:BB:CC:DD:EE:FF"); + EXPECT_EQ(deviceInfo->addr[0].type, ConnectionAddrType::CONNECTION_ADDR_BLE); + EXPECT_EQ(index, 1); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceInfo_005, testing::ext::TestSize.Level1) +{ + PeerTargetId targetId; + std::string addrType = ""; + std::string deviceId; + auto deviceInfo = std::make_shared(); + int32_t index = 0; + + int32_t ret = deviceManagerServiceImpl_->GetDeviceInfo(targetId, addrType, deviceId, deviceInfo, index); + EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); +} + +HWTEST_F(DeviceManagerServiceImplFirstTest, DeleteAclByDelProfileMap_001, testing::ext::TestSize.Level1) +{ + std::map delProfileMap; + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + const std::string localUdid = "123456"; + profile.GetAccesser().SetAccesserTokenId(5678); + profiles.push_back(profile); + int32_t key = 12; + std::string value = "acl_info1"; + deviceManagerServiceImpl_->DeleteAclByDelProfileMap(delProfileMap, profiles, localUdid); + + EXPECT_FALSE(profiles.empty()); +} } // 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 04dcec1a1384fd255bab2c5edbe2a1a769a837d7..25a0c22599242e3a0b10e0f96634a5db9fc3d0db 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.h +++ b/test/unittest/UTTest_device_manager_service_impl_first.h @@ -30,6 +30,7 @@ #include "dm_device_state_manager_mock.h" #include "device_manager_service_impl_mock.h" #include "hichain_connector_mock.h" +#include "hichain_auth_connector_mock.h" namespace OHOS { namespace DistributedHardware { @@ -52,8 +53,10 @@ public: std::make_shared(); static inline std::shared_ptr deviceManagerServiceImplMock_ = std::make_shared(); - static inline std::shared_ptr hiChainConnectorMock_ = + static inline std::shared_ptr hiChainConnectorMock_ = std::make_shared(); + static inline std::shared_ptr hiChainAuthConnectorMock_ = + std::make_shared(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/device_manager_service_impl_mock.cpp b/test/unittest/mock/device_manager_service_impl_mock.cpp index efd5f34ecb4667df97805dd0b3cc38a35da18867..ce896de7158d6a1f6d26320cd5115f7600bbbcb4 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.cpp +++ b/test/unittest/mock/device_manager_service_impl_mock.cpp @@ -102,5 +102,31 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId, peerTokenId); } + +bool DeviceManagerServiceImpl::IsAuthNewVersion(int32_t bindLevel, std::string localUdid, + std::string remoteUdid, int32_t tokenId, int32_t userId) +{ + return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->IsAuthNewVersion(bindLevel, localUdid, + remoteUdid, tokenId, userId); +} + +int32_t DeviceManagerServiceImpl::DeleteAcl(const std::string &sessionName, const std::string &localUdid, + const std::string &remoteUdid, int32_t bindLevel, const std::string &extra) +{ + return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->DeleteAcl(sessionName, localUdid, remoteUdid, + bindLevel, extra); +} + +int32_t DeviceManagerServiceImpl::DeleteAclForProcV2(const std::string &localUdid, uint32_t localTokenId, + const std::string &remoteUdid, int32_t bindLevel, const std::string &extra, int32_t userId) +{ + return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->DeleteAclForProcV2(localUdid, localTokenId, + remoteUdid, bindLevel, extra, userId); +} + +std::string DeviceManagerServiceImpl::GetBundleLable(const std::string &bundleName) +{ + return DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl->GetBundleLable(bundleName); +} } // 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 6a31d6008d335490d14d9e1742ede635df578401..50aecbc2b71f8cdb19e207a95032da9e8f688ce7 100644 --- a/test/unittest/mock/device_manager_service_impl_mock.h +++ b/test/unittest/mock/device_manager_service_impl_mock.h @@ -46,6 +46,13 @@ public: virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId) = 0; virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, int32_t peerTokenId) = 0; + virtual bool IsAuthNewVersion(int32_t bindLevel, std::string localUdid, std::string remoteUdid, + int32_t tokenId, int32_t userId) = 0; + virtual int32_t DeleteAcl(const std::string &sessionName, const std::string &localUdid, + const std::string &remoteUdid, int32_t bindLevel, const std::string &extra) = 0; + virtual int32_t DeleteAclForProcV2(const std::string &localUdid, uint32_t localTokenId, + const std::string &remoteUdid, int32_t bindLevel, const std::string &extra, int32_t userId) = 0; + virtual std::string GetBundleLable(const std::string &bundleName) = 0; public: static inline std::shared_ptr dmDeviceManagerServiceImpl = nullptr; }; @@ -69,6 +76,13 @@ public: MOCK_METHOD(void, HandleAppUnBindEvent, (int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId)); MOCK_METHOD(void, HandleAppUnBindEvent, (int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, int32_t peerTokenId)); + MOCK_METHOD(bool, IsAuthNewVersion, (int32_t bindLevel, std::string localUdid, std::string remoteUdid, + int32_t tokenId, int32_t userId)); + MOCK_METHOD(int32_t, DeleteAcl, (const std::string &sessionName, const std::string &localUdid, + const std::string &remoteUdid, int32_t bindLevel, const std::string &extra)); + MOCK_METHOD(int32_t, DeleteAclForProcV2, (const std::string &localUdid, uint32_t localTokenId, + const std::string &remoteUdid, int32_t bindLevel, const std::string &extra, int32_t userId)); + MOCK_METHOD(std::string, GetBundleLable, (const std::string &bundleName)); }; } } diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 4f82813a289ff08bcde1d6432d874c10a940a3a5..ae770c772fdf624fa528de533dc6b8f8269523a1 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -200,5 +200,67 @@ bool DeviceProfileConnector::IsLnnAcl(const DistributedDeviceProfile::AccessCont { return DmDeviceProfileConnector::dmDeviceProfileConnector->IsLnnAcl(profile); } + +int32_t DeviceProfileConnector::DeleteSessionKey(int32_t userId, int32_t sessionKeyId) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->DeleteSessionKey(userId, sessionKeyId); +} +DmOfflineParam DeviceProfileConnector::FilterNeedDeleteACL(const std::string &localDeviceId, uint32_t localTokenId, + const std::string &remoteDeviceId, const std::string &extra) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->FilterNeedDeleteACL(localDeviceId, localTokenId, + remoteDeviceId, extra); +} + +void DeviceProfileConnector::UpdateACL(std::string &localUdid, const std::vector &localUserIds, + const std::string &remoteUdid, const std::vector &remoteFrontUserIds, + const std::vector &remoteBackUserIds, DmOfflineParam &offlineParam) +{ + DmDeviceProfileConnector::dmDeviceProfileConnector->UpdateACL(localUdid, localUserIds, + remoteUdid, remoteFrontUserIds, remoteBackUserIds, offlineParam); +} + +void DeviceProfileConnector::HandleSyncBackgroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid) +{ + DmDeviceProfileConnector::dmDeviceProfileConnector->HandleSyncBackgroundUserIdEvent(remoteUserIds, remoteUdid, + localUserIds, localUdid); +} + +void DeviceProfileConnector::HandleSyncForegroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid) +{ + DmDeviceProfileConnector::dmDeviceProfileConnector->HandleSyncForegroundUserIdEvent(remoteUserIds, remoteUdid, + localUserIds, localUdid); +} + +bool DeviceProfileConnector::CheckSrcAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->CheckSrcAccessControl(caller, srcUdid, callee, sinkUdid); +} + +bool DeviceProfileConnector::CheckSinkAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->CheckSinkAccessControl(caller, + srcUdid, callee, sinkUdid); +} + +bool DeviceProfileConnector::CheckSrcIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->CheckSrcIsSameAccount(caller, + srcUdid, callee, sinkUdid); +} + +bool DeviceProfileConnector::CheckSinkIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->CheckSinkIsSameAccount(caller, + srcUdid, callee, sinkUdid); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index 84d5c9d04804bd05482ac71f3d149a58a32ab81a..f3ac524a5d7e3c465387260e3dde4735f9d7e165 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -75,6 +75,26 @@ public: virtual void CacheAcerAclId(const DistributedDeviceProfile::AccessControlProfile &profile, std::vector &aclInfos) = 0; virtual bool IsLnnAcl(const DistributedDeviceProfile::AccessControlProfile &profile) = 0; + virtual int32_t DeleteSessionKey(int32_t userId, int32_t sessionKeyId) = 0; + virtual DmOfflineParam FilterNeedDeleteACL(const std::string &localDeviceId, uint32_t localTokenId, + const std::string &remoteDeviceId, const std::string &extra) = 0; + virtual void HandleSyncBackgroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid) = 0; + virtual void HandleSyncForegroundUserIdEvent( + const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid) = 0; + virtual void UpdateACL(std::string &localUdid, const std::vector &localUserIds, + const std::string &remoteUdid, const std::vector &remoteFrontUserIds, + const std::vector &remoteBackUserIds, DmOfflineParam &offlineParam) = 0; + virtual bool CheckSrcAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) = 0; + virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) = 0; + virtual bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) = 0; + virtual bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid) = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; }; @@ -124,6 +144,26 @@ public: MOCK_METHOD(void, CacheAcerAclId, (const DistributedDeviceProfile::AccessControlProfile &profile, std::vector &aclInfos)); MOCK_METHOD(bool, IsLnnAcl, (const DistributedDeviceProfile::AccessControlProfile &profile)); + MOCK_METHOD(int32_t, DeleteSessionKey, (int32_t userId, int32_t sessionKeyId)); + MOCK_METHOD(DmOfflineParam, FilterNeedDeleteACL, (const std::string &localDeviceId, uint32_t localTokenId, + const std::string &remoteDeviceId, const std::string &extra)); + MOCK_METHOD(void, UpdateACL, (std::string &localUdid, const std::vector &localUserIds, + const std::string &remoteUdid, const std::vector &remoteFrontUserIds, + const std::vector &remoteBackUserIds, DmOfflineParam &offlineParam)); + MOCK_METHOD(void, HandleSyncBackgroundUserIdEvent, + (const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid)); + MOCK_METHOD(void, HandleSyncForegroundUserIdEvent, + (const std::vector &remoteUserIds, const std::string &remoteUdid, + const std::vector &localUserIds, std::string &localUdid)); + MOCK_METHOD(bool, CheckSrcAccessControl, (const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid)); + MOCK_METHOD(bool, CheckSinkAccessControl, (const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid)); + MOCK_METHOD(bool, CheckSrcIsSameAccount, (const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid)); + MOCK_METHOD(bool, CheckSinkIsSameAccount, (const DmAccessCaller &caller, const std::string &srcUdid, + const DmAccessCallee &callee, const std::string &sinkUdid)); }; } } diff --git a/test/unittest/mock/multiple_user_connector_mock.cpp b/test/unittest/mock/multiple_user_connector_mock.cpp index 5d19450cbd7607b48ddf15bc30d5194739b9b4f6..b8ac46647c6b94e7b75ca8b4dbad910c4794558f 100644 --- a/test/unittest/mock/multiple_user_connector_mock.cpp +++ b/test/unittest/mock/multiple_user_connector_mock.cpp @@ -68,5 +68,15 @@ void MultipleUserConnector::GetCallerUserId(int32_t &userId) { return DmMultipleUserConnector::dmMultipleUserConnector->GetCallerUserId(userId); } + +void MultipleUserConnector::GetCallingTokenId(uint32_t &tokenId) +{ + return DmMultipleUserConnector::dmMultipleUserConnector->GetCallingTokenId(tokenId); +} + +void MultipleUserConnector::ClearLockedUser(std::vector &foregroundUserVec) +{ + return DmMultipleUserConnector::dmMultipleUserConnector->ClearLockedUser(foregroundUserVec); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/multiple_user_connector_mock.h b/test/unittest/mock/multiple_user_connector_mock.h index 9a39bb1b0923bb9c40dfa47f2acc898a090e836e..1de71422883abb54fa3cb79b865d29d63168a719 100644 --- a/test/unittest/mock/multiple_user_connector_mock.h +++ b/test/unittest/mock/multiple_user_connector_mock.h @@ -36,6 +36,8 @@ public: virtual std::string GetOhosAccountIdByUserId(int32_t userId) = 0; virtual std::string GetAccountNickName(int32_t) = 0; virtual void GetCallerUserId(int32_t &) = 0; + virtual void GetCallingTokenId(uint32_t &tokenId) = 0; + virtual void ClearLockedUser(std::vector &foregroundUserVec) = 0; public: static inline std::shared_ptr dmMultipleUserConnector = nullptr; }; @@ -52,6 +54,8 @@ public: MOCK_METHOD(std::string, GetOhosAccountIdByUserId, (int32_t)); MOCK_METHOD(std::string, GetAccountNickName, (int32_t)); MOCK_METHOD(void, GetCallerUserId, (int32_t &)); + MOCK_METHOD(void, GetCallingTokenId, (uint32_t &)); + MOCK_METHOD(void, ClearLockedUser, (std::vector &foregroundUserVec)); }; } } diff --git a/test/unittest/mock/softbus_connector_mock.cpp b/test/unittest/mock/softbus_connector_mock.cpp index d49c8c253cca5c3fd2e4fd1dad7a6cb08dee23bc..0d59a9b9ca0e4d4aeb25c5645f8c83bdb5211def 100644 --- a/test/unittest/mock/softbus_connector_mock.cpp +++ b/test/unittest/mock/softbus_connector_mock.cpp @@ -59,5 +59,10 @@ int32_t SoftbusConnector::SyncLocalAclListProcess(const DevUserInfo &localDevUse return DmSoftbusConnector::dmSoftbusConnector->SyncLocalAclListProcess(localDevUserInfo, remoteDevUserInfo, remoteAclList); } + +void SoftbusConnector::HandleDeviceOffline(std::string deviceId) +{ + DmSoftbusConnector::dmSoftbusConnector->HandleDeviceOffline(deviceId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/softbus_connector_mock.h b/test/unittest/mock/softbus_connector_mock.h index e71d229f659cdbd9e6264fc0ec65ddbd797c72c8..5d45736e53f3dd7c79422f3b6158a977d2fe017f 100644 --- a/test/unittest/mock/softbus_connector_mock.h +++ b/test/unittest/mock/softbus_connector_mock.h @@ -35,6 +35,7 @@ public: virtual void SetProcessInfoVec(std::vector processInfoVec) = 0; virtual int32_t SyncLocalAclListProcess(const DevUserInfo &localDevUserInfo, const DevUserInfo &remoteDevUserInfo, std::string remoteAclList) = 0; + virtual void HandleDeviceOffline(std::string deviceId) = 0; public: static inline std::shared_ptr dmSoftbusConnector = nullptr; @@ -50,6 +51,7 @@ public: MOCK_METHOD(void, SetProcessInfo, (ProcessInfo processInfo)); MOCK_METHOD(void, SetProcessInfoVec, (std::vector processInfoVec)); MOCK_METHOD(int32_t, SyncLocalAclListProcess, (const DevUserInfo &, const DevUserInfo &, std::string)); + MOCK_METHOD(void, HandleDeviceOffline, (std::string deviceId)); }; } }