1 /*
2 * Authors: Chad Sellers <csellers@tresys.com>
3 * Joshua Brindle <jbrindle@tresys.com>
4 *
5 * Copyright (C) 2006 Tresys Technology, LLC
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "test-expander-attr-map.h"
23 #include "test-common.h"
24
25 #include <sepol/policydb/policydb.h>
26 #include <CUnit/Basic.h>
27 #include <stdlib.h>
28
29 extern policydb_t base_expanded2;
30
test_expander_attr_mapping(void)31 void test_expander_attr_mapping(void)
32 {
33 /* note that many cases are ommitted because they don't make sense
34 (i.e. declaring in an optional and then using it in the base) or
35 because declare in optional then require in a different optional
36 logic still doesn't work */
37
38 const char *typesb1[] = { "attr_check_base_1_1_t", "attr_check_base_1_2_t" };
39 const char *typesb2[] = { "attr_check_base_2_1_t", "attr_check_base_2_2_t" };
40 const char *typesb3[] = { "attr_check_base_3_1_t", "attr_check_base_3_2_t",
41 "attr_check_base_3_3_t", "attr_check_base_3_4_t"
42 };
43 const char *typesb4[] = { "attr_check_base_4_1_t", "attr_check_base_4_2_t" };
44 const char *typesb5[] = { "attr_check_base_5_1_t", "attr_check_base_5_2_t" };
45 const char *typesb6[] = { "attr_check_base_6_1_t", "attr_check_base_6_2_t",
46 "attr_check_base_6_3_t", "attr_check_base_6_4_t"
47 };
48 const char *typesbo2[] = { "attr_check_base_optional_2_1_t",
49 "attr_check_base_optional_2_2_t"
50 };
51 const char *typesbo5[] = { "attr_check_base_optional_5_1_t",
52 "attr_check_base_optional_5_2_t"
53 };
54 const char *typesm2[] = { "attr_check_mod_2_1_t", "attr_check_mod_2_2_t" };
55 const char *typesm4[] = { "attr_check_mod_4_1_t", "attr_check_mod_4_2_t" };
56 const char *typesm5[] = { "attr_check_mod_5_1_t", "attr_check_mod_5_2_t" };
57 const char *typesm6[] = { "attr_check_mod_6_1_t", "attr_check_mod_6_2_t",
58 "attr_check_mod_6_3_t", "attr_check_mod_6_4_t"
59 };
60 const char *typesmo2[] = { "attr_check_mod_optional_4_1_t",
61 "attr_check_mod_optional_4_2_t"
62 };
63 const char *typesb10[] = { "attr_check_base_10_1_t", "attr_check_base_10_2_t" };
64 const char *typesb11[] = { "attr_check_base_11_3_t", "attr_check_base_11_4_t" };
65 const char *typesm10[] = { "attr_check_mod_10_1_t", "attr_check_mod_10_2_t" };
66 const char *typesm11[] = { "attr_check_mod_11_3_t", "attr_check_mod_11_4_t" };
67
68 test_attr_types(&base_expanded2, "attr_check_base_1", NULL, typesb1, 2);
69 test_attr_types(&base_expanded2, "attr_check_base_2", NULL, typesb2, 2);
70 test_attr_types(&base_expanded2, "attr_check_base_3", NULL, typesb3, 4);
71 test_attr_types(&base_expanded2, "attr_check_base_4", NULL, typesb4, 2);
72 test_attr_types(&base_expanded2, "attr_check_base_5", NULL, typesb5, 2);
73 test_attr_types(&base_expanded2, "attr_check_base_6", NULL, typesb6, 4);
74 test_attr_types(&base_expanded2, "attr_check_base_optional_2", NULL, typesbo2, 2);
75 test_attr_types(&base_expanded2, "attr_check_base_optional_5", NULL, typesbo5, 2);
76 test_attr_types(&base_expanded2, "attr_check_mod_2", NULL, typesm2, 2);
77 test_attr_types(&base_expanded2, "attr_check_mod_4", NULL, typesm4, 2);
78 test_attr_types(&base_expanded2, "attr_check_mod_5", NULL, typesm5, 2);
79 test_attr_types(&base_expanded2, "attr_check_mod_6", NULL, typesm6, 4);
80 test_attr_types(&base_expanded2, "attr_check_mod_optional_4", NULL, typesmo2, 2);
81 test_attr_types(&base_expanded2, "attr_check_base_7", NULL, NULL, 0);
82 test_attr_types(&base_expanded2, "attr_check_base_8", NULL, NULL, 0);
83 test_attr_types(&base_expanded2, "attr_check_base_9", NULL, NULL, 0);
84 test_attr_types(&base_expanded2, "attr_check_base_10", NULL, typesb10, 2);
85 test_attr_types(&base_expanded2, "attr_check_base_11", NULL, typesb11, 2);
86 test_attr_types(&base_expanded2, "attr_check_mod_7", NULL, NULL, 0);
87 test_attr_types(&base_expanded2, "attr_check_mod_8", NULL, NULL, 0);
88 test_attr_types(&base_expanded2, "attr_check_mod_9", NULL, NULL, 0);
89 test_attr_types(&base_expanded2, "attr_check_mod_10", NULL, typesm10, 2);
90 test_attr_types(&base_expanded2, "attr_check_mod_11", NULL, typesm11, 2);
91 test_attr_types(&base_expanded2, "attr_check_base_optional_8", NULL, NULL, 0);
92 test_attr_types(&base_expanded2, "attr_check_mod_optional_7", NULL, NULL, 0);
93 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_5"));
94 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_5_1_t"));
95 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_5_2_t"));
96 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_8"));
97 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_8_1_t"));
98 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_base_optional_disabled_8_2_t"));
99 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_4"));
100 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_4_1_t"));
101 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_4_2_t"));
102 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_7"));
103 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_7_1_t"));
104 CU_ASSERT(!hashtab_search((&base_expanded2)->p_types.table, "attr_check_mod_optional_disabled_7_2_t"));
105 }
106