!1363 补充appspawn ut

Merge pull request !1363 from 钟柠/ut_0815
This commit is contained in:
openharmony_ci 2024-08-16 06:08:36 +00:00 committed by Gitee
commit c1ce55376e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 723 additions and 23 deletions

View File

@ -28,4 +28,5 @@ declare_args() {
appspawn_sandbox_new = false
appspawn_use_encaps = false
enable_appspawn_dump_catcher = true
appspawn_unittest_coverage = false
}

View File

@ -208,7 +208,7 @@ static int HandleMsgSend(AppSpawnReqMsgMgr *reqMgr, int socketId, AppSpawnReqMsg
return 0;
}
static void TryCreateSocket(AppSpawnReqMsgMgr *reqMgr)
APPSPAWN_STATIC void TryCreateSocket(AppSpawnReqMsgMgr *reqMgr)
{
uint32_t retryCount = 1;
while (retryCount <= reqMgr->maxRetryCount) {

View File

@ -187,7 +187,7 @@ int SetInternetPermission(const AppSpawningCtx *property)
return 0;
}
APPSPAWN_STATIC void InitAppCommonEnv(const AppSpawningCtx *property)
void InitAppCommonEnv(const AppSpawningCtx *property)
{
AppDacInfo *appInfo = reinterpret_cast<AppDacInfo *>(GetAppProperty(property, TLV_DAC_INFO));
if (appInfo == NULL) {

View File

@ -166,7 +166,7 @@ static void KillProcessesByCGroup(const char *path, AppSpawnMgr *content, const
(void)fclose(file);
}
static int ProcessMgrRemoveApp(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo)
APPSPAWN_STATIC int ProcessMgrRemoveApp(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo)
{
APPSPAWN_CHECK_ONLY_EXPER(content != NULL, return -1);
APPSPAWN_CHECK_ONLY_EXPER(appInfo != NULL, return -1);
@ -192,7 +192,7 @@ static int ProcessMgrRemoveApp(const AppSpawnMgr *content, const AppSpawnedProce
return ret;
}
static int ProcessMgrAddApp(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo)
APPSPAWN_STATIC int ProcessMgrAddApp(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo)
{
APPSPAWN_CHECK_ONLY_EXPER(content != NULL, return -1);
APPSPAWN_CHECK_ONLY_EXPER(appInfo != NULL, return -1);

View File

@ -32,7 +32,7 @@
#define PID_NS_INIT_UID 100000 // reserved for pid_ns_init process, avoid app, render proc, etc.
#define PID_NS_INIT_GID 100000
typedef struct {
typedef struct TagAppSpawnNamespace {
AppSpawnExtData extData;
int nsSelfPidFd; // ns pid fd of appspawn
int nsInitPidFd; // ns pid fd of pid_ns_init
@ -56,7 +56,7 @@ APPSPAWN_STATIC AppSpawnNamespace *GetAppSpawnNamespace(const AppSpawnMgr *conte
return (AppSpawnNamespace *)ListEntry(node, AppSpawnNamespace, extData);
}
static void DeleteAppSpawnNamespace(AppSpawnNamespace *namespace)
APPSPAWN_STATIC void DeleteAppSpawnNamespace(AppSpawnNamespace *namespace)
{
APPSPAWN_CHECK_ONLY_EXPER(namespace != NULL, return);
APPSPAWN_LOGV("DeleteAppSpawnNamespace");
@ -74,14 +74,14 @@ static void DeleteAppSpawnNamespace(AppSpawnNamespace *namespace)
free(namespace);
}
static void FreeAppSpawnNamespace(struct TagAppSpawnExtData *data)
APPSPAWN_STATIC void FreeAppSpawnNamespace(struct TagAppSpawnExtData *data)
{
AppSpawnNamespace *namespace = ListEntry(data, AppSpawnNamespace, extData);
APPSPAWN_CHECK_ONLY_EXPER(namespace != NULL, return);
DeleteAppSpawnNamespace(namespace);
}
static AppSpawnNamespace *CreateAppSpawnNamespace(void)
APPSPAWN_STATIC AppSpawnNamespace *CreateAppSpawnNamespace(void)
{
APPSPAWN_LOGV("CreateAppSpawnNamespace");
AppSpawnNamespace *namespace = (AppSpawnNamespace *)calloc(1, sizeof(AppSpawnNamespace));
@ -235,7 +235,7 @@ static int SetPidNamespace(int nsPidFd, int nsType)
return 0;
}
static int PreForkSetPidNamespace(AppSpawnMgr *content, AppSpawningCtx *property)
APPSPAWN_STATIC int PreForkSetPidNamespace(AppSpawnMgr *content, AppSpawningCtx *property)
{
AppSpawnNamespace *namespace = GetAppSpawnNamespace(content);
if (namespace == NULL) {
@ -247,7 +247,7 @@ static int PreForkSetPidNamespace(AppSpawnMgr *content, AppSpawningCtx *property
return 0;
}
static int PostForkSetPidNamespace(AppSpawnMgr *content, AppSpawningCtx *property)
APPSPAWN_STATIC int PostForkSetPidNamespace(AppSpawnMgr *content, AppSpawningCtx *property)
{
AppSpawnNamespace *namespace = GetAppSpawnNamespace(content);
if (namespace == NULL) {

View File

@ -41,7 +41,7 @@ static int VarPackageNameIndexReplace(const SandboxContext *context,
return 0;
}
static int VarPackageNameReplace(const SandboxContext *context,
APPSPAWN_STATIC int VarPackageNameReplace(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData)
{
int len = sprintf_s((char *)buffer, bufferLen, "%s", context->bundleName);
@ -118,7 +118,7 @@ static int ReplaceVariableByParameter(const char *varData, SandboxBuffer *sandbo
return 0;
}
static int ReplaceVariableForDepSandboxPath(const SandboxContext *context,
APPSPAWN_STATIC int ReplaceVariableForDepSandboxPath(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData)
{
APPSPAWN_CHECK(extraData != NULL && extraData->data.depNode != NULL, return -1, "Invalid extra data ");
@ -129,7 +129,7 @@ static int ReplaceVariableForDepSandboxPath(const SandboxContext *context,
return 0;
}
static int ReplaceVariableForDepSrcPath(const SandboxContext *context,
APPSPAWN_STATIC int ReplaceVariableForDepSrcPath(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData)
{
APPSPAWN_CHECK(extraData != NULL && extraData->data.depNode != NULL, return -1, "Invalid extra data ");
@ -140,7 +140,7 @@ static int ReplaceVariableForDepSrcPath(const SandboxContext *context,
return 0;
}
static int ReplaceVariableForDepPath(const SandboxContext *context,
APPSPAWN_STATIC int ReplaceVariableForDepPath(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData)
{
APPSPAWN_CHECK(extraData != NULL && extraData->data.depNode != NULL, return -1, "Invalid extra data ");

View File

@ -119,7 +119,7 @@ static inline bool CheckAppFullMountEnable(void)
return GetBoolParameter("const.filemanager.full_mount.enable", false);
}
static unsigned long GetMountModeFromConfig(const cJSON *config, const char *key, unsigned long def)
APPSPAWN_STATIC unsigned long GetMountModeFromConfig(const cJSON *config, const char *key, unsigned long def)
{
char *value = cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(config, key));
if (value == NULL) {
@ -181,7 +181,7 @@ static mode_t GetChmodFromJson(const cJSON *config)
return mode;
}
static uint32_t GetFlagIndexFromJson(const cJSON *config)
APPSPAWN_STATIC uint32_t GetFlagIndexFromJson(const cJSON *config)
{
char *flagStr = GetStringFromJsonObj(config, "name");
if (flagStr == NULL) {
@ -242,7 +242,7 @@ static PathMountNode *DecodeMountPathConfig(const SandboxSection *section, const
return sandboxNode;
}
static int ParseMountPathsConfig(AppSpawnSandboxCfg *sandbox,
APPSPAWN_STATIC int ParseMountPathsConfig(AppSpawnSandboxCfg *sandbox,
const cJSON *mountConfigs, SandboxSection *section, uint32_t type)
{
APPSPAWN_CHECK_ONLY_EXPER(mountConfigs != NULL && cJSON_IsArray(mountConfigs), return -1);
@ -288,7 +288,8 @@ static SymbolLinkNode *DecodeSymbolLinksConfig(const SandboxSection *section, co
return node;
}
static int ParseSymbolLinksConfig(AppSpawnSandboxCfg *sandbox, const cJSON *symbolLinkConfigs, SandboxSection *section)
APPSPAWN_STATIC int ParseSymbolLinksConfig(AppSpawnSandboxCfg *sandbox, const cJSON *symbolLinkConfigs,
SandboxSection *section)
{
APPSPAWN_CHECK_ONLY_EXPER(symbolLinkConfigs != NULL && cJSON_IsArray(symbolLinkConfigs), return -1);
uint32_t symlinkPointSize = cJSON_GetArraySize(symbolLinkConfigs);
@ -304,7 +305,7 @@ static int ParseSymbolLinksConfig(AppSpawnSandboxCfg *sandbox, const cJSON *symb
return 0;
}
static int ParseGidTableConfig(AppSpawnSandboxCfg *sandbox, const cJSON *configs, SandboxSection *section)
APPSPAWN_STATIC int ParseGidTableConfig(AppSpawnSandboxCfg *sandbox, const cJSON *configs, SandboxSection *section)
{
APPSPAWN_CHECK(cJSON_IsArray(configs), return 0, "json is not array.");
uint32_t arrayLen = (uint32_t)cJSON_GetArraySize(configs);

View File

@ -48,10 +48,39 @@ typedef struct TagPathMountNode PathMountNode;
typedef struct TagMountArg MountArg;
typedef struct TagVarExtraData VarExtraData;
typedef struct TagSandboxSection SandboxSection;
typedef struct TagAppSpawnNamespace AppSpawnNamespace;
typedef struct TagAppSpawnedProcess AppSpawnedProcessInfo;
AppSpawnNamespace *GetAppSpawnNamespace(const AppSpawnMgr *content);
void DeleteAppSpawnNamespace(AppSpawnNamespace *ns);
void FreeAppSpawnNamespace(struct TagAppSpawnExtData *data);
int PreForkSetPidNamespace(AppSpawnMgr *content, AppSpawningCtx *property);
int PostForkSetPidNamespace(AppSpawnMgr *content, AppSpawningCtx *property);
int ProcessMgrRemoveApp(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo);
int ProcessMgrAddApp(const AppSpawnMgr *content, const AppSpawnedProcessInfo *appInfo);
void TryCreateSocket(AppSpawnReqMsgMgr *reqMgr);
int MountAllGroup(const SandboxContext *context, const cJSON *groups);
int MountAllHsp(const SandboxContext *context, const cJSON *hsps);
void CheckAndCreateSandboxFile(const char *file);
int VarPackageNameReplace(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData);
int ReplaceVariableForDepSandboxPath(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData);
int ReplaceVariableForDepSrcPath(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData);
int ReplaceVariableForDepPath(const SandboxContext *context,
const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData);
int SpawnPrepareSandboxCfg(AppSpawnMgr *content, AppSpawningCtx *property);
unsigned long GetMountModeFromConfig(const cJSON *config, const char *key, unsigned long def);
uint32_t GetFlagIndexFromJson(const cJSON *config);
int ParseMountPathsConfig(AppSpawnSandboxCfg *sandbox,
const cJSON *mountConfigs, SandboxSection *section, uint32_t type);
int ParseSymbolLinksConfig(AppSpawnSandboxCfg *sandbox, const cJSON *symbolLinkConfigs,
SandboxSection *section);
int ParseGidTableConfig(AppSpawnSandboxCfg *sandbox, const cJSON *configs, SandboxSection *section);
int AppSpawnColdStartApp(struct AppSpawnContent *content, AppSpawnClient *client);
void ProcessSignal(const struct signalfd_siginfo *siginfo);
int CreateClientSocket(uint32_t type, int block);
@ -100,5 +129,4 @@ StubNode *GetStubNode(int type);
}
#endif
int SetSelinuxConNweb(const AppSpawnMgr *content, const AppSpawningCtx *property);
void InitAppCommonEnv(const AppSpawningCtx *property);
#endif // APPSPAWN_TEST_STUB_H

View File

@ -17,6 +17,11 @@ import("//build/test.gni")
ohos_unittest("AppSpawn_client_ut") {
module_out_path = "${module_output_path}"
deps = []
if (appspawn_unittest_coverage) {
cflags = [ "--coverage" ]
ldflags = [ "--coverage" ]
cflags_cc = [ "--coverage" ]
}
defines = [
"APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"",
"APPSPAWN_TEST",

View File

@ -1211,4 +1211,13 @@ HWTEST_F(AppSpawnClientTest, App_Spawn_Permission_006, TestSize.Level0)
#endif
AppSpawnClientDestroy(clientHandle);
}
HWTEST_F(AppSpawnClientTest, App_Spawn_interface001, TestSize.Level0)
{
AppSpawnReqMsgMgr *clientInstance = (AppSpawnReqMsgMgr *)malloc(sizeof(AppSpawnReqMsgMgr) + RECV_BLOCK_LEN);
clientInstance->socketId = 1;
clientInstance->maxRetryCount = 1;
TryCreateSocket(clientInstance);
free(clientInstance);
}
} // namespace OHOS

View File

@ -16,6 +16,11 @@ import("//build/test.gni")
ohos_unittest("AppSpawn_ut") {
module_out_path = "${module_output_path}"
if (appspawn_unittest_coverage) {
cflags = [ "--coverage" ]
ldflags = [ "--coverage" ]
cflags_cc = [ "--coverage" ]
}
deps = []
defines = [
"APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"",
@ -135,7 +140,7 @@ ohos_unittest("AppSpawn_ut") {
if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
sources += [
"${appspawn_path}/test/unittest/app_spawn_standard_test/app_spawn_sandbox_new_coverage_test.cpp",
"${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",
]
defines += [ "APPSPAWN_SANDBOX_NEW" ]

View File

@ -182,4 +182,31 @@ HWTEST_F(AppSpawnBegetCtlTest, App_Spawn_BetgetCtl_004, TestSize.Level0)
AppSpawnClientDestroy(clientHandle);
ASSERT_EQ(ret, 0);
}
HWTEST_F(AppSpawnBegetCtlTest, App_Spawn_BetgetCtl_005, TestSize.Level0)
{
AppSpawnClientHandle clientHandle = nullptr;
AppSpawnReqMsgHandle reqHandle = 0;
AppSpawningCtx *property = nullptr;
AppSpawnMgr *mgr = nullptr;
int ret = -1;
do {
mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
// create msg
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", APPSPAWN_SERVER_NAME);
reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0);
APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break,
"Failed to create req %{public}s", APPSPAWN_SERVER_NAME);
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
property->client.flags |= APP_BEGETCTL_BOOT;
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
ret = RunBegetctlBootApp(mgr, property);
} while (0);
DeleteAppSpawningCtx(property);
AppSpawnClientDestroy(clientHandle);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, -1);
}
} // namespace OHOS

View File

@ -392,4 +392,24 @@ HWTEST_F(AppSpawnCGroupTest, App_Spawn_CGroup_010, TestSize.Level0)
LE_CloseLoop(LE_GetDefaultLoop());
ASSERT_EQ(ret, 0);
}
HWTEST_F(AppSpawnCGroupTest, App_Spawn_CGroup_011, TestSize.Level0)
{
int ret = ProcessMgrRemoveApp(nullptr, nullptr);
ASSERT_EQ(ret, -1);
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_APP_SPAWN);
ret = ProcessMgrRemoveApp(mgr, nullptr);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, -1);
}
HWTEST_F(AppSpawnCGroupTest, App_Spawn_CGroup_012, TestSize.Level0)
{
int ret = ProcessMgrAddApp(nullptr, nullptr);
ASSERT_EQ(ret, -1);
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_APP_SPAWN);
ret = ProcessMgrAddApp(mgr, nullptr);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, -1);
}
} // namespace OHOS

View File

@ -444,4 +444,252 @@ HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_021, TestSize.Level0)
ASSERT_EQ(ret, -1);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_022, TestSize.Level0)
{
int ret = SetInternetPermission(nullptr);
ASSERT_EQ(ret, 0);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_023, TestSize.Level0)
{
AppSpawnClientHandle clientHandle = nullptr;
AppSpawnReqMsgHandle reqHandle = 0;
AppSpawningCtx *property = nullptr;
int ret = -1;
do {
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", APPSPAWN_SERVER_NAME);
reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0);
APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break, "Failed to create req %{public}s", APPSPAWN_SERVER_NAME);
const char *appEnv = "{\"test\"}";
ret = AppSpawnReqMsgAddExtInfo(reqHandle, "AppEnv",
reinterpret_cast<uint8_t *>(const_cast<char *>(appEnv)), strlen(appEnv) + 1);
APPSPAWN_CHECK(ret == 0, break, "Failed to add ext tlv %{public}s", appEnv);
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
reqHandle = nullptr;
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
SetEnvInfo(nullptr, property);
// spawn
property = nullptr;
} while (0);
DeleteAppSpawningCtx(property);
AppSpawnReqMsgFree(reqHandle);
AppSpawnClientDestroy(clientHandle);
ASSERT_EQ(ret, 0);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_024, TestSize.Level0)
{
AppSpawnClientHandle clientHandle = nullptr;
AppSpawnReqMsgHandle reqHandle = 0;
AppSpawningCtx *property = nullptr;
int ret = -1;
do {
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", APPSPAWN_SERVER_NAME);
reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0);
APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break, "Failed to create req %{public}s", APPSPAWN_SERVER_NAME);
const char *appEnv = "%";
ret = AppSpawnReqMsgAddExtInfo(reqHandle, "AppEnv",
reinterpret_cast<uint8_t *>(const_cast<char *>(appEnv)), strlen(appEnv) + 1);
APPSPAWN_CHECK(ret == 0, break, "Failed to add ext tlv %{public}s", appEnv);
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
reqHandle = nullptr;
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
SetEnvInfo(nullptr, property);
// spawn
property = nullptr;
} while (0);
DeleteAppSpawningCtx(property);
AppSpawnReqMsgFree(reqHandle);
AppSpawnClientDestroy(clientHandle);
ASSERT_EQ(ret, 0);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_025, TestSize.Level0)
{
AppSpawnClientHandle clientHandle = nullptr;
AppSpawnReqMsgHandle reqHandle = 0;
AppSpawningCtx *property = nullptr;
int ret = -1;
do {
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", APPSPAWN_SERVER_NAME);
reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0);
APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break, "Failed to create req %{public}s", APPSPAWN_SERVER_NAME);
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
reqHandle = nullptr;
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
SetEnvInfo(nullptr, property);
// spawn
property = nullptr;
} while (0);
DeleteAppSpawningCtx(property);
AppSpawnReqMsgFree(reqHandle);
AppSpawnClientDestroy(clientHandle);
ASSERT_EQ(ret, 0);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_026, TestSize.Level0)
{
AppSpawnClientHandle clientHandle = nullptr;
AppSpawnReqMsgHandle reqHandle = 0;
AppSpawningCtx *property = nullptr;
AppSpawnMgr *mgr = nullptr;
int ret = -1;
do {
mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
// create msg
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", APPSPAWN_SERVER_NAME);
reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0);
APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break,
"Failed to create req %{public}s", APPSPAWN_SERVER_NAME);
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
property->client.flags |= APP_BEGETCTL_BOOT;
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
SetAppSpawnMsgFlag(property->message, APP_FLAGS_ISOLATED_SANDBOX, 16);
ret = SetSelinuxCon(mgr, property);
} while (0);
DeleteAppSpawningCtx(property);
AppSpawnClientDestroy(clientHandle);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, APPSPAWN_NATIVE_NOT_SUPPORT);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_027, TestSize.Level0)
{
AppSpawnClientHandle clientHandle = nullptr;
AppSpawnReqMsgHandle reqHandle = 0;
AppSpawningCtx *property = nullptr;
AppSpawnMgr *mgr = nullptr;
int ret = -1;
do {
mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
// create msg
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", APPSPAWN_SERVER_NAME);
reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0);
APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break,
"Failed to create req %{public}s", APPSPAWN_SERVER_NAME);
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
property->client.flags |= APP_BEGETCTL_BOOT;
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
SetAppSpawnMsgFlag(property->message, APP_FLAGS_DLP_MANAGER, 1);
ret = SetSelinuxCon(mgr, property);
} while (0);
DeleteAppSpawningCtx(property);
AppSpawnClientDestroy(clientHandle);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, APPSPAWN_NATIVE_NOT_SUPPORT);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_028, TestSize.Level0)
{
AppSpawnClientHandle clientHandle = nullptr;
AppSpawnReqMsgHandle reqHandle = 0;
AppSpawningCtx *property = nullptr;
AppSpawnMgr *mgr = nullptr;
int ret = -1;
do {
mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
// create msg
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
APPSPAWN_CHECK(ret == 0, break, "Failed to create reqMgr %{public}s", APPSPAWN_SERVER_NAME);
reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_SPAWN_NATIVE_PROCESS, 0);
APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, break,
"Failed to create req %{public}s", APPSPAWN_SERVER_NAME);
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
property->client.flags |= APP_BEGETCTL_BOOT;
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
SetAppSpawnMsgFlag(property->message, APP_FLAGS_DEBUGGABLE, 1);
ret = SetSelinuxCon(mgr, property);
} while (0);
DeleteAppSpawningCtx(property);
AppSpawnClientDestroy(clientHandle);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, APPSPAWN_NATIVE_NOT_SUPPORT);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_029, TestSize.Level0)
{
ASSERT_EQ(GetAppSpawnNamespace(nullptr), nullptr);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_030, TestSize.Level0)
{
DeleteAppSpawnNamespace(nullptr);
FreeAppSpawnNamespace(nullptr);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_031, TestSize.Level0)
{
int ret = -1;
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_APP_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
mgr->content.sandboxNsFlags = 1;
ret = PreForkSetPidNamespace(mgr, nullptr);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, 0);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_Common_032, TestSize.Level0)
{
int ret = -1;
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_APP_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
mgr->content.sandboxNsFlags = 0;
ret = PostForkSetPidNamespace(mgr, nullptr);
DeleteAppSpawnMgr(mgr);
ASSERT_EQ(ret, 0);
AppSpawnClientInit(nullptr, nullptr);
}
HWTEST_F(AppSpawnCommonTest, App_Spawn_SetFdEnv, TestSize.Level0)
{
int ret = SetFdEnv(nullptr, nullptr);
EXPECT_EQ(ret, -1);
AppSpawningCtx property;
ret = SetFdEnv(nullptr, &property);
EXPECT_EQ(ret, -1); // message == null
property.message = (AppSpawnMsgNode *)malloc(sizeof(AppSpawnMsgNode) + sizeof(AppSpawnMsgNode) + APP_LEN_PROC_NAME);
ASSERT_EQ(property.message != nullptr, 1);
AppSpawnConnection *connection = (AppSpawnConnection *)malloc(sizeof(AppSpawnConnection));
ASSERT_EQ(connection != nullptr, 1);
uint8_t *buffer = (uint8_t*)malloc(sizeof(uint8_t) * 10);
ASSERT_EQ(buffer != nullptr, 1);
property.message->buffer = nullptr;
property.message->connection = nullptr;
ret = SetFdEnv(nullptr, &property);
EXPECT_EQ(ret, -1); // message != null, message->buffer == null, message->connection == null
property.message->buffer = nullptr;
property.message->connection = connection;
ret = SetFdEnv(nullptr, &property); // message != null, message->connection != null, message->buffer == null
EXPECT_EQ(ret, -1);
property.message->buffer = buffer;
property.message->connection = nullptr;
ret = SetFdEnv(nullptr, &property); // message != null, message->connection == null, message->buffer != null
EXPECT_EQ(ret, -1);
property.message->buffer = buffer;
property.message->connection = connection;
ret = SetFdEnv(nullptr, &property); // message != null, message->connection != null, message->buffer != null
EXPECT_EQ(ret, -1);
free(buffer);
free(connection);
free(property.message);
}
} // namespace OHOS

