test_responder_cache_req.c revision 50c9d542e8bf641412debaa82a4dcf67ddb72258
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Authors:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Pavel Březina <pbrezina@redhat.com>
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Copyright (C) 2014 Red Hat
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin This program is free software; you can redistribute it and/or modify
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin it under the terms of the GNU General Public License as published by
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin the Free Software Foundation; either version 3 of the License, or
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (at your option) any later version.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin This program is distributed in the hope that it will be useful,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin but WITHOUT ANY WARRANTY; without even the implied warranty of
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GNU General Public License for more details.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin You should have received a copy of the GNU General Public License
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin along with this program. If not, see <http://www.gnu.org/licenses/>.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <talloc.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <tevent.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <errno.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <popt.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "tests/cmocka/common_mock.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "tests/cmocka/common_mock_resp.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "db/sysdb.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "responder/common/responder_cache_req.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TESTS_PATH "tp_" BASE_FILE_STEM
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_CONF_DB "test_responder_cache_req_conf.ldb"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_DOM_NAME "responder_cache_req_test"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_ID_PROVIDER "ldap"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_USER_NAME "test-user"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_USER_ID 1000
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_GROUP_NAME "test-group"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_GROUP_ID 1000
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_USER_NAME2 "test-user2"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define TEST_GROUP_NAME2 "test-group2"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define new_single_domain_test(test) \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin cmocka_unit_test_setup_teardown(test_ ## test, \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin test_single_domain_setup, \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin test_single_domain_teardown)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define new_multi_domain_test(test) \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin cmocka_unit_test_setup_teardown(test_ ## test, \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin test_multi_domain_setup, \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin test_multi_domain_teardown)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct cache_req_test_ctx {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct sss_test_ctx *tctx;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct resp_ctx *rctx;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct sss_nc_ctx *ncache;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct ldb_result *result;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct sss_domain_info *domain;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char *name;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bool dp_called;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bool create_user;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bool create_group;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinconst char *domains[] = {"responder_cache_req_test_a",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "responder_cache_req_test_b",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "responder_cache_req_test_c",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "responder_cache_req_test_d",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin NULL};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct cli_protocol_version *register_cli_protocol_version(void)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin static struct cli_protocol_version version[] = {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin { 0, NULL, NULL }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin };
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return version;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct tevent_req *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct resp_ctx *rctx,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct sss_domain_info *dom,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bool fast_reply,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin enum sss_dp_acct_type type,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char *opt_name,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin uint32_t opt_id,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin const char *extra)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct cache_req_test_ctx *ctx = NULL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errno_t ret;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ctx->dp_called = true;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (ctx->create_user) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ret = sysdb_store_user(ctx->tctx->dom, TEST_USER_NAME, "pwd",
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin TEST_USER_ID, 1000, NULL, NULL, NULL,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "cn=test-user,dc=test", NULL, NULL,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin 1000, time(NULL));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin assert_int_equal(ret, EOK);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (ctx->create_group) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin TEST_GROUP_ID, NULL, 1000, time(NULL));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin assert_int_equal(ret, EOK);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return test_req_succeed_send(mem_ctx, rctx->ev);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void cache_req_user_by_name_test_done(struct tevent_req *req)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin struct cache_req_test_ctx *ctx = NULL;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ctx->tctx->error = cache_req_user_by_name_recv(ctx, req,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &ctx->result,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &ctx->domain,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin &ctx->name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin talloc_zfree(req);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ctx->tctx->done = true;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
static void cache_req_user_by_id_test_done(struct tevent_req *req)
{
struct cache_req_test_ctx *ctx = NULL;
ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
ctx->tctx->error = cache_req_user_by_id_recv(ctx, req,
&ctx->result, &ctx->domain);
talloc_zfree(req);
ctx->tctx->done = true;
}
static void cache_req_group_by_name_test_done(struct tevent_req *req)
{
struct cache_req_test_ctx *ctx = NULL;
ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
ctx->tctx->error = cache_req_group_by_name_recv(ctx, req,
&ctx->result,
&ctx->domain,
&ctx->name);
talloc_zfree(req);
ctx->tctx->done = true;
}
static void cache_req_group_by_id_test_done(struct tevent_req *req)
{
struct cache_req_test_ctx *ctx = NULL;
ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
ctx->tctx->error = cache_req_group_by_id_recv(ctx, req,
&ctx->result, &ctx->domain);
talloc_zfree(req);
ctx->tctx->done = true;
}
static int test_single_domain_setup(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
errno_t ret;
test_dom_suite_setup(TESTS_PATH);
test_ctx = talloc_zero(NULL, struct cache_req_test_ctx);
assert_non_null(test_ctx);
*state = test_ctx;
test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
TEST_DOM_NAME, TEST_ID_PROVIDER, NULL);
assert_non_null(test_ctx->tctx);
test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
test_ctx->tctx->dom, NULL);
assert_non_null(test_ctx->rctx);
ret = sss_ncache_init(test_ctx, &test_ctx->ncache);
assert_int_equal(ret, EOK);
return 0;
}
static int test_single_domain_teardown(void **state)
{
talloc_zfree(*state);
test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
return 0;
}
static int test_multi_domain_setup(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
errno_t ret;
test_dom_suite_setup(TESTS_PATH);
test_ctx = talloc_zero(NULL, struct cache_req_test_ctx);
assert_non_null(test_ctx);
*state = test_ctx;
test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
TEST_CONF_DB, domains,
TEST_ID_PROVIDER, NULL);
assert_non_null(test_ctx->tctx);
test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
test_ctx->tctx->dom, NULL);
assert_non_null(test_ctx->rctx);
ret = sss_ncache_init(test_ctx, &test_ctx->ncache);
assert_int_equal(ret, EOK);
return 0;
}
static int test_multi_domain_teardown(void **state)
{
talloc_zfree(*state);
test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
return 0;
}
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);
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);
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);
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));
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_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);
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);
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));
assert_true(test_ctx->dp_called);
}
void test_user_by_name_multiple_domains_parse(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 *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. */
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,
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. */
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);
/* Append domain name to the username. */
fqn = talloc_asprintf(test_ctx, "%s@%s", name,
"responder_cache_req_test_d");
assert_non_null(fqn);
/* Test. */
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
mock_parse_inp(name, "responder_cache_req_test_d");
req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, fqn);
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_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);
assert_non_null(test_ctx->name);
assert_string_equal(name, test_ctx->name);
}
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);
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);
}
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);
/* 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));
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_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);
/* 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));
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_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);
ret = sss_ncache_set_user(test_ctx->ncache, false,
test_ctx->tctx->dom, 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));
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);
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));
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_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);
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));
assert_true(test_ctx->dp_called);
}
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);
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);
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));
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);
}
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);
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));
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);
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);
}
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);
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();
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_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);
}
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);
/* 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));
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);
}
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);
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));
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);
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));
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);
}
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);
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));
assert_true(test_ctx->dp_called);
}
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);
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, 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);
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);
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));
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_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);
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);
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));
assert_true(test_ctx->dp_called);
}
void test_group_by_name_multiple_domains_parse(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 *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. */
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,
1000, time(NULL));
assert_int_equal(ret, EOK);
/* Add user to the last domain, with different uid. */
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);
/* Append domain name to the username. */
fqn = talloc_asprintf(test_ctx, "%s@%s", name,
"responder_cache_req_test_d");
assert_non_null(fqn);
/* Test. */
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
mock_parse_inp(name, "responder_cache_req_test_d");
req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 10, 0,
NULL, fqn);
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_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);
assert_non_null(test_ctx->name);
assert_string_equal(name, test_ctx->name);
}
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);
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);
}
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);
/* 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));
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_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);
/* 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));
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_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);
ret = sss_ncache_set_group(test_ctx->ncache, false,
test_ctx->tctx->dom, 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));
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);
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));
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_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);
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));
assert_true(test_ctx->dp_called);
}
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);
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);
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);
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));
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);
}
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);
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));
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);
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);
}
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);
/* 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));
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);
}
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);
/* 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));
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);
}
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);
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));
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);
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));
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);
}
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);
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));
assert_true(test_ctx->dp_called);
}
static void cache_req_user_by_filter_test_done(struct tevent_req *req)
{
struct cache_req_test_ctx *ctx = NULL;
ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
ctx->tctx->error = cache_req_user_by_filter_recv(ctx, req,
&ctx->result,
&ctx->domain);
talloc_zfree(req);
ctx->tctx->done = true;
}
void test_users_by_filter_filter_old(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
test_ctx->create_user = true;
/* This user was updated in distant past, so it wont't be reported by
* the filter search */
ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME2, "pwd", 1001, 1001,
NULL, NULL, NULL, "cn="TEST_USER_NAME2",dc=test", NULL,
NULL, 1000, 1);
assert_int_equal(ret, EOK);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Filters always go to DP */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
test_ctx->tctx->dom->name,
"test*");
assert_non_null(req);
tevent_req_set_callback(req, cache_req_user_by_filter_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);
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);
}
void test_users_by_filter_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = 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);
/* Filters always go to DP */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
test_ctx->tctx->dom->name,
"nosuchuser*");
assert_non_null(req);
tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
ret = test_ev_loop(test_ctx->tctx);
assert_int_equal(ret, ENOENT);
assert_true(check_leaks_pop(req_mem_ctx));
}
static void test_users_by_filter_multiple_domains_notfound(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;
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);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Filters always go to DP */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
domain->name,
"nosuchuser*");
assert_non_null(req);
tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
ret = test_ev_loop(test_ctx->tctx);
assert_int_equal(ret, ENOENT);
assert_true(check_leaks_pop(req_mem_ctx));
}
static void cache_req_group_by_filter_test_done(struct tevent_req *req)
{
struct cache_req_test_ctx *ctx = NULL;
ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
ctx->tctx->error = cache_req_group_by_filter_recv(ctx, req,
&ctx->result,
&ctx->domain);
talloc_zfree(req);
ctx->tctx->done = true;
}
void test_groups_by_filter_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = 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);
/* Filters always go to DP */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
test_ctx->tctx->dom->name,
"nosuchgroup*");
assert_non_null(req);
tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
ret = test_ev_loop(test_ctx->tctx);
assert_int_equal(ret, ENOENT);
assert_true(check_leaks_pop(req_mem_ctx));
}
void test_groups_by_filter_multiple_domains_notfound(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;
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);
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
/* Filters always go to DP */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
domain->name,
"nosuchgroup*");
assert_non_null(req);
tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
ret = test_ev_loop(test_ctx->tctx);
assert_int_equal(ret, ENOENT);
assert_true(check_leaks_pop(req_mem_ctx));
}
int main(int argc, const char *argv[])
{
poptContext pc;
int opt;
struct poptOption long_options[] = {
POPT_AUTOHELP
SSSD_DEBUG_OPTS
POPT_TABLEEND
};
const struct CMUnitTest tests[] = {
new_single_domain_test(user_by_name_cache_valid),
new_single_domain_test(user_by_name_cache_expired),
new_single_domain_test(user_by_name_cache_midpoint),
new_single_domain_test(user_by_name_ncache),
new_single_domain_test(user_by_name_missing_found),
new_single_domain_test(user_by_name_missing_notfound),
new_multi_domain_test(user_by_name_multiple_domains_found),
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_id_cache_valid),
new_single_domain_test(user_by_id_cache_expired),
new_single_domain_test(user_by_id_cache_midpoint),
new_single_domain_test(user_by_id_ncache),
new_single_domain_test(user_by_id_missing_found),
new_single_domain_test(user_by_id_missing_notfound),
new_multi_domain_test(user_by_id_multiple_domains_found),
new_multi_domain_test(user_by_id_multiple_domains_notfound),
new_single_domain_test(group_by_name_cache_valid),
new_single_domain_test(group_by_name_cache_expired),
new_single_domain_test(group_by_name_cache_midpoint),
new_single_domain_test(group_by_name_ncache),
new_single_domain_test(group_by_name_missing_found),
new_single_domain_test(group_by_name_missing_notfound),
new_multi_domain_test(group_by_name_multiple_domains_found),
new_multi_domain_test(group_by_name_multiple_domains_notfound),
new_multi_domain_test(group_by_name_multiple_domains_parse),
new_single_domain_test(group_by_id_cache_valid),
new_single_domain_test(group_by_id_cache_expired),
new_single_domain_test(group_by_id_cache_midpoint),
new_single_domain_test(group_by_id_ncache),
new_single_domain_test(group_by_id_missing_found),
new_single_domain_test(group_by_id_missing_notfound),
new_multi_domain_test(group_by_id_multiple_domains_found),
new_multi_domain_test(group_by_id_multiple_domains_notfound),
new_single_domain_test(users_by_filter_filter_old),
new_single_domain_test(users_by_filter_notfound),
new_multi_domain_test(users_by_filter_multiple_domains_notfound),
new_single_domain_test(groups_by_filter_notfound),
new_multi_domain_test(groups_by_filter_multiple_domains_notfound),
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
debug_level = SSSDBG_INVALID;
pc = poptGetContext(argv[0], argc, argv, long_options, 0);
while((opt = poptGetNextOpt(pc)) != -1) {
switch(opt) {
default:
fprintf(stderr, "\nInvalid option %s: %s\n\n",
poptBadOption(pc, 0), poptStrerror(opt));
poptPrintUsage(pc, stderr, 0);
return 1;
}
}
poptFreeContext(pc);
DEBUG_CLI_INIT(debug_level);
/* Even though normally the tests should clean up after themselves
* they might not after a failed run. Remove the old db to be sure */
tests_set_cwd();
test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
return cmocka_run_group_tests(tests, NULL, NULL);
}