mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 14:30:21 +00:00
commit
84f1b38f2c
@ -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
|
||||
|
@ -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<Want> spWant = MockWant(bundleName, abilityName, 0);
|
||||
|
@ -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");
|
||||
|
@ -29,7 +29,6 @@ public:
|
||||
void TearDown();
|
||||
|
||||
std::string deviceId_;
|
||||
uint64_t tokenId_;
|
||||
|
||||
protected:
|
||||
class DeviceInitCallBack : public OHOS::DistributedHardware::DmInitCallback {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user