!641 【distributedhardware】【master】分布式Dp用例添加权限

Merge pull request !641 from bjliang/master
This commit is contained in:
openharmony_ci 2024-05-10 07:38:52 +00:00 committed by Gitee
commit b968b0f1b5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 37 additions and 2 deletions

View File

@ -40,6 +40,9 @@ ohos_moduletest_suite("SubDctsDistributedDpTest") {
"$base_root/foundation/deviceprofile/device_info_manager/common/include/interfaces",
"$base_root/foundation/deviceprofile/device_info_manager/common/include/utils",
"$base_root/foundation/deviceprofile/device_info_manager/radar/include",
"$base_root/base/security/access_token/interfaces/innerkits/accesstoke/include",
"$base_root/base/security/access_token/interfaces/innerkits/nativetoken/include",
"$base_root/base/security/access_token/interfaces/innerkits/token_setproc/include",
]
sources = [ "device_profile_test.cpp" ]
@ -56,6 +59,8 @@ ohos_moduletest_suite("SubDctsDistributedDpTest") {
]
deps = [
"$base_root/base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken",
"$base_root/base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc",
"$base_root/foundation/deviceprofile/device_info_manager/common:distributed_device_profile_common",
"$base_root/foundation/deviceprofile/device_info_manager/interfaces/innerkits/core:distributed_device_profile_sdk",
"$base_root/foundation/deviceprofile/device_info_manager/services/core:distributed_device_profile_svr",

View File

@ -34,6 +34,9 @@
#include "device_profile_manager.h"
#include "kv_adapter.h"
#include "profile_cache.h"
#include "accesstoken_kit.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
#undef PRIVATE
#undef PROTECTED
@ -42,6 +45,28 @@ namespace DistributedDeviceProfile {
using namespace testing::ext;
using namespace std;
void AddPermission(void)
{
const int32_t PERMS_NUM = 2;
const char *perms[PERMS_NUM] = {
"ohos.permission.DISTRIBUTED_DATASYNC",
"ohos.permission.DISTRIBUTED_SOFTBUS_CENTER"
};
uint64_t tokenId;
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = PERMS_NUM,
.aclsNum = 0,
.dcaps = nullptr,
.perms = perms,
.acls = nullptr,
.processName = "deviceprofile",
.aplStr = "system_core",
};
tokenId = GetAccessTokenId(&infoInstance);
SetSelfTokenID(tokenId);
}
class DeviceProfileManagerTest : public testing::Test {
public:
static void SetUpTestCase(void);
@ -50,7 +75,12 @@ public:
void TearDown();
};
void DeviceProfileManagerTest::SetUpTestCase(void) {
void DeviceProfileManagerTest::SetUpTestCase(void)
{
AddPermission();
sleep(1);
system("pidof accesstoken_service | xargs kill -9");
sleep(1);
}
void DeviceProfileManagerTest::TearDownTestCase(void) {
@ -858,4 +888,4 @@ HWTEST_F(DeviceProfileManagerTest, SUB_DH_DDp_Dcts_3900, TestSize.Level1)
EXPECT_EQ(errCode, DP_INVALID_PARAMS);
}
} // namespace DistributedDeviceProfile
} // namespace OHOS
} // namespace OHOS