1 /*
2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include "hilog_tag_wrapper.h"
18 #define private public
19 #include "app_spawn_client.h"
20 #undef private
21 #include "app_spawn_client.cpp"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace AppExecFwk {
28 class AppSpawnClientTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase(void)36 void AppSpawnClientTest::SetUpTestCase(void)
37 {}
38
TearDownTestCase(void)39 void AppSpawnClientTest::TearDownTestCase(void)
40 {}
41
SetUp()42 void AppSpawnClientTest::SetUp()
43 {}
44
TearDown()45 void AppSpawnClientTest::TearDown()
46 {}
47
48 /**
49 * @tc.name: PreStartNWebSpawnProcess_001
50 * @tc.desc: prestart nwebspawn process.
51 * @tc.type: FUNC
52 * @tc.require: issueI5W4S7
53 */
54 HWTEST_F(AppSpawnClientTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
55 {
56 auto asc = std::make_shared<AppSpawnClient>(true);
57 int ret = asc->PreStartNWebSpawnProcess();
58 EXPECT_EQ(ret, ERR_OK);
59 }
60
61 /**
62 * @tc.name: PreStartNWebSpawnProcessImpl_002
63 * @tc.desc: prestart nwebspawn process.
64 * @tc.type: FUNC
65 * @tc.require: issueI5W4S7
66 */
67 HWTEST_F(AppSpawnClientTest, PreStartNWebSpawnProcessImpl_002, TestSize.Level0)
68 {
69 auto asc = std::make_shared<AppSpawnClient>(true);
70 asc->OpenConnection();
71 int ret = asc->PreStartNWebSpawnProcess();
72 EXPECT_EQ(ret, ERR_OK);
73 }
74
75 /**
76 * @tc.name: AppSpawnClient_001
77 * @tc.desc: new AppSpawnClient object
78 * @tc.type: FUNC
79 * @tc.require: issueI5W4S7
80 */
81 HWTEST_F(AppSpawnClientTest, AppSpawnClient_001, TestSize.Level0)
82 {
83 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_001 start");
84 const char* serviceName = "appspawn";
85 auto asc = std::make_shared<AppSpawnClient>(serviceName);
86 auto ret = asc->OpenConnection();
87 EXPECT_EQ(ret, ERR_OK);
88 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_001 end");
89 }
90
91 /**
92 * @tc.name: AppSpawnClient_002
93 * @tc.desc: new AppSpawnClient object
94 * @tc.type: FUNC
95 * @tc.require: issueI5W4S7
96 */
97 HWTEST_F(AppSpawnClientTest, AppSpawnClient_002, TestSize.Level0)
98 {
99 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_002 start");
100 const char* serviceName = "cjappspawn";
101 auto asc = std::make_shared<AppSpawnClient>(serviceName);
102 auto ret = asc->OpenConnection();
103 EXPECT_EQ(ret, ERR_OK);
104 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_002 end");
105 }
106
107 /**
108 * @tc.name: AppSpawnClient_003
109 * @tc.desc: new AppSpawnClient object
110 * @tc.type: FUNC
111 * @tc.require: issueI5W4S7
112 */
113 HWTEST_F(AppSpawnClientTest, AppSpawnClient_003, TestSize.Level0)
114 {
115 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_003 start");
116 const char* serviceName = "nwebRestart";
117 auto asc = std::make_shared<AppSpawnClient>(serviceName);
118 auto ret = asc->OpenConnection();
119 EXPECT_EQ(ret, ERR_OK);
120 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_003 end");
121 }
122
123 /**
124 * @tc.name: AppSpawnClient_004
125 * @tc.desc: new AppSpawnClient object
126 * @tc.type: FUNC
127 * @tc.require: issueI5W4S7
128 */
129 HWTEST_F(AppSpawnClientTest, AppSpawnClient_004, TestSize.Level0)
130 {
131 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_004 start");
132 const char* serviceName = "nativespawn";
133 auto asc = std::make_shared<AppSpawnClient>(serviceName);
134 auto ret = asc->OpenConnection();
135 EXPECT_EQ(ret, ERR_OK);
136 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_004 end");
137 }
138
139 /**
140 * @tc.name: AppSpawnClient_005
141 * @tc.desc: new AppSpawnClient object
142 * @tc.type: FUNC
143 * @tc.require: issueI5W4S7
144 */
145 HWTEST_F(AppSpawnClientTest, AppSpawnClient_005, TestSize.Level0)
146 {
147 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_005 start");
148 const char* serviceName = "nwebspawn";
149 auto asc = std::make_shared<AppSpawnClient>(serviceName);
150 auto ret = asc->OpenConnection();
151 EXPECT_EQ(ret, ERR_OK);
152 TAG_LOGI(AAFwkTag::TEST, "AppSpawnClient_005 end");
153 }
154
155 /**
156 * @tc.name: OpenConnection_001
157 * @tc.desc: appspawn OpenConnection
158 * @tc.type: FUNC
159 * @tc.require: issueI5W4S7
160 */
161 HWTEST_F(AppSpawnClientTest, OpenConnection_001, TestSize.Level0)
162 {
163 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start");
164 auto asc = std::make_shared<AppSpawnClient>(true);
165 auto ret = asc->OpenConnection();
166 EXPECT_EQ(ret, ERR_OK);
167 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end");
168 }
169
170 /**
171 * @tc.name: OpenConnection_002
172 * @tc.desc: appspawn OpenConnection
173 * @tc.type: FUNC
174 * @tc.require: issueI5W4S7
175 */
176 HWTEST_F(AppSpawnClientTest, OpenConnection_002, TestSize.Level0)
177 {
178 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start");
179 auto asc = std::make_shared<AppSpawnClient>(false);
180 auto ret = asc->OpenConnection();
181 EXPECT_EQ(ret, ERR_OK);
182 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end");
183 }
184
185 /**
186 * @tc.name: CloseConnection_001
187 * @tc.desc: appspawn CloseConnection
188 * @tc.type: FUNC
189 * @tc.require: issueI5W4S7
190 */
191 HWTEST_F(AppSpawnClientTest, CloseConnection_001, TestSize.Level0)
192 {
193 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start");
194 auto asc = std::make_shared<AppSpawnClient>(true);
195 auto ret = asc->OpenConnection();
196 EXPECT_EQ(ret, ERR_OK);
197 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end");
198 }
199
200 /**
201 * @tc.name: CloseConnection_002
202 * @tc.desc: appspawn CloseConnection
203 * @tc.type: FUNC
204 * @tc.require: issueI5W4S7
205 */
206 HWTEST_F(AppSpawnClientTest, CloseConnection_002, TestSize.Level0)
207 {
208 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 start");
209 auto asc = std::make_shared<AppSpawnClient>(false);
210 auto ret = asc->OpenConnection();
211 EXPECT_EQ(ret, ERR_OK);
212 TAG_LOGI(AAFwkTag::TEST, "OpenConnection_001 end");
213 }
214
215 /**
216 * @tc.name: SetDacInfo_001
217 * @tc.desc: appspawn SetDacInfo
218 * @tc.type: FUNC
219 * @tc.require: issueI5W4S7
220 */
221 HWTEST_F(AppSpawnClientTest, SetDacInfo_001, TestSize.Level0)
222 {
223 TAG_LOGI(AAFwkTag::TEST, "SetDacInfo_001 start");
224 AppSpawnStartMsg startMsg = {0};
225 startMsg.uid = 1001;
226 startMsg.gid = 2001;
227 startMsg.gids = {1001, 1002, 1003};
228 std::string procName("test_proc_name");
229 startMsg.procName = procName;
230 std::string permission1("permission_for_test_1");
231 std::string permission2("permission_for_test_2");
232 std::string permission3("permission_for_test_3");
233 startMsg.permissions.insert(permission1);
234 startMsg.permissions.insert(permission2);
235 startMsg.permissions.insert(permission3);
236 startMsg.flags = 0x1000;
237 startMsg.atomicServiceFlag = false;
238 startMsg.strictMode = false;
239 startMsg.isolatedExtension = false;
240 startMsg.childProcessType = 1;
241 startMsg.isolationMode = false;
242 std::string provisionType("test_provisionType");
243 startMsg.provisionType = provisionType;
244 std::string processType("test_processType");
245 startMsg.processType = processType;
246 startMsg.maxChildProcess = 1;
247 std::string extensionSandboxPath("test_extensionSandboxPath");
248 startMsg.extensionSandboxPath = extensionSandboxPath;
249
250 auto asc = std::make_shared<AppSpawnClient>(false);
251 int32_t ret = 0;
252 AppSpawnReqMsgHandle reqHandle = nullptr;
253 ret = asc->OpenConnection();
254 EXPECT_EQ(ret, ERR_OK);
255 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
256 EXPECT_EQ(ret, ERR_OK);
257 ret = asc->SetDacInfo(startMsg, reqHandle);
258 EXPECT_EQ(ret, ERR_OK);
259
260 TAG_LOGI(AAFwkTag::TEST, "SetDacInfo_001 end");
261 }
262
263 /**
264 * @tc.name: SetMountPermission_001
265 * @tc.desc: appspawn SetMountPermission
266 * @tc.type: FUNC
267 * @tc.require: issueI5W4S7
268 */
269 HWTEST_F(AppSpawnClientTest, SetMountPermission_001, TestSize.Level0)
270 {
271 TAG_LOGI(AAFwkTag::TEST, "SetMountPermission_001 start");
272 AppSpawnStartMsg startMsg = {0};
273 startMsg.uid = 1001;
274 startMsg.gid = 2001;
275 startMsg.gids = {1001, 1002, 1003};
276 std::string procName("test_proc_name");
277 startMsg.procName = procName;
278 std::string permission1("permission_for_test_1");
279 std::string permission2("permission_for_test_2");
280 std::string permission3("permission_for_test_3");
281 startMsg.permissions.insert(permission1);
282 startMsg.permissions.insert(permission2);
283 startMsg.permissions.insert(permission3);
284 startMsg.flags = 0x1000;
285 startMsg.atomicServiceFlag = false;
286 startMsg.strictMode = false;
287 startMsg.isolatedExtension = false;
288 startMsg.childProcessType = 1;
289 startMsg.isolationMode = false;
290 std::string provisionType("test_provisionType");
291 startMsg.provisionType = provisionType;
292 std::string processType("test_processType");
293 startMsg.processType = processType;
294 startMsg.maxChildProcess = 1;
295 std::string extensionSandboxPath("test_extensionSandboxPath");
296 startMsg.extensionSandboxPath = extensionSandboxPath;
297
298 auto asc = std::make_shared<AppSpawnClient>(false);
299 int32_t ret = 0;
300 AppSpawnReqMsgHandle reqHandle = nullptr;
301 ret = asc->OpenConnection();
302 EXPECT_EQ(ret, ERR_OK);
303 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
304 EXPECT_EQ(ret, ERR_OK);
305 ret = asc->SetMountPermission(startMsg, reqHandle);
306 EXPECT_NE(ret, ERR_OK);
307
308 TAG_LOGI(AAFwkTag::TEST, "SetMountPermission_001 end");
309 }
310
311 /**
312 * @tc.name: SetStartFlags_001
313 * @tc.desc: appspawn SetStartFlags
314 * @tc.type: FUNC
315 * @tc.require: issueI5W4S7
316 */
317 HWTEST_F(AppSpawnClientTest, SetStartFlags_001, TestSize.Level0)
318 {
319 TAG_LOGI(AAFwkTag::TEST, "SetStartFlags_001 start");
320 AppSpawnStartMsg startMsg = {0};
321 startMsg.uid = 1001;
322 startMsg.gid = 2001;
323 startMsg.gids = {1001, 1002, 1003};
324 std::string procName("test_proc_name");
325 startMsg.procName = procName;
326 std::string permission1("permission_for_test_1");
327 std::string permission2("permission_for_test_2");
328 std::string permission3("permission_for_test_3");
329 startMsg.permissions.insert(permission1);
330 startMsg.permissions.insert(permission2);
331 startMsg.permissions.insert(permission3);
332 startMsg.flags = 0x1000;
333 startMsg.atomicServiceFlag = false;
334 startMsg.strictMode = false;
335 startMsg.isolatedExtension = false;
336 startMsg.childProcessType = 1;
337 startMsg.isolationMode = false;
338 std::string provisionType("test_provisionType");
339 startMsg.provisionType = provisionType;
340 std::string processType("test_processType");
341 startMsg.processType = processType;
342 startMsg.maxChildProcess = 1;
343 std::string extensionSandboxPath("test_extensionSandboxPath");
344 startMsg.extensionSandboxPath = extensionSandboxPath;
345
346 auto asc = std::make_shared<AppSpawnClient>(false);
347 int32_t ret = 0;
348 AppSpawnReqMsgHandle reqHandle = nullptr;
349 ret = asc->OpenConnection();
350 EXPECT_EQ(ret, ERR_OK);
351 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
352 EXPECT_EQ(ret, ERR_OK);
353 ret = asc->SetStartFlags(startMsg, reqHandle);
354 EXPECT_EQ(ret, ERR_OK);
355 TAG_LOGI(AAFwkTag::TEST, "SetStartFlags_001 end");
356 }
357
358
359 /**
360 * @tc.name: AppspawnSetExtMsgMore_001
361 * @tc.desc: appspawn AppspawnSetExtMsgMore
362 * @tc.type: FUNC
363 * @tc.require: issueI5W4S7
364 */
365 HWTEST_F(AppSpawnClientTest, AppspawnSetExtMsgMore_001, TestSize.Level0)
366 {
367 TAG_LOGI(AAFwkTag::TEST, "AppspawnSetExtMsgMore_001 start");
368 AppSpawnStartMsg startMsg = {0};
369 startMsg.uid = 1001;
370 startMsg.gid = 2001;
371 startMsg.gids = {1001, 1002, 1003};
372 std::string procName("test_proc_name");
373 startMsg.procName = procName;
374 std::string permission1("permission_for_test_1");
375 std::string permission2("permission_for_test_2");
376 std::string permission3("permission_for_test_3");
377 startMsg.permissions.insert(permission1);
378 startMsg.permissions.insert(permission2);
379 startMsg.permissions.insert(permission3);
380 startMsg.flags = 0x1000;
381 startMsg.atomicServiceFlag = false;
382 startMsg.strictMode = false;
383 startMsg.isolatedExtension = false;
384 startMsg.childProcessType = 1;
385 startMsg.isolationMode = false;
386 std::string provisionType("test_provisionType");
387 startMsg.provisionType = provisionType;
388 std::string processType("test_processType");
389 startMsg.processType = processType;
390 startMsg.maxChildProcess = 1;
391 std::string extensionSandboxPath("test_extensionSandboxPath");
392 startMsg.extensionSandboxPath = extensionSandboxPath;
393
394 auto asc = std::make_shared<AppSpawnClient>(false);
395 int32_t ret = 0;
396 AppSpawnReqMsgHandle reqHandle = nullptr;
397 ret = asc->OpenConnection();
398 EXPECT_EQ(ret, ERR_OK);
399 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
400 EXPECT_EQ(ret, ERR_OK);
401 ret = asc->AppspawnSetExtMsgMore(startMsg, reqHandle);
402 EXPECT_EQ(ret, ERR_OK);
403
404 TAG_LOGI(AAFwkTag::TEST, "AppspawnSetExtMsgMore_001 end");
405 }
406
407
408 /**
409 * @tc.name: AppspawnCreateDefaultMsg_001
410 * @tc.desc: appspawn AppspawnCreateDefaultMsg
411 * @tc.type: FUNC
412 * @tc.require: issueI5W4S7
413 */
414 HWTEST_F(AppSpawnClientTest, AppspawnCreateDefaultMsg_001, TestSize.Level0)
415 {
416 TAG_LOGI(AAFwkTag::TEST, "AppspawnCreateDefaultMsg_001 start");
417 AppSpawnStartMsg startMsg = {0};
418 startMsg.uid = 1001;
419 startMsg.gid = 2001;
420 startMsg.gids = {1001, 1002, 1003};
421 std::string procName("test_proc_name");
422 startMsg.procName = procName;
423 std::string apl("test_apl");
424 startMsg.apl = apl;
425 std::string ownerId("test_owner_id");
426 startMsg.ownerId = ownerId;
427 std::string bundleName("test_bundle_name");
428 startMsg.bundleName = bundleName;
429 std::string permission1("permission_for_test_1");
430 std::string permission2("permission_for_test_2");
431 std::string permission3("permission_for_test_3");
432 startMsg.permissions.insert(permission1);
433 startMsg.permissions.insert(permission2);
434 startMsg.permissions.insert(permission3);
435 startMsg.flags = 0x1000;
436 startMsg.atomicServiceFlag = false;
437 startMsg.strictMode = false;
438 startMsg.isolatedExtension = false;
439 startMsg.childProcessType = 1;
440 startMsg.isolationMode = false;
441 std::string provisionType("test_provisionType");
442 startMsg.provisionType = provisionType;
443 std::string processType("test_processType");
444 startMsg.processType = processType;
445 startMsg.maxChildProcess = 1;
446 std::string extensionSandboxPath("test_extensionSandboxPath");
447 startMsg.extensionSandboxPath = extensionSandboxPath;
448
449 auto asc = std::make_shared<AppSpawnClient>(false);
450 int32_t ret = 0;
451 AppSpawnReqMsgHandle reqHandle = nullptr;
452 ret = asc->OpenConnection();
453 EXPECT_EQ(ret, ERR_OK);
454 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
455 EXPECT_EQ(ret, ERR_OK);
456 ret = asc->AppspawnCreateDefaultMsg(startMsg, reqHandle);
457 EXPECT_NE(ret, ERR_OK);
458
459 TAG_LOGI(AAFwkTag::TEST, "AppspawnCreateDefaultMsg_001 end");
460 }
461
462
463 /**
464 * @tc.name: VerifyMsg_001
465 * @tc.desc: appspawn VerifyMsg
466 * @tc.type: FUNC
467 * @tc.require: issueI5W4S7
468 */
469 HWTEST_F(AppSpawnClientTest, VerifyMsg_001, TestSize.Level0)
470 {
471 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_001 start");
472 AppSpawnStartMsg startMsg = {0};
473 startMsg.uid = 1001;
474 startMsg.gid = 2001;
475 startMsg.gids = {1001, 1002, 1003};
476 std::string procName("test_proc_name");
477 startMsg.procName = procName;
478 std::string permission1("permission_for_test_1");
479 std::string permission2("permission_for_test_2");
480 std::string permission3("permission_for_test_3");
481 startMsg.permissions.insert(permission1);
482 startMsg.permissions.insert(permission2);
483 startMsg.permissions.insert(permission3);
484 startMsg.flags = 0x1000;
485 startMsg.atomicServiceFlag = false;
486 startMsg.strictMode = false;
487 startMsg.isolatedExtension = false;
488 startMsg.childProcessType = 1;
489 startMsg.isolationMode = false;
490 std::string provisionType("test_provisionType");
491 startMsg.provisionType = provisionType;
492 std::string processType("test_processType");
493 startMsg.processType = processType;
494 startMsg.maxChildProcess = 1;
495 std::string extensionSandboxPath("test_extensionSandboxPath");
496 startMsg.extensionSandboxPath = extensionSandboxPath;
497
498 auto asc = std::make_shared<AppSpawnClient>(false);
499 int32_t ret = 0;
500 bool result = false;
501 AppSpawnReqMsgHandle reqHandle = nullptr;
502 ret = asc->OpenConnection();
503 EXPECT_EQ(ret, ERR_OK);
504 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
505 EXPECT_EQ(ret, ERR_OK);
506
507 result = asc->VerifyMsg(startMsg);
508 EXPECT_EQ(result, true);
509
510 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_001 end");
511 }
512
513 /**
514 * @tc.name: VerifyMsg_002
515 * @tc.desc: appspawn VerifyMsg
516 * @tc.type: FUNC
517 * @tc.require: issueI5W4S7
518 */
519 HWTEST_F(AppSpawnClientTest, VerifyMsg_002, TestSize.Level0)
520 {
521 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_002 start");
522 AppSpawnStartMsg startMsg = {0};
523 startMsg.uid = -1;
524 startMsg.gid = 2001;
525 startMsg.gids = {1001, 1002, 1003};
526 std::string procName("test_proc_name");
527 startMsg.procName = procName;
528 std::string permission1("permission_for_test_1");
529 std::string permission2("permission_for_test_2");
530 std::string permission3("permission_for_test_3");
531 startMsg.permissions.insert(permission1);
532 startMsg.permissions.insert(permission2);
533 startMsg.permissions.insert(permission3);
534 startMsg.flags = 0x1000;
535 startMsg.atomicServiceFlag = false;
536 startMsg.strictMode = false;
537 startMsg.isolatedExtension = false;
538 startMsg.childProcessType = 1;
539 startMsg.isolationMode = false;
540 std::string provisionType("test_provisionType");
541 startMsg.provisionType = provisionType;
542 std::string processType("test_processType");
543 startMsg.processType = processType;
544 startMsg.maxChildProcess = 1;
545 std::string extensionSandboxPath("test_extensionSandboxPath");
546 startMsg.extensionSandboxPath = extensionSandboxPath;
547
548 auto asc = std::make_shared<AppSpawnClient>(false);
549 int32_t ret = 0;
550 bool result = false;
551 AppSpawnReqMsgHandle reqHandle = nullptr;
552 ret = asc->OpenConnection();
553 EXPECT_EQ(ret, ERR_OK);
554 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
555 EXPECT_EQ(ret, ERR_OK);
556
557 result = asc->VerifyMsg(startMsg);
558 EXPECT_EQ(result, false);
559
560 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_002 end");
561 }
562
563 /**
564 * @tc.name: VerifyMsg_003
565 * @tc.desc: appspawn VerifyMsg
566 * @tc.type: FUNC
567 * @tc.require: issueI5W4S7
568 */
569 HWTEST_F(AppSpawnClientTest, VerifyMsg_003, TestSize.Level0)
570 {
571 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_003 start");
572 AppSpawnStartMsg startMsg = {0};
573 startMsg.uid = 1001;
574 startMsg.gid = -1;
575 startMsg.gids = {1001, 1002, 1003};
576 std::string procName("test_proc_name");
577 startMsg.procName = procName;
578 std::string permission1("permission_for_test_1");
579 std::string permission2("permission_for_test_2");
580 std::string permission3("permission_for_test_3");
581 startMsg.permissions.insert(permission1);
582 startMsg.permissions.insert(permission2);
583 startMsg.permissions.insert(permission3);
584 startMsg.flags = 0x1000;
585 startMsg.atomicServiceFlag = false;
586 startMsg.strictMode = false;
587 startMsg.isolatedExtension = false;
588 startMsg.childProcessType = 1;
589 startMsg.isolationMode = false;
590 std::string provisionType("test_provisionType");
591 startMsg.provisionType = provisionType;
592 std::string processType("test_processType");
593 startMsg.processType = processType;
594 startMsg.maxChildProcess = 1;
595 std::string extensionSandboxPath("test_extensionSandboxPath");
596 startMsg.extensionSandboxPath = extensionSandboxPath;
597
598 auto asc = std::make_shared<AppSpawnClient>(false);
599 int32_t ret = 0;
600 bool result = false;
601 AppSpawnReqMsgHandle reqHandle = nullptr;
602 ret = asc->OpenConnection();
603 EXPECT_EQ(ret, ERR_OK);
604 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
605 EXPECT_EQ(ret, ERR_OK);
606
607 result = asc->VerifyMsg(startMsg);
608 EXPECT_EQ(result, false);
609
610 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_003 end");
611 }
612
613 /**
614 * @tc.name: VerifyMsg_004
615 * @tc.desc: appspawn VerifyMsg
616 * @tc.type: FUNC
617 * @tc.require: issueI5W4S7
618 */
619 HWTEST_F(AppSpawnClientTest, VerifyMsg_004, TestSize.Level0)
620 {
621 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_004 start");
622 AppSpawnStartMsg startMsg = {0};
623 startMsg.uid = 1001;
624 startMsg.gid = 2001;
625 startMsg.gids = {1001, 1002, 1003, -1};
626 std::string procName("test_proc_name");
627 startMsg.procName = procName;
628 std::string permission1("permission_for_test_1");
629 std::string permission2("permission_for_test_2");
630 std::string permission3("permission_for_test_3");
631 startMsg.permissions.insert(permission1);
632 startMsg.permissions.insert(permission2);
633 startMsg.permissions.insert(permission3);
634 startMsg.flags = 0x1000;
635 startMsg.atomicServiceFlag = false;
636 startMsg.strictMode = false;
637 startMsg.isolatedExtension = false;
638 startMsg.childProcessType = 1;
639 startMsg.isolationMode = false;
640 std::string provisionType("test_provisionType");
641 startMsg.provisionType = provisionType;
642 std::string processType("test_processType");
643 startMsg.processType = processType;
644 startMsg.maxChildProcess = 1;
645 std::string extensionSandboxPath("test_extensionSandboxPath");
646 startMsg.extensionSandboxPath = extensionSandboxPath;
647
648 auto asc = std::make_shared<AppSpawnClient>(false);
649 int32_t ret = 0;
650 bool result = false;
651 ret = asc->OpenConnection();
652 EXPECT_EQ(ret, ERR_OK);
653 result = asc->VerifyMsg(startMsg);
654 EXPECT_EQ(result, false);
655
656 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_004 end");
657 }
658
659 /**
660 * @tc.name: VerifyMsg_005
661 * @tc.desc: appspawn VerifyMsg
662 * @tc.type: FUNC
663 * @tc.require: issueI5W4S7
664 */
665 HWTEST_F(AppSpawnClientTest, VerifyMsg_005, TestSize.Level0)
666 {
667 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_005 start");
668 AppSpawnStartMsg startMsg = {0};
669 startMsg.uid = 1001;
670 startMsg.gid = 2001;
671 startMsg.gids = {1001, 1002};
672 std::string procName("");
673 startMsg.procName = procName;
674 std::string permission1("permission_for_test_1");
675 std::string permission2("permission_for_test_2");
676 std::string permission3("permission_for_test_3");
677 startMsg.permissions.insert(permission1);
678 startMsg.permissions.insert(permission2);
679 startMsg.permissions.insert(permission3);
680 startMsg.flags = 0x1000;
681 startMsg.atomicServiceFlag = false;
682 startMsg.strictMode = false;
683 startMsg.isolatedExtension = false;
684 startMsg.childProcessType = 1;
685 startMsg.isolationMode = false;
686 std::string provisionType("test_provisionType");
687 startMsg.provisionType = provisionType;
688 std::string processType("test_processType");
689 startMsg.processType = processType;
690 startMsg.maxChildProcess = 1;
691 std::string extensionSandboxPath("test_extensionSandboxPath");
692 startMsg.extensionSandboxPath = extensionSandboxPath;
693
694 auto asc = std::make_shared<AppSpawnClient>(false);
695 int32_t ret = 0;
696 bool result = false;
697 ret = asc->OpenConnection();
698 EXPECT_EQ(ret, ERR_OK);
699 result = asc->VerifyMsg(startMsg);
700 EXPECT_EQ(result, false);
701
702 TAG_LOGI(AAFwkTag::TEST, "VerifyMsg_005 end");
703 }
704
705 /**
706 * @tc.name: SetChildProcessTypeStartFlag_001
707 * @tc.desc: appspawn SetChildProcessTypeStartFlag
708 * @tc.type: FUNC
709 * @tc.require: issueI5W4S7
710 */
711 HWTEST_F(AppSpawnClientTest, SetChildProcessTypeStartFlag_001, TestSize.Level0)
712 {
713 TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_001 start");
714 AppSpawnStartMsg startMsg = {0};
715 std::string procName("test_proc_name");
716 startMsg.procName = procName;
717 int32_t childProcessType = 1;
718 auto asc = std::make_shared<AppSpawnClient>(false);
719 int32_t ret = 0;
720 AppSpawnReqMsgHandle reqHandle = nullptr;
721 ret = asc->OpenConnection();
722 EXPECT_EQ(ret, ERR_OK);
723 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
724 EXPECT_EQ(ret, ERR_OK);
725 ret = asc->SetChildProcessTypeStartFlag(reqHandle, childProcessType);
726 EXPECT_EQ(ret, ERR_OK);
727 TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_001 end");
728 }
729
730 /**
731 * @tc.name: SetChildProcessTypeStartFlag_002
732 * @tc.desc: appspawn SetChildProcessTypeStartFlag
733 * @tc.type: FUNC
734 * @tc.require: issueI5W4S7
735 */
736 HWTEST_F(AppSpawnClientTest, SetChildProcessTypeStartFlag_002, TestSize.Level0)
737 {
738 TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_002 start");
739 AppSpawnStartMsg startMsg = {0};
740 std::string procName("test_proc_name");
741 startMsg.procName = procName;
742 int32_t childProcessType = -1;
743 auto asc = std::make_shared<AppSpawnClient>(false);
744 int32_t ret = 0;
745 AppSpawnReqMsgHandle reqHandle = nullptr;
746 ret = asc->OpenConnection();
747 EXPECT_EQ(ret, ERR_OK);
748 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
749 EXPECT_EQ(ret, ERR_OK);
750 ret = asc->SetChildProcessTypeStartFlag(reqHandle, childProcessType);
751 EXPECT_EQ(ret, ERR_OK);
752 TAG_LOGI(AAFwkTag::TEST, "SetChildProcessTypeStartFlag_002 end");
753 }
754
755 /**
756 * @tc.name: SetExtMsgFds_001
757 * @tc.desc: appspawn SetExtMsgFds
758 * @tc.type: FUNC
759 * @tc.require: issueI5W4S7
760 */
761 HWTEST_F(AppSpawnClientTest, SetExtMsgFds_001, TestSize.Level0)
762 {
763 TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_001 start");
764 AppSpawnStartMsg startMsg = {0};
765 std::string procName("test_proc_name");
766 startMsg.procName = procName;
767 startMsg.fds.emplace("test_fd1", 100);
768 startMsg.fds.emplace("test_fd2", 101);
769 startMsg.fds.emplace("test_fd3", 102);
770
771 auto asc = std::make_shared<AppSpawnClient>(false);
772 int32_t ret = 0;
773 AppSpawnReqMsgHandle reqHandle = nullptr;
774 ret = asc->OpenConnection();
775 EXPECT_EQ(ret, ERR_OK);
776 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
777 EXPECT_EQ(ret, ERR_OK);
778 ret = asc->SetExtMsgFds(reqHandle, startMsg.fds);
779 EXPECT_EQ(ret, ERR_OK);
780 TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_001 end");
781 }
782
783 /**
784 * @tc.name: SetExtMsgFds_002
785 * @tc.desc: appspawn SetExtMsgFds
786 * @tc.type: FUNC
787 * @tc.require: issueI5W4S7
788 */
789 HWTEST_F(AppSpawnClientTest, SetExtMsgFds_002, TestSize.Level0)
790 {
791 TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_002 start");
792 AppSpawnStartMsg startMsg = {0};
793 std::string procName("test_proc_name");
794 startMsg.procName = procName;
795 startMsg.fds.emplace("test_fd1", 100);
796 startMsg.fds.emplace("test_fd2", 101);
797 startMsg.fds.emplace("test_fd3", -1);
798 auto asc = std::make_shared<AppSpawnClient>(false);
799 int32_t ret = 0;
800 AppSpawnReqMsgHandle reqHandle = nullptr;
801 ret = asc->OpenConnection();
802 EXPECT_EQ(ret, ERR_OK);
803 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
804 EXPECT_EQ(ret, ERR_OK);
805 ret = asc->SetExtMsgFds(reqHandle, startMsg.fds);
806 EXPECT_NE(ret, ERR_OK);
807 TAG_LOGI(AAFwkTag::TEST, "SetExtMsgFds_002 end");
808 }
809
810 /**
811 * @tc.name: SetIsolationModeFlag_001
812 * @tc.desc: appspawn SetIsolationModeFlag
813 * @tc.type: FUNC
814 * @tc.require: issueI5W4S7
815 */
816 HWTEST_F(AppSpawnClientTest, SetIsolationModeFlag_001, TestSize.Level0)
817 {
818 TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_001 start");
819 AppSpawnStartMsg startMsg = {0};
820 std::string procName("test_proc_name");
821 startMsg.procName = procName;
822 startMsg.isolationMode = true;
823 auto asc = std::make_shared<AppSpawnClient>(false);
824 int32_t ret = 0;
825 AppSpawnReqMsgHandle reqHandle = nullptr;
826 ret = asc->OpenConnection();
827 EXPECT_EQ(ret, ERR_OK);
828 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
829 EXPECT_EQ(ret, ERR_OK);
830 ret = asc->SetIsolationModeFlag(startMsg, reqHandle);
831 EXPECT_EQ(ret, ERR_OK);
832 TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_001 end");
833 }
834
835 /**
836 * @tc.name: SetIsolationModeFlag_002
837 * @tc.desc: appspawn SetIsolationModeFlag
838 * @tc.type: FUNC
839 * @tc.require: issueI5W4S7
840 */
841 HWTEST_F(AppSpawnClientTest, SetIsolationModeFlag_002, TestSize.Level0)
842 {
843 TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_002 start");
844 AppSpawnStartMsg startMsg = {0};
845 std::string procName("test_proc_name");
846 startMsg.procName = procName;
847 startMsg.isolationMode = false;
848 auto asc = std::make_shared<AppSpawnClient>(false);
849 int32_t ret = 0;
850 AppSpawnReqMsgHandle reqHandle = nullptr;
851 ret = asc->OpenConnection();
852 EXPECT_EQ(ret, ERR_OK);
853 ret = AppSpawnReqMsgCreate(static_cast<AppSpawnMsgType>(startMsg.code), startMsg.procName.c_str(), &reqHandle);
854 EXPECT_EQ(ret, ERR_OK);
855 ret = asc->SetIsolationModeFlag(startMsg, reqHandle);
856 EXPECT_EQ(ret, ERR_OK);
857 TAG_LOGI(AAFwkTag::TEST, "SetIsolationModeFlag_002 end");
858 }
859
860
861 /**
862 * @tc.name: StartProcess_001
863 * @tc.desc: appspawn StartProcess
864 * @tc.type: FUNC
865 * @tc.require: issueI5W4S7
866 */
867 HWTEST_F(AppSpawnClientTest, StartProcess_001, TestSize.Level0)
868 {
869 TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 start");
870 AppSpawnStartMsg startMsg = {0};
871 startMsg.uid = 1001;
872 startMsg.gid = 2001;
873 startMsg.gids = {1001, 1002, 1003};
874 std::string procName("test_proc_name");
875 startMsg.procName = procName;
876 std::string permission1("permission_for_test_1");
877 std::string permission2("permission_for_test_2");
878 std::string permission3("permission_for_test_3");
879 startMsg.permissions.insert(permission1);
880 startMsg.permissions.insert(permission2);
881 startMsg.permissions.insert(permission3);
882 startMsg.flags = 0x1000;
883 startMsg.atomicServiceFlag = false;
884 startMsg.strictMode = false;
885 startMsg.isolatedExtension = false;
886 startMsg.childProcessType = 1;
887 startMsg.isolationMode = false;
888 std::string provisionType("test_provisionType");
889 startMsg.provisionType = provisionType;
890 std::string processType("test_processType");
891 startMsg.processType = processType;
892 startMsg.maxChildProcess = 1;
893 std::string extensionSandboxPath("test_extensionSandboxPath");
894 startMsg.extensionSandboxPath = extensionSandboxPath;
895
896 int32_t ret = 0;
897 auto asc = std::make_shared<AppSpawnClient>(false);
898 pid_t pid = 0;
899 ret = asc->StartProcess(startMsg, pid);
900 EXPECT_NE(ret, ERR_OK);
901
902 TAG_LOGI(AAFwkTag::TEST, "StartProcess_001 end");
903 }
904
905 /**
906 * @tc.name: StartProcess_002
907 * @tc.desc: appspawn StartProcess
908 * @tc.type: FUNC
909 * @tc.require: issueI5W4S7
910 */
911 HWTEST_F(AppSpawnClientTest, StartProcess_002, TestSize.Level0)
912 {
913 TAG_LOGI(AAFwkTag::TEST, "StartProcess_002 start");
914 AppSpawnStartMsg startMsg = {0};
915 startMsg.uid = 1001;
916 startMsg.gid = 2001;
917 startMsg.gids = {1001, 1002, 1003, -1};
918 std::string procName("test_proc_name");
919 startMsg.procName = procName;
920 std::string permission1("permission_for_test_1");
921 std::string permission2("permission_for_test_2");
922 std::string permission3("permission_for_test_3");
923 startMsg.permissions.insert(permission1);
924 startMsg.permissions.insert(permission2);
925 startMsg.permissions.insert(permission3);
926 startMsg.flags = 0x1000;
927 startMsg.atomicServiceFlag = false;
928 startMsg.strictMode = false;
929 startMsg.isolatedExtension = false;
930 startMsg.childProcessType = 1;
931 startMsg.isolationMode = false;
932 std::string provisionType("test_provisionType");
933 startMsg.provisionType = provisionType;
934 std::string processType("test_processType");
935 startMsg.processType = processType;
936 startMsg.maxChildProcess = 1;
937 std::string extensionSandboxPath("test_extensionSandboxPath");
938 startMsg.extensionSandboxPath = extensionSandboxPath;
939
940 int32_t ret = 0;
941 auto asc = std::make_shared<AppSpawnClient>(false);
942 pid_t pid = 0;
943 ret = asc->StartProcess(startMsg, pid);
944 EXPECT_NE(ret, ERR_OK);
945
946 TAG_LOGI(AAFwkTag::TEST, "StartProcess_002 end");
947 }
948
949 /**
950 * @tc.name: DumpJITPermissionListToJson_001
951 * @tc.desc: appspawn client DumpJITPermissionListToJson_001
952 * @tc.type: FUNC
953 */
954 HWTEST_F(AppSpawnClientTest, DumpJITPermissionListToJson_001, TestSize.Level0)
955 {
956 std::map<std::string, std::string> jitPermissionsMap = {
957 {"ohos.permission.jit1", "1"}, {"ohos.permission.jit2", "{\"cont\": \"1\"}"}
958 };
959 std::string jsonJITPermissions = DumpJITPermissionListToJson(jitPermissionsMap);
960
961 size_t pos = jsonJITPermissions.find("ohos.permission.jit1");
962 ASSERT_NE(pos, std::string::npos);
963 pos = jsonJITPermissions.find("ohos.permission.jit2");
964 ASSERT_NE(pos, std::string::npos);
965 }
966
967 /**
968 * @tc.name: SendAppSpawnUninstallDebugHapMsg_001
969 * @tc.desc: SendAppSpawnUninstallDebugHapMsg
970 * @tc.type: FUNC
971 */
972 HWTEST_F(AppSpawnClientTest, SendAppSpawnUninstallDebugHapMsg_001, TestSize.Level0)
973 {
974 auto appSpawnClient = std::make_shared<AppSpawnClient>(false);
975 int32_t userId = 0;
976 auto ret = appSpawnClient->SendAppSpawnUninstallDebugHapMsg(userId);
977 ASSERT_EQ(ret, ERR_OK);
978 }
979 } // namespace AppExecFwk
980 } // namespace OHOS
981