已合并
新增foundation/distributedhardware/device_manager模块的ut #2203
AtomGit-Bot创建于 2024年12月7日
新增foundation/distributedhardware/device_manager模块的ut #2203
已合并
AtomGit-Bot创建于 2024年12月7日
从refs/pull/2203/head合入到master
共 28 个文件变更+1363-97
@@ -499,6 +499,52 @@ HWTEST_F(DmAnonymousTest, ParseMapFromJsonString_003, testing::ext::TestSize.Lev
499 ParseMapFromJsonString(jsonStr, paramMap);499 ParseMapFromJsonString(jsonStr, paramMap);
500 EXPECT_EQ(paramMap.size(), 0);500 EXPECT_EQ(paramMap.size(), 0);
501}501}
502+ 
503+HWTEST_F(DmAnonymousTest, GetAnonyStringList_001, testing::ext::TestSize.Level0)
504+{
505+ std::string value = "valueTest";
506+ std::vector<std::string> valueVec;
507+ valueVec.push_back(value);
508+ std::string str = GetAnonyStringList(valueVec);
509+ auto ret = str.size();
510+ EXPECT_GE(ret, 0);
511+}
512+ 
513+HWTEST_F(DmAnonymousTest, StringToInt64_002, testing::ext::TestSize.Level0)
514+{
515+ std::string str = "12345";
516+ int32_t base = 10;
517+ int32_t ret = StringToInt64(str, base);
518+ EXPECT_EQ(ret, 12345);
519+}
520+ 
521+HWTEST_F(DmAnonymousTest, GetCallerPkgName_001, testing::ext::TestSize.Level0)
522+{
523+ std::string str = "pkgName#12345";
524+ std::string ret = GetCallerPkgName(str);
525+ EXPECT_FALSE(ret.empty());
526+}
527+ 
528+HWTEST_F(DmAnonymousTest, IsMessageLengthValid_001, testing::ext::TestSize.Level0)
529+{
530+ std::string inputMessage;
531+ bool ret = IsMessageLengthValid(inputMessage);
532+ EXPECT_FALSE(ret);
533+}
534+ 
535+HWTEST_F(DmAnonymousTest, IsDmCommonNotifyEventValid_001, testing::ext::TestSize.Level0)
536+{
537+ DmCommonNotifyEvent dmCommonNotifyEvent = DmCommonNotifyEvent::MAX;
538+ bool ret = IsDmCommonNotifyEventValid(dmCommonNotifyEvent);
539+ EXPECT_FALSE(ret);
540+}
541+ 
542+HWTEST_F(DmAnonymousTest, GetSubscribeId_001, testing::ext::TestSize.Level0)
543+{
544+ std::string pkgName = "12345#pkgName";
545+ uint16_t ret = GetSubscribeId(pkgName);
546+ EXPECT_GE(ret, 0);
547+}
502} // namespace548} // namespace
503} // namespace DistributedHardware549} // namespace DistributedHardware
504} // namespace OHOS550} // namespace OHOS
@@ -25,6 +25,7 @@
25#include "dm_radar_helper.h"25#include "dm_radar_helper.h"
26#include "nlohmann/json.hpp"26#include "nlohmann/json.hpp"
27#include "softbus_error_code.h"27#include "softbus_error_code.h"
28+#include <memory>
28 29 
29static bool g_reportAuthOpenSessionReturnBoolValue = false;30static bool g_reportAuthOpenSessionReturnBoolValue = false;
30static bool g_reportAuthConfirmBoxReturnBoolValue = false;31static bool g_reportAuthConfirmBoxReturnBoolValue = false;
@@ -80,6 +81,8 @@ void DmAuthManagerTest::SetUpTestCase()
80 DmSoftbusSession::dmSoftbusSession = softbusSessionMock_;81 DmSoftbusSession::dmSoftbusSession = softbusSessionMock_;
81 appManagerMock_ = std::make_shared<AppManagerMock>();82 appManagerMock_ = std::make_shared<AppManagerMock>();
82 DmAppManager::dmAppManager = appManagerMock_;83 DmAppManager::dmAppManager = appManagerMock_;
84+ cryptoMock_ = std::make_shared<CryptoMock>();
85+ DmCrypto::dmCrypto = cryptoMock_;
83}86}
84void DmAuthManagerTest::TearDownTestCase()87void DmAuthManagerTest::TearDownTestCase()
85{88{
@@ -87,6 +90,8 @@ void DmAuthManagerTest::TearDownTestCase()
87 softbusSessionMock_ = nullptr;90 softbusSessionMock_ = nullptr;
88 DmAppManager::dmAppManager = nullptr;91 DmAppManager::dmAppManager = nullptr;
89 appManagerMock_ = nullptr;92 appManagerMock_ = nullptr;
93+ DmCrypto::dmCrypto = nullptr;
94+ cryptoMock_ = nullptr;
90}95}
91 96 
92namespace {97namespace {
@@ -262,6 +267,9 @@ HWTEST_F(DmAuthManagerTest, AddMember_002, testing::ext::TestSize.Level0)
262 authManager_->authResponseContext_ = nullptr;267 authManager_->authResponseContext_ = nullptr;
263 int32_t ret = authManager_->AddMember(pinCode);268 int32_t ret = authManager_->AddMember(pinCode);
264 ASSERT_EQ(ret, ERR_DM_FAILED);269 ASSERT_EQ(ret, ERR_DM_FAILED);
270+ authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
271+ std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
272+ authManager_->authUiStateMgr_ = std::make_shared<AuthUiStateManager>(listener);
265 authManager_->isAddingMember_ = true;273 authManager_->isAddingMember_ = true;
266 ret = authManager_->AddMember(pinCode);274 ret = authManager_->AddMember(pinCode);
267 ASSERT_EQ(ret, ERR_DM_FAILED);275 ASSERT_EQ(ret, ERR_DM_FAILED);
@@ -338,13 +346,16 @@ HWTEST_F(DmAuthManagerTest, SetPageId_002, testing::ext::TestSize.Level0)
338 authManager_->authResponseContext_ = nullptr;346 authManager_->authResponseContext_ = nullptr;
339 authManager_->authMessageProcessor_ = nullptr;347 authManager_->authMessageProcessor_ = nullptr;
340 const int32_t sessionId = 65;348 const int32_t sessionId = 65;
341- const std::string message = "messageTest";349+ std::string message = "messageTest";
342 int64_t requestId = 555;350 int64_t requestId = 555;
343 int32_t status = 2;351 int32_t status = 2;
352+ nlohmann::json jsonObject;
353+ jsonObject[TAG_MSG_TYPE] = MSG_TYPE_AUTH_BY_PIN;
344 authManager_->OnMemberJoin(requestId, status);354 authManager_->OnMemberJoin(requestId, status);
345 authManager_->OnDataReceived(sessionId, message);355 authManager_->OnDataReceived(sessionId, message);
346 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();356 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
347 authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();357 authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
358+ message = jsonObject.dump();
348 authManager_->authResponseState_ = nullptr;359 authManager_->authResponseState_ = nullptr;
349 authManager_->OnDataReceived(sessionId, message);360 authManager_->OnDataReceived(sessionId, message);
350 authManager_->authRequestState_ = nullptr;361 authManager_->authRequestState_ = nullptr;
@@ -481,6 +492,13 @@ HWTEST_F(DmAuthManagerTest, AuthenticateDevice_001, testing::ext::TestSize.Level
481 std::string extra = "extraTest";492 std::string extra = "extraTest";
482 int32_t ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);493 int32_t ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
483 ASSERT_EQ(ret, ERR_DM_AUTH_FAILED);494 ASSERT_EQ(ret, ERR_DM_AUTH_FAILED);
495+ 
496+ authType = 0;
497+ nlohmann::json jsonObject;
498+ jsonObject["bindLevel"] = 5;
499+ extra = jsonObject.dump();
500+ ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
501+ ASSERT_EQ(ret, ERR_DM_AUTH_BUSINESS_BUSY);
484}502}
485 503 
486HWTEST_F(DmAuthManagerTest, AuthenticateDevice_002, testing::ext::TestSize.Level0)504HWTEST_F(DmAuthManagerTest, AuthenticateDevice_002, testing::ext::TestSize.Level0)
@@ -1405,6 +1423,11 @@ HWTEST_F(DmAuthManagerTest, StopAuthenticateDevice_001, testing::ext::TestSize.L
1405 authManager_->NegotiateRespMsg(DM_VERSION_4_1_5_1);1423 authManager_->NegotiateRespMsg(DM_VERSION_4_1_5_1);
1406 authManager_->NegotiateRespMsg(DM_VERSION_5_0_2);1424 authManager_->NegotiateRespMsg(DM_VERSION_5_0_2);
1407 EXPECT_CALL(*softbusSessionMock_, GetPeerDeviceId(_, _)).WillOnce(Return(DM_OK));1425 EXPECT_CALL(*softbusSessionMock_, GetPeerDeviceId(_, _)).WillOnce(Return(DM_OK));
1426+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK));
1427+ authManager_->GetPeerUdidHash(sessionId, peerUdidHash);
1428+ 
1429+ EXPECT_CALL(*softbusSessionMock_, GetPeerDeviceId(_, _)).WillOnce(Return(DM_OK));
1430+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED));
1408 authManager_->GetPeerUdidHash(sessionId, peerUdidHash);1431 authManager_->GetPeerUdidHash(sessionId, peerUdidHash);
1409 ret = authManager_->StopAuthenticateDevice(pkgName);1432 ret = authManager_->StopAuthenticateDevice(pkgName);
1410 ASSERT_EQ(ret, DM_OK);1433 ASSERT_EQ(ret, DM_OK);
@@ -1449,6 +1472,10 @@ HWTEST_F(DmAuthManagerTest, GetBindLevel_001, testing::ext::TestSize.Level0)
1449 EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false));1472 EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false));
1450 ret = authManager_->GetBindLevel(bindLevel);1473 ret = authManager_->GetBindLevel(bindLevel);
1451 ASSERT_EQ(ret, SERVICE);1474 ASSERT_EQ(ret, SERVICE);
1475+ 
1476+ EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(true));
1477+ ret = authManager_->GetBindLevel(bindLevel);
1478+ ASSERT_EQ(ret, SERVICE);
1452}1479}
1453 1480 
1454HWTEST_F(DmAuthManagerTest, IsAuthFinish_001, testing::ext::TestSize.Level0)1481HWTEST_F(DmAuthManagerTest, IsAuthFinish_001, testing::ext::TestSize.Level0)
@@ -1488,6 +1515,7 @@ HWTEST_F(DmAuthManagerTest, IsAuthFinish_001, testing::ext::TestSize.Level0)
1488 authManager_->authResponseContext_->isOnline = true;1515 authManager_->authResponseContext_->isOnline = true;
1489 authManager_->authResponseContext_->authed = true;1516 authManager_->authResponseContext_->authed = true;
1490 authManager_->authResponseContext_->importAuthCode = "";1517 authManager_->authResponseContext_->importAuthCode = "";
1518+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)).WillOnce(Return(DM_OK));
1491 authManager_->ProcessAuthRequestExt(sessionId);1519 authManager_->ProcessAuthRequestExt(sessionId);
1492 authManager_->authResponseContext_->reply = ERR_DM_AUTH_BUSINESS_BUSY;1520 authManager_->authResponseContext_->reply = ERR_DM_AUTH_BUSINESS_BUSY;
1493 authManager_->authResponseContext_->isOnline = false;1521 authManager_->authResponseContext_->isOnline = false;
@@ -1496,6 +1524,111 @@ HWTEST_F(DmAuthManagerTest, IsAuthFinish_001, testing::ext::TestSize.Level0)
1496 authManager_->authResponseContext_->isAuthCodeReady = true;1524 authManager_->authResponseContext_->isAuthCodeReady = true;
1497 authManager_->ProcessAuthRequestExt(sessionId);1525 authManager_->ProcessAuthRequestExt(sessionId);
1498}1526}
1527+ 
1528+HWTEST_F(DmAuthManagerTest, RespNegotiate_101, testing::ext::TestSize.Level0)
1529+{
1530+ int64_t requestId = 1;
1531+ authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1532+ authManager_->authResponseContext_->dmVersion = "5.0.2";
1533+ authManager_->authResponseContext_->bindLevel = 1;
1534+ authManager_->RespNegotiate(requestId);
1535+ authManager_->authResponseContext_->dmVersion = "5.0.1";
1536+ authManager_->authResponseContext_->bindLevel = 0;
1537+ authManager_->RespNegotiate(requestId);
1538+ ASSERT_NE(authManager_->authResponseContext_, nullptr);
1539+}
1540+ 
1541+HWTEST_F(DmAuthManagerTest, SendAuthRequest_101, testing::ext::TestSize.Level0)
1542+{
1543+ int64_t sessionId = 1;
1544+ authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1545+ authManager_->authResponseContext_->reply = ERR_DM_VERSION_INCOMPATIBLE;
1546+ authManager_->SendAuthRequest(sessionId);
1547+ 
1548+ authManager_->authResponseContext_->reply = ERR_DM_AUTH_CODE_INCORRECT;
1549+ authManager_->authResponseContext_->bindLevel = 5;
1550+ ASSERT_NE(authManager_->authResponseContext_, nullptr);
1551+}
1552+ 
1553+HWTEST_F(DmAuthManagerTest, AuthDeviceError_007, testing::ext::TestSize.Level0)
1554+{
1555+ authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1556+ authManager_->authResponseState_ = nullptr;
1557+ authManager_->authResponseContext_->requestId = 3;
1558+ authManager_->authTimes_ = 0;
1559+ authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1560+ int64_t requestId = authManager_->authResponseContext_->requestId;
1561+ int32_t errorCode = DM_OK;
1562+ authManager_->AuthDeviceError(requestId, errorCode);
1563+ ASSERT_NE(authManager_->authRequestState_, nullptr);
1564+}
1565+ 
1566+HWTEST_F(DmAuthManagerTest, DeleteGroup_003, testing::ext::TestSize.Level0)
1567+{
1568+ std::string pkgName = "pkgName";
1569+ int32_t userId = 0;
1570+ std::string deviceId;
1571+ int32_t ret = authManager_->DeleteGroup(pkgName, userId, deviceId);
1572+ ASSERT_EQ(ret, ERR_DM_FAILED);
1573+}
1574+ 
1575+HWTEST_F(DmAuthManagerTest, CompatiblePutAcl_004, testing::ext::TestSize.Level0)
1576+{
1577+ authManager_->action_ = USER_OPERATION_TYPE_ALLOW_AUTH;
1578+ authManager_->authRequestState_ = nullptr;
1579+ authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
1580+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK));
1581+ authManager_->CompatiblePutAcl();
1582+ ASSERT_EQ(authManager_->authRequestState_, nullptr);
1583+}
1584+ 
1585+HWTEST_F(DmAuthManagerTest, ProcRespNegotiateExt002, testing::ext::TestSize.Level0)
1586+{
1587+ int32_t sessionId = 0;
1588+ authManager_->authResponseContext_->authed = true;
1589+ authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1590+ authManager_->importAuthCode_ = "importAuthCode_";
1591+ authManager_->ProcRespNegotiateExt(sessionId);
1592+ ASSERT_EQ(authManager_->isAuthDevice_, false);
1593+}
1594+ 
1595+HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived006, testing::ext::TestSize.Level0)
1596+{
1597+ int32_t sessionId = 0;
1598+ nlohmann::json jsonObject;
1599+ jsonObject[TAG_DATA] = "123";
1600+ jsonObject[TAG_DATA_LEN] = 123;
1601+ jsonObject[TAG_MSG_TYPE] = 123;
1602+ std::string message = jsonObject.dump();
1603+ authManager_->authResponseContext_ = nullptr;
1604+ authManager_->OnAuthDeviceDataReceived(sessionId, message);
1605+ ASSERT_EQ(authManager_->isAuthDevice_, false);
1606+}
1607+ 
1608+HWTEST_F(DmAuthManagerTest, GetBinderInfo_001, testing::ext::TestSize.Level0)
1609+{
1610+ authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1611+ authManager_->authResponseContext_->bundleName = "bundleName";
1612+ EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(DM_OK));
1613+ int32_t ret = authManager_->GetBinderInfo();
1614+ ASSERT_EQ(ret, DM_OK);
1615+ 
1616+ EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(ERR_DM_FAILED));
1617+ EXPECT_CALL(*appManagerMock_, GetHapTokenIdByName(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED));
1618+ ret = authManager_->GetBinderInfo();
1619+ ASSERT_EQ(ret, ERR_DM_FAILED);
1620+ 
1621+ EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(ERR_DM_FAILED));
1622+ EXPECT_CALL(*appManagerMock_, GetHapTokenIdByName(_, _, _, _)).WillOnce(Return(DM_OK));
1623+ ret = authManager_->GetBinderInfo();
1624+ ASSERT_EQ(ret, DM_OK);
1625+ 
1626+ authManager_->authResponseContext_->bindLevel = DEVICE;
1627+ authManager_->SetProcessInfo();
1628+ 
1629+ authManager_->authResponseContext_->bindLevel = SERVICE;
1630+ authManager_->SetProcessInfo();
1631+}
1499} // namespace1632} // namespace
1500} // namespace DistributedHardware1633} // namespace DistributedHardware
1501} // namespace OHOS1634} // namespace OHOS
@@ -35,6 +35,7 @@
35#include "dm_auth_manager.h"35#include "dm_auth_manager.h"
36#include "softbus_session_mock.h"36#include "softbus_session_mock.h"
37#include "app_manager_mock.h"37#include "app_manager_mock.h"
38+#include "dm_crypto_mock.h"
38 39 
39namespace OHOS {40namespace OHOS {
40namespace DistributedHardware {41namespace DistributedHardware {
@@ -54,6 +55,7 @@ public:
54 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector);55 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector);
55 static inline std::shared_ptr<SoftbusSessionMock> softbusSessionMock_ = nullptr;56 static inline std::shared_ptr<SoftbusSessionMock> softbusSessionMock_ = nullptr;
56 static inline std::shared_ptr<AppManagerMock> appManagerMock_ = nullptr;57 static inline std::shared_ptr<AppManagerMock> appManagerMock_ = nullptr;
58+ static inline std::shared_ptr<CryptoMock> cryptoMock_ = nullptr;
57};59};
58 60 
59class AuthRequestFinishStateMock : public AuthRequestFinishState {61class AuthRequestFinishStateMock : public AuthRequestFinishState {
@@ -39,6 +39,7 @@ void DmAuthManagerTest::SetUp()
39 authManager_ = std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector);39 authManager_ = std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector);
40 authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);40 authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
41 authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();41 authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
42+ authManager_->authMessageProcessor_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
42 authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();43 authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
43 authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();44 authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
44 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();45 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
@@ -63,6 +64,10 @@ void DmAuthManagerTest::SetUpTestCase()
63 DmSoftbusConnector::dmSoftbusConnector = softbusConnectorMock_;64 DmSoftbusConnector::dmSoftbusConnector = softbusConnectorMock_;
64 hiChainAuthConnectorMock_ = std::make_shared<HiChainAuthConnectorMock>();65 hiChainAuthConnectorMock_ = std::make_shared<HiChainAuthConnectorMock>();
65 DmHiChainAuthConnector::dmHiChainAuthConnector = hiChainAuthConnectorMock_;66 DmHiChainAuthConnector::dmHiChainAuthConnector = hiChainAuthConnectorMock_;
67+ deviceProfileConnectorMock_ = std::make_shared<DeviceProfileConnectorMock>();
68+ DmDeviceProfileConnector::dmDeviceProfileConnector = deviceProfileConnectorMock_;
69+ cryptoMock_ = std::make_shared<CryptoMock>();
70+ DmCrypto::dmCrypto = cryptoMock_;
66}71}
67void DmAuthManagerTest::TearDownTestCase()72void DmAuthManagerTest::TearDownTestCase()
68{73{
@@ -74,6 +79,10 @@ void DmAuthManagerTest::TearDownTestCase()
74 softbusConnectorMock_ = nullptr;79 softbusConnectorMock_ = nullptr;
75 DmHiChainAuthConnector::dmHiChainAuthConnector = nullptr;80 DmHiChainAuthConnector::dmHiChainAuthConnector = nullptr;
76 hiChainAuthConnectorMock_ = nullptr;81 hiChainAuthConnectorMock_ = nullptr;
82+ DmDeviceProfileConnector::dmDeviceProfileConnector = nullptr;
83+ deviceProfileConnectorMock_ = nullptr;
84+ DmCrypto::dmCrypto = nullptr;
85+ cryptoMock_ = nullptr;
77}86}
78 87 
79namespace {88namespace {
@@ -1476,13 +1485,13 @@ HWTEST_F(DmAuthManagerTest, IsIdenticalAccount_201, testing::ext::TestSize.Level
1476 ret = authManager_->IsIdenticalAccount();1485 ret = authManager_->IsIdenticalAccount();
1477 ASSERT_FALSE(ret);1486 ASSERT_FALSE(ret);
1478 1487 
1479- authManager_->authRequestContext_ = nullptr;1488+ authManager_->authResponseContext_ = nullptr;
1480 EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0));1489 EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0));
1481 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));1490 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));
1482 ret = authManager_->IsIdenticalAccount();1491 ret = authManager_->IsIdenticalAccount();
1483 ASSERT_FALSE(ret);1492 ASSERT_FALSE(ret);
1484 1493 
1485- authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();1494+ authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1486 authManager_->authResponseContext_->accountGroupIdHash = OLD_VERSION_ACCOUNT;1495 authManager_->authResponseContext_->accountGroupIdHash = OLD_VERSION_ACCOUNT;
1487 EXPECT_CALL(*multipleUserConnectorMock_,1496 EXPECT_CALL(*multipleUserConnectorMock_,
1488 GetCurrentAccountUserID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0));1497 GetCurrentAccountUserID()).WillOnce(Return(0)).WillOnce(Return(0)).WillOnce(Return(0));
@@ -1512,6 +1521,7 @@ HWTEST_F(DmAuthManagerTest, IsIdenticalAccount_201, testing::ext::TestSize.Level
1512 authManager_->authResponseContext_->accountGroupIdHash = SafetyDump(jsonPeerGroupIdObj);1521 authManager_->authResponseContext_->accountGroupIdHash = SafetyDump(jsonPeerGroupIdObj);
1513 EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0));1522 EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0));
1514 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));1523 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));
1524+ EXPECT_CALL(*cryptoMock_, GetGroupIdHash(_)).WillOnce(Return("123"));
1515 ret = authManager_->IsIdenticalAccount();1525 ret = authManager_->IsIdenticalAccount();
1516 ASSERT_FALSE(ret);1526 ASSERT_FALSE(ret);
1517}1527}
@@ -1526,6 +1536,23 @@ HWTEST_F(DmAuthManagerTest, GetAccountGroupIdHash_201, testing::ext::TestSize.Le
1526 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));1536 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));
1527 ret = authManager_->GetAccountGroupIdHash();1537 ret = authManager_->GetAccountGroupIdHash();
1528 ASSERT_FALSE(ret.empty());1538 ASSERT_FALSE(ret.empty());
1539+ 
1540+ std::vector<GroupInfo> groupList;
1541+ GroupInfo groupInfo;
1542+ groupInfo.groupId = "123456";
1543+ groupInfo.groupName = "group101";
1544+ groupInfo.groupType = 1;
1545+ groupList.push_back(groupInfo);
1546+ nlohmann::json jsonPeerGroupIdObj;
1547+ jsonPeerGroupIdObj["groupId"] = "123456";
1548+ authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1549+ authManager_->authResponseContext_->accountGroupIdHash = jsonPeerGroupIdObj.dump();
1550+ EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0));
1551+ EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _))
1552+ .WillOnce(DoAll(SetArgReferee<2>(groupList), Return(true)));
1553+ EXPECT_CALL(*cryptoMock_, GetGroupIdHash(_)).WillOnce(Return("123456"));
1554+ bool rets = authManager_->IsIdenticalAccount();
1555+ ASSERT_FALSE(rets);
1529}1556}
1530 1557 
1531HWTEST_F(DmAuthManagerTest, CheckTrustState_003, testing::ext::TestSize.Level0)1558HWTEST_F(DmAuthManagerTest, CheckTrustState_003, testing::ext::TestSize.Level0)
@@ -1537,6 +1564,91 @@ HWTEST_F(DmAuthManagerTest, CheckTrustState_003, testing::ext::TestSize.Level0)
1537 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));1564 EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));
1538 int32_t ret = authManager_->CheckTrustState();1565 int32_t ret = authManager_->CheckTrustState();
1539 ASSERT_EQ(ret, 1);1566 ASSERT_EQ(ret, 1);
1567+ 
1568+ int32_t sessionId = 1;
1569+ authManager_->authResponseContext_->authType = AUTH_TYPE_PIN;
1570+ authManager_->authResponseContext_->isOnline = true;
1571+ EXPECT_CALL(*softbusConnectorMock_, CheckIsOnline(_)).Times(::testing::AtLeast(2)).WillOnce(Return(true));
1572+ EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0));
1573+ EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true));
1574+ authManager_->ProcessAuthRequest(sessionId);
1575+ 
1576+ authManager_->authResponseContext_->haveCredential = true;
1577+ EXPECT_CALL(*hiChainAuthConnectorMock_, QueryCredential(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(true));
1578+ authManager_->GetAuthRequestContext();
1579+ 
1580+ authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1581+ authManager_->authResponseContext_->importAuthCode = "";
1582+ std::vector<int32_t> bindType;
1583+ bindType.push_back(101);
1584+ bindType.push_back(102);
1585+ EXPECT_CALL(*deviceProfileConnectorMock_, SyncAclByBindType(_, _, _, _)).WillOnce(Return(bindType));
1586+ authManager_->ProcessAuthRequestExt(sessionId);
1587+}
1588+ 
1589+HWTEST_F(DmAuthManagerTest, DeleteGroup_201, testing::ext::TestSize.Level0)
1590+{
1591+ std::string pkgName = "pkgName";
1592+ std::string deviceId;
1593+ std::vector<GroupInfo> groupList;
1594+ GroupInfo groupInfo;
1595+ groupInfo.groupId = "123456";
1596+ groupList.push_back(groupInfo);
1597+ EXPECT_CALL(*hiChainConnectorMock_, GetRelatedGroups(_, _))
1598+ .WillOnce(DoAll(SetArgReferee<1>(groupList), Return(DM_OK)));
1599+ EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0));
1600+ int32_t ret = authManager_->DeleteGroup(pkgName, deviceId);
1601+ ASSERT_EQ(ret, DM_OK);
1602+}
1603+ 
1604+HWTEST_F(DmAuthManagerTest, DeleteGroup_202, testing::ext::TestSize.Level0)
1605+{
1606+ std::string pkgName;
1607+ int32_t userId = 0;
1608+ std::string deviceId;
1609+ int32_t ret = authManager_->DeleteGroup(pkgName, userId, deviceId);
1610+ ASSERT_EQ(ret, ERR_DM_FAILED);
1611+
1612+ pkgName = "pkgName";
1613+ std::vector<GroupInfo> groupList;
1614+ GroupInfo groupInfo;
1615+ groupInfo.groupId = "123456";
1616+ groupList.push_back(groupInfo);
1617+ GroupInfo groupInfo1;
1618+ groupInfo1.groupId = "12345";
1619+ groupList.push_back(groupInfo1);
1620+ EXPECT_CALL(*hiChainConnectorMock_, GetRelatedGroups(_, _, _))
1621+ .WillOnce(DoAll(SetArgReferee<2>(groupList), Return(DM_OK)));
1622+ ret = authManager_->DeleteGroup(pkgName, userId, deviceId);
1623+ ASSERT_EQ(ret, DM_OK);
1624+}
1625+ 
1626+HWTEST_F(DmAuthManagerTest, ParseConnectAddr_201, testing::ext::TestSize.Level0)
1627+{
1628+ PeerTargetId targetId;
1629+ targetId.wifiIp = "12131415";
1630+ targetId.brMac = "D4G4E5G2B4G";
1631+ targetId.bleMac = "1463158131321";
1632+ std::string deviceId;
1633+ std::string addrType;
1634+ int32_t ret = authManager_->ParseConnectAddr(targetId, deviceId, addrType);
1635+ ASSERT_EQ(ret, DM_OK);
1636+}
1637+ 
1638+HWTEST_F(DmAuthManagerTest, ParseConnectAddr_202, testing::ext::TestSize.Level0)
1639+{
1640+ PeerTargetId targetId;
1641+ targetId.wifiIp;
1642+ targetId.brMac = "D4G4E5G2B4G";
1643+ targetId.bleMac = "1463158131321";
1644+ std::string deviceId;
1645+ std::string addrType;
1646+ int32_t ret = authManager_->ParseConnectAddr(targetId, deviceId, addrType);
1647+ ASSERT_EQ(ret, DM_OK);
1648+ 
1649+ targetId.brMac = "";
1650+ ret = authManager_->ParseConnectAddr(targetId, deviceId, addrType);
1651+ ASSERT_EQ(ret, DM_OK);
1540}1652}
1541} // namespace1653} // namespace
1542} // namespace DistributedHardware1654} // namespace DistributedHardware
@@ -37,6 +37,8 @@
37#include "multiple_user_connector_mock.h"37#include "multiple_user_connector_mock.h"
38#include "softbus_connector_mock.h"38#include "softbus_connector_mock.h"
39#include "hichain_auth_connector_mock.h"39#include "hichain_auth_connector_mock.h"
40+#include "deviceprofile_connector_mock.h"
41+#include "dm_crypto_mock.h"
40 42 
41namespace OHOS {43namespace OHOS {
42namespace DistributedHardware {44namespace DistributedHardware {
@@ -52,6 +54,8 @@ public:
52 static inline std::shared_ptr<MultipleUserConnectorMock> multipleUserConnectorMock_ = nullptr;54 static inline std::shared_ptr<MultipleUserConnectorMock> multipleUserConnectorMock_ = nullptr;
53 static inline std::shared_ptr<SoftbusConnectorMock> softbusConnectorMock_ = nullptr;55 static inline std::shared_ptr<SoftbusConnectorMock> softbusConnectorMock_ = nullptr;
54 static inline std::shared_ptr<HiChainAuthConnectorMock> hiChainAuthConnectorMock_ = nullptr;56 static inline std::shared_ptr<HiChainAuthConnectorMock> hiChainAuthConnectorMock_ = nullptr;
57+ static inline std::shared_ptr<DeviceProfileConnectorMock> deviceProfileConnectorMock_ = nullptr;
58+ static inline std::shared_ptr<CryptoMock> cryptoMock_ = nullptr;
55};59};
56 60 
57class AuthResponseInitStateMock : public AuthResponseInitState {61class AuthResponseInitStateMock : public AuthResponseInitState {
@@ -563,7 +563,7 @@ HWTEST_F(DeviceProfileConnectorTest, GetDeviceAclParam_001, testing::ext::TestSi
563 DmDiscoveryInfo discoveryInfo;563 DmDiscoveryInfo discoveryInfo;
564 bool isonline = true;564 bool isonline = true;
565 int32_t authForm = 0;565 int32_t authForm = 0;
566- EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(30)).WillOnce(Return(DM_OK));566+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(38)).WillOnce(Return(DM_OK));
567 int32_t ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);567 int32_t ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);
568 EXPECT_EQ(ret, DM_OK);568 EXPECT_EQ(ret, DM_OK);
569}569}
@@ -1188,6 +1188,11 @@ HWTEST_F(DeviceProfileConnectorTest, GetAuthForm_001, testing::ext::TestSize.Lev
1188 profile.SetBindType(INVALIED_TYPE);1188 profile.SetBindType(INVALIED_TYPE);
1189 ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev);1189 ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev);
1190 EXPECT_EQ(ret, INVALIED_TYPE);1190 EXPECT_EQ(ret, INVALIED_TYPE);
1191+ 
1192+ profile.SetBindType(DM_POINT_TO_POINT);
1193+ profile.SetBindLevel(APP);
1194+ ret = DeviceProfileConnector::GetInstance().GetAuthForm(profile, trustDev, reqDev);
1195+ EXPECT_EQ(ret, APP_PEER_TO_PEER_TYPE);
1191}1196}
1192 1197 
1193HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_001, testing::ext::TestSize.Level0)1198HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_001, testing::ext::TestSize.Level0)
@@ -1414,9 +1419,9 @@ HWTEST_F(DeviceProfileConnectorTest, DeleteServiceBindLevel_001, testing::ext::T
1414HWTEST_F(DeviceProfileConnectorTest, CheckSrcDevIdInAclForDevBind_004, testing::ext::TestSize.Level0)1419HWTEST_F(DeviceProfileConnectorTest, CheckSrcDevIdInAclForDevBind_004, testing::ext::TestSize.Level0)
1415{1420{
1416 std::string pkgName = "bundleName";1421 std::string pkgName = "bundleName";
1417- std::string deviceId = "remoteDeviceId";1422+ std::string deviceId = "localDeviceId";
1418 bool ret = DeviceProfileConnector::GetInstance().CheckSrcDevIdInAclForDevBind(pkgName, deviceId);1423 bool ret = DeviceProfileConnector::GetInstance().CheckSrcDevIdInAclForDevBind(pkgName, deviceId);
1419- EXPECT_FALSE(ret);1424+ EXPECT_TRUE(ret);
1420}1425}
1421 1426 
1422HWTEST_F(DeviceProfileConnectorTest, DeleteTimeOutAcl_002, testing::ext::TestSize.Level0)1427HWTEST_F(DeviceProfileConnectorTest, DeleteTimeOutAcl_002, testing::ext::TestSize.Level0)
@@ -1556,6 +1561,13 @@ HWTEST_F(DeviceProfileConnectorTest, DeleteAclForAccountLogOut_001, testing::ext
1556 peerUserId = 123456;1561 peerUserId = 123456;
1557 ret = DeviceProfileConnector::GetInstance().DeleteAclForAccountLogOut(localUdid, localUserId, peerUdid, peerUserId);1562 ret = DeviceProfileConnector::GetInstance().DeleteAclForAccountLogOut(localUdid, localUserId, peerUdid, peerUserId);
1558 EXPECT_FALSE(ret);1563 EXPECT_FALSE(ret);
1564+ 
1565+ localUdid = "remoteDeviceId";
1566+ localUserId = 1234;
1567+ peerUdid = "localDeviceId";
1568+ peerUserId = 1234;
1569+ ret = DeviceProfileConnector::GetInstance().DeleteAclForAccountLogOut(localUdid, localUserId, peerUdid, peerUserId);
1570+ EXPECT_TRUE(ret);
1559}1571}
1560 1572 
1561HWTEST_F(DeviceProfileConnectorTest, GetProcessInfoFromAclByUserId_005, testing::ext::TestSize.Level0)1573HWTEST_F(DeviceProfileConnectorTest, GetProcessInfoFromAclByUserId_005, testing::ext::TestSize.Level0)
@@ -1672,6 +1684,11 @@ HWTEST_F(DeviceProfileConnectorTest, GetUserIdAndBindLevel_001, testing::ext::Te
1672 ret = DeviceProfileConnector::GetInstance().GetUserIdAndBindLevel(localUdid, peerUdid);1684 ret = DeviceProfileConnector::GetInstance().GetUserIdAndBindLevel(localUdid, peerUdid);
1673 EXPECT_FALSE(ret.empty());1685 EXPECT_FALSE(ret.empty());
1674 1686 
1687+ localUdid = "remoteDeviceIdee";
1688+ peerUdid = "localDeviceIder";
1689+ ret = DeviceProfileConnector::GetInstance().GetUserIdAndBindLevel(localUdid, peerUdid);
1690+ EXPECT_FALSE(ret.empty());
1691+ 
1675 int32_t userId = 123456;1692 int32_t userId = 123456;
1676 std::vector<int32_t> localUserIds;1693 std::vector<int32_t> localUserIds;
1677 localUserIds.push_back(userId);1694 localUserIds.push_back(userId);
@@ -1750,10 +1767,30 @@ HWTEST_F(DeviceProfileConnectorTest, GetAppTrustDeviceList_004, testing::ext::Te
1750 auto ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);1767 auto ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);
1751 EXPECT_EQ(ret.empty(), false);1768 EXPECT_EQ(ret.empty(), false);
1752 1769 
1753- deviceId = "deviceIder001";1770+ deviceId = "remoteDeviceId";
1754- EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(123456));1771+ EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234));
1755 ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);1772 ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);
1756- EXPECT_EQ(ret.empty(), true);1773+ EXPECT_EQ(ret.empty(), false);
1774+ 
1775+ deviceId = "remoteDeviceId";
1776+ EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234));
1777+ ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);
1778+ EXPECT_EQ(ret.empty(), false);
1779+ 
1780+ deviceId = "remoteDeviceId";
1781+ EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(1234));
1782+ ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);
1783+ EXPECT_EQ(ret.empty(), false);
1784+ 
1785+ deviceId = "remoteDeviceId";
1786+ EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(12345));
1787+ ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);
1788+ EXPECT_EQ(ret.empty(), false);
1789+ 
1790+ deviceId = "remoteDeviceId";
1791+ EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(12345));
1792+ ret = DeviceProfileConnector::GetInstance().GetAppTrustDeviceList(pkgName, deviceId);
1793+ EXPECT_EQ(ret.empty(), false);
1757 1794 
1758 std::string udid;1795 std::string udid;
1759 DeviceProfileConnector::GetInstance().DeleteAccessControlList(udid);1796 DeviceProfileConnector::GetInstance().DeleteAccessControlList(udid);
@@ -1801,13 +1838,18 @@ HWTEST_F(DeviceProfileConnectorTest, GetDeviceAclParam_002, testing::ext::TestSi
1801 discoveryInfo.pkgname = "";1838 discoveryInfo.pkgname = "";
1802 bool isonline = true;1839 bool isonline = true;
1803 int32_t authForm = 0;1840 int32_t authForm = 0;
1804- EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(30)).WillOnce(Return(DM_OK));1841+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(38)).WillOnce(Return(DM_OK));
1805 int32_t ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);1842 int32_t ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);
1806 EXPECT_EQ(ret, DM_OK);1843 EXPECT_EQ(ret, DM_OK);
1807 1844 
1808 discoveryInfo.pkgname = "bundleName";1845 discoveryInfo.pkgname = "bundleName";
1809 discoveryInfo.localDeviceId = "deviceId";1846 discoveryInfo.localDeviceId = "deviceId";
1810- EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(30)).WillOnce(Return(DM_OK));1847+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(38)).WillOnce(Return(DM_OK));
1848+ ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);
1849+ EXPECT_EQ(ret, DM_OK);
1850+ 
1851+ discoveryInfo.localDeviceId = "trustDeviceId";
1852+ EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(38)).WillOnce(Return(DM_OK));
1811 ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);1853 ret = DeviceProfileConnector::GetInstance().GetDeviceAclParam(discoveryInfo, isonline, authForm);
1812 EXPECT_EQ(ret, DM_OK);1854 EXPECT_EQ(ret, DM_OK);
1813}1855}
@@ -1815,9 +1857,9 @@ HWTEST_F(DeviceProfileConnectorTest, GetDeviceAclParam_002, testing::ext::TestSi
1815HWTEST_F(DeviceProfileConnectorTest, CheckSinkDevIdInAclForDevBind_004, testing::ext::TestSize.Level0)1857HWTEST_F(DeviceProfileConnectorTest, CheckSinkDevIdInAclForDevBind_004, testing::ext::TestSize.Level0)
1816{1858{
1817 std::string pkgName = "bundleName";1859 std::string pkgName = "bundleName";
1818- std::string deviceId = "123456";1860+ std::string deviceId = "localDeviceId";
1819 bool ret = DeviceProfileConnector::GetInstance().CheckSinkDevIdInAclForDevBind(pkgName, deviceId);1861 bool ret = DeviceProfileConnector::GetInstance().CheckSinkDevIdInAclForDevBind(pkgName, deviceId);
1820- EXPECT_EQ(ret, false);1862+ EXPECT_EQ(ret, true);
1821}1863}
1822 1864 
1823HWTEST_F(DeviceProfileConnectorTest, CheckSrcDevIdInAclForDevBind_005, testing::ext::TestSize.Level0)1865HWTEST_F(DeviceProfileConnectorTest, CheckSrcDevIdInAclForDevBind_005, testing::ext::TestSize.Level0)
@@ -1930,5 +1972,14 @@ HWTEST_F(DeviceProfileConnectorTest, PutAllTrustedDevices_001, testing::ext::Tes
1930 int32_t ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);1972 int32_t ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);
1931 EXPECT_NE(ret, DM_OK);1973 EXPECT_NE(ret, DM_OK);
1932}1974}
1975+ 
1976+HWTEST_F(DeviceProfileConnectorTest, CheckBindType_004, testing::ext::TestSize.Level0)
1977+{
1978+ std::string peerUdid = "localDeviceId";
1979+ std::string localUdid = "remoteDeviceId";
1980+ EXPECT_CALL(*multipleUserConnectorMock_, GetFirstForegroundUserId()).WillOnce(Return(0));
1981+ uint32_t ret = DeviceProfileConnector::GetInstance().CheckBindType(peerUdid, localUdid);
1982+ EXPECT_EQ(ret, IDENTICAL_ACCOUNT_TYPE);
1983+}
1933} // namespace DistributedHardware1984} // namespace DistributedHardware
1934} // namespace OHOS1985} // namespace OHOS
@@ -18,6 +18,7 @@
18#include "dm_constants.h"18#include "dm_constants.h"
19#include "deviceprofile_connector.h"19#include "deviceprofile_connector.h"
20#include <iterator>20#include <iterator>
21+#include "dp_inited_callback_stub.h"
21 22 
22using namespace testing;23using namespace testing;
23using namespace testing::ext;24using namespace testing::ext;
@@ -43,6 +44,20 @@ void DeviceProfileConnectorSecondTest::TearDownTestCase()
43 distributedDeviceProfileClientMock_ = nullptr;44 distributedDeviceProfileClientMock_ = nullptr;
44}45}
45 46 
47+class DpInitedCallback : public DistributedDeviceProfile::DpInitedCallbackStub {
48+public:
49+ DpInitedCallback()
50+ {
51+ }
52+ ~DpInitedCallback()
53+ {
54+ }
55+ int32_t OnDpInited()
56+ {
57+ return 0;
58+ }
59+};
60+ 
46void AddAccessControlProfile(std::vector<DistributedDeviceProfile::AccessControlProfile>& accessControlProfiles)61void AddAccessControlProfile(std::vector<DistributedDeviceProfile::AccessControlProfile>& accessControlProfiles)
47{62{
48 int32_t userId = 123456;63 int32_t userId = 123456;
@@ -403,5 +418,50 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUserId_002, testing::ex
403 auto result = connector.GetDeviceIdAndUserId("", 0);418 auto result = connector.GetDeviceIdAndUserId("", 0);
404 EXPECT_EQ(result.size(), 0);419 EXPECT_EQ(result.size(), 0);
405}420}
421+ 
422+HWTEST_F(DeviceProfileConnectorSecondTest, SubscribeDeviceProfileInited_201, testing::ext::TestSize.Level0)
423+{
424+ OHOS::sptr<DistributedDeviceProfile::IDpInitedCallback> dpInitedCallback = nullptr;
425+ int32_t ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
426+ EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
427+ 
428+ dpInitedCallback = sptr<DistributedDeviceProfile::IDpInitedCallback>(new DpInitedCallback());
429+ EXPECT_CALL(*distributedDeviceProfileClientMock_, SubscribeDeviceProfileInited(_, _))
430+ .WillOnce(Return(ERR_DM_FAILED));
431+ ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
432+ EXPECT_EQ(ret, ERR_DM_FAILED);
433+ 
434+ EXPECT_CALL(*distributedDeviceProfileClientMock_, SubscribeDeviceProfileInited(_, _))
435+ .WillOnce(Return(DM_OK));
436+ ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
437+ EXPECT_EQ(ret, DM_OK);
438+}
439+ 
440+HWTEST_F(DeviceProfileConnectorSecondTest, UnSubscribeDeviceProfileInited_201, testing::ext::TestSize.Level0)
441+{
442+ EXPECT_CALL(*distributedDeviceProfileClientMock_, UnSubscribeDeviceProfileInited(_))
443+ .WillOnce(Return(ERR_DM_FAILED));
444+ int32_t ret = DeviceProfileConnector::GetInstance().UnSubscribeDeviceProfileInited();
445+ EXPECT_EQ(ret, ERR_DM_FAILED);
446+ 
447+ EXPECT_CALL(*distributedDeviceProfileClientMock_, UnSubscribeDeviceProfileInited(_))
448+ .WillOnce(Return(DM_OK));
449+ ret = DeviceProfileConnector::GetInstance().UnSubscribeDeviceProfileInited();
450+ EXPECT_EQ(ret, DM_OK);
451+}
452+ 
453+HWTEST_F(DeviceProfileConnectorSecondTest, PutAllTrustedDevices_201, testing::ext::TestSize.Level0)
454+{
455+ std::vector<DistributedDeviceProfile::TrustedDeviceInfo> deviceInfos;
456+ EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAllTrustedDevices(_))
457+ .WillOnce(Return(ERR_DM_FAILED));
458+ int32_t ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);
459+ EXPECT_EQ(ret, ERR_DM_FAILED);
460+ 
461+ EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAllTrustedDevices(_))
462+ .WillOnce(Return(DM_OK));
463+ ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);
464+ EXPECT_EQ(ret, DM_OK);
465+}
406} // namespace DistributedHardware466} // namespace DistributedHardware
407} // namespace OHOS467} // namespace OHOS
@@ -26,6 +26,7 @@ group("unittest") {
26 ":UTTest_device_manager_notify",26 ":UTTest_device_manager_notify",
27 ":UTTest_device_manager_service",27 ":UTTest_device_manager_service",
28 ":UTTest_device_manager_service_impl",28 ":UTTest_device_manager_service_impl",
29+ ":UTTest_device_manager_service_impl_first",
29 ":UTTest_device_manager_service_listener",30 ":UTTest_device_manager_service_listener",
30 ":UTTest_device_manager_service_three",31 ":UTTest_device_manager_service_three",
31 ":UTTest_discovery_filter",32 ":UTTest_discovery_filter",
@@ -335,6 +336,7 @@ ohos_unittest("UTTest_device_manager_service") {
335 "mock/dm_crypto_mock.cpp",336 "mock/dm_crypto_mock.cpp",
336 "mock/dm_softbus_cache_mock.cpp",337 "mock/dm_softbus_cache_mock.cpp",
337 "mock/kv_adapter_manager_mock.cpp",338 "mock/kv_adapter_manager_mock.cpp",
339+ "mock/multiple_user_connector_mock.cpp",
338 "mock/permission_manager_mock.cpp",340 "mock/permission_manager_mock.cpp",
339 "mock/softbus_listener_mock.cpp",341 "mock/softbus_listener_mock.cpp",
340 ]342 ]
@@ -1039,6 +1041,33 @@ ohos_unittest("UTTest_device_manager_service_impl") {
1039 1041 
1040## UnitTest UTTest_device_manager_service_impl }}}1042## UnitTest UTTest_device_manager_service_impl }}}
1041 1043 
1044+## UnitTest UTTest_device_manager_service_impl_first {{{
1045+ohos_unittest("UTTest_device_manager_service_impl_first") {
1046+ module_out_path = module_out_path
1047+ 
1048+ sources = [
1049+ "${servicesimpl_path}/src/device_manager_service_impl.cpp",
1050+ "UTTest_device_manager_service_impl_first.cpp",
1051+ "mock/deviceprofile_connector_mock.cpp",
1052+ "mock/multiple_user_connector_mock.cpp",
1053+ ]
1054+ 
1055+ deps = [ ":device_manager_test_common" ]
1056+ 
1057+ external_deps = [
1058+ "device_auth:deviceauth_sdk",
1059+ "device_info_manager:distributed_device_profile_common",
1060+ "device_info_manager:distributed_device_profile_sdk",
1061+ "ffrt:libffrt",
1062+ "googletest:gmock",
1063+ "googletest:gmock_main",
1064+ "os_account:libaccountkits",
1065+ "os_account:os_account_innerkits",
1066+ ]
1067+}
1068+ 
1069+## UnitTest UTTest_device_manager_service_impl_first }}}
1070+ 
1042## UnitTest UTTest_device_manager_service_listener {{{1071## UnitTest UTTest_device_manager_service_listener {{{
1043ohos_unittest("UTTest_device_manager_service_listener") {1072ohos_unittest("UTTest_device_manager_service_listener") {
1044 module_out_path = module_out_path1073 module_out_path = module_out_path
@@ -1139,6 +1168,7 @@ ohos_unittest("UTTest_dm_auth_manager_first") {
1139 sources = [1168 sources = [
1140 "${devicemanager_path}/test/commonunittest/UTTest_dm_auth_manager_first.cpp",1169 "${devicemanager_path}/test/commonunittest/UTTest_dm_auth_manager_first.cpp",
1141 "mock/app_manager_mock.cpp",1170 "mock/app_manager_mock.cpp",
1171+ "mock/dm_crypto_mock.cpp",
1142 "mock/softbus_session_mock.cpp",1172 "mock/softbus_session_mock.cpp",
1143 ]1173 ]
1144 1174 
@@ -1173,6 +1203,7 @@ ohos_unittest("UTTest_dm_auth_manager_second") {
1173 1203 
1174 sources = [1204 sources = [
1175 "${devicemanager_path}/test/commonunittest/UTTest_dm_auth_manager_second.cpp",1205 "${devicemanager_path}/test/commonunittest/UTTest_dm_auth_manager_second.cpp",
1206+ "mock/deviceprofile_connector_mock.cpp",
1176 "mock/hichain_auth_connector_mock.cpp",1207 "mock/hichain_auth_connector_mock.cpp",
1177 "mock/hichain_connector_mock.cpp",1208 "mock/hichain_connector_mock.cpp",
1178 "mock/multiple_user_connector_mock.cpp",1209 "mock/multiple_user_connector_mock.cpp",
@@ -23,6 +23,7 @@
23#include "softbus_session.h"23#include "softbus_session.h"
24#include "dm_auth_manager.h"24#include "dm_auth_manager.h"
25#include "device_manager_service_listener.h"25#include "device_manager_service_listener.h"
26+#include "auth_ui_state_manager.h"
26 27 
27namespace OHOS {28namespace OHOS {
28namespace DistributedHardware {29namespace DistributedHardware {
@@ -1645,6 +1646,19 @@ HWTEST_F(AuthMessageProcessorTest, CreateDeviceAuthMessage_001, testing::ext::Te
1645 std::string str = "1324213";1646 std::string str = "1324213";
1646 std::string ret = authMessageProcessor->CreateDeviceAuthMessage(msgType, &param, dataLen);1647 std::string ret = authMessageProcessor->CreateDeviceAuthMessage(msgType, &param, dataLen);
1647 ASSERT_EQ(ret.empty(), false);1648 ASSERT_EQ(ret.empty(), false);
1649+ 
1650+ std::shared_ptr<DeviceManagerServiceListener> listener_ = nullptr;
1651+ std::shared_ptr<AuthUiStateManager> authUiStateManager = std::make_shared<AuthUiStateManager>(listener_);
1652+ DmUiStateMsg msg = DmUiStateMsg::MSG_PIN_CODE_SUCCESS;
1653+ authUiStateManager->UpdateUiState(msg);
1654+ 
1655+ listener_ = std::make_shared<DeviceManagerServiceListener>();
1656+ std::shared_ptr<AuthUiStateManager> authUiStateManager_ = std::make_shared<AuthUiStateManager>(listener_);
1657+ ProcessInfo processInfo;
1658+ processInfo.pkgName = "pkgName";
1659+ processInfo.userId = 123456;
1660+ authUiStateManager_->pkgSet_.insert(processInfo);
1661+ authUiStateManager_->UpdateUiState(msg);
1648}1662}
1649} // namespace1663} // namespace
1650} // namespace DistributedHardware1664} // namespace DistributedHardware
@@ -262,17 +262,25 @@ HWTEST_F(DeviceManagerServiceTest, UnPublishDeviceDiscovery_004, testing::ext::T
262 int32_t preUserId = 3;262 int32_t preUserId = 3;
263 std::vector<std::string> peerUdids;263 std::vector<std::string> peerUdids;
264 std::string accountName = "openharmony123";264 std::string accountName = "openharmony123";
265+ std::map<std::string, int32_t> curUserDeviceMap;
266+ std::map<std::string, int32_t> preUserDeviceMap;
265 std::string commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED;267 std::string commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED;
268+ EXPECT_CALL(*deviceManagerServiceImplMock_,
269+ GetDeviceIdAndBindLevel(_)).WillOnce(Return(curUserDeviceMap)).WillOnce(Return(preUserDeviceMap));
266 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);270 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);
267 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN;271 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN;
272+ DMAccountInfo dmAccountInfo;
268 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);273 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);
269 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT;274 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT;
275+ EXPECT_CALL(*multipleUserConnectorMock_, GetAccountInfoByUserId(_)).WillOnce(Return(dmAccountInfo));
270 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);276 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);
271 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED;277 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED;
278+ EXPECT_CALL(*deviceManagerServiceImplMock_, GetDeviceIdAndBindLevel(_)).WillOnce(Return(curUserDeviceMap));
272 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);279 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);
273 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED;280 commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED;
274 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);281 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, preUserId);
275 DeviceManagerService::GetInstance().HandleAccountLogout(userId, accountId, pkgName);282 DeviceManagerService::GetInstance().HandleAccountLogout(userId, accountId, pkgName);
283+ EXPECT_CALL(*deviceManagerServiceImplMock_, GetDeviceIdAndBindLevel(_)).WillOnce(Return(curUserDeviceMap));
276 DeviceManagerService::GetInstance().HandleUserRemoved(preUserId);284 DeviceManagerService::GetInstance().HandleUserRemoved(preUserId);
277 DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();285 DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();
278 DeviceManagerService::GetInstance().SendAccountLogoutBroadCast(peerUdids, accountId, accountName, userId);286 DeviceManagerService::GetInstance().SendAccountLogoutBroadCast(peerUdids, accountId, accountName, userId);
@@ -358,12 +358,22 @@ HWTEST_F(DeviceManagerServiceImplTest, NotifyEvent_005, testing::ext::TestSize.L
358 int32_t remoteUserId = 1;358 int32_t remoteUserId = 1;
359 std::string remoteAccountHash = "45552878";359 std::string remoteAccountHash = "45552878";
360 std::string remoteUdid = "ajdakndkwj98877";360 std::string remoteUdid = "ajdakndkwj98877";
361- EXPECT_CALL(*deviceProfileConnectorMock_,361+ std::multimap<std::string, int32_t> devIdAndUserMap;
362- HandleAccountLogoutEvent(_, _, _, _)).WillOnce(Return(DM_INVALIED_BINDTYPE));362+ devIdAndUserMap.insert(std::make_pair("devId01", 101));
363- deviceManagerServiceImpl_->HandleAccountLogoutEvent(remoteUserId, remoteAccountHash, remoteUdid);363+ devIdAndUserMap.insert(std::make_pair("devId02", 102));
364- EXPECT_CALL(*deviceProfileConnectorMock_,364+ devIdAndUserMap.insert(std::make_pair("devId03", 103));
365- HandleAccountLogoutEvent(_, _, _, _)).WillOnce(Return(DM_IDENTICAL_ACCOUNT));365+ EXPECT_CALL(*deviceProfileConnectorMock_, GetDevIdAndUserIdByActHash(_, _, _, _)).WillOnce(Return(devIdAndUserMap));
366+ EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAclForAccountLogOut(_, _, _, _))
367+ .Times(::testing::AtLeast(3)).WillOnce(Return(true));
366 deviceManagerServiceImpl_->HandleAccountLogoutEvent(remoteUserId, remoteAccountHash, remoteUdid);368 deviceManagerServiceImpl_->HandleAccountLogoutEvent(remoteUserId, remoteAccountHash, remoteUdid);
369+ 
370+ std::string localUdid = "localUdid";
371+ int32_t localUserId = 123;
372+ std::string peerUdid = "peerUdid";
373+ int32_t peerUserId = 456;
374+ EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAclForAccountLogOut(_, _, _, _)).WillOnce(Return(true));
375+ deviceManagerServiceImpl_->HandleIdentAccountLogout(localUdid, localUserId, peerUdid, peerUserId);
376+ 
367 EXPECT_CALL(*dmDeviceStateManagerMock_, ProcNotifyEvent(_, _)).WillOnce(Return(DM_OK));377 EXPECT_CALL(*dmDeviceStateManagerMock_, ProcNotifyEvent(_, _)).WillOnce(Return(DM_OK));
368 int ret = deviceManagerServiceImpl_->NotifyEvent(pkgName, eventId, event);378 int ret = deviceManagerServiceImpl_->NotifyEvent(pkgName, eventId, event);
369 EXPECT_EQ(ret, DM_OK);379 EXPECT_EQ(ret, DM_OK);
@@ -1532,6 +1542,8 @@ HWTEST_F(DeviceManagerServiceImplTest, UnBindDevice_104, testing::ext::TestSize.
1532 int32_t ret = deviceManagerServiceImpl_->UnBindDevice(pkgName, udid, bindLevel);1542 int32_t ret = deviceManagerServiceImpl_->UnBindDevice(pkgName, udid, bindLevel);
1533 int32_t userId = 100;1543 int32_t userId = 100;
1534 std::string accountId = "60008";1544 std::string accountId = "60008";
1545+ EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAclForAccountLogOut(_, _, _, _))
1546+ .Times(::testing::AtLeast(1)).WillOnce(Return(true));
1535 deviceManagerServiceImpl_->HandleIdentAccountLogout(udid, userId, udid, userId);1547 deviceManagerServiceImpl_->HandleIdentAccountLogout(udid, userId, udid, userId);
1536 deviceManagerServiceImpl_->HandleUserRemoved(userId);1548 deviceManagerServiceImpl_->HandleUserRemoved(userId);
1537 deviceManagerServiceImpl_->HandleDeviceNotTrust(udid);1549 deviceManagerServiceImpl_->HandleDeviceNotTrust(udid);
@@ -1635,7 +1647,7 @@ HWTEST_F(DeviceManagerServiceImplTest, StopAuthenticateDevice_102, testing::ext:
1635 deviceManagerServiceImpl_->Initialize(listener_);1647 deviceManagerServiceImpl_->Initialize(listener_);
1636 }1648 }
1637 int ret = deviceManagerServiceImpl_->StopAuthenticateDevice(pkgName);1649 int ret = deviceManagerServiceImpl_->StopAuthenticateDevice(pkgName);
1638- EXPECT_EQ(ret, DM_OK);1650+ EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
1639}1651}
1640 1652 
1641HWTEST_F(DeviceManagerServiceImplTest, CheckIsSameAccount_001, testing::ext::TestSize.Level0)1653HWTEST_F(DeviceManagerServiceImplTest, CheckIsSameAccount_001, testing::ext::TestSize.Level0)
@@ -1902,6 +1914,31 @@ HWTEST_F(DeviceManagerServiceImplTest, SaveOnlineDeviceInfo_001, testing::ext::T
1902 deviceManagerServiceImpl_->Initialize(listener_);1914 deviceManagerServiceImpl_->Initialize(listener_);
1903 }1915 }
1904 deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid);1916 deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid);
1917+ 
1918+ int32_t userId = 123456;
1919+ remoteUdid = "remoteDeviceId";
1920+ if (deviceManagerServiceImpl_->hiChainConnector_ == nullptr) {
1921+ deviceManagerServiceImpl_->Initialize(listener_);
1922+ }
1923+ deviceManagerServiceImpl_->HandleRemoteUserRemoved(userId, remoteUdid);
1924+}
1925+ 
1926+HWTEST_F(DeviceManagerServiceImplTest, GetDeviceIdAndBindLevel_001, testing::ext::TestSize.Level0)
1927+{
1928+ int32_t userId = 123456;
1929+ std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1930+ EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles));
1931+ auto ret = deviceManagerServiceImpl_->GetDeviceIdAndBindLevel(userId);
1932+ EXPECT_TRUE(ret.empty());
1933+}
1934+ 
1935+HWTEST_F(DeviceManagerServiceImplTest, GetDeviceIdAndUserId_002, testing::ext::TestSize.Level0)
1936+{
1937+ int32_t localUserId = 123456;
1938+ std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1939+ EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles));
1940+ auto ret = deviceManagerServiceImpl_->GetDeviceIdAndUserId(localUserId);
1941+ EXPECT_TRUE(ret.empty());
1905}1942}
1906} // namespace1943} // namespace
1907} // namespace DistributedHardware1944} // namespace DistributedHardware
@@ -27,7 +27,6 @@
27#include "softbus_connector_mock.h"27#include "softbus_connector_mock.h"
28#include "dm_device_state_manager_mock.h"28#include "dm_device_state_manager_mock.h"
29#include "mine_hichain_connector_mock.h"29#include "mine_hichain_connector_mock.h"
30- 
31namespace OHOS {30namespace OHOS {
32namespace DistributedHardware {31namespace DistributedHardware {
33class DeviceManagerServiceImplTest : public testing::Test {32class DeviceManagerServiceImplTest : public testing::Test {
@@ -0,0 +1,93 @@
1+/*
2+ * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#include "UTTest_device_manager_service_impl_first.h"
17+#include "softbus_error_code.h"
18+#include "common_event_support.h"
19+#include "deviceprofile_connector.h"
20+#include "distributed_device_profile_client.h"
21+ 
22+using namespace testing;
23+using namespace testing::ext;
24+using namespace OHOS::DistributedDeviceProfile;
25+namespace OHOS {
26+namespace DistributedHardware {
27+void DeviceManagerServiceImplFirstTest::SetUp()
28+{
29+ if (deviceManagerServiceImpl_ == nullptr) {
30+ deviceManagerServiceImpl_ = std::make_shared<DeviceManagerServiceImpl>();
31+ }
32+ deviceManagerServiceImpl_->Initialize(listener_);
33+}
34+ 
35+void DeviceManagerServiceImplFirstTest::TearDown()
36+{
37+}
38+ 
39+void DeviceManagerServiceImplFirstTest::SetUpTestCase()
40+{
41+ DmDeviceProfileConnector::dmDeviceProfileConnector = deviceProfileConnectorMock_;
42+ DmMultipleUserConnector::dmMultipleUserConnector = multipleUserConnectorMock_;
43+}
44+ 
45+void DeviceManagerServiceImplFirstTest::TearDownTestCase()
46+{
47+ DmDeviceProfileConnector::dmDeviceProfileConnector = nullptr;
48+ deviceProfileConnectorMock_ = nullptr;
49+ DmMultipleUserConnector::dmMultipleUserConnector = nullptr;
50+ multipleUserConnectorMock_ = nullptr;
51+}
52+ 
53+namespace {
54+HWTEST_F(DeviceManagerServiceImplFirstTest, GetDeviceIdAndUserId_101, testing::ext::TestSize.Level0)
55+{
56+ int32_t userId = 1;
57+ std::string accountId = "accountId";
58+ auto ret = deviceManagerServiceImpl_->GetDeviceIdAndUserId(userId, accountId);
59+ EXPECT_TRUE(ret.empty());
60+ 
61+ ret = deviceManagerServiceImpl_->GetDeviceIdAndUserId(userId);
62+ EXPECT_TRUE(ret.empty());
63+ 
64+ std::string localUdid = "deviceId";
65+ int32_t localUserId = 123456;
66+ std::string peerUdid = "remoteUdid";
67+ int32_t peerUserId = 1;
68+ EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAclForAccountLogOut(_, _, _, _)).WillOnce(Return(true));
69+ if (deviceManagerServiceImpl_->softbusConnector_ == nullptr) {
70+ deviceManagerServiceImpl_->Initialize(listener_);
71+ }
72+ 
73+ if (deviceManagerServiceImpl_->deviceStateMgr_ == nullptr) {
74+ deviceManagerServiceImpl_->Initialize(listener_);
75+ }
76+ deviceManagerServiceImpl_->HandleIdentAccountLogout(localUdid, localUserId, peerUdid, peerUserId);
77+ 
78+ std::vector<uint32_t> foregroundUserIds;
79+ std::vector<uint32_t> backgroundUserIds;
80+ std::string remoteUdid = "deviceId";
81+ EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));
82+ deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid);
83+ 
84+ std::vector<int32_t> localUserIds;
85+ localUserIds.push_back(101);
86+ localUserIds.push_back(102);
87+ EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_))
88+ .WillOnce(DoAll(SetArgReferee<0>(localUserIds), Return(DM_OK)));
89+ deviceManagerServiceImpl_->HandleSyncUserIdEvent(foregroundUserIds, backgroundUserIds, remoteUdid);
90+}
91+} // namespace
92+} // namespace DistributedHardware
93+} // namespace OHOS
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
16+#ifndef OHOS_UTTEST_DM_SERVICE_IMPL_FIRST_H
17+#define OHOS_UTTEST_DM_SERVICE_IMPL_FIRST_H
18+ 
19+#include <gtest/gtest.h>
20+#include <refbase.h>
21+ 
22+#include <string>
23+#include <vector>
24+ 
25+#include "device_manager_service_impl.h"
26+#include "device_manager_service_listener.h"
27+#include "deviceprofile_connector_mock.h"
28+#include "multiple_user_connector_mock.h"
29+ 
30+namespace OHOS {
31+namespace DistributedHardware {
32+class DeviceManagerServiceImplFirstTest : public testing::Test {
33+public:
34+ static void SetUpTestCase();
35+ static void TearDownTestCase();
36+ void SetUp() override;
37+ void TearDown() override;
38+ 
39+ std::shared_ptr<IDeviceManagerServiceListener> listener_ = std::make_shared<DeviceManagerServiceListener>();
40+ std::shared_ptr<DeviceManagerServiceImpl> deviceManagerServiceImpl_ = std::make_shared<DeviceManagerServiceImpl>();
41+ static inline std::shared_ptr<DeviceProfileConnectorMock> deviceProfileConnectorMock_ =
42+ std::make_shared<DeviceProfileConnectorMock>();
43+ static inline std::shared_ptr<MultipleUserConnectorMock> multipleUserConnectorMock_ =
44+ std::make_shared<MultipleUserConnectorMock>();
45+};
46+} // namespace DistributedHardware
47+} // namespace OHOS
48+#endif
@@ -409,6 +409,10 @@ HWTEST_F(DeviceManagerServiceThreeTest, SetDnPolicy_301, testing::ext::TestSize.
409 EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceAdapterLoad()).WillOnce(Return(false));409 EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceAdapterLoad()).WillOnce(Return(false));
410 int32_t ret = DeviceManagerService::GetInstance().SetDnPolicy(packName, policy);410 int32_t ret = DeviceManagerService::GetInstance().SetDnPolicy(packName, policy);
411 ASSERT_EQ(ret, ERR_DM_UNSUPPORTED_METHOD);411 ASSERT_EQ(ret, ERR_DM_UNSUPPORTED_METHOD);
412+ 
413+ std::string msg = "msg";
414+ EXPECT_CALL(*deviceManagerServiceMock_, IsDMServiceImplReady()).WillOnce(Return(false));
415+ DeviceManagerService::GetInstance().HandleDeviceTrustedChange(msg);
412}416}
413} // namespace417} // namespace
414} // namespace DistributedHardware418} // namespace DistributedHardware
@@ -266,14 +266,17 @@ HWTEST_F(DeviceManagerServiceTest, InitAccountInfo_201, testing::ext::TestSize.L
266{266{
267 int32_t userId = 100;267 int32_t userId = 100;
268 std::string commonEventType = "usual.event.USER_SWITCHED";268 std::string commonEventType = "usual.event.USER_SWITCHED";
269+ std::map<std::string, int32_t> curUserDeviceMap;
270+ EXPECT_CALL(*deviceManagerServiceImplMock_, GetDeviceIdAndBindLevel(_))
271+ .WillOnce(Return(curUserDeviceMap)).WillOnce(Return(curUserDeviceMap));
269 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, 101);272 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, 101);
270 commonEventType = "common.event.HWID_LOGIN";273 commonEventType = "common.event.HWID_LOGIN";
271 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, 101);274 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, userId, 101);
272- commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED;275+ commonEventType = "usual.event.USER_SWITCHED";
273 int32_t currentUserId = -1;276 int32_t currentUserId = -1;
274 int32_t beforeUserId = 0;277 int32_t beforeUserId = 0;
275 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, currentUserId, beforeUserId);278 DeviceManagerService::GetInstance().AccountCommonEventCallback(commonEventType, currentUserId, beforeUserId);
276- commonEventType = EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT;279+ commonEventType = "common.event.HWID_LOGOUT";
277 currentUserId = 1;280 currentUserId = 1;
278 beforeUserId = 1;281 beforeUserId = 1;
279 DMAccountInfo dmAccountInfo;282 DMAccountInfo dmAccountInfo;
@@ -632,6 +635,7 @@ HWTEST_F(DeviceManagerServiceTest, UnAuthenticateDevice_201, testing::ext::TestS
632 preUserDeviceMap["accountName"] = 1;635 preUserDeviceMap["accountName"] = 1;
633 EXPECT_CALL(*deviceManagerServiceImplMock_,636 EXPECT_CALL(*deviceManagerServiceImplMock_,
634 GetDeviceIdAndBindLevel(_)).WillOnce(Return(curUserDeviceMap)).WillOnce(Return(preUserDeviceMap));637 GetDeviceIdAndBindLevel(_)).WillOnce(Return(curUserDeviceMap)).WillOnce(Return(preUserDeviceMap));
638+ EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));
635 EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));639 EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));
636 DeviceManagerService::GetInstance().HandleUserSwitched(curUserId, preUserId);640 DeviceManagerService::GetInstance().HandleUserSwitched(curUserId, preUserId);
637 641 
@@ -666,6 +670,8 @@ HWTEST_F(DeviceManagerServiceTest, BindDevice_205, testing::ext::TestSize.Level0
666 if (DeviceManagerService::GetInstance().softbusListener_ == nullptr) {670 if (DeviceManagerService::GetInstance().softbusListener_ == nullptr) {
667 DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();671 DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();
668 }672 }
673+
674+ EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));
669 DeviceManagerService::GetInstance().ProcessSyncUserIds(foregroundUserIds, backgroundUserIds, remoteUdid);675 DeviceManagerService::GetInstance().ProcessSyncUserIds(foregroundUserIds, backgroundUserIds, remoteUdid);
670 DeviceManagerService::GetInstance().softbusListener_ = nullptr;676 DeviceManagerService::GetInstance().softbusListener_ = nullptr;
671}677}
@@ -709,8 +715,14 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_205, testing::ext::TestSiz
709 remoteUserIdInfos.push_back(userIdInfo);715 remoteUserIdInfos.push_back(userIdInfo);
710 UserIdInfo userIdInfo1(true, 102);716 UserIdInfo userIdInfo1(true, 102);
711 remoteUserIdInfos.push_back(userIdInfo1);717 remoteUserIdInfos.push_back(userIdInfo1);
718+ UserIdInfo userIdInfo2(false, 103);
719+ remoteUserIdInfos.push_back(userIdInfo2);
720+ UserIdInfo userIdInfo3(false, 104);
721+ remoteUserIdInfos.push_back(userIdInfo3);
712 std::string remoteUdid = "remoteDeviceId";722 std::string remoteUdid = "remoteDeviceId";
713 isNeedResponse = true;723 isNeedResponse = true;
724+ EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_))
725+ .WillOnce(Return(ERR_DM_FAILED)).WillOnce(Return(ERR_DM_FAILED));
714 EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));726 EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));
715 DeviceManagerService::GetInstance().HandleUserIdsBroadCast(remoteUserIdInfos, remoteUdid, isNeedResponse);727 DeviceManagerService::GetInstance().HandleUserIdsBroadCast(remoteUserIdInfos, remoteUdid, isNeedResponse);
716 728 
@@ -718,7 +730,7 @@ HWTEST_F(DeviceManagerServiceTest, AuthenticateDevice_205, testing::ext::TestSiz
718 foregroundUserVec.push_back(1);730 foregroundUserVec.push_back(1);
719 foregroundUserVec.push_back(102);731 foregroundUserVec.push_back(102);
720 EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_))732 EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_))
721- .WillOnce(DoAll(SetArgReferee<0>(foregroundUserVec), Return(DM_OK)));733+ .WillOnce(DoAll(SetArgReferee<0>(foregroundUserVec), Return(DM_OK))).WillOnce(Return(DM_OK));
722 EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(DM_OK));734 EXPECT_CALL(*multipleUserConnectorMock_, GetBackgroundUserIds(_)).WillOnce(Return(DM_OK));
723 DeviceManagerService::GetInstance().HandleUserIdsBroadCast(remoteUserIdInfos, remoteUdid, isNeedResponse);735 DeviceManagerService::GetInstance().HandleUserIdsBroadCast(remoteUserIdInfos, remoteUdid, isNeedResponse);
724 DeviceManagerService::GetInstance().softbusListener_ = nullptr;736 DeviceManagerService::GetInstance().softbusListener_ = nullptr;
@@ -773,6 +785,107 @@ HWTEST_F(DeviceManagerServiceTest, RegDevStateCallbackToService_201, testing::ex
773}785}
774 786 
775HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_205, testing::ext::TestSize.Level0)787HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_205, testing::ext::TestSize.Level0)
788+{
789+ std::string pkgName;
790+ std::string extra = "extra";
791+ std::vector<DmDeviceInfo> deviceList;
792+ int ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
793+ EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
794+ 
795+ pkgName = "jjdjk_pkgName";
796+ DeviceManagerService::GetInstance().softbusListener_ = nullptr;
797+ ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
798+ EXPECT_EQ(ret, ERR_DM_POINT_NULL);
799+ 
800+ DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();
801+ DeviceManagerService::GetInstance().InitDMServiceListener();
802+ EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_)).WillOnce(Return(ERR_DM_FAILED));
803+ ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
804+ EXPECT_EQ(ret, ERR_DM_FAILED);
805+ 
806+ std::vector<DmDeviceInfo> onlineDeviceList;
807+ DmDeviceInfo dmDeviceInfo;
808+ dmDeviceInfo.authForm = DmAuthForm::ACROSS_ACCOUNT;
809+ dmDeviceInfo.networkType = 1;
810+ onlineDeviceList.push_back(dmDeviceInfo);
811+ std::unordered_map<std::string, DmAuthForm> udidMap;
812+ udidMap.insert(std::make_pair("udid01", DmAuthForm::IDENTICAL_ACCOUNT));
813+ udidMap.insert(std::make_pair("udid02", DmAuthForm::ACROSS_ACCOUNT));
814+ EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_))
815+ .WillOnce(DoAll(SetArgReferee<0>(onlineDeviceList), Return(DM_OK)));
816+ EXPECT_CALL(*deviceManagerServiceImplMock_, GetAppTrustDeviceIdList(_)).WillOnce(Return(udidMap));
817+ EXPECT_CALL(*softbusListenerMock_, GetUdidByNetworkId(_, _))
818+ .WillOnce(DoAll(SetArgReferee<1>("udid01"), Return(DM_OK)));
819+ ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
820+ EXPECT_EQ(ret, DM_OK);
821+ 
822+ pkgName = "ohos.deviceprofile";
823+ EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_))
824+ .WillOnce(DoAll(SetArgReferee<0>(onlineDeviceList), Return(DM_OK)));
825+ EXPECT_CALL(*deviceManagerServiceImplMock_, GetAppTrustDeviceIdList(_)).WillOnce(Return(udidMap));
826+ EXPECT_CALL(*softbusListenerMock_, GetUdidByNetworkId(_, _))
827+ .WillOnce(DoAll(SetArgReferee<1>("udid02"), Return(DM_OK)));
828+ ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
829+ EXPECT_EQ(ret, DM_OK);
830+ DeviceManagerService::GetInstance().UninitDMServiceListener();
831+ DeviceManagerService::GetInstance().softbusListener_ = nullptr;
832+}
833+ 
834+HWTEST_F(DeviceManagerServiceTest, DmHiDumper_201, testing::ext::TestSize.Level0)
835+{
836+ std::vector<std::string> args;
837+ args.push_back(std::string("-getTrustlist"));
838+ std::string result;
839+ std::vector<DmDeviceInfo> deviceList;
840+ DmDeviceInfo dmDeviceInfo;
841+ dmDeviceInfo.authForm = DmAuthForm::ACROSS_ACCOUNT;
842+ dmDeviceInfo.deviceTypeId = 0;
843+ deviceList.push_back(dmDeviceInfo);
844+ DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();
845+ EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_))
846+ .WillOnce(DoAll(SetArgReferee<0>(deviceList), Return(DM_OK)));
847+ int ret = DeviceManagerService::GetInstance().DmHiDumper(args, result);
848+ EXPECT_EQ(ret, DM_OK);
849+ 
850+ EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_))
851+ .WillOnce(DoAll(SetArgReferee<0>(deviceList), Return(ERR_DM_FAILED)));
852+ ret = DeviceManagerService::GetInstance().DmHiDumper(args, result);
853+ EXPECT_EQ(ret, ERR_DM_FAILED);
854+ 
855+ std::vector<uint32_t> foregroundUserIds;
856+ foregroundUserIds.push_back(1);
857+ std::vector<uint32_t> backgroundUserIds;
858+ backgroundUserIds.push_back(2);
859+ std::string remoteUdid = "remoteUdid";
860+ if (DeviceManagerService::GetInstance().softbusListener_ == nullptr) {
861+ DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();
862+ }
863+ EXPECT_CALL(*multipleUserConnectorMock_, GetForegroundUserIds(_)).WillOnce(Return(ERR_DM_FAILED));
864+ DeviceManagerService::GetInstance().ProcessSyncUserIds(foregroundUserIds, backgroundUserIds, remoteUdid);
865+}
866+ 
867+HWTEST_F(DeviceManagerServiceTest, SetDnPolicy_207, testing::ext::TestSize.Level0)
868+{
869+ SetSetDnPolicyPermission();
870+ std::string packName = "com.ohos.test";
871+ std::map<std::string, std::string> policy;
872+ policy[PARAM_KEY_POLICY_STRATEGY_FOR_BLE] = "100a";
873+ policy[PARAM_KEY_POLICY_TIME_OUT] = "10";
874+ std::string processName = "collaboration_service";
875+ EXPECT_CALL(*permissionManagerMock_, GetCallerProcessName(_))
876+ .WillOnce(DoAll(SetArgReferee<0>(processName), Return(DM_OK)));
877+ int32_t ret = DeviceManagerService::GetInstance().SetDnPolicy(packName, policy);
878+ ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
879+ 
880+ policy[PARAM_KEY_POLICY_STRATEGY_FOR_BLE] = "100";
881+ policy[PARAM_KEY_POLICY_TIME_OUT] = "10a";
882+ EXPECT_CALL(*permissionManagerMock_, GetCallerProcessName(_))
883+ .WillOnce(DoAll(SetArgReferee<0>(processName), Return(DM_OK)));
884+ ret = DeviceManagerService::GetInstance().SetDnPolicy(packName, policy);
885+ ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
886+}
887+ 
888+HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_206, testing::ext::TestSize.Level0)
776{889{
777 std::string pkgName;890 std::string pkgName;
778 std::vector<DmDeviceInfo> deviceList;891 std::vector<DmDeviceInfo> deviceList;
@@ -818,55 +931,21 @@ HWTEST_F(DeviceManagerServiceTest, GetTrustedDeviceList_205, testing::ext::TestS
818 DeviceManagerService::GetInstance().softbusListener_ = nullptr;931 DeviceManagerService::GetInstance().softbusListener_ = nullptr;
819}932}
820 933 
821-HWTEST_F(DeviceManagerServiceTest, DmHiDumper_201, testing::ext::TestSize.Level0)934+HWTEST_F(DeviceManagerServiceTest, ParseCheckSumMsg_201, testing::ext::TestSize.Level0)
822{935{
823- std::vector<std::string> args;936+ std::string msg;
824- args.push_back(std::string("-getTrustlist"));937+ std::string networkId;
825- std::string result;938+ uint32_t discoveryType = 0;
826- std::vector<DmDeviceInfo> deviceList;939+ bool isChange = false;
827- DmDeviceInfo dmDeviceInfo;940+ nlohmann::json msgJsonObj;
828- dmDeviceInfo.authForm = DmAuthForm::ACROSS_ACCOUNT;941+ msgJsonObj["networkId"] = "networkId001";
829- dmDeviceInfo.deviceTypeId = 0;942+ msgJsonObj["discoverType"] = 1;
830- deviceList.push_back(dmDeviceInfo);943+ msgJsonObj["ischange"] = false;
831- DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();944+ msg = msgJsonObj.dump();
832- EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_))945+ int ret = DeviceManagerService::GetInstance().ParseCheckSumMsg(msg, networkId, discoveryType, isChange);
833- .WillOnce(DoAll(SetArgReferee<0>(deviceList), Return(DM_OK)));
834- int ret = DeviceManagerService::GetInstance().DmHiDumper(args, result);
835 EXPECT_EQ(ret, DM_OK);946 EXPECT_EQ(ret, DM_OK);
836- 
837- EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_))
838- .WillOnce(DoAll(SetArgReferee<0>(deviceList), Return(ERR_DM_FAILED)));
839- ret = DeviceManagerService::GetInstance().DmHiDumper(args, result);
840- EXPECT_EQ(ret, ERR_DM_FAILED);
841- 
842- std::vector<uint32_t> foregroundUserIds;
843- foregroundUserIds.push_back(1);
844- std::vector<uint32_t> backgroundUserIds;
845- backgroundUserIds.push_back(2);
846- std::string remoteUdid = "remoteUdid";
847- if (DeviceManagerService::GetInstance().softbusListener_ == nullptr) {
848- DeviceManagerService::GetInstance().softbusListener_ = std::make_shared<SoftbusListener>();
849- }
850- DeviceManagerService::GetInstance().ProcessSyncUserIds(foregroundUserIds, backgroundUserIds, remoteUdid);
851}947}
852 948 
853-HWTEST_F(DeviceManagerServiceTest, SetDnPolicy_207, testing::ext::TestSize.Level0)
854-{
855- SetSetDnPolicyPermission();
856- std::string packName = "com.ohos.test";
857- std::map<std::string, std::string> policy;
858- policy[PARAM_KEY_POLICY_STRATEGY_FOR_BLE] = "100a";
859- policy[PARAM_KEY_POLICY_TIME_OUT] = "10";
860- EXPECT_CALL(*permissionManagerMock_, GetCallerProcessName(_)).WillOnce(Return(ERR_DM_FAILED));
861- int32_t ret = DeviceManagerService::GetInstance().SetDnPolicy(packName, policy);
862- ASSERT_EQ(ret, ERR_DM_FAILED);
863- 
864- policy[PARAM_KEY_POLICY_STRATEGY_FOR_BLE] = "100";
865- policy[PARAM_KEY_POLICY_TIME_OUT] = "10a";
866- EXPECT_CALL(*permissionManagerMock_, GetCallerProcessName(_)).WillOnce(Return(DM_OK));
867- ret = DeviceManagerService::GetInstance().SetDnPolicy(packName, policy);
868- ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
869-}
870} // namespace949} // namespace
871} // namespace DistributedHardware950} // namespace DistributedHardware
872} // namespace OHOS951} // namespace OHOS
@@ -38,8 +38,10 @@ void DmAccountCommonEventManagerTest::TearDownTestCase()
38{38{
39}39}
40 40 
41+void AccountCommonEventCallbacks(const std::string commonEventType, int32_t currentUserId, int32_t beforeUserId)
42+{
43+}
41namespace {44namespace {
42- 
43HWTEST_F(DmAccountCommonEventManagerTest, SubscribeAccountCommonEvent_001, testing::ext::TestSize.Level0)45HWTEST_F(DmAccountCommonEventManagerTest, SubscribeAccountCommonEvent_001, testing::ext::TestSize.Level0)
44{46{
45 std::shared_ptr<DmAccountCommonEventManager> accountCommonEventManager47 std::shared_ptr<DmAccountCommonEventManager> accountCommonEventManager
@@ -76,7 +78,9 @@ HWTEST_F(DmAccountCommonEventManagerTest, OnReceiveEvent_001, testing::ext::Test
76 std::string strEvent = "test";78 std::string strEvent = "test";
77 std::vector<std::string> strEventVec;79 std::vector<std::string> strEventVec;
78 strEventVec.push_back(strEvent);80 strEventVec.push_back(strEvent);
79- AccountEventCallback callback = nullptr;81+ AccountEventCallback callback = [=](const auto &eventType, const auto &currentUserId, const auto &beforeUserId) {
82+ AccountCommonEventCallbacks(eventType, currentUserId, beforeUserId);
83+ };
80 EventFwk::MatchingSkills matchingSkills;84 EventFwk::MatchingSkills matchingSkills;
81 matchingSkills.AddEvent(strEvent);85 matchingSkills.AddEvent(strEvent);
82 CommonEventSubscribeInfo subscriberInfo(matchingSkills);86 CommonEventSubscribeInfo subscriberInfo(matchingSkills);
@@ -29,5 +29,15 @@ bool AppManager::IsSystemSA()
29{29{
30 return DmAppManager::dmAppManager->IsSystemSA();30 return DmAppManager::dmAppManager->IsSystemSA();
31}31}
32+ 
33+int32_t AppManager::GetNativeTokenIdByName(std::string &processName, int64_t &tokenId)
34+{
35+ return DmAppManager::dmAppManager->GetNativeTokenIdByName(processName, tokenId);
36+}
37+ 
38+int32_t AppManager::GetHapTokenIdByName(int32_t userId, std::string &bundleName, int32_t instIndex, int64_t &tokenId)
39+{
40+ return DmAppManager::dmAppManager->GetHapTokenIdByName(userId, bundleName, instIndex, tokenId);
41+}
32} // namespace DistributedHardware42} // namespace DistributedHardware
33} // namespace OHOS43} // namespace OHOS
@@ -28,6 +28,9 @@ public:
28public:28public:
29 virtual std::string GetAppId() = 0;29 virtual std::string GetAppId() = 0;
30 virtual bool IsSystemSA() = 0;30 virtual bool IsSystemSA() = 0;
31+ virtual int32_t GetNativeTokenIdByName(std::string &processName, int64_t &tokenId) = 0;
32+ virtual int32_t GetHapTokenIdByName(int32_t userId, std::string &bundleName, int32_t instIndex,
33+ int64_t &tokenId) = 0;
31public:34public:
32 static inline std::shared_ptr<DmAppManager> dmAppManager = nullptr;35 static inline std::shared_ptr<DmAppManager> dmAppManager = nullptr;
33};36};
@@ -36,6 +39,8 @@ class AppManagerMock : public DmAppManager {
36public:39public:
37 MOCK_METHOD(std::string, GetAppId, ());40 MOCK_METHOD(std::string, GetAppId, ());
38 MOCK_METHOD(bool, IsSystemSA, ());41 MOCK_METHOD(bool, IsSystemSA, ());
42+ MOCK_METHOD(int32_t, GetNativeTokenIdByName, (std::string &, int64_t &));
43+ MOCK_METHOD(int32_t, GetHapTokenIdByName, (int32_t, std::string &, int32_t, int64_t &));
39};44};
40}45}
41}46}
@@ -63,5 +63,19 @@ OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEv
63 return DmDeviceProfileConnector::dmDeviceProfileConnector->HandleAppUnBindEvent(remoteUserId, remoteUdid,63 return DmDeviceProfileConnector::dmDeviceProfileConnector->HandleAppUnBindEvent(remoteUserId, remoteUdid,
64 tokenId, localUdid);64 tokenId, localUdid);
65}65}
66+ 
67+std::multimap<std::string, int32_t> DeviceProfileConnector::GetDevIdAndUserIdByActHash(const std::string &localUdid,
68+ const std::string &peerUdid, int32_t peerUserId, const std::string &peerAccountHash)
69+{
70+ return DmDeviceProfileConnector::dmDeviceProfileConnector->GetDevIdAndUserIdByActHash(localUdid, peerUdid,
71+ peerUserId, peerAccountHash);
72+}
73+ 
74+std::vector<int32_t> DeviceProfileConnector::SyncAclByBindType(std::string pkgName, std::vector<int32_t> bindTypeVec,
75+ std::string localDeviceId, std::string targetDeviceId)
76+{
77+ return DmDeviceProfileConnector::dmDeviceProfileConnector->SyncAclByBindType(pkgName, bindTypeVec,
78+ localDeviceId, targetDeviceId);
79+}
66} // namespace DistributedHardware80} // namespace DistributedHardware
67} // namespace OHOS81} // namespace OHOS
@@ -39,6 +39,10 @@ public:
39 const std::string &peerUdid, int32_t peerUserId) = 0;39 const std::string &peerUdid, int32_t peerUserId) = 0;
40 virtual OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent(int32_t remoteUserId,40 virtual OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent(int32_t remoteUserId,
41 const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid) = 0;41 const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid) = 0;
42+ virtual std::multimap<std::string, int32_t> GetDevIdAndUserIdByActHash(const std::string &localUdid,
43+ const std::string &peerUdid, int32_t peerUserId, const std::string &peerAccountHash) = 0;
44+ virtual std::vector<int32_t> SyncAclByBindType(std::string pkgName, std::vector<int32_t> bindTypeVec,
45+ std::string localDeviceId, std::string targetDeviceId) = 0;
42public:46public:
43 static inline std::shared_ptr<DmDeviceProfileConnector> dmDeviceProfileConnector = nullptr;47 static inline std::shared_ptr<DmDeviceProfileConnector> dmDeviceProfileConnector = nullptr;
44};48};
@@ -54,6 +58,10 @@ public:
54 MOCK_METHOD(bool, DeleteAclForAccountLogOut, (const std::string &, int32_t, const std::string &, int32_t));58 MOCK_METHOD(bool, DeleteAclForAccountLogOut, (const std::string &, int32_t, const std::string &, int32_t));
55 MOCK_METHOD((OHOS::DistributedHardware::ProcessInfo), HandleAppUnBindEvent, (int32_t, const std::string &,59 MOCK_METHOD((OHOS::DistributedHardware::ProcessInfo), HandleAppUnBindEvent, (int32_t, const std::string &,
56 int32_t, const std::string &));60 int32_t, const std::string &));
61+ MOCK_METHOD((std::multimap<std::string, int32_t>), GetDevIdAndUserIdByActHash, (const std::string &,
62+ const std::string &, int32_t, const std::string &));
63+ MOCK_METHOD((std::vector<int32_t>), SyncAclByBindType, (std::string, std::vector<int32_t>, std::string,
64+ std::string));
57};65};
58}66}
59}67}
@@ -39,5 +39,22 @@ int32_t DistributedDeviceProfileClient::GetAllAccessControlProfile(
39 return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->GetAllAccessControlProfile(39 return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->GetAllAccessControlProfile(
40 accessControlProfiles);40 accessControlProfiles);
41}41}
42+ 
43+int32_t DistributedDeviceProfileClient::SubscribeDeviceProfileInited(int32_t saId, sptr<IDpInitedCallback> initedCb)
44+{
45+ return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->SubscribeDeviceProfileInited(saId,
46+ initedCb);
47+}
48+ 
49+int32_t DistributedDeviceProfileClient::UnSubscribeDeviceProfileInited(int32_t saId)
50+{
51+ return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->UnSubscribeDeviceProfileInited(saId);
52+}
53+ 
54+int32_t DistributedDeviceProfileClient::PutAllTrustedDevices(
55+ const std::vector<DistributedDeviceProfile::TrustedDeviceInfo> &deviceInfos)
56+{
57+ return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->PutAllTrustedDevices(deviceInfos);
58+}
42} // namespace DistributedHardware59} // namespace DistributedHardware
43} // namespace OHOS60} // namespace OHOS
@@ -30,6 +30,10 @@ public:
30 std::vector<AccessControlProfile>& accessControlProfiles) = 0;30 std::vector<AccessControlProfile>& accessControlProfiles) = 0;
31 virtual int32_t PutAccessControlProfile(const AccessControlProfile& accessControlProfile) = 0;31 virtual int32_t PutAccessControlProfile(const AccessControlProfile& accessControlProfile) = 0;
32 virtual int32_t GetAllAccessControlProfile(std::vector<AccessControlProfile>& accessControlProfiles) = 0;32 virtual int32_t GetAllAccessControlProfile(std::vector<AccessControlProfile>& accessControlProfiles) = 0;
33+ virtual int32_t SubscribeDeviceProfileInited(int32_t saId, sptr<IDpInitedCallback> initedCb) = 0;
34+ virtual int32_t UnSubscribeDeviceProfileInited(int32_t saId) = 0;
35+ virtual int32_t PutAllTrustedDevices(const std::vector<DistributedDeviceProfile::TrustedDeviceInfo> &deviceInfos)
36+ = 0;
33public:37public:
34 static inline std::shared_ptr<DpDistributedDeviceProfileClient> dpDistributedDeviceProfileClient = nullptr;38 static inline std::shared_ptr<DpDistributedDeviceProfileClient> dpDistributedDeviceProfileClient = nullptr;
35};39};
@@ -40,6 +44,9 @@ public:
40 std::vector<AccessControlProfile>&));44 std::vector<AccessControlProfile>&));
41 MOCK_METHOD(int32_t, PutAccessControlProfile, (const AccessControlProfile&));45 MOCK_METHOD(int32_t, PutAccessControlProfile, (const AccessControlProfile&));
42 MOCK_METHOD(int32_t, GetAllAccessControlProfile, (std::vector<AccessControlProfile>&));46 MOCK_METHOD(int32_t, GetAllAccessControlProfile, (std::vector<AccessControlProfile>&));
47+ MOCK_METHOD(int32_t, SubscribeDeviceProfileInited, (int32_t, sptr<IDpInitedCallback>));
48+ MOCK_METHOD(int32_t, UnSubscribeDeviceProfileInited, (int32_t));
49+ MOCK_METHOD(int32_t, PutAllTrustedDevices, (const std::vector<DistributedDeviceProfile::TrustedDeviceInfo> &));
43};50};
44}51}
45}52}
@@ -34,5 +34,10 @@ int32_t Crypto::GetUdidHash(const std::string &udid, unsigned char *udidHash)
34{34{
35 return DmCrypto::dmCrypto->GetUdidHash(udid, udidHash);35 return DmCrypto::dmCrypto->GetUdidHash(udid, udidHash);
36}36}
37+ 
38+std::string Crypto::GetGroupIdHash(const std::string &groupId)
39+{
40+ return DmCrypto::dmCrypto->GetGroupIdHash(groupId);
41+}
37} // namespace DistributedHardware42} // namespace DistributedHardware
38} // namespace OHOS43} // namespace OHOS
@@ -30,6 +30,7 @@ public:
30 virtual int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash,30 virtual int32_t ConvertUdidHashToAnoyAndSave(const std::string &appId, const std::string &udidHash,
31 DmKVValue &kvValue) = 0;31 DmKVValue &kvValue) = 0;
32 virtual int32_t GetUdidHash(const std::string &udid, unsigned char *udidHash) = 0;32 virtual int32_t GetUdidHash(const std::string &udid, unsigned char *udidHash) = 0;
33+ virtual std::string GetGroupIdHash(const std::string &groupId) = 0;
33public:34public:
34 static inline std::shared_ptr<DmCrypto> dmCrypto = nullptr;35 static inline std::shared_ptr<DmCrypto> dmCrypto = nullptr;
35};36};
@@ -39,6 +40,7 @@ public:
39 MOCK_METHOD(int32_t, GetAccountIdHash, (const std::string &, unsigned char *));40 MOCK_METHOD(int32_t, GetAccountIdHash, (const std::string &, unsigned char *));
40 MOCK_METHOD(int32_t, ConvertUdidHashToAnoyAndSave, (const std::string &, const std::string &, DmKVValue &));41 MOCK_METHOD(int32_t, ConvertUdidHashToAnoyAndSave, (const std::string &, const std::string &, DmKVValue &));
41 MOCK_METHOD(int32_t, GetUdidHash, (const std::string &, unsigned char *));42 MOCK_METHOD(int32_t, GetUdidHash, (const std::string &, unsigned char *));
43+ MOCK_METHOD(std::string, GetGroupIdHash, (const std::string &));
42};44};
43}45}
44}46}
@@ -22,33 +22,6 @@ namespace DistributedHardware {
22bool HiChainConnector::GetGroupInfo(const int32_t userId, const std::string &queryParams,22bool HiChainConnector::GetGroupInfo(const int32_t userId, const std::string &queryParams,
23 std::vector<GroupInfo> &groupList)23 std::vector<GroupInfo> &groupList)
24{24{
25- GroupInfo groupInfo;
26- groupInfo.groupName = "group1";
27- groupInfo.groupId = "123456";
28- groupInfo.groupOwner = "sdsd";
29- groupInfo.groupType = 1;
30- groupInfo.groupVisibility = 0;
31- groupInfo.userId = "82898";
32- 
33- GroupInfo groupInfo2;
34- groupInfo2.groupName = "group2";
35- groupInfo2.groupId = "123456";
36- groupInfo2.groupOwner = "sdsd";
37- groupInfo2.groupType = 1;
38- groupInfo2.groupVisibility = 0;
39- groupInfo2.userId = "82898";
40- 
41- GroupInfo groupInfo3;
42- groupInfo3.groupName = "group3";
43- groupInfo3.groupId = "123456";
44- groupInfo3.groupOwner = "sdsd";
45- groupInfo3.groupType = 1;
46- groupInfo3.groupVisibility = 0;
47- groupInfo3.userId = "82898";
48- 
49- groupList.push_back(groupInfo);
50- groupList.push_back(groupInfo2);
51- groupList.push_back(groupInfo3);
52 return DmHiChainConnector::dmHiChainConnector->GetGroupInfo(userId, queryParams, groupList);25 return DmHiChainConnector::dmHiChainConnector->GetGroupInfo(userId, queryParams, groupList);
53}26}
54 27 
@@ -56,5 +29,16 @@ bool HiChainConnector::IsDevicesInP2PGroup(const std::string &hostDevice, const
56{29{
57 return DmHiChainConnector::dmHiChainConnector->IsDevicesInP2PGroup(hostDevice, peerDevice);30 return DmHiChainConnector::dmHiChainConnector->IsDevicesInP2PGroup(hostDevice, peerDevice);
58}31}
32+ 
33+int32_t HiChainConnector::GetRelatedGroups(const std::string &deviceId, std::vector<GroupInfo> &groupList)
34+{
35+ return DmHiChainConnector::dmHiChainConnector->GetRelatedGroups(deviceId, groupList);
36+}
37+ 
38+int32_t HiChainConnector::GetRelatedGroups(int32_t userId, const std::string &deviceId,
39+ std::vector<GroupInfo> &groupList)
40+{
41+ return DmHiChainConnector::dmHiChainConnector->GetRelatedGroups(userId, deviceId, groupList);
42+}
59} // namespace DistributedHardware43} // namespace DistributedHardware
60} // namespace OHOS44} // namespace OHOS
@@ -29,6 +29,9 @@ public:
29 virtual bool GetGroupInfo(const int32_t userId, const std::string &queryParams,29 virtual bool GetGroupInfo(const int32_t userId, const std::string &queryParams,
30 std::vector<GroupInfo> &groupList) = 0;30 std::vector<GroupInfo> &groupList) = 0;
31 virtual bool IsDevicesInP2PGroup(const std::string &hostDevice, const std::string &peerDevice) = 0;31 virtual bool IsDevicesInP2PGroup(const std::string &hostDevice, const std::string &peerDevice) = 0;
32+ virtual int32_t GetRelatedGroups(const std::string &deviceId, std::vector<GroupInfo> &groupList) = 0;
33+ virtual int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId,
34+ std::vector<GroupInfo> &groupList) = 0;
32public:35public:
33 static inline std::shared_ptr<DmHiChainConnector> dmHiChainConnector = nullptr;36 static inline std::shared_ptr<DmHiChainConnector> dmHiChainConnector = nullptr;
34};37};
@@ -37,6 +40,8 @@ class HiChainConnectorMock : public DmHiChainConnector {
37public:40public:
38 MOCK_METHOD(bool, GetGroupInfo, (const int32_t, const std::string &, std::vector<GroupInfo> &));41 MOCK_METHOD(bool, GetGroupInfo, (const int32_t, const std::string &, std::vector<GroupInfo> &));
39 MOCK_METHOD(bool, IsDevicesInP2PGroup, (const std::string &, const std::string &));42 MOCK_METHOD(bool, IsDevicesInP2PGroup, (const std::string &, const std::string &));
43+ MOCK_METHOD(int32_t, GetRelatedGroups, (const std::string &, std::vector<GroupInfo> &));
44+ MOCK_METHOD(int32_t, GetRelatedGroups, (int32_t, const std::string &, std::vector<GroupInfo> &));
40};45};
41}46}
42}47}
@@ -1617,6 +1617,474 @@ void AddAccessControlProfilethirtyfirst(std::vector<AccessControlProfile>& acces
1617 accessControlProfiles.push_back(profileFifth);1617 accessControlProfiles.push_back(profileFifth);
1618}1618}
1619 1619 
1620+void AddAccessControlProfilethirtysecond(std::vector<AccessControlProfile>& accessControlProfiles)
1621+{
1622+ int32_t userId = 1234;
1623+ int32_t bindType = 256;
1624+ int32_t deviceIdType = 1;
1625+ uint32_t bindLevel = 1;
1626+ uint32_t status = 1;
1627+ uint32_t authenticationType = 2;
1628+ uint32_t accesserId = 1;
1629+ uint32_t tokenId = 1001;
1630+ 
1631+ std::string oldAccountId = "";
1632+ std::string newAccountId = "newAccountId";
1633+ std::string deviceIdEr = "localDeviceId";
1634+ std::string deviceIdEe = "remoteDeviceId";
1635+ std::string trustDeviceId = "123456";
1636+ 
1637+ Accesser accesser;
1638+ accesser.SetAccesserId(accesserId);
1639+ accesser.SetAccesserDeviceId(deviceIdEr);
1640+ accesser.SetAccesserUserId(userId);
1641+ accesser.SetAccesserAccountId(oldAccountId);
1642+ accesser.SetAccesserTokenId(tokenId);
1643+ accesser.SetAccesserBundleName("bundleName");
1644+ accesser.SetAccesserHapSignature("uph1");
1645+ accesser.SetAccesserBindLevel(bindLevel);
1646+ 
1647+ Accessee accessee;
1648+ accessee.SetAccesseeId(accesserId);
1649+ accessee.SetAccesseeDeviceId(deviceIdEe);
1650+ accessee.SetAccesseeUserId(userId);
1651+ accessee.SetAccesseeAccountId(newAccountId);
1652+ accessee.SetAccesseeTokenId(tokenId);
1653+ accessee.SetAccesseeBundleName("bundleName");
1654+ accessee.SetAccesseeHapSignature("uph1");
1655+ accessee.SetAccesseeBindLevel(bindLevel);
1656+ 
1657+ AccessControlProfile profileFifth;
1658+ profileFifth.SetAccessControlId(accesserId);
1659+ profileFifth.SetAccesserId(accesserId);
1660+ profileFifth.SetAccesseeId(accesserId);
1661+ profileFifth.SetTrustDeviceId(trustDeviceId);
1662+ profileFifth.SetBindType(bindType);
1663+ profileFifth.SetAuthenticationType(authenticationType);
1664+ profileFifth.SetDeviceIdType(deviceIdType);
1665+ profileFifth.SetStatus(status);
1666+ profileFifth.SetBindLevel(bindLevel);
1667+ profileFifth.SetAccesser(accesser);
1668+ profileFifth.SetAccessee(accessee);
1669+ accessControlProfiles.push_back(profileFifth);
1670+}
1671+ 
1672+void AddAccessControlProfilethirtythird(std::vector<AccessControlProfile>& accessControlProfiles)
1673+{
1674+ int32_t userId = 1234;
1675+ int32_t bindType = 256;
1676+ int32_t deviceIdType = 1;
1677+ uint32_t bindLevel = 1;
1678+ uint32_t status = 1;
1679+ uint32_t authenticationType = 2;
1680+ uint32_t accesserId = 1;
1681+ uint32_t tokenId = 1001;
1682+ 
1683+ std::string oldAccountId = "";
1684+ std::string newAccountId = "newAccountId";
1685+ std::string deviceIdEr = "localDeviceId";
1686+ std::string deviceIdEe = "remoteDeviceId";
1687+ std::string trustDeviceId = "123456";
1688+ 
1689+ Accesser accesser;
1690+ accesser.SetAccesserId(accesserId);
1691+ accesser.SetAccesserDeviceId(deviceIdEr);
1692+ accesser.SetAccesserUserId(userId);
1693+ accesser.SetAccesserAccountId(oldAccountId);
1694+ accesser.SetAccesserTokenId(tokenId);
1695+ accesser.SetAccesserBundleName("bundleName");
1696+ accesser.SetAccesserHapSignature("uph1");
1697+ accesser.SetAccesserBindLevel(bindLevel);
1698+ 
1699+ Accessee accessee;
1700+ accessee.SetAccesseeId(accesserId);
1701+ accessee.SetAccesseeDeviceId(deviceIdEe);
1702+ accessee.SetAccesseeUserId(userId);
1703+ accessee.SetAccesseeAccountId(newAccountId);
1704+ accessee.SetAccesseeTokenId(tokenId);
1705+ accessee.SetAccesseeBundleName("bundleName");
1706+ accessee.SetAccesseeHapSignature("uph1");
1707+ accessee.SetAccesseeBindLevel(bindLevel);
1708+ 
1709+ AccessControlProfile profileFifth;
1710+ profileFifth.SetAccessControlId(accesserId);
1711+ profileFifth.SetAccesserId(accesserId);
1712+ profileFifth.SetAccesseeId(accesserId);
1713+ profileFifth.SetTrustDeviceId(trustDeviceId);
1714+ profileFifth.SetBindType(bindType);
1715+ profileFifth.SetAuthenticationType(authenticationType);
1716+ profileFifth.SetDeviceIdType(deviceIdType);