View File

@ -38,6 +38,13 @@
using namespace testing;
using namespace testing::ext;
#define MAX_BUFF 20
#define TEST_STR_LEN 30
extern "C" {
void DumpSandboxMountNode(const SandboxMountNode *sandboxNode, uint32_t index);
}
namespace OHOS {
static AppSpawnTestHelper g_testHelper;
class AppSpawnSandboxCoverageTest : public testing::Test {
@ -301,4 +308,318 @@ HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_MountAllGroup_001, TestS
ret = MountAllGroup(context, config6); // dir is not Array
ASSERT_EQ(ret, -1);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_cfgvar, TestSize.Level0)
{
SandboxContext context = {};
context.bundleName = "com.xxx.xxx.xxx";
char buffer[MAX_BUFF] = {};
uint32_t realLen = 0;
int ret = VarPackageNameReplace(&context, buffer, MAX_BUFF, &realLen, nullptr);
EXPECT_EQ(ret, 0);
context.bundleName = "com.xxxxxxx.xxxxxxx.xxxxxxx";
ret = VarPackageNameReplace(&context, buffer, MAX_BUFF, &realLen, nullptr);
EXPECT_EQ(ret, -1);
VarExtraData extraData = {};
ret = ReplaceVariableForDepSandboxPath(nullptr, buffer, MAX_BUFF, &realLen, nullptr);
EXPECT_EQ(ret, -1);
ret = ReplaceVariableForDepSrcPath(nullptr, buffer, MAX_BUFF, &realLen, nullptr);
EXPECT_EQ(ret, -1);
ret = ReplaceVariableForDepSandboxPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, -1);
ret = ReplaceVariableForDepSrcPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, -1);
extraData.data.depNode = (PathMountNode *)malloc(sizeof(PathMountNode));
ASSERT_EQ(extraData.data.depNode != nullptr, 1);
extraData.data.depNode->target = (char*)malloc(sizeof(char) * TEST_STR_LEN);
ASSERT_EQ(extraData.data.depNode->target != nullptr, 1);
(void)strcpy_s(extraData.data.depNode->target, TEST_STR_LEN, "/xxxx/xxxx/xxxxxxx/xxxxxx/xxx");
ret = ReplaceVariableForDepSandboxPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, -1);
(void)strcpy_s(extraData.data.depNode->target, TEST_STR_LEN, "/xxxx/xxxx/xxxxxx");
ret = ReplaceVariableForDepSandboxPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, 0);
extraData.data.depNode->source = (char*)malloc(sizeof(char) * TEST_STR_LEN);
ASSERT_EQ(extraData.data.depNode->source != nullptr, 1);
(void)strcpy_s(extraData.data.depNode->source, TEST_STR_LEN, "/xxxx/xxxx/xxxxxxx/xxxxxx/xxx");
ret = ReplaceVariableForDepSrcPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, -1);
(void)strcpy_s(extraData.data.depNode->source, TEST_STR_LEN, "/xxxx/xxxx/xxxxxx");
ret = ReplaceVariableForDepSrcPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, 0);
free(extraData.data.depNode->target);
free(extraData.data.depNode->source);
free(extraData.data.depNode);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_cfgvar_001, TestSize.Level0)
{
char buffer[MAX_BUFF] = {};
uint32_t realLen = 0;
VarExtraData extraData = {};
int ret = ReplaceVariableForDepPath(nullptr, buffer, MAX_BUFF, &realLen, nullptr);
EXPECT_EQ(ret, -1);
ret = ReplaceVariableForDepPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, -1);
extraData.data.depNode = (PathMountNode *)malloc(sizeof(PathMountNode));
ASSERT_EQ(extraData.data.depNode != nullptr, 1);
extraData.data.depNode->source = (char*)malloc(sizeof(char) * TEST_STR_LEN);
EXPECT_EQ(extraData.data.depNode->source != nullptr, 1);
ret = ReplaceVariableForDepPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, 0);
extraData.operation = 0x1 << MOUNT_PATH_OP_REPLACE_BY_SRC;
ret = ReplaceVariableForDepPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, 0);
(void)strcpy_s(extraData.data.depNode->source, TEST_STR_LEN, "/xxxx/xxxx/xxxxxxx/xxxxxx/xxx");
ret = ReplaceVariableForDepPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, -1);
(void)strcpy_s(extraData.data.depNode->source, TEST_STR_LEN, "/xxxx/xxxx/xxxxxx");
ret = ReplaceVariableForDepPath(nullptr, buffer, MAX_BUFF, &realLen, &extraData);
EXPECT_EQ(ret, 0);
free(extraData.data.depNode->source);
free(extraData.data.depNode);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_cfgvar_002, TestSize.Level0)
{
const char *realVar = GetSandboxRealVar(nullptr, 0, nullptr, nullptr, nullptr);
EXPECT_EQ(realVar == nullptr, 1);
SandboxContext context = {};
realVar = GetSandboxRealVar(&context, 0, nullptr, nullptr, nullptr);
EXPECT_EQ(realVar == nullptr, 1);
context.buffer[0].buffer = (char*)malloc(sizeof(char) * MAX_BUFF);
ASSERT_EQ(context.buffer[0].buffer != nullptr, 1);
(void)strcpy_s(context.buffer[0].buffer, MAX_BUFF, "xxxxxxxx");
context.buffer[0].bufferLen = MAX_BUFF;
context.buffer[0].current = 0;
realVar = GetSandboxRealVar(&context, 0, nullptr, nullptr, nullptr);
EXPECT_EQ(realVar != nullptr, 1);
realVar = GetSandboxRealVar(&context, 4, nullptr, nullptr, nullptr);
EXPECT_EQ(realVar == nullptr, 1);
realVar = GetSandboxRealVar(&context, 0, nullptr, "test/xxxx", nullptr);
EXPECT_EQ(realVar != nullptr, 1);
realVar = GetSandboxRealVar(&context, 0, "xxxx/xxx", nullptr, nullptr);
EXPECT_EQ(realVar != nullptr, 1);
realVar = GetSandboxRealVar(&context, 0, "xxxx/xxx", "test/xxxx", nullptr);
EXPECT_EQ(realVar != nullptr, 1);
GetSandboxRealVar(&context, 1, nullptr, nullptr, nullptr);
EXPECT_EQ(realVar != nullptr, 1);
free(context.buffer[0].buffer);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_manager, TestSize.Level0)
{
int ret = SpawnPrepareSandboxCfg(nullptr, nullptr);
EXPECT_EQ(ret, -1);
AppSpawnMgr content = {};
ret = SpawnPrepareSandboxCfg(&content, nullptr);
EXPECT_EQ(ret, -1);
AppSpawningCtx property = {};
property.message = (AppSpawnMsgNode *)malloc(sizeof(AppSpawnMsgNode));
ASSERT_EQ(property.message != nullptr, 1);
(void)strcpy_s(property.message->msgHeader.processName, APP_LEN_PROC_NAME, "com.xxx.xxx.xxx");
ret = SpawnPrepareSandboxCfg(&content, &property);
EXPECT_EQ(ret, -1);
free(property.message);
PathMountNode mountNode = {};
mountNode.checkErrorFlag = true;
mountNode.createDemand = 0;
DumpSandboxMountNode(nullptr, 0);
mountNode.sandboxNode.type = SANDBOX_TAG_MOUNT_PATH;
DumpSandboxMountNode(&mountNode.sandboxNode, 0);
mountNode.sandboxNode.type = SANDBOX_TAG_SYMLINK;
DumpSandboxMountNode(&mountNode.sandboxNode, 0);
mountNode.source = (char*)malloc(sizeof(char) * TEST_STR_LEN);
ASSERT_EQ(mountNode.source!= nullptr, 1);
mountNode.target = (char*)malloc(sizeof(char) * TEST_STR_LEN);
ASSERT_EQ(mountNode.target!= nullptr, 1);
mountNode.appAplName = (char*)malloc(sizeof(char) * TEST_STR_LEN);
ASSERT_EQ(mountNode.appAplName!= nullptr, 1);
(void)strcpy_s(mountNode.source, TEST_STR_LEN, "/xxxxx/xxx");
(void)strcpy_s(mountNode.target, TEST_STR_LEN, "/test/xxxx");
(void)strcpy_s(mountNode.appAplName, TEST_STR_LEN, "apl");
mountNode.sandboxNode.type = SANDBOX_TAG_MOUNT_FILE;
DumpSandboxMountNode(&mountNode.sandboxNode, 0);
mountNode.checkErrorFlag = false;
mountNode.createDemand = 1;
mountNode.sandboxNode.type = SANDBOX_TAG_SYMLINK;
DumpSandboxMountNode(&mountNode.sandboxNode, 0);
mountNode.sandboxNode.type = SANDBOX_TAG_REQUIRED;
DumpSandboxMountNode(&mountNode.sandboxNode, 0);
free(mountNode.source);
free(mountNode.target);
free(mountNode.appAplName);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_load, TestSize.Level0)
{
unsigned long ret = GetMountModeFromConfig(nullptr, nullptr, 1);
EXPECT_EQ(ret, 1);
const char testStr[] = "{ \
\"test\":\"xxxxxxxxx\", \
}";
const cJSON *config = cJSON_Parse(testStr);
ret = GetMountModeFromConfig(config, "test", 1);
EXPECT_EQ(ret, 1);
ret = GetFlagIndexFromJson(config);
EXPECT_EQ(ret, 0);
const char testStr1[] = "{ \
\"name\":\"xxxxxxxxx\", \
}";
const cJSON *config1 = cJSON_Parse(testStr1);
ret = GetFlagIndexFromJson(config1);
EXPECT_EQ(ret, 0);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_load_001, TestSize.Level0)
{
const char testStr[] = "{ \
\"test\":\"xxxxxxxxx\" \
}";
const cJSON *config = cJSON_Parse(testStr);
unsigned long ret = GetMountModeFromConfig(config, "test", 1);
EXPECT_EQ(ret, 1);
int result = ParseMountPathsConfig(nullptr, nullptr, nullptr, 1);
EXPECT_EQ(result, -1);
result = ParseMountPathsConfig(nullptr, config, nullptr, 1);
EXPECT_EQ(result, -1);
const char testStr1[] = "{ \
\"mount-paths\":[\"/xxxx/xxx\", \"/xxx/xxx\"] \
}";
const cJSON *config1 = cJSON_Parse(testStr1);
cJSON *mountPaths = cJSON_GetObjectItemCaseSensitive(config1, "mount-paths");
result = ParseMountPathsConfig(nullptr, mountPaths, nullptr, 1);
EXPECT_EQ(result, 0);
const char testStr2[] = "{ \
\"mount-paths\":[{\
\"src-path\": \"/config\", \
\"test\": \"/test/xxx\" \
}] \
}";
const cJSON *config2 = cJSON_Parse(testStr2);
mountPaths = cJSON_GetObjectItemCaseSensitive(config2, "mount-paths");
result = ParseMountPathsConfig(nullptr, mountPaths, nullptr, 1);
EXPECT_EQ(result, 0);
const char testStr3[] = "{ \
\"mount-paths\":[{ \
\"sandbox-path\": \"/config\", \
\"test\": \"/test/xxx\"}] \
}";
const cJSON *config3 = cJSON_Parse(testStr3);
mountPaths = cJSON_GetObjectItemCaseSensitive(config3, "mount-paths");
result = ParseMountPathsConfig(nullptr, mountPaths, nullptr, 1);
EXPECT_EQ(result, 0);
const char testStr4[] = "{ \
\"mount-paths\":[{ \
\"src-path\": \"/xxx/xxx\", \
\"sandbox-path\": \"/test/xxx\"}] \
}";
const cJSON *config4 = cJSON_Parse(testStr4);
mountPaths = cJSON_GetObjectItemCaseSensitive(config4, "mount-paths");
result = ParseMountPathsConfig(nullptr, mountPaths, nullptr, 1);
EXPECT_EQ(result, 0);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_load_002, TestSize.Level0)
{
int ret = ParseSymbolLinksConfig(nullptr, nullptr, nullptr);
EXPECT_EQ(ret, -1);
const char testStr1[] = "{ \
\"test\":\"xxxxxxxxx\" \
}";
const cJSON *config1 = cJSON_Parse(testStr1);
ret = ParseSymbolLinksConfig(nullptr, config1, nullptr);
EXPECT_EQ(ret, -1);
const char testStr2[] = "{ \
\"symbol-links\":[\"/xxxx/xxx\", \"/xxx/xxx\"] \
}";
const cJSON *config2 = cJSON_Parse(testStr2);
cJSON *symbolLinks = cJSON_GetObjectItemCaseSensitive(config2, "symbol-links");
ret = ParseSymbolLinksConfig(nullptr, symbolLinks, nullptr);
EXPECT_EQ(ret, -1);
const char testStr3[] = "{ \
\"symbol-links\":[{\
\"test\":\"/xxxx/xxx\", \
\"target-name\":\"/xxx/xxx\"}] \
}";
const cJSON *config3 = cJSON_Parse(testStr3);
symbolLinks = cJSON_GetObjectItemCaseSensitive(config3, "symbol-links");
ret = ParseSymbolLinksConfig(nullptr, symbolLinks, nullptr);
EXPECT_EQ(ret, -1);
const char testStr4[] = "{ \
\"symbol-links\":[{\
\"test\":\"/xxxx/xxx\", \
\"link-name\":\"/xxx/xxx\"}] \
}";
const cJSON *config4 = cJSON_Parse(testStr4);
symbolLinks = cJSON_GetObjectItemCaseSensitive(config4, "symbol-links");
ret = ParseSymbolLinksConfig(nullptr, symbolLinks, nullptr);
EXPECT_EQ(ret, -1);
const char testStr5[] = "{ \
\"symbol-links\":[{\
\"target-name\":\"/xxxx/xxx\", \
\"link-name\":\"/xxx/xxx\"}] \
}";
const cJSON *config5 = cJSON_Parse(testStr5);
symbolLinks = cJSON_GetObjectItemCaseSensitive(config5, "symbol-links");
ret = ParseSymbolLinksConfig(nullptr, symbolLinks, nullptr);
EXPECT_EQ(ret, 0);
}
HWTEST_F(AppSpawnSandboxCoverageTest, App_Spawn_Sandbox_load_003, TestSize.Level0)
{
const char testStr[] = "{ \
\"test\":\"xxxxxxxxx\" \
}";
const cJSON *config = cJSON_Parse(testStr);
int ret = ParseGidTableConfig(nullptr, config, nullptr);
EXPECT_EQ(ret, 0);
const char testStr1[] = "{ \
\"test\":[] \
}";
const cJSON *config1 = cJSON_Parse(testStr1);
cJSON *testCfg = cJSON_GetObjectItemCaseSensitive(config1, "test");
ret = ParseGidTableConfig(nullptr, testCfg, nullptr);
EXPECT_EQ(ret, 0);
SandboxSection section = {};
const char testStr2[] = "{ \
\"gids\":[\"202400\", \"202500\", \"202600\"] \
}";
const cJSON *config2 = cJSON_Parse(testStr2);
testCfg = cJSON_GetObjectItemCaseSensitive(config2, "gids");
ret = ParseGidTableConfig(nullptr, testCfg, &section);
EXPECT_EQ(ret, 0);
section.gidTable = (gid_t *)malloc(sizeof(gid_t) * 10);
ASSERT_EQ(section.gidTable != nullptr, 1);
ret = ParseGidTableConfig(nullptr, testCfg, &section);
EXPECT_EQ(ret, 0);
if (section.gidTable != nullptr) {
free(section.gidTable);
}
}
}

View File

@ -2272,7 +2272,6 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_sandbox, TestSize.Level0)
const PathMountNode sandboxNode = {node, nullptr, nullptr, 0, false, 1, 1, 0, nullptr, {}};
const MountArg args = {"/data/xxx/xxx", nullptr, nullptr, 0, nullptr, 0};
CreateDemandSrc(contextTest, &sandboxNode, &args);
char apl[] = "apl";
const PathMountNode sandboxNode1 = {node, source, nullptr, 0, false, 1, 1, 0, nullptr, {}};
const PathMountNode sandboxNode2 = {node, nullptr, target, 0, false, 1, 1, 0, nullptr, {}};
@ -2289,7 +2288,43 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_sandbox, TestSize.Level0)
res = CheckSandboxMountNode(nullptr, &section, &sandboxNode2, 0);
ASSERT_EQ(res, 0);
res = CheckSandboxMountNode(&context1, &section, &sandboxNode3, MOUNT_PATH_OP_NONE);
ASSERT_EQ(res, 0);
EXPECT_EQ(res, 0);
}
HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_sandbox_001, TestSize.Level0)
{
char target[] = {"/data/storage/el1/database"};
SandboxMountNode node = {};
struct ListNode front;
char name[] = "test";
char apl[] = "apl";
const SandboxSection section = {node, front, name, 16, 16, nullptr, 1, 1, nullptr};
char rootPath[] = "/test/xxxx";
SandboxContext context1 = {{{}}, "test.example.ohos.com", nullptr, 1, 1, 1, 1, 1, 1, 1, 1, rootPath};
char source1[] = {"/xxx/xxx/xxx"};
uint32_t operation = 0x1 << SANDBOX_TAG_SPAWN_FLAGS;
const PathMountNode sandboxNode4 = {node, source1, target, 0, false, 1, 1, 0, apl, {}};
context1.bundleHasWps = 1;
int res = CheckSandboxMountNode(&context1, &section, &sandboxNode4, operation);
EXPECT_EQ(res, 1);
context1.bundleHasWps = 0;
res = CheckSandboxMountNode(&context1, &section, &sandboxNode4, operation);
EXPECT_EQ(res, 1);
char source2[] = "/data/app/xxx";
const PathMountNode sandboxNode5 = {node, source2, target, 0, false, 1, 1, 0, apl, {}};
res = CheckSandboxMountNode(&context1, &section, &sandboxNode5, operation);
EXPECT_EQ(res, 1);
char source3[] = "/data/app/base";
const PathMountNode sandboxNode6 = {node, source3, target, 0, false, 1, 1, 0, apl, {}};
res = CheckSandboxMountNode(&context1, &section, &sandboxNode6, operation);
EXPECT_EQ(res, 1);
char source4[] = "/data/app/<PackageName>";
const PathMountNode sandboxNode7 = {node, source4, target, 0, false, 1, 1, 0, apl, {}};
res = CheckSandboxMountNode(&context1, &section, &sandboxNode7, operation);
EXPECT_EQ(res, 1);
}
HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_template, TestSize.Level0)