f69f3581658351003a6d9245045e41d0efb85022Sumit Bose Sumit Bose <sbose@redhat.com>
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose Copyright (C) 2014 Red Hat
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose SSSD tests: Unit tests for id-mapping in the IPA provider
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose This program is free software; you can redistribute it and/or modify
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose it under the terms of the GNU General Public License as published by
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose the Free Software Foundation; either version 3 of the License, or
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose (at your option) any later version.
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose This program is distributed in the hope that it will be useful,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose GNU General Public License for more details.
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose You should have received a copy of the GNU General Public License
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define DOMAIN_SID discard_const("S-1-5-21-2-3-4")
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* working IPA_RANGE_LOCAL range */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, SECONDARY_BASE_RID,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose EOK, DOMAIN_NAME, NULL, 0, {BASE_ID, RANGE_MAX}, true},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* working old-style IPA_RANGE_LOCAL range without range type */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, SECONDARY_BASE_RID,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose EOK, DOMAIN_NAME, NULL, 0, {BASE_ID, RANGE_MAX}, true},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* old-style IPA_RANGE_LOCAL without SID and secondary base rid */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, 0, NULL, NULL},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* old-style range with SID and secondary base rid */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, SECONDARY_BASE_RID,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* working IPA_RANGE_AD_TRUST range */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, 0, DOMAIN_SID,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose EOK, DOMAIN_SID, DOMAIN_SID, BASE_RID, {BASE_ID, RANGE_MAX}, false},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* working old-style IPA_RANGE_AD_TRUST range without range type */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, 0, DOMAIN_SID, NULL},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose EOK, DOMAIN_SID, DOMAIN_SID, BASE_RID, {BASE_ID, RANGE_MAX}, false},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* working IPA_RANGE_AD_TRUST_POSIX range */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, 0, DOMAIN_SID,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose EOK, DOMAIN_SID, DOMAIN_SID, 0, {BASE_ID, RANGE_MAX}, true},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = get_idmap_data_from_range(&d[c].r, DOMAIN_NAME, &dom_name, &sid,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_string_equal(dom_name, d[c].exp_dom_name);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_true(external_mapping == d[c].exp_external_mapping);
f69f3581658351003a6d9245045e41d0efb85022Sumit Boseerrno_t __wrap_sysdb_get_ranges(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bosestatic struct range_info **get_range_list(TALLOC_CTX *mem_ctx)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list = talloc_array(mem_ctx, struct range_info *, 2);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0] = talloc_zero(range_list, struct range_info);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->name = talloc_strdup(range_list[0], RANGE_NAME);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->trusted_dom_sid = talloc_strdup(range_list[0], DOMAIN_SID);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->range_type = talloc_strdup(range_list[0],
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx->sdap_id_ctx->be = talloc_zero(test_ctx->sdap_id_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx->sdap_id_ctx->be->domain = talloc_zero(test_ctx->sdap_id_ctx->be,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx->sdap_id_ctx->be->domain);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose talloc_strdup(test_ctx->sdap_id_ctx->be->domain, DOMAIN_NAME);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx->sdap_id_ctx->be->domain->name);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose will_return(__wrap_sysdb_get_ranges, get_range_list(global_talloc_context));
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = ipa_idmap_init(test_ctx, test_ctx->sdap_id_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bosevoid test_ipa_idmap_get_ranges_from_sysdb(void **state)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose will_return(__wrap_sysdb_get_ranges, get_range_list(test_ctx->idmap_ctx));
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = ipa_idmap_get_ranges_from_sysdb(test_ctx->idmap_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose will_return(__wrap_sysdb_get_ranges, get_range_list(global_talloc_context));
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = ipa_idmap_get_ranges_from_sysdb(test_ctx->idmap_ctx,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_get_idmap_data_from_range),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_idmap_get_ranges_from_sysdb,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* Set debug level to invalid value so we can deside if -d 0 was used. */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);