• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <string>
18 #include <cerrno>
19 #include <memory>
20 
21 #include "appspawn_service.h"
22 #include "appspawn_adapter.h"
23 #include "appspawn_server.h"
24 #include "app_spawn_stub.h"
25 #include "securec.h"
26 #include "json_utils.h"
27 #include "init_hashmap.h"
28 #include "le_task.h"
29 #include "loop_event.h"
30 #include "sandbox_utils.h"
31 #include "parameter.h"
32 
33 using namespace testing;
34 using namespace testing::ext;
35 using namespace OHOS::AppSpawn;
36 using nlohmann::json;
37 
38 namespace OHOS {
39 class AppSpawnSandboxTest : public testing::Test {
40 public:
41     static void SetUpTestCase();
42     static void TearDownTestCase();
43     void SetUp();
44     void TearDown();
45 };
46 
SetUpTestCase()47 void AppSpawnSandboxTest::SetUpTestCase()
48 {}
49 
TearDownTestCase()50 void AppSpawnSandboxTest::TearDownTestCase()
51 {}
52 
SetUp()53 void AppSpawnSandboxTest::SetUp()
54 {}
55 
TearDown()56 void AppSpawnSandboxTest::TearDown()
57 {}
58 
GetAppSpawnClientExt(void)59 static AppSpawnClientExt *GetAppSpawnClientExt(void)
60 {
61     static AppSpawnClientExt client;
62     return &client;
63 }
64 
GetAppProperty(void)65 static ClientSocket::AppProperty *GetAppProperty(void)
66 {
67     return &GetAppSpawnClientExt()->property;
68 }
69 
GetAppSpawnClient(void)70 static AppSpawnClient *GetAppSpawnClient(void)
71 {
72     return &GetAppSpawnClientExt()->client;
73 }
74 
75 /**
76 * @tc.name: App_Spawn_Sandbox_005
77 * @tc.desc: load system config SetAppSandboxProperty by App ohos.samples.ecg.
78 * @tc.type: FUNC
79 * @tc.require:issueI5NTX6
80 * @tc.author:
81 */
82 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_08, TestSize.Level0)
83 {
84     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_08 start";
85     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
86 
87     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
88     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
89     m_appProperty->gidCount = 1;
90 
91     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "ohos.samples.ecg") != 0) {
92         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
93     }
94 
95     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "ohos.samples.ecg") != 0) {
96         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
97     }
98 
99     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
100         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
101     }
102 
103     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
104 
105     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
106     m_appProperty->pid = 354; // query render process exited status by render process pid
107 
108     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
109     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_08 end";
110 }
111 
112 /**
113 * @tc.name: App_Spawn_Sandbox_09
114 * @tc.desc: load system config SetAppSandboxProperty by App com.ohos.dlpmanager.
115 * @tc.type: FUNC
116 * @tc.require:issueI5NTX6
117 * @tc.author:
118 */
119 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_09, TestSize.Level0)
120 {
121     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_09 start";
122     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
123 
124     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
125     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
126     m_appProperty->gidCount = 1;
127 
128     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "com.ohos.dlpmanager") != 0) {
129         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
130     }
131 
132     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "com.ohos.dlpmanager") != 0) {
133         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
134     }
135 
136     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
137         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
138     }
139 
140     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
141     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
142     m_appProperty->pid = 354; // query render process exited status by render process pid
143 
144     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
145     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_09 end";
146 }
147 
148 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_09_1, TestSize.Level0)
149 {
150     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_09_1 start";
151     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
152 
153     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
154     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
155     m_appProperty->gidCount = 1;
156 
157     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "com.ohos.dlpmanager") != 0) {
158         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
159     }
160 
161     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
162         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
163     }
164 
165     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
166     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
167     m_appProperty->pid = 354; // query render process exited status by render process pid
168 
169     int ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(nullptr);
170     EXPECT_NE(ret, 0);
171     m_appProperty->bundleName[0] = '\0';
172     ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
173     EXPECT_NE(ret, 0);
174     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "com.\\ohos.dlpmanager") != 0) {
175         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
176     }
177     ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
178     EXPECT_NE(ret, 0);
179     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "com./ohos.dlpmanager") != 0) {
180         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
181     }
182     ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
183     EXPECT_NE(ret, 0);
184     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_09_1 end";
185 }
186 
187 /**
188 * @tc.name: App_Spawn_Sandbox_10
189 * @tc.desc: parse config define by self Set App Sandbox Property.
190 * @tc.type: FUNC
191 * @tc.require:issueI5NTX6
192 * @tc.author:
193 */
194 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_10, TestSize.Level0)
195 {
196     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_10 start";
197     std::string mJsconfig = "{ \
198         \"common\":[{ \
199             \"top-sandbox-switch\": \"ON\", \
200             \"app-base\":[{ \
201                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
202                 \"mount-paths\" : [{ \
203                     \"src-path\" : \"/config\", \
204                     \"sandbox-path\" : \"/config\", \
205                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
206                     \"check-action-status\": \"false\", \
207                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
208                 }], \
209                 \"symbol-links\" : [] \
210             }] \
211         }], \
212         \"individual\": [] \
213     }";
214     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
215 
216     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
217 
218     GTEST_LOG_(INFO) << "SetAppSandboxProperty start" << std::endl;
219     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
220 
221     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
222     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
223 
224     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "test.appspawn") != 0) {
225         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
226     }
227     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
228         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
229     }
230     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
231         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
232     }
233 
234     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
235     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
236     m_appProperty->pid = 354; // query render process exited status by render process pid
237 
238     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
239     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_10 end";
240 }
241 
242 /**
243 * @tc.name: App_Spawn_Sandbox_012
244 * @tc.desc: Create an application process parameter check.
245 * @tc.type: FUNC
246 * @tc.require: issueI5OE8Q
247 * @tc.author:
248 */
249 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_012, TestSize.Level0)
250 {
251     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_012 start";
252     AppSpawnContent_ appContent = {0};
253     AppSpawnClient appClient = {0};
254     pid_t pid = -1;
255     AppSandboxArg *sandboxArg = (AppSandboxArg *)malloc(sizeof(AppSandboxArg));
256     EXPECT_TRUE(sandboxArg != nullptr);
257     (void)memset_s(sandboxArg, sizeof(AppSandboxArg), 0, sizeof(AppSandboxArg));
258     int ret = AppSpawnProcessMsg(sandboxArg, &pid);
259     EXPECT_TRUE(ret < 0);
260     sandboxArg->content = &appContent;
261     ret = AppSpawnProcessMsg(sandboxArg, &pid);
262     EXPECT_TRUE(ret < 0);
263     sandboxArg->client = &appClient;
264     ret = AppSpawnProcessMsg(sandboxArg, NULL);
265     EXPECT_TRUE(ret < 0);
266     free(sandboxArg);
267     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_012 end";
268 }
269 
270 /**
271 * @tc.name: App_Spawn_Sandbox_13
272 * @tc.desc: parse config define by self Set App Sandbox Property.
273 * @tc.type: FUNC
274 * @tc.require:issueI5NTX6
275 * @tc.author:
276 */
277 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_13, TestSize.Level0)
278 {
279     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_13 start";
280     std::string mJsconfig = "{ \
281         \"common\":[{ \
282             \"app-base\":[{ \
283                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
284                 \"mount-paths\" : [{ \
285                     \"src-path\" : \"/config\", \
286                     \"sandbox-path\" : \"\", \
287                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
288                     \"check-action-status\": \"false\", \
289                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
290                 }], \
291                 \"symbol-links\" : [] \
292             }] \
293         }], \
294         \"individual\": [] \
295     }";
296     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
297 
298     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
299 
300     GTEST_LOG_(INFO) << "SetAppSandboxProperty start" << std::endl;
301     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
302 
303     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
304     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
305 
306     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "test.appspawn") != 0) {
307         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
308     }
309     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
310         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
311     }
312     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
313         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
314     }
315 
316     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
317     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
318     m_appProperty->pid = 354; // query render process exited status by render process pid
319 
320     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
321     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_13 end";
322 }
323 
324 /**
325 * @tc.name: App_Spawn_Sandbox_14
326 * @tc.desc: parse sandbox config without sandbox-root label
327 * @tc.type: FUNC
328 * @tc.require:issueI5NTX6
329 * @tc.author:
330 */
331 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_14, TestSize.Level0)
332 {
333     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_14 start";
334     std::string mJsconfig = "{ \
335         \"common\":[{ \
336             \"app-base\":[{ \
337                 \"mount-paths\" : [{ \
338                     \"src-path\" : \"/config\", \
339                     \"sandbox-path\" : \"\", \
340                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
341                     \"check-action-status\": \"false\", \
342                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
343                 }], \
344                 \"symbol-links\" : [] \
345             }] \
346         }], \
347         \"individual\": [] \
348     }";
349     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
350 
351     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
352 
353     GTEST_LOG_(INFO) << "SetAppSandboxProperty start" << std::endl;
354     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
355 
356     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
357     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
358 
359     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "test.appspawn") != 0) {
360         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
361     }
362     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
363         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
364     }
365     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
366         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
367     }
368 
369     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
370     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
371     m_appProperty->pid = 354; // query render process exited status by render process pid
372 
373     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
374     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_14 end";
375 }
376 
377 /**
378 * @tc.name: App_Spawn_Sandbox_15
379 * @tc.desc: parse app sandbox config with PackageName_index label
380 * @tc.type: FUNC
381 * @tc.require:issueI5NTX6
382 * @tc.author:
383 */
384 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_15, TestSize.Level0)
385 {
386     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_15 start";
387     std::string mJsconfig = "{ \
388         \"common\":[{ \
389             \"app-base\":[{ \
390                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName_index>\", \
391                 \"mount-paths\" : [{ \
392                     \"src-path\" : \"/config\", \
393                     \"sandbox-path\" : \"\", \
394                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
395                     \"check-action-status\": \"false\", \
396                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
397                 }], \
398                 \"symbol-links\" : [] \
399             }] \
400         }], \
401         \"individual\": [] \
402     }";
403     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
404 
405     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
406 
407     GTEST_LOG_(INFO) << "SetAppSandboxProperty start" << std::endl;
408     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
409 
410     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
411     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
412 
413     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "test.appspawn") != 0) {
414         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
415     }
416     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
417         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
418     }
419     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
420         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
421     }
422 
423     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
424     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
425     m_appProperty->pid = 354; // query render process exited status by render process pid
426 
427     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
428     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_15 end";
429 }
430 
431 /**
432 * @tc.name: App_Spawn_Sandbox_16
433 * @tc.desc: parse config define by self Set App Sandbox Property.
434 * @tc.type: FUNC
435 * @tc.require:issueI5NTX6
436 * @tc.author:
437 */
438 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_16, TestSize.Level0)
439 {
440     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_16 start";
441     std::string mJsconfig = "{ \
442         \"common\":[{ \
443             \"app-base\":[{ \
444                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
445                 \"symbol-links\" : [] \
446             }] \
447         }], \
448         \"individual\": [] \
449     }";
450     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
451 
452     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
453 
454     GTEST_LOG_(INFO) << "SetAppSandboxProperty start" << std::endl;
455     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
456 
457     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
458     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
459 
460     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "test.appspawn") != 0) {
461         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
462     }
463     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
464         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
465     }
466     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
467         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
468     }
469 
470     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
471     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
472     m_appProperty->pid = 354; // query render process exited status by render process pid
473 
474     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
475     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_16 end";
476 }
477 
478 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_17, TestSize.Level0)
479 {
480     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_09 start";
481     nlohmann::json appSandboxConfig;
482     bool rc = JsonUtils::GetJsonObjFromJson(appSandboxConfig, "");
483     EXPECT_FALSE(rc);
484     std::string path(256, 'w'); // 256 test
485     rc = JsonUtils::GetJsonObjFromJson(appSandboxConfig, path);
486     EXPECT_FALSE(rc);
487 
488     std::string mJsconfig = "{ \
489         \"common\":[{ \
490             \"app-base\":[{ \
491                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
492                 \"symbol-links\" : [] \
493             }] \
494         }], \
495         \"individual\": [] \
496     }";
497     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
498     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
499 
500     std::string value;
501     rc = JsonUtils::GetStringFromJson(j_config, "common", value);
502     EXPECT_FALSE(rc);
503     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_09 end";
504 }
505 
506 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_18, TestSize.Level0)
507 {
508     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_18 start";
509     std::string mJsconfig1 = "{ \
510         \"sandbox-switch\": \"ON\", \
511         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
512     }";
513     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
514     bool ret = OHOS::AppSpawn::SandboxUtils::GetSbxSwitchStatusByConfig(j_config1);
515     EXPECT_TRUE(ret);
516 
517     std::string mJsconfig2 = "{ \
518         \"sandbox-switch\": \"OFF\", \
519         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
520     }";
521     nlohmann::json j_config2 = nlohmann::json::parse(mJsconfig2.c_str());
522     ret = OHOS::AppSpawn::SandboxUtils::GetSbxSwitchStatusByConfig(j_config2);
523     EXPECT_FALSE(ret);
524 
525     std::string mJsconfig3 = "{ \
526         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
527     }";
528     nlohmann::json j_config3 = nlohmann::json::parse(mJsconfig3.c_str());
529     ret = OHOS::AppSpawn::SandboxUtils::GetSbxSwitchStatusByConfig(j_config3);
530     EXPECT_TRUE(ret);
531 }
532 
533 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_19, TestSize.Level0)
534 {
535     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_19 start";
536     int ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(nullptr);
537     EXPECT_EQ(ret, -1);
538 
539     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
540     ret = memset_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, 0, APP_LEN_BUNDLE_NAME);
541     if (ret != 0) {
542         GTEST_LOG_(ERROR) << "Failed to memset_s err=" << errno;
543         ASSERT_TRUE(0);
544     }
545     ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
546     EXPECT_EQ(ret, -1);
547 
548     ret = strncpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "\\test", APP_LEN_BUNDLE_NAME - 1);
549     if (ret != 0) {
550         GTEST_LOG_(ERROR) << "Failed to strncpy_s err=" << errno;
551         ASSERT_TRUE(0);
552     }
553     ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
554     EXPECT_EQ(ret, -1);
555 
556     ret = strncpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "/test", APP_LEN_BUNDLE_NAME - 1);
557     if (ret != 0) {
558         GTEST_LOG_(ERROR) << "Failed to strncpy_s err=" << errno;
559         ASSERT_TRUE(0);
560     }
561     ret = OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
562     EXPECT_EQ(ret, -1);
563 }
564 
565 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_20, TestSize.Level0)
566 {
567     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_20 start";
568     std::string mJsconfig = "{ \
569         \"common\":[{ \
570             \"top-sandbox-switch\": \"OFF\", \
571             \"app-base\":[{ \
572                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
573                 \"symbol-links\" : [] \
574             }] \
575         }], \
576         \"individual\": [] \
577     }";
578     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
579     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
580     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
581 
582     m_appProperty->uid = 1000; // the UNIX uid that the child process setuid() to after fork()
583     m_appProperty->gid = 1000; // the UNIX gid that the child process setgid() to after fork()
584 
585     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "test.appspawn") != 0) {
586         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
587     }
588     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
589         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
590     }
591     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
592         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
593     }
594     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
595 
596     std::string mJsconfig1 = "{ \
597         \"common\":[{ \
598             \"app-base\":[{ \
599                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
600                 \"symbol-links\" : [] \
601             }] \
602         }], \
603         \"individual\": [{ \
604             \"test.bundle.name\" : [{ \
605                 \"sandbox-switch\": \"OFF\", \
606                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
607             }] \
608         }] \
609     }";
610     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
611     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config1);
612     OHOS::AppSpawn::SandboxUtils::SetAppSandboxProperty(GetAppSpawnClient());
613 }
614 
615 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_21, TestSize.Level0)
616 {
617     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_21 start";
618 
619     bool ret = OHOS::AppSpawn::SandboxUtils::CheckBundleNameForPrivate(std::string("__internal__"));
620     EXPECT_FALSE(ret);
621 }
622 
623 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_22, TestSize.Level0)
624 {
625     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_22 start";
626     std::string mJsconfig1 = "{ \
627         \"common\":[], \
628         \"individual\": [] \
629     }";
630     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
631     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config1);
632 
633     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
634     int ret = strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "system_basic");
635     if (ret != 0) {
636         GTEST_LOG_(ERROR) << "Failed to strcpy_s err=" << errno;
637         ASSERT_TRUE(0);
638     }
639     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
640     std::string testBundle = strl1;
641     ret = OHOS::AppSpawn::SandboxUtils::SetCommonAppSandboxProperty(m_appProperty,
642             testBundle);
643     EXPECT_EQ(ret, 0);
644 
645     if (memset_s(m_appProperty->apl, APP_APL_MAX_LEN, 0, APP_APL_MAX_LEN) != 0) {
646         GTEST_LOG_(ERROR) << "Failed to memset_s err=" << errno;
647         ASSERT_TRUE(0);
648     }
649     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "system_core") != 0) {
650         GTEST_LOG_(ERROR) << "Failed to strcpy_s err=" << errno;
651         ASSERT_TRUE(0);
652     }
653     ret = OHOS::AppSpawn::SandboxUtils::SetCommonAppSandboxProperty(m_appProperty,
654             testBundle);
655     EXPECT_EQ(ret, 0);
656 }
657 
658 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_23, TestSize.Level0)
659 {
660     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_23 start";
661     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
662     std::string testBundle = strl1;
663     int ret = OHOS::AppSpawn::SandboxUtils::SetRenderSandboxProperty(nullptr,
664             testBundle);
665     EXPECT_EQ(ret, 0);
666 }
667 
668 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_24, TestSize.Level0)
669 {
670     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_24 start";
671     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
672     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name1") != 0) {
673         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
674     }
675     m_appProperty->bundleIndex = 1;
676     std::string mJsconfig1 = "{ \
677         \"common\":[{ \
678             \"app-base\":[{ \
679                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
680                 \"symbol-links\" : [{ \
681                     \"target-name\" : \"/system/etc\", \
682                     \"link-name\" : \"/etc\", \
683                     \"check-action-status\": \"false\" \
684                 }, { \
685                     \"target\" : \"/system/etc\", \
686                     \"link\" : \"/etc\", \
687                     \"check\": \"false\" \
688                 }] \
689             }], \
690             \"app-resources\" : [{ \
691                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
692                 \"mount-paths\" : [], \
693                 \"symbol-links\" : [] \
694             }] \
695         }] \
696     }";
697     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
698     int ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFileCommonSymlink(m_appProperty, j_config1);
699     EXPECT_EQ(ret, 0);
700 
701     std::string mJsconfig2 = "{ \
702         \"common\":[{ \
703             \"app-base\":[{ \
704                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
705                 \"symbol-links\" : [{ \
706                     \"target-name\" : \"/data/test123\", \
707                     \"link-name\" : \"/test123\", \
708                     \"check-action-status\": \"true\" \
709                 }] \
710             }] \
711         }] \
712     }";
713     nlohmann::json j_config2 = nlohmann::json::parse(mJsconfig2.c_str());
714     ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFileCommonSymlink(m_appProperty, j_config2);
715     EXPECT_NE(ret, 0);
716 }
717 
718 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_25, TestSize.Level0)
719 {
720     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_25 start";
721     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
722     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.wps") != 0) {
723         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
724     }
725     m_appProperty->flags = 4; // 4 is test parameter
726     std::string mJsconfig1 = "{ \
727         \"common\":[{ \
728             \"app-resources\" : [{ \
729                 \"flags\": \"DLP_MANAGER\", \
730                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
731                 \"mount-paths\" : [{ \
732                     \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
733                     \"sandbox-path\" : \"/data/storage/el2/base\", \
734                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
735                     \"check-action-status\": \"false\", \
736                     \"app-apl-name\": \"test123\", \
737                     \"fs-type\": \"ext4\" \
738                 }, { \
739                     \"src\" : \"/data/app/el1/<currentUserId>/database/<PackageName_index>\", \
740                     \"sandbox-path\" : \"/data/storage/el1/database\", \
741                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
742                     \"check-action-status\": \"false\" \
743                 }], \
744                 \"symbol-links\" : [] \
745             }] \
746         }] \
747     }";
748     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
749     int ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFileCommonBind(m_appProperty, j_config1);
750     EXPECT_EQ(ret, 0);
751 
752     ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFileCommonFlagsPointHandle(m_appProperty, j_config1);
753     EXPECT_EQ(ret, 0);
754 }
755 
756 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_26, TestSize.Level0)
757 {
758     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_26 start";
759     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
760     std::string mJsconfig2 = "{ \
761         \"common\":[{ \
762             \"app-base\" : [{ \
763                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
764                 \"mount-paths\" : [{ \
765                     \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
766                     \"sandbox-path\" : \"/data/storage/el2/base\", \
767                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
768                     \"fs-type\" : \"ext4\", \
769                     \"check-action-status\": \"true\" \
770                 }] \
771             }] \
772         }] \
773     }";
774     nlohmann::json j_config2 = nlohmann::json::parse(mJsconfig2.c_str());
775     if (memset_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, 0, APP_LEN_BUNDLE_NAME) != 0) {
776         GTEST_LOG_(INFO) << "Failed to memset_s err=" << errno << std::endl;
777     }
778     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "com.ohos.dlpmanager") != 0) {
779         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
780     }
781     int ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFileCommonBind(m_appProperty, j_config2);
782     EXPECT_NE(ret, 0);
783 }
784 
785 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_27, TestSize.Level0)
786 {
787     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_27 start";
788     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
789     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
790         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
791     }
792     std::string mJsconfig1 = "{ \
793         \"individual\": [{ \
794             \"test.bundle.name\" : [{ \
795                 \"sandbox-switch\": \"OFF\", \
796                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
797             }] \
798         }] \
799     }";
800     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
801     int ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFilePrivateFlagsPointHandle(m_appProperty, j_config1);
802     EXPECT_EQ(ret, 0);
803 
804     std::string mJsconfig2 = "{ \
805         \"individual\": [{ \
806             \"test.bundle.name\" : [{ \
807                 \"flags-point\" : [{ \
808                     \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
809                     \"mount-paths\" : [{ \
810                         \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
811                         \"sandbox-path\" : \"/data/storage/el2/base\", \
812                         \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
813                         \"check-action-status\": \"false\" \
814                     }]\
815                 }], \
816                 \"sandbox-switch\": \"OFF\", \
817                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
818             }] \
819         }] \
820     }";
821     nlohmann::json j_config2 = nlohmann::json::parse(mJsconfig2.c_str());
822     ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFilePrivateFlagsPointHandle(m_appProperty, j_config2);
823     EXPECT_EQ(ret, 0);
824 }
825 
826 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_28, TestSize.Level0)
827 {
828     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_28 start";
829     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
830     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
831         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
832     }
833     m_appProperty->flags = 4;
834     std::string mJsconfig3 = "{ \
835         \"individual\": [{ \
836             \"test.bundle.name\" : [{ \
837                 \"flags-point\" : [{ \
838                     \"flags\": \"DLP_MANAGER\", \
839                     \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
840                     \"mount-paths\" : [{ \
841                         \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
842                         \"sandbox-path\" : \"/data/storage/el2/base\", \
843                         \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
844                         \"check-action-status\": \"false\" \
845                     }] \
846                 }], \
847                 \"sandbox-switch\": \"OFF\", \
848                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
849             }] \
850         }] \
851     }";
852     nlohmann::json j_config3 = nlohmann::json::parse(mJsconfig3.c_str());
853     int ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFilePrivateFlagsPointHandle(m_appProperty, j_config3);
854     EXPECT_EQ(ret, 0);
855 }
856 
857 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_29, TestSize.Level0)
858 {
859     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_29 start";
860     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
861     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "test.bundle.name") != 0) {
862         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
863     }
864     m_appProperty->flags = 4;
865     std::string mJsconfig3 = "{ \
866         \"individual\": [{ \
867             \"test.bundle.name\" : [{ \
868                 \"flags-point\" : [{ \
869                     \"flags\": \"DLP_MANAGER\", \
870                     \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
871                     \"mount-paths\" : [{ \
872                         \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
873                         \"sandbox-path\" : \"/data/storage/el2/base\", \
874                         \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
875                         \"check-action-status\": \"false\" \
876                     }] \
877                 }], \
878                 \"sandbox-switch\": \"OFF\", \
879                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
880             }] \
881         }] \
882     }";
883     nlohmann::json j_config3 = nlohmann::json::parse(mJsconfig3.c_str());
884     int ret = OHOS::AppSpawn::SandboxUtils::DoSandboxFilePrivateFlagsPointHandle(m_appProperty, j_config3);
885     EXPECT_EQ(ret, 0);
886 }
887 
888 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_30, TestSize.Level0)
889 {
890     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_30 start";
891     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
892 
893     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "apl123") != 0) {
894         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
895     }
896 
897     std::string mJsconfig3 = "{ \
898         \"flags\": \"DLP_MANAGER\", \
899         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
900         \"mount-paths\" : [{ \
901             \"src-path\" : \"/data/app/el2/<currentUserId>/base/database/<PackageName>\", \
902             \"sandbox-path\" : \"/data/storage/el2/base\", \
903             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
904             \"check-action-status\": \"false\" \
905         }] \
906     }";
907     nlohmann::json j_config3 = nlohmann::json::parse(mJsconfig3.c_str());
908     m_appProperty->flags = 4;
909     if (memset_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, 0, APP_LEN_BUNDLE_NAME) != 0) {
910         GTEST_LOG_(INFO) << "Failed to memset_s err=" << errno << std::endl;
911     }
912     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "com.ohos.wps") != 0) {
913         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
914     }
915     int ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(m_appProperty, j_config3);
916     EXPECT_EQ(ret, 0);
917 
918     std::string mJsconfig4 = "{ \
919         \"flags\": \"DLP_MANAGER\", \
920         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
921         \"mount-paths\" : [{ \
922             \"src-path\" : \"/data/app/el2/<currentUserId>/database/<PackageName>\", \
923             \"sandbox-path\" : \"/data/storage/el2/base\", \
924             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
925             \"check-action-status\": \"false\" \
926         }] \
927     }";
928     nlohmann::json j_config4 = nlohmann::json::parse(mJsconfig4.c_str());
929     ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(m_appProperty, j_config4);
930     EXPECT_EQ(ret, 0);
931 }
932 
933 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_31, TestSize.Level0)
934 {
935     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_31 start";
936     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
937     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "com.ohos.dlpmanager") != 0) {
938         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
939     }
940     std::string mJsconfig1 = "{ \
941         \"flags\": \"DLP_TEST\", \
942         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
943         \"mount-paths\" : [{ \
944             \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
945             \"sandbox-path\" : \"/data/storage/el2/base\", \
946             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
947             \"check-action-status\": \"false\" \
948         }] \
949     }";
950     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
951     int ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(m_appProperty, j_config1);
952     EXPECT_EQ(ret, 0);
953 
954     std::string mJsconfig2 = "{ \
955         \"flags\": \"DLP_TEST\", \
956         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
957         \"mount-paths\" : [{ \
958             \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
959             \"sandbox-path\" : \"/data/storage/el2/base\", \
960             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
961             \"fs-type\" : \"ext4\", \
962             \"check-action-status\": \"false\", \
963             \"app-apl-name\" : \"apl123\" \
964         }, { \
965             \"src-path\" : \"/data/app/el2/<currentUserId>/database/<PackageName_index>\", \
966             \"sandbox-path\" : \"/data/storage/el2/base\", \
967             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
968             \"fs-type\" : \"ext4\", \
969             \"check-action-status\": \"true\" \
970         }] \
971     }";
972 
973     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "apl123") != 0) {
974         GTEST_LOG_(INFO) << "Failed to strcpy_s err=" << errno << std::endl;
975     }
976     nlohmann::json j_config2 = nlohmann::json::parse(mJsconfig2.c_str());
977     ret = OHOS::AppSpawn::SandboxUtils::DoAllMntPointsMount(m_appProperty, j_config2);
978     EXPECT_TRUE(ret != 0);
979 }
980 
981 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_32, TestSize.Level0)
982 {
983     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_32 start";
984     int ret = OHOS::AppSpawn::SandboxUtils::DoAppSandboxMountOnce(nullptr, "", nullptr, 0, nullptr);
985     EXPECT_EQ(ret, 0);
986 
987     std::string mJsconfig1 = "{ \
988         \"dest-mode\" : \"S_IRUSR|S_IWUSR|S_IXUSR\" \
989     }";
990     nlohmann::json j_config1 = nlohmann::json::parse(mJsconfig1.c_str());
991     std::string sandboxRoot;
992     const char *str = "/data/test11122";
993     sandboxRoot = str;
994     OHOS::AppSpawn::SandboxUtils::DoSandboxChmod(j_config1, sandboxRoot);
995 }
996 
997 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_34, TestSize.Level0)
998 {
999     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_34 start";
1000     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
1001     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
1002     std::string testBundle = strl1;
1003 
1004     { // totalLength is 0
1005         m_appProperty->extraInfo = {};
1006         int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
1007         EXPECT_EQ(0, ret);
1008     }
1009     { // data is nullptr
1010         m_appProperty->extraInfo = {1, 0, nullptr};
1011         int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
1012         EXPECT_EQ(0, ret);
1013     }
1014     { // success
1015         char hspListStr[] = "|HspList|{ \
1016             \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1017             \"modules\":[\"module1\", \"module2\"], \
1018             \"versions\":[\"v10001\", \"v10002\"] \
1019         }|HspList|";
1020         m_appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1021         int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
1022         EXPECT_EQ(0, ret);
1023     }
1024 
1025     m_appProperty->extraInfo = {};
1026     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_34 end";
1027 }
1028 
InvalidJsonTest(ClientSocket::AppProperty * appProperty,std::string & testBundle)1029 static void InvalidJsonTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1030 {
1031     char hspListStr[] = "|HspList|{|HspList|";
1032     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1033     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1034     EXPECT_NE(0, ret);
1035 }
1036 
NoBundleTest(ClientSocket::AppProperty * appProperty,std::string & testBundle)1037 static void NoBundleTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1038 {
1039     char hspListStr[] = "|HspList|{ \
1040         \"modules\":[\"module1\", \"module2\"], \
1041         \"versions\":[\"v10001\", \"v10002\"] \
1042     }|HspList|";
1043     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1044     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1045     EXPECT_NE(0, ret);
1046 }
1047 
NoModulesTest(ClientSocket::AppProperty * appProperty,std::string & testBundle)1048 static void NoModulesTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1049 {
1050     char hspListStr[] = "|HspList|{ \
1051         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1052         \"versions\":[\"v10001\", \"v10002\"] \
1053     }|HspList|";
1054     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1055     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1056     EXPECT_NE(0, ret);
1057 }
1058 
NoVersionsTest(ClientSocket::AppProperty * appProperty,std::string & testBundle)1059 static void NoVersionsTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1060 {
1061     char hspListStr[] = "|HspList|{ \
1062         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1063         \"modules\":[\"module1\", \"module2\"] \
1064     }|HspList|";
1065     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1066     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1067     EXPECT_NE(0, ret);
1068 }
1069 
ListSizeNotSameTest(ClientSocket::AppProperty * appProperty,std::string & testBundle)1070 static void ListSizeNotSameTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1071 {
1072     char hspListStr[] = "|HspList|{ \
1073         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1074         \"modules\":[\"module1\"], \
1075         \"versions\":[\"v10001\", \"v10002\"] \
1076     }|HspList|";
1077     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1078     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1079     EXPECT_NE(0, ret);
1080 }
1081 
ValueTypeIsNotArraryTest(ClientSocket::AppProperty * appProperty,std::string & testBundle)1082 static void ValueTypeIsNotArraryTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1083 {
1084     char hspListStr[] = "|HspList|{ \
1085         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1086         \"modules\":[\"module1\", \"module2\"], \
1087         \"versions\": 1001 \
1088     }|HspList|";
1089     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1090     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1091     EXPECT_NE(0, ret);
1092 }
1093 
ElementTypeIsNotStringTest(ClientSocket::AppProperty * appProperty,std::string & testBundle)1094 static void ElementTypeIsNotStringTest(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1095 {
1096     char hspListStr[] = "|HspList|{ \
1097         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1098         \"modules\":[\"module1\", \"module2\"], \
1099         \"versions\": [1001, 1002] \
1100     }|HspList|";
1101     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1102     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1103     EXPECT_NE(0, ret);
1104 }
1105 
ElementTypeIsNotSameTestSN(ClientSocket::AppProperty * appProperty,std::string & testBundle)1106 static void ElementTypeIsNotSameTestSN(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1107 {
1108     // element type is not same, string + number
1109     char hspListStr[] = "|HspList|{ \
1110         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1111         \"modules\":[\"module1\", \"module2\"], \
1112         \"versions\": [\"v10001\", 1002] \
1113     }|HspList|";
1114     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1115     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1116     EXPECT_NE(0, ret);
1117 }
1118 
ElementTypeIsNotSameTestNS(ClientSocket::AppProperty * appProperty,std::string & testBundle)1119 static void ElementTypeIsNotSameTestNS(ClientSocket::AppProperty* appProperty, std::string &testBundle)
1120 {
1121     // element type is not same, number + string
1122     char hspListStr[] = "|HspList|{ \
1123         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1124         \"modules\":[\"module1\", \"module2\"], \
1125         \"versions\": [1001, \"v10002\"] \
1126     }|HspList|";
1127     appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1128     int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(appProperty, testBundle);
1129     EXPECT_NE(0, ret);
1130 }
1131 
1132 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_35, TestSize.Level0)
1133 {
1134     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_35 start";
1135     ClientSocket::AppProperty *appProperty = GetAppProperty();
1136     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
1137     std::string testBundle = strl1;
1138     InvalidJsonTest(appProperty, testBundle);
1139     NoBundleTest(appProperty, testBundle);
1140     NoModulesTest(appProperty, testBundle);
1141     NoVersionsTest(appProperty, testBundle);
1142     ListSizeNotSameTest(appProperty, testBundle);
1143     ValueTypeIsNotArraryTest(appProperty, testBundle);
1144     ElementTypeIsNotStringTest(appProperty, testBundle);
1145     ElementTypeIsNotSameTestSN(appProperty, testBundle);
1146     ElementTypeIsNotSameTestNS(appProperty, testBundle);
1147     appProperty->extraInfo = {};
1148     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_35 end";
1149 }
1150 
1151 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_36, TestSize.Level0)
1152 {
1153     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_36 start";
1154     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
1155     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
1156     std::string testBundle = strl1;
1157 
1158     { // empty name
1159         char hspListStr[] = "|HspList|{ \
1160             \"bundles\":[\"\", \"test.bundle2\"], \
1161             \"modules\":[\"module1\", \"module2\"], \
1162             \"versions\":[\"v10001\", \"v10002\"] \
1163         }|HspList|";
1164         m_appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1165         int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
1166         EXPECT_NE(0, ret);
1167     }
1168     { // name is .
1169         char hspListStr[] = "|HspList|{ \
1170             \"bundles\":[\".\", \"test.bundle2\"], \
1171             \"modules\":[\"module1\", \"module2\"], \
1172             \"versions\":[\"v10001\", \"v10002\"] \
1173         }|HspList|";
1174         m_appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1175         int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
1176         EXPECT_NE(0, ret);
1177     }
1178     { // name is ..
1179         char hspListStr[] = "|HspList|{ \
1180             \"bundles\":[\"..\", \"test.bundle2\"], \
1181             \"modules\":[\"module1\", \"module2\"], \
1182             \"versions\":[\"v10001\", \"v10002\"] \
1183         }|HspList|";
1184         m_appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1185         int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
1186         EXPECT_NE(0, ret);
1187     }
1188     { // name contains /
1189         char hspListStr[] = "|HspList|{ \
1190             \"bundles\":[\"test/bundle1\", \"test.bundle2\"], \
1191             \"modules\":[\"module1\", \"module2\"], \
1192             \"versions\":[\"v10001\", \"v10002\"] \
1193         }|HspList|";
1194         m_appProperty->extraInfo = {strlen(hspListStr), 0, hspListStr};
1195         int ret = OHOS::AppSpawn::SandboxUtils::MountAllHsp(m_appProperty, testBundle);
1196         EXPECT_NE(0, ret);
1197     }
1198 
1199     m_appProperty->extraInfo = {};
1200     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_36 end";
1201 }
1202 
1203 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_37, TestSize.Level0)
1204 {
1205     APPSPAWN_LOGI("App_Spawn_Sandbox_37 start");
1206     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
1207     m_appProperty->uid = 1000;
1208     m_appProperty->gid = 1000;
1209     (void)strcpy_s(m_appProperty->bundleName, sizeof(m_appProperty->bundleName), "ohos.samples.xxx");
1210     AppSpawnContent content;
1211     LoadAppSandboxConfig(&content);
1212     std::string sandboxPackagePath = "/mnt/sandbox/100/";
1213     const std::string bundleName = m_appProperty->bundleName;
1214     sandboxPackagePath += bundleName;
1215 
1216     int ret = SandboxUtils::SetPrivateAppSandboxProperty(m_appProperty);
1217     EXPECT_EQ(0, ret);
1218     ret = SandboxUtils::SetCommonAppSandboxProperty(m_appProperty, sandboxPackagePath);
1219     EXPECT_EQ(0, ret);
1220     APPSPAWN_LOGI("App_Spawn_Sandbox_37 end");
1221 }
1222 
1223 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_38, TestSize.Level0)
1224 {
1225     APPSPAWN_LOGI("App_Spawn_Sandbox_38 start");
1226     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
1227     m_appProperty->uid = 1000;
1228     m_appProperty->gid = 1000;
1229 
1230     (void)strcpy_s(m_appProperty->bundleName, sizeof(m_appProperty->bundleName), "com.example.deviceinfo");
1231     std::string pJsconfig1 = "{ \
1232         \"common\":[],                      \
1233         \"individual\": [ {                  \
1234             \"com.example.deviceinfo\" : [{   \
1235             \"sandbox-switch\": \"ON\",     \
1236             \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\",  \
1237             \"mount-paths\" : [{    \
1238                     \"src-path\" : \"/data/app/el1/bundle/public/\",    \
1239                     \"sandbox-path\" : \"/data/accounts/account_0/applications/2222222\",   \
1240                     \"sandbox-flags\" : [ \"bind\", \"rec\" ],  \
1241                     \"check-action-status\": \"true\"   \
1242                 }, { \
1243                     \"src-path\" : \"/data/app/el1/bundle/public/\",    \
1244                     \"sandbox-path\" : \"/data/bundles/aaaaaa\",    \
1245                     \"sandbox-flags\" : [ \"bind\", \"rec\" ],  \
1246                     \"check-action-status\": \"true\"   \
1247                 }\
1248             ],\
1249             \"symbol-links\" : []   \
1250         }] \
1251         }] \
1252     }";
1253     try {
1254         nlohmann::json p_config1 = nlohmann::json::parse(pJsconfig1.c_str());
1255         OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(p_config1);
1256     } catch (nlohmann::detail::exception& e) {
1257         APPSPAWN_LOGE("App_Spawn_Sandbox_38 Invalid json");
1258         EXPECT_EQ(0, 1);
1259     }
1260     std::string sandboxPackagePath = "/mnt/sandbox/100/";
1261     const std::string bundleName = m_appProperty->bundleName;
1262     sandboxPackagePath += bundleName;
1263     int ret = SandboxUtils::SetPrivateAppSandboxProperty(m_appProperty);
1264     EXPECT_EQ(0, ret);
1265     ret = SandboxUtils::SetCommonAppSandboxProperty(m_appProperty, sandboxPackagePath);
1266     EXPECT_EQ(0, ret);
1267     APPSPAWN_LOGI("App_Spawn_Sandbox_38 end");
1268 }
1269 
1270 /**
1271 * @tc.name: App_Spawn_Sandbox_39
1272 * @tc.desc: load overlay config SetAppSandboxProperty by App com.ohos.demo.
1273 * @tc.type: FUNC
1274 * @tc.require:issueI7D0H9
1275 * @tc.author:
1276 */
1277 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_39, TestSize.Level0)
1278 {
1279     APPSPAWN_LOGI("App_Spawn_Sandbox_39 start");
1280     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
1281     m_appProperty->uid = 1000;
1282     m_appProperty->gid = 1000;
1283     m_appProperty->gidCount = 1;
1284     m_appProperty->flags |= 0x100;
1285     m_appProperty->extraInfo.totalLength = 55;
1286     string overlayInfo = "|Overlay|/data/app/el1/bundle/public/com.ohos.demo/feature.hsp|";
1287     overlayInfo+="/data/app/el1/bundle/public/com.ohos.demo/feature.hsp||Overlay|";
1288     m_appProperty->extraInfo.data = new char[overlayInfo.length() + 1];
1289     if (strcpy_s(m_appProperty->extraInfo.data, overlayInfo.length() + 1, overlayInfo.c_str()) != 0) {
1290         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 1" << std::endl;
1291     }
1292     std::string sandBoxRootDir = "/mnt/sandbox/100/com.ohos.demo";
1293 
1294     if (strcpy_s(m_appProperty->processName, APP_LEN_PROC_NAME, "com.ohos.demo") != 0) {
1295         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 2" << std::endl;
1296     }
1297 
1298     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "com.ohos.demo") != 0) {
1299         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 3" << std::endl;
1300     }
1301 
1302     if (strcpy_s(m_appProperty->apl, APP_APL_MAX_LEN, "normal") != 0) {
1303         GTEST_LOG_(INFO) << "SetAppSandboxProperty start 4" << std::endl;
1304     }
1305 
1306     GTEST_LOG_(INFO) << "SetAppSandboxProperty section 2"  << std::endl;
1307     m_appProperty->accessTokenId = 671201800; // 671201800 is accessTokenId
1308     m_appProperty->pid = 354; // query render process exited status by render process pid
1309 
1310     int32_t ret = OHOS::AppSpawn::SandboxUtils::SetOverlayAppSandboxProperty(m_appProperty, sandBoxRootDir);
1311     EXPECT_EQ(0, ret);
1312     m_appProperty->flags &= ~0x100;
1313     m_appProperty->extraInfo.totalLength = 0;
1314     if (m_appProperty->extraInfo.data != nullptr) {
1315         delete [] m_appProperty->extraInfo.data;
1316     }
1317     m_appProperty->extraInfo = {};
1318 
1319     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_39 end";
1320 }
1321 /**
1322 * @tc.name: App_Spawn_Sandbox_40
1323 * @tc.desc: load group info config SetAppSandboxProperty
1324 * @tc.type: FUNC
1325 * @tc.require:issueI7FUPV
1326 * @tc.author:
1327 */
1328 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_40, TestSize.Level0)
1329 {
1330     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_40 start";
1331     ClientSocket::AppProperty *m_appProperty = GetAppProperty();
1332     m_appProperty->uid = 1100;
1333     m_appProperty->gid = 1100;
1334     m_appProperty->gidCount = 2;
1335     m_appProperty->flags |= 0x100;
1336     std::string sandboxPrefix = "/mnt/sandbox/100/testBundle";
1337 
1338     if (strcpy_s(m_appProperty->bundleName, APP_LEN_BUNDLE_NAME, "testBundle") != 0) {
1339         GTEST_LOG_(INFO) << "SetAppSandboxProperty set bundleName" << std::endl;
1340     }
1341     { // totalLength is 0
1342         m_appProperty->extraInfo = {};
1343         int ret = OHOS::AppSpawn::SandboxUtils::MountAllGroup(m_appProperty, sandboxPrefix);
1344         EXPECT_EQ(0, ret);
1345     }
1346     { // data is nullptr
1347         m_appProperty->extraInfo = {1, 0, nullptr};
1348         int ret = OHOS::AppSpawn::SandboxUtils::MountAllGroup(m_appProperty, sandboxPrefix);
1349         EXPECT_EQ(0, ret);
1350     }
1351     { // success
1352         char dataGroupInfoListStr[] = "|DataGroup|{ \
1353             \"dataGroupId\":[\"1234abcd5678efgh\", \"abcduiop1234\"], \
1354             \"dir\":[\"/data/app/el2/100/group/091a68a9-2cc9-4279-8849-28631b598975\", \
1355                      \"/data/app/el2/100/group/ce876162-fe69-45d3-aa8e-411a047af564\"], \
1356             \"gid\":[\"20100001\", \"20100002\"] \
1357         }|DataGroup|";
1358         m_appProperty->extraInfo = {strlen(dataGroupInfoListStr), 0, dataGroupInfoListStr};
1359         int ret = OHOS::AppSpawn::SandboxUtils::MountAllGroup(m_appProperty, sandboxPrefix);
1360         EXPECT_EQ(0, ret);
1361     }
1362     m_appProperty->extraInfo = {};
1363     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_40 end";
1364 }
1365 
1366 /**
1367 * @tc.name: App_Spawn_Sandbox_41
1368 * @tc.desc: parse namespace config.
1369 * @tc.type: FUNC
1370 * @tc.require:issueI8B63M
1371 * @tc.author:
1372 */
1373 HWTEST(AppSpawnSandboxTest, App_Spawn_Sandbox_41, TestSize.Level0)
1374 {
1375     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_41 start";
1376     std::string mJsconfig = "{ \
1377         \"common\":[{ \
1378             \"top-sandbox-switch\": \"ON\", \
1379             \"app-base\":[{ \
1380                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
1381                 \"sandbox-ns-flags\": [ \"pid\" ], \
1382                 \"mount-paths\" : [], \
1383                 \"symbol-links\" : [] \
1384             }] \
1385         }], \
1386         \"individual\":[{ \
1387             \"__internal__.com.ohos.render\":[{ \
1388                 \"sandbox-root\" : \"/mnt/sandbox/com.ohos.render/<PackageName>\", \
1389                 \"sandbox-ns-flags\": [ \"pid\", \"net\" ], \
1390                 \"mount-paths\" : [], \
1391                 \"symbol-links\" : [] \
1392             }] \
1393         }] \
1394     }";
1395     nlohmann::json j_config = nlohmann::json::parse(mJsconfig.c_str());
1396 
1397     OHOS::AppSpawn::SandboxUtils::StoreJsonConfig(j_config);
1398 
1399     uint32_t cloneFlags = OHOS::AppSpawn::SandboxUtils::GetSandboxNsFlags(false);
1400     EXPECT_EQ(!!(cloneFlags & CLONE_NEWPID), true);
1401 
1402     cloneFlags = OHOS::AppSpawn::SandboxUtils::GetSandboxNsFlags(true);
1403     EXPECT_EQ(!!(cloneFlags & (CLONE_NEWPID | CLONE_NEWNET)), true);
1404 
1405     GTEST_LOG_(INFO) << "App_Spawn_Sandbox_41 end";
1406 }
1407 } // namespace OHOS
1408