From e2ab9c9a808760a7f19d8113d93502377df95549 Mon Sep 17 00:00:00 2001 From: nianyuu Date: Thu, 28 Aug 2025 10:44:35 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90OpenHarmony-6.0-Release=E3=80=91fix=20?= =?UTF-8?q?test=20diff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nianyuu --- appspawn.cfg | 6 +- interfaces/innerkits/client/appspawn_msg.c | 9 +- modules/common/appspawn_begetctl.c | 2 +- modules/common/appspawn_cgroup.c | 2 +- modules/common/appspawn_common.c | 9 +- modules/native_adapter/BUILD.gn | 2 +- modules/sandbox/modern/sandbox_debug_mode.c | 4 +- modules/sandbox/normal/sandbox_common.cpp | 5 +- modules/sandbox/normal/sandbox_core.cpp | 2 +- standard/appspawn_service.c | 8 +- test/BUILD.gn | 1 + test/moduletest/appspawn_client_test.cpp | 1 - test/moduletest/appspawn_test_cmder.cpp | 1 - test/moduletest/test_app_info.json | 1 - test/unittest/app_spawn_client_test/BUILD.gn | 1 - .../app_spawn_client_test.cpp | 2 +- .../unittest/app_spawn_standard_test/BUILD.gn | 106 +++++++++++++++++- .../app_spawn_appmgr_test.cpp | 8 -- .../app_spawn_common_test.cpp | 3 +- .../app_spawn_kickdog_test.cpp | 2 +- .../app_spawn_sandbox_debug_mode.cpp | 2 +- .../app_spawn_sandbox_new_debug_mode.cpp | 21 ++-- .../app_spawn_sandbox_test.cpp | 12 ++ .../app_spawn_sandboxmgr_test.cpp | 2 +- test/unittest/app_spawn_test_helper.h | 1 - util/include/appspawn_error.h | 6 +- 26 files changed, 161 insertions(+), 58 deletions(-) diff --git a/appspawn.cfg b/appspawn.cfg index 989ab65f..9759e7e8 100644 --- a/appspawn.cfg +++ b/appspawn.cfg @@ -17,9 +17,9 @@ "chown root appspawn /dev/pids", "chown root appspawn /dev/pids/tasks", "chown root appspawn /dev/pids/cgroup.procs", - "chmod 0750 /dev/pids", - "chmod 0750 /dev/pids/tasks", - "chmod 0750 /dev/pids/cgroup.procs" + "chmod 0755 /dev/pids", + "chmod 0755 /dev/pids/tasks", + "chmod 0755 /dev/pids/cgroup.procs" ] } ], diff --git a/interfaces/innerkits/client/appspawn_msg.c b/interfaces/innerkits/client/appspawn_msg.c index ab871cb7..3b7332af 100644 --- a/interfaces/innerkits/client/appspawn_msg.c +++ b/interfaces/innerkits/client/appspawn_msg.c @@ -19,7 +19,7 @@ #include "appspawn_utils.h" #include "parameter.h" #include "securec.h" - +#define OHOS_PERMISSION_FOWNER "ohos.permission.FOWNER" static inline int CalcFlagsUnits(uint32_t maxIndex) { return ((maxIndex / 32) + ((maxIndex % 32 == 0) ? 0 : 1)); // 32 max bit in uint32_t @@ -552,10 +552,17 @@ int AppSpawnClientAddPermission(AppSpawnClientHandle handle, AppSpawnReqMsgHandl APPSPAWN_CHECK(permission != NULL, return APPSPAWN_ARG_INVALID, "Invalid permission "); APPSPAWN_CHECK(reqNode->permissionFlags != NULL, return APPSPAWN_ARG_INVALID, "No permission tlv "); + if (strcmp(permission, OHOS_PERMISSION_FOWNER) == 0) { + APPSPAWN_LOGI("AppSpawnClientAddPermission %{public}s", permission); + return AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_SET_CAPS_FOWNER); + } + +#ifdef APPSPAWN_SANDBOX_NEW // Don't need to transmit sandbox permission in nwebspawn mode if (reqMgr->type == CLIENT_FOR_NWEBSPAWN) { return 0; } +#endif int32_t maxIndex = GetMaxPermissionIndex(handle); int index = GetPermissionIndex(handle, permission); diff --git a/modules/common/appspawn_begetctl.c b/modules/common/appspawn_begetctl.c index c813e839..3696bb8f 100755 --- a/modules/common/appspawn_begetctl.c +++ b/modules/common/appspawn_begetctl.c @@ -48,7 +48,7 @@ APPSPAWN_STATIC void RunAppSandbox(const char *ptyName) } APPSPAWN_CHECK(realPath != NULL, _exit(1), "Failed get realpath, err=%{public}d", errno); int n = strncmp(realPath, "/dev/pts/", strlen("/dev/pts/")); - APPSPAWN_CHECK(n == 0, free(realPath); _exit(1), "pts path %{public}s is invaild", realPath); + APPSPAWN_CHECK(n == 0, free(realPath); _exit(1), "pts path %{public}s is invalid", realPath); int fd = open(realPath, O_RDWR); free(realPath); APPSPAWN_CHECK(fd >= 0, _exit(1), "Failed open %{public}s, err=%{public}d", ptyName, errno); diff --git a/modules/common/appspawn_cgroup.c b/modules/common/appspawn_cgroup.c index eaf73279..4f6043a6 100644 --- a/modules/common/appspawn_cgroup.c +++ b/modules/common/appspawn_cgroup.c @@ -151,7 +151,7 @@ APPSPAWN_STATIC int ProcessMgrAddApp(const AppSpawnMgr *content, const AppSpawne APPSPAWN_LOGV("ProcessMgrAddApp %{public}d %{public}d to cgroup ", appInfo->pid, appInfo->uid); int ret = GetCgroupPath(appInfo, path, sizeof(path)); APPSPAWN_CHECK(ret == 0, return -1, "Failed to get real path errno: %{public}d", errno); - (void)CreateSandboxDir(path, 0750); // 0750 default mode + (void)CreateSandboxDir(path, 0755); // 0755 default mode ret = strcat_s(path, sizeof(path), "cgroup.procs"); APPSPAWN_CHECK(ret == 0, return ret, "Failed to strcat_s errno: %{public}d", errno); ret = WriteToFile(path, 0, (pid_t *)&appInfo->pid, 1); diff --git a/modules/common/appspawn_common.c b/modules/common/appspawn_common.c index 901c06bb..7c6095d7 100644 --- a/modules/common/appspawn_common.c +++ b/modules/common/appspawn_common.c @@ -137,7 +137,7 @@ static int SetAmbientCapabilities(const AppSpawningCtx *property) { const int caps[] = {CAP_DAC_OVERRIDE, CAP_DAC_READ_SEARCH, CAP_FOWNER}; size_t capCount = sizeof(caps) / sizeof(caps[0]); - for (size_t i = 0;i < capCount; ++i) { + for (size_t i = 0; i < capCount; ++i) { if (SetAmbientCapability(caps[i]) != 0) { APPSPAWN_LOGE("set cap failed: %{public}d", caps[i]); return -1; @@ -160,7 +160,7 @@ APPSPAWN_STATIC int SetCapabilities(const AppSpawnMgr *content, const AppSpawnin capHeader.version = _LINUX_CAPABILITY_VERSION_3; capHeader.pid = 0; - struct __user_cap_data_struct capData[2]; // 2 is data number + struct __user_cap_data_struct capData[2]; isRet = memset_s(&capData, sizeof(capData), 0, sizeof(capData)) != EOK; APPSPAWN_CHECK(!isRet, return -EINVAL, "Failed to memset cap data"); @@ -195,10 +195,9 @@ APPSPAWN_STATIC int SetCapabilities(const AppSpawnMgr *content, const AppSpawnin capData[1].permitted = (__u32)(permitted >> BITLEN32); capData[0].effective = (__u32)(effective); capData[1].effective = (__u32)(effective >> BITLEN32); - - // set capabilities isRet = capset(&capHeader, &capData[0]) != 0; APPSPAWN_CHECK(!isRet, return -errno, "Failed to capset errno: %{public}d", errno); + #ifdef APPSPAWN_SUPPORT_NOSHAREFS if (!CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX_TYPE) && (IsAppSpawnMode(content) || IsNativeSpawnMode(content))) { @@ -558,7 +557,7 @@ APPSPAWN_STATIC int FilterAppSpawnTrace(AppSpawnMgr *content, AppSpawningCtx *pr APPSPAWN_LOGV("processName: %{public}s pid: %{public}d", processName, pid); FilterAppTrace(processName, pid); } else { - APPSPAWN_LOGV("processName is NULL"); + APPSPAWN_LOGI("processName is NULL"); } return 0; diff --git a/modules/native_adapter/BUILD.gn b/modules/native_adapter/BUILD.gn index e1819d51..2804b03f 100644 --- a/modules/native_adapter/BUILD.gn +++ b/modules/native_adapter/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024-2025 Huawei Device Co., Ltd. +# Copyright (c) 2025 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/modules/sandbox/modern/sandbox_debug_mode.c b/modules/sandbox/modern/sandbox_debug_mode.c index 7953b34a..54b9b945 100644 --- a/modules/sandbox/modern/sandbox_debug_mode.c +++ b/modules/sandbox/modern/sandbox_debug_mode.c @@ -384,7 +384,7 @@ static int MountDebugDirBySharefs(const SandboxContext *context, const AppSpawnS return 0; } -static int InstallDebugSandbox(AppSpawnMgr *content, AppSpawningCtx *property) +APPSPAWN_STATIC int InstallDebugSandbox(AppSpawnMgr *content, AppSpawningCtx *property) { APPSPAWN_CHECK(property != NULL && content != NULL, return APPSPAWN_ARG_INVALID, "Invalid appspawn client or property"); @@ -410,6 +410,8 @@ static int InstallDebugSandbox(AppSpawnMgr *content, AppSpawningCtx *property) APPSPAWN_CHECK_ONLY_EXPER(ret == 0, DeleteSandboxContext(&context); return ret); + APPSPAWN_LOGI("Set sandbox config %{public}s sandboxNsFlags 0x%{public}x", + context->rootPath, context->sandboxNsFlags); do { ret = MountDebugTmpConfig(context, sandboxCfg); APPSPAWN_CHECK_ONLY_EXPER(ret == 0, break); diff --git a/modules/sandbox/normal/sandbox_common.cpp b/modules/sandbox/normal/sandbox_common.cpp index 9eca40fc..cc962ed2 100644 --- a/modules/sandbox/normal/sandbox_common.cpp +++ b/modules/sandbox/normal/sandbox_common.cpp @@ -900,9 +900,8 @@ std::string SandboxCommon::ConvertToRealPathWithPermission(const AppSpawningCtx AppSpawnMsgBundleInfo *info = reinterpret_cast(GetAppProperty(appProperty, TLV_BUNDLE_INFO)); AppSpawnMsgDacInfo *dacInfo = reinterpret_cast(GetAppProperty(appProperty, TLV_DAC_INFO)); - if (info == nullptr || dacInfo == nullptr) { - return ""; - } + APPSPAWN_CHECK((info != nullptr && dacInfo != nullptr), return "", "Invalid params"); + if (path.find(SandboxCommonDef::g_packageNameIndex) != std::string::npos) { std::string bundleNameWithIndex = info->bundleName; if (info->bundleIndex != 0) { diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index 524053a7..462dd748 100644 --- a/modules/sandbox/normal/sandbox_core.cpp +++ b/modules/sandbox/normal/sandbox_core.cpp @@ -1040,7 +1040,7 @@ int32_t SandboxCore::SetAppSandboxPropertyNweb(AppSpawningCtx *appProperty, uint } APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxRootFolderCreate failed, %{public}s", bundleName.c_str()); - // rendering process can be created by different apps, and the bundle names of these apps are different + // rendering process can be created by different apps, and the bundle names of these apps are different, // so we can't use the method SetPrivateAppSandboxProperty which mount dirs by using bundle name. rc = SetRenderSandboxPropertyNweb(appProperty, sandboxPackagePath); APPSPAWN_CHECK(rc == 0, return rc, "SetRenderSandboxPropertyNweb for %{public}s failed", bundleName.c_str()); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 8a0a5989..beef0504 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -441,8 +441,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer, connection->receiverCtx.incompleteMsg = NULL; int ret = 0; do { - APPSPAWN_LOGI("connectionId:%{public}u buffLen:%{public}d", - connection->connectionId, buffLen - currLen); + APPSPAWN_LOGI("connectionId:%{public}u buffLen:%{public}d", connection->connectionId, buffLen - currLen); ret = GetAppSpawnMsgFromBuffer(buffer + currLen, buffLen - currLen, &message, &connection->receiverCtx.msgRecvLen, &reminder); @@ -1115,6 +1114,7 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_ static void NotifyResToParent(AppSpawnContent *content, AppSpawnClient *client, int result) { AppSpawningCtx *property = (AppSpawningCtx *)client; + APPSPAWN_CHECK(property != NULL && client != NULL, return, "invalid param"); int fd = property->forkCtx.fd[1]; if (fd >= 0) { (void)write(fd, &result, sizeof(result)); @@ -1605,7 +1605,7 @@ APPSPAWN_STATIC int AppspawpnDevicedebugKill(int pid, cJSON *args) "appspawn devicedebug process is not debuggable, pid=%{public}d", pid); APPSPAWN_LOGI("appspawn devicedebug debugable=%{public}d, pid=%{public}d, signal=%{public}d", - appInfo->isDebuggable, pid, (int)signal->valueint); + appInfo->isDebuggable, pid, signal->valueint); if (kill(pid, signal->valueint) != 0) { APPSPAWN_LOGE("appspawn devicedebug unable to kill process, pid: %{public}d ret %{public}d", pid, errno); @@ -1620,7 +1620,7 @@ APPSPAWN_STATIC int AppspawnDevicedebugDeal(const char* op, int pid, cJSON *args if (strcmp(op, "kill") == 0) { return AppspawpnDevicedebugKill(pid, args); } - APPSPAWN_LOGE("appspawn devicedebug op:%{public}s invaild", op); + APPSPAWN_LOGE("appspawn devicedebug op:%{public}s invalid", op); return -1; } diff --git a/test/BUILD.gn b/test/BUILD.gn index 7e399ae1..22e12e97 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -29,6 +29,7 @@ group("unittest") { deps += [ "unittest/app_spawn_standard_test:AppSpawn_ut" ] deps += [ "unittest/app_spawn_standard_test:AppSpawn_common_ut" ] deps += [ "unittest/app_spawn_standard_test:AppSpawn_coldrun_ut" ] + deps += [ "unittest/app_spawn_standard_test:AppSpawnDebugSandbox" ] } deps += [ "unittest/hnp_test:HnpTest" ] deps += [ "unittest/single_test/hnp_installer:hnp_installer_test" ] diff --git a/test/moduletest/appspawn_client_test.cpp b/test/moduletest/appspawn_client_test.cpp index 3e285594..8e2960f1 100644 --- a/test/moduletest/appspawn_client_test.cpp +++ b/test/moduletest/appspawn_client_test.cpp @@ -67,7 +67,6 @@ static AppSpawnReqMsgHandle CreateMsg(AppSpawnClientHandle handle, const char *b static const char *permissions[] = { "ohos.permission.MANAGE_PRIVATE_PHOTOS", - "ohos.permission.FILE_CROSS_APP", "ohos.permission.ACTIVATE_THEME_PACKAGE", "ohos.permission.GET_WALLPAPER", }; diff --git a/test/moduletest/appspawn_test_cmder.cpp b/test/moduletest/appspawn_test_cmder.cpp index f2449821..b1bca776 100644 --- a/test/moduletest/appspawn_test_cmder.cpp +++ b/test/moduletest/appspawn_test_cmder.cpp @@ -56,7 +56,6 @@ static const std::string g_defaultAppInfo = "{ \ },\ \"permission\" : [\ \"ohos.permission.MANAGE_PRIVATE_PHOTOS\",\ - \"ohos.permission.FILE_CROSS_APP\",\ \"ohos.permission.ACTIVATE_THEME_PACKAGE\"\ ],\ \"internet-permission\" : {\ diff --git a/test/moduletest/test_app_info.json b/test/moduletest/test_app_info.json index 549e4699..bf584d89 100644 --- a/test/moduletest/test_app_info.json +++ b/test/moduletest/test_app_info.json @@ -14,7 +14,6 @@ }, "permission": [ "ohos.permission.MANAGE_PRIVATE_PHOTOS", - "ohos.permission.FILE_CROSS_APP", "ohos.permission.ACTIVATE_THEME_PACKAGE" ], "internet-permission": { diff --git a/test/unittest/app_spawn_client_test/BUILD.gn b/test/unittest/app_spawn_client_test/BUILD.gn index 3b3932f6..dd62ab13 100644 --- a/test/unittest/app_spawn_client_test/BUILD.gn +++ b/test/unittest/app_spawn_client_test/BUILD.gn @@ -40,7 +40,6 @@ ohos_unittest("AppSpawn_client_ut") { "${appspawn_path}/modules/common", "${appspawn_path}/modules/sandbox", "${appspawn_path}/modules/sandbox/normal", - "${appspawn_path}/modules/sandbox/modern", "${appspawn_path}/modules/module_engine/include", "${appspawn_path}/modules/sysevent", "${appspawn_innerkits_path}/client", diff --git a/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp b/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp index 4fa5b75f..d99749cb 100644 --- a/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp +++ b/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp @@ -1199,7 +1199,7 @@ HWTEST_F(AppSpawnClientTest, App_Spawn_Permission_006, TestSize.Level0) // for old sandbox, only one config #ifdef APPSPAWN_SANDBOX_NEW int max = GetMaxPermissionIndex(clientHandle); - EXPECT_EQ(max, 0); + EXPECT_EQ(max, sizeof(g_spawnerPermissionList) / sizeof(g_spawnerPermissionList[0])); int index = GetPermissionIndex(clientHandle, nullptr); EXPECT_EQ(index, INVALID_PERMISSION_INDEX); diff --git a/test/unittest/app_spawn_standard_test/BUILD.gn b/test/unittest/app_spawn_standard_test/BUILD.gn index c1624c89..024c3d97 100644 --- a/test/unittest/app_spawn_standard_test/BUILD.gn +++ b/test/unittest/app_spawn_standard_test/BUILD.gn @@ -137,10 +137,13 @@ ohos_unittest("AppSpawn_ut") { "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_mount_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_test.cpp", "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp", + "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp", ] defines += [ "APPSPAWN_SANDBOX_NEW" ] } else { - sources += [ "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp" ] + sources += [ + "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp", + ] } configs = [ "${appspawn_path}:appspawn_config" ] @@ -215,6 +218,103 @@ ohos_unittest("AppSpawn_ut") { } } +ohos_unittest("AppSpawnDebugSandbox") { + module_out_path = "appspawn/appspawn" + cflags = [ "-Dprivate=public" ] + if (appspawn_unittest_coverage) { + cflags += [ "--coverage" ] + ldflags = [ "--coverage" ] + cflags_cc = [ "--coverage" ] + } + deps = [] + defines = [ + "APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"", + "APPSPAWN_LABEL=\"APPSPAWN_UT\"", + "APPSPAWN_TEST", + "APPSPAWN_CLIENT", + "APPSPAWN_DEBUG", + "DEBUG_BEGETCTL_BOOT", + "USER_TIMER_TO_CHECK", + "OHOS_DEBUG", + ] + + include_dirs = [ + "${appspawn_path}", + "${appspawn_path}/common", + "${appspawn_path}/standard", + "${appspawn_innerkits_path}/client", + "${appspawn_innerkits_path}/permission", + "${appspawn_path}/test/mock", + "${appspawn_path}/test/unittest", + "${appspawn_path}/util/include", + "${appspawn_path}/modules/module_engine/include", + "${appspawn_path}/modules/sandbox", + "${appspawn_path}/modules/sandbox/normal" + ] + + sources = [ + "${appspawn_path}/util/src/appspawn_utils.c", + "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c", + "${appspawn_path}/standard/appspawn_msgmgr.c", + "${appspawn_path}/common/appspawn_trace.cpp", + "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c", + ] + + if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) { + defines += [ "APPSPAWN_SANDBOX_NEW" ] + } else { + sources += [ + "${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_debug_mode.cpp", + "${appspawn_path}/test/mock/lib_func_mock/lib_func_mock.cpp", + "${appspawn_path}/modules/sandbox/sandbox_dec.c", + "${appspawn_path}/modules/sandbox/appspawn_permission.c", + "${appspawn_path}/modules/sandbox/normal/sandbox_shared_mount.cpp", + "${appspawn_path}/modules/sandbox/normal/appspawn_sandbox_manager.cpp", + "${appspawn_path}/modules/sandbox/normal/sandbox_common.cpp", + ] + include_dirs += [ "${appspawn_path}/test/mock/lib_func_mock" ] + } + + configs = [ "${appspawn_path}:appspawn_config" ] + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "config_policy:configpolicy_util", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "googletest:gmock_main", + ] + + if (target_cpu == "arm64" || target_cpu == "x86_64" || + target_cpu == "riscv64") { + defines += [ "APPSPAWN_64" ] + } + + if (build_selinux) { + defines += [ "WITH_SELINUX" ] + external_deps += [ + "selinux:libselinux", + "selinux_adapter:libhap_restorecon", + ] + } + + if (appspawn_report_event) { + defines += [ "REPORT_EVENT" ] + external_deps += [ "hisysevent:libhisysevent" ] + sources += [ + "${appspawn_path}/modules/sysevent/appspawn_hisysevent.cpp", + "${appspawn_path}/modules/sysevent/event_reporter.cpp", + "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp", + ] + } + + if (dlp_permission_enable) { + cflags_cc = [ "-DWITH_DLP" ] + external_deps += [ "dlp_permission_service:libdlp_fuse" ] + } +} + ohos_unittest("AppSpawn_coldrun_ut") { module_out_path = "appspawn/appspawn" cflags = [ "-Dprivate=public" ] @@ -309,10 +409,6 @@ ohos_unittest("AppSpawn_coldrun_ut") { ] sources += appspawn_sandbox_src - if (appspawn_use_encaps == true) { - sources += [ "${appspawn_path}/modules/common/appspawn_encaps.c" ] - } - # add stub include_dirs += [ "${appspawn_path}/test/mock" ] sources += [ diff --git a/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp index fa672280..f648c1d1 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_appmgr_test.cpp @@ -956,14 +956,6 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawningCtx_Msg_003, TestSize.Level0) ret = CheckAppPermissionFlagSet(nullptr, j); EXPECT_EQ(0, ret); } - uint32_t result[MAX_FLAGS_INDEX] = {0}; - result[0] = 0; - result[1] = 1; - result[3] = 1; - for (int j = 0; j < MAX_FLAGS_INDEX; j++) { - ret = CheckAppMsgFlagsSet(appCtx, j); - EXPECT_EQ(result[j], ret); - } DeleteAppSpawningCtx(appCtx); DeleteAppSpawnMgr(mgr); } diff --git a/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp index 266cb7be..86d322ab 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_common_test.cpp @@ -1471,7 +1471,7 @@ HWTEST_F(AppSpawnCommonTest, App_Spawn_SetCapabilities, TestSize.Level0) // create msg ret = AppSpawnClientInit(NWEBSPAWN_SERVER_NAME, &clientHandle); APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", NWEBSPAWN_SERVER_NAME); - reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0); APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break, "Failed to create req %{public}s", NWEBSPAWN_SERVER_NAME); property = g_testHelper.GetAppProperty(clientHandle, reqHandle); @@ -1483,5 +1483,4 @@ HWTEST_F(AppSpawnCommonTest, App_Spawn_SetCapabilities, TestSize.Level0) DeleteAppSpawnMgr(mgr); ASSERT_EQ(ret, 0); } - } // namespace OHOS diff --git a/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp index 7b7760b3..5706afbf 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_kickdog_test.cpp @@ -43,7 +43,7 @@ static int CheckFileContent(const char *filePath, const char *targetStr) char buf[100]; if (filePath == nullptr) { - printf("para invaild\n"); + printf("para invalid\n"); return -1; } diff --git a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_debug_mode.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_debug_mode.cpp index 5b4c5d40..c8cea619 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_debug_mode.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_debug_mode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 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/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp index 04396530..396d0855 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_debug_mode.cpp @@ -46,7 +46,7 @@ extern "C" { } namespace OHOS { -AppSpawnTestHelper g_testHelper; +static AppSpawnTestHelper g_testHelper; class AppSpawnDebugSandboxTest : public testing::Test { public: static void SetUpTestCase() {} @@ -80,7 +80,7 @@ static AppSpawningCtx *AppSpawnDebugSandboxTestCreateAppSpawningCtx(int base) return nullptr; } -static SandboxContext *AppSpawnDebugSandboxTestGetSandboxContext(const AppSpawningCtx *property, int newbspawn) +static SandboxContext *AppSpawnDebugSandboxTestGetSandboxContext(const AppSpawningCtx *property, int nwebspawn) { AppSpawnMsgFlags *msgFlags = (AppSpawnMsgFlags *)GetAppProperty(property, TLV_MSG_FLAGS); APPSPAWN_CHECK(msgFlags != nullptr, return nullptr, "No msg flags in msg %{public}s", GetProcessName(property)); @@ -88,7 +88,7 @@ static SandboxContext *AppSpawnDebugSandboxTestGetSandboxContext(const AppSpawni SandboxContext *context = GetSandboxContext(); APPSPAWN_CHECK(context != nullptr, return nullptr, "Failed to get context"); - context->nwebspawn = newbspawn; + context->nwebspawn = nwebspawn; context->bundleName = GetBundleName(property); context->bundleHasWps = strstr(context->bundleName, "wps") != nullptr; context->dlpBundle = strcmp(GetProcessName(property), "com.ohos.dlpmanager") == 0; @@ -104,7 +104,7 @@ static SandboxContext *AppSpawnDebugSandboxTestGetSandboxContext(const AppSpawni /** * @tc.name: InstallDebugSandbox_ShouldReturnInvalidArg_WhenPropertyIsNull - * @tc.desc: 测试当 property 为NULL 时, 函数应返回 APPSPAWN_ARG_INVAILD. + * @tc.desc: 测试当 property 为 NULL 时,函数应返回 APPSPAWN_ARG_INVALID. * @tc.number: InstallDebugSandboxTest_001 */ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnInvalidArg_WhenPropertyIsNull, TestSize.Level0) @@ -119,7 +119,7 @@ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnInvalidAr /** * @tc.name: InstallDebugSandbox_ShouldReturnInvalidArg_WhenContentIsNull - * @tc.desc: 测试当 content 为NULL 时, 函数应返回 APPSPAWN_ARG_INVAILD. + * @tc.desc: 测试当 content 为 NULL 时,函数应返回 APPSPAWN_ARG_INVALID. * @tc.number: InstallDebugSandboxTest_002 */ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnInvalidArg_WhenContentIsNull, TestSize.Level0) @@ -137,7 +137,7 @@ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnInvalidAr * @tc.desc: 测试当不在开发者模式时,函数应返回 0. * @tc.number: InstallDebugSandboxTest_003 */ -HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnZero_WhenNotDeveloperMode, TestSize.Level0) +HWTEST_F(AppSpawnDebugSandboxTest, InstallDebugSandbox_ShouldReturnZero_WhenNotDeveloperMode, TestSize.Level0) { AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_APP_SPAWN); AppSpawningCtx *property = AppSpawnDebugSandboxTestCreateAppSpawningCtx(0); @@ -167,11 +167,11 @@ HWTEST_F(AppSpawnDebugSandboxTest, ATC_InstallDebugSandbox_ShouldReturnZero_When /** * @tc.name: InstallDebugSandbox_ShouldReturnSandboxInvalid_WhenSandboxConfigNotFound - * @tc.desc: 测试当找不到沙箱配置时,函数3应返回 APPSPAWN_SANDBOX_INVALID. + * @tc.desc: 测试当找不到沙箱配置时,函数应返回 APPSPAWN_SANDBOX_INVALID. * @tc.number: InstallDebugSandboxTest_005 */ HWTEST_F(AppSpawnDebugSandboxTest, - ATC_InstallDebugSandbox_ShouldReturnSandboxInvalid_WhenSandboxConfigNotFound, TestSize.Level0) + InstallDebugSandbox_ShouldReturnSandboxInvalid_WhenSandboxConfigNotFound, TestSize.Level0) { AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_APP_SPAWN); AppSpawningCtx *property = AppSpawnDebugSandboxTestCreateAppSpawningCtx(1); @@ -185,11 +185,11 @@ HWTEST_F(AppSpawnDebugSandboxTest, /** * @tc.name: InstallDebugSandbox_ShouldReturnSystemError_WhenSandboxContextIsNull - * @tc.desc: 测试当沙箱上下文获取失败时,函数应返回 APPSPAWN_SYSTEM_ERROR + * @tc.desc: 测试当沙箱上下文获取失败时,函数应返回 APPSPAWN_SYSTEM_ERROR. * @tc.number: InstallDebugSandboxTest_006 */ HWTEST_F(AppSpawnDebugSandboxTest, - ATC_InstallDebugSandbox_ShouldReturnSystemError_WhenSandboxContextIsNull, TestSize.Level0) + InstallDebugSandbox_ShouldReturnSystemError_WhenSandboxContextIsNull, TestSize.Level0) { AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_APP_SPAWN); AppSpawningCtx *property = AppSpawnDebugSandboxTestCreateAppSpawningCtx(1); @@ -201,4 +201,5 @@ HWTEST_F(AppSpawnDebugSandboxTest, // delete DeleteAppSpawningCtx(property); DeleteAppSpawnMgr(mgr); +} } \ No newline at end of file diff --git a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp index 1d488af1..7121407e 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandbox_test.cpp @@ -2363,6 +2363,18 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_DevModel_001, TestSize.Level0) DeleteAppSpawningCtx(spawningCtx); } +HWTEST_F(AppSpawnSandboxTest, App_Spawn_permissionUserId_001, TestSize.Level0) +{ + AppSpawningCtx* spawningCtx = GetTestAppProperty(); + std::string path = AppSpawn::SandboxCommon::ConvertToRealPathWithPermission(spawningCtx, + "/mnt/sandbox//storage/Users/currentUser"); + ASSERT_NE(path.c_str(), nullptr); + std::string examplePath = "/mnt/sandbox/100/storage/Users/currentUser"; + + ASSERT_EQ(strcmp(path.c_str(), examplePath.c_str()), 0); + DeleteAppSpawningCtx(spawningCtx); +} + HWTEST_F(AppSpawnSandboxTest, Handle_Flag_Point_PreInstall_Shell_Hap_001, TestSize.Level0) { std::string flagPointConfigStr = "{ \ diff --git a/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp b/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp index 1f736325..219854ad 100644 --- a/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp +++ b/test/unittest/app_spawn_standard_test/app_spawn_sandboxmgr_test.cpp @@ -724,7 +724,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_Permission_003, TestSize.Level0) #else // nweb no permission, so max = 0 max = GetMaxPermissionIndex(clientHandle); - EXPECT_EQ(max, 0); + EXPECT_EQ(max, sizeof(g_spawnerPermissionList) / sizeof(g_spawnerPermissionList[0])); #endif AppSpawnClientDestroy(clientHandle); } diff --git a/test/unittest/app_spawn_test_helper.h b/test/unittest/app_spawn_test_helper.h index 4c9bfc33..4c2e859f 100644 --- a/test/unittest/app_spawn_test_helper.h +++ b/test/unittest/app_spawn_test_helper.h @@ -149,7 +149,6 @@ private: int fdArg = -1; std::vector permissions_ = { const_cast("ohos.permission.MANAGE_PRIVATE_PHOTOS"), - const_cast("ohos.permission.FILE_CROSS_APP"), const_cast("ohos.permission.ACTIVATE_THEME_PACKAGE"), const_cast("ohos.permission.GET_WALLPAPER"), const_cast("ohos.permission.FILE_ACCESS_MANAGER") diff --git a/util/include/appspawn_error.h b/util/include/appspawn_error.h index ba0c7350..f3258678 100644 --- a/util/include/appspawn_error.h +++ b/util/include/appspawn_error.h @@ -84,12 +84,12 @@ typedef enum { typedef enum { APPSPAWN_ERROR_MSG_TO_LONG = DECLARE_APPSPAWN_ERRORCODE(APPSPAWN_SPAWNER, APPSPAWN_UTILS_COMMON, 0x0000), - APPSPAWN_ERROR_MSG_INVAILD, + APPSPAWN_ERROR_MSG_INVALID, } SpawnerErrorCode; typedef enum { - SANDBOX_ERROR_ARGS_INVAILD = DECLARE_APPSPAWN_ERRORCODE(APPSPAWN_SANDBOX, APPSPAWN_SANDBOX_COMMON, 0x0000), - SANDBOX_ERROR_MSG_INVAILD, + SANDBOX_ERROR_ARGS_INVALID = DECLARE_APPSPAWN_ERRORCODE(APPSPAWN_SANDBOX, APPSPAWN_SANDBOX_COMMON, 0x0000), + SANDBOX_ERROR_MSG_INVALID, } SandboxErrorCode; #ifdef __cplusplus -- Gitee