diff --git a/services/dtbschedmgr/test/cfi_blocklist.txt b/services/dtbschedmgr/test/cfi_blocklist.txt index 27246388..12542b76 100644 --- a/services/dtbschedmgr/test/cfi_blocklist.txt +++ b/services/dtbschedmgr/test/cfi_blocklist.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2023 Huawei Device Co., Ltd. +# Copyright (C) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_continuation_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_continuation_test.cpp index b335a8ad..b24ab8b1 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_continuation_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_continuation_test.cpp @@ -356,6 +356,7 @@ HWTEST_F(DSchedContinuationTest, SetWantForContinuation_002, TestSize.Level1) * @tc.steps: step1. input valid bundleName. * @tc.expected: step1. return OK. */ + DistributedSchedUtil::MockBundlePermission(); std::string bundleName = "com.ohos.mms"; std::string abilityName = "bmsThirdBundle"; std::shared_ptr spWant = MockWant(bundleName, abilityName, 0); diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.cpp index b453f2c7..301cad13 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.cpp @@ -77,29 +77,6 @@ void NativeTokenGet() ASSERT_NE(tokenId, 0); SetSelfTokenID(tokenId); } - -void EnablePermissionAccess(const char* perms[], size_t permsNum, uint64_t &tokenId) -{ - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = permsNum, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .aplStr = "system_basic", - }; - - infoInstance.processName = "DistributedSchedPermissionTest"; - tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); -} - -void DisablePermissionAccess(const uint64_t &tokenId) -{ - OHOS::Security::AccessToken::AccessTokenKit::DeleteToken(tokenId); -} } void DistributedSchedPermissionTest::SetUpTestCase() @@ -118,16 +95,11 @@ void DistributedSchedPermissionTest::TearDownTestCase() void DistributedSchedPermissionTest::TearDown() { DTEST_LOG << "DistributedSchedPermissionTest::TearDown" << std::endl; - DisablePermissionAccess(tokenId_); } void DistributedSchedPermissionTest::SetUp() { DTEST_LOG << "DistributedSchedPermissionTest::SetUp" << std::endl; - const char* perms[] = { - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - }; - EnablePermissionAccess(perms, sizeof(perms) / sizeof(perms[0]), tokenId_); DistributedSchedUtil::MockPermission(); DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId_); @@ -485,6 +457,7 @@ HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_001, TestSize.Level3) HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_002, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_002 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; ElementName name; name.SetAbilityName(ABILITY_NAME); @@ -505,6 +478,7 @@ HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_002, TestSize.Level3) HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_003, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_003 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; ElementName name; name.SetAbilityName(ABILITY_NAME); @@ -526,6 +500,7 @@ HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_003, TestSize.Level3) HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_004, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_004 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; ElementName name; name.SetAbilityName(ABILITY_NAME); @@ -546,6 +521,7 @@ HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_004, TestSize.Level3) HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_005, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_005 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; ElementName name; name.SetAbilityName(ABILITY_NAME); @@ -567,6 +543,7 @@ HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_005, TestSize.Level3) HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_006, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_006 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; ElementName name; name.SetAbilityName(ABILITY_NAME); @@ -589,6 +566,7 @@ HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_006, TestSize.Level3) HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_007, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_007 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; ElementName name; name.SetAbilityName(ABILITY_NAME); @@ -651,6 +629,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_002, TestSize. HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_003, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_003 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; CallerInfo callerInfo; bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId); @@ -951,6 +930,7 @@ HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_011, TestSi HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_012, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_012 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AppExecFwk::AbilityInfo targetAbility; targetAbility.visible = true; targetAbility.type = AppExecFwk::AbilityType::SERVICE; @@ -2222,6 +2202,7 @@ HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_002, TestSize.Level3) HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_003, TestSize.Level3) { DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_003 begin" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION); want.SetUri("file://com.ohos.mms/data/test_B"); diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.h b/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.h index c8d49644..7210d657 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.h +++ b/services/dtbschedmgr/test/unittest/distributed_sched_permission_test.h @@ -29,7 +29,6 @@ public: void TearDown(); std::string deviceId_; - uint64_t tokenId_; protected: class DeviceInitCallBack : public OHOS::DistributedHardware::DmInitCallback { diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp index a144a44f..ec0f67b9 100755 --- a/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_service_test.cpp @@ -1894,6 +1894,7 @@ HWTEST_F(DistributedSchedServiceTest, ConnectAbilityFromRemote_001, TestSize.Lev HWTEST_F(DistributedSchedServiceTest, ConnectAbilityFromRemote_002, TestSize.Level3) { DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_002 start" << std::endl; + DistributedSchedUtil::MockBundlePermission(); AAFwk::Want want; std::string localDeviceId; DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId); diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_util.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_util.cpp index 9b0c332d..0b9f4f72 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_util.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_util.cpp @@ -94,6 +94,14 @@ void DistributedSchedUtil::MockPermission() MockProcessAndPermission(DISTSCHED_PROCESS_NAME, PERMS, PERMS_NUM); } +void DistributedSchedUtil::MockBundlePermission() +{ + static const char *PERMS[] = { + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }; + MockProcessAndPermission("DistributedSchedPermissionTest", PERMS, sizeof(PERMS) / sizeof(PERMS[0])); +} + void DistributedSchedUtil::MockProcess(const char* processName) { MockProcessAndPermission(processName); diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_util.h b/services/dtbschedmgr/test/unittest/distributed_sched_util.h index c35e0dc6..b5ef9390 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_util.h +++ b/services/dtbschedmgr/test/unittest/distributed_sched_util.h @@ -28,6 +28,7 @@ namespace DistributedSchedule { class DistributedSchedUtil { public: static void MockPermission(); + static void MockBundlePermission(); static void MockProcess(const char* processName); static void MockProcessAndPermission(const char* processName, const char *perms[] = nullptr, int32_t permsNum = 0); diff --git a/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp b/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp index f7be9ff7..6c1f7c1f 100644 --- a/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp +++ b/services/dtbschedmgr/test/unittest/dms_network_adapter_test.cpp @@ -21,6 +21,7 @@ #define private public #include "adapter/dnetwork_adapter.h" #undef private +#include "distributed_sched_util.h" #include "dtbschedmgr_device_info_storage.h" using namespace std; @@ -381,6 +382,7 @@ HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_002, TestSize.Level3) */ HWTEST_F(DMSNetworkAdapterTest, UpdateDeviceInfoStorage_001, TestSize.Level3) { + DistributedSchedUtil::MockBundlePermission(); bool result = DnetworkAdapter::GetInstance()->UpdateDeviceInfoStorage(); EXPECT_EQ(result, true); } diff --git a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp index 9c7e7231..f0c27480 100644 --- a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp +++ b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp @@ -203,6 +203,7 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetDeviceIdSetTest_001, TestSize.Leve HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetLocalDeviceFromDnetTest_001, TestSize.Level3) { DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetLocalDeviceFromDnetTest_001 start" << std::endl; + DistributedSchedUtil::MockBundlePermission(); std::string deviceId; /** * @tc.steps: step1. test GetLocalDeviceFromDnet;