On (20/11/14 14:01), Jakub Hrozek wrote: >On Tue, Nov 18, 2014 at 11:23:47AM +0100, Lukas Slebodnik wrote: >> ehlo, >> >> Attached patches are unit test for ticket >> https://fedorahosted.org/sssd/ticket/2487 >> >> The ./nss-srv-tests passed with sssd-1.12.1. >> >> LS > >> From ee8a9a9d65f1ca71d945c95eb664d1ff7f04cfc5 Mon Sep 17 00:00:00 2001 >> From: Lukas Slebodnik <lsleb...@redhat.com> >> Date: Tue, 18 Nov 2014 11:09:51 +0100 >> Subject: [PATCH 1/2] TESTS: Add function to purge optionf from confdb > >Isn't it better to always set up and teardown the whole db instead of >cherry-picking the right parameters? The purpose is to remove just some options from confdb and do not tuch sysdb.
rebased patches on top of the tatest prebzina's changes. LS
>From f02ccc018ce552d32e83a44ad6ba3f7fedd05e6d Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik <lsleb...@redhat.com> 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 <errno.h> #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<domain>[^\\\\]+)\\\\(?P<name>.+$))|" + "((?P<name>[^@]+)@(?P<domain>.+$))|" + "(^(?P<name>[^@\\\\]+)$))"; + 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<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \ - "((?P<name>[^@]+)@(?P<domain>.+$))|" \ - "(^(?P<name>[^@\\\\]+)$))", + 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
>From 70c25478f654ed705c18c2bb45b9e7aae9848904 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik <lsleb...@redhat.com> Date: Tue, 18 Nov 2014 11:16:41 +0100 Subject: [PATCH 2/2] test_nss_srv: Add regression test for option re_expression This regression was cused by commit 09a36be00ddcf1d7bd5b8a368143d5b2e2f4fb68 "sss_get_domain_name: check for fq name first" Related: https://fedorahosted.org/sssd/ticket/2487 --- src/tests/cmocka/test_nss_srv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tests/cmocka/test_nss_srv.c b/src/tests/cmocka/test_nss_srv.c index 8f297a7842e4c9a21821795dbcbe1a5025259ce1..1e70c80fea571f2034a761c6ab2b4d500470849f 100644 --- a/src/tests/cmocka/test_nss_srv.c +++ b/src/tests/cmocka/test_nss_srv.c @@ -2007,6 +2007,7 @@ void nss_fqdn_fancy_test_setup(void **state) struct sss_test_conf_param params[] = { { "enumerate", "false" }, { "full_name_format", "%1$s@@@@@%2$s" }, + { "re_expression", "(?P<name>[^@]+)@(?P<domain>[^@]*$)" }, { NULL, NULL }, /* Sentinel */ }; @@ -2015,6 +2016,18 @@ void nss_fqdn_fancy_test_setup(void **state) void nss_test_teardown(void **state) { + int ret; + const char *params[] = { + "enumerate", + "full_name_format", + "re_expression", + NULL, + }; + + ret = test_dom_purge_conf_options(nss_test_ctx, nss_test_ctx->tctx, + TEST_DOM_NAME, params); + assert_int_equal(ret, EOK); + talloc_free(nss_test_ctx); } -- 2.1.0
_______________________________________________ sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/sssd-devel