Jason Tang jtang@tresys.com
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Definition in file terule-tests.c.
#include <config.h>
#include <CUnit/CUnit.h>
#include <apol/policy.h>
#include <apol/policy-path.h>
#include <apol/terule-query.h>
#include <qpol/policy_extend.h>
#include <stdbool.h>
Go to the source code of this file.
Defines | |
| #define | BIN_POLICY TEST_POLICIES "/setools-3.3/rules/rules-mls.21" |
| #define | SOURCE_POLICY TEST_POLICIES "/setools-3.3/rules/rules-mls.conf" |
Functions | |
| void | terule_basic_syn (void) |
| int | terule_init () |
| int | terule_cleanup () |
Variables | |
| apol_policy_t * | bp = NULL |
| apol_policy_t * | sp = NULL |
| CU_TestInfo | terule_tests [] |
|
|
Definition at line 35 of file terule-tests.c. |
|
|
Definition at line 36 of file terule-tests.c. |
|
|
Definition at line 41 of file terule-tests.c. References apol_policy_get_qpol(), apol_syn_terule_get_by_query(), apol_terule_query_append_class(), apol_terule_query_create(), apol_terule_query_destroy(), apol_terule_query_set_rules(), apol_terule_query_t, apol_vector_destroy(), apol_vector_get_element(), apol_vector_get_size(), apol_vector_t, qpol_policy_t, QPOL_RULE_TYPE_CHANGE, QPOL_RULE_TYPE_MEMBER, QPOL_RULE_TYPE_TRANS, qpol_syn_terule_get_rule_type(), qpol_syn_terule_t, and sp. 00042 {
00043 apol_terule_query_t *tq = apol_terule_query_create();
00044 CU_ASSERT_PTR_NOT_NULL_FATAL(tq);
00045
00046 int retval;
00047 retval = apol_terule_query_set_rules(sp, tq, QPOL_RULE_TYPE_TRANS | QPOL_RULE_TYPE_CHANGE | QPOL_RULE_TYPE_MEMBER);
00048 CU_ASSERT_EQUAL_FATAL(retval, 0);
00049
00050 apol_vector_t *v = NULL;
00051 retval = apol_syn_terule_get_by_query(sp, tq, &v);
00052 CU_ASSERT_EQUAL_FATAL(retval, 0);
00053 CU_ASSERT_PTR_NOT_NULL(v);
00054
00055 size_t num_trans = 0, num_changes = 0, num_members = 0;
00056
00057 qpol_policy_t *q = apol_policy_get_qpol(sp);
00058 size_t i;
00059 for (i = 0; i < apol_vector_get_size(v); i++) {
00060 const qpol_syn_terule_t *syn = (const qpol_syn_terule_t *)apol_vector_get_element(v, i);
00061 uint32_t rule_type;
00062 retval = qpol_syn_terule_get_rule_type(q, syn, &rule_type);
00063 CU_ASSERT_EQUAL_FATAL(retval, 0);
00064 CU_ASSERT(rule_type == QPOL_RULE_TYPE_TRANS || rule_type == QPOL_RULE_TYPE_CHANGE ||
00065 rule_type == QPOL_RULE_TYPE_MEMBER);
00066
00067 if (rule_type == QPOL_RULE_TYPE_TRANS) {
00068 num_trans++;
00069 } else if (rule_type == QPOL_RULE_TYPE_CHANGE) {
00070 num_changes++;
00071 } else if (rule_type == QPOL_RULE_TYPE_MEMBER) {
00072 num_members++;
00073 }
00074 }
00075 CU_ASSERT(num_trans == 6 && num_changes == 3 && num_members == 4);
00076 apol_vector_destroy(&v);
00077
00078 retval = apol_terule_query_append_class(sp, tq, "cursor");
00079 CU_ASSERT_EQUAL_FATAL(retval, 0);
00080
00081 retval = apol_syn_terule_get_by_query(sp, tq, &v);
00082 CU_ASSERT_EQUAL_FATAL(retval, 0);
00083 CU_ASSERT(v != NULL && apol_vector_get_size(v) == 0);
00084 apol_vector_destroy(&v);
00085 apol_terule_query_destroy(&tq);
00086 }
|
|
|
Definition at line 94 of file terule-tests.c. References apol_policy_create_from_policy_path(), apol_policy_get_qpol(), apol_policy_path_create(), apol_policy_path_destroy(), apol_policy_path_t, APOL_POLICY_PATH_TYPE_MONOLITHIC, BIN_POLICY, bp, qpol_policy_build_syn_rule_table(), SOURCE_POLICY, and sp. 00095 {
00096 apol_policy_path_t *ppath = apol_policy_path_create(APOL_POLICY_PATH_TYPE_MONOLITHIC, BIN_POLICY, NULL);
00097 if (ppath == NULL) {
00098 return 1;
00099 }
00100
00101 if ((bp = apol_policy_create_from_policy_path(ppath, 0, NULL, NULL)) == NULL) {
00102 apol_policy_path_destroy(&ppath);
00103 return 1;
00104 }
00105 apol_policy_path_destroy(&ppath);
00106
00107 ppath = apol_policy_path_create(APOL_POLICY_PATH_TYPE_MONOLITHIC, SOURCE_POLICY, NULL);
00108 if (ppath == NULL) {
00109 return 1;
00110 }
00111
00112 if ((sp = apol_policy_create_from_policy_path(ppath, 0, NULL, NULL)) == NULL) {
00113 apol_policy_path_destroy(&ppath);
00114 return 1;
00115 }
00116 apol_policy_path_destroy(&ppath);
00117
00118 if (qpol_policy_build_syn_rule_table(apol_policy_get_qpol(sp)) != 0) {
00119 return 1;
00120 }
00121
00122 return 0;
00123 }
|
|
|
Definition at line 125 of file terule-tests.c. References apol_policy_destroy(), bp, and sp. 00126 {
00127 apol_policy_destroy(&bp);
00128 apol_policy_destroy(&sp);
00129 return 0;
00130 }
|
|
|
Definition at line 38 of file terule-tests.c. Referenced by terule_cleanup(), and terule_init(). |
|
|
Definition at line 39 of file terule-tests.c. Referenced by terule_basic_syn(), terule_cleanup(), and terule_init(). |
|
|
Initial value: {
{"basic syntactic search", terule_basic_syn}
,
CU_TEST_INFO_NULL
}
Definition at line 88 of file terule-tests.c. Referenced by main(). |