From ff1e4e8ddbf17296e425f435cbbd677be1d1a564 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Jan 2025 20:05:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=A5=97=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: unknown --- test/unittest/BUILD.gn | 8 +++++++ .../device_usage_statistics_multi_test.cpp | 21 +++++++++++++++++ .../device_usage_statistics_service_test.cpp | 21 +++++++++++++++++ .../unittest/device_usage_statistics_test.cpp | 23 ++++++++++++++++++- 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 704188e..a0ab21e 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -95,6 +95,9 @@ ohos_unittest("DeviceUsageStatsTest") { ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "eventhandler:libeventhandler", "ffrt:libffrt", @@ -129,6 +132,9 @@ ohos_unittest("DeviceUsageStatsMultiTest") { ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "eventhandler:libeventhandler", "ffrt:libffrt", @@ -166,6 +172,8 @@ ohos_unittest("DeviceUsageStatsServiceTest") { "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", diff --git a/test/unittest/device_usage_statistics_multi_test.cpp b/test/unittest/device_usage_statistics_multi_test.cpp index 01e908f..2c37a5e 100644 --- a/test/unittest/device_usage_statistics_multi_test.cpp +++ b/test/unittest/device_usage_statistics_multi_test.cpp @@ -32,12 +32,16 @@ #include "app_group_callback_proxy.h" #include "bundle_active_log.h" #include "iapp_group_callback.h" +#include "accesstoken_kit.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" using namespace testing::ext; using namespace testing::mt; namespace OHOS { namespace DeviceUsageStats { +using namespace Security::AccessToken; #ifdef __aarch64__ static std::string g_defaultBundleName = "com.huawei.hmos.camera"; #else @@ -67,6 +71,23 @@ public: void DeviceUsageStatisticsMultiTest::SetUpTestCase(void) { + static const char *perms[] = { + "ohos.permission.BUNDLE_ACTIVE_INFO", + }; + uint64_t tokenId; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "DeviceUsageStatisticsMultiTest", + .aplStr = "system_core", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + AccessTokenKit::ReloadNativeTokenInfo(); } void DeviceUsageStatisticsMultiTest::TearDownTestCase(void) diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp index 134203b..f45ba49 100644 --- a/test/unittest/device_usage_statistics_service_test.cpp +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -29,11 +29,15 @@ #include "bundle_active_group_controller.h" #include "bundle_active_log.h" #include "bundle_active_config_reader.h" +#include "accesstoken_kit.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" using namespace testing::ext; namespace OHOS { namespace DeviceUsageStats { +using namespace Security::AccessToken; class DeviceUsageStatisticsServiceTest : public testing::Test { public: static void SetUpTestCase(void); @@ -47,6 +51,23 @@ std::shared_ptr DeviceUsageStatisticsServiceTest::bundleActive void DeviceUsageStatisticsServiceTest::SetUpTestCase(void) { + static const char *perms[] = { + "ohos.permission.BUNDLE_ACTIVE_INFO", + }; + uint64_t tokenId; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "DeviceUsageStatisticsServiceTest", + .aplStr = "system_core", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + AccessTokenKit::ReloadNativeTokenInfo(); bundleActiveCore_ = std::make_shared(); bundleActiveCore_->Init(); bundleActiveCore_->InitBundleGroupController(); diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 63e75e7..20783e9 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -30,11 +30,15 @@ #include "app_group_callback_proxy.h" #include "iapp_group_callback.h" #include "bundle_active_log.h" +#include "accesstoken_kit.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" using namespace testing::ext; namespace OHOS { namespace DeviceUsageStats { +using namespace Security::AccessToken; #ifdef __aarch64__ static std::string g_defaultBundleName = "com.huawei.hmos.camera"; #else @@ -62,6 +66,23 @@ public: void DeviceUsageStatisticsTest::SetUpTestCase(void) { + static const char *perms[] = { + "ohos.permission.BUNDLE_ACTIVE_INFO", + }; + uint64_t tokenId; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = perms, + .acls = nullptr, + .processName = "DeviceUsageStatisticsTest", + .aplStr = "system_core", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + AccessTokenKit::ReloadNativeTokenInfo(); } void DeviceUsageStatisticsTest::TearDownTestCase(void) @@ -205,7 +226,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_IsBundleUsePeriod_ bool result = false; int32_t errCode = BundleActiveClient::GetInstance().IsBundleUsePeriod(result, g_defaultBundleName, g_defaultUserId); EXPECT_EQ(result, false); - EXPECT_EQ(errCode, ERR_PERMISSION_DENIED); + EXPECT_EQ(errCode, 0); } /* -- Gitee From ca8b4c8b3876b5189d52b8d5f4c062d85a78946a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Jan 2025 14:17:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0cfi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: unknown --- test/unittest/BUILD.gn | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index a0ab21e..e3b3062 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -74,6 +74,13 @@ ohos_unittest("BundleActiveTotalTest") { defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ] external_deps += [ "power_manager:powermgr_client" ] } + branch_protector_ret = "pac_ret" + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } } ohos_unittest("DeviceUsageStatsTest") { @@ -111,6 +118,13 @@ ohos_unittest("DeviceUsageStatsTest") { defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ] external_deps += [ "power_manager:powermgr_client" ] } + branch_protector_ret = "pac_ret" + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } } ohos_unittest("DeviceUsageStatsMultiTest") { @@ -148,6 +162,13 @@ ohos_unittest("DeviceUsageStatsMultiTest") { defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ] external_deps += [ "power_manager:powermgr_client" ] } + branch_protector_ret = "pac_ret" + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } } ohos_unittest("DeviceUsageStatsServiceTest") { @@ -248,6 +269,13 @@ ohos_unittest("DeviceUsageStatsMockTest") { defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ] external_deps += [ "power_manager:powermgr_client" ] } + branch_protector_ret = "pac_ret" + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } } ohos_unittest("DeviceUsagePackageUsageTest") { @@ -290,6 +318,13 @@ ohos_unittest("DeviceUsagePackageUsageTest") { defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ] external_deps += [ "power_manager:powermgr_client" ] } + branch_protector_ret = "pac_ret" + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } } group("unittest") { -- Gitee