test_ad_common.c revision 51b5e1475b3e0b7acac34ed382cfaca8411883a4
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen Jakub Hrozek <jhrozek@redhat.com>
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen Copyright (C) 2013 Red Hat
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen SSSD tests: AD access control filter tests
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen This program is free software; you can redistribute it and/or modify
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen it under the terms of the GNU General Public License as published by
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen the Free Software Foundation; either version 3 of the License, or
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen (at your option) any later version.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen This program is distributed in the hope that it will be useful,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen GNU General Public License for more details.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen You should have received a copy of the GNU General Public License
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/* In order to access opaque types */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen#define KEYTAB_TEST_PRINC TEST_AUTHID"@"REALMNAME
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen#define KEYTAB_PATH TEST_DIR"/keytab_test.keytab"
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenkrb5_error_code __wrap_krb5_kt_default(krb5_context context, krb5_keytab *id)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen return krb5_kt_resolve(context, KEYTAB_PATH, id);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen test_ctx = talloc_zero(global_talloc_context, struct ad_common_test_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen test_ctx->dom = talloc_zero(test_ctx, struct sss_domain_info);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen test_ctx->subdom = talloc_zero(test_ctx, struct sss_domain_info);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen test_ctx->subdom->name = discard_const(SUBDOMNAME);
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen test_ctx->ad_ctx = talloc_zero(test_ctx, struct ad_id_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic int test_ad_common_teardown(void **state)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen assert_true(check_leaks_pop(test_ctx) == true);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen assert_true(check_leaks_pop(global_talloc_context) == true);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic void test_ad_create_2way_trust_options(void **state)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen const char *s;
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen mock_keytab_with_contents(test_ctx, KEYTAB_PATH, KEYTAB_TEST_PRINC);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen test_ctx->ad_ctx->ad_options = ad_create_2way_trust_options(
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen assert_non_null(test_ctx->ad_ctx->ad_options);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen assert_int_equal(test_ctx->ad_ctx->ad_options->id->schema_type,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->basic,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen assert_null(s); /* This is the system keytab */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen s = dp_opt_get_string(test_ctx->ad_ctx->ad_options->id->basic,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ret = test_ad_common_setup((void **) &test_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ad_ctx->ad_options = ad_create_2way_trust_options(ad_ctx,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ad_ctx->gc_ctx = talloc_zero(ad_ctx, struct sdap_id_conn_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ad_ctx->ldap_ctx = talloc_zero(ad_ctx, struct sdap_id_conn_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ad_ctx->sdap_id_ctx = talloc_zero(ad_ctx, struct sdap_id_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ad_ctx->sdap_id_ctx->opts = talloc_zero(ad_ctx->sdap_id_ctx,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ret = sdap_domain_add(ad_ctx->sdap_id_ctx->opts, test_ctx->dom, &sdom);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen subdom_ad_ctx = talloc_zero(test_ctx, struct ad_id_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen subdom_ldap_ctx = talloc_zero(subdom_ad_ctx, struct sdap_id_conn_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ret = sdap_domain_add(ad_ctx->sdap_id_ctx->opts, test_ctx->subdom, &sdom);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen__real_sdap_set_sasl_options(struct sdap_options *id_opts,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen__wrap_sdap_set_sasl_options(struct sdap_options *id_opts,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* Pretend SASL is fine */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen conn = ad_get_dom_ldap_conn(test_ctx->ad_ctx, test_ctx->dom);
01f54478a7c69b88ab13840c99bbab19a0d7d754Timo Sirainen assert_true(conn == test_ctx->ad_ctx->ldap_ctx);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen conn = ad_get_dom_ldap_conn(test_ctx->ad_ctx, test_ctx->subdom);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen assert_true(conn == test_ctx->subdom_ad_ctx->ldap_ctx);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen struct ad_common_test_ctx *test_ctx = talloc_get_type(*state,
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_true(dp_opt_get_bool(test_ctx->ad_ctx->ad_options->basic,
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->dom);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_true(conn_list[0] == test_ctx->ad_ctx->gc_ctx);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen /* If there is a fallback, we should ignore the offline mode */
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_true(conn_list[0]->ignore_mark_offline);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_true(conn_list[1] == test_ctx->ad_ctx->ldap_ctx);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_false(conn_list[1]->ignore_mark_offline);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->subdom);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_true(conn_list[0] == test_ctx->ad_ctx->gc_ctx);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_true(conn_list[0]->ignore_mark_offline);
74ae32512357bdd4872bf160dc697ff7b54b54c5Timo Sirainen assert_true(conn_list[1] == test_ctx->subdom_ad_ctx->ldap_ctx);
AD_ENABLE_GC));
int opt;
switch(opt) {