f69f3581658351003a6d9245045e41d0efb85022Sumit Bose/*
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose Authors:
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose Sumit Bose <sbose@redhat.com>
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose Copyright (C) 2014 Red Hat
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose SSSD tests: Unit tests for id-mapping in the IPA provider
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
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
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
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*/
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#include <popt.h>
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#include "tests/cmocka/common_mock.h"
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#include "lib/idmap/sss_idmap.h"
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#include "providers/ipa/ipa_common.h"
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#include "providers/ldap/sdap_idmap.h"
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define RANGE_NAME discard_const("range1")
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define DOMAIN_SID discard_const("S-1-5-21-2-3-4")
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define DOMAIN_NAME discard_const("dom.test")
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define BASE_RID 111
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define SECONDARY_BASE_RID 11223344
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define BASE_ID 123456
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define RANGE_SIZE 222222
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose#define RANGE_MAX (BASE_ID + RANGE_SIZE - 1)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bosevoid test_get_idmap_data_from_range(void **state)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose{
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose char *dom_name;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose char *sid;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose uint32_t rid;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct sss_idmap_range range;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose bool external_mapping;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose size_t c;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose errno_t ret;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct test_data {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct range_info r;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose errno_t exp_ret;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose char *exp_dom_name;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose char *exp_sid;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose uint32_t exp_rid;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct sss_idmap_range exp_range;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose bool exp_external_mapping;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose } d[] = {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* working IPA_RANGE_LOCAL range */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, SECONDARY_BASE_RID,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose NULL, discard_const(IPA_RANGE_LOCAL)},
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 NULL, NULL},
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 EINVAL, NULL, NULL, 0, {0, 0}, false},
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 DOMAIN_SID, NULL},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose EINVAL, NULL, NULL, 0, {0, 0}, false},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* working IPA_RANGE_AD_TRUST range */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{RANGE_NAME, BASE_ID, RANGE_SIZE, BASE_RID, 0, DOMAIN_SID,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose discard_const(IPA_RANGE_AD_TRUST)},
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 discard_const(IPA_RANGE_AD_TRUST_POSIX)},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose EOK, DOMAIN_SID, DOMAIN_SID, 0, {BASE_ID, RANGE_MAX}, true},
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose {{0}, 0, NULL, NULL, 0, {0, 0}, false}
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose };
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose for (c = 0; d[c].exp_dom_name != NULL; c++) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = get_idmap_data_from_range(&d[c].r, DOMAIN_NAME, &dom_name, &sid,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose &rid, &range, &external_mapping);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_int_equal(ret, d[c].exp_ret);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_string_equal(dom_name, d[c].exp_dom_name);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose if (d[c].exp_sid == NULL) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_null(sid);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose } else {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_string_equal(sid, d[c].exp_sid);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose }
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_int_equal(rid, d[c].exp_rid);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_int_equal(range.min, d[c].exp_range.min);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_int_equal(range.max, d[c].exp_range.max);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_true(external_mapping == d[c].exp_external_mapping);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose }
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose}
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Boseerrno_t __wrap_sysdb_get_ranges(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose size_t *range_count,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct range_info ***range_list)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose{
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose *range_count = sss_mock_type(size_t);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose *range_list = talloc_steal(mem_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose sss_mock_ptr_type(struct range_info **));
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose return EOK;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose}
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bosestruct test_ctx {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct sdap_idmap_ctx *idmap_ctx;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct sdap_id_ctx *sdap_id_ctx;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose};
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bosestatic struct range_info **get_range_list(TALLOC_CTX *mem_ctx)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose{
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct range_info **range_list;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list = talloc_array(mem_ctx, struct range_info *, 2);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(range_list);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0] = talloc_zero(range_list, struct range_info);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(range_list[0]);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->name = talloc_strdup(range_list[0], RANGE_NAME);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null( range_list[0]->name);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->base_id = BASE_ID;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->id_range_size = RANGE_SIZE;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->base_rid = BASE_RID;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->secondary_base_rid = 0;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->trusted_dom_sid = talloc_strdup(range_list[0], DOMAIN_SID);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(range_list[0]->trusted_dom_sid);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose range_list[0]->range_type = talloc_strdup(range_list[0],
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose IPA_RANGE_AD_TRUST);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(range_list[0]->range_type);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose return range_list;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose}
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int setup_idmap_ctx(void **state)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose{
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose int ret;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct test_ctx *test_ctx;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_true(leak_check_setup());
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx->sdap_id_ctx = talloc_zero(test_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct sdap_id_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx->sdap_id_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx->sdap_id_ctx->be = talloc_zero(test_ctx->sdap_id_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct be_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx->sdap_id_ctx->be);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx->sdap_id_ctx->be->domain = talloc_zero(test_ctx->sdap_id_ctx->be,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct sss_domain_info);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx->sdap_id_ctx->be->domain);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose test_ctx->sdap_id_ctx->be->domain->name =
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
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose will_return(__wrap_sysdb_get_ranges, 1);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose will_return(__wrap_sysdb_get_ranges, get_range_list(global_talloc_context));
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose ret = ipa_idmap_init(test_ctx, test_ctx->sdap_id_ctx,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose &test_ctx->idmap_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_int_equal(ret, EOK);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose check_leaks_push(test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose *state = test_ctx;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose}
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int teardown_idmap_ctx(void **state)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose{
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_true(check_leaks_pop(test_ctx) == true);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose talloc_free(test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose}
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bosevoid test_ipa_idmap_get_ranges_from_sysdb(void **state)
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose{
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose int ret;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_non_null(test_ctx);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose will_return(__wrap_sysdb_get_ranges, 1);
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 DOMAIN_NAME, DOMAIN_SID, true);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_int_equal(ret, EOK);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose will_return(__wrap_sysdb_get_ranges, 1);
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,
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose DOMAIN_NAME, DOMAIN_SID, false);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose assert_int_equal(ret, EIO);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose}
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Boseint main(int argc, const char *argv[])
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose{
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose poptContext pc;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose int opt;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose struct poptOption long_options[] = {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose POPT_AUTOHELP
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose SSSD_DEBUG_OPTS
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose POPT_TABLEEND
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose };
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
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,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_idmap_ctx, teardown_idmap_ctx),
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose };
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* Set debug level to invalid value so we can deside if -d 0 was used. */
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose debug_level = SSSDBG_INVALID;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose switch(opt) {
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose default:
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose poptPrintUsage(pc, stderr, 0);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose return 1;
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose }
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose }
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose poptFreeContext(pc);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose tests_set_cwd();
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return cmocka_run_group_tests(tests, NULL, NULL);
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose}