summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-03-03 11:27:47 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-04-27 15:09:13 +0200
commit0886ef266c865463ee9c43c512044232d06a8d6b (patch)
tree368977015545dda543c6cf718598256539258931
parentbbd6f73bbad478a450ecfa2933a63de6dc269778 (diff)
downloadsssd-0886ef266c865463ee9c43c512044232d06a8d6b.tar.gz
sssd-0886ef266c865463ee9c43c512044232d06a8d6b.tar.xz
sssd-0886ef266c865463ee9c43c512044232d06a8d6b.zip
selinux testselinux
-rw-r--r--Makefile.am32
-rw-r--r--src/providers/data_provider_be.c2
-rw-r--r--src/tests/cmocka/test_ipa_selinux.c113
-rw-r--r--src/tests/cwrap/Makefile.am2
-rw-r--r--src/util/server.c6
5 files changed, 144 insertions, 11 deletions
diff --git a/Makefile.am b/Makefile.am
index 0aad222c1..e711cc589 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -205,6 +205,7 @@ if HAVE_CMOCKA
nestedgroups-tests \
test_sss_idmap \
test_ipa_idmap \
+ test_ipa_selinux \
test_utils \
ad_common_tests \
dp_opt_tests \
@@ -1305,7 +1306,7 @@ libdlopen_test_providers_la_SOURCES = \
libdlopen_test_providers_la_CFLAGS = \
$(AM_CFLAGS) \
$(CHECK_CFLAGS) \
- -DUNIT_TESTING
+ -DSSS_UNIT_TESTING
libdlopen_test_providers_la_LIBADD = \
$(PAM_LIBS) \
$(SSSD_LIBS) \
@@ -1553,7 +1554,7 @@ simple_access_tests_SOURCES = \
simple_access_tests_CFLAGS = \
$(AM_CFLAGS) \
$(CHECK_CFLAGS) \
- -DUNIT_TESTING
+ -DSSS_UNIT_TESTING
simple_access_tests_LDADD = \
$(LIBADD_DL) \
$(SSSD_LIBS) \
@@ -1949,6 +1950,25 @@ test_ipa_idmap_LDADD = \
$(SSSD_INTERNAL_LTLIBS) \
libsss_test_common.la
+test_ipa_selinux_SOURCES = \
+ src/tests/cmocka/test_ipa_selinux.c \
+ src/providers/ipa/ipa_selinux.c \
+ src/providers/ipa/ipa_hosts.c \
+ src/providers/ipa/ipa_access.c \
+ src/providers/data_provider_be.c \
+ src/providers/data_provider_opts.c \
+ src/providers/ldap/sdap_id_op.c \
+ $(NULL)
+test_ipa_selinux_CFLAGS = \
+ $(AM_CFLAGS) \
+ -DSSS_UNIT_TESTING \
+ $(NULL)
+test_ipa_selinux_LDADD = \
+ $(CMOCKA_LIBS) \
+ $(POPT_LIBS) \
+ $(SSSD_INTERNAL_LTLIBS) \
+ libsss_test_common.la
+
test_utils_SOURCES = \
src/tests/cmocka/test_utils.c \
src/tests/cmocka/test_sss_ssh.c \
@@ -1967,7 +1987,7 @@ test_search_bases_SOURCES = \
src/tests/cmocka/test_search_bases.c
test_search_bases_CFLAGS = \
$(AM_CFLAGS) \
- -DUNIT_TESTING
+ -DSSS_UNIT_TESTING
test_search_bases_LDADD = \
$(PAM_LIBS) \
$(CMOCKA_LIBS) \
@@ -2029,7 +2049,7 @@ ad_access_filter_tests_SOURCES = \
src/tests/cmocka/test_ad_access_filter.c
ad_access_filter_tests_CFLAGS = \
$(AM_CFLAGS) \
- -DUNIT_TESTING
+ -DSSS_UNIT_TESTING
ad_access_filter_tests_LDADD = \
$(PAM_LIBS) \
$(CMOCKA_LIBS) \
@@ -2050,7 +2070,7 @@ ad_gpo_tests_SOURCES = \
ad_gpo_tests_CFLAGS = \
$(AM_CFLAGS) \
$(NDR_NBT_CFLAGS) \
- -DUNIT_TESTING
+ -DSSS_UNIT_TESTING
ad_gpo_tests_LDADD = \
$(PAM_LIBS) \
$(CMOCKA_LIBS) \
@@ -2069,7 +2089,7 @@ ad_common_tests_SOURCES = \
src/tests/cmocka/test_ad_common.c
ad_common_tests_CFLAGS = \
$(AM_CFLAGS) \
- -DUNIT_TESTING
+ -DSSS_UNIT_TESTING
ad_common_tests_LDFLAGS = \
-Wl,-wrap,sdap_set_sasl_options
ad_common_tests_LDADD = \
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index a48a42878..d874342f1 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -2805,7 +2805,7 @@ fail:
return ret;
}
-#ifndef UNIT_TESTING
+#ifndef SSS_UNIT_TESTING
int main(int argc, const char *argv[])
{
int opt;
diff --git a/src/tests/cmocka/test_ipa_selinux.c b/src/tests/cmocka/test_ipa_selinux.c
new file mode 100644
index 000000000..6927695f2
--- /dev/null
+++ b/src/tests/cmocka/test_ipa_selinux.c
@@ -0,0 +1,113 @@
+/*
+ Authors:
+ Jakub Hrozek <jhrozek@redhat.com>
+
+ Copyright (C) 2015 Red Hat
+
+ SSSD tests: Unit tests for the IPA SELinux module
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <popt.h>
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include "tests/common.h"
+
+struct selinux_test_ctx {
+ struct tevent_context *ev;
+ struct be_ctx *be_ctx;
+};
+
+static int selinux_test_setup(void **state)
+{
+ struct selinux_test_ctx *test_ctx = NULL;
+
+ assert_true(leak_check_setup());
+
+ test_ctx = talloc_zero(global_talloc_context,
+ struct selinux_test_ctx);
+ assert_non_null(test_ctx);
+
+ /* create be_ctx, only ev and offline field should be used */
+ test_ctx->be_ctx = talloc_zero(test_ctx, struct be_ctx);
+ assert_non_null(test_ctx->be_ctx);
+
+ test_ctx->be_ctx->ev = tevent_context_init(test_ctx->be_ctx);
+ assert_non_null(test_ctx->be_ctx->ev);
+
+ *state = test_ctx;
+
+ return 0;
+}
+
+static int selinux_test_teardown(void **state)
+{
+ struct selinux_test_ctx *test_ctx = \
+ talloc_get_type(*state, struct selinux_test_ctx);
+
+ assert_true(leak_check_teardown());
+ talloc_free(test_ctx);
+
+ return 0;
+}
+
+static int test_user_context(void **state)
+{
+ (void) state; /* unused */
+
+ return 0;
+}
+
+int main(int argc, const char *argv[])
+{
+ poptContext pc;
+ int opt;
+ struct poptOption long_options[] = {
+ POPT_AUTOHELP
+ SSSD_DEBUG_OPTS
+ POPT_TABLEEND
+ };
+
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_user_context),
+ };
+
+ /* Set debug level to invalid value so we can deside if -d 0 was used. */
+ debug_level = SSSDBG_INVALID;
+
+ pc = poptGetContext(argv[0], argc, argv, long_options, 0);
+ while((opt = poptGetNextOpt(pc)) != -1) {
+ switch(opt) {
+ default:
+ fprintf(stderr, "\nInvalid option %s: %s\n\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ poptPrintUsage(pc, stderr, 0);
+ return 1;
+ }
+ }
+ poptFreeContext(pc);
+
+ DEBUG_CLI_INIT(debug_level);
+
+ tests_set_cwd();
+
+ return cmocka_run_group_tests(tests,
+ selinux_test_setup,
+ selinux_test_teardown);
+}
diff --git a/src/tests/cwrap/Makefile.am b/src/tests/cwrap/Makefile.am
index b805e8349..eab9f2618 100644
--- a/src/tests/cwrap/Makefile.am
+++ b/src/tests/cwrap/Makefile.am
@@ -99,7 +99,7 @@ server_tests_CFLAGS = \
$(LIBCAPNG_CFLAGS) \
-DTEST_DB_PATH=\"server_tests\" \
-DTEST_PID_PATH=\"server_tests\" \
- -DUNIT_TESTING \
+ -DSSS_UNIT_TESTING \
$(NULL)
server_tests_LDADD = \
$(CMOCKA_LIBS) \
diff --git a/src/util/server.c b/src/util/server.c
index 7e9b76f74..075ced0f9 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -419,7 +419,7 @@ errno_t server_common_rotate_logs(struct confdb_ctx *confdb,
static const char *get_db_path(void)
{
-#ifdef UNIT_TESTING
+#ifdef SSS_UNIT_TESTING
#ifdef TEST_DB_PATH
return TEST_DB_PATH;
#else
@@ -427,12 +427,12 @@ static const char *get_db_path(void)
#endif /* TEST_DB_PATH */
#else
return DB_PATH;
-#endif /* UNIT_TESTING */
+#endif /* SSS_UNIT_TESTING */
}
static const char *get_pid_path(void)
{
-#ifdef UNIT_TESTING
+#ifdef SSS_UNIT_TESTING
#ifdef TEST_PID_PATH
return TEST_PID_PATH;
#else