>From f02ccc018ce552d32e83a44ad6ba3f7fedd05e6d Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Tue, 18 Nov 2014 11:09:51 +0100 Subject: [PATCH 1/2] TESTS: Add function to purge optionf from confdb Some unit tests can fail if option from previous unit test was not removed from confdb. --- src/tests/common.h | 5 +++ src/tests/common_dom.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/tests/common.h b/src/tests/common.h index 714be6988aa032d935c09bc7db524545a4c9154e..677fd0a62965318d6a1d19285ba9e5c67897156e 100644 --- a/src/tests/common.h +++ b/src/tests/common.h @@ -103,6 +103,11 @@ void test_dom_suite_cleanup(const char *tests_path, const char *cdb_file, const char *domain); +int test_dom_purge_conf_options(TALLOC_CTX *mem_ctx, + struct sss_test_ctx *test_ctx, + const char *domain_name, + const char **params); + struct tevent_req * test_request_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, errno_t err); diff --git a/src/tests/common_dom.c b/src/tests/common_dom.c index 41f876555352744c4f61215c1a88369918f5192c..9bc30d3b3d8e57a3675d5fc72cbba33577c6dc06 100644 --- a/src/tests/common_dom.c +++ b/src/tests/common_dom.c @@ -24,6 +24,38 @@ #include #include "tests/common.h" +static char * +get_re_expression(TALLOC_CTX *mem_ctx, + struct confdb_ctx *confdb, + const char *domain_name) +{ + const char *dompath; + char *re_expression; + const char *default_re_expression = + "(((?P[^\\\\]+)\\\\(?P.+$))|" + "((?P[^@]+)@(?P.+$))|" + "(^(?P[^@\\\\]+)$))"; + int ret; + + dompath = talloc_asprintf(mem_ctx, "config/domain/%s", domain_name); + if (dompath == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed\n"); + goto fail; + } + + ret = confdb_get_string(confdb, mem_ctx, dompath, + "re_expression", default_re_expression, + &re_expression); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, "confdb_get_string failed\n"); + goto fail; + } + + return re_expression; + +fail: + return NULL; +} static errno_t mock_confdb(TALLOC_CTX *mem_ctx, @@ -179,6 +211,7 @@ mock_domain(TALLOC_CTX *mem_ctx, { struct sss_domain_info *domain = NULL; errno_t ret; + const char *re_expression; /* initialize sysdb */ ret = sssd_domain_init(mem_ctx, cdb, name, db_path, &domain); @@ -188,11 +221,14 @@ mock_domain(TALLOC_CTX *mem_ctx, goto done; } - /* init with an AD-style regex to be able to test flat name */ - ret = sss_names_init_from_args(domain, - "(((?P[^\\\\]+)\\\\(?P.+$))|" \ - "((?P[^@]+)@(?P.+$))|" \ - "(^(?P[^@\\\\]+)$))", + re_expression = get_re_expression(mem_ctx, cdb, name); + if (re_expression == NULL) { + ret = ENOMEM; + goto done; + } + + /* Init with an AD-style regex to be able to test flat name */ + ret = sss_names_init_from_args(domain, re_expression, "%1$s@%2$s", &domain->names); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "cannot create names context\n"); @@ -384,3 +420,39 @@ void test_dom_suite_cleanup(const char *tests_path, test_multidom_suite_cleanup(tests_path, cdb_file, domains); } + +int test_dom_purge_conf_options(TALLOC_CTX *mem_ctx, + struct sss_test_ctx *test_ctx, + const char *domain_name, + const char **params) +{ + size_t i; + const char *val[] = { NULL }; + errno_t ret; + char *dompath; + + dompath = talloc_asprintf(mem_ctx, "config/domain/%s", domain_name); + if (dompath == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed\n"); + ret = ENOMEM; + goto done; + } + + if (params) { + for (i = 0; params[i]; i++) { + ret = confdb_add_param(test_ctx->confdb, true, + dompath, params[i], + val); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, + "cannot remove parameter %s: %d\n", params[i], ret); + goto done; + } + } + } + + ret = EOK; + +done: + return ret; +} -- 2.1.0