• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
18 #include <cerrno>
19 #include <memory>
20 #include <string>
21 
22 #include "appspawn_server.h"
23 #include "appspawn_service.h"
24 #include "json_utils.h"
25 #include "parameter.h"
26 #include "sandbox_def.h"
27 #include "sandbox_core.h"
28 #include "sandbox_common.h"
29 #include "securec.h"
30 
31 #include "app_spawn_stub.h"
32 #include "app_spawn_test_helper.h"
33 #include "sandbox_dec.h"
34 #include "sandbox_shared_mount.h"
35 #include "parameters.h"
36 
37 using namespace testing;
38 using namespace testing::ext;
39 using namespace OHOS::AppSpawn;
40 
41 namespace OHOS {
42 AppSpawnTestHelper g_testHelper;
43 
44 class AppSpawnSandboxTest : public testing::Test {
45 public:
46     static void SetUpTestCase();
47     static void TearDownTestCase();
48     void SetUp();
49     void TearDown();
50 };
51 
SetUpTestCase()52 void AppSpawnSandboxTest::SetUpTestCase() {}
53 
TearDownTestCase()54 void AppSpawnSandboxTest::TearDownTestCase() {}
55 
SetUp()56 void AppSpawnSandboxTest::SetUp() {
57     const TestInfo *info = UnitTest::GetInstance()->current_test_info();
58     GTEST_LOG_(INFO) << info->test_suite_name() << "." << info->name() << " start";
59     APPSPAWN_LOGI("%{public}s.%{public}s start", info->test_suite_name(), info->name());
60 
61     std::vector<cJSON *> &appVec =
62         AppSpawn::SandboxCommon::GetCJsonConfig(SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
63     appVec.erase(appVec.begin(), appVec.end());
64 
65     std::vector<cJSON *> &isolatedVec =
66         AppSpawn::SandboxCommon::GetCJsonConfig(SandboxCommonDef::SANDBOX_ISOLATED_JSON_CONFIG);
67     isolatedVec.erase(isolatedVec.begin(), isolatedVec.end());
68 }
69 
TearDown()70 void AppSpawnSandboxTest::TearDown() {
71     std::vector<cJSON *> &appVec =
72         AppSpawn::SandboxCommon::GetCJsonConfig(SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
73     appVec.erase(appVec.begin(), appVec.end());
74 
75     std::vector<cJSON *> &isolatedVec =
76         AppSpawn::SandboxCommon::GetCJsonConfig(SandboxCommonDef::SANDBOX_ISOLATED_JSON_CONFIG);
77     isolatedVec.erase(isolatedVec.begin(), isolatedVec.end());
78 
79     const TestInfo *info = UnitTest::GetInstance()->current_test_info();
80     GTEST_LOG_(INFO) << info->test_suite_name() << "." << info->name() << " end";
81     APPSPAWN_LOGI("%{public}s.%{public}s end", info->test_suite_name(), info->name());
82 }
83 
GetTestAppProperty()84 static AppSpawningCtx *GetTestAppProperty()
85 {
86     AppSpawnClientHandle clientHandle = nullptr;
87     int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
88     APPSPAWN_CHECK(ret == 0, return nullptr, "Failed to create reqMgr");
89     AppSpawnReqMsgHandle reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0);
90     APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, return nullptr, "Failed to create req");
91     return g_testHelper.GetAppProperty(clientHandle, reqHandle);
92 }
93 
GetTestAppPropertyWithExtInfo(const char * name,const char * value)94 static AppSpawningCtx *GetTestAppPropertyWithExtInfo(const char *name, const char *value)
95 {
96     AppSpawnClientHandle clientHandle = nullptr;
97     int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
98     APPSPAWN_CHECK(ret == 0, return nullptr, "Failed to create reqMgr");
99     AppSpawnReqMsgHandle reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0);
100     APPSPAWN_CHECK(reqHandle != INVALID_REQ_HANDLE, return nullptr, "Failed to create req");
101     AppSpawnReqMsgAddStringInfo(reqHandle, name, value);
102     return g_testHelper.GetAppProperty(clientHandle, reqHandle);
103 }
104 
105 /**
106  * @tc.name: App_Spawn_Sandbox_005
107  * @tc.desc: load system config SetAppSandboxProperty by App ohos.samples.ecg.
108  * @tc.type: FUNC
109  * @tc.require:issueI5NTX6
110  * @tc.author:
111  */
112 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_08, TestSize.Level0)
113 {
114     g_testHelper.SetTestUid(1000);  // 1000 test
115     g_testHelper.SetTestGid(1000);  // 1000 test
116     g_testHelper.SetProcessName("ohos.samples.ecg");
117     AppSpawningCtx *appProperty = GetTestAppProperty();
118     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
119     EXPECT_EQ(ret, 0);
120 
121     DeleteAppSpawningCtx(appProperty);
122 }
123 
124 /**
125  * @tc.name: App_Spawn_Sandbox_09
126  * @tc.desc: load system config SetAppSandboxProperty by App com.ohos.dlpmanager.
127  * @tc.type: FUNC
128  * @tc.require:issueI5NTX6
129  * @tc.author:
130  */
131 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_09, TestSize.Level0)
132 {
133     g_testHelper.SetProcessName("com.ohos.dlpmanager");
134     g_testHelper.SetTestApl("normal");
135     AppSpawningCtx *appProperty = GetTestAppProperty();
136     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
137     EXPECT_EQ(ret, 0);
138 
139     DeleteAppSpawningCtx(appProperty);
140 }
141 
142 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_09_1, TestSize.Level0)
143 {
144     g_testHelper.SetTestUid(1000);  // 1000 test
145     g_testHelper.SetTestGid(1000);  // 1000 test
146     g_testHelper.SetProcessName("com.ohos.dlpmanager");
147     g_testHelper.SetTestApl("normal");
148     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(nullptr, CLONE_NEWPID);
149     EXPECT_NE(ret, 0);
150 }
151 
152 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_09_2, TestSize.Level0)
153 {
154     g_testHelper.SetTestUid(1000);  // 1000 test
155     g_testHelper.SetTestGid(1000);  // 1000 test
156     g_testHelper.SetProcessName("");
157     g_testHelper.SetTestApl("normal");
158     AppSpawningCtx *appProperty = GetTestAppProperty();
159     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
160     EXPECT_NE(ret, 0);
161 
162     DeleteAppSpawningCtx(appProperty);
163 }
164 
165 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_09_3, TestSize.Level0)
166 {
167     g_testHelper.SetTestUid(1000);  // 1000 test
168     g_testHelper.SetTestGid(1000);  // 1000 test
169     g_testHelper.SetProcessName("com.\\ohos.dlpmanager");
170     g_testHelper.SetTestApl("normal");
171     AppSpawningCtx *appProperty = GetTestAppProperty();
172     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
173     EXPECT_NE(ret, 0);
174 
175     DeleteAppSpawningCtx(appProperty);
176 }
177 
178 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_09_4, TestSize.Level0)
179 {
180     g_testHelper.SetTestUid(1000);  // 1000 test
181     g_testHelper.SetTestGid(1000);  // 1000 test
182     g_testHelper.SetProcessName("com./ohos.dlpmanager");
183     g_testHelper.SetTestApl("normal");
184     AppSpawningCtx *appProperty = GetTestAppProperty();
185     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
186     EXPECT_NE(ret, 0);
187 
188     DeleteAppSpawningCtx(appProperty);
189 }
190 
191 /**
192  * @tc.name: App_Spawn_Sandbox_10
193  * @tc.desc: parse config define by self Set App Sandbox Property.
194  * @tc.type: FUNC
195  * @tc.require:issueI5NTX6
196  * @tc.author:
197  */
198 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_10, TestSize.Level0)
199 {
200     std::string mJsconfig = "{ \
201         \"common\":[{ \
202             \"top-sandbox-switch\": \"ON\", \
203             \"app-base\":[{ \
204                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
205                 \"mount-paths\" : [{ \
206                     \"src-path\" : \"/config\", \
207                     \"sandbox-path\" : \"/config\", \
208                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
209                     \"check-action-status\": \"false\", \
210                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
211                 }], \
212                 \"symbol-links\" : [] \
213             }] \
214         }], \
215         \"individual\": [] \
216     }";
217     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
218     ASSERT_NE(j_config, nullptr);
219     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
220 
221     g_testHelper.SetTestUid(1000);  // 1000 test
222     g_testHelper.SetTestGid(1000);  // 1000 test
223     g_testHelper.SetProcessName("test.appspawn");
224     g_testHelper.SetTestApl("normal");
225     AppSpawningCtx *appProperty = GetTestAppProperty();
226     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
227     EXPECT_EQ(ret, 0);
228 
229     cJSON_Delete(j_config);
230     DeleteAppSpawningCtx(appProperty);
231 }
232 
233 /**
234  * @tc.name: App_Spawn_Sandbox_13
235  * @tc.desc: parse config define by self Set App Sandbox Property.
236  * @tc.type: FUNC
237  * @tc.require:issueI5NTX6
238  * @tc.author:
239  */
240 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_13, TestSize.Level0)
241 {
242     std::string mJsconfig = "{ \
243         \"common\":[{ \
244             \"app-base\":[{ \
245                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
246                 \"mount-paths\" : [{ \
247                     \"src-path\" : \"/config\", \
248                     \"sandbox-path\" : \"\", \
249                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
250                     \"check-action-status\": \"false\", \
251                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
252                 }], \
253                 \"symbol-links\" : [] \
254             }] \
255         }], \
256         \"individual\": [] \
257     }";
258     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
259     ASSERT_NE(j_config, nullptr);
260     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
261 
262     g_testHelper.SetTestUid(1000);  // 1000 test
263     g_testHelper.SetTestGid(1000);  // 1000 test
264     g_testHelper.SetProcessName("test.appspawn");
265     g_testHelper.SetTestApl("normal");
266     AppSpawningCtx *appProperty = GetTestAppProperty();
267     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
268     EXPECT_EQ(ret, 0);
269 
270     cJSON_Delete(j_config);
271     DeleteAppSpawningCtx(appProperty);
272 }
273 
274 /**
275  * @tc.name: App_Spawn_Sandbox_14
276  * @tc.desc: parse sandbox config without sandbox-root label
277  * @tc.type: FUNC
278  * @tc.require:issueI5NTX6
279  * @tc.author:
280  */
281 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_14, TestSize.Level0)
282 {
283     std::string mJsconfig = "{ \
284         \"common\":[{ \
285             \"app-base\":[{ \
286                 \"mount-paths\" : [{ \
287                     \"src-path\" : \"/config\", \
288                     \"sandbox-path\" : \"\", \
289                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
290                     \"check-action-status\": \"false\", \
291                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
292                 }], \
293                 \"symbol-links\" : [] \
294             }] \
295         }], \
296         \"individual\": [] \
297     }";
298     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
299     ASSERT_NE(j_config, nullptr);
300     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
301 
302     g_testHelper.SetTestUid(1000);  // 1000 test
303     g_testHelper.SetTestGid(1000);  // 1000 test
304     g_testHelper.SetProcessName("test.appspawn");
305     g_testHelper.SetTestApl("normal");
306     AppSpawningCtx *appProperty = GetTestAppProperty();
307     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
308     EXPECT_EQ(ret, 0);
309 
310     cJSON_Delete(j_config);
311     DeleteAppSpawningCtx(appProperty);
312 }
313 
314 /**
315  * @tc.name: App_Spawn_Sandbox_15
316  * @tc.desc: parse app sandbox config with PackageName_index label
317  * @tc.type: FUNC
318  * @tc.require:issueI5NTX6
319  * @tc.author:
320  */
321 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_15, TestSize.Level0)
322 {
323     std::string mJsconfig = "{ \
324         \"common\":[{ \
325             \"app-base\":[{ \
326                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName_index>\", \
327                 \"mount-paths\" : [{ \
328                     \"src-path\" : \"/config\", \
329                     \"sandbox-path\" : \"\", \
330                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
331                     \"check-action-status\": \"false\", \
332                     \"dest-mode\": \"S_IRUSR | S_IWOTH | S_IRWXU \" \
333                 }], \
334                 \"symbol-links\" : [] \
335             }] \
336         }], \
337         \"individual\": [] \
338     }";
339     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
340     ASSERT_NE(j_config, nullptr);
341     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
342 
343     g_testHelper.SetTestUid(1000);  // 1000 test
344     g_testHelper.SetTestGid(1000);  // 1000 test
345     g_testHelper.SetProcessName("test.appspawn");
346     g_testHelper.SetTestApl("normal");
347     AppSpawningCtx *appProperty = GetTestAppProperty();
348     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
349     EXPECT_EQ(ret, 0);
350 
351     cJSON_Delete(j_config);
352     DeleteAppSpawningCtx(appProperty);
353 }
354 
355 /**
356  * @tc.name: App_Spawn_Sandbox_16
357  * @tc.desc: parse config define by self Set App Sandbox Property.
358  * @tc.type: FUNC
359  * @tc.require:issueI5NTX6
360  * @tc.author:
361  */
362 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_16, TestSize.Level0)
363 {
364     std::string mJsconfig = "{ \
365         \"common\":[{ \
366             \"app-base\":[{ \
367                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
368                 \"symbol-links\" : [] \
369             }] \
370         }], \
371         \"individual\": [] \
372     }";
373     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
374     ASSERT_NE(j_config, nullptr);
375     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
376 
377     g_testHelper.SetTestUid(1000);  // 1000 test
378     g_testHelper.SetTestGid(1000);  // 1000 test
379     g_testHelper.SetProcessName("test.appspawn");
380     g_testHelper.SetTestApl("normal");
381     AppSpawningCtx *appProperty = GetTestAppProperty();
382     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
383     EXPECT_EQ(ret, 0);
384 
385     cJSON_Delete(j_config);
386     DeleteAppSpawningCtx(appProperty);
387 }
388 
389 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_17, TestSize.Level0)
390 {
391     cJSON *appSandboxConfig = GetJsonObjFromFile("");
392     EXPECT_EQ(appSandboxConfig, nullptr);
393 
394     std::string path(256, 'w');  // 256 test
395     appSandboxConfig = GetJsonObjFromFile(path.c_str());
396     EXPECT_EQ(appSandboxConfig, nullptr);
397 
398     std::string mJsconfig = "{ \
399         \"common\":[{ \
400             \"app-base\":[{ \
401                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
402                 \"symbol-links\" : [] \
403             }] \
404         }], \
405         \"individual\": [] \
406     }";
407     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
408     ASSERT_NE(j_config, nullptr);
409     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
410 
411     const char *value = GetStringFromJsonObj(j_config, "common");
412     EXPECT_EQ(value, nullptr);
413 
414     cJSON_Delete(j_config);
415 }
416 
417 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_18, TestSize.Level0)
418 {
419     std::string mJsconfig1 = "{ \
420         \"sandbox-switch\": \"ON\", \
421         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
422     }";
423     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
424     ASSERT_NE(j_config1, nullptr);
425     bool ret = AppSpawn::SandboxCommon::GetSwitchStatus(j_config1);
426     EXPECT_TRUE(ret);
427 
428     std::string mJsconfig2 = "{ \
429         \"sandbox-switch\": \"OFF\", \
430         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
431     }";
432     cJSON *j_config2 = cJSON_Parse(mJsconfig2.c_str());
433     ASSERT_NE(j_config2, nullptr);
434     ret = AppSpawn::SandboxCommon::GetSwitchStatus(j_config2);
435     EXPECT_FALSE(ret);
436 
437     std::string mJsconfig3 = "{ \
438         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
439     }";
440     cJSON *j_config3 = cJSON_Parse(mJsconfig3.c_str());
441     ASSERT_NE(j_config3, nullptr);
442     ret = AppSpawn::SandboxCommon::GetSwitchStatus(j_config3);
443     EXPECT_TRUE(ret);
444 
445     cJSON_Delete(j_config1);
446     cJSON_Delete(j_config2);
447     cJSON_Delete(j_config3);
448 }
449 
450 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_20, TestSize.Level0)
451 {
452     std::string mJsconfig = "{ \
453         \"common\":[{ \
454             \"top-sandbox-switch\": \"OFF\", \
455             \"app-base\":[{ \
456                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
457                 \"symbol-links\" : [] \
458             }] \
459         }], \
460         \"individual\": [] \
461     }";
462     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
463     ASSERT_NE(j_config, nullptr);
464     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
465 
466     g_testHelper.SetTestUid(1000);  // 1000 test
467     g_testHelper.SetTestGid(1000);  // 1000 test
468     g_testHelper.SetProcessName("test.appspawn");
469     g_testHelper.SetTestApl("normal");
470     AppSpawningCtx *appProperty = GetTestAppProperty();
471     int32_t ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
472     EXPECT_EQ(ret, 0);
473 
474     std::string mJsconfig1 = "{ \
475         \"common\":[{ \
476             \"app-base\":[{ \
477                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
478                 \"symbol-links\" : [] \
479             }] \
480         }], \
481         \"individual\": [{ \
482             \"test.bundle.name\" : [{ \
483                 \"sandbox-switch\": \"OFF\", \
484                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
485             }] \
486         }] \
487     }";
488     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
489     ASSERT_NE(j_config1, nullptr);
490 
491     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config1, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
492     ret = AppSpawn::SandboxCore::SetAppSandboxProperty(appProperty, CLONE_NEWPID);
493     EXPECT_EQ(ret, 0);
494 
495     cJSON_Delete(j_config);
496     cJSON_Delete(j_config1);
497     DeleteAppSpawningCtx(appProperty);
498 }
499 
500 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_21, TestSize.Level0)
501 {
502     bool ret = AppSpawn::SandboxCommon::HasPrivateInBundleName(std::string("__internal__"));
503     EXPECT_FALSE(ret);
504 }
505 
506 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_22, TestSize.Level0)
507 {
508     std::string mJsconfig1 = "{ \
509         \"common\":[], \
510         \"individual\": [] \
511     }";
512     cJSON *j_config = cJSON_Parse(mJsconfig1.c_str());
513     ASSERT_NE(j_config, nullptr);
514     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
515 
516     g_testHelper.SetTestUid(1000);  // 1000 test
517     g_testHelper.SetTestGid(1000);  // 1000 test
518     g_testHelper.SetProcessName("test.appspawn");
519     g_testHelper.SetTestApl("system_basic");
520     AppSpawningCtx *appProperty = GetTestAppProperty();
521 
522     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
523     std::string testBundle = strl1;
524     int32_t ret = AppSpawn::SandboxCore::SetCommonAppSandboxProperty(appProperty, testBundle);
525     EXPECT_EQ(ret, 0);
526 
527     cJSON_Delete(j_config);
528     DeleteAppSpawningCtx(appProperty);
529 }
530 
531 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_24, TestSize.Level0)
532 {
533     g_testHelper.SetTestUid(1000);  // 1000 test
534     g_testHelper.SetTestGid(1000);  // 1000 test
535     g_testHelper.SetProcessName("test.bundle.name1");
536     g_testHelper.SetTestApl("system_basic");
537     AppSpawningCtx *appProperty = GetTestAppProperty();
538 
539     std::string mJsconfig1 = "{ \
540         \"common\":[{ \
541             \"app-base\":[{ \
542                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
543                 \"symbol-links\" : [{ \
544                     \"target-name\" : \"/system/etc\", \
545                     \"link-name\" : \"/etc\", \
546                     \"check-action-status\": \"false\" \
547                 }, { \
548                     \"target\" : \"/system/etc\", \
549                     \"link\" : \"/etc\", \
550                     \"check\": \"false\" \
551                 }] \
552             }], \
553             \"app-resources\" : [{ \
554                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
555                 \"mount-paths\" : [], \
556                 \"symbol-links\" : [] \
557             }] \
558         }] \
559     }";
560     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
561     ASSERT_NE(j_config1, nullptr);
562     int32_t ret = AppSpawn::SandboxCore::DoSandboxFileCommonSymlink(appProperty, j_config1);
563     EXPECT_EQ(ret, 0);
564 
565     std::string mJsconfig2 = "{ \
566         \"common\":[{ \
567             \"app-base\":[{ \
568                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
569                 \"symbol-links\" : [{ \
570                     \"target-name\" : \"/data/test123\", \
571                     \"link-name\" : \"/test123\", \
572                     \"check-action-status\": \"true\" \
573                 }] \
574             }] \
575         }] \
576     }";
577     cJSON *j_config2 = cJSON_Parse(mJsconfig2.c_str());
578     ASSERT_NE(j_config2, nullptr);
579     ret = AppSpawn::SandboxCore::DoSandboxFileCommonSymlink(appProperty, j_config2);
580     EXPECT_EQ(ret, 0);
581 
582     cJSON_Delete(j_config1);
583     cJSON_Delete(j_config2);
584     DeleteAppSpawningCtx(appProperty);
585 }
586 
587 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_25, TestSize.Level0)
588 {
589     g_testHelper.SetTestUid(1000);  // 1000 test
590     g_testHelper.SetTestGid(1000);  // 1000 test
591     g_testHelper.SetProcessName("test.bundle.wps");
592     g_testHelper.SetTestApl("system_basic");
593     g_testHelper.SetTestMsgFlags(4);  // 4 is test parameter
594     AppSpawningCtx *appProperty = GetTestAppProperty();
595 
596     std::string mJsconfig1 = "{ \
597         \"common\":[{ \
598             \"app-resources\" : [{ \
599                 \"flags\": \"DLP_MANAGER\", \
600                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
601                 \"mount-paths\" : [{ \
602                     \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
603                     \"sandbox-path\" : \"/data/storage/el2/base\", \
604                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
605                     \"check-action-status\": \"false\", \
606                     \"app-apl-name\": \"test123\", \
607                     \"fs-type\": \"ext4\" \
608                 }, { \
609                     \"src-path\" : \"/data/app/el1/<currentUserId>/database/<PackageName_index>\", \
610                     \"sandbox-path\" : \"/data/storage/el1/database\", \
611                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
612                     \"check-action-status\": \"false\" \
613                 }], \
614                 \"symbol-links\" : [] \
615             }] \
616         }] \
617     }";
618     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
619     ASSERT_NE(j_config1, nullptr);
620     int32_t ret = AppSpawn::SandboxCore::DoSandboxFileCommonBind(appProperty, j_config1);
621     EXPECT_EQ(ret, 0);
622 
623     ret = AppSpawn::SandboxCore::DoSandboxFileCommonFlagsPointHandle(appProperty, j_config1);
624     EXPECT_EQ(ret, 0);
625 
626     cJSON_Delete(j_config1);
627     DeleteAppSpawningCtx(appProperty);
628 }
629 
630 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_26, TestSize.Level0)
631 {
632     g_testHelper.SetTestUid(1000);  // 1000 test
633     g_testHelper.SetTestGid(1000);  // 1000 test
634     g_testHelper.SetProcessName("com.ohos.dlpmanager");
635     g_testHelper.SetTestApl("system_basic");
636     AppSpawningCtx *appProperty = GetTestAppProperty();
637 
638     std::string mJsconfig2 = "{ \
639         \"common\":[{ \
640             \"app-base\" : [{ \
641                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
642                 \"mount-paths\" : [{ \
643                     \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
644                     \"sandbox-path\" : \"/data/storage/el2/base\", \
645                     \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
646                     \"fs-type\" : \"ext4\", \
647                     \"check-action-status\": \"true\" \
648                 }] \
649             }] \
650         }] \
651     }";
652     cJSON *j_config2 = cJSON_Parse(mJsconfig2.c_str());
653     ASSERT_NE(j_config2, nullptr);
654     int32_t ret = AppSpawn::SandboxCore::DoSandboxFileCommonBind(appProperty, j_config2);
655     EXPECT_NE(ret, 0);
656 
657     cJSON_Delete(j_config2);
658     DeleteAppSpawningCtx(appProperty);
659 }
660 
661 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_27, TestSize.Level0)
662 {
663     g_testHelper.SetTestUid(1000);  // 1000 test
664     g_testHelper.SetTestGid(1000);  // 1000 test
665     g_testHelper.SetProcessName("test.bundle.name");
666     g_testHelper.SetTestApl("system_basic");
667     AppSpawningCtx *appProperty = GetTestAppProperty();
668 
669     std::string mJsconfig1 = "{ \
670         \"individual\": [{ \
671             \"test.bundle.name\" : [{ \
672                 \"sandbox-switch\": \"OFF\", \
673                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
674             }] \
675         }] \
676     }";
677     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
678     ASSERT_NE(j_config1, nullptr);
679     int32_t ret = AppSpawn::SandboxCore::DoSandboxFilePrivateFlagsPointHandle(appProperty, j_config1);
680     EXPECT_EQ(ret, 0);
681 
682     std::string mJsconfig2 = "{ \
683         \"individual\": [{ \
684             \"test.bundle.name\" : [{ \
685                 \"flags-point\" : [{ \
686                     \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
687                     \"mount-paths\" : [{ \
688                         \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
689                         \"sandbox-path\" : \"/data/storage/el2/base\", \
690                         \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
691                         \"check-action-status\": \"false\" \
692                     }]\
693                 }], \
694                 \"sandbox-switch\": \"OFF\", \
695                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
696             }] \
697         }] \
698     }";
699     cJSON *j_config2 = cJSON_Parse(mJsconfig2.c_str());
700     ASSERT_NE(j_config2, nullptr);
701     ret = AppSpawn::SandboxCore::DoSandboxFilePrivateFlagsPointHandle(appProperty, j_config2);
702     EXPECT_EQ(ret, 0);
703 
704     cJSON_Delete(j_config1);
705     cJSON_Delete(j_config2);
706     DeleteAppSpawningCtx(appProperty);
707 }
708 
709 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_28, TestSize.Level0)
710 {
711     g_testHelper.SetTestUid(1000);  // 1000 test
712     g_testHelper.SetTestGid(1000);  // 1000 test
713     g_testHelper.SetProcessName("test.bundle.name");
714     g_testHelper.SetTestApl("system_basic");
715     g_testHelper.SetTestMsgFlags(4);  // 4 is test parameter
716     AppSpawningCtx *appProperty = GetTestAppProperty();
717 
718     std::string mJsconfig3 = "{ \
719         \"individual\": [{ \
720             \"test.bundle.name\" : [{ \
721                 \"flags-point\" : [{ \
722                     \"flags\": \"DLP_MANAGER\", \
723                     \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
724                     \"mount-paths\" : [{ \
725                         \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
726                         \"sandbox-path\" : \"/data/storage/el2/base\", \
727                         \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
728                         \"check-action-status\": \"false\" \
729                     }] \
730                 }], \
731                 \"sandbox-switch\": \"OFF\", \
732                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
733             }] \
734         }] \
735     }";
736     cJSON *j_config3 = cJSON_Parse(mJsconfig3.c_str());
737     ASSERT_NE(j_config3, nullptr);
738     int ret = AppSpawn::SandboxCore::DoSandboxFilePrivateFlagsPointHandle(appProperty, j_config3);
739     EXPECT_EQ(ret, 0);
740 
741     cJSON_Delete(j_config3);
742     DeleteAppSpawningCtx(appProperty);
743 }
744 
745 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_29, TestSize.Level0)
746 {
747     g_testHelper.SetTestUid(1000);  // 1000 test
748     g_testHelper.SetTestGid(1000);  // 1000 test
749     g_testHelper.SetProcessName("test.bundle.name");
750     g_testHelper.SetTestApl("system_basic");
751     g_testHelper.SetTestMsgFlags(4);  // 4 is test parameter
752     AppSpawningCtx *appProperty = GetTestAppProperty();
753 
754     std::string mJsconfig3 = "{ \
755         \"individual\": [{ \
756             \"test.bundle.name\" : [{ \
757                 \"flags-point\" : [{ \
758                     \"flags\": \"DLP_MANAGER\", \
759                     \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
760                     \"mount-paths\" : [{ \
761                         \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
762                         \"sandbox-path\" : \"/data/storage/el2/base\", \
763                         \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
764                         \"check-action-status\": \"false\" \
765                     }] \
766                 }], \
767                 \"sandbox-switch\": \"OFF\", \
768                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\" \
769             }] \
770         }] \
771     }";
772     cJSON *j_config3 = cJSON_Parse(mJsconfig3.c_str());
773     ASSERT_NE(j_config3, nullptr);
774     int ret = AppSpawn::SandboxCore::DoSandboxFilePrivateFlagsPointHandle(appProperty, j_config3);
775     EXPECT_EQ(ret, 0);
776 
777     cJSON_Delete(j_config3);
778     DeleteAppSpawningCtx(appProperty);
779 }
780 
781 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_30, TestSize.Level0)
782 {
783     g_testHelper.SetTestUid(1000);  // 1000 test
784     g_testHelper.SetTestGid(1000);  // 1000 test
785     g_testHelper.SetProcessName("com.ohos.wps");
786     g_testHelper.SetTestApl("apl123");
787     g_testHelper.SetTestMsgFlags(4);  // 4 is test parameter
788     AppSpawningCtx *appProperty = GetTestAppProperty();
789 
790     std::string mJsconfig3 = "{ \
791         \"flags\": \"DLP_MANAGER\", \
792         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
793         \"mount-paths\" : [{ \
794             \"src-path\" : \"/data/app/el2/<currentUserId>/base/database/<PackageName>\", \
795             \"sandbox-path\" : \"/data/storage/el2/base\", \
796             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
797             \"check-action-status\": \"false\" \
798         }] \
799     }";
800     cJSON *j_config3 = cJSON_Parse(mJsconfig3.c_str());
801     ASSERT_NE(j_config3, nullptr);
802     int32_t ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config3, nullptr);
803     EXPECT_EQ(ret, 0);
804 
805     std::string mJsconfig4 = "{ \
806         \"flags\": \"DLP_MANAGER\", \
807         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
808         \"mount-paths\" : [{ \
809             \"src-path\" : \"/data/app/el2/<currentUserId>/database/<PackageName>\", \
810             \"sandbox-path\" : \"/data/storage/el2/base\", \
811             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
812             \"check-action-status\": \"false\" \
813         }] \
814     }";
815     cJSON *j_config4 = cJSON_Parse(mJsconfig4.c_str());
816     ASSERT_NE(j_config4, nullptr);
817     ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config4, nullptr);
818     EXPECT_EQ(ret, 0);
819 
820     cJSON_Delete(j_config3);
821     cJSON_Delete(j_config4);
822     DeleteAppSpawningCtx(appProperty);
823 }
824 
825 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_31, TestSize.Level0)
826 {
827     g_testHelper.SetTestUid(1000);  // 1000 test
828     g_testHelper.SetTestGid(1000);  // 1000 test
829     g_testHelper.SetProcessName("com.ohos.dlpmanager");
830     g_testHelper.SetTestApl("apl123");
831     AppSpawningCtx *appProperty = GetTestAppProperty();
832 
833     std::string mJsconfig1 = "{ \
834         \"flags\": \"DLP_TEST\", \
835         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
836         \"mount-paths\" : [{ \
837             \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
838             \"sandbox-path\" : \"/data/storage/el2/base\", \
839             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
840             \"check-action-status\": \"false\" \
841         }] \
842     }";
843     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
844     ASSERT_NE(j_config1, nullptr);
845     int32_t ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config1, nullptr);
846     EXPECT_EQ(ret, 0);
847 
848     std::string mJsconfig2 = "{ \
849         \"flags\": \"DLP_TEST\", \
850         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
851         \"mount-paths\" : [{ \
852             \"src-path\" : \"/data/app/el2/<currentUserId>/base/<PackageName_index>\", \
853             \"sandbox-path\" : \"/data/storage/el2/base\", \
854             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
855             \"fs-type\" : \"ext4\", \
856             \"check-action-status\": \"false\", \
857             \"app-apl-name\" : \"apl123\" \
858         }, { \
859             \"src-path\" : \"/data/app/el2/<currentUserId>/database/<PackageName_index>\", \
860             \"sandbox-path\" : \"/data/storage/el2/base\", \
861             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
862             \"fs-type\" : \"ext4\", \
863             \"check-action-status\": \"true\" \
864         }] \
865     }";
866     cJSON *j_config2 = cJSON_Parse(mJsconfig2.c_str());
867     ASSERT_NE(j_config2, nullptr);
868     ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config2, nullptr);
869     EXPECT_NE(ret, 0);
870 
871     cJSON_Delete(j_config1);
872     cJSON_Delete(j_config2);
873     DeleteAppSpawningCtx(appProperty);
874 }
875 
876 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_32, TestSize.Level0)
877 {
878     int32_t ret = AppSpawn::SandboxCommon::DoAppSandboxMountOnce(nullptr, nullptr);
879     EXPECT_EQ(ret, 0);
880 
881     std::string mJsconfig1 = "{ \
882         \"dest-mode\" : \"S_IRUSR|S_IWUSR|S_IXUSR\" \
883     }";
884     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
885     ASSERT_NE(j_config1, nullptr);
886     std::string sandboxRoot;
887     const char *str = "/data/test11122";
888     sandboxRoot = str;
889     AppSpawn::SandboxCommon::SetSandboxPathChmod(j_config1, sandboxRoot);
890 
891     cJSON_Delete(j_config1);
892 }
893 
894 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_34, TestSize.Level0)
895 {
896     g_testHelper.SetTestUid(1000);  // 1000 test
897     g_testHelper.SetTestGid(1000);  // 1000 test
898     g_testHelper.SetProcessName("com.ohos.dlpmanager");
899     g_testHelper.SetTestApl("apl123");
900 
901     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
902     std::string testBundle = strl1;
903     char hspListStr[] = "{ \
904         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
905         \"modules\":[\"module1\", \"module2\"], \
906         \"versions\":[\"v10001\", \"v10002\"] \
907     }";
908     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
909     cJSON *hspRoot = cJSON_Parse(hspListStr);
910     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
911     cJSON_Delete(hspRoot);
912     EXPECT_EQ(ret, 0);
913 
914     DeleteAppSpawningCtx(appProperty);
915 }
916 
InvalidJsonTest(std::string & testBundle)917 static void InvalidJsonTest(std::string &testBundle)
918 {
919     char hspListStr[] = "{";
920     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
921     cJSON *hspRoot = cJSON_Parse(hspListStr);
922     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
923     cJSON_Delete(hspRoot);
924     DeleteAppSpawningCtx(appProperty);
925     EXPECT_EQ(ret, 0);
926 }
927 
NoBundleTest(std::string & testBundle)928 static void NoBundleTest(std::string &testBundle)
929 {
930     char hspListStr[] = "{ \
931         \"modules\":[\"module1\", \"module2\"], \
932         \"versions\":[\"v10001\", \"v10002\"] \
933     }";
934     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
935     cJSON *hspRoot = cJSON_Parse(hspListStr);
936     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
937     cJSON_Delete(hspRoot);
938     DeleteAppSpawningCtx(appProperty);
939     EXPECT_NE(ret, 0);
940 }
941 
NoModulesTest(std::string & testBundle)942 static void NoModulesTest(std::string &testBundle)
943 {
944     char hspListStr[] = "{ \
945         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
946         \"versions\":[\"v10001\", \"v10002\"] \
947     }";
948 
949     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
950     cJSON *hspRoot = cJSON_Parse(hspListStr);
951     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
952     cJSON_Delete(hspRoot);
953     DeleteAppSpawningCtx(appProperty);
954     EXPECT_NE(ret, 0);
955 }
956 
NoVersionsTest(std::string & testBundle)957 static void NoVersionsTest(std::string &testBundle)
958 {
959     char hspListStr[] = "{ \
960         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
961         \"modules\":[\"module1\", \"module2\"] \
962     }";
963     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
964     cJSON *hspRoot = cJSON_Parse(hspListStr);
965     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
966     cJSON_Delete(hspRoot);
967     DeleteAppSpawningCtx(appProperty);
968     EXPECT_NE(ret, 0);
969 }
970 
ListSizeNotSameTest(std::string & testBundle)971 static void ListSizeNotSameTest(std::string &testBundle)
972 {
973     char hspListStr[] = "{ \
974         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
975         \"modules\":[\"module1\"], \
976         \"versions\":[\"v10001\", \"v10002\"] \
977     }";
978     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
979     cJSON *hspRoot = cJSON_Parse(hspListStr);
980     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
981     cJSON_Delete(hspRoot);
982     DeleteAppSpawningCtx(appProperty);
983     EXPECT_NE(ret, 0);
984 }
985 
ValueTypeIsNotArraryTest(std::string & testBundle)986 static void ValueTypeIsNotArraryTest(std::string &testBundle)
987 {
988     char hspListStr[] = "{ \
989         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
990         \"modules\":[\"module1\", \"module2\"], \
991         \"versions\": 1001 \
992     }";
993     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
994     cJSON *hspRoot = cJSON_Parse(hspListStr);
995     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
996     cJSON_Delete(hspRoot);
997     DeleteAppSpawningCtx(appProperty);
998     EXPECT_NE(ret, 0);
999 }
1000 
ElementTypeIsNotStringTest(std::string & testBundle)1001 static void ElementTypeIsNotStringTest(std::string &testBundle)
1002 {
1003     char hspListStr[] = "{ \
1004         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1005         \"modules\":[\"module1\", \"module2\"], \
1006         \"versions\": [1001, 1002] \
1007     }";
1008     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
1009     cJSON *hspRoot = cJSON_Parse(hspListStr);
1010     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
1011     cJSON_Delete(hspRoot);
1012     DeleteAppSpawningCtx(appProperty);
1013     EXPECT_NE(ret, 0);
1014 }
1015 
ElementTypeIsNotSameTestSN(std::string & testBundle)1016 static void ElementTypeIsNotSameTestSN(std::string &testBundle)
1017 {
1018     // element type is not same, string + number
1019     char hspListStr[] = "{ \
1020         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1021         \"modules\":[\"module1\", \"module2\"], \
1022         \"versions\": [\"v10001\", 1002] \
1023     }";
1024     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
1025     cJSON *hspRoot = cJSON_Parse(hspListStr);
1026     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
1027     cJSON_Delete(hspRoot);
1028     DeleteAppSpawningCtx(appProperty);
1029     EXPECT_NE(ret, 0);
1030 }
1031 
ElementTypeIsNotSameTestNS(std::string & testBundle)1032 static void ElementTypeIsNotSameTestNS(std::string &testBundle)
1033 {
1034     // element type is not same, number + string
1035     char hspListStr[] = "{ \
1036         \"bundles\":[\"test.bundle1\", \"test.bundle2\"], \
1037         \"modules\":[\"module1\", \"module2\"], \
1038         \"versions\": [1001, \"v10002\"] \
1039     }";
1040     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
1041     cJSON *hspRoot = cJSON_Parse(hspListStr);
1042     int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
1043     cJSON_Delete(hspRoot);
1044     DeleteAppSpawningCtx(appProperty);
1045     EXPECT_NE(ret, 0);
1046 }
1047 
1048 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_35, TestSize.Level0)
1049 {
1050     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
1051     std::string testBundle = strl1;
1052     InvalidJsonTest(testBundle);
1053     NoBundleTest(testBundle);
1054     NoModulesTest(testBundle);
1055     NoVersionsTest(testBundle);
1056     ListSizeNotSameTest(testBundle);
1057     ValueTypeIsNotArraryTest(testBundle);
1058     ElementTypeIsNotStringTest(testBundle);
1059     ElementTypeIsNotSameTestSN(testBundle);
1060     ElementTypeIsNotSameTestNS(testBundle);
1061 }
1062 
1063 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_36, TestSize.Level0)
1064 {
1065     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
1066     std::string testBundle = strl1;
1067 
1068     {  // empty name
1069         char hspListStr[] = "{ \
1070             \"bundles\":[\"\", \"test.bundle2\"], \
1071             \"modules\":[\"module1\", \"module2\"], \
1072             \"versions\":[\"v10001\", \"v10002\"] \
1073         }";
1074         AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
1075         cJSON *hspRoot = cJSON_Parse(hspListStr);
1076         int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
1077         cJSON_Delete(hspRoot);
1078         DeleteAppSpawningCtx(appProperty);
1079         EXPECT_NE(ret, 0);
1080     }
1081     {  // name is .
1082         char hspListStr[] = "{ \
1083             \"bundles\":[\".\", \"test.bundle2\"], \
1084             \"modules\":[\"module1\", \"module2\"], \
1085             \"versions\":[\"v10001\", \"v10002\"] \
1086         }";
1087         AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
1088         cJSON *hspRoot = cJSON_Parse(hspListStr);
1089         int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
1090         cJSON_Delete(hspRoot);
1091         DeleteAppSpawningCtx(appProperty);
1092         EXPECT_NE(ret, 0);
1093     }
1094 }
1095 
1096 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_37, TestSize.Level0)
1097 {
1098     const char *strl1 = "/mnt/sandbox/100/test.bundle1";
1099     std::string testBundle = strl1;
1100     {  // name is ..
1101         char hspListStr[] = "{ \
1102             \"bundles\":[\"..\", \"test.bundle2\"], \
1103             \"modules\":[\"module1\", \"module2\"], \
1104             \"versions\":[\"v10001\", \"v10002\"] \
1105         }";
1106         AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
1107         cJSON *hspRoot = cJSON_Parse(hspListStr);
1108         int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
1109         cJSON_Delete(hspRoot);
1110         DeleteAppSpawningCtx(appProperty);
1111         EXPECT_NE(ret, 0);
1112     }
1113     {  // name contains /
1114         char hspListStr[] = "{ \
1115             \"bundles\":[\"test/bundle1\", \"test.bundle2\"], \
1116             \"modules\":[\"module1\", \"module2\"], \
1117             \"versions\":[\"v10001\", \"v10002\"] \
1118         }";
1119         AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("HspList", hspListStr);
1120         cJSON *hspRoot = cJSON_Parse(hspListStr);
1121         int32_t ret = AppSpawn::SandboxCore::MountAllHsp(appProperty, testBundle, hspRoot);
1122         cJSON_Delete(hspRoot);
1123         DeleteAppSpawningCtx(appProperty);
1124         EXPECT_NE(ret, 0);
1125     }
1126 }
1127 
1128 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_38, TestSize.Level0)
1129 {
1130     g_testHelper.SetTestUid(1000);  // 1000 test
1131     g_testHelper.SetTestGid(1000);  // 1000 test
1132     g_testHelper.SetProcessName("ohos.samples.xxx");
1133     g_testHelper.SetTestApl("system_basic");
1134     AppSpawningCtx *appProperty = GetTestAppProperty();
1135 
1136     AppSpawnMgr content;
1137     AppSpawn::SandboxCommon::LoadAppSandboxConfigCJson(&content);
1138     std::string sandboxPackagePath = "/mnt/sandbox/100/";
1139     const std::string bundleName = GetBundleName(appProperty);
1140     sandboxPackagePath += bundleName;
1141 
1142     int32_t ret = AppSpawn::SandboxCore::SetPrivateAppSandboxProperty(appProperty);
1143     EXPECT_EQ(ret, 0);
1144     ret = AppSpawn::SandboxCore::SetCommonAppSandboxProperty(appProperty, sandboxPackagePath);
1145     EXPECT_EQ(ret, 0);
1146 
1147     DeleteAppSpawningCtx(appProperty);
1148 }
1149 
1150 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_39, TestSize.Level0)
1151 {
1152     g_testHelper.SetTestUid(1000);  // 1000 test
1153     g_testHelper.SetTestGid(1000);  // 1000 test
1154     g_testHelper.SetProcessName("com.example.deviceinfo");
1155     g_testHelper.SetTestApl("system_basic");
1156     AppSpawningCtx *appProperty = GetTestAppProperty();
1157 
1158     std::string pJsconfig1 = "{ \
1159         \"common\":[],                      \
1160         \"individual\": [ {                  \
1161             \"com.example.deviceinfo\" : [{   \
1162             \"sandbox-switch\": \"ON\",     \
1163             \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\",  \
1164             \"mount-paths\" : [{    \
1165                     \"src-path\" : \"/data/app/el1/bundle/public/\",    \
1166                     \"sandbox-path\" : \"/data/accounts/account_0/applications/2222222\",   \
1167                     \"sandbox-flags\" : [ \"bind\", \"rec\" ],  \
1168                     \"check-action-status\": \"true\"   \
1169                 }, { \
1170                     \"src-path\" : \"/data/app/el1/bundle/public/\",    \
1171                     \"sandbox-path\" : \"/data/bundles/aaaaaa\",    \
1172                     \"sandbox-flags\" : [ \"bind\", \"rec\" ],  \
1173                     \"check-action-status\": \"true\"   \
1174                 }\
1175             ],\
1176             \"symbol-links\" : []   \
1177         }] \
1178         }] \
1179     }";
1180     cJSON *j_config = cJSON_Parse(pJsconfig1.c_str());
1181     ASSERT_NE(j_config, nullptr);
1182     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1183 
1184     std::string sandboxPackagePath = "/mnt/sandbox/100/";
1185     const std::string bundleName = GetBundleName(appProperty);
1186     sandboxPackagePath += bundleName;
1187     int32_t ret = AppSpawn::SandboxCore::SetPrivateAppSandboxProperty(appProperty);
1188     EXPECT_EQ(ret, 0);
1189     ret = AppSpawn::SandboxCore::SetCommonAppSandboxProperty(appProperty, sandboxPackagePath);
1190     EXPECT_EQ(ret, 0);
1191 
1192     cJSON_Delete(j_config);
1193     DeleteAppSpawningCtx(appProperty);
1194 }
1195 
1196 /**
1197  * @tc.name: App_Spawn_Sandbox_39
1198  * @tc.desc: load overlay config SetAppSandboxProperty by App com.ohos.demo.
1199  * @tc.type: FUNC
1200  * @tc.require:issueI7D0H9
1201  * @tc.author:
1202  */
1203 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_40, TestSize.Level0)
1204 {
1205     g_testHelper.SetTestUid(1000);  // 1000 test
1206     g_testHelper.SetTestGid(1000);  // 1000 test
1207     g_testHelper.SetProcessName("com.ohos.demo");
1208     g_testHelper.SetTestApl("normal");
1209     g_testHelper.SetTestMsgFlags(0x100);  // 0x100 is test parameter
1210 
1211     std::string overlayInfo = "/data/app/el1/bundle/public/com.ohos.demo/feature.hsp|";
1212     overlayInfo += "/data/app/el1/bundle/public/com.ohos.demo/feature.hsp|";
1213     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("Overlay", overlayInfo.c_str());
1214     std::string sandBoxRootDir = "/mnt/sandbox/100/com.ohos.demo";
1215     int32_t ret = AppSpawn::SandboxCore::SetOverlayAppSandboxProperty(appProperty, sandBoxRootDir);
1216     EXPECT_EQ(ret, 0);
1217 
1218     DeleteAppSpawningCtx(appProperty);
1219 }
1220 
1221 /**
1222  * @tc.name: App_Spawn_Sandbox_40
1223  * @tc.desc: load group info config SetAppSandboxProperty
1224  * @tc.type: FUNC
1225  * @tc.require:issueI7FUPV
1226  * @tc.author:
1227  */
1228 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_41, TestSize.Level0)
1229 {
1230     g_testHelper.SetTestUid(1000);  // 1000 test
1231     g_testHelper.SetTestGid(1000);  // 1000 test
1232     g_testHelper.SetProcessName("com.ohos.demo");
1233     g_testHelper.SetTestApl("normal");
1234     g_testHelper.SetTestMsgFlags(0x100);
1235     std::string sandboxPrefix = "/mnt/sandbox/100/testBundle";
1236     char dataGroupInfoListStr[] = R"([
1237         {
1238             "gid": "1002",
1239             "dir": "data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
1240             "dataGroupId": "43200",
1241             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
1242         },
1243         {
1244             "gid": "1002",
1245             "dir": "data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
1246             "dataGroupId": "43200",
1247             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
1248         }
1249     ])";
1250     AppSpawningCtx *appProperty = GetTestAppPropertyWithExtInfo("DataGroup", dataGroupInfoListStr);
1251     int32_t ret = AppSpawn::SandboxCore::MountAllGroup(appProperty, sandboxPrefix);
1252     EXPECT_EQ(ret, 0);
1253 
1254     DeleteAppSpawningCtx(appProperty);
1255 }
1256 
1257 /**
1258  * @tc.name: App_Spawn_Sandbox_41
1259  * @tc.desc: parse namespace config
1260  * @tc.type: FUNC
1261  * @tc.require:issueI8B63M
1262  * @tc.author:
1263  */
1264 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_42, TestSize.Level0)
1265 {
1266     std::string mJsconfig = "{ \
1267         \"common\":[{ \
1268             \"top-sandbox-switch\": \"ON\", \
1269             \"app-base\":[{ \
1270                 \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
1271                 \"sandbox-ns-flags\": [ \"pid\" ], \
1272                 \"mount-paths\" : [], \
1273                 \"symbol-links\" : [] \
1274             }] \
1275         }], \
1276         \"individual\":[{ \
1277             \"__internal__.com.ohos.render\":[{ \
1278                 \"sandbox-root\" : \"/mnt/sandbox/com.ohos.render/<PackageName>\", \
1279                 \"sandbox-ns-flags\": [ \"pid\", \"net\" ], \
1280                 \"mount-paths\" : [], \
1281                 \"symbol-links\" : [] \
1282             }] \
1283         }] \
1284     }";
1285     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1286     ASSERT_NE(j_config, nullptr);
1287     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1288 
1289     uint32_t cloneFlags = AppSpawn::SandboxCommon::GetSandboxNsFlags(false);
1290     EXPECT_EQ(!!(cloneFlags & CLONE_NEWPID), true);
1291 
1292     cloneFlags = AppSpawn::SandboxCommon::GetSandboxNsFlags(true);
1293     EXPECT_EQ(!!(cloneFlags & (CLONE_NEWPID | CLONE_NEWNET)), true);
1294 
1295     cJSON_Delete(j_config);
1296 }
1297 
1298 /**
1299  * @tc.name: App_Spawn_Sandbox_42
1300  * @tc.desc: parse config file for fstype
1301  * @tc.type: FUNC
1302  * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
1303  * @tc.author:
1304  */
1305 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_43, TestSize.Level0)
1306 {
1307     std::string mJsconfig = "{ \
1308         \"mount-paths\": [{ \
1309             \"src-path\": \"/data/app/el1/<currentUserId>/base\", \
1310             \"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
1311             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1312             \"dac-override-sensitive\": \"true\", \
1313             \"fs-type\": \"sharefs\", \
1314             \"options\": \"support_overwrite=1\" \
1315         }] \
1316     }";
1317     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1318     ASSERT_NE(j_config, nullptr);
1319     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1320 
1321     int ret = 0;
1322     do {
1323         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1324         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1325             break, "Invalid mountPaths config");
1326 
1327         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1328             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1329             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mountPoint config");
1330             std::string fsType = AppSpawn::SandboxCommon::GetFsType(mntPoint);
1331             ret = strcmp(fsType.c_str(), "sharefs");
1332         }
1333         EXPECT_EQ(ret, 0);
1334     } while (0);
1335 
1336     cJSON_Delete(j_config);
1337 }
1338 
1339 /**
1340  * @tc.name: App_Spawn_Sandbox_43
1341  * @tc.desc: get sandbox mount config when section is common.
1342  * @tc.type: FUNC
1343  * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
1344  * @tc.author:
1345  */
1346 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_44, TestSize.Level0)
1347 {
1348     std::string mJsconfig = "{ \
1349         \"mount-paths\": [{ \
1350             \"src-path\": \"/data/app/el1/<currentUserId>/base\", \
1351             \"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
1352             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1353             \"dac-override-sensitive\": \"true\", \
1354             \"fs-type\": \"sharefs\", \
1355             \"options\": \"support_overwrite=1\" \
1356         }] \
1357     }";
1358     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1359     ASSERT_NE(j_config, nullptr);
1360     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1361 
1362     int ret = 0;
1363     AppSpawningCtx *appProperty = GetTestAppProperty();
1364     do {
1365         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1366         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1367             break, "Invalid mountPaths config");
1368 
1369         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1370             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1371             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mntPoint config");
1372             SandboxMountConfig mountConfig = {0};
1373             AppSpawn::SandboxCommon::GetSandboxMountConfig(appProperty, "common", mntPoint, mountConfig);
1374             ret = strcmp(mountConfig.fsType.c_str(), "sharefs");
1375         }
1376         EXPECT_EQ(ret, 0);
1377     } while (0);
1378 
1379     cJSON_Delete(j_config);
1380     DeleteAppSpawningCtx(appProperty);
1381 }
1382 
1383 /**
1384  * @tc.name: App_Spawn_Sandbox_44
1385  * @tc.desc: get sandbox mount config when section is permission.
1386  * @tc.type: FUNC
1387  * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
1388  * @tc.author:
1389  */
1390 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_45, TestSize.Level0)
1391 {
1392     std::string mJsconfig = "{ \
1393         \"mount-paths\": [{ \
1394             \"src-path\": \"/data/app/el1/<currentUserId>/base\", \
1395             \"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
1396             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1397             \"dac-override-sensitive\": \"true\", \
1398             \"fs-type\": \"sharefs\", \
1399             \"options\": \"support_overwrite=1\" \
1400         }] \
1401     }";
1402     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1403     ASSERT_NE(j_config, nullptr);
1404     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1405 
1406     int ret = 0;
1407     AppSpawningCtx *appProperty = GetTestAppProperty();
1408     do {
1409         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1410         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1411             break, "Invalid mountPaths config");
1412 
1413         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1414             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1415             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mntPoint config");
1416             SandboxMountConfig mountConfig = {0};
1417             AppSpawn::SandboxCommon::GetSandboxMountConfig(appProperty, "permission", mntPoint, mountConfig);
1418             ret = strcmp(mountConfig.fsType.c_str(), "sharefs");
1419         }
1420         EXPECT_EQ(ret, 0);
1421     } while (0);
1422 
1423     cJSON_Delete(j_config);
1424     DeleteAppSpawningCtx(appProperty);
1425 }
1426 
1427 /**
1428  * @tc.name: App_Spawn_Sandbox_45
1429  * @tc.desc: parse config file for options.
1430  * @tc.type: FUNC
1431  * @tc.require: https://gitee.com/openharmony/startup_appspawn/issues/I8OF9K
1432  * @tc.author:
1433  */
1434 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_46, TestSize.Level0)
1435 {
1436     std::string mJsconfig = "{ \
1437         \"mount-paths\": [{ \
1438             \"src-path\": \"/data/app/el1/<currentUserId>/base\", \
1439             \"sandbox-path\": \"/storage/Users/<currentUserId>/appdata/el1\", \
1440             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1441             \"dac-override-sensitive\": \"true\", \
1442             \"fs-type\": \"sharefs\", \
1443             \"options\": \"support_overwrite=1\" \
1444         }] \
1445     }";
1446     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1447     ASSERT_NE(j_config, nullptr);
1448     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1449 
1450     int ret = 0;
1451     AppSpawningCtx *appProperty = GetTestAppProperty();
1452     do {
1453         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1454         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1455             break, "Invalid mountPaths config");
1456 
1457         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1458             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1459             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mountPoint config");
1460             std::string options = AppSpawn::SandboxCommon::GetOptions(appProperty, mntPoint);
1461             ret = strcmp(options.c_str(), "support_overwrite=1,user_id=100");
1462         }
1463         EXPECT_EQ(ret, 0);
1464     } while (0);
1465 
1466     cJSON_Delete(j_config);
1467     DeleteAppSpawningCtx(appProperty);
1468 }
1469 
1470 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_47, TestSize.Level0)
1471 {
1472     g_testHelper.SetTestUid(1000);  // 1000 test
1473     g_testHelper.SetTestGid(1000);  // 1000 test
1474     g_testHelper.SetProcessName("com.example.myapplication");
1475     g_testHelper.SetTestApl("apl123");
1476     g_testHelper.SetTestMsgFlags(4);  // 4 is test parameter
1477     AppSpawningCtx *appProperty = GetTestAppProperty();
1478 
1479     std::string mJsconfig1 = "{ \
1480         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
1481         \"mount-paths\" : [{ \
1482             \"src-path\" : \"/data/service/el1/public/themes/<currentUserId>/a/app/\", \
1483             \"sandbox-path\" : \"/data/themes/a/app\", \
1484             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
1485             \"check-action-status\": \"false\" \
1486         }] \
1487     }";
1488     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
1489     ASSERT_NE(j_config1, nullptr);
1490     int32_t ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config1, nullptr);
1491     EXPECT_EQ(ret, 0);
1492 
1493     std::string mJsconfig2 = "{ \
1494         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
1495         \"mount-paths\" : [{ \
1496             \"src-path\" : \"/data/service/el1/public/themes/<currentUserId>/a/app/createSandboxPath01\", \
1497             \"sandbox-path\" : \"/data/themes/a/app/createSandboxPath01\", \
1498             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
1499             \"check-action-status\": \"false\", \
1500             \"create-sandbox-path\": \"true\" \
1501         }] \
1502     }";
1503     cJSON *j_config2 = cJSON_Parse(mJsconfig2.c_str());
1504     ASSERT_NE(j_config2, nullptr);
1505     ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config2, nullptr);
1506     EXPECT_EQ(ret, 0);
1507 
1508     cJSON_Delete(j_config1);
1509     cJSON_Delete(j_config2);
1510     DeleteAppSpawningCtx(appProperty);
1511 }
1512 
1513 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_48, TestSize.Level0)
1514 {
1515     g_testHelper.SetTestUid(1000);  // 1000 test
1516     g_testHelper.SetTestGid(1000);  // 1000 test
1517     g_testHelper.SetProcessName("com.example.myapplication");
1518     g_testHelper.SetTestApl("apl123");
1519     g_testHelper.SetTestMsgFlags(4);  // 4 is test parameter
1520     AppSpawningCtx *appProperty = GetTestAppProperty();
1521 
1522     std::string mJsconfig1 = "{ \
1523         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
1524         \"mount-paths\" : [{ \
1525             \"src-path\" : \"/data/service/el1/public/themes/<currentUserId>/a/app/\", \
1526             \"sandbox-path\" : \"/data/themes/a/app\", \
1527             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
1528             \"check-action-status\": \"false\" \
1529         }] \
1530     }";
1531     cJSON *j_config1 = cJSON_Parse(mJsconfig1.c_str());
1532     ASSERT_NE(j_config1, nullptr);
1533     int32_t ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config1, nullptr);
1534     EXPECT_EQ(ret, 0);
1535 
1536     std::string mJsconfig2 = "{ \
1537         \"sandbox-root\" : \"/mnt/sandbox/<currentUserId>/<PackageName>\", \
1538         \"mount-paths\" : [{ \
1539             \"src-path\" : \"/data/service/el1/public/themes/<currentUserId>/a/app/createSandboxPath01\", \
1540             \"sandbox-path\" : \"/data/themes/a/app/createSandboxPath01\", \
1541             \"sandbox-flags\" : [ \"bind\", \"rec\" ], \
1542             \"check-action-status\": \"false\", \
1543             \"create-sandbox-path\": \"false\" \
1544         }] \
1545     }";
1546     cJSON *j_config2 = cJSON_Parse(mJsconfig2.c_str());
1547     ASSERT_NE(j_config2, nullptr);
1548     ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config2, nullptr);
1549     EXPECT_EQ(ret, 0);
1550 
1551     cJSON_Delete(j_config1);
1552     cJSON_Delete(j_config2);
1553     DeleteAppSpawningCtx(appProperty);
1554 }
1555 /**
1556  * @brief 测试app extension
1557  *
1558  */
1559 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_004, TestSize.Level0)
1560 {
1561     AppSpawningCtx *spawningCtx = GetTestAppProperty();
1562     std::string path = AppSpawn::SandboxCommon::ConvertToRealPath(spawningCtx, "/system/<variablePackageName>/module");
1563     ASSERT_NE(path.c_str(), nullptr);
1564     ASSERT_EQ(strcmp(path.c_str(), "/system/com.example.myapplication/module"), 0);
1565     DeleteAppSpawningCtx(spawningCtx);
1566 }
1567 
1568 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_005, TestSize.Level0)
1569 {
1570     AppSpawningCtx *spawningCtx = GetTestAppProperty();
1571     ASSERT_EQ(spawningCtx != nullptr, 1);
1572     int ret = SetAppSpawnMsgFlag(spawningCtx->message, TLV_MSG_FLAGS, APP_FLAGS_CLONE_ENABLE);
1573     ASSERT_EQ(ret, 0);
1574 
1575     std::string path = AppSpawn::SandboxCommon::ConvertToRealPath(spawningCtx, "/system/<variablePackageName>/module");
1576     ASSERT_NE(path.c_str(), nullptr);   // +clone-bundleIndex+packageName
1577     ASSERT_EQ(strcmp(path.c_str(), "/system/+clone-100+com.example.myapplication/module"), 0);
1578     DeleteAppSpawningCtx(spawningCtx);
1579 }
1580 
1581 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_006, TestSize.Level0)
1582 {
1583     AppSpawnClientHandle clientHandle = nullptr;
1584     int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
1585     ASSERT_EQ(ret, 0);
1586     AppSpawnReqMsgHandle reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0);
1587     ASSERT_EQ(reqHandle != nullptr, 1);
1588     ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_APP_EXTENSION, "test001");
1589     ASSERT_EQ(ret, 0);
1590     ret = AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_EXTENSION_SANDBOX);
1591     ASSERT_EQ(ret, 0);
1592     AppSpawningCtx *spawningCtx = g_testHelper.GetAppProperty(clientHandle, reqHandle);
1593     ASSERT_EQ(spawningCtx != nullptr, 1);
1594 
1595     std::string path = AppSpawn::SandboxCommon::ConvertToRealPath(spawningCtx, "/system/<variablePackageName>/module");
1596     ASSERT_NE(path.c_str(), nullptr);  // +extension-<extensionType>+packageName
1597     ASSERT_EQ(strcmp(path.c_str(), "/system/+extension-test001+com.example.myapplication/module"), 0);
1598 
1599     DeleteAppSpawningCtx(spawningCtx);
1600     AppSpawnClientDestroy(clientHandle);
1601 }
1602 
1603 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_007, TestSize.Level0)
1604 {
1605     AppSpawnClientHandle clientHandle = nullptr;
1606     int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
1607     ASSERT_EQ(ret, 0);
1608     AppSpawnReqMsgHandle reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0);
1609     ASSERT_EQ(reqHandle != nullptr, 1);
1610     ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_APP_EXTENSION, "test001");
1611     ASSERT_EQ(ret, 0);
1612     ret = AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_EXTENSION_SANDBOX);
1613     ASSERT_EQ(ret, 0);
1614     ret = AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_CLONE_ENABLE);
1615     ASSERT_EQ(ret, 0);
1616     AppSpawningCtx *spawningCtx = g_testHelper.GetAppProperty(clientHandle, reqHandle);
1617     ASSERT_EQ(spawningCtx != nullptr, 1);
1618 
1619     std::string path = AppSpawn::SandboxCommon::ConvertToRealPath(spawningCtx, "/system/<variablePackageName>/module");
1620     ASSERT_NE(path.c_str(), nullptr);   // +clone-bundleIndex+extension-<extensionType>+packageName
1621     ASSERT_EQ(strcmp(path.c_str(), "/system/+clone-100+extension-test001+com.example.myapplication/module"), 0);
1622 
1623     DeleteAppSpawningCtx(spawningCtx);
1624     AppSpawnClientDestroy(clientHandle);
1625 }
1626 
1627 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_008, TestSize.Level0)
1628 {
1629     AppSpawnClientHandle clientHandle = nullptr;
1630     int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
1631     ASSERT_EQ(ret, 0);
1632     AppSpawnReqMsgHandle reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0);
1633     ASSERT_EQ(reqHandle != nullptr, 1);
1634     ret = AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_EXTENSION_SANDBOX);
1635     ASSERT_EQ(ret, 0);
1636     ret = AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_CLONE_ENABLE);
1637     ASSERT_EQ(ret, 0);
1638     AppSpawningCtx *spawningCtx = g_testHelper.GetAppProperty(clientHandle, reqHandle);
1639     ASSERT_EQ(spawningCtx != nullptr, 1);
1640 
1641     std::string path = AppSpawn::SandboxCommon::ConvertToRealPath(spawningCtx, "/system/<variablePackageName>/module");
1642     ASSERT_STREQ(path.c_str(), "");
1643 
1644     DeleteAppSpawningCtx(spawningCtx);
1645     AppSpawnClientDestroy(clientHandle);
1646 }
1647 
1648 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_AppExtension_009, TestSize.Level0)
1649 {
1650     AppSpawnClientHandle clientHandle = nullptr;
1651     int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
1652     ASSERT_EQ(ret, 0);
1653     AppSpawnReqMsgHandle reqHandle = g_testHelper.CreateMsg(clientHandle, MSG_APP_SPAWN, 0);
1654     ASSERT_EQ(reqHandle != nullptr, 1);
1655     ret = AppSpawnReqMsgSetAppFlag(reqHandle, APP_FLAGS_EXTENSION_SANDBOX);
1656     ASSERT_EQ(ret, 0);
1657     AppSpawningCtx *spawningCtx = g_testHelper.GetAppProperty(clientHandle, reqHandle);
1658     ASSERT_EQ(spawningCtx != nullptr, 1);
1659 
1660     std::string path = AppSpawn::SandboxCommon::ConvertToRealPath(spawningCtx, "/system/<variablePackageName>/module");
1661     ASSERT_STREQ(path.c_str(), "");
1662 
1663     DeleteAppSpawningCtx(spawningCtx);
1664     AppSpawnClientDestroy(clientHandle);
1665 }
1666 
1667 /**
1668  * @tc.name: App_Spawn_Sandbox_dec_01
1669  * @tc.desc: parse config file for dec paths.
1670  * @tc.type: FUNC
1671  * @tc.author:
1672  */
1673 #define DEC_PATH_SIZE 3
1674 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_dec_01, TestSize.Level0)
1675 {
1676     std::string mJsconfig = "{ \
1677         \"mount-paths\": [{ \
1678             \"src-path\": \"\", \
1679             \"sandbox-path\": \"\", \
1680             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1681             \"dec-paths\": [ \"/storage/Users\", \"/storage/External\", \"/storage/test\" ] \
1682         }] \
1683     }";
1684     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1685     ASSERT_NE(j_config, nullptr);
1686     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1687 
1688     int ret = 0;
1689     AppSpawningCtx *appProperty = GetTestAppProperty();
1690     do {
1691         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1692         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1693             break, "Invalid mountPaths config");
1694 
1695         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1696             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1697             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mntPoint config");
1698             SandboxMountConfig mountConfig = {0};
1699             AppSpawn::SandboxCommon::GetSandboxMountConfig(appProperty, "permission", mntPoint, mountConfig);
1700 
1701             int decPathSize = mountConfig.decPaths.size();
1702             ASSERT_EQ(decPathSize, DEC_PATH_SIZE);
1703             ret = strcmp(mountConfig.decPaths[0].c_str(), "/storage/Users") ||
1704                   strcmp(mountConfig.decPaths[1].c_str(), "/storage/External") ||
1705                   strcmp(mountConfig.decPaths[2].c_str(), "/storage/test");
1706         }
1707         EXPECT_EQ(ret, 0);
1708     } while (0);
1709 
1710     cJSON_Delete(j_config);
1711     DeleteAppSpawningCtx(appProperty);
1712 }
1713 
1714 /**
1715  * @tc.name: App_Spawn_Sandbox_dec_02
1716  * @tc.desc: parse config file for dec paths.
1717  * @tc.type: FUNC
1718  * @tc.author:
1719  */
1720 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_dec_02, TestSize.Level0)
1721 {
1722     std::string mJsconfig = "{ \
1723         \"mount-paths\": [{ \
1724             \"src-path\": \"\", \
1725             \"sandbox-path\": \"\", \
1726             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1727             \"dec-paths\": [ ] \
1728         }] \
1729     }";
1730     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1731     ASSERT_NE(j_config, nullptr);
1732     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1733 
1734     int ret = 0;
1735     AppSpawningCtx *appProperty = GetTestAppProperty();
1736     do {
1737         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1738         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1739             break, "Invalid mountPaths config");
1740 
1741         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1742             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1743             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mntPoint config");
1744             SandboxMountConfig mountConfig = {0};
1745             AppSpawn::SandboxCommon::GetSandboxMountConfig(appProperty, "permission", mntPoint, mountConfig);
1746 
1747             int decPathSize = mountConfig.decPaths.size();
1748             EXPECT_EQ(decPathSize, 0);
1749         }
1750         EXPECT_EQ(ret, 0);
1751     } while (0);
1752 
1753     cJSON_Delete(j_config);
1754     DeleteAppSpawningCtx(appProperty);
1755 }
1756 
1757 /**
1758  * @tc.name: App_Spawn_Sandbox_dec_03
1759  * @tc.desc: parse config file for set policy.
1760  * @tc.type: FUNC
1761  * @tc.author:
1762  */
1763 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_dec_03, TestSize.Level0)
1764 {
1765     std::string mJsconfig = "{ \
1766         \"mount-paths\": [{ \
1767             \"src-path\": \"\", \
1768             \"sandbox-path\": \"\", \
1769             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1770             \"dec-paths\": [ \"/storage/Users\", \"/storage/External\", \"/storage/test\" ] \
1771         }] \
1772     }";
1773     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1774     ASSERT_NE(j_config, nullptr);
1775     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1776 
1777     int ret = 0;
1778     AppSpawningCtx *appProperty = GetTestAppProperty();
1779     do {
1780         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1781         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1782             break, "Invalid mountPaths config");
1783 
1784         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1785             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1786             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mntPoint config");
1787             SandboxMountConfig mountConfig = {0};
1788             AppSpawn::SandboxCommon::GetSandboxMountConfig(appProperty, "permission", mntPoint, mountConfig);
1789 
1790             int decPathSize = mountConfig.decPaths.size();
1791             EXPECT_EQ(decPathSize, DEC_PATH_SIZE);
1792             ret = AppSpawn::SandboxCore::SetDecPolicyWithPermission(appProperty, mountConfig);
1793         }
1794         EXPECT_EQ(ret, 0);
1795     } while (0);
1796 
1797     cJSON_Delete(j_config);
1798     DeleteAppSpawningCtx(appProperty);
1799 }
1800 
1801 /**
1802  * @tc.name: App_Spawn_Sandbox_dec_04
1803  * @tc.desc: parse config file for mount.
1804  * @tc.type: FUNC
1805  * @tc.author:
1806  */
1807 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_dec_04, TestSize.Level0)
1808 {
1809     std::string mJsconfig = "{ \
1810         \"mount-paths\": [{ \
1811             \"src-path\": \"\", \
1812             \"sandbox-path\": \"\", \
1813             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1814             \"dec-paths\": [ \"/storage/Users\", \"/storage/External\", \"/storage/test\" ] \
1815         }] \
1816     }";
1817     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1818     ASSERT_NE(j_config, nullptr);
1819     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1820 
1821     int ret = 0;
1822     AppSpawningCtx *appProperty = GetTestAppProperty();
1823     do {
1824         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1825         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1826             break, "Invalid mountPaths config");
1827 
1828         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1829             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1830             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mntPoint config");
1831             SandboxMountConfig mountConfig = {0};
1832             AppSpawn::SandboxCommon::GetSandboxMountConfig(appProperty, "permission", mntPoint, mountConfig);
1833 
1834             int decPathSize = mountConfig.decPaths.size();
1835             EXPECT_EQ(decPathSize, DEC_PATH_SIZE);
1836         }
1837         EXPECT_EQ(ret, 0);
1838     } while (0);
1839     ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config, nullptr, "permission");
1840     EXPECT_EQ(ret, 0);
1841 
1842     cJSON_Delete(j_config);
1843     DeleteAppSpawningCtx(appProperty);
1844 }
1845 
1846 /**
1847  * @tc.name: App_Spawn_Sandbox_dec_05
1848  * @tc.desc: parse config file for READ_WRITE_DOWNLOAD_DIRECTORY.
1849  * @tc.type: FUNC
1850  * @tc.author:
1851  */
1852 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_dec_05, TestSize.Level0)
1853 {
1854     std::string mJsconfig = "{ \
1855         \"mount-paths\": [{ \
1856             \"src-path\": \"\", \
1857             \"sandbox-path\": \"\", \
1858             \"sandbox-flags-customized\": [ \"MS_NODEV\", \"MS_RDONLY\" ], \
1859             \"dec-paths\": [ \"/storage/Users/<currentUserId>/Download\" ] \
1860         }] \
1861     }";
1862     cJSON *j_config = cJSON_Parse(mJsconfig.c_str());
1863     ASSERT_NE(j_config, nullptr);
1864     AppSpawn::SandboxCommon::StoreCJsonConfig(j_config, SandboxCommonDef::SANDBOX_APP_JSON_CONFIG);
1865 
1866     int ret = 0;
1867     AppSpawningCtx *appProperty = GetTestAppProperty();
1868     do {
1869         cJSON *mountPoints = cJSON_GetObjectItemCaseSensitive(j_config, "mount-paths");
1870         APPSPAWN_CHECK(mountPoints != nullptr || cJSON_IsArray(mountPoints), ret = -1;
1871             break, "Invalid mountPaths config");
1872 
1873         for (int i = 0; i < cJSON_GetArraySize(mountPoints); ++i) {
1874             cJSON *mntPoint = cJSON_GetArrayItem(mountPoints, i);
1875             APPSPAWN_CHECK(mntPoint != nullptr, ret = -2; break, "Invalid mntPoint config");
1876             SandboxMountConfig mountConfig = {0};
1877             AppSpawn::SandboxCommon::GetSandboxMountConfig(appProperty, "permission", mntPoint, mountConfig);
1878 
1879             int decPathSize = mountConfig.decPaths.size();
1880             EXPECT_EQ(decPathSize, 1);
1881         }
1882         EXPECT_EQ(ret, 0);
1883     } while (0);
1884     ret = AppSpawn::SandboxCore::DoAllMntPointsMount(appProperty, j_config, nullptr, "permission");
1885     EXPECT_EQ(ret, 0);
1886 
1887     cJSON_Delete(j_config);
1888     DeleteAppSpawningCtx(appProperty);
1889 }
1890 
1891 /**
1892  * @tc.name: App_Spawn_Sandbox_Shared_Mount_01
1893  * @tc.desc: [IsValidDataGroupItem] input valid param
1894  * @tc.type: FUNC
1895  * @tc.author:
1896  */
1897 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_01, TestSize.Level0)
1898 {
1899     char dataGroupInfoListStr[] = R"(
1900         {
1901             "gid": "1002",
1902             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
1903             "dataGroupId": "43200",
1904             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
1905         }
1906     )";
1907     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
1908     ASSERT_NE(j_config, nullptr);
1909     bool ret = IsValidDataGroupItem(j_config);
1910     EXPECT_TRUE(ret);
1911 
1912     cJSON_Delete(j_config);
1913 }
1914 
1915 /**
1916  * @tc.name: App_Spawn_Sandbox_Shared_Mount_02
1917  * @tc.desc: [IsValidDataGroupItem] input valid param in json array
1918  * @tc.type: FUNC
1919  * @tc.author:
1920  */
1921 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_02, TestSize.Level0)
1922 {
1923     char dataGroupInfoListStr[] = R"([
1924         {
1925             "gid": "1002",
1926             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
1927             "dataGroupId": "43200",
1928             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
1929         },
1930         {
1931             "gid": "1002",
1932             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
1933             "dataGroupId": "43200",
1934             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
1935         }
1936     ])";
1937     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
1938     ASSERT_NE(j_config, nullptr);
1939     bool ret = false;
1940     cJSON *child = nullptr;
cJSON_ArrayForEach(child,j_config)1941     cJSON_ArrayForEach(child, j_config) {
1942         ret = IsValidDataGroupItem(child);
1943         if (!ret) {
1944             break;
1945         }
1946     }
1947     EXPECT_TRUE(ret);
1948 
1949     cJSON_Delete(j_config);
1950 }
1951 
1952 /**
1953  * @tc.name: App_Spawn_Sandbox_Shared_Mount_03
1954  * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId is not string type
1955  * @tc.type: FUNC
1956  * @tc.author:
1957  */
1958 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_03, TestSize.Level0)
1959 {
1960     char dataGroupInfoListStr[] = R"(
1961         {
1962             "gid": "1002",
1963             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
1964             "dataGroupId": 43200,
1965             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
1966         }
1967     )";
1968     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
1969     ASSERT_NE(j_config, nullptr);
1970     bool ret = IsValidDataGroupItem(j_config);
1971     EXPECT_FALSE(ret);
1972 
1973     cJSON_Delete(j_config);
1974 }
1975 
1976 /**
1977  * @tc.name: App_Spawn_Sandbox_Shared_Mount_04
1978  * @tc.desc: [IsValidDataGroupItem] input valid param, gid is not string type
1979  * @tc.type: FUNC
1980  * @tc.author:
1981  */
1982 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_04, TestSize.Level0)
1983 {
1984     char dataGroupInfoListStr[] = R"(
1985         {
1986             "gid": 1002,
1987             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
1988             "dataGroupId": "43200",
1989             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
1990         }
1991     )";
1992     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
1993     ASSERT_NE(j_config, nullptr);
1994     bool ret = IsValidDataGroupItem(j_config);
1995     EXPECT_FALSE(ret);
1996 
1997     cJSON_Delete(j_config);
1998 }
1999 
2000 /**
2001  * @tc.name: App_Spawn_Sandbox_Shared_Mount_05
2002  * @tc.desc: [IsValidDataGroupItem] input valid param, dir is not string type
2003  * @tc.type: FUNC
2004  * @tc.author:
2005  */
2006 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_05, TestSize.Level0)
2007 {
2008     char dataGroupInfoListStr[] = R"(
2009         {
2010             "gid": "1002",
2011             "dir": 100,
2012             "dataGroupId": "43200",
2013             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
2014         }
2015     )";
2016     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2017     ASSERT_NE(j_config, nullptr);
2018     bool ret = IsValidDataGroupItem(j_config);
2019     EXPECT_FALSE(ret);
2020 
2021     cJSON_Delete(j_config);
2022 }
2023 
2024 /**
2025  * @tc.name: App_Spawn_Sandbox_Shared_Mount_06
2026  * @tc.desc: [IsValidDataGroupItem] input valid param, uuid is not string type
2027  * @tc.type: FUNC
2028  * @tc.author:
2029  */
2030 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_06, TestSize.Level0)
2031 {
2032     char dataGroupInfoListStr[] = R"(
2033         {
2034             "gid": "1002",
2035             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
2036             "dataGroupId": "43200",
2037             "uuid": 124
2038         }
2039     )";
2040     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2041     ASSERT_NE(j_config, nullptr);
2042     bool ret = IsValidDataGroupItem(j_config);
2043     EXPECT_FALSE(ret);
2044 
2045     cJSON_Delete(j_config);
2046 }
2047 
2048 /**
2049  * @tc.name: App_Spawn_Sandbox_Shared_Mount_07
2050  * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId and gid is not string type
2051  * @tc.type: FUNC
2052  * @tc.author:
2053  */
2054 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_07, TestSize.Level0)
2055 {
2056     char dataGroupInfoListStr[] = R"(
2057         {
2058             "gid": 1002,
2059             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
2060             "dataGroupId": 43200,
2061             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
2062         }
2063     )";
2064     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2065     ASSERT_NE(j_config, nullptr);
2066     bool ret = IsValidDataGroupItem(j_config);
2067     EXPECT_FALSE(ret);
2068 
2069     cJSON_Delete(j_config);
2070 }
2071 
2072 /**
2073  * @tc.name: App_Spawn_Sandbox_Shared_Mount_08
2074  * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId and dir is not string type
2075  * @tc.type: FUNC
2076  * @tc.author:
2077  */
2078 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_08, TestSize.Level0)
2079 {
2080     char dataGroupInfoListStr[] = R"(
2081         {
2082             "gid": "1002",
2083             "dir": 100,
2084             "dataGroupId": 43200,
2085             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
2086         }
2087     )";
2088     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2089     ASSERT_NE(j_config, nullptr);
2090     bool ret = IsValidDataGroupItem(j_config);
2091     EXPECT_FALSE(ret);
2092 
2093     cJSON_Delete(j_config);
2094 }
2095 
2096 /**
2097  * @tc.name: App_Spawn_Sandbox_Shared_Mount_09
2098  * @tc.desc: [IsValidDataGroupItem] input valid param, datagroupId and uuid is not string type
2099  * @tc.type: FUNC
2100  * @tc.author:
2101  */
2102 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_09, TestSize.Level0)
2103 {
2104     char dataGroupInfoListStr[] = R"(
2105         {
2106             "gid": "1002",
2107             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
2108             "dataGroupId": 43200,
2109             "uuid": 124
2110         }
2111     )";
2112     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2113     ASSERT_NE(j_config, nullptr);
2114     bool ret = IsValidDataGroupItem(j_config);
2115     EXPECT_FALSE(ret);
2116 
2117     cJSON_Delete(j_config);
2118 }
2119 
2120 /**
2121  * @tc.name: App_Spawn_Sandbox_Shared_Mount_10
2122  * @tc.desc: [IsValidDataGroupItem] input valid param, gid and dir is not string type
2123  * @tc.type: FUNC
2124  * @tc.author:
2125  */
2126 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_10, TestSize.Level0)
2127 {
2128     char dataGroupInfoListStr[] = R"(
2129         {
2130             "gid": 1002,
2131             "dir": 100,
2132             "dataGroupId": "43200",
2133             "uuid": "49c016e6-065a-abd1-5867-b1f91114f840"
2134         }
2135     )";
2136     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2137     ASSERT_NE(j_config, nullptr);
2138     bool ret = IsValidDataGroupItem(j_config);
2139     EXPECT_FALSE(ret);
2140 
2141     cJSON_Delete(j_config);
2142 }
2143 
2144 /**
2145  * @tc.name: App_Spawn_Sandbox_Shared_Mount_11
2146  * @tc.desc: [IsValidDataGroupItem] input valid param, gid and uuid is not string type
2147  * @tc.type: FUNC
2148  * @tc.author:
2149  */
2150 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_11, TestSize.Level0)
2151 {
2152     char dataGroupInfoListStr[] = R"(
2153         {
2154             "gid": 1002,
2155             "dir": "/data/app/el2/100/group/49c016e6-065a-abd1-5867-b1f91114f840",
2156             "dataGroupId": "43200",
2157             "uuid": 124
2158         }
2159     )";
2160     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2161     ASSERT_NE(j_config, nullptr);
2162     bool ret = IsValidDataGroupItem(j_config);
2163     EXPECT_FALSE(ret);
2164 
2165     cJSON_Delete(j_config);
2166 }
2167 
2168 /**
2169  * @tc.name: App_Spawn_Sandbox_Shared_Mount_12
2170  * @tc.desc: [IsValidDataGroupItem] input valid param, dir and uuid is not string type
2171  * @tc.type: FUNC
2172  * @tc.author:
2173  */
2174 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_12, TestSize.Level0)
2175 {
2176     char dataGroupInfoListStr[] = R"(
2177         {
2178             "gid": "1002",
2179             "dir": 100,
2180             "dataGroupId": "43200",
2181             "uuid": 124
2182         }
2183     )";
2184     cJSON *j_config = cJSON_Parse(dataGroupInfoListStr);
2185     ASSERT_NE(j_config, nullptr);
2186     bool ret = IsValidDataGroupItem(j_config);
2187     EXPECT_FALSE(ret);
2188 
2189     cJSON_Delete(j_config);
2190 }
2191 
2192 /**
2193  * @tc.name: App_Spawn_Sandbox_Shared_Mount_13
2194  * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el2.
2195  * @tc.type: FUNC
2196  * @tc.author:
2197  */
2198 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_13, TestSize.Level0)
2199 {
2200     std::string str = "/data/storage/el2/group/";
2201     int res = GetElxInfoFromDir(str.c_str());
2202     EXPECT_EQ(res, EL2);
2203 }
2204 
2205 /**
2206  * @tc.name: App_Spawn_Sandbox_Shared_Mount_14
2207  * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el3.
2208  * @tc.type: FUNC
2209  * @tc.author:
2210  */
2211 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_14, TestSize.Level0)
2212 {
2213     std::string str = "/data/storage/el3/group/";
2214     int res = GetElxInfoFromDir(str.c_str());
2215     EXPECT_EQ(res, EL3);
2216 }
2217 
2218 /**
2219  * @tc.name: App_Spawn_Sandbox_Shared_Mount_15
2220  * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el4.
2221  * @tc.type: FUNC
2222  * @tc.author:
2223  */
2224 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_15, TestSize.Level0)
2225 {
2226     std::string str = "/data/storage/el4/group/";
2227     int res = GetElxInfoFromDir(str.c_str());
2228     EXPECT_EQ(res, EL4);
2229 }
2230 
2231 /**
2232  * @tc.name: App_Spawn_Sandbox_Shared_Mount_16
2233  * @tc.desc: [GetElxInfoFromDir] input valid, the directory contains el5.
2234  * @tc.type: FUNC
2235  * @tc.author:
2236  */
2237 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_16, TestSize.Level0)
2238 {
2239     std::string str = "/data/storage/el5/group/";
2240     int res = GetElxInfoFromDir(str.c_str());
2241     EXPECT_EQ(res, EL5);
2242 }
2243 
2244 /**
2245  * @tc.name: App_Spawn_Sandbox_Shared_Mount_17
2246  * @tc.desc: [GetElxInfoFromDir] input invalid, the directory don't contains el2~el5, contains el0.
2247  * @tc.type: FUNC
2248  * @tc.author:
2249  */
2250 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_17, TestSize.Level0)
2251 {
2252     std::string str = "/data/storage/el0/group/";
2253     int res = GetElxInfoFromDir(str.c_str());
2254     EXPECT_EQ(res, ELX_MAX);
2255 }
2256 
2257 /**
2258  * @tc.name: App_Spawn_Sandbox_Shared_Mount_18
2259  * @tc.desc: [GetElxInfoFromDir] input invalid, the directory don't contains el2~el5, contains el6.
2260  * @tc.type: FUNC
2261  * @tc.author:
2262  */
2263 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_18, TestSize.Level0)
2264 {
2265     std::string str = "/data/storage/el6/group/";
2266     int res = GetElxInfoFromDir(str.c_str());
2267     EXPECT_EQ(res, ELX_MAX);
2268 }
2269 
2270 /**
2271  * @tc.name: App_Spawn_Sandbox_Shared_Mount_19
2272  * @tc.desc: [GetElxInfoFromDir] input invalid, the directory don't contains el2~el5, param is null.
2273  * @tc.type: FUNC
2274  * @tc.author:
2275  */
2276 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_19, TestSize.Level0)
2277 {
2278     int res = GetElxInfoFromDir(nullptr);
2279     EXPECT_EQ(res, ELX_MAX);
2280 }
2281 
2282 /**
2283  * @tc.name: App_Spawn_Sandbox_Shared_Mount_20
2284  * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL2.
2285  * @tc.type: FUNC
2286  * @tc.author:
2287  */
2288 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_20, TestSize.Level0)
2289 {
2290     const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL2);
2291     ASSERT_EQ(templateItem != nullptr, 1);
2292     int res = strcmp(templateItem->elxName, "el2");
2293     EXPECT_EQ(res, 0);
2294 }
2295 
2296 /**
2297  * @tc.name: App_Spawn_Sandbox_Shared_Mount_21
2298  * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL3.
2299  * @tc.type: FUNC
2300  * @tc.author:
2301  */
2302 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_21, TestSize.Level0)
2303 {
2304     const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL3);
2305     ASSERT_EQ(templateItem != nullptr, 1);
2306     int res = strcmp(templateItem->elxName, "el3");
2307     EXPECT_EQ(res, 0);
2308 }
2309 
2310 /**
2311  * @tc.name: App_Spawn_Sandbox_Shared_Mount_22
2312  * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL4.
2313  * @tc.type: FUNC
2314  * @tc.author:
2315  */
2316 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_22, TestSize.Level0)
2317 {
2318     const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL4);
2319     ASSERT_EQ(templateItem != nullptr, 1);
2320     int res = strcmp(templateItem->elxName, "el4");
2321     EXPECT_EQ(res, 0);
2322 }
2323 
2324 /**
2325  * @tc.name: App_Spawn_Sandbox_Shared_Mount_23
2326  * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is EL5.
2327  * @tc.type: FUNC
2328  * @tc.author:
2329  */
2330 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_23, TestSize.Level0)
2331 {
2332     const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(EL5);
2333     ASSERT_EQ(templateItem != nullptr, 1);
2334     int res = strcmp(templateItem->elxName, "el5");
2335     EXPECT_EQ(res, 0);
2336 }
2337 
2338 /**
2339  * @tc.name: App_Spawn_Sandbox_Shared_Mount_24
2340  * @tc.desc: [GetDataGroupArgTemplate] input invalid, the category is between el2 and el5, category is 6.
2341  * @tc.type: FUNC
2342  * @tc.author:
2343  */
2344 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_Shared_Mount_24, TestSize.Level0)
2345 {
2346     const DataGroupSandboxPathTemplate *templateItem = GetDataGroupArgTemplate(6);
2347     int res = -1;
2348     if (templateItem == nullptr) {
2349         res = 0;
2350     }
2351     EXPECT_EQ(res, 0);
2352 }
2353 
2354 HWTEST_F(AppSpawnSandboxTest, App_Spawn_Sandbox_DevModel_001, TestSize.Level0)
2355 {
2356     AppSpawningCtx* spawningCtx = GetTestAppProperty();
2357     std::string path = AppSpawn::SandboxCommon::ConvertToRealPath(spawningCtx, "/version/special_cust/<devModel>");
2358     ASSERT_NE(path.c_str(), nullptr);
2359     std::string devModelPath =
2360         "/version/special_cust/" + system::GetParameter(SandboxCommonDef::DEVICE_MODEL_NAME_PARAM, "");
2361 
2362     ASSERT_EQ(strcmp(path.c_str(), devModelPath.c_str()), 0);
2363     DeleteAppSpawningCtx(spawningCtx);
2364 }
2365 
2366 HWTEST_F(AppSpawnSandboxTest, App_Spawn_permissionUserId_001, TestSize.Level0)
2367 {
2368     AppSpawningCtx* spawningCtx = GetTestAppProperty();
2369     std::string path = AppSpawn::SandboxCommon::ConvertToRealPathWithPermission(spawningCtx,
2370                         "/mnt/sandbox/<permissionUserId>/storage/Users/currentUser");
2371     ASSERT_NE(path.c_str(), nullptr);
2372     std::string examplePath = "/mnt/sandbox/100/storage/Users/currentUser";
2373 
2374     ASSERT_EQ(strcmp(path.c_str(), examplePath.c_str()), 0);
2375     DeleteAppSpawningCtx(spawningCtx);
2376 }
2377 
2378 HWTEST_F(AppSpawnSandboxTest, Handle_Flag_Point_PreInstall_Shell_Hap_001, TestSize.Level0)
2379 {
2380     std::string flagPointConfigStr = "{ \
2381         \"flags-point\": [ \
2382             { \
2383                 \"flags\": \"PREINSTALLED_HAP\", \
2384                 \"mount-paths\": [{ \
2385                     \"src-path\": \"/version/special_cust/app\", \
2386                     \"sandbox-path\": \"/version/special_cust/app\", \
2387                     \"sandbox-flags\": [ \
2388                         \"bind\", \
2389                         \"rec\" \
2390                     ], \
2391                     \"check-action-status\": \"false\" \
2392                 }] \
2393             }, \
2394             { \
2395                 \"flags\": \"PREINSTALLED_SHELL_HAP\", \
2396                 \"mount-paths\": [{ \
2397                     \"src-path\": \"/system/app/HiShell\", \
2398                     \"sandbox-path\": \"/system/app/HiShell\", \
2399                     \"sandbox-flags\": [ \
2400                         \"bind\", \
2401                         \"rec\" \
2402                     ], \
2403                     \"check-action-status\": \"false\" \
2404                 }] \
2405             } \
2406         ] \
2407     }";
2408     cJSON *flagPointConfig = cJSON_Parse(flagPointConfigStr.c_str());
2409     AppSpawningCtx *appProperty = GetTestAppProperty();
2410     ASSERT_EQ(appProperty != nullptr, 1);
2411     int32_t ret = AppSpawn::SandboxCore::HandleFlagsPoint(appProperty, flagPointConfig);
2412     EXPECT_EQ(ret, 0);
2413     DeleteAppSpawningCtx(appProperty);
2414 }
2415 
2416 HWTEST_F(AppSpawnSandboxTest, Handle_Flag_Point_PreInstall_Shell_Hap_002, TestSize.Level0)
2417 {
2418     std::string flagPointConfigStr = "{ \
2419         \"flags-point\": [ \
2420             { \
2421                 \"flags\": \"PREINSTALLED_HAP\", \
2422                 \"mount-paths\": [{ \
2423                     \"src-path\": \"/version/special_cust/app\", \
2424                     \"sandbox-path\": \"/version/special_cust/app\", \
2425                     \"sandbox-flags\": [ \
2426                         \"bind\", \
2427                         \"rec\" \
2428                     ], \
2429                     \"check-action-status\": \"false\" \
2430                 }] \
2431             }, \
2432             { \
2433                 \"flags\": \"PREINSTALLED_SHELL_HAP\", \
2434                 \"mount-paths\": [{ \
2435                     \"src-path\": \"/system/app/HiShell\", \
2436                     \"sandbox-path\": \"/system/app/HiShell\", \
2437                     \"sandbox-flags\": [ \
2438                         \"bind\", \
2439                         \"rec\" \
2440                     ], \
2441                     \"check-action-status\": \"false\" \
2442                 }] \
2443             } \
2444         ] \
2445     }";
2446     cJSON *flagPointConfig = cJSON_Parse(flagPointConfigStr.c_str());
2447     AppSpawningCtx *appProperty = GetTestAppProperty();
2448     ASSERT_EQ(appProperty != nullptr, 1);
2449     int ret = SetAppSpawnMsgFlag(appProperty->message, TLV_MSG_FLAGS, APP_FLAGS_PRE_INSTALLED_HAP);
2450     ASSERT_EQ(ret, 0);
2451     int32_t res = AppSpawn::SandboxCore::HandleFlagsPoint(appProperty, flagPointConfig);
2452     EXPECT_EQ(res, 0);
2453     DeleteAppSpawningCtx(appProperty);
2454 }
2455 }  // namespace OHOS
2456