e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl Pavel Reichl <preichl@redhat.com>
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl Copyright (C) 2015 Red Hat
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl SSSD tests - id cleanup
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl This program is free software; you can redistribute it and/or modify
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl it under the terms of the GNU General Public License as published by
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl the Free Software Foundation; either version 3 of the License, or
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl (at your option) any later version.
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl This program is distributed in the hope that it will be useful,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl but WITHOUT ANY WARRANTY; without even the implied warranty of
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl GNU General Public License for more details.
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl You should have received a copy of the GNU General Public License
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl along with this program. If not, see <http://www.gnu.org/licenses/>.
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichlstatic int _setup_sysdb_tests(struct sysdb_test_ctx **ctx, bool enumerate)
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl /* Create tests directory if it doesn't exist */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl /* (relative to current dir) */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl test_ctx = talloc_zero(global_talloc_context, struct sysdb_test_ctx);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl /* Create an event context
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl * It will not be used except in confdb_init and sysdb_init
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl DEBUG(SSSDBG_MINOR_FAILURE, "CONFDB: %s\n", conf_db);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl /* Connect to the conf db */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl "config/domain/LOCAL", "cache_credentials", val);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl#define setup_sysdb_tests(ctx) _setup_sysdb_tests((ctx), false)
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl /* set options */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl test_ctx->opts = talloc_zero(test_ctx, struct sdap_options);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sdap_copy_map(test_ctx->opts, rfc2307_user_map,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = dp_copy_defaults(test_ctx->opts, default_basic_opts,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl dp_opt_set_int(test_ctx->opts->basic, SDAP_ACCOUNT_CACHE_EXPIRATION, 1);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichlstatic errno_t invalidate_group(TALLOC_CTX *ctx,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl const char *name)
2cec08a3174bff951c048c57b4b0e4517ad6b7b1Lukas Slebodnik ret = sysdb_set_group_attr(domain, name, sys_attrs,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl "Could not add expiration time to attributes\n");
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl DEBUG(SSSDBG_MINOR_FAILURE, "Could not create sysdb attributes\n");
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichlstatic void test_id_cleanup_exp_group(void **state)
f02b62138466c876f6e8d6382769105f2e920d96Michal Židek /* This timeout can be bigger because we will call invalidate_group
f02b62138466c876f6e8d6382769105f2e920d96Michal Židek * to expire entries without waiting. */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek special_grp = sss_create_internal_fqname(test_ctx,
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek "special_gr*o/u\\p(2016)",
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek empty_special_grp = sss_create_internal_fqname(test_ctx,
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek "empty_gr*o/u\\p(2016)",
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek empty_grp = sss_create_internal_fqname(test_ctx, "empty_grp",
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek grp = sss_create_internal_fqname(test_ctx, "grp", test_ctx->domain->name);
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek test_user = sss_create_internal_fqname(test_ctx, "test_user",
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek test_user2 = sss_create_internal_fqname(test_ctx, "test_user2",
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_store_group(test_ctx->domain, special_grp,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_store_group(test_ctx->domain, empty_special_grp,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_store_group(test_ctx->domain, empty_grp,
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek ret = sysdb_store_user(test_ctx->domain, test_user, NULL,
338af078fcc18126df939f20182acea7a646b7c8Michal Zidek ret = sysdb_store_user(test_ctx->domain, test_user2, NULL,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl /* not expired */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl /* let records to expire */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl invalidate_group(test_ctx, test_ctx->domain, special_grp);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl invalidate_group(test_ctx, test_ctx->domain, empty_special_grp);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl invalidate_group(test_ctx, test_ctx->domain, grp);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl invalidate_group(test_ctx, test_ctx->domain, empty_grp);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl ret = sysdb_search_group_by_name(test_ctx, test_ctx->domain,
2cec08a3174bff951c048c57b4b0e4517ad6b7b1Lukas Slebodnik { "no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
2cec08a3174bff951c048c57b4b0e4517ad6b7b1Lukas Slebodnik _("Do not delete the test database after a test run"), NULL },
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl cmocka_unit_test_setup_teardown(test_id_cleanup_exp_group,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl pc = poptGetContext(argv[0], argc, argv, long_options, 0);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_FILE, LOCAL_SYSDB_FILE);
e2e334b2f51118cb14c7391c4e4e44ff247ef638Pavel Reichl rv = cmocka_run_group_tests(tests, NULL, NULL);