!1463 nativespawn适配新沙箱

Merge pull request !1463 from 王达/nativespawn_sanbox
This commit is contained in:
openharmony_ci 2024-09-19 07:31:45 +00:00 committed by Gitee
commit bf8fa0a42e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 178 additions and 68 deletions

View File

@ -0,0 +1,63 @@
{
"global": {
"sandbox-root" : "/mnt/sandbox/<PackageName>",
"sandbox-ns-flags" : [ "net" ]
},
"required": {
"system-const": {
"mount-paths": [{
"src-path" : "/dev",
"sandbox-path" : "/dev"
}, {
"src-path" : "/proc",
"sandbox-path" : "/proc"
}, {
"src-path" : "/sys",
"sandbox-path" : "/sys"
}, {
"src-path" : "/system/fonts",
"sandbox-path" : "/system/fonts"
}, {
"src-path" : "/system/etc",
"sandbox-path" : "/system/etc"
}, {
"src-path" : "/system/bin",
"sandbox-path" : "/system/bin"
}, {
"src-path" : "/system/lib",
"sandbox-path" : "/system/lib"
}, {
"src-path" : "/system/lib64",
"sandbox-path" : "/system/lib64"
}, {
"src-path" : "/data/app/el1/bundle/public/<PackageName>",
"sandbox-path" : "/data/storage/el1/bundle"
}],
"symbol-links" : [{
"target-name" : "/system/etc",
"link-name" : "/etc",
"check-action-status": "false"
}, {
"target-name" : "/system/bin",
"link-name" : "/bin",
"check-action-status": "false"
}, {
"target-name" : "/system/lib",
"link-name" : "/lib",
"check-action-status": "false"
}, {
"target-name" : "/system/lib64",
"link-name" : "/lib64",
"check-action-status": "false"
}],
"mount-files": [{
"src-path" : "/system/etc/hosts",
"sandbox-path" : "/data/service/el1/network/hosts_user/hosts"
}],
"mount-groups" : []
},
"app-variable": {
"mount-groups": []
}
}
}

View File

