0001: Use extra flag also in OOB request.
0002: Provide support for UPN. This add an improvement from NSS code, but I'm not sure if it is desired or not.
If you have [domain/AD.PB] in sssd.conf and UPN "upn@ad.pb" then NSS responder will not find this user, cache_req will. Is this nss behavior intentional or a bug?
0003: I got really sick of the way new test are written in cache_req when writing new tests so I kinda rewrote it.
On 09/14/2015 01:32 PM, Pavel Březina wrote:
0001: Use extra flag also in OOB request.
0002: Provide support for UPN. This add an improvement from NSS code, but I'm not sure if it is desired or not.
If you have [domain/AD.PB] in sssd.conf and UPN "upn@ad.pb" then NSS responder will not find this user, cache_req will. Is this nss behavior intentional or a bug?
0003: I got really sick of the way new test are written in cache_req when writing new tests so I kinda rewrote it.
I think this completes the cache_req interface. If you find anything missing, please let me no so I can add it.
On 09/14/2015 01:34 PM, Pavel Březina wrote:
On 09/14/2015 01:32 PM, Pavel Březina wrote:
0001: Use extra flag also in OOB request.
0002: Provide support for UPN. This add an improvement from NSS code, but I'm not sure if it is desired or not.
If you have [domain/AD.PB] in sssd.conf and UPN "upn@ad.pb" then NSS responder will not find this user, cache_req will. Is this nss behavior intentional or a bug?
0003: I got really sick of the way new test are written in cache_req when writing new tests so I kinda rewrote it.
I think this completes the cache_req interface. If you find anything missing, please let me no so I can add it.
Hi,
I compiled it. CI tests over all 3 patches: http://sssd-ci.duckdns.org/logs/job/26/73/summary.html
I was interested in the third patch, since it affects the tests, with which I have worked. This is something what I will inspect more detail.
I cannot say ack, because there is large logic. I would like to ask someone more experienced to take care of this review.
Petr
PS: I installed AD on my laptop and I try to set up it correctly.
sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
On Wed, Sep 16, 2015 at 03:50:37PM +0200, Petr Cech wrote:
On 09/14/2015 01:34 PM, Pavel Březina wrote:
On 09/14/2015 01:32 PM, Pavel Březina wrote:
0001: Use extra flag also in OOB request.
0002: Provide support for UPN. This add an improvement from NSS code, but I'm not sure if it is desired or not.
If you have [domain/AD.PB] in sssd.conf and UPN "upn@ad.pb" then NSS responder will not find this user, cache_req will. Is this nss behavior intentional or a bug?
0003: I got really sick of the way new test are written in cache_req when writing new tests so I kinda rewrote it.
I think this completes the cache_req interface. If you find anything missing, please let me no so I can add it.
Hi,
I compiled it. CI tests over all 3 patches: http://sssd-ci.duckdns.org/logs/job/26/73/summary.html
I was interested in the third patch, since it affects the tests, with which I have worked. This is something what I will inspect more detail.
I cannot say ack, because there is large logic. I would like to ask someone more experienced to take care of this review.
Thank you, please don't hesitate to just note anything strange you notice in the patchset -- you don't have to review it all!
On 09/14/2015 01:32 PM, Pavel Březina wrote:
0001: Use extra flag also in OOB request.
0002: Provide support for UPN. This add an improvement from NSS code, but I'm not sure if it is desired or not.
If you have [domain/AD.PB] in sssd.conf and UPN "upn@ad.pb" then NSS responder will not find this user, cache_req will. Is this nss behavior intentional or a bug?
0003: I got really sick of the way new test are written in cache_req when writing new tests so I kinda rewrote it.
0001-cache_req-provide-extra-flag-for-oob-request.patch
From ce37e5591bcdc3bf3f755ab91a28c60f8c5c8bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?=pbrezina@redhat.com Date: Thu, 7 May 2015 13:01:44 +0200 Subject: [PATCH 1/3] cache_req: provide extra flag for oob request
src/responder/common/responder_cache_req.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/responder/common/responder_cache_req.c b/src/responder/common/responder_cache_req.c index d0a90d2c94b7f990a46af488a08dd386854384e0..fba5001476481040ed962dbbd9b01cc16fe0ba74 100644 --- a/src/responder/common/responder_cache_req.c +++ b/src/responder/common/responder_cache_req.c @@ -615,6 +615,11 @@ static errno_t cache_req_cache_check(struct tevent_req *req) if (state->input->type == CACHE_REQ_USER_BY_CERT) { search_str = state->input->cert; }
- if (DOM_HAS_VIEWS(state->input->domain)) {
extra_flag = EXTRA_INPUT_MAYBE_WITH_VIEW;
- }
switch (ret) { case EOK: DEBUG(SSSDBG_TRACE_FUNC, "Cached entry is valid, returning...\n");
@@ -629,7 +634,7 @@ static errno_t cache_req_cache_check(struct tevent_req *req) state->input->domain, true, state->input->dp_type, search_str,
state->input->id, NULL);
state->input->id, extra_flag); if (subreq == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory sending out-of-band " "data provider request\n");
@@ -643,10 +648,6 @@ static errno_t cache_req_cache_check(struct tevent_req *req) /* Cache miss or the cache is expired. We need to get the updated * information before returning it. */
if (DOM_HAS_VIEWS(state->input->domain)) {
extra_flag = EXTRA_INPUT_MAYBE_WITH_VIEW;
}
subreq = sss_dp_get_account_send(state, state->rctx, state->input->domain, true, state->input->dp_type,
-- 2.1.0
0002-cache_req-add-support-for-UPN.patch
From 6e3ba71eb4a84f90d024b7d888cc139237325917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?=pbrezina@redhat.com Date: Wed, 6 May 2015 12:16:46 +0200 Subject: [PATCH 2/3] cache_req: add support for UPN
src/db/sysdb.h | 10 + src/db/sysdb_search.c | 117 ++++++++ src/responder/common/responder_cache_req.c | 109 +++++++- src/responder/common/responder_cache_req.h | 4 +- src/responder/common/responder_get_domains.c | 21 +- src/tests/cmocka/common_mock_resp.h | 2 +- src/tests/cmocka/common_mock_resp_dp.c | 5 +- src/tests/cmocka/test_responder_cache_req.c | 388 ++++++++++++++++++++++++++- 8 files changed, 632 insertions(+), 24 deletions(-)
diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 3c76fb0ce849ad03c7848dfb43dbbfeac6bce7c2..9d76401292338a47586d7a44a92a0c1cf711f283 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -609,6 +609,11 @@ int sysdb_getpwuid(TALLOC_CTX *mem_ctx, uid_t uid, struct ldb_result **res);
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **res);
- int sysdb_enumpwent(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, struct ldb_result **res);
@@ -681,6 +686,11 @@ int sysdb_initgroups(TALLOC_CTX *mem_ctx, const char *name, struct ldb_result **res);
+int sysdb_initgroups_by_upn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **res);
- int sysdb_initgroups_with_views(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *name,
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 5f33b225a31e1c1add7f776215d500fb09e127ca..02956f83296273f730df0fd6231657e881cc9ce8 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, return filter; }
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- static const char *attrs[] = SYSDB_PW_ATTRS;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn() failed.\n");
Pavel, I think you forgot to free memory here.
return ret;
- }
- res = talloc_zero(tmp_ctx, struct ldb_result);
- if (res == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "talloc_zero() failed.\n");
ret = ENOMEM;
goto done;
- }
- if (ret == ENOENT) {
res->count = 0;
res->msgs = NULL;
- } else {
res->count = 1;
res->msgs = talloc_array(res, struct ldb_message *, 1);
if (res->msgs == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
ret = ENOMEM;
goto done;
}
res->msgs[0] = talloc_steal(res->msgs, msg);
- }
- *_res = talloc_steal(mem_ctx, res);
- ret = EOK;
+done:
- talloc_free(tmp_ctx);
- return ret;
+}
- int sysdb_enumpwent_filter(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *name_filter,
@@ -953,6 +1006,70 @@ done: return ret; }
+int sysdb_initgroups_by_upn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- const char *sysdb_name;
- static const char *attrs[] = SYSDB_INITGR_ATTRS;
- size_t i;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn() failed.\n");
There is the same case of forgotten free memory.
return ret;
- }
- res = talloc_zero(tmp_ctx, struct ldb_result);
- if (res == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "talloc_zero() failed.\n");
ret = ENOMEM;
goto done;
- }
- if (ret == ENOENT) {
res->count = 0;
res->msgs = NULL;
- } else {
sysdb_name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
if (sysdb_name == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "Sysdb entry does not have a name.\n");
return EINVAL;
}
ret = sysdb_initgroups(tmp_ctx, domain, sysdb_name, &res);
if (ret == EOK && DOM_HAS_VIEWS(domain)) {
for (i = 0; i < res->count; i++) {
ret = sysdb_add_overrides_to_object(domain, res->msgs[i],
NULL, NULL);
if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
"sysdb_add_overrides_to_object() failed.\n");
return ret;
}
}
}
- }
- *_res = talloc_steal(mem_ctx, res);
- ret = EOK;
+done:
- talloc_free(tmp_ctx);
- return ret;
+}
- int sysdb_initgroups_with_views(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *name,
diff --git a/src/responder/common/responder_cache_req.c b/src/responder/common/responder_cache_req.c index fba5001476481040ed962dbbd9b01cc16fe0ba74..1702c006a50d77a132707b42995aa34a05f4a1dd 100644 --- a/src/responder/common/responder_cache_req.c +++ b/src/responder/common/responder_cache_req.c @@ -70,6 +70,7 @@ struct cache_req_input { enum cache_req_type type;
/* Provided input. */
- const char *raw_name; const char *orig_name; uint32_t id; const char *cert;
@@ -113,15 +114,22 @@ cache_req_input_create(TALLOC_CTX *mem_ctx, /* Check that input parameters match selected type. */ switch (input->type) { case CACHE_REQ_USER_BY_NAME:
case CACHE_REQ_USER_BY_UPN: case CACHE_REQ_GROUP_BY_NAME: case CACHE_REQ_USER_BY_FILTER: case CACHE_REQ_GROUP_BY_FILTER: case CACHE_REQ_INITGROUPS:
case CACHE_REQ_INITGROUPS_BY_UPN: if (name == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Bug: name cannot be NULL!\n"); goto fail; }
input->raw_name = talloc_strdup(input, name);
if (input->raw_name == NULL) {
goto fail;
}
input->orig_name = talloc_strdup(input, name); if (input->orig_name == NULL) { goto fail;
@@ -152,6 +160,7 @@ cache_req_input_create(TALLOC_CTX *mem_ctx, /* Resolve Data Provider request type. */ switch (type) { case CACHE_REQ_USER_BY_NAME:
- case CACHE_REQ_USER_BY_UPN: case CACHE_REQ_USER_BY_ID: input->dp_type = SSS_DP_USER; break;
@@ -162,6 +171,7 @@ cache_req_input_create(TALLOC_CTX *mem_ctx, break;
case CACHE_REQ_INITGROUPS:
- case CACHE_REQ_INITGROUPS_BY_UPN: input->dp_type = SSS_DP_INITGROUPS; break;
@@ -222,10 +232,12 @@ cache_req_input_set_domain(struct cache_req_input *input,
switch (input->type) { case CACHE_REQ_USER_BY_NAME:
- case CACHE_REQ_USER_BY_UPN: case CACHE_REQ_GROUP_BY_NAME: case CACHE_REQ_USER_BY_FILTER: case CACHE_REQ_GROUP_BY_FILTER: case CACHE_REQ_INITGROUPS:
- case CACHE_REQ_INITGROUPS_BY_UPN: name = sss_get_cased_name(tmp_ctx, input->orig_name, domain->case_sensitive); if (name == NULL) {
@@ -286,6 +298,49 @@ done: return ret; }
+static bool +cache_req_input_is_upn(struct cache_req_input *input) +{
- switch (input->type) {
- case CACHE_REQ_USER_BY_UPN:
- case CACHE_REQ_INITGROUPS_BY_UPN:
return true;
- default:
return false;
- }
+}
+static bool +cache_req_input_assume_upn(struct cache_req_input *input) +{
- bool ret;
- if (input->raw_name == NULL || strchr(input->raw_name, '@') == NULL) {
return false;
- }
- switch (input->type) {
- case CACHE_REQ_USER_BY_NAME:
input->type = CACHE_REQ_USER_BY_UPN;
ret = true;
break;
- case CACHE_REQ_INITGROUPS:
input->type = CACHE_REQ_INITGROUPS_BY_UPN;
ret = true;
break;
- default:
ret = false;
break;
- }
- if (ret == true) {
DEBUG(SSSDBG_TRACE_FUNC, "Assuming UPN %s\n", input->raw_name);
cache_req_input_set_orig_name(input, input->raw_name);
Pavel, maybe we could check return value of the function cache_req_input_set_orig_name return value. I looked at src/responder/common/responder_cache_req.c:199 it return EOK or ENOMEM if there is no memory.
- }
- return ret;
+}
- static errno_t cache_req_check_ncache(struct cache_req_input *input, struct sss_nc_ctx *ncache, int neg_timeout)
@@ -294,7 +349,9 @@ static errno_t cache_req_check_ncache(struct cache_req_input *input,
switch (input->type) { case CACHE_REQ_USER_BY_NAME:
- case CACHE_REQ_USER_BY_UPN: case CACHE_REQ_INITGROUPS:
- case CACHE_REQ_INITGROUPS_BY_UPN: ret = sss_ncache_check_user(ncache, neg_timeout, input->domain, input->dom_objname); break;
@@ -332,7 +389,9 @@ static void cache_req_add_to_ncache(struct cache_req_input *input,
switch (input->type) { case CACHE_REQ_USER_BY_NAME:
- case CACHE_REQ_USER_BY_UPN: case CACHE_REQ_INITGROUPS:
- case CACHE_REQ_INITGROUPS_BY_UPN: ret = sss_ncache_set_user(ncache, false, input->domain, input->dom_objname); break;
@@ -375,8 +434,10 @@ static void cache_req_add_to_ncache_global(struct cache_req_input *input, /* Nothing to do, adding a wildcard request to ncache doesn't * make sense */ case CACHE_REQ_USER_BY_NAME:
- case CACHE_REQ_USER_BY_UPN: case CACHE_REQ_GROUP_BY_NAME: case CACHE_REQ_INITGROUPS:
- case CACHE_REQ_INITGROUPS_BY_UPN: /* Nothing to do. Those types are already in ncache for selected * domains. */ ret = EOK;
@@ -418,6 +479,11 @@ static errno_t cache_req_get_object(TALLOC_CTX *mem_ctx, ret = sysdb_getpwnam_with_views(mem_ctx, input->domain, input->dom_objname, &result); break;
- case CACHE_REQ_USER_BY_UPN:
one_item_only = true;
ret = sysdb_getpwupn(mem_ctx, input->domain,
input->dom_objname, &result);
break; case CACHE_REQ_USER_BY_ID: one_item_only = true; ret = sysdb_getpwuid_with_views(mem_ctx, input->domain,
@@ -438,6 +504,11 @@ static errno_t cache_req_get_object(TALLOC_CTX *mem_ctx, ret = sysdb_initgroups_with_views(mem_ctx, input->domain, input->dom_objname, &result); break;
- case CACHE_REQ_INITGROUPS_BY_UPN:
one_item_only = false;
ret = sysdb_initgroups_by_upn(mem_ctx, input->domain,
input->dom_objname, &result);
break; case CACHE_REQ_USER_BY_CERT: one_item_only = true; ret = sysdb_search_user_by_cert(mem_ctx, input->domain,
@@ -618,6 +689,8 @@ static errno_t cache_req_cache_check(struct tevent_req *req)
if (DOM_HAS_VIEWS(state->input->domain)) { extra_flag = EXTRA_INPUT_MAYBE_WITH_VIEW;
} else if (cache_req_input_is_upn(state->input)) {
extra_flag = EXTRA_NAME_IS_UPN; } switch (ret) {
@@ -821,23 +894,35 @@ static void cache_req_input_parsed(struct tevent_req *subreq) char *name; char *domain; errno_t ret;
bool maybe_upn;
req = tevent_req_callback_data(subreq, struct tevent_req); state = tevent_req_data(req, struct cache_req_state);
ret = sss_parse_inp_recv(subreq, state, &name, &domain);
- if (ret != EOK) {
tevent_req_error(req, ret);
return;
- }
- if (strcmp(name, state->input->orig_name) != 0) {
/* The name has changed during input parse phase. */
ret = cache_req_input_set_orig_name(state->input, name);
if (ret != EOK) {
switch (ret) {
case EOK:
if (strcmp(name, state->input->orig_name) != 0) {
/* The name has changed during input parse phase. */
ret = cache_req_input_set_orig_name(state->input, name);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
}
break;
case ERR_DOMAIN_NOT_FOUND:
maybe_upn = cache_req_input_assume_upn(state->input);
if (!maybe_upn) { tevent_req_error(req, ret); return; }
domain = NULL;
break;
default:
tevent_req_error(req, ret);
return; } ret = cache_req_select_domains(req, domain);
@@ -943,6 +1028,12 @@ static void cache_req_done(struct tevent_req *subreq) }
if (state->check_next == false) {
if (ret == ENOENT && cache_req_input_assume_upn(state->input)) {
/* search by upn now */
cache_req_select_domains(req, NULL);
return;
}
tevent_req_error(req, ret); return; }
diff --git a/src/responder/common/responder_cache_req.h b/src/responder/common/responder_cache_req.h index 9e3f88a1427f3dcbde9f81df2ec647821b7aa931..474d42647586c044925c83a0641200d065862b87 100644 --- a/src/responder/common/responder_cache_req.h +++ b/src/responder/common/responder_cache_req.h @@ -29,13 +29,15 @@
enum cache_req_type { CACHE_REQ_USER_BY_NAME,
- CACHE_REQ_USER_BY_UPN, CACHE_REQ_USER_BY_ID, CACHE_REQ_GROUP_BY_NAME, CACHE_REQ_GROUP_BY_ID, CACHE_REQ_INITGROUPS,
- CACHE_REQ_INITGROUPS_BY_UPN, CACHE_REQ_USER_BY_CERT, CACHE_REQ_USER_BY_FILTER,
- CACHE_REQ_GROUP_BY_FILTER,
CACHE_REQ_GROUP_BY_FILTER };
struct cache_req_input;
diff --git a/src/responder/common/responder_get_domains.c b/src/responder/common/responder_get_domains.c index 8fbab082aee02f6d5fae85b04bab047e59d20b44..7fd0b48eef12c741349996ff582b44202de3f090 100644 --- a/src/responder/common/responder_get_domains.c +++ b/src/responder/common/responder_get_domains.c @@ -446,6 +446,7 @@ struct sss_parse_inp_state {
char *name; char *domname;
errno_t error; };
static void sss_parse_inp_done(struct tevent_req *subreq);
@@ -527,14 +528,24 @@ static void sss_parse_inp_done(struct tevent_req *subreq) return; }
- state->error = ERR_OK;
ret = sss_parse_name_for_domains(state, state->rctx->domains, state->rctx->default_domain, state->rawinp, &state->domname, &state->name);
- if (ret != EOK) {
- if (ret == EAGAIN && state->domname != NULL && state->name == NULL) {
DEBUG(SSSDBG_OP_FAILURE,
"Unknown domain in [%s]\n", state->rawinp);
state->error = ERR_DOMAIN_NOT_FOUND;
- } else if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Invalid name received [%s]\n", state->rawinp);
tevent_req_error(req, ERR_INPUT_PARSE);
state->error = ERR_INPUT_PARSE;
- }
- if (state->error != ERR_OK) {
tevent_req_error(req, state->error); return; }
@@ -548,7 +559,9 @@ errno_t sss_parse_inp_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct sss_parse_inp_state *state = tevent_req_data(req, struct sss_parse_inp_state);
- TEVENT_REQ_RETURN_ON_ERROR(req);
if (state->error != ERR_DOMAIN_NOT_FOUND) {
TEVENT_REQ_RETURN_ON_ERROR(req);
}
if (_name) { *_name = talloc_steal(mem_ctx, state->name);
@@ -558,5 +571,5 @@ errno_t sss_parse_inp_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, *_domname = talloc_steal(mem_ctx, state->domname); }
- return EOK;
- return state->error; }
I have not read further. It is about tests and I will read tomorow with clear mind. I need understand this refactor for my other work. :-)
Petr
diff --git a/src/tests/cmocka/common_mock_resp.h b/src/tests/cmocka/common_mock_resp.h index 88c09c88d9f39c6335b8c857319cca42cba9be4f..a4d8f55c701ee0c2fa6f0b9d8c34fdaf518a95a9 100644 --- a/src/tests/cmocka/common_mock_resp.h +++ b/src/tests/cmocka/common_mock_resp.h @@ -59,6 +59,6 @@ void mock_account_recv(uint16_t dp_err, uint32_t dp_ret, char *msg,
void mock_account_recv_simple(void);
-void mock_parse_inp(const char *name, const char *domname); +void mock_parse_inp(const char *name, const char *domname, errno_t ret);
#endif /* __COMMON_MOCK_RESP_H_ */ diff --git a/src/tests/cmocka/common_mock_resp_dp.c b/src/tests/cmocka/common_mock_resp_dp.c index a67ceee4a43184d9894c19a5c11161aca4e1caff..f62606eb8a33b6417bbd32a7dccdbeaabd05818f 100644 --- a/src/tests/cmocka/common_mock_resp_dp.c +++ b/src/tests/cmocka/common_mock_resp_dp.c @@ -92,13 +92,14 @@ errno_t sss_parse_inp_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, *_name = sss_mock_ptr_type(char *); *_domname = sss_mock_ptr_type(char *);
- return test_request_recv(req);
- return sss_mock_type(errno_t); }
-void mock_parse_inp(const char *name, const char *domname) +void mock_parse_inp(const char *name, const char *domname, errno_t ret) { will_return(sss_parse_inp_recv, name); will_return(sss_parse_inp_recv, domname);
will_return(sss_parse_inp_recv, ret); }
/* Mock subdomain requests */
diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c index bc6e2dc8f86a8fa8dc322da10fff4883f075ec7d..7db87ccc816ea0e30e707ec8c2fa4666441892a8 100644 --- a/src/tests/cmocka/test_responder_cache_req.c +++ b/src/tests/cmocka/test_responder_cache_req.c @@ -34,6 +34,7 @@ #define TEST_ID_PROVIDER "ldap"
#define TEST_USER_NAME "test-user" +#define TEST_UPN"upn@upndomain.com" #define TEST_USER_ID 1000 #define TEST_GROUP_NAME "test-group" #define TEST_GROUP_ID 1000 @@ -89,6 +90,7 @@ __wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx, uint32_t opt_id, const char *extra) {
- struct sysdb_attrs *attrs = NULL; struct cache_req_test_ctx *ctx = NULL; errno_t ret;
@@ -96,9 +98,15 @@ __wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx, ctx->dp_called = true;
if (ctx->create_user) {
attrs = sysdb_new_attrs(ctx);
assert_non_null(attrs);
ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, TEST_UPN);
assert_int_equal(ret, EOK);
ret = sysdb_store_user(ctx->tctx->dom, TEST_USER_NAME, "pwd", TEST_USER_ID, 1000, NULL, NULL, NULL,
"cn=test-user,dc=test", NULL, NULL,
"cn=test-user,dc=test", attrs, NULL, 1000, time(NULL)); assert_int_equal(ret, EOK); }
@@ -257,7 +265,7 @@ void test_user_by_name_multiple_domains_found(void **state)
will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL);
mock_parse_inp(name, NULL, ERR_OK);
req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev, test_ctx->rctx, test_ctx->ncache, 10, 0,
@@ -300,7 +308,7 @@ void test_user_by_name_multiple_domains_notfound(void **state)
will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL);
mock_parse_inp(name, NULL, ERR_OK);
req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev, test_ctx->rctx, test_ctx->ncache, 10, 0,
@@ -360,7 +368,7 @@ void test_user_by_name_multiple_domains_parse(void **state) req_mem_ctx = talloc_new(global_talloc_context); check_leaks_push(req_mem_ctx);
- mock_parse_inp(name, "responder_cache_req_test_d");
mock_parse_inp(name, "responder_cache_req_test_d", ERR_OK);
req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev, test_ctx->rctx, test_ctx->ncache, 10, 0,
@@ -626,6 +634,363 @@ void test_user_by_name_missing_notfound(void **state) assert_true(test_ctx->dp_called); }
+void test_user_by_upn_multiple_domains_found(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- struct sysdb_attrs *attrs = NULL;
- struct sss_domain_info *domain = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- const char *name = TEST_USER_NAME;
- const char *upn = TEST_UPN;
- const char *ldbname = NULL;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- domain = find_domain_by_name(test_ctx->tctx->dom,
"responder_cache_req_test_d", true);
- assert_non_null(domain);
- attrs = sysdb_new_attrs(test_ctx);
- assert_non_null(attrs);
- ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
- assert_int_equal(ret, EOK);
- ret = sysdb_store_user(domain, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, 1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
- will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
+}
+void test_user_by_upn_multiple_domains_notfound(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- const char *upn = TEST_UPN;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
- will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_true(test_ctx->dp_called);
+}
+void test_user_by_upn_cache_valid(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- struct sysdb_attrs *attrs = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- const char *name = TEST_USER_NAME;
- const char *upn = TEST_UPN;
- const char *ldbname = NULL;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- attrs = sysdb_new_attrs(test_ctx);
- assert_non_null(attrs);
- ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
- assert_int_equal(ret, EOK);
- ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, 1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
+}
+void test_user_by_upn_cache_expired(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- struct sysdb_attrs *attrs = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- const char *name = TEST_USER_NAME;
- const char *upn = TEST_UPN;
- const char *ldbname = NULL;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- attrs = sysdb_new_attrs(test_ctx);
- assert_non_null(attrs);
- ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
- assert_int_equal(ret, EOK);
- ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, -1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- /* DP should be contacted */
- will_return(__wrap_sss_dp_get_account_send, test_ctx);
- mock_account_recv_simple();
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
+}
+void test_user_by_upn_cache_midpoint(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- struct sysdb_attrs *attrs = NULL;
- const char *upn = TEST_UPN;
- const char *name = TEST_USER_NAME;
- const char *ldbname = NULL;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- attrs = sysdb_new_attrs(test_ctx);
- assert_non_null(attrs);
- ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
- assert_int_equal(ret, EOK);
- ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, 50, time(NULL) - 26);
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- /* DP should be contacted without callback */
- will_return(__wrap_sss_dp_get_account_send, test_ctx);
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 50,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
+}
+void test_user_by_upn_ncache(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- const char *upn = TEST_UPN;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- ret = sss_ncache_set_user(test_ctx->ncache, false,
test_ctx->tctx->dom, upn);
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_false(test_ctx->dp_called);
+}
+void test_user_by_upn_missing_found(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- const char *upn = TEST_UPN;
- const char *name = TEST_USER_NAME;
- const char *ldbname = NULL;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- will_return(__wrap_sss_dp_get_account_send, test_ctx);
- mock_account_recv_simple();
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- test_ctx->create_user = true;
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
+}
+void test_user_by_upn_missing_notfound(void **state) +{
- struct cache_req_test_ctx *test_ctx = NULL;
- TALLOC_CTX *req_mem_ctx = NULL;
- struct tevent_req *req = NULL;
- const char *upn = TEST_UPN;
- errno_t ret;
- test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- will_return(__wrap_sss_dp_get_account_send, test_ctx);
- mock_account_recv_simple();
- mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_true(test_ctx->dp_called);
+}
- void test_user_by_id_multiple_domains_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
@@ -994,7 +1359,7 @@ void test_group_by_name_multiple_domains_found(void **state)
will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL);
mock_parse_inp(name, NULL, ERR_OK);
req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev, test_ctx->rctx, test_ctx->ncache, 10, 0,
@@ -1037,7 +1402,7 @@ void test_group_by_name_multiple_domains_notfound(void **state)
will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL);
mock_parse_inp(name, NULL, ERR_OK);
req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev, test_ctx->rctx, test_ctx->ncache, 10, 0,
@@ -1095,7 +1460,7 @@ void test_group_by_name_multiple_domains_parse(void **state) req_mem_ctx = talloc_new(global_talloc_context); check_leaks_push(req_mem_ctx);
- mock_parse_inp(name, "responder_cache_req_test_d");
mock_parse_inp(name, "responder_cache_req_test_d", ERR_OK);
req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev, test_ctx->rctx, test_ctx->ncache, 10, 0,
@@ -1910,6 +2275,15 @@ int main(int argc, const char *argv[]) new_multi_domain_test(user_by_name_multiple_domains_notfound), new_multi_domain_test(user_by_name_multiple_domains_parse),
new_single_domain_test(user_by_upn_cache_valid),
new_single_domain_test(user_by_upn_cache_expired),
new_single_domain_test(user_by_upn_cache_midpoint),
new_single_domain_test(user_by_upn_ncache),
new_single_domain_test(user_by_upn_missing_found),
new_single_domain_test(user_by_upn_missing_notfound),
new_multi_domain_test(user_by_upn_multiple_domains_found),
new_multi_domain_test(user_by_upn_multiple_domains_notfound),
new_single_domain_test(user_by_id_cache_valid), new_single_domain_test(user_by_id_cache_expired), new_single_domain_test(user_by_id_cache_midpoint),
-- 2.1.0
0003-cache_req-tests-reduce-code-duplication.patch
From e41f96a47f2b0f8d3e07e34af83e9a516d29df34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?=pbrezina@redhat.com Date: Mon, 14 Sep 2015 11:06:45 +0200 Subject: [PATCH 3/3] cache_req tests: reduce code duplication
src/tests/cmocka/test_responder_cache_req.c | 1624 +++++++-------------------- 1 file changed, 394 insertions(+), 1230 deletions(-)
diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c index 7db87ccc816ea0e30e707ec8c2fa4666441892a8..2af481494319d0d01d29d0c243020c5adcb06d3a 100644 --- a/src/tests/cmocka/test_responder_cache_req.c +++ b/src/tests/cmocka/test_responder_cache_req.c @@ -52,6 +52,27 @@ test_multi_domain_setup, \ test_multi_domain_teardown)
+#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
- TALLOC_CTX *req_mem_ctx; \
- struct tevent_req *req; \
- errno_t ret; \
\
- req_mem_ctx = talloc_new(global_talloc_context); \
- check_leaks_push(req_mem_ctx); \
\
- req = send_fn(req_mem_ctx, ctx->tctx->ev, ctx->rctx, \
ctx->ncache, 10, crp, \
(dom == NULL ? NULL : dom->name), lookup); \
- assert_non_null(req); \
- tevent_req_set_callback(req, done_fn, ctx); \
\
- ret = test_ev_loop(ctx->tctx); \
- assert_int_equal(ret, expret); \
- assert_true(check_leaks_pop(req_mem_ctx)); \
\
- talloc_free(req_mem_ctx); \
+} while (0)
- struct cache_req_test_ctx { struct sss_test_ctx *tctx; struct resp_ctx *rctx;
@@ -80,46 +101,6 @@ struct cli_protocol_version *register_cli_protocol_version(void) return version; }
-struct tevent_req * -__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
struct resp_ctx *rctx,
struct sss_domain_info *dom,
bool fast_reply,
enum sss_dp_acct_type type,
const char *opt_name,
uint32_t opt_id,
const char *extra)
-{
- struct sysdb_attrs *attrs = NULL;
- struct cache_req_test_ctx *ctx = NULL;
- errno_t ret;
- ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
- ctx->dp_called = true;
- if (ctx->create_user) {
attrs = sysdb_new_attrs(ctx);
assert_non_null(attrs);
ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, TEST_UPN);
assert_int_equal(ret, EOK);
ret = sysdb_store_user(ctx->tctx->dom, TEST_USER_NAME, "pwd",
TEST_USER_ID, 1000, NULL, NULL, NULL,
"cn=test-user,dc=test", attrs, NULL,
1000, time(NULL));
assert_int_equal(ret, EOK);
- }
- if (ctx->create_group) {
ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
TEST_GROUP_ID, NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);
- }
- return test_req_succeed_send(mem_ctx, rctx->ev);
-}
- static void cache_req_user_by_name_test_done(struct tevent_req *req) { struct cache_req_test_ctx *ctx = NULL;
@@ -176,6 +157,173 @@ static void cache_req_group_by_id_test_done(struct tevent_req *req) ctx->tctx->done = true; }
+static void prepare_user(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
uint64_t timeout,
time_t time)
+{
- struct sysdb_attrs *attrs;
- errno_t ret;
- attrs = sysdb_new_attrs(mem_ctx);
- assert_non_null(attrs);
- ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, TEST_UPN);
- assert_int_equal(ret, EOK);
- ret = sysdb_store_user(domain, TEST_USER_NAME, "pwd",
TEST_USER_ID, TEST_GROUP_ID, NULL, NULL, NULL,
"cn=test-user,dc=test", attrs, NULL,
timeout, time);
- assert_int_equal(ret, EOK);
+}
+static void run_user_by_name(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_USER_NAME, exp_ret);
+}
+static errno_t run_user_by_upn(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_UPN, exp_ret);
+}
+static errno_t run_user_by_id(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_id_send,
cache_req_user_by_id_test_done, domain,
cache_refresh_percent, TEST_USER_ID, exp_ret);
+}
+static void check_user(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *exp_dom)
+{
- const char *ldbname;
- const char *ldbupn;
- uid_t ldbuid;
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, TEST_USER_NAME);
- ldbupn = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_UPN, NULL);
- assert_non_null(ldbupn);
- assert_string_equal(ldbupn, TEST_UPN);
- ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_UIDNUM, 0);
- assert_int_equal(ldbuid, TEST_USER_ID);
- assert_non_null(test_ctx->domain);
- assert_string_equal(exp_dom->name, test_ctx->domain->name);
+}
+static void prepare_group(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
uint64_t timeout,
time_t time)
+{
- errno_t ret;
- ret = sysdb_store_group(domain, TEST_GROUP_NAME, TEST_GROUP_ID, NULL,
timeout, time);
- assert_int_equal(ret, EOK);
+}
+static errno_t run_group_by_name(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_group_by_name_send,
cache_req_group_by_name_test_done, domain,
cache_refresh_percent, TEST_GROUP_NAME, exp_ret);
+}
+static errno_t run_group_by_id(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_group_by_id_send,
cache_req_group_by_id_test_done, domain,
cache_refresh_percent, TEST_GROUP_ID, exp_ret);
+}
+static void check_group(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *exp_dom)
+{
- const char *ldbname;
- gid_t ldbgid;
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, TEST_GROUP_NAME);
- ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_GIDNUM, 0);
- assert_int_equal(ldbgid, TEST_USER_ID);
- assert_non_null(test_ctx->domain);
- assert_string_equal(exp_dom->name, test_ctx->domain->name);
+}
+struct tevent_req * +__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
struct resp_ctx *rctx,
struct sss_domain_info *dom,
bool fast_reply,
enum sss_dp_acct_type type,
const char *opt_name,
uint32_t opt_id,
const char *extra)
+{
- struct cache_req_test_ctx *ctx = NULL;
- errno_t ret;
- ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
- ctx->dp_called = true;
- if (ctx->create_user) {
prepare_user(ctx, ctx->tctx->dom, 1000, time(NULL));
- }
- if (ctx->create_group) {
ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
TEST_GROUP_ID, NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);
- }
- return test_req_succeed_send(mem_ctx, rctx->ev);
+}
- static int test_single_domain_setup(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
@@ -243,83 +391,40 @@ void test_user_by_name_multiple_domains_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL; struct sss_domain_info *domain = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup user. */ domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_d", true); assert_non_null(domain);
- ret = sysdb_store_user(domain, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
prepare_user(test_ctx, domain, 1000, time(NULL));
/* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL, ERR_OK);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
mock_parse_inp(TEST_USER_NAME, NULL, ERR_OK);
/* Test. */
run_user_by_name(test_ctx, NULL, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
check_user(test_ctx, domain); }
void test_user_by_name_multiple_domains_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL, ERR_OK);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
mock_parse_inp(TEST_USER_NAME, NULL, ERR_OK);
/* Test. */
run_user_by_name(test_ctx, NULL, 0, ENOENT); assert_true(test_ctx->dp_called); }
@@ -331,45 +436,41 @@ void test_user_by_name_multiple_domains_parse(void **state) struct tevent_req *req = NULL; const char *name = TEST_USER_NAME; const char *fqn = NULL;
const char *ldbname = NULL;
uid_t uid = 2000;
uid_t ldbuid; errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Add user to the first domain. */
- /* Add user to the first domain with different uid then test user. */ domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_a", true); assert_non_null(domain);
- ret = sysdb_store_user(domain, name, "pwd", 1000, 1000,
- ret = sysdb_store_user(domain, name, "pwd", 2000, 1000, NULL, NULL, NULL, "cn=test-user,dc=test", NULL, NULL, 1000, time(NULL)); assert_int_equal(ret, EOK);
- /* Add user to the last domain, with different uid. */
/* Add test user to the last domain. */
domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_d", true); assert_non_null(domain);
- ret = sysdb_store_user(domain, name, "pwd", uid, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 1000, time(NULL));
- assert_int_equal(ret, EOK);
prepare_user(test_ctx, domain, 1000, time(NULL));
/* Append domain name to the username. */ fqn = talloc_asprintf(test_ctx, "%s@%s", name, "responder_cache_req_test_d"); assert_non_null(fqn);
/* Mock values. */
mock_parse_inp(name, "responder_cache_req_test_d", ERR_OK);
/* Test. */ req_mem_ctx = talloc_new(global_talloc_context); check_leaks_push(req_mem_ctx);
- mock_parse_inp(name, "responder_cache_req_test_d", ERR_OK);
req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev, test_ctx->rctx, test_ctx->ncache, 10, 0, NULL, fqn);
@@ -381,22 +482,7 @@ void test_user_by_name_multiple_domains_parse(void **state) assert_true(check_leaks_pop(req_mem_ctx)); assert_false(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_UIDNUM, 0);
- assert_int_equal(ldbuid, uid);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
check_user(test_ctx, domain);
assert_non_null(test_ctx->name); assert_string_equal(name, test_ctx->name);
@@ -405,589 +491,257 @@ void test_user_by_name_multiple_domains_parse(void **state) void test_user_by_name_cache_valid(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);
- /* Setup user. */
- prepare_user(test_ctx, test_ctx->tctx->dom, 1000, time(NULL));
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_name_cache_expired(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, -1000, time(NULL));
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */ /* DP should be contacted */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_name_cache_midpoint(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 50, time(NULL) - 26);
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */ /* DP should be contacted without callback */ will_return(__wrap_sss_dp_get_account_send, test_ctx);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 50,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_name_ncache(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME; errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup user. */ ret = sss_ncache_set_user(test_ctx->ncache, false,
test_ctx->tctx->dom, name);
test_ctx->tctx->dom, TEST_USER_NAME); assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_false(test_ctx->dp_called); }
void test_user_by_name_missing_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
test_ctx->create_user = true;
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_name_missing_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_true(test_ctx->dp_called); }
void test_user_by_upn_multiple_domains_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
struct sysdb_attrs *attrs = NULL; struct sss_domain_info *domain = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *upn = TEST_UPN;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup user. */ domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_d", true); assert_non_null(domain);
- attrs = sysdb_new_attrs(test_ctx);
- assert_non_null(attrs);
- ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
- assert_int_equal(ret, EOK);
- ret = sysdb_store_user(domain, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, 1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
prepare_user(test_ctx, domain, 1000, time(NULL));
/* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0); mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_upn(test_ctx, NULL, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
check_user(test_ctx, domain); }
void test_user_by_upn_multiple_domains_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *upn = TEST_UPN;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0); mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ENOENT); assert_true(test_ctx->dp_called); }
void test_user_by_upn_cache_valid(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
struct sysdb_attrs *attrs = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *upn = TEST_UPN;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
attrs = sysdb_new_attrs(test_ctx);
assert_non_null(attrs);
ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
assert_int_equal(ret, EOK);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 1000, time(NULL));
/* Mock values. */ mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_upn_cache_expired(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
struct sysdb_attrs *attrs = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *upn = TEST_UPN;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
attrs = sysdb_new_attrs(test_ctx);
assert_non_null(attrs);
ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
assert_int_equal(ret, EOK);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, -1000, time(NULL));
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */ /* DP should be contacted */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple(); mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_upn(test_ctx, NULL, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_upn_cache_midpoint(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
struct sysdb_attrs *attrs = NULL;
const char *upn = TEST_UPN;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
attrs = sysdb_new_attrs(test_ctx);
assert_non_null(attrs);
ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, upn);
assert_int_equal(ret, EOK);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", attrs,
NULL, 50, time(NULL) - 26);
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */ /* DP should be contacted without callback */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 50,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_upn(test_ctx, NULL, 50, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_upn_ncache(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *upn = TEST_UPN; errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup user. */ ret = sss_ncache_set_user(test_ctx->ncache, false,
test_ctx->tctx->dom, upn);
test_ctx->tctx->dom, TEST_UPN); assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- /* Mock values. */ mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ENOENT); assert_false(test_ctx->dp_called); }
void test_user_by_upn_missing_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *upn = TEST_UPN;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple(); mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
test_ctx->create_user = true;
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_upn(test_ctx, NULL, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_upn_missing_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *upn = TEST_UPN;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple(); mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
- req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
NULL, upn);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_upn(test_ctx, NULL, 0, ENOENT); assert_true(test_ctx->dp_called); }
@@ -995,342 +749,140 @@ void test_user_by_id_multiple_domains_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL; struct sss_domain_info *domain = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
uid_t uid = TEST_USER_ID;
const char *ldbname = NULL;
uid_t ldbuid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup user. */ domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_d", true); assert_non_null(domain);
- ret = sysdb_store_user(domain, name, "pwd", uid, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
prepare_user(test_ctx, domain, 1000, time(NULL));
/* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_id(test_ctx, NULL, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_UIDNUM, 0);
- assert_int_equal(ldbuid, uid);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
check_user(test_ctx, domain); }
void test_user_by_id_multiple_domains_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
uid_t uid = TEST_USER_ID;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_user_by_id(test_ctx, NULL, 0, ENOENT); assert_true(test_ctx->dp_called); }
void test_user_by_id_cache_valid(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
uid_t uid = TEST_USER_ID;
uid_t ldbuid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", uid, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);
- /* Setup user. */
- prepare_user(test_ctx, test_ctx->tctx->dom, 1000, time(NULL));
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_UIDNUM, 0);
- assert_int_equal(ldbuid, uid);
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_id_cache_expired(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
uid_t uid = TEST_USER_ID;
uid_t ldbuid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", uid, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, -1000, time(NULL));
assert_int_equal(ret, EOK);
- /* Setup user. */
- prepare_user(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- /* DP should be contacted */
- /* Mock values. */
- /* DP should be contacted. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_UIDNUM, 0);
- assert_int_equal(ldbuid, uid);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_id_cache_midpoint(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
uid_t uid = TEST_USER_ID;
uid_t ldbuid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_user(test_ctx->tctx->dom, name, "pwd", uid, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 50, time(NULL) - 26);
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */ /* DP should be contacted without callback */ will_return(__wrap_sss_dp_get_account_send, test_ctx);
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 50,
test_ctx->tctx->dom->name, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_UIDNUM, 0);
- assert_int_equal(ldbuid, uid);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_id_ncache(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
uid_t uid = TEST_USER_ID; errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sss_ncache_set_uid(test_ctx->ncache, false, NULL, uid);
- /* Setup user. */
- ret = sss_ncache_set_uid(test_ctx->ncache, false, NULL, TEST_USER_ID); assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_false(test_ctx->dp_called); }
void test_user_by_id_missing_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_USER_NAME;
const char *ldbname = NULL;
uid_t uid = TEST_USER_ID;
uid_t ldbuid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
test_ctx->create_user = true;
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_UIDNUM, 0);
- assert_int_equal(ldbuid, uid);
check_user(test_ctx, test_ctx->tctx->dom); }
void test_user_by_id_missing_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
uid_t uid = TEST_USER_ID;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_user_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, uid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_user_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_true(test_ctx->dp_called); }
@@ -1338,82 +890,39 @@ void test_group_by_name_multiple_domains_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL; struct sss_domain_info *domain = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup group. */ domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_d", true); assert_non_null(domain);
- prepare_group(test_ctx, domain, 1000, time(NULL));
- ret = sysdb_store_group(domain, name, TEST_GROUP_ID, NULL,
1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL, ERR_OK);
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
mock_parse_inp(TEST_GROUP_NAME, NULL, ERR_OK);
/* Test. */
run_group_by_name(test_ctx, NULL, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
check_group(test_ctx, domain); }
void test_group_by_name_multiple_domains_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- mock_parse_inp(name, NULL, ERR_OK);
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
mock_parse_inp(TEST_GROUP_NAME, NULL, ERR_OK);
/* Test. */
run_group_by_name(test_ctx, NULL, 0, ENOENT); assert_true(test_ctx->dp_called); }
@@ -1425,31 +934,26 @@ void test_group_by_name_multiple_domains_parse(void **state) struct tevent_req *req = NULL; const char *name = TEST_GROUP_NAME; const char *fqn = NULL;
const char *ldbname = NULL;
uid_t gid = 2000;
uid_t ldbgid; errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Add user to the first domain. */
- /* Add group to the first domain. */ domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_a", true); assert_non_null(domain);
- ret = sysdb_store_group(domain, name, 1000, NULL,
- ret = sysdb_store_group(domain, name, 2000, NULL, 1000, time(NULL)); assert_int_equal(ret, EOK);
- /* Add user to the last domain, with different uid. */
/* Add group to the last domain, with different gid. */
domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_d", true); assert_non_null(domain);
- ret = sysdb_store_group(domain, name, gid, NULL,
1000, time(NULL));
- assert_int_equal(ret, EOK);
prepare_group(test_ctx, domain, 1000, time(NULL));
/* Append domain name to the username. */ fqn = talloc_asprintf(test_ctx, "%s@%s", name,
@@ -1473,22 +977,7 @@ void test_group_by_name_multiple_domains_parse(void **state) assert_true(check_leaks_pop(req_mem_ctx)); assert_false(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_GIDNUM, 0);
- assert_int_equal(ldbgid, gid);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
check_group(test_ctx, domain);
assert_non_null(test_ctx->name); assert_string_equal(name, test_ctx->name);
@@ -1497,229 +986,103 @@ void test_group_by_name_multiple_domains_parse(void **state) void test_group_by_name_cache_valid(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_group(test_ctx->tctx->dom, name, TEST_GROUP_ID, NULL,
1000, time(NULL));
assert_int_equal(ret, EOK);
- /* Setup group. */
- prepare_group(test_ctx, test_ctx->tctx->dom, 1000, time(NULL));
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_name_cache_expired(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_group(test_ctx->tctx->dom, name, TEST_GROUP_ID, NULL,
-1000, time(NULL));
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */ /* DP should be contacted */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_name_cache_midpoint(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_group(test_ctx->tctx->dom, name, TEST_GROUP_ID, NULL,
50, time(NULL) - 26);
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */ /* DP should be contacted without callback */ will_return(__wrap_sss_dp_get_account_send, test_ctx);
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 50,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_name_ncache(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME; errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup group. */ ret = sss_ncache_set_group(test_ctx->ncache, false,
test_ctx->tctx->dom, name);
test_ctx->tctx->dom, TEST_GROUP_NAME); assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_false(test_ctx->dp_called); }
void test_group_by_name_missing_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
test_ctx->create_group = true;
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_name_missing_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, name);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_true(test_ctx->dp_called); }
@@ -1727,338 +1090,139 @@ void test_group_by_id_multiple_domains_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL; struct sss_domain_info *domain = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
gid_t gid = TEST_GROUP_ID;
gid_t ldbgid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
- /* Setup group. */ domain = find_domain_by_name(test_ctx->tctx->dom, "responder_cache_req_test_d", true); assert_non_null(domain);
- prepare_group(test_ctx, domain, 1000, time(NULL));
- ret = sysdb_store_group(domain, name, gid, NULL,
1000, time(NULL));
- assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_id(test_ctx, NULL, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_GIDNUM, 0);
- assert_int_equal(ldbgid, gid);
- assert_non_null(test_ctx->domain);
- assert_string_equal(domain->name, test_ctx->domain->name);
check_group(test_ctx, domain); }
void test_group_by_id_multiple_domains_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
gid_t gid = TEST_GROUP_ID;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return_always(__wrap_sss_dp_get_account_send, test_ctx); will_return_always(sss_dp_get_account_recv, 0);
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_group_by_id(test_ctx, NULL, 0, ENOENT); assert_true(test_ctx->dp_called); }
void test_group_by_id_cache_valid(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
gid_t gid = TEST_GROUP_ID;
gid_t ldbgid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_group(test_ctx->tctx->dom, name, gid, NULL,
1000, time(NULL));
assert_int_equal(ret, EOK);
- /* Setup group. */
- prepare_group(test_ctx, test_ctx->tctx->dom, 1000, time(NULL));
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_GIDNUM, 0);
- assert_int_equal(ldbgid, gid);
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_id_cache_expired(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
gid_t gid = TEST_GROUP_ID;
gid_t ldbgid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_group(test_ctx->tctx->dom, name, gid, NULL,
-1000, time(NULL));
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */ /* DP should be contacted */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
test_ctx->tctx->dom->name, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_GIDNUM, 0);
- assert_int_equal(ldbgid, gid);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_id_cache_midpoint(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
gid_t gid = TEST_GROUP_ID;
gid_t ldbgid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sysdb_store_group(test_ctx->tctx->dom, name, gid, NULL,
50, time(NULL) - 26);
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */ /* DP should be contacted without callback */ will_return(__wrap_sss_dp_get_account_send, test_ctx);
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 50,
test_ctx->tctx->dom->name, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_GIDNUM, 0);
- assert_int_equal(ldbgid, gid);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_id_ncache(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
gid_t gid = TEST_GROUP_ID; errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
ret = sss_ncache_set_gid(test_ctx->ncache, false, NULL, gid);
- /* Setup group. */
- ret = sss_ncache_set_gid(test_ctx->ncache, false, NULL, TEST_GROUP_ID); assert_int_equal(ret, EOK);
- req_mem_ctx = talloc_new(global_talloc_context);
- check_leaks_push(req_mem_ctx);
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_false(test_ctx->dp_called); }
void test_group_by_id_missing_found(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *name = TEST_GROUP_NAME;
const char *ldbname = NULL;
gid_t gid = TEST_GROUP_ID;
gid_t ldbgid;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
test_ctx->create_group = true;
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ERR_OK);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK); assert_true(test_ctx->dp_called);
- assert_non_null(test_ctx->result);
- assert_int_equal(test_ctx->result->count, 1);
- assert_non_null(test_ctx->result->msgs);
- assert_non_null(test_ctx->result->msgs[0]);
- ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
SYSDB_NAME, NULL);
- assert_non_null(ldbname);
- assert_string_equal(ldbname, name);
- ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
SYSDB_GIDNUM, 0);
- assert_int_equal(ldbgid, gid);
check_group(test_ctx, test_ctx->tctx->dom); }
void test_group_by_id_missing_notfound(void **state) { struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
gid_t gid = TEST_GROUP_ID;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
- /* Mock values. */ will_return(__wrap_sss_dp_get_account_send, test_ctx); mock_account_recv_simple();
- req = cache_req_group_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 100, 0,
test_ctx->tctx->dom->name, gid);
- assert_non_null(req);
- tevent_req_set_callback(req, cache_req_group_by_id_test_done, test_ctx);
- ret = test_ev_loop(test_ctx->tctx);
- assert_int_equal(ret, ENOENT);
- assert_true(check_leaks_pop(req_mem_ctx));
- /* Test. */
- run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT); assert_true(test_ctx->dp_called); }
-- 2.1.0
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
On 09/16/2015 04:26 PM, Petr Cech wrote:
0003-cache_req-tests-reduce-code-duplication.patch
From e41f96a47f2b0f8d3e07e34af83e9a516d29df34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?=pbrezina@redhat.com Date: Mon, 14 Sep 2015 11:06:45 +0200 Subject: [PATCH 3/3] cache_req tests: reduce code duplication
src/tests/cmocka/test_responder_cache_req.c | 1624 +++++++-------------------- 1 file changed, 394 insertions(+), 1230 deletions(-)
diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c index 7db87ccc816ea0e30e707ec8c2fa4666441892a8..2af481494319d0d01d29d0c243020c5adcb06d3a 100644 --- a/src/tests/cmocka/test_responder_cache_req.c +++ b/src/tests/cmocka/test_responder_cache_req.c @@ -52,6 +52,27 @@ test_multi_domain_setup, \ test_multi_domain_teardown)
+#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
- TALLOC_CTX
*req_mem_ctx; \
- struct tevent_req
*req; \
- errno_t
ret; \
\
- req_mem_ctx =
talloc_new(global_talloc_context); \
check_leaks_push(req_mem_ctx); \
\
- req = send_fn(req_mem_ctx, ctx->tctx->ev,
ctx->rctx, \
ctx->ncache, 10,
crp, \
(dom == NULL ? NULL : dom->name),
lookup); \
assert_non_null(req); \
- tevent_req_set_callback(req, done_fn,
ctx); \
\
- ret =
test_ev_loop(ctx->tctx); \
- assert_int_equal(ret,
expret); \
assert_true(check_leaks_pop(req_mem_ctx)); \
\
talloc_free(req_mem_ctx); \ +} while (0)
This definition should be a function. I found that you use it like # return run_cache_req(...) but it doesn't provide value.
- struct cache_req_test_ctx { struct sss_test_ctx *tctx; struct resp_ctx *rctx;
@@ -80,46 +101,6 @@ struct cli_protocol_version *register_cli_protocol_version(void) return version; }
-struct tevent_req * -__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
struct resp_ctx *rctx,
struct sss_domain_info *dom,
bool fast_reply,
enum sss_dp_acct_type type,
const char *opt_name,
uint32_t opt_id,
const char *extra)
-{
- struct sysdb_attrs *attrs = NULL;
- struct cache_req_test_ctx *ctx = NULL;
- errno_t ret;
- ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
- ctx->dp_called = true;
- if (ctx->create_user) {
attrs = sysdb_new_attrs(ctx);
assert_non_null(attrs);
ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, TEST_UPN);
assert_int_equal(ret, EOK);
ret = sysdb_store_user(ctx->tctx->dom, TEST_USER_NAME, "pwd",
TEST_USER_ID, 1000, NULL, NULL, NULL,
"cn=test-user,dc=test", attrs, NULL,
1000, time(NULL));
assert_int_equal(ret, EOK);
- }
- if (ctx->create_group) {
ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
TEST_GROUP_ID, NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);
- }
- return test_req_succeed_send(mem_ctx, rctx->ev);
-}
- static void cache_req_user_by_name_test_done(struct tevent_req *req) { struct cache_req_test_ctx *ctx = NULL;
@@ -176,6 +157,173 @@ static void cache_req_group_by_id_test_done(struct tevent_req *req) ctx->tctx->done = true; }
+static void prepare_user(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
uint64_t timeout,
time_t time)
+{
- struct sysdb_attrs *attrs;
- errno_t ret;
- attrs = sysdb_new_attrs(mem_ctx);
- assert_non_null(attrs);
- ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, TEST_UPN);
- assert_int_equal(ret, EOK);
- ret = sysdb_store_user(domain, TEST_USER_NAME, "pwd",
TEST_USER_ID, TEST_GROUP_ID, NULL, NULL, NULL,
"cn=test-user,dc=test", attrs, NULL,
timeout, time);
- assert_int_equal(ret, EOK);
+}
+static void run_user_by_name(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_USER_NAME, exp_ret);
+}
+static errno_t run_user_by_upn(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_UPN, exp_ret);
+}
This function returns errno_t but run_cache_req is without return statement.
I tried with your patches # make responder_cache_req-tests and thre is a result:
src/tests/cmocka/test_responder_cache_req.c: In function ‘run_user_by_upn’: src/tests/cmocka/test_responder_cache_req.c:199:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_user_by_id’: src/tests/cmocka/test_responder_cache_req.c:209:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_group_by_name’: src/tests/cmocka/test_responder_cache_req.c:261:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_group_by_id’: src/tests/cmocka/test_responder_cache_req.c:271:1: warning: no return statement in function returning non-void [-Wreturn-type] }
That's all for me. I didn't test the functionality. Please, ask someone other who has skills with AD (and running instance of it) to test it.
Regards
Petr
On 09/17/2015 10:32 AM, Petr Cech wrote:
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
+#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
- TALLOC_CTX
*req_mem_ctx; \
- struct tevent_req
*req; \
- errno_t
ret; \
\
- req_mem_ctx =
talloc_new(global_talloc_context); \
check_leaks_push(req_mem_ctx); \
\
- req = send_fn(req_mem_ctx, ctx->tctx->ev,
ctx->rctx, \
ctx->ncache, 10,
crp, \
(dom == NULL ? NULL : dom->name),
lookup); \
assert_non_null(req); \
- tevent_req_set_callback(req, done_fn,
ctx); \
\
- ret =
test_ev_loop(ctx->tctx); \
- assert_int_equal(ret,
expret); \
assert_true(check_leaks_pop(req_mem_ctx)); \
\
talloc_free(req_mem_ctx); \ +} while (0)
This definition should be a function. I found that you use it like
I wanted to avoid writing types for send_fn and done_fn. I'll do it if you want me to, but I think this is good enough for test.
# return run_cache_req(...) but it doesn't provide value.
It was there originally then I realized I don't have to return a value. I forgot to switch errno_t with void in function definition though, thanks!
However, I did not find line "return run_cache_req...", so if it is there somewhere, please tell me.
+static void run_user_by_name(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_USER_NAME, exp_ret);
+}
+static errno_t run_user_by_upn(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_UPN, exp_ret);
+}
This function returns errno_t but run_cache_req is without return statement.
I tried with your patches # make responder_cache_req-tests and thre is a result:
src/tests/cmocka/test_responder_cache_req.c: In function ‘run_user_by_upn’: src/tests/cmocka/test_responder_cache_req.c:199:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_user_by_id’: src/tests/cmocka/test_responder_cache_req.c:209:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_group_by_name’: src/tests/cmocka/test_responder_cache_req.c:261:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_group_by_id’: src/tests/cmocka/test_responder_cache_req.c:271:1: warning: no return statement in function returning non-void [-Wreturn-type] }
See above.
That's all for me. I didn't test the functionality. Please, ask someone other who has skills with AD (and running instance of it) to test it.
Regards
Petr _______________________________________________ sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
On 09/17/2015 11:06 AM, Pavel Březina wrote:
I wanted to avoid writing types for send_fn and done_fn. I'll do it if you want me to, but I think this is good enough for test.
Well.
# return run_cache_req(...) but it doesn't provide value.
It was there originally then I realized I don't have to return a value. I forgot to switch errno_t with void in function definition though, thanks!
However, I did not find line "return run_cache_req...", so if it is there somewhere, please tell me.
That's my fault. There isn't any return run_cache_req(...) but I think that should be.
Thanks for addressing all comments (I didn't check it.).
Petr
On 09/17/2015 11:06 AM, Pavel Březina wrote:
On 09/17/2015 10:32 AM, Petr Cech wrote:
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
+#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
- TALLOC_CTX
*req_mem_ctx; \
- struct tevent_req
*req; \
- errno_t
ret; \
\
- req_mem_ctx =
talloc_new(global_talloc_context); \
check_leaks_push(req_mem_ctx); \
\
- req = send_fn(req_mem_ctx, ctx->tctx->ev,
ctx->rctx, \
ctx->ncache, 10,
crp, \
(dom == NULL ? NULL : dom->name),
lookup); \
assert_non_null(req); \
- tevent_req_set_callback(req, done_fn,
ctx); \
\
- ret =
test_ev_loop(ctx->tctx); \
- assert_int_equal(ret,
expret); \
assert_true(check_leaks_pop(req_mem_ctx)); \
\
talloc_free(req_mem_ctx); \ +} while (0)
This definition should be a function. I found that you use it like
I wanted to avoid writing types for send_fn and done_fn. I'll do it if you want me to, but I think this is good enough for test.
# return run_cache_req(...) but it doesn't provide value.
It was there originally then I realized I don't have to return a value. I forgot to switch errno_t with void in function definition though, thanks!
However, I did not find line "return run_cache_req...", so if it is there somewhere, please tell me.
+static void run_user_by_name(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_USER_NAME, exp_ret);
+}
+static errno_t run_user_by_upn(struct cache_req_test_ctx *test_ctx,
struct sss_domain_info *domain,
int cache_refresh_percent,
errno_t exp_ret)
+{
- run_cache_req(test_ctx, cache_req_user_by_name_send,
cache_req_user_by_name_test_done, domain,
cache_refresh_percent, TEST_UPN, exp_ret);
+}
This function returns errno_t but run_cache_req is without return statement.
I tried with your patches # make responder_cache_req-tests and thre is a result:
src/tests/cmocka/test_responder_cache_req.c: In function ‘run_user_by_upn’: src/tests/cmocka/test_responder_cache_req.c:199:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_user_by_id’: src/tests/cmocka/test_responder_cache_req.c:209:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_group_by_name’: src/tests/cmocka/test_responder_cache_req.c:261:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^ src/tests/cmocka/test_responder_cache_req.c: In function ‘run_group_by_id’: src/tests/cmocka/test_responder_cache_req.c:271:1: warning: no return statement in function returning non-void [-Wreturn-type] }
See above.
That's all for me. I didn't test the functionality. Please, ask someone other who has skills with AD (and running instance of it) to test it.
Regards
Petr
Bump.
On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote:
On 09/17/2015 10:32 AM, Petr Cech wrote:
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
[PATCH 2/3] cache_req: add support for UPN
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, return filter; }
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- static const char *attrs[] = SYSDB_PW_ATTRS;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn() failed.\n");
goto done;
- }
The call stack here would be
sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search()
and the returned results, starting from ldb_search()
ldb_result -> ldb_message (array) -> ldb_message -> ldb_result
I think it would be easier and safe some allocations if it would be
sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() .
Do you think this change makes sense?
- res = talloc_zero(tmp_ctx, struct ldb_result);
- if (res == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "talloc_zero() failed.\n");
ret = ENOMEM;
goto done;
- }
- if (ret == ENOENT) {
res->count = 0;
res->msgs = NULL;
- } else {
res->count = 1;
res->msgs = talloc_array(res, struct ldb_message *, 1);
if (res->msgs == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
ret = ENOMEM;
goto done;
}
res->msgs[0] = talloc_steal(res->msgs, msg);
- }
- *_res = talloc_steal(mem_ctx, res);
- ret = EOK;
+done:
- talloc_free(tmp_ctx);
- return ret;
+}
...
diff --git a/src/responder/common/responder_cache_req.c b/src/responder/common/responder_cache_req.c index fba5001476481040ed962dbbd9b01cc16fe0ba74..70a3010eb697cf14874bd1a950cb7a874bc060b4 100644 --- a/src/responder/common/responder_cache_req.c +++ b/src/responder/common/responder_cache_req.c @@ -70,6 +70,7 @@ struct cache_req_input { enum cache_req_type type;
/* Provided input. */
- const char *raw_name; const char *orig_name;
Instead of adding a new member which again will hold the originally provided name I would suggest to refactor the change added by e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if needed) by introducing a member called e.g. parsed_name which keeps the name returned by sss_parse_inp_recv() and return it in cache_req_recv().
In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite orig_name because no additional member was needed. But now I think the code would be more clear if orig_name will be kept unmodified.
bye, Sumit
On 10/01/2015 05:06 PM, Sumit Bose wrote:
On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote:
On 09/17/2015 10:32 AM, Petr Cech wrote:
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
[PATCH 2/3] cache_req: add support for UPN
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, return filter; }
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- static const char *attrs[] = SYSDB_PW_ATTRS;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn() failed.\n");
goto done;
- }
The call stack here would be
sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search()
and the returned results, starting from ldb_search()
ldb_result -> ldb_message (array) -> ldb_message -> ldb_result
I think it would be easier and safe some allocations if it would be
sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() .
Do you think this change makes sense?
Hi, thanks for the review. Done.
Although I created a new function sysdb_search_user_by_upn_res since you can't pass attrs into sysdb_getpwnupn (unless we are inconsistent with api).
const char *orig_name;
Instead of adding a new member which again will hold the originally provided name I would suggest to refactor the change added by e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if needed) by introducing a member called e.g. parsed_name which keeps the name returned by sss_parse_inp_recv() and return it in cache_req_recv().
In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite orig_name because no additional member was needed. But now I think the code would be more clear if orig_name will be kept unmodified.
Done in separate patch so the changes are more visible. It can be squashed to the second patch.
bye, Sumit _______________________________________________ sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
On 10/06/2015 03:16 PM, Pavel Březina wrote:
On 10/01/2015 05:06 PM, Sumit Bose wrote:
On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote:
On 09/17/2015 10:32 AM, Petr Cech wrote:
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
[PATCH 2/3] cache_req: add support for UPN
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, return filter; }
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- static const char *attrs[] = SYSDB_PW_ATTRS;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn()
failed.\n");
goto done;
- }
The call stack here would be
sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search()
and the returned results, starting from ldb_search()
ldb_result -> ldb_message (array) -> ldb_message -> ldb_result
I think it would be easier and safe some allocations if it would be
sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() .
Do you think this change makes sense?
Hi, thanks for the review. Done.
Although I created a new function sysdb_search_user_by_upn_res since you can't pass attrs into sysdb_getpwnupn (unless we are inconsistent with api).
const char *orig_name;
Instead of adding a new member which again will hold the originally provided name I would suggest to refactor the change added by e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if needed) by introducing a member called e.g. parsed_name which keeps the name returned by sss_parse_inp_recv() and return it in cache_req_recv().
In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite orig_name because no additional member was needed. But now I think the code would be more clear if orig_name will be kept unmodified.
Done in separate patch so the changes are more visible. It can be squashed to the second patch.
Sumit found that test won't pass. New patchset is attached.
On Wed, Oct 07, 2015 at 02:42:18PM +0200, Pavel Březina wrote:
On 10/06/2015 03:16 PM, Pavel Březina wrote:
On 10/01/2015 05:06 PM, Sumit Bose wrote:
On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote:
On 09/17/2015 10:32 AM, Petr Cech wrote:
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
[PATCH 2/3] cache_req: add support for UPN
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, return filter; }
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- static const char *attrs[] = SYSDB_PW_ATTRS;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn()
failed.\n");
goto done;
- }
The call stack here would be
sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search()
and the returned results, starting from ldb_search()
ldb_result -> ldb_message (array) -> ldb_message -> ldb_result
I think it would be easier and safe some allocations if it would be
sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() .
Do you think this change makes sense?
Hi, thanks for the review. Done.
Although I created a new function sysdb_search_user_by_upn_res since you can't pass attrs into sysdb_getpwnupn (unless we are inconsistent with api).
const char *orig_name;
Instead of adding a new member which again will hold the originally provided name I would suggest to refactor the change added by e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if needed) by introducing a member called e.g. parsed_name which keeps the name returned by sss_parse_inp_recv() and return it in cache_req_recv().
In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite orig_name because no additional member was needed. But now I think the code would be more clear if orig_name will be kept unmodified.
Done in separate patch so the changes are more visible. It can be squashed to the second patch.
Sumit found that test won't pass. New patchset is attached.
Thank you, the tests pass now. I've seen a compiler warning which is seen with the first patch I attached.
During testing I found that UPN lookups for sub-domain users do not work even with the original nss responder code. I attached fixes for your patches and the nss responder since the sysdb change depends on you patches.
bye, Sumit
On Wed, Oct 07, 2015 at 04:22:31PM +0200, Sumit Bose wrote:
On Wed, Oct 07, 2015 at 02:42:18PM +0200, Pavel Březina wrote:
On 10/06/2015 03:16 PM, Pavel Březina wrote:
On 10/01/2015 05:06 PM, Sumit Bose wrote:
On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote:
On 09/17/2015 10:32 AM, Petr Cech wrote:
Hi Pavel!
There is some code between my last end and this continuation. I was read it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
[PATCH 2/3] cache_req: add support for UPN
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, return filter; }
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- static const char *attrs[] = SYSDB_PW_ATTRS;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn()
failed.\n");
goto done;
- }
The call stack here would be
sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search()
and the returned results, starting from ldb_search()
ldb_result -> ldb_message (array) -> ldb_message -> ldb_result
I think it would be easier and safe some allocations if it would be
sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() .
Do you think this change makes sense?
Hi, thanks for the review. Done.
Although I created a new function sysdb_search_user_by_upn_res since you can't pass attrs into sysdb_getpwnupn (unless we are inconsistent with api).
const char *orig_name;
Instead of adding a new member which again will hold the originally provided name I would suggest to refactor the change added by e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if needed) by introducing a member called e.g. parsed_name which keeps the name returned by sss_parse_inp_recv() and return it in cache_req_recv().
In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite orig_name because no additional member was needed. But now I think the code would be more clear if orig_name will be kept unmodified.
Done in separate patch so the changes are more visible. It can be squashed to the second patch.
Sumit found that test won't pass. New patchset is attached.
Thank you, the tests pass now. I've seen a compiler warning which is seen with the first patch I attached.
During testing I found that UPN lookups for sub-domain users do not work even with the original nss responder code. I attached fixes for your patches and the nss responder since the sysdb change depends on you patches.
and now with patches ...
bye, Sumit _______________________________________________ sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
On 10/07/2015 04:28 PM, Sumit Bose wrote:
On Wed, Oct 07, 2015 at 04:22:31PM +0200, Sumit Bose wrote:
On Wed, Oct 07, 2015 at 02:42:18PM +0200, Pavel Březina wrote:
On 10/06/2015 03:16 PM, Pavel Březina wrote:
On 10/01/2015 05:06 PM, Sumit Bose wrote:
On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote:
On 09/17/2015 10:32 AM, Petr Cech wrote: > Hi Pavel! > > There is some code between my last end and this continuation. I was > read > it and did't find anything wrong.
Hi Petr, thank you for you review. New patches are attached. All comments from the previous mail should be addressed.
[PATCH 2/3] cache_req: add support for UPN
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c index 5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e 100644 --- a/src/db/sysdb_search.c +++ b/src/db/sysdb_search.c @@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, return filter; }
+int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *upn,
struct ldb_result **_res)
+{
- TALLOC_CTX *tmp_ctx;
- struct ldb_message *msg;
- struct ldb_result *res;
- static const char *attrs[] = SYSDB_PW_ATTRS;
- errno_t ret;
- tmp_ctx = talloc_new(NULL);
- if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
- }
- ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg);
- if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn()
failed.\n");
goto done;
- }
The call stack here would be
sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search()
and the returned results, starting from ldb_search()
ldb_result -> ldb_message (array) -> ldb_message -> ldb_result
I think it would be easier and safe some allocations if it would be
sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() .
Do you think this change makes sense?
Hi, thanks for the review. Done.
Although I created a new function sysdb_search_user_by_upn_res since you can't pass attrs into sysdb_getpwnupn (unless we are inconsistent with api).
const char *orig_name;
Instead of adding a new member which again will hold the originally provided name I would suggest to refactor the change added by e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if needed) by introducing a member called e.g. parsed_name which keeps the name returned by sss_parse_inp_recv() and return it in cache_req_recv().
In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite orig_name because no additional member was needed. But now I think the code would be more clear if orig_name will be kept unmodified.
Done in separate patch so the changes are more visible. It can be squashed to the second patch.
Sumit found that test won't pass. New patchset is attached.
Thank you, the tests pass now. I've seen a compiler warning which is seen with the first patch I attached.
During testing I found that UPN lookups for sub-domain users do not work even with the original nss responder code. I attached fixes for your patches and the nss responder since the sysdb change depends on you patches.
and now with patches ...
Ack. Thank you!
On Thu, Oct 08, 2015 at 01:21:29PM +0200, Pavel Březina wrote:
On 10/07/2015 04:28 PM, Sumit Bose wrote:
On Wed, Oct 07, 2015 at 04:22:31PM +0200, Sumit Bose wrote:
On Wed, Oct 07, 2015 at 02:42:18PM +0200, Pavel Březina wrote:
On 10/06/2015 03:16 PM, Pavel Březina wrote:
On 10/01/2015 05:06 PM, Sumit Bose wrote:
On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote: >On 09/17/2015 10:32 AM, Petr Cech wrote: >>Hi Pavel! >> >>There is some code between my last end and this continuation. I was >>read >>it and did't find anything wrong. > >Hi Petr, >thank you for you review. New patches are attached. All comments from >the >previous mail should be addressed. >
[PATCH 2/3] cache_req: add support for UPN
>diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c >index >5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e >100644 >--- a/src/db/sysdb_search.c >+++ b/src/db/sysdb_search.c >@@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, > return filter; > } > >+int sysdb_getpwupn(TALLOC_CTX *mem_ctx, >+ struct sss_domain_info *domain, >+ const char *upn, >+ struct ldb_result **_res) >+{ >+ TALLOC_CTX *tmp_ctx; >+ struct ldb_message *msg; >+ struct ldb_result *res; >+ static const char *attrs[] = SYSDB_PW_ATTRS; >+ errno_t ret; >+ >+ tmp_ctx = talloc_new(NULL); >+ if (tmp_ctx == NULL) { >+ DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n"); >+ return ENOMEM; >+ } >+ >+ ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg); >+ if (ret != EOK && ret != ENOENT) { >+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn() >failed.\n"); >+ goto done; >+ }
The call stack here would be
sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search()
and the returned results, starting from ldb_search()
ldb_result -> ldb_message (array) -> ldb_message -> ldb_result
I think it would be easier and safe some allocations if it would be
sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() .
Do you think this change makes sense?
Hi, thanks for the review. Done.
Although I created a new function sysdb_search_user_by_upn_res since you can't pass attrs into sysdb_getpwnupn (unless we are inconsistent with api).
const char *orig_name;
Instead of adding a new member which again will hold the originally provided name I would suggest to refactor the change added by e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if needed) by introducing a member called e.g. parsed_name which keeps the name returned by sss_parse_inp_recv() and return it in cache_req_recv().
In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite orig_name because no additional member was needed. But now I think the code would be more clear if orig_name will be kept unmodified.
Done in separate patch so the changes are more visible. It can be squashed to the second patch.
Sumit found that test won't pass. New patchset is attached.
Thank you, the tests pass now. I've seen a compiler warning which is seen with the first patch I attached.
During testing I found that UPN lookups for sub-domain users do not work even with the original nss responder code. I attached fixes for your patches and the nss responder since the sysdb change depends on you patches.
and now with patches ...
Ack. Thank you!
I pushed both sets to master: * 8ded8b2f4a57d1833fd230307218d8b07a571785 * 374268c5eda35e8bbc2fef30752299199439cffe * 391b81f2a78a812a87530e0c50c70d59150f49eb * 2fce47f2dadd10d2a2c8bf9f03ab7094bc6c6b3a * 3688374991afb34bbaf2b7843683fc13dd77879d * 28ebfa4373d1e7ce45b5d70a3619df1c074a661e * d8125f0e0d38c6939887a0849a44859d6c498c57 and sssd-1-13: * b1b0abe6223348083be552531f195518b0df3ba5 * f2c3994c6ffd6e715621d7d7ee580db3cd3e85a9 * 055248cf20c1ad9dfba06903789e71b88752b810 * 6bb2a01333bca8a338cb0be6e8d513040b227cb8 * 44415c5a8ad054555a5e0cc016eec8a125c927ab * f04ead531a4e941de1a5bcb695326ca11a3dd145 * ae3896a12fb4818aac11ccc5d3a57d2cdf61cd43
I hope it's OK to push these all to sssd-1-13 since Sumit's patches depend on Pavel's and in 1-13 the cache_req is mostly used for UPN.
On Thu, Oct 08, 2015 at 08:34:17PM +0200, Jakub Hrozek wrote:
On Thu, Oct 08, 2015 at 01:21:29PM +0200, Pavel Březina wrote:
On 10/07/2015 04:28 PM, Sumit Bose wrote:
On Wed, Oct 07, 2015 at 04:22:31PM +0200, Sumit Bose wrote:
On Wed, Oct 07, 2015 at 02:42:18PM +0200, Pavel Březina wrote:
On 10/06/2015 03:16 PM, Pavel Březina wrote:
On 10/01/2015 05:06 PM, Sumit Bose wrote: >On Thu, Sep 17, 2015 at 11:06:30AM +0200, Pavel Březina wrote: >>On 09/17/2015 10:32 AM, Petr Cech wrote: >>>Hi Pavel! >>> >>>There is some code between my last end and this continuation. I was >>>read >>>it and did't find anything wrong. >> >>Hi Petr, >>thank you for you review. New patches are attached. All comments from >>the >>previous mail should be addressed. >> > > >[PATCH 2/3] cache_req: add support for UPN > >>diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c >>index >>5f33b225a31e1c1add7f776215d500fb09e127ca..a72a8bac594dc10ff9aa337399f27d9936830a8e >>100644 >>--- a/src/db/sysdb_search.c >>+++ b/src/db/sysdb_search.c >>@@ -295,6 +295,59 @@ static char *enum_filter(TALLOC_CTX *mem_ctx, >> return filter; >> } >> >>+int sysdb_getpwupn(TALLOC_CTX *mem_ctx, >>+ struct sss_domain_info *domain, >>+ const char *upn, >>+ struct ldb_result **_res) >>+{ >>+ TALLOC_CTX *tmp_ctx; >>+ struct ldb_message *msg; >>+ struct ldb_result *res; >>+ static const char *attrs[] = SYSDB_PW_ATTRS; >>+ errno_t ret; >>+ >>+ tmp_ctx = talloc_new(NULL); >>+ if (tmp_ctx == NULL) { >>+ DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n"); >>+ return ENOMEM; >>+ } >>+ >>+ ret = sysdb_search_user_by_upn(tmp_ctx, domain, upn, attrs, &msg); >>+ if (ret != EOK && ret != ENOENT) { >>+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn() >>failed.\n"); >>+ goto done; >>+ } > >The call stack here would be > >sysdb_getpwupn()->sysdb_search_user_by_upn()->sysdb_search_entry()->ldb_search() > > >and the returned results, starting from ldb_search() > >ldb_result -> ldb_message (array) -> ldb_message -> ldb_result > >I think it would be easier and safe some allocations if it would be > >sysdb_search_user_by_upn()->sysdb_getpwupn()->ldb_search() . > >Do you think this change makes sense?
Hi, thanks for the review. Done.
Although I created a new function sysdb_search_user_by_upn_res since you can't pass attrs into sysdb_getpwnupn (unless we are inconsistent with api).
> const char *orig_name; > >Instead of adding a new member which again will hold the originally >provided name I would suggest to refactor the change added by >e87b2a6e94c1066b3044fe683825ff5b4f8716c2 (cache_req: parse input name if >needed) by introducing a member called e.g. parsed_name which keeps the >name returned by sss_parse_inp_recv() and return it in cache_req_recv(). > >In e87b2a6e94c1066b3044fe683825ff5b4f8716c2 it made sense to overwrite >orig_name because no additional member was needed. But now I think the >code would be more clear if orig_name will be kept unmodified.
Done in separate patch so the changes are more visible. It can be squashed to the second patch.
Sumit found that test won't pass. New patchset is attached.
Thank you, the tests pass now. I've seen a compiler warning which is seen with the first patch I attached.
During testing I found that UPN lookups for sub-domain users do not work even with the original nss responder code. I attached fixes for your patches and the nss responder since the sysdb change depends on you patches.
and now with patches ...
Ack. Thank you!
I pushed both sets to master: * 8ded8b2f4a57d1833fd230307218d8b07a571785 * 374268c5eda35e8bbc2fef30752299199439cffe * 391b81f2a78a812a87530e0c50c70d59150f49eb * 2fce47f2dadd10d2a2c8bf9f03ab7094bc6c6b3a * 3688374991afb34bbaf2b7843683fc13dd77879d * 28ebfa4373d1e7ce45b5d70a3619df1c074a661e * d8125f0e0d38c6939887a0849a44859d6c498c57 and sssd-1-13: * b1b0abe6223348083be552531f195518b0df3ba5 * f2c3994c6ffd6e715621d7d7ee580db3cd3e85a9 * 055248cf20c1ad9dfba06903789e71b88752b810 * 6bb2a01333bca8a338cb0be6e8d513040b227cb8 * 44415c5a8ad054555a5e0cc016eec8a125c927ab * f04ead531a4e941de1a5bcb695326ca11a3dd145 * ae3896a12fb4818aac11ccc5d3a57d2cdf61cd43
I hope it's OK to push these all to sssd-1-13 since Sumit's patches depend on Pavel's and in 1-13 the cache_req is mostly used for UPN.
~~~~~~~~ For IFP
On Wed, Oct 07, 2015 at 04:28:02PM +0200, Sumit Bose wrote:
From 3d5352977ca07f8a1a6d3bbaa57d11b54fd705d0 Mon Sep 17 00:00:00 2001 From: Sumit Bose sbose@redhat.com Date: Wed, 7 Oct 2015 15:22:34 +0200 Subject: [PATCH 3/3] nss: fix UPN lookups for sub-domain users
This one should go to sssd-1-12, right? Can you send a rebased version, please?
On Thu, Oct 08, 2015 at 08:51:41PM +0200, Jakub Hrozek wrote:
On Wed, Oct 07, 2015 at 04:28:02PM +0200, Sumit Bose wrote:
From 3d5352977ca07f8a1a6d3bbaa57d11b54fd705d0 Mon Sep 17 00:00:00 2001 From: Sumit Bose sbose@redhat.com Date: Wed, 7 Oct 2015 15:22:34 +0200 Subject: [PATCH 3/3] nss: fix UPN lookups for sub-domain users
This one should go to sssd-1-12, right? Can you send a rebased version, please?
please find it attached.
bye, Sumit
sssd-devel mailing list sssd-devel@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
On 10/09/2015 01:34 PM, Sumit Bose wrote:
On Thu, Oct 08, 2015 at 08:51:41PM +0200, Jakub Hrozek wrote:
On Wed, Oct 07, 2015 at 04:28:02PM +0200, Sumit Bose wrote:
From 3d5352977ca07f8a1a6d3bbaa57d11b54fd705d0 Mon Sep 17 00:00:00 2001 From: Sumit Bose sbose@redhat.com Date: Wed, 7 Oct 2015 15:22:34 +0200 Subject: [PATCH 3/3] nss: fix UPN lookups for sub-domain users
This one should go to sssd-1-12, right? Can you send a rebased version, please?
please find it attached.
bye, Sumit
Ack.
On Fri, Oct 09, 2015 at 02:14:12PM +0200, Pavel Březina wrote:
On 10/09/2015 01:34 PM, Sumit Bose wrote:
On Thu, Oct 08, 2015 at 08:51:41PM +0200, Jakub Hrozek wrote:
On Wed, Oct 07, 2015 at 04:28:02PM +0200, Sumit Bose wrote:
From 3d5352977ca07f8a1a6d3bbaa57d11b54fd705d0 Mon Sep 17 00:00:00 2001 From: Sumit Bose sbose@redhat.com Date: Wed, 7 Oct 2015 15:22:34 +0200 Subject: [PATCH 3/3] nss: fix UPN lookups for sub-domain users
This one should go to sssd-1-12, right? Can you send a rebased version, please?
please find it attached.
bye, Sumit
Ack.
CI: http://sssd-ci.duckdns.org/logs/job/30/06/summary.html
* sssd-1-12: e412f49be66e6248fbfa61cdd1516c3444deaff8
sssd-devel@lists.fedorahosted.org