diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index de578f338e99e8f3d42adedfd77727140c9b0f6e..281890227994afec7e5ff789614611cbedc3ef96 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -937,6 +937,870 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_007, testing::ext::Tes EXPECT_EQ(ret[trustDeviceId], DmAuthForm::IDENTICAL_ACCOUNT); } +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACL_001, testing::ext::TestSize.Level1) +{ + std::string localDeviceId = "local_device"; + uint32_t localTokenId = 1234; + std::string remoteDeviceId = "remote_device"; + std::string extra = R"({"peerTokenId": 5678, "peerBundleName": "test_bundle"})"; + DmOfflineParam offlineParam; + + std::vector profiles; + + DeviceProfileConnector::GetInstance().FilterNeedDeleteACLInfos( + profiles, localDeviceId, localTokenId, remoteDeviceId, extra, offlineParam); + + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACL_002, testing::ext::TestSize.Level1) +{ + std::string localDeviceId = "local_device"; + uint32_t localTokenId = 1234; + std::string remoteDeviceId = "remote_device"; + std::string extra = "invalid_extra"; + DmOfflineParam offlineParam; + + std::vector profiles; + + DeviceProfileConnector::GetInstance().FilterNeedDeleteACLInfos( + profiles, localDeviceId, localTokenId, remoteDeviceId, extra, offlineParam); + + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACL_003, testing::ext::TestSize.Level1) +{ + std::string localDeviceId = "local_device"; + uint32_t localTokenId = 1234; + std::string remoteDeviceId = "remote_device"; + std::string extra = "{}"; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(DM_OK)); + + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().FilterNeedDeleteACL( + localDeviceId, localTokenId, remoteDeviceId, extra); + + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); + EXPECT_FALSE(offlineParam.hasLnnAcl); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACL_004, testing::ext::TestSize.Level1) +{ + std::string localDeviceId = "local_device"; + uint32_t localTokenId = 1234; + std::string remoteDeviceId = "remote_device"; + std::string extra = R"({"invalidKey": "invalidValue"})"; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetTrustDeviceId(remoteDeviceId); + profiles.push_back(profile); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(DM_OK)); + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().FilterNeedDeleteACL( + localDeviceId, localTokenId, remoteDeviceId, extra); + + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACL_005, testing::ext::TestSize.Level1) +{ + std::string localDeviceId = "local_device"; + uint32_t localTokenId = 1234; + std::string remoteDeviceId = "non_matching_device"; + std::string extra = R"({"peerTokenId": 5678, "peerBundleName": "test_bundle"})"; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.SetTrustDeviceId("other_device"); + profiles.push_back(profile); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(DM_OK)); + + DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().FilterNeedDeleteACL( + localDeviceId, localTokenId, remoteDeviceId, extra); + + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteCacheAcl_001, testing::ext::TestSize.Level1) +{ + std::vector delAclIdVec; + std::vector profiles; + + DeviceProfileConnector::GetInstance().DeleteCacheAcl(delAclIdVec, profiles); + + EXPECT_TRUE(profiles.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteCacheAcl_002, testing::ext::TestSize.Level1) +{ + std::vector delAclIdVec; + std::vector profiles(2); + + profiles[0].SetAccessControlId(1); + profiles[1].SetAccessControlId(2); + + DeviceProfileConnector::GetInstance().DeleteCacheAcl(delAclIdVec, profiles); + + EXPECT_EQ(profiles.size(), 2); + EXPECT_EQ(profiles[0].GetAccessControlId(), 1); + EXPECT_EQ(profiles[1].GetAccessControlId(), 2); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteCacheAcl_003, testing::ext::TestSize.Level1) +{ + std::vector delAclIdVec = {1, 2}; + std::vector profiles; + + DeviceProfileConnector::GetInstance().DeleteCacheAcl(delAclIdVec, profiles); + + EXPECT_TRUE(profiles.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteCacheAcl_004, testing::ext::TestSize.Level1) +{ + std::vector delAclIdVec = {1}; + std::vector profiles(2); + + profiles[0].SetAccessControlId(1); + profiles[1].SetAccessControlId(2); + + DeviceProfileConnector::GetInstance().DeleteCacheAcl(delAclIdVec, profiles); + + EXPECT_EQ(profiles.size(), 1); + EXPECT_EQ(profiles[0].GetAccessControlId(), 2); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteCacheAcl_005, testing::ext::TestSize.Level1) +{ + std::vector delAclIdVec = {3}; + std::vector profiles(2); + + profiles[0].SetAccessControlId(1); + profiles[1].SetAccessControlId(2); + + DeviceProfileConnector::GetInstance().DeleteCacheAcl(delAclIdVec, profiles); + + EXPECT_EQ(profiles.size(), 2); + EXPECT_EQ(profiles[0].GetAccessControlId(), 1); + EXPECT_EQ(profiles[1].GetAccessControlId(), 2); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteCacheAcl_006, testing::ext::TestSize.Level1) +{ + std::vector delAclIdVec = {1, 2}; + std::vector profiles(3); + + profiles[0].SetAccessControlId(1); + profiles[1].SetAccessControlId(2); + profiles[2].SetAccessControlId(3); + + DeviceProfileConnector::GetInstance().DeleteCacheAcl(delAclIdVec, profiles); + + EXPECT_EQ(profiles.size(), 1); + EXPECT_EQ(profiles[0].GetAccessControlId(), 3); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteCacheAcl_007, testing::ext::TestSize.Level1) +{ + std::vector delAclIdVec = {1, 4}; + std::vector profiles(3); + + profiles[0].SetAccessControlId(1); + profiles[1].SetAccessControlId(2); + profiles[2].SetAccessControlId(3); + + DeviceProfileConnector::GetInstance().DeleteCacheAcl(delAclIdVec, profiles); + + EXPECT_EQ(profiles.size(), 2); + EXPECT_EQ(profiles[0].GetAccessControlId(), 2); + EXPECT_EQ(profiles[1].GetAccessControlId(), 3); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, ParseExtra_001, testing::ext::TestSize.Level1) +{ + std::string extra = ""; + uint64_t peerTokenId = 0; + std::string peerBundleName; + + DeviceProfileConnector::GetInstance().ParseExtra(extra, peerTokenId, peerBundleName); + + EXPECT_EQ(peerTokenId, 0); + EXPECT_TRUE(peerBundleName.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, ParseExtra_002, testing::ext::TestSize.Level1) +{ + std::string extra = "invalid_json"; + uint64_t peerTokenId = 0; + std::string peerBundleName; + + DeviceProfileConnector::GetInstance().ParseExtra(extra, peerTokenId, peerBundleName); + + EXPECT_EQ(peerTokenId, 0); + EXPECT_TRUE(peerBundleName.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, ParseExtra_003, testing::ext::TestSize.Level1) +{ + std::string extra = R"({"peerTokenId": "invalidTokenId", "peerBundleName": "testBundle"})"; + uint64_t peerTokenId = 0; + std::string peerBundleName; + + DeviceProfileConnector::GetInstance().ParseExtra(extra, peerTokenId, peerBundleName); + + EXPECT_EQ(peerTokenId, 0); + EXPECT_TRUE(peerBundleName.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, ParseExtra_004, testing::ext::TestSize.Level1) +{ + std::string extra = R"({"peerTokenId": 12345, "peerBundleName": "testBundle"})"; + uint64_t peerTokenId = 0; + std::string peerBundleName; + + DeviceProfileConnector::GetInstance().ParseExtra(extra, peerTokenId, peerBundleName); + + EXPECT_EQ(peerTokenId, 12345); + EXPECT_EQ(peerBundleName, "testBundle"); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, ParseExtra_005, testing::ext::TestSize.Level1) +{ + std::string extra = R"({"peerTokenId": 12345, "peerBundleName": 12345})"; + uint64_t peerTokenId = 0; + std::string peerBundleName; + + DeviceProfileConnector::GetInstance().ParseExtra(extra, peerTokenId, peerBundleName); + + EXPECT_EQ(peerTokenId, 0); + EXPECT_TRUE(peerBundleName.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, ParseExtra_006, testing::ext::TestSize.Level1) +{ + std::string extra = R"({"peerTokenId": 12345, "peerBundleName": "testBundle", "extraField": "extraValue"})"; + uint64_t peerTokenId = 0; + std::string peerBundleName; + + DeviceProfileConnector::GetInstance().ParseExtra(extra, peerTokenId, peerBundleName); + + EXPECT_EQ(peerTokenId, 12345); + EXPECT_EQ(peerBundleName, "testBundle"); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindTargetAcl_001, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + acl.accesser_.SetAccesserTokenId(1001); + acl.accesser_.SetAccesserDeviceId("local_device"); + acl.accesser_.SetAccesserBundleName("test_pkg"); + acl.accesser_.SetAccesserUserId(1000); + acl.accessee_.SetAccesseeDeviceId("remote_device"); + acl.accessee_.SetAccesseeTokenId(0); + acl.SetAccessControlId(12345); + acl.SetBindType(DM_POINT_TO_POINT); + acl.SetBindLevel(APP); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + uint32_t peerTokenId = 0; + DmOfflineParam offlineParam; + + bool result = DeviceProfileConnector::GetInstance(). + FindTargetAcl(acl, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam); + + EXPECT_TRUE(result); + EXPECT_EQ(offlineParam.processVec.size(), 1); + EXPECT_EQ(offlineParam.processVec[0].pkgName, "test_pkg"); + EXPECT_EQ(offlineParam.processVec[0].userId, 1000); + EXPECT_EQ(offlineParam.needDelAclInfos.size(), 1); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindTargetAcl_002, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + acl.accesser_.SetAccesserTokenId(1001); + acl.accesser_.SetAccesserDeviceId("local_device"); + acl.accesser_.SetAccesserBundleName("test_pkg"); + acl.accesser_.SetAccesserUserId(1000); + acl.accessee_.SetAccesseeDeviceId("remote_device"); + acl.accessee_.SetAccesseeTokenId(2002); + acl.SetAccessControlId(12345); + acl.SetBindType(DM_POINT_TO_POINT); + acl.SetBindLevel(APP); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + uint32_t peerTokenId = 2002; + DmOfflineParam offlineParam; + + bool result = DeviceProfileConnector::GetInstance(). + FindTargetAcl(acl, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam); + + EXPECT_TRUE(result); + EXPECT_EQ(offlineParam.processVec.size(), 1); + EXPECT_EQ(offlineParam.needDelAclInfos.size(), 1); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindTargetAcl_003, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + acl.accessee_.SetAccesseeTokenId(1001); + acl.accessee_.SetAccesseeDeviceId("local_device"); + acl.accessee_.SetAccesseeBundleName("test_pkg"); + acl.accessee_.SetAccesseeUserId(1000); + acl.accesser_.SetAccesserDeviceId("remote_device"); + acl.accesser_.SetAccesserTokenId(0); + acl.SetAccessControlId(12345); + acl.SetBindType(DM_POINT_TO_POINT); + acl.SetBindLevel(APP); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + uint32_t peerTokenId = 0; + DmOfflineParam offlineParam; + + bool result = DeviceProfileConnector::GetInstance(). + FindTargetAcl(acl, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam); + + EXPECT_TRUE(result); + EXPECT_EQ(offlineParam.processVec.size(), 1); + EXPECT_EQ(offlineParam.processVec[0].pkgName, "test_pkg"); + EXPECT_EQ(offlineParam.needDelAclInfos.size(), 1); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindTargetAcl_004, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + acl.accessee_.SetAccesseeTokenId(1001); + acl.accessee_.SetAccesseeDeviceId("local_device"); + acl.accessee_.SetAccesseeBundleName("test_pkg"); + acl.accessee_.SetAccesseeUserId(1000); + acl.accesser_.SetAccesserDeviceId("remote_device"); + acl.accesser_.SetAccesserTokenId(2002); + acl.SetAccessControlId(12345); + acl.SetBindType(DM_POINT_TO_POINT); + acl.SetBindLevel(APP); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + uint32_t peerTokenId = 2002; + DmOfflineParam offlineParam; + + bool result = DeviceProfileConnector::GetInstance(). + FindTargetAcl(acl, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam); + + EXPECT_TRUE(result); + EXPECT_EQ(offlineParam.processVec.size(), 1); + EXPECT_EQ(offlineParam.needDelAclInfos.size(), 1); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindTargetAcl_005, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + acl.accesser_.SetAccesserTokenId(9999); + acl.accesser_.SetAccesserDeviceId("wrong_device"); + acl.accessee_.SetAccesseeDeviceId("wrong_device"); + acl.SetAccessControlId(12345); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + uint32_t peerTokenId = 2002; + DmOfflineParam offlineParam; + + bool result = DeviceProfileConnector::GetInstance(). + FindTargetAcl(acl, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam); + + EXPECT_FALSE(result); + EXPECT_TRUE(offlineParam.processVec.empty()); + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindTargetAcl_006, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + acl.accesser_.SetAccesserTokenId(1001); + acl.accesser_.SetAccesserDeviceId("local_device"); + acl.accessee_.SetAccesseeDeviceId("remote_device"); + acl.accessee_.SetAccesseeTokenId(9999); + acl.SetAccessControlId(12345); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + uint32_t peerTokenId = 2002; + DmOfflineParam offlineParam; + + bool result = DeviceProfileConnector::GetInstance(). + FindTargetAcl(acl, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam); + + EXPECT_FALSE(result); + EXPECT_TRUE(offlineParam.processVec.empty()); + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindTargetAcl_007, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + acl.accessee_.SetAccesseeTokenId(1001); + acl.accessee_.SetAccesseeDeviceId("local_device"); + acl.accesser_.SetAccesserDeviceId("remote_device"); + acl.accesser_.SetAccesserTokenId(9999); + acl.SetAccessControlId(12345); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + uint32_t peerTokenId = 2002; + DmOfflineParam offlineParam; + + bool result = DeviceProfileConnector::GetInstance(). + FindTargetAcl(acl, localUdid, localTokenId, remoteUdid, peerTokenId, offlineParam); + + EXPECT_FALSE(result); + EXPECT_TRUE(offlineParam.processVec.empty()); + EXPECT_TRUE(offlineParam.needDelAclInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindUserAcl_001, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(USER); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindUserAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindUserAcl_002, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindType(DM_IDENTICAL_ACCOUNT); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindUserAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindUserAcl_003, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(SERVICE); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindUserAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_FALSE(result); + EXPECT_EQ(offlineParam.allUserAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindUserAcl_004, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindType(DM_IDENTICAL_ACCOUNT); + acl.accesser_.SetAccesserDeviceId(remoteUdid); + acl.accessee_.SetAccesseeDeviceId(localUdid); + + bool result = DeviceProfileConnector::GetInstance().FindUserAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); + EXPECT_EQ(offlineParam.allUserAclInfos.size(), 1); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindUserAcl_005, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "non_matching_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(USER); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId("other_device"); + + bool result = DeviceProfileConnector::GetInstance().FindUserAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); + EXPECT_EQ(offlineParam.allUserAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindUserAcl_006, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = ""; + std::string remoteUdid = ""; + DmOfflineParam offlineParam; + + acl.SetBindLevel(USER); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindUserAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindLeftAcl_001, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(SERVICE); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindLeftAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindLeftAcl_002, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(APP); + acl.GetAccesser().SetAccesserDeviceId(remoteUdid); + acl.GetAccessee().SetAccesseeDeviceId(localUdid); + + bool result = DeviceProfileConnector::GetInstance().FindLeftAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindLeftAcl_003, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(USER); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindLeftAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_FALSE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindLeftAcl_004, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(SERVICE); + acl.GetAccesser().SetAccesserDeviceId("non_matching_device"); + acl.GetAccessee().SetAccesseeDeviceId(localUdid); + + bool result = DeviceProfileConnector::GetInstance().FindLeftAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindLeftAcl_005, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "non_matching_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(SERVICE); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId("other_device"); + + bool result = DeviceProfileConnector::GetInstance().FindLeftAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindLeftAcl_006, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = ""; + std::string remoteUdid = ""; + DmOfflineParam offlineParam; + + acl.SetBindLevel(SERVICE); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindLeftAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FindLeftAcl_007, testing::ext::TestSize.Level1) +{ + DistributedDeviceProfile::AccessControlProfile acl; + std::string localUdid = "local_device"; + std::string remoteUdid = "remote_device"; + DmOfflineParam offlineParam; + + acl.SetBindLevel(999); + acl.GetAccesser().SetAccesserDeviceId(localUdid); + acl.GetAccessee().SetAccesseeDeviceId(remoteUdid); + + bool result = DeviceProfileConnector::GetInstance().FindLeftAcl(acl, localUdid, remoteUdid, offlineParam); + + EXPECT_FALSE(result); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACLInfos_001, testing::ext::TestSize.Level1) +{ + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile acl; + acl.SetTrustDeviceId("remote_device"); + acl.accesser_.SetAccesserTokenId(1001); + acl.accesser_.SetAccesserDeviceId("local_device"); + acl.accessee_.SetAccesseeDeviceId("remote_device"); + profiles.push_back(acl); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + std::string extra = ""; + DmOfflineParam offlineParam; + + connector.FilterNeedDeleteACLInfos(profiles, localUdid, localTokenId, remoteUdid, extra, offlineParam); + + EXPECT_GT(offlineParam.needDelAclInfos.size(), 0); + EXPECT_EQ(offlineParam.allUserAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACLInfos_002, testing::ext::TestSize.Level1) +{ + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile acl; + acl.SetTrustDeviceId("remote_device"); + acl.SetBindLevel(USER); + acl.accesser_.SetAccesserDeviceId("local_device"); + acl.accessee_.SetAccesseeDeviceId("remote_device"); + profiles.push_back(acl); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + std::string extra = ""; + DmOfflineParam offlineParam; + + connector.FilterNeedDeleteACLInfos(profiles, localUdid, localTokenId, remoteUdid, extra, offlineParam); + + EXPECT_GT(offlineParam.allUserAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACLInfos_003, testing::ext::TestSize.Level1) +{ + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile acl; + acl.SetTrustDeviceId("wrong_device"); + acl.accesser_.SetAccesserDeviceId("local_device"); + acl.accessee_.SetAccesseeDeviceId("remote_device"); + profiles.push_back(acl); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + std::string extra = ""; + DmOfflineParam offlineParam; + + connector.FilterNeedDeleteACLInfos(profiles, localUdid, localTokenId, remoteUdid, extra, offlineParam); + + EXPECT_EQ(offlineParam.needDelAclInfos.size(), 0); + EXPECT_EQ(offlineParam.allUserAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACLInfos_004, testing::ext::TestSize.Level1) +{ + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile acl; + acl.SetTrustDeviceId("remote_device"); + acl.accesser_.SetAccesserTokenId(1001); + acl.accesser_.SetAccesserDeviceId("local_device"); + acl.accessee_.SetAccesseeDeviceId("remote_device"); + acl.accessee_.SetAccesseeTokenId(2002); + profiles.push_back(acl); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + std::string extra = "2002:test_pkg"; + DmOfflineParam offlineParam; + + connector.FilterNeedDeleteACLInfos(profiles, localUdid, localTokenId, remoteUdid, extra, offlineParam); + + EXPECT_GT(offlineParam.needDelAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACLInfos_005, testing::ext::TestSize.Level1) +{ + std::vector profiles; + + DistributedDeviceProfile::AccessControlProfile acl1; + acl1.SetTrustDeviceId("remote_device"); + acl1.accesser_.SetAccesserTokenId(1001); + acl1.accesser_.SetAccesserDeviceId("local_device"); + acl1.accessee_.SetAccesseeDeviceId("remote_device"); + profiles.push_back(acl1); + + DistributedDeviceProfile::AccessControlProfile acl2; + acl2.SetTrustDeviceId("remote_device"); + acl2.SetBindLevel(USER); + acl2.accesser_.SetAccesserDeviceId("local_device"); + acl2.accessee_.SetAccesseeDeviceId("remote_device"); + profiles.push_back(acl2); + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + std::string extra = ""; + DmOfflineParam offlineParam; + + connector.FilterNeedDeleteACLInfos(profiles, localUdid, localTokenId, remoteUdid, extra, offlineParam); + + EXPECT_GT(offlineParam.needDelAclInfos.size(), 0); + EXPECT_GT(offlineParam.allUserAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, FilterNeedDeleteACLInfos_006, testing::ext::TestSize.Level1) +{ + std::vector profiles; + + std::string localUdid = "local_device"; + uint32_t localTokenId = 1001; + std::string remoteUdid = "remote_device"; + std::string extra = ""; + DmOfflineParam offlineParam; + + connector.FilterNeedDeleteACLInfos(profiles, localUdid, localTokenId, remoteUdid, extra, offlineParam); + + EXPECT_EQ(offlineParam.needDelAclInfos.size(), 0); + EXPECT_EQ(offlineParam.allUserAclInfos.size(), 0); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByDeviceIdAndUserId_001, testing::ext::TestSize.Level1) +{ + std::string deviceId = "deviceId"; + int32_t userId = 123456; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(DM_OK)); + + auto result = DeviceProfileConnector::GetInstance().GetAclProfileByDeviceIdAndUserId(deviceId, userId); + + EXPECT_TRUE(result.empty()); +} + + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByDeviceIdAndUserId_002, testing::ext::TestSize.Level1) +{ + std::string deviceId = "deviceId"; + int32_t userId = 123456; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserDeviceId("nonMatchingDeviceId"); + profile.GetAccesser().SetAccesserUserId(999999); + profiles.push_back(profile); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)). + WillOnce(DoAll(SetArgReferee<1>(profiles), Return(DM_OK))); + + auto result = DeviceProfileConnector::GetInstance().GetAclProfileByDeviceIdAndUserId(deviceId, userId); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByDeviceIdAndUserId_003, testing::ext::TestSize.Level1) +{ + std::string deviceId = "deviceId"; + int32_t userId = 123456; + std::string remoteDeviceId = "remoteDeviceId"; + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile profile; + profile.GetAccesser().SetAccesserDeviceId("nonMatchingDeviceId"); + profile.GetAccesser().SetAccesserUserId(999999); + profile.GetAccessee().SetAccesseeDeviceId("nonMatchingRemoteDeviceId"); + profiles.push_back(profile); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) + .WillOnce(DoAll(SetArgReferee<0>(profiles), Return(DM_OK))); + + auto result = DeviceProfileConnector::GetInstance(). + GetAclProfileByDeviceIdAndUserId(deviceId, userId, remoteDeviceId); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByDeviceIdAndUserId_004, testing::ext::TestSize.Level1) +{ + std::string deviceId = "deviceId"; + int32_t userId = 123456; + std::string remoteDeviceId = "remoteDeviceId"; + + std::vector profiles; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) + .WillOnce(DoAll(SetArgReferee<0>(profiles), Return(DM_OK))); + + auto result = DeviceProfileConnector::GetInstance(). + GetAclProfileByDeviceIdAndUserId(deviceId, userId, remoteDeviceId); + + EXPECT_TRUE(result.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByDeviceIdAndUserId_005, testing::ext::TestSize.Level1) +{ + std::string deviceId = "deviceId"; + int32_t userId = 123456; + std::string remoteDeviceId = "remoteDeviceId"; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + auto result = DeviceProfileConnector::GetInstance(). + GetAclProfileByDeviceIdAndUserId(deviceId, userId, remoteDeviceId); + EXPECT_TRUE(result.empty()); +} + HWTEST_F(DeviceProfileConnectorSecondTest, GetVersionByExtra_001, testing::ext::TestSize.Level1) { std::string extraInfo = "";