!762 [优化]:修复UT权限问题 ,增加权限

Merge pull request !762 from 师皓杰/master
This commit is contained in:
openharmony_ci 2023-12-21 06:36:11 +00:00 committed by Gitee
commit 916ea807fd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 29 additions and 0 deletions

View File

@ -77,6 +77,29 @@ 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()
@ -95,11 +118,16 @@ 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_);

View File

@ -29,6 +29,7 @@ public:
void TearDown();
std::string deviceId_;
uint64_t tokenId_;
protected:
class DeviceInitCallBack : public OHOS::DistributedHardware::DmInitCallback {