e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech/*
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech Authors:
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech Petr Čech <pcech@redhat.com>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech Copyright (C) 2016 Red Hat
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech SSSD tests: AD subdomain tests
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech This program is free software; you can redistribute it and/or modify
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech it under the terms of the GNU General Public License as published by
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech the Free Software Foundation; either version 3 of the License, or
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech (at your option) any later version.
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech This program is distributed in the hope that it will be useful,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech but WITHOUT ANY WARRANTY; without even the implied warranty of
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech GNU General Public License for more details.
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech You should have received a copy of the GNU General Public License
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech along with this program. If not, see <http://www.gnu.org/licenses/>.
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech*/
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <talloc.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <tevent.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <errno.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <popt.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <arpa/inet.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <netinet/in.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <sys/types.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <stdarg.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include <stdlib.h>
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include "tests/cmocka/common_mock.h"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include "tests/cmocka/common_mock_resp.h"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include "providers/ad/ad_common.h"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include "providers/ad/ad_subdomains.c"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#include "providers/ad/ad_opts.c"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#define AD_DOMAIN "ad_domain.domain.test"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#define DOMAIN_1 "one.domain.test"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech#define DOMAIN_2 "two.domain.test"
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstruct test_ad_subdom_ctx {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct ad_id_ctx *ad_id_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech};
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic struct ad_id_ctx *
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechtest_ad_subdom_init_ad_id_ctx(TALLOC_CTX *mem_ctx)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct ad_id_ctx *ad_id_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct ad_options *ad_options;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech errno_t ret;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_id_ctx = talloc_zero(mem_ctx, struct ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_options = talloc_zero(ad_id_ctx, struct ad_options);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(ad_options);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = dp_copy_defaults(ad_options,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_basic_opts,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_OPTS_BASIC,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech &ad_options->basic);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_id_ctx->ad_options = ad_options;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech return ad_id_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic int test_ad_subdom_setup(void **state)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct test_ad_subdom_ctx *test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_true(leak_check_setup());
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx = talloc_zero(global_talloc_context, struct test_ad_subdom_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx->ad_id_ctx = NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech check_leaks_push(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech *state = test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech return 0;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic int test_ad_subdom_teardown(void **state)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct test_ad_subdom_ctx *test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx = talloc_get_type(*state, struct test_ad_subdom_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_true(check_leaks_pop(test_ctx) == true);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_free(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_true(leak_check_teardown());
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech return 0;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic void test_ad_subdom_default(void **state)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct test_ad_subdom_ctx *test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char **ad_enabled_domains = NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech errno_t ret;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx = talloc_get_type(*state, struct test_ad_subdom_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx->ad_id_ctx = test_ad_subdom_init_ad_id_ctx(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = ad_get_enabled_domains(test_ctx, test_ctx->ad_id_ctx,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_DOMAIN,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech &ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_null(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic void test_ad_subdom_add_one(void **state)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct test_ad_subdom_ctx *test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char **ad_enabled_domains = NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int enabled_domains_count;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int domain_count = 2;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char *domains[domain_count];
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech errno_t ret;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx = talloc_get_type(*state, struct test_ad_subdom_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx->ad_id_ctx = test_ad_subdom_init_ad_id_ctx(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = dp_opt_set_string(test_ctx->ad_id_ctx->ad_options->basic,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_ENABLED_DOMAINS, DOMAIN_1);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = ad_get_enabled_domains(test_ctx, test_ctx->ad_id_ctx,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_DOMAIN,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech &ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech for (enabled_domains_count = 0;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains[enabled_domains_count] != NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech enabled_domains_count++) {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech }
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(domain_count, enabled_domains_count);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[0] = AD_DOMAIN;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[1] = DOMAIN_1;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_true(are_values_in_array(domains, domain_count,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains, enabled_domains_count));
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic void test_ad_subdom_add_two(void **state)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct test_ad_subdom_ctx *test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char **ad_enabled_domains = NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int enabled_domains_count;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int domain_count = 3;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char *domains[domain_count];
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech errno_t ret;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx = talloc_get_type(*state, struct test_ad_subdom_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx->ad_id_ctx = test_ad_subdom_init_ad_id_ctx(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = dp_opt_set_string(test_ctx->ad_id_ctx->ad_options->basic,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_ENABLED_DOMAINS, DOMAIN_1","DOMAIN_2);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = ad_get_enabled_domains(test_ctx, test_ctx->ad_id_ctx,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_DOMAIN,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech &ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech for (enabled_domains_count = 0;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains[enabled_domains_count] != NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech enabled_domains_count++) {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech }
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(domain_count, enabled_domains_count);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[0] = AD_DOMAIN;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[1] = DOMAIN_1;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[2] = DOMAIN_2;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_true(are_values_in_array(domains, domain_count,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains, enabled_domains_count));
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic void test_ad_subdom_add_master(void **state)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct test_ad_subdom_ctx *test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char **ad_enabled_domains = NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int enabled_domains_count;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int domain_count = 1;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char *domains[domain_count];
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech errno_t ret;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx = talloc_get_type(*state, struct test_ad_subdom_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx->ad_id_ctx = test_ad_subdom_init_ad_id_ctx(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = dp_opt_set_string(test_ctx->ad_id_ctx->ad_options->basic,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_ENABLED_DOMAINS, AD_DOMAIN);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = ad_get_enabled_domains(test_ctx, test_ctx->ad_id_ctx,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_DOMAIN,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech &ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech for (enabled_domains_count = 0;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains[enabled_domains_count] != NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech enabled_domains_count++) {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech }
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(domain_count, enabled_domains_count);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[0] = AD_DOMAIN;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_true(are_values_in_array(domains, domain_count,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains, enabled_domains_count));
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechstatic void test_ad_subdom_add_two_with_master(void **state)
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct test_ad_subdom_ctx *test_ctx;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char **ad_enabled_domains = NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int enabled_domains_count;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int domain_count = 3;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const char *domains[domain_count];
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech errno_t ret;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx = talloc_get_type(*state, struct test_ad_subdom_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ctx->ad_id_ctx = test_ad_subdom_init_ad_id_ctx(test_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = dp_opt_set_string(test_ctx->ad_id_ctx->ad_options->basic,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_ENABLED_DOMAINS,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech DOMAIN_1","AD_DOMAIN","DOMAIN_2);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ret = ad_get_enabled_domains(test_ctx, test_ctx->ad_id_ctx,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech AD_DOMAIN,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech &ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(ret, EOK);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_non_null(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech for (enabled_domains_count = 0;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains[enabled_domains_count] != NULL;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech enabled_domains_count++) {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech }
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_int_equal(domain_count, enabled_domains_count);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[0] = AD_DOMAIN;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[1] = DOMAIN_1;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech domains[2] = DOMAIN_2;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech assert_true(are_values_in_array(domains, domain_count,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech ad_enabled_domains, enabled_domains_count));
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(test_ctx->ad_id_ctx);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech talloc_zfree(ad_enabled_domains);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cechint main(int argc, const char *argv[])
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech{
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int rv;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech poptContext pc;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech int opt;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech struct poptOption long_options[] = {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech POPT_AUTOHELP
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech SSSD_DEBUG_OPTS
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech POPT_TABLEEND
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech };
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech const struct CMUnitTest tests[] = {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech cmocka_unit_test_setup_teardown(test_ad_subdom_default,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_setup,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_teardown),
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech cmocka_unit_test_setup_teardown(test_ad_subdom_add_one,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_setup,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_teardown),
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech cmocka_unit_test_setup_teardown(test_ad_subdom_add_two,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_setup,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_teardown),
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech cmocka_unit_test_setup_teardown(test_ad_subdom_add_master,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_setup,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_teardown),
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech cmocka_unit_test_setup_teardown(test_ad_subdom_add_two_with_master,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_setup,
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech test_ad_subdom_teardown),
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech };
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech debug_level = SSSDBG_INVALID;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech pc = poptGetContext(argv[0], argc, argv, long_options, 0);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech while((opt = poptGetNextOpt(pc)) != -1) {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech switch(opt) {
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech default:
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech fprintf(stderr, "\nInvalid option %s: %s\n\n",
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech poptBadOption(pc, 0), poptStrerror(opt));
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech poptPrintUsage(pc, stderr, 0);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech return 1;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech }
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech }
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech poptFreeContext(pc);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech DEBUG_CLI_INIT(debug_level);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech tests_set_cwd();
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech rv = cmocka_run_group_tests(tests, NULL, NULL);
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech return rv;
e4d18b748fd8298b5cc6b6687ca05ffffa20c574Petr Cech}