1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "test.h"
16 #include "namespace.h"
17 #include "functionalext.h"
18
19 typedef void (*TEST_FUN)(void);
20
21 struct dso {
22 char* name;
23 };
24
25 /**
26 * @tc.name : namespace_test_0010
27 * @tc.desc : ns_free test arg is null
28 * @tc.level : Level 2
29 */
namespace_test_0010(void)30 static void namespace_test_0010(void)
31 {
32 ns_free(NULL);
33 EXPECT_TRUE(__FUNCTION__, true);
34 }
35
36 /**
37 * @tc.name : namespace_test_0020
38 * @tc.desc : ns_free test normal condition
39 * @tc.level : Level 0
40 */
namespace_test_0020(void)41 static void namespace_test_0020(void)
42 {
43 ns_t ns;
44 int tmp = 1;
45 ns.ns_dsos = (dsolist*)&tmp;
46 ns.ns_name = (char*)&tmp;
47 ns.env_paths = (char*)&tmp;
48 ns.lib_paths = (char*)&tmp;
49 ns.asan_lib_paths = (char*)&tmp;
50 ns.permitted_paths = NULL;
51 ns.asan_permitted_paths = NULL;
52 ns.allowed_libs = NULL;
53 ns_inherit_list list;
54 list.num = 1;
55 ns_inherit inherit;
56 inherit.shared_libs = NULL;
57 ns_inherit* pInherit = &inherit;
58 list.inherits = &pInherit;
59 ns.ns_inherits = &list;
60
61 ns_free(&ns);
62 EXPECT_TRUE(__FUNCTION__, true);
63 }
64
65 /**
66 * @tc.name : namespace_test_0030
67 * @tc.desc : ns_free test arg ns's memebers are NULL
68 * @tc.level : Level 2
69 */
namespace_test_0030(void)70 static void namespace_test_0030(void)
71 {
72 ns_t ns;
73 ns.ns_dsos = NULL;
74 ns.ns_name = NULL;
75 ns.env_paths = NULL;
76 ns.lib_paths = NULL;
77 ns.asan_lib_paths = NULL;
78 ns.permitted_paths = NULL;
79 ns.asan_permitted_paths = NULL;
80 ns.allowed_libs = NULL;
81 ns.ns_inherits = NULL;
82
83 ns_free(&ns);
84 EXPECT_TRUE(__FUNCTION__, true);
85 }
86
87 /**
88 * @tc.name : namespace_test_0040
89 * @tc.desc : ns_add_dso test args are NULL
90 * @tc.level : Level 2
91 */
namespace_test_0040(void)92 static void namespace_test_0040(void)
93 {
94 ns_add_dso(NULL, NULL);
95 EXPECT_TRUE(__FUNCTION__, true);
96 }
97
98 /**
99 * @tc.name : namespace_test_0050
100 * @tc.desc : ns_add_dso test arg dso is NULL
101 * @tc.level : Level 2
102 */
namespace_test_0050(void)103 static void namespace_test_0050(void)
104 {
105 ns_t ns;
106 ns_add_dso(&ns, NULL);
107 EXPECT_TRUE(__FUNCTION__, true);
108 }
109
110 /**
111 * @tc.name : namespace_test_0060
112 * @tc.desc : ns_add_dso test arg ns is NULL
113 * @tc.level : Level 2
114 */
namespace_test_0060(void)115 static void namespace_test_0060(void)
116 {
117 struct dso d;
118 ns_add_dso(NULL, &d);
119 EXPECT_TRUE(__FUNCTION__, true);
120 }
121
122 /**
123 * @tc.name : namespace_test_0070
124 * @tc.desc : ns_add_dso test normal condition
125 * @tc.level : Level 1
126 */
namespace_test_0070(void)127 static void namespace_test_0070(void)
128 {
129 ns_t ns;
130 struct dso d;
131 dsolist list;
132 list.num = 1;
133 list.size = 1;
134 ns.ns_dsos = &list;
135 ns_add_dso(&ns, &d);
136 EXPECT_EQ(__FUNCTION__, list.size, 2);
137 }
138
139 /**
140 * @tc.name : namespace_test_0080
141 * @tc.desc : nslist_add_ns test many times
142 * @tc.level : Level 1
143 */
namespace_test_0080(void)144 static void namespace_test_0080(void)
145 {
146 ns_t ns;
147 nslist_add_ns(&ns);
148 nslist_add_ns(&ns);
149 nslist_add_ns(&ns);
150 nslist_add_ns(&ns);
151 nslist_add_ns(&ns);
152 nslist_add_ns(&ns);
153 nslist_add_ns(&ns);
154 nslist_add_ns(&ns);
155 nslist_add_ns(&ns);
156 nslist_add_ns(&ns);
157 nslist_add_ns(&ns);
158 nslist_add_ns(&ns);
159 nslist_add_ns(&ns);
160 nslist_add_ns(&ns);
161 nslist_add_ns(&ns);
162 nslist_add_ns(&ns);
163 nslist_add_ns(&ns);
164 EXPECT_TRUE(__FUNCTION__, true);
165 }
166
167 /**
168 * @tc.name : namespace_test_0090
169 * @tc.desc : nslist_add_ns test arg is NULL
170 * @tc.level : Level 2
171 */
namespace_test_0090(void)172 static void namespace_test_0090(void)
173 {
174 nslist_add_ns(NULL);
175 EXPECT_TRUE(__FUNCTION__, true);
176 }
177
178 /**
179 * @tc.name : namespace_test_0100
180 * @tc.desc : ns_set_name test args are NULL
181 * @tc.level : Level 2
182 */
namespace_test_0100(void)183 static void namespace_test_0100(void)
184 {
185 ns_set_name(NULL, NULL);
186 EXPECT_TRUE(__FUNCTION__, true);
187 }
188
189 /**
190 * @tc.name : namespace_test_0110
191 * @tc.desc : ns_set_name test arg name is NULL
192 * @tc.level : Level 2
193 */
namespace_test_0110(void)194 static void namespace_test_0110(void)
195 {
196 ns_t ns;
197 ns_set_name(&ns, NULL);
198 EXPECT_TRUE(__FUNCTION__, true);
199 }
200
201 /**
202 * @tc.name : namespace_test_0120
203 * @tc.desc : ns_set_name test arg ns is NULL
204 * @tc.level : Level 2
205 */
namespace_test_0120(void)206 static void namespace_test_0120(void)
207 {
208 ns_set_name(NULL, "abc");
209 EXPECT_TRUE(__FUNCTION__, true);
210 }
211
212 /**
213 * @tc.name : namespace_test_0130
214 * @tc.desc : ns_set_env_paths test arg ns is NULL
215 * @tc.level : Level 2
216 */
namespace_test_0130(void)217 static void namespace_test_0130(void)
218 {
219 ns_set_env_paths(NULL, "abc");
220 EXPECT_TRUE(__FUNCTION__, true);
221 }
222
223 /**
224 * @tc.name : namespace_test_0140
225 * @tc.desc : ns_set_env_paths test arg ns.env_paths is NULL
226 * @tc.level : Level 1
227 */
namespace_test_0140(void)228 static void namespace_test_0140(void)
229 {
230 ns_t ns;
231 ns.env_paths = NULL;
232 ns_set_env_paths(&ns, "abc");
233 EXPECT_EQ(__FUNCTION__, strcmp(ns.env_paths, "abc"), 0);
234 }
235
236 /**
237 * @tc.name : namespace_test_0150
238 * @tc.desc : ns_set_env_paths test arg ns.env_paths is equal to arg name
239 * @tc.level : Level 1
240 */
namespace_test_0150(void)241 static void namespace_test_0150(void)
242 {
243 ns_t ns;
244 ns.env_paths = "abc";
245 ns_set_env_paths(&ns, "abc");
246 EXPECT_EQ(__FUNCTION__, strcmp(ns.env_paths, "abc"), 0);
247 }
248
249 /**
250 * @tc.name : namespace_test_0160
251 * @tc.desc : ns_set_env_paths test arg name is NULL and ns.env_paths is NULL
252 * @tc.level : Level 2
253 */
namespace_test_0160(void)254 static void namespace_test_0160(void)
255 {
256 ns_t ns;
257 ns.env_paths = NULL;
258 ns_set_env_paths(&ns, NULL);
259 EXPECT_EQ(__FUNCTION__, ns.env_paths, NULL);
260 }
261
262 /**
263 * @tc.name : namespace_test_0170
264 * @tc.desc : ns_set_env_paths test arg name is NULL and ns.env_paths is not NULL
265 * @tc.level : Level 2
266 */
namespace_test_0170(void)267 static void namespace_test_0170(void)
268 {
269 ns_t ns;
270 ns.env_paths = "abc";
271 ns_set_env_paths(&ns, NULL);
272 EXPECT_EQ(__FUNCTION__, ns.env_paths, NULL);
273 }
274
275 /**
276 * @tc.name : namespace_test_0180
277 * @tc.desc : ns_set_asan_lib_paths test arg ns is NULL
278 * @tc.level : Level 2
279 */
namespace_test_0180(void)280 static void namespace_test_0180(void)
281 {
282 ns_set_asan_lib_paths(NULL, "abc");
283 EXPECT_TRUE(__FUNCTION__, true);
284 }
285
286 /**
287 * @tc.name : namespace_test_0190
288 * @tc.desc : ns_set_asan_lib_paths test arg ns.asan_lib_paths is NULL
289 * @tc.level : Level 1
290 */
namespace_test_0190(void)291 static void namespace_test_0190(void)
292 {
293 ns_t ns;
294 ns.asan_lib_paths = NULL;
295 ns_set_asan_lib_paths(&ns, "abc");
296 EXPECT_EQ(__FUNCTION__, strcmp(ns.asan_lib_paths, "abc"), 0);
297 }
298
299 /**
300 * @tc.name : namespace_test_0200
301 * @tc.desc : ns_set_asan_lib_paths test arg ns.asan_lib_paths is equal to arg name
302 * @tc.level : Level 1
303 */
namespace_test_0200(void)304 static void namespace_test_0200(void)
305 {
306 ns_t ns;
307 ns.asan_lib_paths = "abc";
308 ns_set_asan_lib_paths(&ns, "abc");
309 EXPECT_EQ(__FUNCTION__, strcmp(ns.asan_lib_paths, "abc"), 0);
310 }
311
312 /**
313 * @tc.name : namespace_test_0210
314 * @tc.desc : ns_set_asan_lib_paths test arg name is NULL and ns.asan_lib_paths is NULL
315 * @tc.level : Level 2
316 */
namespace_test_0210(void)317 static void namespace_test_0210(void)
318 {
319 ns_t ns;
320 ns.asan_lib_paths = NULL;
321 ns_set_asan_lib_paths(&ns, NULL);
322 EXPECT_EQ(__FUNCTION__, ns.asan_lib_paths, NULL);
323 }
324
325 /**
326 * @tc.name : namespace_test_0220
327 * @tc.desc : ns_set_asan_lib_paths test arg name is NULL and ns.asan_lib_paths is not NULL
328 * @tc.level : Level 1
329 */
namespace_test_0220(void)330 static void namespace_test_0220(void)
331 {
332 ns_t ns;
333 ns.asan_lib_paths = "abc";
334 ns_set_asan_lib_paths(&ns, NULL);
335 EXPECT_EQ(__FUNCTION__, ns.asan_lib_paths, NULL);
336 }
337
338 /**
339 * @tc.name : namespace_test_0230
340 * @tc.desc : ns_set_permitted_paths test arg permitted_paths is NULL and ns.permitted_paths is not NULL
341 * @tc.level : Level 1
342 */
namespace_test_0230(void)343 static void namespace_test_0230(void)
344 {
345 ns_t ns;
346 strlist list;
347 ns.permitted_paths = &list;
348 ns_set_permitted_paths(&ns, NULL);
349 EXPECT_EQ(__FUNCTION__, ns.permitted_paths, NULL);
350 }
351
352 /**
353 * @tc.name : namespace_test_0240
354 * @tc.desc : ns_set_permitted_paths test args are NULL
355 * @tc.level : Level 2
356 */
namespace_test_0240(void)357 static void namespace_test_0240(void)
358 {
359 ns_set_permitted_paths(NULL, NULL);
360 EXPECT_TRUE(__FUNCTION__, true);
361 }
362
363 /**
364 * @tc.name : namespace_test_0250
365 * @tc.desc : ns_set_permitted_paths test arg permitted_paths is NULL and ns.permitted_paths is NULL
366 * @tc.level : Level 2
367 */
namespace_test_0250(void)368 static void namespace_test_0250(void)
369 {
370 ns_t ns;
371 ns.permitted_paths = NULL;
372 ns_set_permitted_paths(&ns, NULL);
373 EXPECT_EQ(__FUNCTION__, ns.permitted_paths, NULL);
374 }
375
376 /**
377 * @tc.name : namespace_test_0260
378 * @tc.desc : ns_set_asan_permitted_paths test arg asan_permitted_paths is NULL and ns.asan_permitted_paths is not NULL
379 * @tc.level : Level 1
380 */
namespace_test_0260(void)381 static void namespace_test_0260(void)
382 {
383 ns_t ns;
384 strlist list;
385 ns.asan_permitted_paths = &list;
386 ns_set_asan_permitted_paths(&ns, NULL);
387 EXPECT_EQ(__FUNCTION__, ns.asan_permitted_paths, NULL);
388 }
389
390 /**
391 * @tc.name : namespace_test_0270
392 * @tc.desc : ns_set_asan_permitted_paths test args are NULL
393 * @tc.level : Level 2
394 */
namespace_test_0270(void)395 static void namespace_test_0270(void)
396 {
397 ns_set_asan_permitted_paths(NULL, NULL);
398 EXPECT_TRUE(__FUNCTION__, true);
399 }
400
401 /**
402 * @tc.name : namespace_test_0280
403 * @tc.desc : ns_set_asan_permitted_paths test arg asan_permitted_paths is NULL and ns.asan_permitted_paths is NULL
404 * @tc.level : Level 1
405 */
namespace_test_0280(void)406 static void namespace_test_0280(void)
407 {
408 ns_t ns;
409 ns.asan_permitted_paths = NULL;
410 ns_set_asan_permitted_paths(&ns, NULL);
411 EXPECT_EQ(__FUNCTION__, ns.asan_permitted_paths, NULL);
412 }
413
414 /**
415 * @tc.name : namespace_test_0290
416 * @tc.desc : ns_set_separated test arg ns is NULL and separated is false
417 * @tc.level : Level 2
418 */
namespace_test_0290(void)419 static void namespace_test_0290(void)
420 {
421 ns_set_separated(NULL, false);
422 EXPECT_TRUE(__FUNCTION__, true);
423 }
424
425 /**
426 * @tc.name : namespace_test_0300
427 * @tc.desc : ns_set_allowed_libs test arg ns is NULL
428 * @tc.level : Level 2
429 */
namespace_test_0300(void)430 static void namespace_test_0300(void)
431 {
432 ns_set_allowed_libs(NULL, "abc");
433 EXPECT_TRUE(__FUNCTION__, true);
434 }
435
436 /**
437 * @tc.name : namespace_test_0310
438 * @tc.desc : ns_set_allowed_libs test arg ns is ns.allowed_libs NULL
439 * @tc.level : Level 1
440 */
namespace_test_0310(void)441 static void namespace_test_0310(void)
442 {
443 ns_t ns;
444 ns.allowed_libs = NULL;
445 ns_set_allowed_libs(&ns, "abc");
446 EXPECT_EQ(__FUNCTION__, (ns.allowed_libs != NULL), true);
447 }
448
449 /**
450 * @tc.name : namespace_test_0320
451 * @tc.desc : ns_set_allowed_libs test normal condition
452 * @tc.level : Level 0
453 */
namespace_test_0320(void)454 static void namespace_test_0320(void)
455 {
456 ns_t ns;
457 strlist list;
458 ns.allowed_libs = &list;
459 ns_set_allowed_libs(&ns, "abc");
460 EXPECT_EQ(__FUNCTION__, (ns.allowed_libs != NULL), true);
461 }
462
463 /**
464 * @tc.name : namespace_test_0330
465 * @tc.desc : ns_set_allowed_libs test allowed_libs is NULL and ns.allowed_libs is NULL
466 * @tc.level : Level 1
467 */
namespace_test_0330(void)468 static void namespace_test_0330(void)
469 {
470 ns_t ns;
471 ns.allowed_libs = NULL;
472 ns_set_allowed_libs(&ns, NULL);
473 EXPECT_EQ(__FUNCTION__, ns.allowed_libs, NULL);
474 }
475
476 /**
477 * @tc.name : namespace_test_0400
478 * @tc.desc : ns_set_allowed_libs test allowed_libs is NULL and ns.allowed_libs is not NULL
479 * @tc.level : Level 1
480 */
namespace_test_0400(void)481 static void namespace_test_0400(void)
482 {
483 ns_t ns;
484 strlist list;
485 ns.allowed_libs = &list;
486 ns_set_allowed_libs(&ns, NULL);
487 EXPECT_EQ(__FUNCTION__, ns.allowed_libs, NULL);
488 }
489
490 /**
491 * @tc.name : namespace_test_0340
492 * @tc.desc : ns_add_inherit test arg ns_inherited and shared_libs are NULL
493 * @tc.level : Level 2
494 */
namespace_test_0340(void)495 static void namespace_test_0340(void)
496 {
497 ns_t ns;
498 ns_add_inherit(&ns, NULL, NULL);
499 EXPECT_TRUE(__FUNCTION__, true);
500 }
501
502 /**
503 * @tc.name : namespace_test_0350
504 * @tc.desc : ns_add_inherit test args are NULL
505 * @tc.level : Level 2
506 */
namespace_test_0350(void)507 static void namespace_test_0350(void)
508 {
509
510 ns_add_inherit(NULL, NULL, NULL);
511 EXPECT_TRUE(__FUNCTION__, true);
512 }
513
514 /**
515 * @tc.name : namespace_test_0360
516 * @tc.desc : ns_add_inherit test arg ns and shared_libs are NULL
517 * @tc.level : Level 2
518 */
namespace_test_0360(void)519 static void namespace_test_0360(void)
520 {
521 ns_t ns;
522 ns_add_inherit(NULL, &ns, NULL);
523 EXPECT_TRUE(__FUNCTION__, true);
524 }
525
526 /**
527 * @tc.name : namespace_test_0370
528 * @tc.desc : is_accessible test arg lib_pathname is NULL
529 * @tc.level : Level 1
530 */
namespace_test_0370(void)531 static void namespace_test_0370(void)
532 {
533 ns_t ns;
534 ns.separated = true;
535 bool ret = is_accessible(&ns, NULL , true, true);
536 EXPECT_EQ(__FUNCTION__, ret, false);
537 }
538
539 /**
540 * @tc.name : namespace_test_0380
541 * @tc.desc : is_accessible test args is (&ns, NULL, true, false) and ns.separated is false
542 * @tc.level : Level 2
543 */
namespace_test_0380(void)544 static void namespace_test_0380(void)
545 {
546 ns_t ns;
547 ns.separated = false;
548 bool ret = is_accessible(&ns, NULL, true, false);
549 EXPECT_EQ(__FUNCTION__, ret, false);
550 }
551
552 /**
553 * @tc.name : namespace_test_0390
554 * @tc.desc : is_accessible test args is (&ns, "/data/test.so", true, false) and ns.separated is false
555 * @tc.level : Level 2
556 */
namespace_test_0390(void)557 static void namespace_test_0390(void)
558 {
559 ns_t ns;
560 ns.separated = false;
561 strlist list;
562 list.num = 1;
563 char *name = "test.so";
564 list.strs = &name;
565
566 ns.allowed_libs = &list;
567 ns.env_paths = NULL;
568 ns.lib_paths = NULL;
569 ns.asan_lib_paths = NULL;
570 ns.asan_permitted_paths = NULL;
571 ns.permitted_paths = NULL;
572 bool ret = is_accessible(&ns, "/data/test.so", true, false);
573 EXPECT_EQ(__FUNCTION__, ret, false);
574 }
575
576 /**
577 * @tc.name : namespace_test_0410
578 * @tc.desc : is_sharable test args are NULL
579 * @tc.level : Level 1
580 */
namespace_test_0410(void)581 static void namespace_test_0410(void)
582 {
583 bool ret = is_sharable(NULL, NULL);
584 EXPECT_EQ(__FUNCTION__, ret, true);
585 }
586
587 /**
588 * @tc.name : namespace_test_0420
589 * @tc.desc : is_sharable test args lib_name are NULL
590 * @tc.level : Level 1
591 */
namespace_test_0420(void)592 void namespace_test_0420(void)
593 {
594 ns_inherit ns;
595 bool ret = is_sharable(&ns, NULL);
596 EXPECT_EQ(__FUNCTION__, ret, true);
597 }
598
599 /**
600 * @tc.name : namespace_test_0440
601 * @tc.desc : is_sharable test args shared_libs are NULL
602 * @tc.level : Level 1
603 */
namespace_test_0440(void)604 void namespace_test_0440(void)
605 {
606 ns_inherit ns;
607 ns.shared_libs = NULL;
608 bool ret = is_sharable(&ns, "lib.so");
609 EXPECT_EQ(__FUNCTION__, ret, true);
610 }
611
612 /**
613 * @tc.name : namespace_test_0450
614 * @tc.desc : is_accessible test args allowed_libs are NULL
615 * @tc.level : Level 2
616 */
namespace_test_0450(void)617 void namespace_test_0450(void)
618 {
619 ns_t ns;
620 ns.separated = false;
621 ns.allowed_libs = NULL;
622 bool ret = is_accessible(&ns, "/data/test.so", true, false);
623 EXPECT_EQ(__FUNCTION__, ret, false);
624 }
625
626 /**
627 * @tc.name : namespace_test_0460
628 * @tc.desc : is_accessible test args allowed_libs are not NULL
629 * @tc.level : Level 2
630 */
namespace_test_0460(void)631 void namespace_test_0460(void)
632 {
633 ns_t ns;
634 ns.separated = false;
635 strlist list;
636 list.num = 0;
637 ns.allowed_libs = &list;
638 ns.env_paths = NULL;
639 ns.lib_paths = NULL;
640 ns.asan_lib_paths = NULL;
641 ns.asan_permitted_paths = NULL;
642 ns.permitted_paths = NULL;
643 bool ret = is_accessible(&ns, "test.so", true, false);
644 EXPECT_EQ(__FUNCTION__, ret, false);
645 }
646
647 /**
648 * @tc.name : namespace_test_0470
649 * @tc.desc : is_accessible test args env_paths are not NULL
650 * @tc.level : Level 2
651 */
namespace_test_0470(void)652 void namespace_test_0470(void)
653 {
654 ns_t ns;
655 ns.separated = false;
656 ns.allowed_libs = NULL;
657 ns.env_paths = "/data/tests:/etc";
658 ns.lib_paths = NULL;
659 ns.asan_lib_paths = NULL;
660 ns.asan_permitted_paths = NULL;
661 ns.permitted_paths = NULL;
662 bool ret = is_accessible(&ns, "/data/abc/", true, false);
663 EXPECT_EQ(__FUNCTION__, ret, false);
664 }
665
666 /**
667 * @tc.name : namespace_test_0480
668 * @tc.desc : is_accessible test param is NULL
669 * @tc.level : Level 2
670 */
namespace_test_0480(void)671 void namespace_test_0480(void)
672 {
673 ns_t ns;
674 ns.separated = false;
675 ns.allowed_libs = NULL;
676 ns.env_paths = NULL;
677 ns.lib_paths = NULL;
678 ns.asan_lib_paths = NULL;
679 ns.asan_permitted_paths = NULL;
680 ns.permitted_paths = NULL;
681 bool ret = is_accessible(&ns, "/data/test.so", true, false);
682
683 ns.env_paths = "";
684 EXPECT_EQ(__FUNCTION__, ret, false);
685 }
686
687 /**
688 * @tc.name : namespace_test_0490
689 * @tc.desc : is_accessible test env_paths is matching
690 * @tc.level : Level 1
691 */
namespace_test_0490(void)692 void namespace_test_0490(void)
693 {
694 ns_t ns;
695 ns.separated = false;
696 ns.allowed_libs = NULL;
697 ns.env_paths = "/data/test:/etc";
698 ns.lib_paths = NULL;
699 ns.asan_lib_paths = NULL;
700 ns.asan_permitted_paths = NULL;
701 ns.permitted_paths = NULL;
702 bool ret = is_accessible(&ns, "/data/test/", true, false);
703
704 EXPECT_EQ(__FUNCTION__, ret, true);
705 }
706
707 /**
708 * @tc.name : namespace_test_0500
709 * @tc.desc : is_accessible test env_paths is not matching
710 * @tc.level : Level 2
711 */
namespace_test_0500(void)712 void namespace_test_0500(void)
713 {
714 ns_t ns;
715 ns.separated = false;
716 ns.allowed_libs = NULL;
717 ns.env_paths = "/data/test:/etc";
718 ns.lib_paths = NULL;
719 ns.asan_lib_paths = NULL;
720 ns.asan_permitted_paths = NULL;
721 ns.permitted_paths = NULL;
722 bool ret = is_accessible(&ns, "/data/test", true, false);
723
724 EXPECT_EQ(__FUNCTION__, ret, false);
725 }
726
727 /**
728 * @tc.name : namespace_test_0510
729 * @tc.desc : is_accessible test env_paths is not matching
730 * @tc.level : Level 2
731 */
namespace_test_0510(void)732 void namespace_test_0510(void)
733 {
734 ns_t ns;
735 ns.separated = false;
736 ns.allowed_libs = NULL;
737 ns.env_paths = "/data/test:/etc";
738 ns.lib_paths = NULL;
739 ns.asan_lib_paths = NULL;
740 ns.asan_permitted_paths = NULL;
741 ns.permitted_paths = NULL;
742 bool ret = is_accessible(&ns, "/data/test//", true, false);
743
744 EXPECT_EQ(__FUNCTION__, ret, false);
745 }
746
747 /**
748 * @tc.name : namespace_test_0520
749 * @tc.desc : is_accessible test asan_lib_paths is matching
750 * @tc.level : Level 2
751 */
namespace_test_0520(void)752 void namespace_test_0520(void)
753 {
754 ns_t ns;
755 ns.separated = false;
756 ns.allowed_libs = NULL;
757 ns.env_paths = NULL;
758 ns.asan_lib_paths = "/data/test:/etc";
759 ns.lib_paths = NULL;
760 ns.asan_permitted_paths = NULL;
761 ns.permitted_paths = NULL;
762 bool ret = is_accessible(&ns, "/data/test/", true, false);
763
764 EXPECT_EQ(__FUNCTION__, ret, true);
765 }
766
767 /**
768 * @tc.name : namespace_test_0530
769 * @tc.desc : is_accessible test permitted_paths is matching
770 * @tc.level : Level 1
771 */
namespace_test_0530(void)772 void namespace_test_0530(void)
773 {
774 ns_t ns;
775 ns.separated = false;
776 ns.allowed_libs = NULL;
777 ns.env_paths = NULL;
778 ns.lib_paths = NULL;
779 ns.asan_lib_paths = NULL;
780 ns.asan_permitted_paths = NULL;
781
782 strlist list;
783 list.num = 1;
784 char *name = "/test";
785 list.strs = &name;
786
787 ns.permitted_paths = &list;
788
789 bool ret = is_accessible(&ns, "/test/", true, false);
790
791 EXPECT_EQ(__FUNCTION__, ret, true);
792 }
793
794 /**
795 * @tc.name : namespace_test_0540
796 * @tc.desc : is_accessible test permitted_paths is not matching
797 * @tc.level : Level 2
798 */
namespace_test_0540(void)799 void namespace_test_0540(void)
800 {
801 ns_t ns;
802 ns.separated = false;
803 ns.allowed_libs = NULL;
804 ns.env_paths = NULL;
805 ns.lib_paths = NULL;
806 ns.asan_lib_paths = NULL;
807 ns.asan_permitted_paths = NULL;
808
809 strlist list;
810 list.num = 1;
811 char *name = "/test";
812 list.strs = &name;
813
814 ns.permitted_paths = &list;
815
816 bool ret = is_accessible(&ns, "/test", true, false);
817 EXPECT_EQ(__FUNCTION__, ret, false);
818 }
819
820 /**
821 * @tc.name : namespace_test_0550
822 * @tc.desc : is_accessible test permitted_paths is not matching
823 * @tc.level : Level 2
824 */
namespace_test_0550(void)825 void namespace_test_0550(void)
826 {
827 ns_t ns;
828 ns.separated = false;
829 ns.allowed_libs = NULL;
830 ns.env_paths = NULL;
831 ns.asan_lib_paths = NULL;
832 ns.asan_permitted_paths = NULL;
833
834 strlist list;
835 list.num = 1;
836 char *name = "/abc";
837 list.strs = &name;
838
839 ns.permitted_paths = &list;
840
841 bool ret = is_accessible(&ns, "/test", true, false);
842
843 EXPECT_EQ(__FUNCTION__, ret, false);
844 }
845
846 /**
847 * @tc.name : namespace_test_0560
848 * @tc.desc : is_accessible test env_paths is not matching
849 * @tc.level : Level 2
850 */
namespace_test_0560(void)851 void namespace_test_0560(void)
852 {
853 ns_t ns;
854 ns.separated = false;
855 ns.allowed_libs = NULL;
856 ns.env_paths = "/data/test:/etc";
857 ns.lib_paths = NULL;
858 ns.asan_lib_paths = NULL;
859 ns.asan_permitted_paths = NULL;
860 ns.permitted_paths = NULL;
861 bool ret = is_accessible(&ns, "/data/abc/", true, false);
862
863 EXPECT_EQ(__FUNCTION__, ret, false);
864 }
865
866 /**
867 * @tc.name : namespace_test_0570
868 * @tc.desc : check_asan_path test wiht invalid input
869 * @tc.level : Level 2
870 */
namespace_test_0570(void)871 void namespace_test_0570(void)
872 {
873 ns_t ns;
874 ns.separated = false;
875 ns.allowed_libs = NULL;
876 ns.env_paths = NULL;
877 ns.asan_lib_paths = NULL;
878 bool ret = check_asan_path(&ns, "/data/test/");
879
880 EXPECT_EQ(__FUNCTION__, ret, false);
881 }
882
883 /**
884 * @tc.name : namespace_test_0580
885 * @tc.desc : check_asan_path test asan_lib_paths is not matching
886 * @tc.level : Level 2
887 */
namespace_test_0580(void)888 void namespace_test_0580(void)
889 {
890 ns_t ns;
891 ns.asan_lib_paths = "";
892 ns.asan_permitted_paths = NULL;
893 bool ret = check_asan_path(&ns, "/abc/");
894
895 EXPECT_EQ(__FUNCTION__, ret, false);
896 }
897
898 /**
899 * @tc.name : namespace_test_0590
900 * @tc.desc : check_asan_path test asan_lib_paths is matching
901 * @tc.level : Level 1
902 */
namespace_test_0590(void)903 void namespace_test_0590(void)
904 {
905 ns_t ns;
906 ns.asan_lib_paths = "/data/test:/etc";
907 ns.asan_permitted_paths = NULL;
908 bool ret = check_asan_path(&ns, "/data/test/");
909 EXPECT_EQ(__FUNCTION__, ret, true);
910 }
911
912 /**
913 * @tc.name : namespace_test_0600
914 * @tc.desc : check_asan_path test asan_lib_paths is not matching
915 * @tc.level : Level 2
916 */
namespace_test_0600(void)917 void namespace_test_0600(void)
918 {
919 ns_t ns;
920 ns.asan_lib_paths = "/data/test:/etc";
921 ns.asan_permitted_paths = NULL;
922 bool ret = check_asan_path(&ns, "/data/test");
923 EXPECT_EQ(__FUNCTION__, ret, false);
924 }
925
926 /**
927 * @tc.name : namespace_test_0610
928 * @tc.desc : check_asan_path test asan_lib_paths is not matching
929 * @tc.level : Level 2
930 */
namespace_test_0610(void)931 void namespace_test_0610(void)
932 {
933 ns_t ns;
934 ns.asan_lib_paths = "/data/test:/etc";
935 ns.asan_permitted_paths = NULL;
936 bool ret = check_asan_path(&ns, "/data/test//");
937 EXPECT_EQ(__FUNCTION__, ret, false);
938 }
939
940 /**
941 * @tc.name : namespace_test_0630
942 * @tc.desc : is_accessible test lib_paths is not matching
943 * @tc.level : Level 2
944 */
namespace_test_0630(void)945 void namespace_test_0630(void)
946 {
947 ns_t ns;
948 ns.separated = false;
949 ns.allowed_libs = NULL;
950 ns.env_paths = NULL;
951 ns.asan_lib_paths = NULL;
952 ns.asan_permitted_paths = NULL;
953 ns.permitted_paths = NULL;
954
955 ns.lib_paths = "";
956
957 bool ret = is_accessible(&ns, "/test/", true, false);
958
959 EXPECT_EQ(__FUNCTION__, ret, false);
960 }
961
962 /**
963 * @tc.name : namespace_test_0640
964 * @tc.desc : is_accessible test lib_paths is not matching
965 * @tc.level : Level 2
966 */
namespace_test_0640(void)967 void namespace_test_0640(void)
968 {
969 ns_t ns;
970 ns.separated = false;
971 ns.allowed_libs = NULL;
972 ns.env_paths = NULL;
973 ns.asan_lib_paths = NULL;
974 ns.asan_permitted_paths = NULL;
975 ns.permitted_paths = NULL;
976
977 ns.lib_paths = "/data/test:/ext";
978
979 bool ret = is_accessible(&ns, "/bct/", true, false);
980
981 EXPECT_EQ(__FUNCTION__, ret, false);
982 }
983
984 /**
985 * @tc.name : namespace_test_0650
986 * @tc.desc : is_accessible test lib_paths is matching
987 * @tc.level : Level 1
988 */
namespace_test_0650(void)989 void namespace_test_0650(void)
990 {
991 ns_t ns;
992 ns.separated = false;
993 ns.allowed_libs = NULL;
994 ns.env_paths = NULL;
995 ns.asan_lib_paths = NULL;
996 ns.asan_permitted_paths = NULL;
997 ns.permitted_paths = NULL;
998
999 ns.lib_paths = "/data/test:/ext";
1000
1001 bool ret = is_accessible(&ns, "/data/test/", true, false);
1002
1003 EXPECT_EQ(__FUNCTION__, ret, true);
1004 }
1005
1006 /**
1007 * @tc.name : namespace_test_0660
1008 * @tc.desc : is_accessible test lib_paths is not matching
1009 * @tc.level : Level 2
1010 */
namespace_test_0660(void)1011 void namespace_test_0660(void)
1012 {
1013 ns_t ns;
1014 ns.separated = false;
1015 ns.allowed_libs = NULL;
1016 ns.env_paths = NULL;
1017 ns.asan_lib_paths = NULL;
1018 ns.asan_permitted_paths = NULL;
1019 ns.permitted_paths = NULL;
1020
1021 ns.lib_paths = "/data/test:/ext";
1022
1023 bool ret = is_accessible(&ns, "/data/test//", true, false);
1024
1025 EXPECT_EQ(__FUNCTION__, ret, false);
1026 }
1027
1028 /**
1029 * @tc.name : namespace_test_0670
1030 * @tc.desc : check_asan_path test asan_permitted_paths is not matching
1031 * @tc.level : Level 2
1032 */
namespace_test_0670(void)1033 void namespace_test_0670(void)
1034 {
1035 ns_t ns;
1036 ns.asan_lib_paths = NULL;
1037
1038 strlist list;
1039 list.num = 1;
1040 char *name = "/abc";
1041 list.strs = &name;
1042
1043 ns.asan_permitted_paths = &list;
1044 bool ret = check_asan_path(&ns, "/test//");
1045 EXPECT_EQ(__FUNCTION__, ret, false);
1046 }
1047
1048 /**
1049 * @tc.name : namespace_test_0680
1050 * @tc.desc : check_asan_path test asan_permitted_paths is matching
1051 * @tc.level : Level 1
1052 */
namespace_test_0680(void)1053 void namespace_test_0680(void)
1054 {
1055 ns_t ns;
1056 ns.asan_lib_paths = NULL;
1057
1058 strlist list;
1059 list.num = 1;
1060 char *name = "/test";
1061 list.strs = &name;
1062
1063 ns.asan_permitted_paths = &list;
1064 bool ret = check_asan_path(&ns, "/test/");
1065 EXPECT_EQ(__FUNCTION__, ret, true);
1066 }
1067
1068 /**
1069 * @tc.name : namespace_test_0690
1070 * @tc.desc : check_asan_path test asan_permitted_paths is matching
1071 * @tc.level : Level 1
1072 */
namespace_test_0690(void)1073 void namespace_test_0690(void)
1074 {
1075 ns_t ns;
1076 ns.asan_lib_paths = NULL;
1077
1078 strlist list;
1079 list.num = 1;
1080 char *name = "/test";
1081 list.strs = &name;
1082
1083 ns.asan_permitted_paths = &list;
1084 bool ret = check_asan_path(&ns, "/test//");
1085 EXPECT_EQ(__FUNCTION__, ret, true);
1086 }
1087
1088 /**
1089 * @tc.name : namespace_test_0700
1090 * @tc.desc : check_asan_path test asan_permitted_paths is not matching
1091 * @tc.level : Level 2
1092 */
namespace_test_0700(void)1093 void namespace_test_0700(void)
1094 {
1095 ns_t ns;
1096 ns.asan_lib_paths = NULL;
1097
1098 strlist list;
1099 list.num = 0;
1100
1101 ns.asan_permitted_paths = &list;
1102 bool ret = check_asan_path(&ns, "/test//");
1103 EXPECT_EQ(__FUNCTION__, ret, false);
1104 }
1105
1106 /**
1107 * @tc.name : namespace_test_0710
1108 * @tc.desc : is_accessible test input param are null
1109 * @tc.level : Level 2
1110 */
namespace_test_0710(void)1111 void namespace_test_0710(void)
1112 {
1113 ns_t ns;
1114 ns.separated = false;
1115 ns.allowed_libs = NULL;
1116 ns.env_paths = NULL;
1117 ns.asan_lib_paths = NULL;
1118 ns.asan_permitted_paths = NULL;
1119 ns.permitted_paths = NULL;
1120 ns.lib_paths = NULL;
1121 bool ret = is_accessible(&ns, NULL , false, false);
1122 EXPECT_EQ(__FUNCTION__, ret, false);
1123 }
1124
1125 /**
1126 * @tc.name : namespace_test_0720
1127 * @tc.desc : is_sharable test shared_libs is matching
1128 * @tc.level : Level 1
1129 */
namespace_test_0720(void)1130 void namespace_test_0720(void)
1131 {
1132 ns_inherit ns;
1133
1134 strlist list;
1135 list.num = 1;
1136 char *name = "/test";
1137 list.strs = &name;
1138 ns.shared_libs = &list;
1139
1140 bool ret = is_sharable(&ns, "/test");
1141 EXPECT_EQ(__FUNCTION__, ret, true);
1142 }
1143
1144 /**
1145 * @tc.name : namespace_test_0730
1146 * @tc.desc : is_sharable test shared_libs is not matching
1147 * @tc.level : Level 2
1148 */
namespace_test_0730(void)1149 void namespace_test_0730(void)
1150 {
1151 ns_inherit ns;
1152
1153 strlist list;
1154 list.num = 0;
1155 ns.shared_libs = &list;
1156
1157 bool ret = is_sharable(&ns, "/test");
1158 EXPECT_EQ(__FUNCTION__, ret, false);
1159 }
1160
1161 // Because below function are static in file and call it difficult through External API, below interfaces are covered by white-box unit testing.
1162 #ifdef UNIT_TEST_STATIC
1163 void nsinherits_realloc(ns_inherit_list *nsinl);
1164
1165 /**
1166 * @tc.name : namespace_test_0740
1167 * @tc.desc : Test nsinherits_realloc with invalid input
1168 * @tc.level : Level 2
1169 */
namespace_test_0740(void)1170 void namespace_test_0740(void)
1171 {
1172 nsinherits_realloc(NULL);
1173 EXPECT_TRUE(__FUNCTION__, true);
1174 }
1175
1176 /**
1177 * @tc.name : namespace_test_0750
1178 * @tc.desc : Test nsinherits_realloc with normal input
1179 * @tc.level : Level 0
1180 */
namespace_test_0750(void)1181 void namespace_test_0750(void)
1182 {
1183 ns_inherit_list nsinl;
1184 nsinl.size = 1;
1185 nsinherits_realloc(&nsinl);
1186 EXPECT_EQ(__FUNCTION__, nsinl.size, 2);
1187 }
1188 #endif
1189
1190 TEST_FUN G_Fun_Array[] = {
1191 namespace_test_0010,
1192 namespace_test_0020,
1193 namespace_test_0030,
1194 namespace_test_0040,
1195 namespace_test_0050,
1196 namespace_test_0060,
1197 namespace_test_0070,
1198 namespace_test_0080,
1199 namespace_test_0090,
1200 namespace_test_0100,
1201 namespace_test_0110,
1202 namespace_test_0120,
1203 namespace_test_0130,
1204 namespace_test_0140,
1205 namespace_test_0150,
1206 namespace_test_0160,
1207 namespace_test_0170,
1208 namespace_test_0180,
1209 namespace_test_0190,
1210 namespace_test_0200,
1211 namespace_test_0210,
1212 namespace_test_0220,
1213 namespace_test_0230,
1214 namespace_test_0250,
1215 namespace_test_0260,
1216 namespace_test_0270,
1217 namespace_test_0280,
1218 namespace_test_0290,
1219 namespace_test_0300,
1220 namespace_test_0310,
1221 namespace_test_0320,
1222 namespace_test_0330,
1223 namespace_test_0340,
1224 namespace_test_0350,
1225 namespace_test_0360,
1226 namespace_test_0370,
1227 namespace_test_0380,
1228 namespace_test_0390,
1229 namespace_test_0400,
1230 namespace_test_0410,
1231 namespace_test_0420,
1232 namespace_test_0440,
1233 namespace_test_0450,
1234 namespace_test_0460,
1235 namespace_test_0470,
1236 namespace_test_0480,
1237 namespace_test_0490,
1238 namespace_test_0500,
1239 namespace_test_0510,
1240 namespace_test_0520,
1241 namespace_test_0530,
1242 namespace_test_0540,
1243 namespace_test_0550,
1244 namespace_test_0560,
1245 namespace_test_0570,
1246 namespace_test_0580,
1247 namespace_test_0590,
1248 namespace_test_0600,
1249 namespace_test_0610,
1250 namespace_test_0630,
1251 namespace_test_0640,
1252 namespace_test_0650,
1253 namespace_test_0660,
1254 namespace_test_0670,
1255 namespace_test_0680,
1256 namespace_test_0690,
1257 namespace_test_0700,
1258 namespace_test_0710,
1259 namespace_test_0720,
1260 namespace_test_0730,
1261 #ifdef UNIT_TEST_STATIC
1262 namespace_test_0740,
1263 namespace_test_0750,
1264 #endif
1265 };
1266
main(void)1267 int main(void)
1268 {
1269 int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
1270 for (int pos = 0; pos < num; ++pos) {
1271 G_Fun_Array[pos]();
1272 }
1273
1274 return t_status;
1275 }
1276