@ -29,7 +29,7 @@ if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
module_install_dir = "etc/sandbox"
}
ohos_prebuilt_etc("appdata-sandbox-isolated.json") {
ohos_prebuilt_etc("appdata-sandbox-isolated-new.json") {
source = "../appdata-sandbox-isolated.json"
part_name = "${part_name}"
module_install_dir = "etc/sandbox"
@ -68,11 +68,13 @@ ohos_prebuilt_etc("appspawn_preload.json") {
group("etc_files") {
deps = [
":appdata-sandbox-isolated.json",
":appdata-sandbox.json",
":appspawn_preload.json",
]
if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
deps += [ ":appdata-sandbox-nweb.json" ]
deps += [ ":appdata-sandbox-isolated-new.json" ]
} else {
deps += [ ":appdata-sandbox-isolated.json" ]
}
}

View File

@ -40,6 +40,7 @@ typedef struct TagAppSpawnedProcess AppSpawnedProcessInfo;
typedef enum {
EXT_DATA_SANDBOX,
EXT_DATA_NAMESPACE,
EXT_DATA_ISOLATED_SANDBOX,
} ExtDataType;
struct TagAppSpawnExtData;

View File

@ -32,7 +32,7 @@ extern "C" {
#endif
#define WEB_SANDBOX_FILE_NAME "/appdata-sandbox-nweb.json"
#define ISOLATED_SANDBOX_FILE_NAME "/appdata-sandbox-isolated.json"
#define ISOLATED_SANDBOX_FILE_NAME "/appdata-sandbox-isolated-new.json"
typedef struct TagSandboxQueue SandboxQueue;
typedef struct TagPermissionNode SandboxPermissionNode;

View File

@ -230,8 +230,8 @@ typedef struct {
*
* @return AppSpawnSandboxCfg*
*/
AppSpawnSandboxCfg *CreateAppSpawnSandbox(void);
AppSpawnSandboxCfg *GetAppSpawnSandbox(const AppSpawnMgr *content);
AppSpawnSandboxCfg *CreateAppSpawnSandbox(ExtDataType type);
AppSpawnSandboxCfg *GetAppSpawnSandbox(const AppSpawnMgr *content, ExtDataType type);
void DeleteAppSpawnSandbox(AppSpawnSandboxCfg *sandbox);
int LoadAppSandboxConfig(AppSpawnSandboxCfg *sandbox, RunMode mode);
void DumpAppSpawnSandboxCfg(AppSpawnSandboxCfg *sandbox);

View File

@ -349,10 +349,10 @@ static int AppSpawnExtDataCompareDataId(ListNode *node, void *data)
return extData->dataId - *(uint32_t *)data;
}
AppSpawnSandboxCfg *GetAppSpawnSandbox(const AppSpawnMgr *content)
AppSpawnSandboxCfg *GetAppSpawnSandbox(const AppSpawnMgr *content, ExtDataType type)
{
APPSPAWN_CHECK_ONLY_EXPER(content != NULL, return NULL);
uint32_t dataId = EXT_DATA_SANDBOX;
uint32_t dataId = type;
ListNode *node = OH_ListFind(&content->extData, (void *)&dataId, AppSpawnExtDataCompareDataId);
if (node == NULL) {
return NULL;
@ -433,7 +433,7 @@ static void FreeAppSpawnSandbox(struct TagAppSpawnExtData *data)
DeleteAppSpawnSandbox(sandbox);
}
AppSpawnSandboxCfg *CreateAppSpawnSandbox(void)
AppSpawnSandboxCfg *CreateAppSpawnSandbox(ExtDataType type)
{
// create sandbox
AppSpawnSandboxCfg *sandbox = (AppSpawnSandboxCfg *)calloc(1, sizeof(AppSpawnSandboxCfg));
@ -441,7 +441,7 @@ AppSpawnSandboxCfg *CreateAppSpawnSandbox(void)
// ext data init
OH_ListInit(&sandbox->extData.node);
sandbox->extData.dataId = EXT_DATA_SANDBOX;
sandbox->extData.dataId = type;
sandbox->extData.freeNode = FreeAppSpawnSandbox;
sandbox->extData.dumpNode = DumpSandbox;
@ -482,17 +482,41 @@ void DumpAppSpawnSandboxCfg(AppSpawnSandboxCfg *sandbox)
DumpSandboxQueue(&sandbox->nameGroupsQueue.front, DumpSandboxNameGroupNode);
}
APPSPAWN_STATIC int PreLoadSandboxCfg(AppSpawnMgr *content)
APPSPAWN_STATIC int PreLoadIsoLatedSandboxCfg(AppSpawnMgr *content)
{
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content);
APPSPAWN_CHECK(sandbox == NULL, return 0, "Sandbox has been load");
if (IsNWebSpawnMode(content)) {
return 0;
}
sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content, EXT_DATA_ISOLATED_SANDBOX);
APPSPAWN_CHECK(sandbox == NULL, return 0, "Isolated sandbox has been load");
sandbox = CreateAppSpawnSandbox(EXT_DATA_ISOLATED_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != NULL, return APPSPAWN_SYSTEM_ERROR);
OH_ListAddTail(&content->extData, &sandbox->extData.node);
// load app sandbox config
LoadAppSandboxConfig(sandbox, IsNWebSpawnMode(content));
LoadAppSandboxConfig(sandbox, MODE_FOR_NATIVE_SPAWN);
sandbox->maxPermissionIndex = PermissionRenumber(&sandbox->permissionQueue);
content->content.sandboxNsFlags = 0;
if (sandbox->pidNamespaceSupport) {
content->content.sandboxNsFlags = sandbox->sandboxNsFlags;
}
return 0;
}
APPSPAWN_STATIC int PreLoadSandboxCfg(AppSpawnMgr *content)
{
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content, EXT_DATA_SANDBOX);
APPSPAWN_CHECK(sandbox == NULL, return 0, "Sandbox has been load");
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != NULL, return APPSPAWN_SYSTEM_ERROR);
OH_ListAddTail(&content->extData, &sandbox->extData.node);
// load app sandbox config
LoadAppSandboxConfig(sandbox, content->content.mode);
sandbox->maxPermissionIndex = PermissionRenumber(&sandbox->permissionQueue);
content->content.sandboxNsFlags = 0;
@ -502,9 +526,17 @@ APPSPAWN_STATIC int PreLoadSandboxCfg(AppSpawnMgr *content)
return 0;
}
APPSPAWN_STATIC int IsolatedSandboxHandleServerExit(AppSpawnMgr *content)
{
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content, EXT_DATA_ISOLATED_SANDBOX);
APPSPAWN_CHECK(sandbox != NULL, return 0, "Isolated sandbox not load");
return 0;
}
APPSPAWN_STATIC int SandboxHandleServerExit(AppSpawnMgr *content)
{
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content);
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content, EXT_DATA_SANDBOX);
APPSPAWN_CHECK(sandbox != NULL, return 0, "Sandbox not load");
return 0;
@ -512,7 +544,9 @@ APPSPAWN_STATIC int SandboxHandleServerExit(AppSpawnMgr *content)
int SpawnBuildSandboxEnv(AppSpawnMgr *content, AppSpawningCtx *property)
{
AppSpawnSandboxCfg *appSandbox = GetAppSpawnSandbox(content);
ExtDataType type = CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX_TYPE) ? EXT_DATA_ISOLATED_SANDBOX :
EXT_DATA_SANDBOX;
AppSpawnSandboxCfg *appSandbox = GetAppSpawnSandbox(content, type);
APPSPAWN_CHECK(appSandbox != NULL, return -1, "Failed to get sandbox for %{public}s", GetProcessName(property));
// no sandbox
if (CheckAppMsgFlagsSet(property, APP_FLAGS_NO_SANDBOX)) {
@ -582,7 +616,9 @@ int SpawnPrepareSandboxCfg(AppSpawnMgr *content, AppSpawningCtx *property)
APPSPAWN_CHECK_ONLY_EXPER(content != NULL, return -1);
APPSPAWN_CHECK_ONLY_EXPER(property != NULL, return -1);
APPSPAWN_LOGV("Prepare sandbox config %{public}s", GetProcessName(property));
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content);
ExtDataType type = CheckAppMsgFlagsSet(property, APP_FLAGS_ISOLATED_SANDBOX_TYPE) ? EXT_DATA_ISOLATED_SANDBOX :
EXT_DATA_SANDBOX;
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content, type);
APPSPAWN_CHECK(sandbox != NULL, return -1, "Failed to get sandbox for %{public}s", GetProcessName(property));
int32_t index = 0;
@ -610,8 +646,13 @@ APPSPAWN_STATIC int SandboxUnmountPath(const AppSpawnMgr *content, const AppSpaw
{
APPSPAWN_CHECK_ONLY_EXPER(content != NULL, return -1);
APPSPAWN_CHECK_ONLY_EXPER(appInfo != NULL, return -1);
AppSpawnSandboxCfg *sandbox = NULL;
APPSPAWN_LOGV("Sandbox process %{public}s %{public}u exit", appInfo->name, appInfo->uid);
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(content);
if (content->content.mode == MODE_FOR_NATIVE_SPAWN) {
sandbox = GetAppSpawnSandbox(content, EXT_DATA_ISOLATED_SANDBOX);
} else {
sandbox = GetAppSpawnSandbox(content, EXT_DATA_SANDBOX);
}
return UnmountDepPaths(sandbox, appInfo->uid);
}
@ -620,7 +661,9 @@ MODULE_CONSTRUCTOR(void)
{
APPSPAWN_LOGV("Load sandbox module ...");
(void)AddServerStageHook(STAGE_SERVER_PRELOAD, HOOK_PRIO_SANDBOX, PreLoadSandboxCfg);
(void)AddServerStageHook(STAGE_SERVER_PRELOAD, HOOK_PRIO_SANDBOX, PreLoadIsoLatedSandboxCfg);
(void)AddServerStageHook(STAGE_SERVER_EXIT, HOOK_PRIO_SANDBOX, SandboxHandleServerExit);
(void)AddServerStageHook(STAGE_SERVER_EXIT, HOOK_PRIO_SANDBOX, IsolatedSandboxHandleServerExit);
(void)AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_SANDBOX, SpawnPrepareSandboxCfg);
(void)AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX, SpawnBuildSandboxEnv);
(void)AddProcessMgrHook(STAGE_SERVER_APP_DIED, 0, SandboxUnmountPath);

