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