diff --git a/modules/sandbox/appspawn_sandbox.c b/modules/sandbox/appspawn_sandbox.c index beb7edc51be7e06417a3866b6d3707ebe733f171..92cda174b0d1f4be4523fd1d8e006a1a9454f40d 100644 --- a/modules/sandbox/appspawn_sandbox.c +++ b/modules/sandbox/appspawn_sandbox.c @@ -188,7 +188,7 @@ void DeleteSandboxContext(SandboxContext *context) free(context); } -static bool NeedNetworkIsolated(SandboxContext *context, const AppSpawningCtx *property) +APPSPAWN_STATIC bool NeedNetworkIsolated(SandboxContext *context, const AppSpawningCtx *property) { int developerMode = IsDeveloperModeOpen(); if (CheckSpawningMsgFlagSet(context, APP_FLAGS_ISOLATED_SANDBOX) && !developerMode) { diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 6d198746c6efff467a518b9ad951917aa75ab1d0..b4817edb0d58b56ee2edf3f2466e5cdfb6c947d7 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -1870,7 +1870,7 @@ int LoadAppSandboxConfig(AppSpawnMgr *content) return 0; } -static bool NeedNetworkIsolated(AppSpawningCtx *property) +APPSPAWN_STATIC bool NeedNetworkIsolated(AppSpawningCtx *property) { int developerMode = IsDeveloperModeOpen(); if (CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX) && !developerMode) { diff --git a/test/mock/app_spawn_stub.h b/test/mock/app_spawn_stub.h index b3a4d6a753db19e677fe98f7e5f07ae87c831673..69917fc2fab0975ef50a1023bace894dd6fd39ad 100644 --- a/test/mock/app_spawn_stub.h +++ b/test/mock/app_spawn_stub.h @@ -133,4 +133,5 @@ StubNode *GetStubNode(int type); #endif int SetSelinuxConNweb(const AppSpawnMgr *content, const AppSpawningCtx *property); void InitAppCommonEnv(const AppSpawningCtx *property); +bool NeedNetworkIsolated(AppSpawningCtx *property); #endif // APPSPAWN_TEST_STUB_H 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 6d2d24e972cf91ba2ad1130226489276cae31b17..8a802e4c9c5abbb841b48b917e555bec2d5c8c21 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 @@ -1426,6 +1426,72 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_47, TestSize.Level0) DeleteAppSpawningCtx(appProperty); EXPECT_EQ(ret, 0); } + +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_48, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_48 start"; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnReqMsgHandle reqHandle = 0; + AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_ISOLATED_SANDBOX); + AppSpawningCtx *appProperty = g_testHelper.GetAppProperty(clientHandle, reqHandle); + bool ret = NeedNetworkIsolated(appProperty); + EXPECT_EQ(ret, false); + DeleteAppSpawningCtx(appProperty); + AppSpawnClientDestroy(clientHandle); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_48 end"; +} + +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_49, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_49 start"; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnReqMsgHandle reqHandle = 0; + AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_ISOLATED_NETWORK); + AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_EXTENSION_TYPE, "form"); + AppSpawningCtx *appProperty = g_testHelper.GetAppProperty(clientHandle, reqHandle); + bool ret = NeedNetworkIsolated(appProperty); + EXPECT_EQ(ret, false); + DeleteAppSpawningCtx(appProperty); + AppSpawnClientDestroy(clientHandle); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_49 end"; +} + +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_50, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_50 start"; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnReqMsgHandle reqHandle = 0; + AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_ISOLATED_NETWORK); + AppSpawningCtx *appProperty = g_testHelper.GetAppProperty(clientHandle, reqHandle); + bool ret = NeedNetworkIsolated(appProperty); + EXPECT_EQ(ret, true); + DeleteAppSpawningCtx(appProperty); + AppSpawnClientDestroy(clientHandle); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_50 end"; +} + +HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_51, TestSize.Level0) +{ + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_51 start"; + AppSpawnClientHandle clientHandle = nullptr; + AppSpawnReqMsgHandle reqHandle = 0; + AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle); + reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0); + AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_COLD_BOOT); + AppSpawningCtx *appProperty = g_testHelper.GetAppProperty(clientHandle, reqHandle); + bool ret = NeedNetworkIsolated(appProperty); + EXPECT_EQ(ret, false); + DeleteAppSpawningCtx(appProperty); + AppSpawnClientDestroy(clientHandle); + GTEST_LOG_(INFO) << "App_Spawn_Sandbox_51 end"; +} + /** * @brief 测试app extension *