[SSSD] [PATCH] nss-srv-tests: Add regression test for option re_expression
Lukas Slebodnik
lslebodn at redhat.com
Tue Nov 18 10:23:47 UTC 2014
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
-------------- next part --------------
>From ee8a9a9d65f1ca71d945c95eb664d1ff7f04cfc5 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at 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 | 79 +++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 80 insertions(+), 4 deletions(-)
diff --git a/src/tests/common.h b/src/tests/common.h
index 9065db39ea5d0db0351447cfb2c9c14f4d9468e5..4da277510722488ab00f3a1bcf3f940d5dd50ea7 100644
--- a/src/tests/common.h
+++ b/src/tests/common.h
@@ -91,6 +91,11 @@ void test_dom_suite_cleanup(const char *tests_path,
const char *confdb_path,
const char *sysdb_path);
+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 bc69c5a093e17fc56e42ccedd998ab6434d85003..0dbec2ad78c7cba188ab6f637215e0c65f28f1a5 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 sss_test_ctx *test_ctx,
+ 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(test_ctx->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;
+}
struct sss_test_ctx *
create_dom_test_ctx(TALLOC_CTX *mem_ctx,
@@ -39,6 +71,7 @@ create_dom_test_ctx(TALLOC_CTX *mem_ctx,
val[1] = NULL;
errno_t ret;
char *dompath;
+ const char *re_expression;
test_ctx = create_ev_test_ctx(mem_ctx);
if (test_ctx == NULL) {
@@ -112,11 +145,13 @@ create_dom_test_ctx(TALLOC_CTX *mem_ctx,
}
test_ctx->sysdb = test_ctx->dom->sysdb;
+ re_expression = get_re_expression(test_ctx, test_ctx, domain_name);
+ if (re_expression == NULL) {
+ goto fail;
+ }
+
/* Init with an AD-style regex to be able to test flat name */
- ret = sss_names_init_from_args(test_ctx,
- "(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
- "((?P<name>[^@]+)@(?P<domain>.+$))|" \
- "(^(?P<name>[^@\\\\]+)$))",
+ ret = sss_names_init_from_args(test_ctx, re_expression,
"%1$s@%2$s", &test_ctx->nctx);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "cannot create names context\n");
@@ -204,3 +239,39 @@ void test_dom_suite_cleanup(const char *tests_path,
done:
talloc_free(tmp_ctx);
}
+
+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
-------------- next part --------------
>From 2efe6066304c9a53a87e8304779738b5aa058eda Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at 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 c318d94be867bbb9991de288cdae45d2ddc29b24..87c2453078c0dd9fbb0ba25ef384f4ff48b66bae 100644
--- a/src/tests/cmocka/test_nss_srv.c
+++ b/src/tests/cmocka/test_nss_srv.c
@@ -2008,6 +2008,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 */
};
@@ -2016,6 +2017,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
More information about the sssd-devel
mailing list