From 431761a3d6ef6d98fc1418efcd1409f8291c602d Mon Sep 17 00:00:00 2001 From: Lotol Date: Thu, 17 Aug 2023 12:17:56 +0000 Subject: [PATCH] =?UTF-8?q?fixed=207785b36=20from=20https://gitee.com/loto?= =?UTF-8?q?l/bundlemanager=5Fdistributed=5Fbundle=5Fframework/pulls/26=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E7=94=A8=E4=BE=8B=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lotol Change-Id: Ic6ba7c6bffecbc257e370653083a7d81cc916a1d --- .../unittest/dbms_services_kit_test/BUILD.gn | 5 ++ .../dbms_services_kit_test.cpp | 46 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn b/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn index 858e0d2..8b8a249 100644 --- a/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn +++ b/services/dbms/test/unittest/dbms_services_kit_test/BUILD.gn @@ -40,6 +40,8 @@ ohos_unittest("DbmsServicesKitTest") { external_deps = [ "ability_base:want", "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", @@ -59,6 +61,9 @@ ohos_unittest("DbmsServicesKitTest") { "samgr:samgr_proxy", ] defines = [] + if (current_cpu == "arm64") { + defines += [ "USE_NO_LAUNCHER" ] + } if (hisysevent_enable_dbms) { sources += [ "${dbms_services_path}/src/event_report.cpp" ] diff --git a/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp b/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp index 84ff533..92ebeae 100644 --- a/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp +++ b/services/dbms/test/unittest/dbms_services_kit_test/dbms_services_kit_test.cpp @@ -22,6 +22,7 @@ #include #include +#include "accesstoken_kit.h" #include "appexecfwk_errors.h" #include "dbms_device_manager.h" #include "distributed_ability_info.h" @@ -34,7 +35,10 @@ #include "event_report.h" #include "image_compress.h" #include "json_util.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" #include "service_control.h" +#include "softbus_common.h" using namespace testing::ext; using namespace std::chrono_literals; @@ -93,6 +97,26 @@ void DbmsServicesKitTest::TearDownTestCase() void DbmsServicesKitTest::SetUp() { + const int32_t PERMS_NUM = 3; + const int32_t PERMS_INDEX_TWO = 2; + uint64_t tokenId; + const char *perms[PERMS_NUM]; + perms[0] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER; + perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC; + perms[PERMS_INDEX_TWO] = "ohos.permission.ACCESS_SERVICE_DM"; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = PERMS_NUM, + .aclsNum = 0, + .dcaps = NULL, + .perms = perms, + .acls = NULL, + .processName = "dsoftbus_service", + .aplStr = "system_core", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); + OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); std::string strExtra = std::to_string(402); auto extraArgv = strExtra.c_str(); ServiceControlWithExtra("d-bms", START, &extraArgv, 1); @@ -279,7 +303,11 @@ HWTEST_F(DbmsServicesKitTest, DbmsServicesKitTest_0007, Function | SmallTest | L name.SetAbilityName(WRONG_ABILITY_NAME); RemoteAbilityInfo info; auto ret = distributedBms->GetAbilityInfo(name, info); + #ifdef USE_NO_LAUNCHER + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_APPLICATION_DISABLED); + #else EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST); + #endif } } @@ -300,7 +328,11 @@ HWTEST_F(DbmsServicesKitTest, DbmsServicesKitTest_0008, Function | SmallTest | L name.SetAbilityName(ABILITY_NAME); RemoteAbilityInfo info; auto ret = distributedBms->GetAbilityInfo(name, info); + #ifdef USE_NO_LAUNCHER + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_APPLICATION_DISABLED); + #else EXPECT_EQ(ret, ERR_OK); + #endif } } @@ -322,7 +354,11 @@ HWTEST_F(DbmsServicesKitTest, DbmsServicesKitTest_0009, Function | SmallTest | L name.SetAbilityName(WRONG_ABILITY_NAME); RemoteAbilityInfo info; auto ret = distributedBms->GetAbilityInfo(name, info); + #ifdef USE_NO_LAUNCHER + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_APPLICATION_DISABLED); + #else EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST); + #endif } } @@ -365,7 +401,11 @@ HWTEST_F(DbmsServicesKitTest, DbmsServicesKitTest_0011, Function | SmallTest | L names.push_back(name); std::vector infos; auto ret = distributedBms->GetAbilityInfos(names, infos); + #ifdef USE_NO_LAUNCHER + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_APPLICATION_DISABLED); + #else EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST); + #endif } } @@ -388,7 +428,11 @@ HWTEST_F(DbmsServicesKitTest, DbmsServicesKitTest_0012, Function | SmallTest | L names.push_back(name); std::vector infos; auto ret = distributedBms->GetAbilityInfos(names, infos); + #ifdef USE_NO_LAUNCHER + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_APPLICATION_DISABLED); + #else EXPECT_EQ(ret, ERR_OK); + #endif } } @@ -1525,6 +1569,6 @@ HWTEST_F(DbmsServicesKitTest, VerifyCallingPermission_0200, Function | MediumTes auto distributedBms = GetDistributedBms(); EXPECT_NE(distributedBms, nullptr); int res = distributedBms->VerifyCallingPermission(""); - EXPECT_FALSE(res); + EXPECT_TRUE(res); } } // OHOS \ No newline at end of file -- Gitee