View File

@ -25,6 +25,7 @@
#include "cJSON.h"
#include "appspawn_client.h"
#include "appspawn_hook.h"
#ifdef __cplusplus
extern "C" {
@ -86,7 +87,7 @@ void ProcessSignal(const struct signalfd_siginfo *siginfo);
int CreateClientSocket(uint32_t type, int block);
void CloseClientSocket(int socketId);
int ParseAppSandboxConfig(const cJSON *appSandboxConfig, AppSpawnSandboxCfg *sandbox);
AppSpawnSandboxCfg *CreateAppSpawnSandbox(void);
AppSpawnSandboxCfg *CreateAppSpawnSandbox(ExtDataType type);
void AddDefaultVariable(void);
bool CheckDirRecursive(const char *path);
void CreateDemandSrc(const SandboxContext *context, const PathMountNode *sandboxNode, const MountArg *args);

View File

@ -679,7 +679,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Permission_01, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN);
sandbox->extData.dumpNode(&sandbox->extData);
@ -727,7 +727,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_ExpandCfg_01, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN);
// add default
@ -767,7 +767,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_ExpandCfg_02, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN);
@ -809,7 +809,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_ExpandCfg_03, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN);
@ -851,7 +851,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_ExpandCfg_04, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN);
@ -910,7 +910,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_cfg_001, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
LoadAppSandboxConfig(sandbox, MODE_FOR_APP_SPAWN);
sandbox->extData.dumpNode(&sandbox->extData);
@ -931,7 +931,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_cfg_002, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
APPSPAWN_LOGV("sandbox->rootPath: %{public}s", sandbox->rootPath);
@ -980,7 +980,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_cfg_003, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
TestParseAppSandboxConfig(sandbox, g_packageNameConfig.c_str());
@ -1028,7 +1028,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_cfg_004, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
TestParseAppSandboxConfig(sandbox, g_permissionConfig.c_str());
@ -1077,7 +1077,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_cfg_005, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
TestParseAppSandboxConfig(sandbox, g_spawnFlagsConfig.c_str());
@ -1118,7 +1118,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_cfg_006, TestSize.Level0)
AppSpawnSandboxCfg *sandbox = nullptr;
int ret = -1;
do {
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1171,7 +1171,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_001, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1224,7 +1224,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_002, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1276,7 +1276,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_003, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
@ -1336,7 +1336,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_004, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_packageNameConfig.c_str());
@ -1387,7 +1387,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_005, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
@ -1439,7 +1439,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_006, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
@ -1497,7 +1497,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_007, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
@ -1554,7 +1554,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Category_001, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1607,7 +1607,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Category_002, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1660,7 +1660,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Category_003, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1713,7 +1713,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Category_004, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1765,7 +1765,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Deps_001, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1817,7 +1817,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Deps_002, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1868,7 +1868,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Deps_003, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1920,7 +1920,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Deps_004, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -1972,7 +1972,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Deps_005, TestSize.Level0)
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
sandbox->appFullMountEnable = 1;
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
@ -2026,7 +2026,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_001, TestSize.Level
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
APPSPAWN_CHECK_ONLY_EXPER(ret == 0, break);
@ -2062,7 +2062,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_002, TestSize.Level
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
APPSPAWN_CHECK_ONLY_EXPER(ret == 0, break);
@ -2108,7 +2108,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_003, TestSize.Level
property = g_testHelper.GetAppProperty(clientHandle, reqHandle);
APPSPAWN_CHECK_ONLY_EXPER(property != nullptr, break);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
APPSPAWN_CHECK_ONLY_EXPER(sandbox != nullptr, break);
ret = TestParseAppSandboxConfig(sandbox, g_commonConfig.c_str());
APPSPAWN_CHECK_ONLY_EXPER(ret == 0, break);
@ -2343,7 +2343,7 @@ HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_mount_template, TestSize.Level0)
HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_permission, TestSize.Level0)
{
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
ASSERT_NE(sandbox, nullptr);
int ret = AddSandboxPermissionNode(FILE_CROSS_APP_MODE, nullptr);
ASSERT_EQ(ret, APPSPAWN_ARG_INVALID);

View File

@ -53,14 +53,14 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_AppSpawnSandboxCfg_001, TestSize.Leve
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(mgr);
AppSpawnSandboxCfg *sandbox = GetAppSpawnSandbox(mgr, EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox == nullptr, 1);
sandbox = CreateAppSpawnSandbox();
sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
sandbox = GetAppSpawnSandbox(mgr);
sandbox = GetAppSpawnSandbox(mgr, EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
// dump
@ -69,12 +69,12 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_AppSpawnSandboxCfg_001, TestSize.Leve
// delete
DeleteAppSpawnSandbox(sandbox);
// get none
sandbox = GetAppSpawnSandbox(mgr);
sandbox = GetAppSpawnSandbox(mgr, EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox == nullptr, 1);
DumpAppSpawnSandboxCfg(sandbox);
DeleteAppSpawnMgr(mgr);
sandbox = GetAppSpawnSandbox(nullptr);
sandbox = GetAppSpawnSandbox(nullptr, EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox == nullptr, 1);
}
@ -83,7 +83,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_AppSpawnSandboxCfg_002, TestSize.Leve
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -105,7 +105,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_AppSpawnSandboxCfg_003, TestSize.Leve
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
int ret = 0;
@ -136,7 +136,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxSection_001, TestSize.Level0)
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -183,7 +183,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxSection_002, TestSize.Level0)
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -220,7 +220,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxSection_003, TestSize.Level0)
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -246,7 +246,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxSection_004, TestSize.Level0)
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -288,7 +288,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxMountNode_001, TestSize.Level0
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -323,7 +323,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxMountNode_002, TestSize.Level0
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -354,7 +354,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxMountNode_003, TestSize.Level0
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -402,7 +402,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_SandboxMountNode_004, TestSize.Level0
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -477,7 +477,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_Mount_001, TestSize.Level0)
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -517,7 +517,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_Mount_002, TestSize.Level0)
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);
@ -550,7 +550,7 @@ HWTEST_F(AppSpawnSandboxMgrTest, App_Spawn_Mount_003, TestSize.Level0)
AppSpawnMgr *mgr = CreateAppSpawnMgr(MODE_FOR_NWEB_SPAWN);
EXPECT_EQ(mgr != nullptr, 1);
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox();
AppSpawnSandboxCfg *sandbox = CreateAppSpawnSandbox(EXT_DATA_SANDBOX);
EXPECT_EQ(sandbox != nullptr, 1);
sandbox->rootPath = strdup("/data/appspawn_ut/sandbox/");
OH_ListAddTail(&sandbox->extData.node, &mgr->extData);