summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
4 files changed, 118 insertions, 5 deletions
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