test_responder_cache_req.c revision a257259b05d62ebe548b6c798a3aa03a97dbc0c2
f3ec420152ca921e4c1ce77782f51b53f659018dnd/*
f3ec420152ca921e4c1ce77782f51b53f659018dnd Authors:
f3ec420152ca921e4c1ce77782f51b53f659018dnd Pavel Březina <pbrezina@redhat.com>
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd Copyright (C) 2014 Red Hat
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd This program is free software; you can redistribute it and/or modify
f3ec420152ca921e4c1ce77782f51b53f659018dnd it under the terms of the GNU General Public License as published by
f3ec420152ca921e4c1ce77782f51b53f659018dnd the Free Software Foundation; either version 3 of the License, or
f3ec420152ca921e4c1ce77782f51b53f659018dnd (at your option) any later version.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen This program is distributed in the hope that it will be useful,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen but WITHOUT ANY WARRANTY; without even the implied warranty of
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f3ec420152ca921e4c1ce77782f51b53f659018dnd GNU General Public License for more details.
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd You should have received a copy of the GNU General Public License
3f08db06526d6901aa08c110b5bc7dde6bc39905nd along with this program. If not, see <http://www.gnu.org/licenses/>.
f3ec420152ca921e4c1ce77782f51b53f659018dnd*/
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd#include <talloc.h>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#include <tevent.h>
f3ec420152ca921e4c1ce77782f51b53f659018dnd#include <errno.h>
f3ec420152ca921e4c1ce77782f51b53f659018dnd#include <popt.h>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun
f3ec420152ca921e4c1ce77782f51b53f659018dnd#include "tests/cmocka/common_mock.h"
f3ec420152ca921e4c1ce77782f51b53f659018dnd#include "tests/cmocka/common_mock_resp.h"
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung#include "db/sysdb.h"
f3ec420152ca921e4c1ce77782f51b53f659018dnd#include "responder/common/responder_cache_req.h"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
f3ec420152ca921e4c1ce77782f51b53f659018dnd#define TESTS_PATH "tp_" BASE_FILE_STEM
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define TEST_CONF_DB "test_responder_cache_req_conf.ldb"
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define TEST_DOM_NAME "responder_cache_req_test"
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define TEST_ID_PROVIDER "ldap"
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define TEST_USER_PREFIX "test*"
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowenstruct test_user {
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *name;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *upn;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *sid;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen uid_t uid;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen gid_t gid;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen} users[] = {{"test-user1", "upn1@upndomain.com",
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen "S-1-5-21-3623811015-3361044348-30300820-1001", 1001, 1001},
f3ec420152ca921e4c1ce77782f51b53f659018dnd {"test-user2", "upn2@upndomain.com",
f3ec420152ca921e4c1ce77782f51b53f659018dnd "S-1-5-21-3623811015-3361044348-30300820-1002", 1002, 1002}};
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstruct test_group {
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *name;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *sid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd gid_t gid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd} groups[] = {{"test-group1", "S-1-5-21-3623811015-3361044348-30300820-2001", 2001},
f3ec420152ca921e4c1ce77782f51b53f659018dnd {"test-group2", "S-1-5-21-3623811015-3361044348-30300820-2002", 2002}};
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd#define new_single_domain_test(test) \
f3ec420152ca921e4c1ce77782f51b53f659018dnd cmocka_unit_test_setup_teardown(test_ ## test, \
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_single_domain_setup, \
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_single_domain_teardown)
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd#define new_multi_domain_test(test) \
f3ec420152ca921e4c1ce77782f51b53f659018dnd cmocka_unit_test_setup_teardown(test_ ## test, \
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_multi_domain_setup, \
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_multi_domain_teardown)
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
f3ec420152ca921e4c1ce77782f51b53f659018dnd#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
f3ec420152ca921e4c1ce77782f51b53f659018dnd TALLOC_CTX *req_mem_ctx; \
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct tevent_req *req; \
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t ret; \
f3ec420152ca921e4c1ce77782f51b53f659018dnd \
f3ec420152ca921e4c1ce77782f51b53f659018dnd req_mem_ctx = talloc_new(global_talloc_context); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd check_leaks_push(req_mem_ctx); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd \
f3ec420152ca921e4c1ce77782f51b53f659018dnd req = send_fn(req_mem_ctx, ctx->tctx->ev, ctx->rctx, \
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->ncache, crp, \
f3ec420152ca921e4c1ce77782f51b53f659018dnd (dom == NULL ? NULL : dom->name), lookup); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(req); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd tevent_req_set_callback(req, done_fn, ctx); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd \
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = test_ev_loop(ctx->tctx); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, expret); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_true(check_leaks_pop(req_mem_ctx)); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd \
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_free(req_mem_ctx); \
f3ec420152ca921e4c1ce77782f51b53f659018dnd} while (0)
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstruct cache_req_test_ctx {
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_test_ctx *tctx;
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct resp_ctx *rctx;
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_nc_ctx *ncache;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct ldb_result *result;
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *domain;
f3ec420152ca921e4c1ce77782f51b53f659018dnd char *name;
f3ec420152ca921e4c1ce77782f51b53f659018dnd bool dp_called;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd /* NOTE: Please, instead of adding new create_[user|group] bool,
f3ec420152ca921e4c1ce77782f51b53f659018dnd * use bitshift. */
f3ec420152ca921e4c1ce77782f51b53f659018dnd bool create_user1;
f3ec420152ca921e4c1ce77782f51b53f659018dnd bool create_user2;
f3ec420152ca921e4c1ce77782f51b53f659018dnd bool create_group1;
f3ec420152ca921e4c1ce77782f51b53f659018dnd bool create_group2;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen};
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndconst char *domains[] = {"responder_cache_req_test_a",
f3ec420152ca921e4c1ce77782f51b53f659018dnd "responder_cache_req_test_b",
f3ec420152ca921e4c1ce77782f51b53f659018dnd "responder_cache_req_test_c",
f3ec420152ca921e4c1ce77782f51b53f659018dnd "responder_cache_req_test_d",
f3ec420152ca921e4c1ce77782f51b53f659018dnd NULL};
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstruct cli_protocol_version *register_cli_protocol_version(void)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd static struct cli_protocol_version version[] = {
f3ec420152ca921e4c1ce77782f51b53f659018dnd { 0, NULL, NULL }
f3ec420152ca921e4c1ce77782f51b53f659018dnd };
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd return version;
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_user_by_name_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *ctx = NULL;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->error = cache_req_user_by_name_recv(ctx, req,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->result,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->domain,
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen &ctx->name);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen talloc_zfree(req);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen ctx->tctx->done = true;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen}
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowenstatic void cache_req_user_by_id_test_done(struct tevent_req *req)
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *ctx = NULL;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->error = cache_req_user_by_id_recv(ctx, req,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->result, &ctx->domain);
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(req);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->done = true;
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_group_by_name_test_done(struct tevent_req *req)
b2a930a0c94e9fd25f8d2b3a2c53573235db3f06nilgun{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *ctx = NULL;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->error = cache_req_group_by_name_recv(ctx, req,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->result,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->name);
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(req);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->done = true;
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_group_by_id_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *ctx = NULL;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->error = cache_req_group_by_id_recv(ctx, req,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->result, &ctx->domain);
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(req);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->done = true;
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_object_by_sid_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *ctx = NULL;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->error = cache_req_object_by_sid_recv(ctx, req,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->result,
f3ec420152ca921e4c1ce77782f51b53f659018dnd &ctx->domain);
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(req);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->done = true;
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void prepare_user(struct sss_domain_info *domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct test_user *user,
f3ec420152ca921e4c1ce77782f51b53f659018dnd uint64_t timeout,
f3ec420152ca921e4c1ce77782f51b53f659018dnd time_t transaction_time)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sysdb_attrs *attrs;
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t ret;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd attrs = sysdb_new_attrs(NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(attrs);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, user->upn);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, EOK);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, user->sid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, EOK);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_store_user(domain, user->name, "pwd",
f3ec420152ca921e4c1ce77782f51b53f659018dnd user->uid, user->gid, NULL, NULL, NULL,
f3ec420152ca921e4c1ce77782f51b53f659018dnd "cn=origdn,dc=test", attrs, NULL,
f3ec420152ca921e4c1ce77782f51b53f659018dnd timeout, transaction_time);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, EOK);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_free(attrs);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_user_by_name(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd int cache_refresh_percent,
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t exp_ret)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd run_cache_req(test_ctx, cache_req_user_by_name_send,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_req_user_by_name_test_done, domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_refresh_percent, users[0].name, exp_ret);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_user_by_upn(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd int cache_refresh_percent,
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t exp_ret)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd run_cache_req(test_ctx, cache_req_user_by_name_send,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_req_user_by_name_test_done, domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_refresh_percent, users[0].upn, exp_ret);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_user_by_id(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd int cache_refresh_percent,
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t exp_ret)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd run_cache_req(test_ctx, cache_req_user_by_id_send,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_req_user_by_id_test_done, domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_refresh_percent, users[0].uid, exp_ret);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void check_user(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct test_user *user,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *exp_dom)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbname;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbupn;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbsid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd uid_t ldbuid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->result);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(test_ctx->result->count, 1);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->result->msgs);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->result->msgs[0]);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd SYSDB_NAME, NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(ldbname);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(ldbname, user->name);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbupn = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd SYSDB_UPN, NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(ldbupn);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(ldbupn, user->upn);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd SYSDB_SID_STR, NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(ldbsid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(ldbsid, user->sid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd SYSDB_UIDNUM, 0);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ldbuid, user->uid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->domain);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(exp_dom->name, test_ctx->domain->name);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void prepare_group(struct sss_domain_info *domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct test_group *group,
f3ec420152ca921e4c1ce77782f51b53f659018dnd uint64_t timeout,
f3ec420152ca921e4c1ce77782f51b53f659018dnd time_t transaction_time)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sysdb_attrs *attrs;
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t ret;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd attrs = sysdb_new_attrs(NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(attrs);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, group->sid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, EOK);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_store_group(domain, group->name, group->gid, attrs,
f3ec420152ca921e4c1ce77782f51b53f659018dnd timeout, transaction_time);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, EOK);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_free(attrs);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
723b4be7951b76cd58116426912adacf55bf96ednilgunstatic void run_group_by_name(struct cache_req_test_ctx *test_ctx,
91f378b5a10f2d83820902ed10ba7967a3920c18nilgun struct sss_domain_info *domain,
723b4be7951b76cd58116426912adacf55bf96ednilgun int cache_refresh_percent,
27dcd8d81085fd60aadcd8a9bad35a607b26b758nilgun errno_t exp_ret)
723b4be7951b76cd58116426912adacf55bf96ednilgun{
723b4be7951b76cd58116426912adacf55bf96ednilgun run_cache_req(test_ctx, cache_req_group_by_name_send,
723b4be7951b76cd58116426912adacf55bf96ednilgun cache_req_group_by_name_test_done, domain,
723b4be7951b76cd58116426912adacf55bf96ednilgun cache_refresh_percent, groups[0].name, exp_ret);
723b4be7951b76cd58116426912adacf55bf96ednilgun}
723b4be7951b76cd58116426912adacf55bf96ednilgun
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_group_by_id(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd int cache_refresh_percent,
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t exp_ret)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd run_cache_req(test_ctx, cache_req_group_by_id_send,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_req_group_by_id_test_done, domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd cache_refresh_percent, groups[0].gid, exp_ret);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void check_group(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct test_group *group,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *exp_dom)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbname;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbsid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd gid_t ldbgid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->result);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(test_ctx->result->count, 1);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->result->msgs);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->result->msgs[0]);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd SYSDB_NAME, NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(ldbname);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(ldbname, group->name);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd SYSDB_SID_STR, NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(ldbsid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(ldbsid, group->sid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd SYSDB_GIDNUM, 0);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ldbgid, group->gid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->domain);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(exp_dom->name, test_ctx->domain->name);
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_object_by_sid(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct sss_domain_info *domain,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *sid,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char **attrs,
f3ec420152ca921e4c1ce77782f51b53f659018dnd int cache_refresh_percent,
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t exp_ret)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd TALLOC_CTX *req_mem_ctx;
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct tevent_req *req;
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t ret;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd req_mem_ctx = talloc_new(global_talloc_context);
f3ec420152ca921e4c1ce77782f51b53f659018dnd check_leaks_push(req_mem_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd req = cache_req_object_by_sid_send(req_mem_ctx, test_ctx->tctx->ev,
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx->rctx, test_ctx->ncache, cache_refresh_percent,
f3ec420152ca921e4c1ce77782f51b53f659018dnd (domain == NULL ? NULL : domain->name), sid, attrs);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(req);
f3ec420152ca921e4c1ce77782f51b53f659018dnd tevent_req_set_callback(req, cache_req_object_by_sid_test_done, test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = test_ev_loop(test_ctx->tctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, exp_ret);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_true(check_leaks_pop(req_mem_ctx));
f3ec420152ca921e4c1ce77782f51b53f659018dnd
d23070a273525fb69f21f5426d31a32157dad337nilgun talloc_free(req_mem_ctx);
d23070a273525fb69f21f5426d31a32157dad337nilgun}
d23070a273525fb69f21f5426d31a32157dad337nilgun
f3ec420152ca921e4c1ce77782f51b53f659018dndstruct tevent_req *
f3ec420152ca921e4c1ce77782f51b53f659018dnd__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct resp_ctx *rctx,
d23070a273525fb69f21f5426d31a32157dad337nilgun struct sss_domain_info *dom,
bcb283e92c05f9564992be3cad88399eb0a163eanilgun bool fast_reply,
f3ec420152ca921e4c1ce77782f51b53f659018dnd enum sss_dp_acct_type type,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *opt_name,
f3ec420152ca921e4c1ce77782f51b53f659018dnd uint32_t opt_id,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *extra)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *ctx = NULL;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen ctx->dp_called = true;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen if (ctx->create_user1) {
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_user(ctx->tctx->dom, &users[0], 1000, time(NULL));
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen }
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen if (ctx->create_user2) {
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_user(ctx->tctx->dom, &users[1], 1000, time(NULL));
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen }
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen if (ctx->create_group1) {
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_group(ctx->tctx->dom, &groups[0], 1000, time(NULL));
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen }
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen if (ctx->create_group2) {
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_group(ctx->tctx->dom, &groups[1], 1000, time(NULL));
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen }
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen return test_req_succeed_send(mem_ctx, rctx->ev);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen}
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowenstatic int test_single_domain_setup(void **state)
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen{
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen struct cache_req_test_ctx *test_ctx = NULL;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen errno_t ret;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_true(leak_check_setup());
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_dom_suite_setup(TESTS_PATH);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd *state = test_ctx;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen TEST_DOM_NAME, TEST_ID_PROVIDER, NULL);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen assert_non_null(test_ctx->tctx);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen test_ctx->tctx->dom, NULL);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen assert_non_null(test_ctx->rctx);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen assert_int_equal(ret, EOK);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen check_leaks_push(test_ctx);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen return 0;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen}
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowenstatic int test_single_domain_teardown(void **state)
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen{
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen struct cache_req_test_ctx *test_ctx;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(test_ctx->result);
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(test_ctx->name);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_true(check_leaks_pop(test_ctx));
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_true(leak_check_teardown());
f3ec420152ca921e4c1ce77782f51b53f659018dnd return 0;
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic int test_multi_domain_setup(void **state)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *test_ctx = NULL;
f3ec420152ca921e4c1ce77782f51b53f659018dnd errno_t ret;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_true(leak_check_setup());
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_dom_suite_setup(TESTS_PATH);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd *state = test_ctx;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
f3ec420152ca921e4c1ce77782f51b53f659018dnd TEST_CONF_DB, domains,
f3ec420152ca921e4c1ce77782f51b53f659018dnd TEST_ID_PROVIDER, NULL);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_non_null(test_ctx->tctx);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx->tctx->dom, NULL);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen assert_non_null(test_ctx->rctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_int_equal(ret, EOK);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd reset_ldb_errstrings(test_ctx->tctx->dom);
f3ec420152ca921e4c1ce77782f51b53f659018dnd check_leaks_push(test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd return 0;
f3ec420152ca921e4c1ce77782f51b53f659018dnd}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic int test_multi_domain_teardown(void **state)
f3ec420152ca921e4c1ce77782f51b53f659018dnd{
f3ec420152ca921e4c1ce77782f51b53f659018dnd struct cache_req_test_ctx *test_ctx;
f3ec420152ca921e4c1ce77782f51b53f659018dnd
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(test_ctx->result);
f3ec420152ca921e4c1ce77782f51b53f659018dnd talloc_zfree(test_ctx->name);
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung
f3ec420152ca921e4c1ce77782f51b53f659018dnd reset_ldb_errstrings(test_ctx->tctx->dom);
5effc8b39fae5cd169d17f342bfc265705840014rbowen assert_true(check_leaks_pop(test_ctx));
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen talloc_zfree(test_ctx);
2c9e74eac9f72c14535dd65a520e4de2e664d9cdhumbedooh test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen assert_true(leak_check_teardown());
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen return 0;
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen}
f3ec420152ca921e4c1ce77782f51b53f659018dnd
void test_user_by_name_multiple_domains_found(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
struct sss_domain_info *domain = NULL;
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);
prepare_user(domain, &users[0], 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(users[0].name, NULL, ERR_OK);
/* Test. */
run_user_by_name(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], domain);
}
void test_user_by_name_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_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(users[0].name, NULL, ERR_OK);
/* Test. */
run_user_by_name(test_ctx, NULL, 0, ENOENT);
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 = users[0].name;
char *fqn;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* 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", 2000, 1000,
NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);
/* 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);
prepare_user(domain, &users[0], 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);
req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 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);
check_user(test_ctx, &users[0], domain);
assert_non_null(test_ctx->name);
assert_string_equal(name, test_ctx->name);
talloc_free(fqn);
}
void test_user_by_name_cache_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_name_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_name_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_name_ncache(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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, users[0].name);
assert_int_equal(ret, EOK);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_name_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* 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 sss_domain_info *domain = NULL;
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);
prepare_user(domain, &users[0], 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);
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], domain);
}
void test_user_by_upn_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_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);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
/* Mock values. */
mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_upn_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], -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);
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_upn_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 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);
/* Test. */
run_user_by_upn(test_ctx, NULL, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_upn_ncache(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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, users[0].upn);
assert_int_equal(ret, EOK);
/* Mock values. */
mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_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_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_upn_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_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. */
run_user_by_upn(test_ctx, NULL, 0, ENOENT);
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;
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);
prepare_user(domain, &users[0], 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);
/* Test. */
run_user_by_id(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], domain);
}
void test_user_by_id_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_id_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
/* Mock values. */
/* DP should be contacted. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_id_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_id_ncache(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
ret = sss_ncache_set_uid(test_ctx->ncache, false, NULL, users[0].uid);
assert_int_equal(ret, EOK);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_user_by_id_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
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;
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(domain, &groups[0], 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(groups[0].name, NULL, ERR_OK);
/* Test. */
run_group_by_name(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], domain);
}
void test_group_by_name_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_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(groups[0].name, NULL, ERR_OK);
/* Test. */
run_group_by_name(test_ctx, NULL, 0, ENOENT);
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 = groups[0].name;
char *fqn;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* 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, 2000, NULL,
1000, time(NULL));
assert_int_equal(ret, EOK);
/* 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);
prepare_group(domain, &groups[0], 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);
/* 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_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx, test_ctx->ncache, 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);
check_group(test_ctx, &groups[0], domain);
assert_non_null(test_ctx->name);
assert_string_equal(name, test_ctx->name);
talloc_free(fqn);
}
void test_group_by_name_cache_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_name_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_name_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_name_ncache(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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, groups[0].name);
assert_int_equal(ret, EOK);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_name_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
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;
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(domain, &groups[0], 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);
/* Test. */
run_group_by_id(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], domain);
}
void test_group_by_id_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_id_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_id_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_id_ncache(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
ret = sss_ncache_set_gid(test_ctx->ncache, false, NULL, groups[0].gid);
assert_int_equal(ret, EOK);
/* 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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_group_by_id_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
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_user_by_recent_filter_valid(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_user1 = true;
test_ctx->create_user2 = false;
prepare_user(test_ctx->tctx->dom, &users[1], 1000, time(NULL) - 1);
req_mem_ctx = talloc_new(test_ctx->tctx);
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();
/* User TEST_USER is created with a DP callback. */
req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
test_ctx->tctx->dom->name,
TEST_USER_PREFIX);
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, users[0].name);
}
void test_users_by_recent_filter_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
struct tevent_req *req = NULL;
size_t num_users = 2;
const char *user_names[num_users];
const char *ldb_results[num_users];
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
test_ctx->create_user1 = true;
test_ctx->create_user2 = true;
req_mem_ctx = talloc_new(test_ctx->tctx);
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();
/* User TEST_USER1 and TEST_USER2 are created with a DP callback. */
req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
test_ctx->tctx->dom->name,
TEST_USER_PREFIX);
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, 2);
user_names[0] = users[0].name;
user_names[1] = users[1].name;
for (int i = 0; i < num_users; ++i) {
ldb_results[i] = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i],
SYSDB_NAME, NULL);
assert_non_null(ldb_results[i]);
}
assert_string_not_equal(ldb_results[0], ldb_results[1]);
assert_true(are_values_in_array(user_names, num_users,
ldb_results, num_users));
}
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_user1 = true;
test_ctx->create_user2 = false;
/* This user was updated in distant past, so it wont't be reported by
* the filter search */
prepare_user(test_ctx->tctx->dom, &users[1], 1000, 1);
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_USER_PREFIX);
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, users[0].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_group_by_recent_filter_valid(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_group1 = true;
test_ctx->create_group2 = false;
prepare_group(test_ctx->tctx->dom, &groups[1], 1001, time(NULL) - 1);
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();
/* Group TEST_GROUP is created with a DP callback. */
req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
test_ctx->tctx->dom->name,
TEST_USER_PREFIX);
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, 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, groups[0].name);
}
void test_groups_by_recent_filter_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
TALLOC_CTX *req_mem_ctx = NULL;
TALLOC_CTX *tmp_ctx = NULL;
struct tevent_req *req = NULL;
const char **group_names = NULL;
const char **ldb_results = NULL;
const char *ldbname = NULL;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
test_ctx->create_group1 = true;
test_ctx->create_group2 = true;
prepare_group(test_ctx->tctx->dom, &groups[1], 1001, time(NULL) - 1);
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();
/* Group TEST_GROUP1 and TEST_GROUP2 are created with a DP callback. */
req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
test_ctx->tctx->dom->name,
TEST_USER_PREFIX);
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, ERR_OK);
assert_true(check_leaks_pop(req_mem_ctx));
assert_non_null(test_ctx->result);
assert_int_equal(test_ctx->result->count, 2);
tmp_ctx = talloc_new(req_mem_ctx);
group_names = talloc_array(tmp_ctx, const char *, 2);
assert_non_null(group_names);
group_names[0] = groups[0].name;
group_names[1] = groups[1].name;
ldb_results = talloc_array(tmp_ctx, const char *, 2);
assert_non_null(ldb_results);
for (int i = 0; i < 2; ++i) {
ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i],
SYSDB_NAME, NULL);
assert_non_null(ldbname);
ldb_results[i] = ldbname;
}
assert_string_not_equal(ldb_results[0], ldb_results[1]);
assert_true(tc_are_values_in_array(group_names, ldb_results));
talloc_zfree(tmp_ctx);
}
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));
}
void test_object_by_sid_user_cache_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
users[0].sid, attrs, 0, ERR_OK);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_object_by_sid_user_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
users[0].sid, attrs, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_object_by_sid_user_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
users[0].sid, attrs, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_object_by_sid_user_ncache(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
ret = sss_ncache_set_sid(test_ctx->ncache, false, users[0].sid);
assert_int_equal(ret, EOK);
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
users[0].sid, attrs, 0, ENOENT);
assert_false(test_ctx->dp_called);
}
void test_object_by_sid_user_missing_found(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
users[0].sid, attrs, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], test_ctx->tctx->dom);
}
void test_object_by_sid_user_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
users[0].sid, attrs, 0, ENOENT);
assert_true(test_ctx->dp_called);
}
void test_object_by_sid_user_multiple_domains_found(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
struct sss_domain_info *domain = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
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);
prepare_user(domain, &users[0], 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);
/* Test. */
run_object_by_sid(test_ctx, NULL, users[0].sid, attrs, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, &users[0], domain);
}
void test_object_by_sid_user_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_PW_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
/* Test. */
run_object_by_sid(test_ctx, NULL, users[0].sid, attrs, 0, ENOENT);
assert_true(test_ctx->dp_called);
}
void test_object_by_sid_group_cache_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
groups[0].sid, attrs, 0, ERR_OK);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_object_by_sid_group_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
groups[0].sid, attrs, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_object_by_sid_group_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
groups[0].sid, attrs, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_object_by_sid_group_ncache(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
errno_t ret;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
ret = sss_ncache_set_sid(test_ctx->ncache, false, groups[0].sid);
assert_int_equal(ret, EOK);
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
groups[0].sid, attrs, 0, ENOENT);
assert_false(test_ctx->dp_called);
}
void test_object_by_sid_group_missing_found(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
groups[0].sid, attrs, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
}
void test_object_by_sid_group_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_object_by_sid(test_ctx, test_ctx->tctx->dom,
groups[0].sid, attrs, 0, ENOENT);
assert_true(test_ctx->dp_called);
}
void test_object_by_sid_group_multiple_domains_found(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
struct sss_domain_info *domain = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
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);
prepare_group(domain, &groups[0], 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);
/* Test. */
run_object_by_sid(test_ctx, NULL, groups[0].sid, attrs, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, &groups[0], domain);
}
void test_object_by_sid_group_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
const char *attrs[] = SYSDB_GRSRC_ATTRS;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
/* Test. */
run_object_by_sid(test_ctx, NULL, groups[0].sid, attrs, 0, ENOENT);
assert_true(test_ctx->dp_called);
}
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_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),
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(user_by_recent_filter_valid),
new_single_domain_test(users_by_recent_filter_valid),
new_single_domain_test(group_by_recent_filter_valid),
new_single_domain_test(groups_by_recent_filter_valid),
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),
new_single_domain_test(object_by_sid_user_cache_valid),
new_single_domain_test(object_by_sid_user_cache_expired),
new_single_domain_test(object_by_sid_user_cache_midpoint),
new_single_domain_test(object_by_sid_user_ncache),
new_single_domain_test(object_by_sid_user_missing_found),
new_single_domain_test(object_by_sid_user_missing_notfound),
new_multi_domain_test(object_by_sid_user_multiple_domains_found),
new_multi_domain_test(object_by_sid_user_multiple_domains_notfound),
new_single_domain_test(object_by_sid_group_cache_valid),
new_single_domain_test(object_by_sid_group_cache_expired),
new_single_domain_test(object_by_sid_group_cache_midpoint),
new_single_domain_test(object_by_sid_group_ncache),
new_single_domain_test(object_by_sid_group_missing_found),
new_single_domain_test(object_by_sid_group_missing_notfound),
new_multi_domain_test(object_by_sid_group_multiple_domains_found),
new_multi_domain_test(object_by_sid_group_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);
}