From 5efc56178cfb86c42f0ae20b4feb1f0955d690ce Mon Sep 17 00:00:00 2001 From: lsq Date: Tue, 31 May 2022 19:48:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BF=9C=E7=AB=AFdeviceid=E6=A0=87?= =?UTF-8?q?=E5=BF=97=E7=94=B1networkID=E6=95=B4=E6=94=B9=E4=B8=BAudid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lsq Change-Id: I20597800af1865f11035d3ae6938f27cc2d2d239 Signed-off-by: lsq --- .../innerkits/accesstoken/test/BUILD.gn | 1 + .../unittest/src/accesstoken_kit_test.cpp | 12 +-- .../command/delete_remote_token_command.cpp | 6 +- .../sync_remote_native_token_command.cpp | 4 +- .../update_remote_hap_token_command.cpp | 6 +- .../src/remote/remote_command_manager.cpp | 4 +- .../service/token_sync_manager_service.cpp | 4 +- .../token_sync_service_test.cpp | 75 ++++++++++--------- 8 files changed, 59 insertions(+), 53 deletions(-) diff --git a/interfaces/innerkits/accesstoken/test/BUILD.gn b/interfaces/innerkits/accesstoken/test/BUILD.gn index 55ed6e19f..5b70fe8c3 100644 --- a/interfaces/innerkits/accesstoken/test/BUILD.gn +++ b/interfaces/innerkits/accesstoken/test/BUILD.gn @@ -26,6 +26,7 @@ ohos_unittest("libaccesstoken_sdk_test") { "//base/security/access_token/interfaces/innerkits/nativetoken/include", "//base/security/access_token/interfaces/innerkits/token_setproc/include", "//base/security/access_token/frameworks/common/include", + "//base/security/access_token/services/tokensyncmanager/include", ] sources = [ "unittest/src/accesstoken_kit_test.cpp" ] diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp index 5213af1bb..499d541d0 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp @@ -2353,7 +2353,7 @@ HWTEST_F(AccessTokenKitTest, GetTokenTypeFlag003, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo001, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo001 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = "deviceid-1:udid-001"; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2362,7 +2362,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo001, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = deviceID, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2912,7 +2912,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo010, TestSize.Level1) HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = "deviceid-1:udid-001"; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2921,7 +2921,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = deviceID, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2966,7 +2966,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken002, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = "deviceid-1:udid-001"; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2975,7 +2975,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken002, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = deviceID, .tokenID = 0x20100000, .tokenAttr = 0 }; diff --git a/services/tokensyncmanager/src/command/delete_remote_token_command.cpp b/services/tokensyncmanager/src/command/delete_remote_token_command.cpp index 3197b08ca..f09bb04c9 100644 --- a/services/tokensyncmanager/src/command/delete_remote_token_command.cpp +++ b/services/tokensyncmanager/src/command/delete_remote_token_command.cpp @@ -80,13 +80,13 @@ void DeleteRemoteTokenCommand::Execute() bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(remoteProtocol_.srcDeviceId, DeviceIdType::UNKNOWN, devInfo); if (!result) { - ACCESSTOKEN_LOG_INFO(LABEL, "error: get remote networkId failed"); + ACCESSTOKEN_LOG_INFO(LABEL, "error: get remote uniqueDeviceId failed"); remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY; return; } - std::string networkID = devInfo.deviceId.networkId; - int ret = AccessTokenKit::DeleteRemoteToken(networkID, deleteTokenId_); + std::string uniqueDeviceId = devInfo.deviceId.uniqueDeviceId; + int ret = AccessTokenKit::DeleteRemoteToken(uniqueDeviceId, deleteTokenId_); if (ret != RET_SUCCESS) { remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY; remoteProtocol_.message = Constant::COMMAND_RESULT_FAILED; diff --git a/services/tokensyncmanager/src/command/sync_remote_native_token_command.cpp b/services/tokensyncmanager/src/command/sync_remote_native_token_command.cpp index 6484d3527..db3fec00b 100644 --- a/services/tokensyncmanager/src/command/sync_remote_native_token_command.cpp +++ b/services/tokensyncmanager/src/command/sync_remote_native_token_command.cpp @@ -102,11 +102,11 @@ void SyncRemoteNativeTokenCommand::Finish() bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(remoteProtocol_.dstDeviceId, DeviceIdType::UNKNOWN, devInfo); if (!result) { - ACCESSTOKEN_LOG_ERROR(LABEL, "SyncRemoteNativeTokenCommand: get remote networkId failed"); + ACCESSTOKEN_LOG_ERROR(LABEL, "SyncRemoteNativeTokenCommand: get remote uniqueDeviceId failed"); remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY; return; } - int ret = AccessTokenKit::SetRemoteNativeTokenInfo(devInfo.deviceId.networkId, nativeTokenInfo_); + int ret = AccessTokenKit::SetRemoteNativeTokenInfo(devInfo.deviceId.uniqueDeviceId, nativeTokenInfo_); if (ret == RET_SUCCESS) { remoteProtocol_.statusCode = Constant::SUCCESS; } else { diff --git a/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp b/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp index 6910c984c..0d6dfe6e6 100644 --- a/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp +++ b/services/tokensyncmanager/src/command/update_remote_hap_token_command.cpp @@ -76,13 +76,13 @@ void UpdateRemoteHapTokenCommand::Execute() bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(remoteProtocol_.srcDeviceId, DeviceIdType::UNKNOWN, devInfo); if (!result) { - ACCESSTOKEN_LOG_INFO(LABEL, "UpdateRemoteHapTokenCommand: get remote networkId failed"); + ACCESSTOKEN_LOG_INFO(LABEL, "UpdateRemoteHapTokenCommand: get remote uniqueDeviceId failed"); remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY; return; } - std::string networkID = devInfo.deviceId.networkId; - int ret = AccessTokenKit::SetRemoteHapTokenInfo(networkID, updateTokenInfo_); + std::string uniqueDeviceId = devInfo.deviceId.uniqueDeviceId; + int ret = AccessTokenKit::SetRemoteHapTokenInfo(uniqueDeviceId, updateTokenInfo_); if (ret != RET_SUCCESS) { remoteProtocol_.statusCode = Constant::FAILURE_BUT_CAN_RETRY; remoteProtocol_.message = Constant::COMMAND_RESULT_FAILED; diff --git a/services/tokensyncmanager/src/remote/remote_command_manager.cpp b/services/tokensyncmanager/src/remote/remote_command_manager.cpp index 5d119f278..d9a604c45 100644 --- a/services/tokensyncmanager/src/remote/remote_command_manager.cpp +++ b/services/tokensyncmanager/src/remote/remote_command_manager.cpp @@ -224,9 +224,9 @@ int RemoteCommandManager::NotifyDeviceOffline(const std::string &nodeId) ACCESSTOKEN_LOG_INFO(LABEL, "get remote networkId failed"); return Constant::FAILURE; } - std::string networkId = devInfo.deviceId.networkId; + std::string uniqueDeviceId = devInfo.deviceId.uniqueDeviceId; std::function delayed = ([=]() { - AccessTokenKit::DeleteRemoteDeviceTokens(networkId); + AccessTokenKit::DeleteRemoteDeviceTokens(uniqueDeviceId); }); std::shared_ptr handler = diff --git a/services/tokensyncmanager/src/service/token_sync_manager_service.cpp b/services/tokensyncmanager/src/service/token_sync_manager_service.cpp index 748e2248c..cb6cd72f7 100644 --- a/services/tokensyncmanager/src/service/token_sync_manager_service.cpp +++ b/services/tokensyncmanager/src/service/token_sync_manager_service.cpp @@ -124,7 +124,7 @@ int TokenSyncManagerService::DeleteRemoteHapTokenInfo(AccessTokenID tokenID) } const std::shared_ptr deleteRemoteTokenCommand = RemoteCommandFactory::GetInstance().NewDeleteRemoteTokenCommand(Constant::GetLocalDeviceId(), - device.deviceId.networkId, tokenID); + device.deviceId.uniqueDeviceId, tokenID); const int32_t resultCode = RemoteCommandManager::GetInstance().ExecuteCommand( device.deviceId.uniqueDeviceId, deleteRemoteTokenCommand); @@ -150,7 +150,7 @@ int TokenSyncManagerService::UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& const std::shared_ptr updateRemoteHapTokenCommand = RemoteCommandFactory::GetInstance().NewUpdateRemoteHapTokenCommand(Constant::GetLocalDeviceId(), - device.deviceId.networkId, tokenInfo); + device.deviceId.uniqueDeviceId, tokenInfo); const int32_t resultCode = RemoteCommandManager::GetInstance().ExecuteCommand( device.deviceId.uniqueDeviceId, updateRemoteHapTokenCommand); diff --git a/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp b/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp index 13116f96e..2e5bc8fee 100644 --- a/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp +++ b/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp @@ -29,6 +29,7 @@ #include "session.h" #include "soft_bus_device_connection_listener.h" #include "soft_bus_session_listener.h" +#include "device_info_manager.h" #define private public #include "token_sync_manager_service.h" @@ -41,6 +42,7 @@ static std::vector threads_; static std::shared_ptr g_ptrDeviceStateCallback = std::make_shared(); static std::string g_networkID = "deviceid-1"; +static std::string g_UDID = "deviceid-1:udid-001"; static DmDeviceInfo g_devInfo = { // udid = deviceid-1:udid-001 uuid = deviceid-1:uuid-001 .deviceId = "deviceid-1", @@ -63,9 +65,11 @@ void TokenSyncServiceTest::SetUpTestCase() void TokenSyncServiceTest::TearDownTestCase() {} void TokenSyncServiceTest::SetUp() -{} +{ +} void TokenSyncServiceTest::TearDown() { + ACCESSTOKEN_LOG_INFO(LABEL, "TearDown start."); for (auto it = threads_.begin(); it != threads_.end(); it++) { it->join(); } @@ -141,7 +145,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo001, TestSize.Level1) "\\\"111111\\\",\\\"instIndex\\\":0,\\\"dlpType\\\":0,\\\"permState\\\":" "null,\\\"tokenAttr\\\":0,\\\"tokenID\\\":537919488," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -151,10 +155,10 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo001, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); int ret = OHOS::DelayedSingleton::GetInstance()->GetRemoteHapTokenInfo( - g_networkID, 0x20100000); + g_UDID, 0x20100000); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20100000); ASSERT_NE(mapID, (AccessTokenID)0); HapTokenInfo tokeInfo; @@ -242,7 +246,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo002, TestSize.Level1) "\\\"requestTokenId\\\":"; std::string tokenJsonStr = std::to_string(tokenIdEx.tokenIdExStruct.tokenID); std::string jsonAfter = ",\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"\\\",\\\"responseVersion\\\":2," - "\\\"srcDeviceId\\\":\\\"deviceid-1\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001," + "\\\"srcDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001," "\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"request\"}"; std::string recvJson = jsonBefore + tokenJsonStr + jsonAfter; @@ -283,7 +287,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo003, TestSize.Level1) "\\\"test\\\",\\\"bundleName\\\":\\\"mock_token_sync\\\",\\\"deviceID\\\":" "\\\"111111\\\",\\\"instIndex\\\":0,\\\"permState\\\":null,\\\"tokenAttr\\\":0,\\\"tokenID\\\":537919488," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -293,9 +297,9 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo003, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); OHOS::DelayedSingleton::GetInstance()->GetRemoteHapTokenInfo( - g_networkID, 0x20100000); + g_UDID, 0x20100000); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20100000); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -315,7 +319,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo004, TestSize.Level1) "\\\"test\\\",\\\"bundleName\\\":\\\"mock_token_sync\\\",\\\"deviceID\\\":" "\\\"111111\\\",\\\"permState\\\":null,\\\"tokenAttr\\\":0," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -325,9 +329,9 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo004, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); OHOS::DelayedSingleton::GetInstance()->GetRemoteHapTokenInfo( - g_networkID, 0x20100000); + g_UDID, 0x20100000); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20100000); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -348,7 +352,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo005, TestSize.Level1) "\\\"111111\\\",\\\"instIndex\\\":1,\\\"permState\\\":null,\\\"tokenAttr\\\":0," "\\\"tokenID\\\":\\\"aaa\\\"," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -358,9 +362,9 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo005, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); OHOS::DelayedSingleton::GetInstance()->GetRemoteHapTokenInfo( - g_networkID, 0x20100000); + g_UDID, 0x20100000); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20100000); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -381,7 +385,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo006, TestSize.Level1) "\\\"111111\\\",\\\"instIndex\\\":1,\\\"permState\\\":null,\\\"tokenAttr\\\":0," "\\\"tokenID\\\":537919488," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -391,9 +395,9 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo006, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); OHOS::DelayedSingleton::GetInstance()->GetRemoteHapTokenInfo( - g_networkID, 0x20100000); + g_UDID, 0x20100000); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20100000); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -426,9 +430,9 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo007, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); OHOS::DelayedSingleton::GetInstance()->GetRemoteHapTokenInfo( - g_networkID, 0x20100000); + g_UDID, 0x20100000); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20100000); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -457,7 +461,7 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo008, TestSize.Level1) "\\\"requestTokenId\\\":"; std::string tokenJsonStr = std::to_string(tokenID); std::string jsonAfter = ",\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"\\\",\\\"responseVersion\\\":2," - "\\\"srcDeviceId\\\":\\\"deviceid-1\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001," + "\\\"srcDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001," "\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"request\"}"; // create recv message @@ -498,7 +502,7 @@ HWTEST_F(TokenSyncServiceTest, SyncNativeTokens001, TestSize.Level1) "{\\\"apl\\\":3,\\\"processName\\\":\\\"attest1\\\",\\\"tokenAttr\\\":0,\\\"tokenId\\\":671088641," "\\\"version\\\":1,\\\"dcaps\\\":[\\\"SYSDCAP\\\",\\\"DMSDCAP\\\"]}]," "\\\"commandName\\\":\\\"SyncRemoteNativeTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"," "\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\"," "\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteNativeTokenCommand\\\"}\"," @@ -510,14 +514,14 @@ HWTEST_F(TokenSyncServiceTest, SyncNativeTokens001, TestSize.Level1) sleep(6); - AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000000); + AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000000); ASSERT_NE(mapID, (AccessTokenID)0); int ret = AccessTokenKit::CheckNativeDCap(mapID, "SYSDCAP"); ASSERT_EQ(ret, RET_SUCCESS); ret = AccessTokenKit::CheckNativeDCap(mapID, "DMSDCAP"); ASSERT_EQ(ret, RET_SUCCESS); - mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000001); + mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000001); ASSERT_NE(mapID, (AccessTokenID)0); ret = AccessTokenKit::CheckNativeDCap(mapID, "SYSDCAP"); ASSERT_EQ(ret, RET_SUCCESS); @@ -554,14 +558,14 @@ HWTEST_F(TokenSyncServiceTest, SyncNativeTokens002, TestSize.Level1) sleep(6); - AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000000); + AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000000); ASSERT_NE(mapID, (AccessTokenID)0); int ret = AccessTokenKit::CheckNativeDCap(mapID, "SYSDCAP"); ASSERT_EQ(ret, RET_SUCCESS); ret = AccessTokenKit::CheckNativeDCap(mapID, "DMSDCAP"); ASSERT_EQ(ret, RET_SUCCESS); - mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000001); + mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000001); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -594,10 +598,10 @@ HWTEST_F(TokenSyncServiceTest, SyncNativeTokens003, TestSize.Level1) sleep(6); - AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000000); + AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000000); ASSERT_EQ(mapID, (AccessTokenID)0); - mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000001); + mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000001); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -631,10 +635,10 @@ HWTEST_F(TokenSyncServiceTest, SyncNativeTokens004, TestSize.Level1) sleep(6); - AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000000); + AccessTokenID mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000000); ASSERT_EQ(mapID, (AccessTokenID)0); - mapID = AccessTokenKit::GetRemoteNativeTokenID(g_networkID, 0x28000001); + mapID = AccessTokenKit::GetRemoteNativeTokenID(g_UDID, 0x28000001); ASSERT_EQ(mapID, (AccessTokenID)0); } @@ -723,9 +727,9 @@ HWTEST_F(TokenSyncServiceTest, UpdateRemoteHapTokenCommand001, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); sleep(6); - int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_networkID, g_remoteHapInfo); + int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_UDID, g_remoteHapInfo); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20000001); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20000001); ASSERT_NE(mapID, 0); HapTokenInfo mapInfo; @@ -805,9 +809,9 @@ HWTEST_F(TokenSyncServiceTest, DeleteRemoteTokenCommand001, TestSize.Level1) g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); - int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_networkID, g_remoteHapInfo); + int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_UDID, g_remoteHapInfo); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20000001); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20000001); ASSERT_NE(mapID, 0); HapTokenInfo mapInfo; @@ -847,9 +851,9 @@ HWTEST_F(TokenSyncServiceTest, DeviceOffline001, TestSize.Level1) // device online g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); - int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_networkID, g_remoteHapInfo); + int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_UDID, g_remoteHapInfo); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_networkID, 0x20000001); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20000001); ASSERT_NE(mapID, 0); HapTokenInfo mapInfo; @@ -861,4 +865,5 @@ HWTEST_F(TokenSyncServiceTest, DeviceOffline001, TestSize.Level1) ret = AccessTokenKit::GetHapTokenInfo(mapID, mapInfo); ASSERT_EQ(ret, RET_FAILED); + } -- Gitee From c983a06ba180d22fbb49cfb6407247d2aff0af82 Mon Sep 17 00:00:00 2001 From: lsq Date: Tue, 31 May 2022 21:30:57 +0800 Subject: [PATCH 2/2] Signed-off-by: lsq Change-Id: Ic2e9cf9e5888a0953a14903d07cca8cbca891da5 Change-Id: I21f0b948fe00b0d2c68854fbd37a2528473b355f --- .../innerkits/accesstoken/test/BUILD.gn | 6 +- .../unittest/src/accesstoken_kit_test.cpp | 107 +++++---- .../test/unittest/src/accesstoken_kit_test.h | 3 + services/accesstokenmanager/BUILD.gn | 1 + .../include/token/accesstoken_info_manager.h | 4 + .../service/accesstoken_manager_service.cpp | 2 +- .../src/token/accesstoken_info_manager.cpp | 26 ++- .../token_sync_service_test.cpp | 206 +----------------- 8 files changed, 105 insertions(+), 250 deletions(-) diff --git a/interfaces/innerkits/accesstoken/test/BUILD.gn b/interfaces/innerkits/accesstoken/test/BUILD.gn index 5b70fe8c3..35c257ec0 100644 --- a/interfaces/innerkits/accesstoken/test/BUILD.gn +++ b/interfaces/innerkits/accesstoken/test/BUILD.gn @@ -26,7 +26,6 @@ ohos_unittest("libaccesstoken_sdk_test") { "//base/security/access_token/interfaces/innerkits/nativetoken/include", "//base/security/access_token/interfaces/innerkits/token_setproc/include", "//base/security/access_token/frameworks/common/include", - "//base/security/access_token/services/tokensyncmanager/include", ] sources = [ "unittest/src/accesstoken_kit_test.cpp" ] @@ -40,7 +39,10 @@ ohos_unittest("libaccesstoken_sdk_test") { "//utils/native/base:utils", ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ + "dsoftbus_standard:softbus_client", + "hiviewdfx_hilog_native:libhilog", + ] if (token_sync_enable == true) { cflags_cc += [ "-DTOKEN_SYNC_ENABLE" ] } diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp index 499d541d0..d665400f7 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp @@ -20,6 +20,7 @@ #include "nativetoken_kit.h" #include "accesstoken_log.h" #include "token_setproc.h" +#include "softbus_bus_center.h" using namespace testing::ext; using namespace OHOS::Security::AccessToken; @@ -262,6 +263,16 @@ void AccessTokenKitTest::SetUp() AccessTokenKit::DeleteToken(tokenID); (void)remove("/data/token.json"); + NodeBasicInfo deviceInfo; + int32_t res = ::GetLocalNodeDeviceInfo(TEST_PKG_NAME.c_str(), &deviceInfo); + ASSERT_EQ(res, RET_SUCCESS); + char udid[128] = {0}; // 128 is udid length + ::GetNodeKeyInfo(TEST_PKG_NAME.c_str(), deviceInfo.networkId, + NodeDeviceInfoKey::NODE_KEY_UDID, (uint8_t *)udid, 128); // 128 is udid length + + udid_.append(udid); + networkId_.append(deviceInfo.networkId); + ACCESSTOKEN_LOG_INFO(LABEL, "SetUp ok."); } @@ -270,6 +281,8 @@ void AccessTokenKitTest::TearDown() AccessTokenID tokenID = GetAccessTokenID(TEST_USER_ID, TEST_BUNDLE_NAME, 0); AccessTokenKit::DeleteToken(tokenID); SetSelfTokenID(selfTokenId_); + udid_.clear(); + networkId_.clear(); } unsigned int AccessTokenKitTest::GetAccessTokenID(int userID, std::string bundleName, int instIndex) @@ -2353,7 +2366,7 @@ HWTEST_F(AccessTokenKitTest, GetTokenTypeFlag003, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo001, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo001 start."); - std::string deviceID = "deviceid-1:udid-001"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2385,7 +2398,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo001, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); // check local map token @@ -2418,7 +2431,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo001, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo002, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo002 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo rightBaseInfo = { .apl = APL_NORMAL, @@ -2427,7 +2440,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo002, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2488,7 +2501,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo002, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo003, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo003 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2497,7 +2510,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo003, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2520,7 +2533,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo003, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); ret = AccessTokenKit::VerifyAccessToken(mapID, "ohos.permission.test1"); @@ -2539,7 +2552,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo003, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo004, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo004 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2548,7 +2561,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo004, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2571,7 +2584,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo004, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); ret = AccessTokenKit::VerifyAccessToken(mapID, "ohos.permission.test1"); @@ -2597,7 +2610,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo004, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo005, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo005 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2606,7 +2619,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo005, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2629,7 +2642,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo005, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); ret = AccessTokenKit::VerifyAccessToken(mapID, "ohos.permission.test1"); @@ -2654,7 +2667,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo005, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo006, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo006 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2663,7 +2676,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo006, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2686,7 +2699,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo006, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); ret = AccessTokenKit::VerifyAccessToken(mapID, "ohos.permission.test1"); @@ -2711,7 +2724,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo006, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo007, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo007 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2720,7 +2733,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo007, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2743,7 +2756,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo007, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); ret = AccessTokenKit::DeleteToken(mapID); @@ -2762,7 +2775,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo007, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo008, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo008 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2771,7 +2784,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo008, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2794,7 +2807,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo008, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); HapPolicyParams policy; @@ -2815,7 +2828,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo008, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo009, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo009 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2824,7 +2837,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo009, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -2847,7 +2860,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo009, TestSize.Level1) ASSERT_EQ(ret, RET_SUCCESS); // Get local map token ID - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); ret = AccessTokenKit::VerifyAccessToken(mapID, "ohos.permission.test1"); @@ -2872,7 +2885,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo009, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo010, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteHapTokenInfo009 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; HapTokenInfo baseInfo = { .apl = APL_NORMAL, .ver = 1, @@ -2880,7 +2893,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo010, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x28100000, .tokenAttr = 0 }; @@ -2912,7 +2925,7 @@ HWTEST_F(AccessTokenKitTest, SetRemoteHapTokenInfo010, TestSize.Level1) HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); - std::string deviceID = "deviceid-1:udid-001"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2943,7 +2956,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) int ret = AccessTokenKit::SetRemoteHapTokenInfo(deviceID, remoteTokenInfo); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); HapTokenInfo info; @@ -2966,7 +2979,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken001, TestSize.Level1) HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken002, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); - std::string deviceID = "deviceid-1:udid-001"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -2997,7 +3010,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken002, TestSize.Level1) int ret = AccessTokenKit::SetRemoteHapTokenInfo(deviceID, remoteTokenInfo); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); HapTokenInfo info; @@ -3023,7 +3036,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken002, TestSize.Level1) HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken003, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceToken003 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); int ret = AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); @@ -3039,7 +3052,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceToken003, TestSize.Level1) HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceTokens001, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens001 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100001); HapTokenInfo baseInfo = { @@ -3049,7 +3062,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceTokens001, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -3077,9 +3090,9 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceTokens001, TestSize.Level1) ret = AccessTokenKit::SetRemoteHapTokenInfo(deviceID, remoteTokenInfo1); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); - AccessTokenID mapID1 = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100001); + AccessTokenID mapID1 = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100001); ASSERT_NE(mapID1, 0); ret = AccessTokenKit::DeleteRemoteDeviceTokens(deviceID); @@ -3101,7 +3114,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceTokens001, TestSize.Level1) HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceTokens002, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteDeviceTokens002 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100001); HapTokenInfo baseInfo = { @@ -3111,7 +3124,7 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceTokens002, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -3139,9 +3152,9 @@ HWTEST_F(AccessTokenKitTest, DeleteRemoteDeviceTokens002, TestSize.Level1) ret = AccessTokenKit::SetRemoteHapTokenInfo(deviceID, remoteTokenInfo1); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); - AccessTokenID mapID1 = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100001); + AccessTokenID mapID1 = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100001); ASSERT_NE(mapID1, 0); ret = AccessTokenKit::DeleteRemoteDeviceTokens("1111111"); @@ -3207,7 +3220,7 @@ HWTEST_F(AccessTokenKitTest, GetHapTokenInfoFromRemote001, TestSize.Level1) HWTEST_F(AccessTokenKitTest, GetHapTokenInfoFromRemote002, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "GetHapTokenInfoFromRemote002 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -3216,7 +3229,7 @@ HWTEST_F(AccessTokenKitTest, GetHapTokenInfoFromRemote002, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -3238,7 +3251,7 @@ HWTEST_F(AccessTokenKitTest, GetHapTokenInfoFromRemote002, TestSize.Level1) int ret = AccessTokenKit::SetRemoteHapTokenInfo(deviceID, remoteTokenInfo); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); HapTokenInfoForSync infoSync; @@ -3271,7 +3284,7 @@ HWTEST_F(AccessTokenKitTest, GetHapTokenInfoFromRemote003, TestSize.Level1) HWTEST_F(AccessTokenKitTest, AllocLocalTokenID001, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "AllocLocalTokenID001 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; AccessTokenKit::DeleteRemoteToken(deviceID, 0x20100000); HapTokenInfo baseInfo = { .apl = APL_NORMAL, @@ -3280,7 +3293,7 @@ HWTEST_F(AccessTokenKitTest, AllocLocalTokenID001, TestSize.Level1) .bundleName = "com.ohos.access_token", .instIndex = 1, .appID = "testtesttesttest", - .deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2", + .deviceID = udid_, .tokenID = 0x20100000, .tokenAttr = 0 }; @@ -3302,7 +3315,7 @@ HWTEST_F(AccessTokenKitTest, AllocLocalTokenID001, TestSize.Level1) int ret = AccessTokenKit::SetRemoteHapTokenInfo(deviceID, remoteTokenInfo); ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceID, 0x20100000); + AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(networkId_, 0x20100000); ASSERT_NE(mapID, 0); } @@ -3330,7 +3343,7 @@ HWTEST_F(AccessTokenKitTest, GetAllNativeTokenInfo001, TestSize.Level1) HWTEST_F(AccessTokenKitTest, SetRemoteNativeTokenInfo001, TestSize.Level1) { ACCESSTOKEN_LOG_INFO(LABEL, "SetRemoteNativeTokenInfo001 start."); - std::string deviceID = "ea82205d1f9964346ee12e17ec0f362bb7203fca7c62d82899ffa917f9cbe6b2"; + std::string deviceID = udid_; NativeTokenInfoForSync native1 = { .baseInfo.apl = APL_NORMAL, diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.h b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.h index b419cd90d..2328ec147 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.h +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.h @@ -25,6 +25,7 @@ static const std::string TEST_BUNDLE_NAME = "ohos"; static const std::string TEST_PERMISSION_NAME_ALPHA = "ohos.permission.ALPHA"; static const std::string TEST_PERMISSION_NAME_BETA = "ohos.permission.BETA"; static const std::string TEST_PERMISSION_NAME_GAMMA = "ohos.permission.GAMMA"; +static const std::string TEST_PKG_NAME = "com.softbus.test"; static const int TEST_USER_ID = 0; static const int TEST_USER_ID_INVALID = -1; static const unsigned int TEST_TOKENID_INVALID = 0; @@ -50,6 +51,8 @@ public: void DeleteTestToken() const; void AllocTestToken() const; uint64_t selfTokenId_; + std::string udid_; + std::string networkId_; }; } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/BUILD.gn b/services/accesstokenmanager/BUILD.gn index 8589a6b43..a2095d564 100644 --- a/services/accesstokenmanager/BUILD.gn +++ b/services/accesstokenmanager/BUILD.gn @@ -89,6 +89,7 @@ ohos_shared_library("accesstoken_manager_service") { external_deps = [ "device_manager_base:devicemanagersdk", + "dsoftbus_standard:softbus_client", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h b/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h index 0fbd98245..0620800f0 100644 --- a/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h +++ b/services/accesstokenmanager/main/cpp/include/token/accesstoken_info_manager.h @@ -32,6 +32,9 @@ namespace OHOS { namespace Security { namespace AccessToken { +static const std::string ACCESS_TOKEN_PACKAGE_NAME = "ohos.security.distributed_token_sync"; +static const int UDID_MAX_LENGTH = 128; // udid/uuid max length + class AccessTokenInfoManager final { public: static AccessTokenInfoManager& GetInstance(); @@ -66,6 +69,7 @@ public: int DeleteRemoteToken(const std::string& deviceID, AccessTokenID tokenID); AccessTokenID GetRemoteNativeTokenID(const std::string& deviceID, AccessTokenID tokenID); int DeleteRemoteDeviceTokens(const std::string& deviceID); + std::string GetUdidByNodeId(const std::string &nodeId); #endif private: diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp index e02ff4abc..8f885455c 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp @@ -41,7 +41,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); -const std::string ACCESS_TOKEN_PACKAGE_NAME = "ohos.security.distributed_token_sync"; + const int32_t RETRY_SLEEP_TIME_MS = 1000; AccessTokenManagerService::AccessTokenManagerService() diff --git a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp index 08bb0c909..0db86d487 100644 --- a/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/accesstoken_info_manager.cpp @@ -15,6 +15,7 @@ #include "accesstoken_info_manager.h" +#include #include "accesstoken_id_manager.h" #include "accesstoken_log.h" #include "accesstoken_remote_token_manager.h" @@ -26,6 +27,7 @@ #include "hap_token_info_inner.h" #include "permission_definition_cache.h" #include "permission_manager.h" +#include "softbus_bus_center.h" #ifdef TOKEN_SYNC_ENABLE #include "token_modify_notifier.h" @@ -811,6 +813,20 @@ int AccessTokenInfoManager::DeleteRemoteDeviceTokens(const std::string& deviceID return RET_SUCCESS; } +std::string AccessTokenInfoManager::GetUdidByNodeId(const std::string &nodeId) +{ + uint8_t info[UDID_MAX_LENGTH + 1] = {0}; + + int32_t ret = ::GetNodeKeyInfo(ACCESS_TOKEN_PACKAGE_NAME.c_str(), nodeId.c_str(), + NodeDeviceInfoKey::NODE_KEY_UDID, info, UDID_MAX_LENGTH); + if (ret != RET_SUCCESS) { + ACCESSTOKEN_LOG_WARN(LABEL, "GetNodeKeyInfo error, code: %{public}d", ret); + return ""; + } + std::string udid(reinterpret_cast(info)); + return udid; +} + AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remoteDeviceID, AccessTokenID remoteTokenID) { @@ -818,19 +834,21 @@ AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remot ACCESSTOKEN_LOG_ERROR(LABEL, "device %{public}s parms invalid", remoteDeviceID.c_str()); return 0; } - AccessTokenID mapID = AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(remoteDeviceID, + std::string remoteUdid = GetUdidByNodeId(remoteDeviceID); + ACCESSTOKEN_LOG_ERROR(LABEL, "device %{public}s remoteUdid", remoteUdid.c_str()); + AccessTokenID mapID = AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(remoteUdid, remoteTokenID); if (mapID != 0) { return mapID; } - int ret = TokenSyncKit::GetRemoteHapTokenInfo(remoteDeviceID, remoteTokenID); + int ret = TokenSyncKit::GetRemoteHapTokenInfo(remoteUdid, remoteTokenID); if (ret != RET_SUCCESS) { ACCESSTOKEN_LOG_ERROR(LABEL, "device %{public}s token %{public}u sync failed", - remoteDeviceID.c_str(), remoteTokenID); + remoteUdid.c_str(), remoteTokenID); return 0; } - return AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(remoteDeviceID, remoteTokenID); + return AccessTokenRemoteTokenManager::GetInstance().GetDeviceMappingTokenID(remoteUdid, remoteTokenID); } #else AccessTokenID AccessTokenInfoManager::AllocLocalTokenID(const std::string& remoteDeviceID, diff --git a/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp b/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp index 2e5bc8fee..396ceaa21 100644 --- a/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp +++ b/services/tokensyncmanager/test/unittest/token_sync_service/token_sync_service_test.cpp @@ -129,43 +129,6 @@ void SendTaskThread() free(sendBuffer); } -/** - * @tc.name: GetRemoteHapTokenInfo001 - * @tc.desc: test remote hap send func - * @tc.type: FUNC - * @tc.require:AR000GK6T5 AR000GK6T9 - */ -HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo001, TestSize.Level1) -{ - ACCESSTOKEN_LOG_INFO(LABEL, "GetRemoteHapTokenInfo001 start."); - g_jsonBefore = "{\"commandName\":\"SyncRemoteHapTokenCommand\", \"id\":\""; - g_jsonAfter = - "\",\"jsonPayload\":\"{\\\"HapTokenInfo\\\":{\\\"apl\\\":1,\\\"appID\\\":" - "\\\"test\\\",\\\"bundleName\\\":\\\"mock_token_sync\\\",\\\"deviceID\\\":" - "\\\"111111\\\",\\\"instIndex\\\":0,\\\"dlpType\\\":0,\\\"permState\\\":" - "null,\\\"tokenAttr\\\":0,\\\"tokenID\\\":537919488," - "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," - "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" - ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," - "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; - - threads_.emplace_back(std::thread(SendTaskThread)); - - g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); - - int ret = OHOS::DelayedSingleton::GetInstance()->GetRemoteHapTokenInfo( - g_UDID, 0x20100000); - ASSERT_EQ(ret, RET_SUCCESS); - - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20100000); - ASSERT_NE(mapID, (AccessTokenID)0); - - HapTokenInfo tokeInfo; - ret = AccessTokenKit::GetHapTokenInfo(mapID, tokeInfo); - ASSERT_EQ(ret, RET_SUCCESS); -} - static PermissionDef g_infoManagerTestPermDef1 = { .permissionName = "ohos.permission.test1", .bundleName = "accesstoken_test", @@ -287,7 +250,8 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo003, TestSize.Level1) "\\\"test\\\",\\\"bundleName\\\":\\\"mock_token_sync\\\",\\\"deviceID\\\":" "\\\"111111\\\",\\\"instIndex\\\":0,\\\"permState\\\":null,\\\"tokenAttr\\\":0,\\\"tokenID\\\":537919488," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\"," + "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -319,7 +283,8 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo004, TestSize.Level1) "\\\"test\\\",\\\"bundleName\\\":\\\"mock_token_sync\\\",\\\"deviceID\\\":" "\\\"111111\\\",\\\"permState\\\":null,\\\"tokenAttr\\\":0," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\"," + "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -352,7 +317,8 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo005, TestSize.Level1) "\\\"111111\\\",\\\"instIndex\\\":1,\\\"permState\\\":null,\\\"tokenAttr\\\":0," "\\\"tokenID\\\":\\\"aaa\\\"," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\"," + "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -385,7 +351,8 @@ HWTEST_F(TokenSyncServiceTest, GetRemoteHapTokenInfo006, TestSize.Level1) "\\\"111111\\\",\\\"instIndex\\\":1,\\\"permState\\\":null,\\\"tokenAttr\\\":0," "\\\"tokenID\\\":537919488," "\\\"userID\\\":0,\\\"version\\\":1},\\\"commandName\\\":\\\"SyncRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\"," + "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestTokenId\\\":537919488,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"" ",\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\",\\\"srcDeviceLevel\\\":\\\"\\\"," "\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteHapTokenCommand\\\"}\",\"type\":\"response\"}"; @@ -502,7 +469,8 @@ HWTEST_F(TokenSyncServiceTest, SyncNativeTokens001, TestSize.Level1) "{\\\"apl\\\":3,\\\"processName\\\":\\\"attest1\\\",\\\"tokenAttr\\\":0,\\\"tokenId\\\":671088641," "\\\"version\\\":1,\\\"dcaps\\\":[\\\"SYSDCAP\\\",\\\"DMSDCAP\\\"]}]," "\\\"commandName\\\":\\\"SyncRemoteNativeTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," + "\\\"dstDeviceId\\\":\\\"deviceid-1:udid-001\\\"," + "\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," "\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"deviceid-1:udid-001\\\"," "\\\"responseVersion\\\":2,\\\"srcDeviceId\\\":\\\"local:udid-001\\\"," "\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":0,\\\"uniqueId\\\":\\\"SyncRemoteNativeTokenCommand\\\"}\"," @@ -713,157 +681,3 @@ HapTokenInfoForSync g_remoteHapInfo = { .permStateList = {g_infoManagerTestUpdateState1, g_infoManagerTestUpdateState2} }; } - -/** - * @tc.name: UpdateRemoteHapTokenCommand001 - * @tc.desc: recv mapping hap token update message - * @tc.type: FUNC - * @tc.require:AR000GK6TB - */ -HWTEST_F(TokenSyncServiceTest, UpdateRemoteHapTokenCommand001, TestSize.Level1) -{ - ACCESSTOKEN_LOG_INFO(LABEL, "UpdateRemoteHapTokenCommand001 start."); - sleep(1); - g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); - sleep(6); - - int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_UDID, g_remoteHapInfo); - ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20000001); - ASSERT_NE(mapID, 0); - - HapTokenInfo mapInfo; - ret = AccessTokenKit::GetHapTokenInfo(mapID, mapInfo); - ASSERT_EQ(ret, RET_SUCCESS); - - ret = AccessTokenKit::VerifyAccessToken(mapID, "ohos.permission.CAMERA"); - ASSERT_EQ(ret, PERMISSION_DENIED); - - std::string recvJson = - "{\"commandName\":\"UpdateRemoteHapTokenCommand\",\"id\":\"ec23cd2d-\",\"jsonPayload\":" - "\"{\\\"HapTokenInfos\\\":{\\\"apl\\\":1,\\\"appID\\\":\\\"testtesttesttest\\\"," - "\\\"bundleName\\\":\\\"accesstoken_test\\\",\\\"deviceID\\\":\\\"0\\\",\\\"instIndex\\\":0,\\\"dlpType\\\":0," - "\\\"permState\\\":[{\\\"grantConfig\\\":[{\\\"grantFlags\\\":2,\\\"grantStatus\\\":0," - "\\\"resDeviceID\\\":\\\"local\\\"}],\\\"isGeneral\\\":true," - "\\\"permissionName\\\":\\\"ohos.permission.CAMERA\\\"},{\\\"grantConfig\\\":[{\\\"grantFlags\\\":1," - "\\\"grantStatus\\\":-1,\\\"resDeviceID\\\":\\\"device 1\\\"},{\\\"grantFlags\\\":2,\\\"grantStatus\\\":-1," - "\\\"resDeviceID\\\":\\\"device 2\\\"}],\\\"isGeneral\\\":false," - "\\\"permissionName\\\":\\\"ohos.permission.ANSWER_CALL\\\"}],\\\"tokenAttr\\\":0,\\\"tokenID\\\":536870913," - "\\\"userID\\\":1,\\\"version\\\":1},\\\"commandName\\\":\\\"UpdateRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"local:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," - "\\\"requestTokenId\\\":536870913,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"\\\"," - "\\\"responseVersion\\\":2," - "\\\"srcDeviceId\\\":\\\"deviceid-1\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001," - "\\\"uniqueId\\\":\\\"UpdateRemoteHapTokenCommand\\\"}\",\"type\":\"request\"}"; - - unsigned char *recvBuffer = (unsigned char *)malloc(0x1000); - int recvLen = 0x1000; - CompressMock(recvJson, recvBuffer, recvLen); - SoftBusSessionListener::OnBytesReceived(1, recvBuffer, recvLen); - sleep(2); - - free(recvBuffer); - - ret = AccessTokenKit::VerifyAccessToken(mapID, "ohos.permission.CAMERA"); - - ASSERT_EQ(ret, PERMISSION_GRANTED); - - recvJson = - "{\"commandName\":\"UpdateRemoteHapTokenCommand\",\"id\":\"ec23cd2d-\",\"jsonPayload\":" - "\"{\\\"HapTokenInfos\\\":{\\\"apl\\\":2,\\\"appID\\\":\\\"testtesttesttest\\\"," - "\\\"bundleName\\\":\\\"accesstoken_test\\\",\\\"deviceID\\\":\\\"0\\\",\\\"instIndex\\\":0,\\\"dlpType\\\":0," - "\\\"permState\\\":[{\\\"grantConfig\\\":[{\\\"grantFlags\\\":2,\\\"grantStatus\\\":0," - "\\\"resDeviceID\\\":\\\"local\\\"}],\\\"isGeneral\\\":true," - "\\\"permissionName\\\":\\\"ohos.permission.CAMERA\\\"},{\\\"grantConfig\\\":[{\\\"grantFlags\\\":1," - "\\\"grantStatus\\\":-1,\\\"resDeviceID\\\":\\\"device 1\\\"},{\\\"grantFlags\\\":2,\\\"grantStatus\\\":-1," - "\\\"resDeviceID\\\":\\\"device 2\\\"}],\\\"isGeneral\\\":false," - "\\\"permissionName\\\":\\\"ohos.permission.ANSWER_CALL\\\"}],\\\"tokenAttr\\\":0,\\\"tokenID\\\":536870913," - "\\\"userID\\\":1,\\\"version\\\":1},\\\"commandName\\\":\\\"UpdateRemoteHapTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"local:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," - "\\\"requestTokenId\\\":536870913,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"\\\"," - "\\\"responseVersion\\\":2," - "\\\"srcDeviceId\\\":\\\"deviceid-1\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001," - "\\\"uniqueId\\\":\\\"UpdateRemoteHapTokenCommand\\\"}\",\"type\":\"request\"}"; - - recvBuffer = (unsigned char *)malloc(0x1000); - recvLen = 0x1000; - CompressMock(recvJson, recvBuffer, recvLen); - SoftBusSessionListener::OnBytesReceived(1, recvBuffer, recvLen); - sleep(2); - free(recvBuffer); - - ret = AccessTokenKit::GetHapTokenInfo(mapID, mapInfo); - ASSERT_EQ(ret, RET_SUCCESS); - ASSERT_EQ(mapInfo.apl, 2); -} - -/** - * @tc.name: DeleteRemoteTokenCommand001 - * @tc.desc: recv delete mapping hap token update message - * @tc.type: FUNC - * @tc.require:AR000GK6TC - */ -HWTEST_F(TokenSyncServiceTest, DeleteRemoteTokenCommand001, TestSize.Level1) -{ - ACCESSTOKEN_LOG_INFO(LABEL, "DeleteRemoteTokenCommand001 start."); - - g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); - - int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_UDID, g_remoteHapInfo); - ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20000001); - ASSERT_NE(mapID, 0); - - HapTokenInfo mapInfo; - ret = AccessTokenKit::GetHapTokenInfo(mapID, mapInfo); - ASSERT_EQ(ret, RET_SUCCESS); - - // create recv message - std::string recvJson = - "{\"commandName\":\"DeleteRemoteTokenCommand\",\"id\":\"9ff19cdf-\",\"jsonPayload\":" - "\"{\\\"commandName\\\":\\\"DeleteRemoteTokenCommand\\\"," - "\\\"dstDeviceId\\\":\\\"local:udid-001\\\",\\\"dstDeviceLevel\\\":\\\"\\\",\\\"message\\\":\\\"success\\\"," - "\\\"requestTokenId\\\":536870913,\\\"requestVersion\\\":2,\\\"responseDeviceId\\\":\\\"\\\"," - "\\\"responseVersion\\\":2," - "\\\"srcDeviceId\\\":\\\"deviceid-1\\\",\\\"srcDeviceLevel\\\":\\\"\\\",\\\"statusCode\\\":100001," - "\\\"tokenId\\\":536870913,\\\"uniqueId\\\":\\\"DeleteRemoteTokenCommand\\\"}\",\"type\":\"request\"}"; - - unsigned char *recvBuffer = (unsigned char *)malloc(0x1000); - int recvLen = 0x1000; - CompressMock(recvJson, recvBuffer, recvLen); - SoftBusSessionListener::OnBytesReceived(1, recvBuffer, recvLen); - sleep(2); - free(recvBuffer); - ret = AccessTokenKit::GetHapTokenInfo(mapID, mapInfo); - ASSERT_EQ(ret, RET_FAILED); -} - -/** - * @tc.name: DeviceOffline001 - * @tc.desc: test device offline, will delete - * @tc.type: FUNC - * @tc.require:AR000GK6TB - */ -HWTEST_F(TokenSyncServiceTest, DeviceOffline001, TestSize.Level1) -{ - ACCESSTOKEN_LOG_INFO(LABEL, "DeviceOffline001 start."); - - // device online - g_ptrDeviceStateCallback->OnDeviceOnline(g_devInfo); - - int ret = AccessTokenKit::SetRemoteHapTokenInfo(g_UDID, g_remoteHapInfo); - ASSERT_EQ(ret, RET_SUCCESS); - AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(g_UDID, 0x20000001); - ASSERT_NE(mapID, 0); - - HapTokenInfo mapInfo; - ret = AccessTokenKit::GetHapTokenInfo(mapID, mapInfo); - ASSERT_EQ(ret, RET_SUCCESS); - - OnDeviceOffline(g_devInfo); - sleep(1); - - ret = AccessTokenKit::GetHapTokenInfo(mapID, mapInfo); - ASSERT_EQ(ret, RET_FAILED); - -} -- Gitee