diff options
author | Miroslav Grepl <mgrepl@redhat.com> | 2014-04-11 09:37:53 +0200 |
---|---|---|
committer | Miroslav Grepl <mgrepl@redhat.com> | 2014-04-11 09:37:53 +0200 |
commit | 47be9ff57e72906660bb62a515222f482131e1fb (patch) | |
tree | 2cb0ef0ba48d73b1df7cc0915754a17e19464bb6 /libseaudit/tests | |
download | setools-master.tar.gz setools-master.tar.xz setools-master.zip |
Create setools-3.3.7 git repomaster
Diffstat (limited to 'libseaudit/tests')
-rw-r--r-- | libseaudit/tests/Makefile.am | 16 | ||||
-rw-r--r-- | libseaudit/tests/filters.c | 114 | ||||
-rw-r--r-- | libseaudit/tests/filters.h | 35 | ||||
-rw-r--r-- | libseaudit/tests/libseaudit-tests.c | 54 | ||||
-rw-r--r-- | libseaudit/tests/parse_file.c | 113 | ||||
-rw-r--r-- | libseaudit/tests/parse_file.h | 35 |
6 files changed, 367 insertions, 0 deletions
diff --git a/libseaudit/tests/Makefile.am b/libseaudit/tests/Makefile.am new file mode 100644 index 0000000..47cef42 --- /dev/null +++ b/libseaudit/tests/Makefile.am @@ -0,0 +1,16 @@ +TESTS = libseaudit-tests +check_PROGRAMS = libseaudit-tests + +libseaudit_tests_SOURCES = \ + filters.c filters.h \ + parse_file.c parse_file.h \ + libseaudit-tests.c + +AM_CFLAGS = @DEBUGCFLAGS@ @WARNCFLAGS@ @PROFILECFLAGS@ @SELINUX_CFLAGS@ \ + @QPOL_CFLAGS@ @APOL_CFLAGS@ @SEAUDIT_CFLAGS@ + +AM_LDFLAGS = @DEBUGLDFLAGS@ @WARNLDFLAGS@ @PROFILELDFLAGS@ + +LDADD = @SELINUX_LIB_FLAG@ @SEAUDIT_LIB_FLAG@ @APOL_LIB_FLAG@ @QPOL_LIB_FLAG@ @CUNIT_LIB_FLAG@ + +libseaudit_tests_DEPENDENCIES = ../src/libseaudit.so diff --git a/libseaudit/tests/filters.c b/libseaudit/tests/filters.c new file mode 100644 index 0000000..4279173 --- /dev/null +++ b/libseaudit/tests/filters.c @@ -0,0 +1,114 @@ +/** + * @file + * + * Test libseaudit's filtering capabilities. + * + * @author Jeremy A. Mowery jmowery@tresys.com + * @author Jason Tang jtang@tresys.com + * + * Copyright (C) 2007 Tresys Technology, LLC + * + * 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 + */ + +#include <config.h> + +#include <CUnit/CUnit.h> +#include <apol/util.h> +#include <seaudit/log.h> +#include <seaudit/message.h> +#include <seaudit/model.h> +#include <seaudit/parse.h> + +#include <stdbool.h> +#include <stdio.h> + +#define MESSAGES_NOWARNS TEST_POLICIES "/setools-3.1/seaudit/messages-nowarns" + +static seaudit_log_t *l = NULL; +static seaudit_model_t *m = NULL; + +static void filters_simple() +{ + seaudit_filter_t *f = seaudit_filter_create("simple filter"); + CU_ASSERT_PTR_NOT_NULL_FATAL(f); + + int retval; + apol_vector_t *v = apol_str_split("system_u", ":"); + CU_ASSERT_PTR_NOT_NULL_FATAL(v); + retval = seaudit_filter_set_source_user(f, v); + CU_ASSERT(retval == 0); + apol_vector_destroy(&v); + + retval = seaudit_model_append_filter(m, f); + CU_ASSERT(retval == 0); + + v = seaudit_model_get_messages(l, m); + CU_ASSERT_PTR_NOT_NULL_FATAL(v); + CU_ASSERT(apol_vector_get_size(v) == 5 + 5); + apol_vector_destroy(&v); + + retval = seaudit_filter_set_strict(f, true); + CU_ASSERT(retval == 0); + v = seaudit_model_get_messages(l, m); + CU_ASSERT_PTR_NOT_NULL_FATAL(v); + CU_ASSERT(apol_vector_get_size(v) == 5); + apol_vector_destroy(&v); + + retval = seaudit_filter_set_strict(f, false); + CU_ASSERT(retval == 0); + v = seaudit_model_get_messages(l, m); + CU_ASSERT_PTR_NOT_NULL_FATAL(v); + CU_ASSERT(apol_vector_get_size(v) == 5 + 5); + apol_vector_destroy(&v); +} + +CU_TestInfo filters_tests[] = { + {"simple filter", filters_simple}, + CU_TEST_INFO_NULL +}; + +int filters_init() +{ + l = seaudit_log_create(NULL, NULL); + if (l == NULL) { + return 1; + } + m = seaudit_model_create("filters", l); + if (m == NULL) { + return 1; + } + + FILE *f = fopen(MESSAGES_NOWARNS, "r"); + if (f == NULL) { + return 1; + } + int retval; + retval = seaudit_log_parse(l, f); + if (retval != 0) { + fclose(f); + return 1; + } + + fclose(f); + return 0; +} + +int filters_cleanup() +{ + seaudit_log_destroy(&l); + seaudit_model_destroy(&m); + return 0; +} diff --git a/libseaudit/tests/filters.h b/libseaudit/tests/filters.h new file mode 100644 index 0000000..97f634b --- /dev/null +++ b/libseaudit/tests/filters.h @@ -0,0 +1,35 @@ +/** + * @file + * + * Declarations for using filters in libseaudit. + * + * @author Jeremy A. Mowery jmowery@tresys.com + * @author Jason Tang jtang@tresys.com + * + * Copyright (C) 2007 Tresys Technology, LLC + * + * 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 + */ + +#ifndef FILTERS_H +#define FILTERS_H + +#include <CUnit/CUnit.h> + +extern CU_TestInfo filters_tests[]; +extern int filters_init(); +extern int filters_cleanup(); + +#endif diff --git a/libseaudit/tests/libseaudit-tests.c b/libseaudit/tests/libseaudit-tests.c new file mode 100644 index 0000000..2b65ec6 --- /dev/null +++ b/libseaudit/tests/libseaudit-tests.c @@ -0,0 +1,54 @@ +/** + * @file + * + * CUnit testing framework for libseaudit. + * + * @author Jeremy A. Mowery jmowery@tresys.com + * @author Jason Tang jtang@tresys.com + * + * Copyright (C) 2007 Tresys Technology, LLC + * + * 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 + */ + +#include <config.h> + +#include <CUnit/CUnit.h> +#include <CUnit/Basic.h> + +#include "filters.h" +#include "parse_file.h" + +int main(void) +{ + if (CU_initialize_registry() != CUE_SUCCESS) { + return CU_get_error(); + } + + CU_SuiteInfo suites[] = { + {"Parse File", parse_file_init, parse_file_cleanup, parse_file_tests} + , + {"Filters", filters_init, filters_cleanup, filters_tests} + , + CU_SUITE_INFO_NULL + }; + + CU_register_suites(suites); + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + unsigned int num_failures = CU_get_number_of_failure_records(); + CU_cleanup_registry(); + return (int)num_failures; +} diff --git a/libseaudit/tests/parse_file.c b/libseaudit/tests/parse_file.c new file mode 100644 index 0000000..a4bac21 --- /dev/null +++ b/libseaudit/tests/parse_file.c @@ -0,0 +1,113 @@ +/** + * @file + * + * Test libseaudit's log file parsing ability. + * + * @author Jeremy A. Mowery jmowery@tresys.com + * @author Jason Tang jtang@tresys.com + * + * Copyright (C) 2007 Tresys Technology, LLC + * + * 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 + */ + +#include <config.h> + +#include <CUnit/CUnit.h> +#include <seaudit/log.h> +#include <seaudit/parse.h> + +#include <stdbool.h> +#include <stdio.h> + +struct log_answer +{ + const char *log_name; + bool has_warnings; +}; + +static void parse_file_test(const struct log_answer *la) +{ + seaudit_log_t *l = seaudit_log_create(NULL, NULL); + CU_ASSERT_PTR_NOT_NULL_FATAL(l); + + FILE *f = fopen(la->log_name, "r"); + CU_ASSERT_PTR_NOT_NULL_FATAL(f); + + int retval; + retval = seaudit_log_parse(l, f); + if (la->has_warnings) { + CU_ASSERT(retval > 0); + } else { + CU_ASSERT(retval == 0); + } + + fclose(f); + seaudit_log_destroy(&l); +} + +static void parse_file_fc4() +{ + struct log_answer l = { + TEST_POLICIES "/setools-3.0/seaudit/messages-FC4", + false + }; + parse_file_test(&l); +} + +static void parse_file_fc5() +{ + struct log_answer l = { + TEST_POLICIES "/setools-3.0/seaudit/messages-FC5", + false + }; + parse_file_test(&l); +} + +static void parse_file_nowarns() +{ + struct log_answer l = { + TEST_POLICIES "/setools-3.1/seaudit/messages-nowarns", + false + }; + parse_file_test(&l); +} + +static void parse_file_warnings() +{ + struct log_answer l = { + TEST_POLICIES "/setools-3.1/seaudit/messages-warnings", + true + }; + parse_file_test(&l); +} + +CU_TestInfo parse_file_tests[] = { + {"FC4 log", parse_file_fc4}, + {"FC5 log", parse_file_fc5}, + {"messages-nowarns", parse_file_nowarns}, + {"messages-warnings", parse_file_warnings}, + CU_TEST_INFO_NULL +}; + +int parse_file_init() +{ + return 0; +} + +int parse_file_cleanup() +{ + return 0; +} diff --git a/libseaudit/tests/parse_file.h b/libseaudit/tests/parse_file.h new file mode 100644 index 0000000..e403e57 --- /dev/null +++ b/libseaudit/tests/parse_file.h @@ -0,0 +1,35 @@ +/** + * @file + * + * Declarations for parsing selinux audit logs from a file pointer. + * + * @author Jeremy A. Mowery jmowery@tresys.com + * @author Jason Tang jtang@tresys.com + * + * Copyright (C) 2007 Tresys Technology, LLC + * + * 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 + */ + +#ifndef PARSE_FILE_H +#define PARSE_FILE_H + +#include <CUnit/CUnit.h> + +extern CU_TestInfo parse_file_tests[]; +extern int parse_file_init(); +extern int parse_file_cleanup(); + +#endif |