From 416b9c4d1d81b0cd3b505ec0174b003186af9bcb Mon Sep 17 00:00:00 2001 From: fan-jingle Date: Tue, 29 Jul 2025 16:11:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9appspawn=20=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fan-jingle --- modules/sandbox/normal/sandbox_core.cpp | 9 +- modules/sandbox/normal/sandbox_core.h | 2 +- .../app_spawn_sandbox_test.cpp | 84 +++++++++++++------ 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/modules/sandbox/normal/sandbox_core.cpp b/modules/sandbox/normal/sandbox_core.cpp index 9b3a0444..ba24bfd8 100644 --- a/modules/sandbox/normal/sandbox_core.cpp +++ b/modules/sandbox/normal/sandbox_core.cpp @@ -422,13 +422,12 @@ static inline cJSON *GetJsonObjFromProperty(const AppSpawningCtx *appProperty, c return root; } -int32_t SandboxCore::MountAllHsp(const AppSpawningCtx *appProperty, std::string &sandboxPackagePath) +int32_t SandboxCore::MountAllHsp(const AppSpawningCtx *appProperty, std::string &sandboxPackagePath, cJSON *hspRoot) { if (appProperty == nullptr || sandboxPackagePath == "") { return 0; } int ret = 0; - cJSON *hspRoot = GetJsonObjFromProperty(appProperty, SandboxCommonDef::HSPLIST_SOCKET_TYPE.c_str()); APPSPAWN_CHECK_ONLY_EXPER(hspRoot != nullptr && cJSON_IsObject(hspRoot), return 0); cJSON *bundles = cJSON_GetObjectItemCaseSensitive(hspRoot, "bundles"); @@ -466,7 +465,6 @@ int32_t SandboxCore::MountAllHsp(const AppSpawningCtx *appProperty, std::string ret = SandboxCommon::DoAppSandboxMountOnce(appProperty, &arg); APPSPAWN_CHECK(ret == 0, return 0, "mount library failed %{public}d", ret); } - cJSON_Delete(hspRoot); return 0; } @@ -829,8 +827,9 @@ int32_t SandboxCore::SetCommonAppSandboxProperty(const AppSpawningCtx *appProper APPSPAWN_CHECK(ret == 0, return ret, "parse appdata config for common failed, %{public}s", sandboxPackagePath.c_str()); } - - ret = MountAllHsp(appProperty, sandboxPackagePath); + cJSON *hspRoot = GetJsonObjFromProperty(appProperty, SandboxCommonDef::HSPLIST_SOCKET_TYPE.c_str()); + ret = MountAllHsp(appProperty, sandboxPackagePath, hspRoot); + cJSON_Delete(hspRoot); APPSPAWN_CHECK(ret == 0, return ret, "mount extraInfo failed, %{public}s", sandboxPackagePath.c_str()); ret = MountAllGroup(appProperty, sandboxPackagePath); diff --git a/modules/sandbox/normal/sandbox_core.h b/modules/sandbox/normal/sandbox_core.h index ab8d05d6..4d627eba 100644 --- a/modules/sandbox/normal/sandbox_core.h +++ b/modules/sandbox/normal/sandbox_core.h @@ -108,7 +108,7 @@ private: static int32_t SetCommonAppSandboxProperty_(const AppSpawningCtx *appProperty, cJSON *config); // 处理可变参数的挂载 - static int32_t MountAllHsp(const AppSpawningCtx *appProperty, std::string &sandboxPackagePath); + static int32_t MountAllHsp(const AppSpawningCtx *appProperty, std::string &sandboxPackagePath, cJSON *hspRoot); static int32_t MountAllGroup(const AppSpawningCtx *appProperty, std::string &sandboxPackagePath); // 沙箱回调函数 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 b33ea9d1..13e3e992 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 @@ -906,7 +906,9 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_34, TestSize.Level0) \"versions\":[\"v10001\", \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); EXPECT_EQ(ret, 0); DeleteAppSpawningCtx(appProperty); @@ -916,7 +918,9 @@ static void InvalidJsonTest(std::string &testBundle) { char hspListStr[] = "{"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_EQ(ret, 0); } @@ -928,7 +932,9 @@ static void NoBundleTest(std::string &testBundle) \"versions\":[\"v10001\", \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -941,7 +947,9 @@ static void NoModulesTest(std::string &testBundle) }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -953,7 +961,9 @@ static void NoVersionsTest(std::string &testBundle) \"modules\":[\"module1\", \"module2\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -966,7 +976,9 @@ static void ListSizeNotSameTest(std::string &testBundle) \"versions\":[\"v10001\", \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -979,7 +991,9 @@ static void ValueTypeIsNotArraryTest(std::string &testBundle) \"versions\": 1001 \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -992,7 +1006,9 @@ static void ElementTypeIsNotStringTest(std::string &testBundle) \"versions\": [1001, 1002] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -1006,7 +1022,9 @@ static void ElementTypeIsNotSameTestSN(std::string &testBundle) \"versions\": [\"v10001\", 1002] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -1020,7 +1038,9 @@ static void ElementTypeIsNotSameTestNS(std::string &testBundle) \"versions\": [1001, \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -1052,7 +1072,9 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_36, TestSize.Level0) \"versions\":[\"v10001\", \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -1063,10 +1085,18 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_36, TestSize.Level0) \"versions\":[\"v10001\", \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } +} + +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_37, TestSize.Level0) +{ + const char *strl1 = "/mnt/sandbox/100/test.bundle1"; + std::string testBundle = strl1; { // name is .. char hspListStr[] = "{ \ \"bundles\":[\"..\", \"test.bundle2\"], \ @@ -1074,7 +1104,9 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_36, TestSize.Level0) \"versions\":[\"v10001\", \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } @@ -1085,13 +1117,15 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_36, TestSize.Level0) \"versions\":[\"v10001\", \"v10002\"] \ }"; AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr); - int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle); + cJSON *hspRoot = cJSON_Parse(hspListStr); + int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot); + cJSON_Delete(hspRoot); DeleteAppSpawningCtx(appProperty); EXPECT_NE(ret, 0); } } -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_37, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_38, TestSize.Level0) { g_testHelper.SetTestUid(1000); // 1000 test g_testHelper.SetTestGid(1000); // 1000 test @@ -1113,7 +1147,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_37, TestSize.Level0) DeleteAppSpawningCtx(appProperty); } -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_38, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_39, TestSize.Level0) { g_testHelper.SetTestUid(1000); // 1000 test g_testHelper.SetTestGid(1000); // 1000 test @@ -1166,7 +1200,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_38, TestSize.Level0) * @tc.require:issueI7D0H9 * @tc.author: */ -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_39, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_40, TestSize.Level0) { g_testHelper.SetTestUid(1000); // 1000 test g_testHelper.SetTestGid(1000); // 1000 test @@ -1191,7 +1225,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_39, TestSize.Level0) * @tc.require:issueI7FUPV * @tc.author: */ -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_40, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_41, TestSize.Level0) { g_testHelper.SetTestUid(1000); // 1000 test g_testHelper.SetTestGid(1000); // 1000 test @@ -1227,7 +1261,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_40, TestSize.Level0) * @tc.require:issueI8B63M * @tc.author: */ -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_41, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_42, TestSize.Level0) { std::string mJsconfig = "{ \ \"common\":[{ \ @@ -1268,7 +1302,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_41, TestSize.Level0) * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K * @tc.author: */ -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_42, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_43, TestSize.Level0) { std::string mJsconfig = "{ \ \"mount-paths\": [{ \ @@ -1309,7 +1343,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_42, TestSize.Level0) * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K * @tc.author: */ -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_43, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_44, TestSize.Level0) { std::string mJsconfig = "{ \ \"mount-paths\": [{ \ @@ -1353,7 +1387,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_43, TestSize.Level0) * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K * @tc.author: */ -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_44, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_45, TestSize.Level0) { std::string mJsconfig = "{ \ \"mount-paths\": [{ \ @@ -1397,7 +1431,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_44, TestSize.Level0) * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K * @tc.author: */ -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_45, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_46, TestSize.Level0) { std::string mJsconfig = "{ \ \"mount-paths\": [{ \ @@ -1433,7 +1467,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_45, TestSize.Level0) DeleteAppSpawningCtx(appProperty); } -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_46, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_47, TestSize.Level0) { g_testHelper.SetTestUid(1000); // 1000 test g_testHelper.SetTestGid(1000); // 1000 test @@ -1476,7 +1510,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_46, TestSize.Level0) DeleteAppSpawningCtx(appProperty); } -HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_47, TestSize.Level0) +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_48, TestSize.Level0) { g_testHelper.SetTestUid(1000); // 1000 test g_testHelper.SetTestGid(1000); // 1000 test -- Gitee