test_responder_cache_req.c revision da79bee1472a06b89be2df903fb0bd8ce600c610
af84459fbf938e508fd10b01cb8d699c79083813takashi/*
af84459fbf938e508fd10b01cb8d699c79083813takashi Authors:
af84459fbf938e508fd10b01cb8d699c79083813takashi Pavel Březina <pbrezina@redhat.com>
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi Copyright (C) 2014 Red Hat
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi This program is free software; you can redistribute it and/or modify
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen it under the terms of the GNU General Public License as published by
af84459fbf938e508fd10b01cb8d699c79083813takashi the Free Software Foundation; either version 3 of the License, or
af84459fbf938e508fd10b01cb8d699c79083813takashi (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
af84459fbf938e508fd10b01cb8d699c79083813takashi GNU General Public License for more details.
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi 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/>.
af84459fbf938e508fd10b01cb8d699c79083813takashi*/
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi#include <talloc.h>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#include <tevent.h>
af84459fbf938e508fd10b01cb8d699c79083813takashi#include <errno.h>
af84459fbf938e508fd10b01cb8d699c79083813takashi#include <popt.h>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "tests/cmocka/common_mock.h"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen#include "tests/cmocka/common_mock_resp.h"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen#include "db/sysdb.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "responder/common/responder_cache_req.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi#define TESTS_PATH "tp_" BASE_FILE_STEM
af84459fbf938e508fd10b01cb8d699c79083813takashi#define TEST_CONF_DB "test_responder_cache_req_conf.ldb"
3c13a815670b54d1c17bf02954f7d2b066cde95cnd#define TEST_DOM_NAME "responder_cache_req_test"
3c13a815670b54d1c17bf02954f7d2b066cde95cnd#define TEST_ID_PROVIDER "ldap"
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define TEST_USER_NAME "test-user"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define TEST_UPN "upn@upndomain.com"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define TEST_USER_ID 1000
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define TEST_GROUP_NAME "test-group"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define TEST_GROUP_ID 1000
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define TEST_USER_NAME2 "test-user2"
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen#define TEST_GROUP_NAME2 "test-group2"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define new_single_domain_test(test) \
af84459fbf938e508fd10b01cb8d699c79083813takashi cmocka_unit_test_setup_teardown(test_ ## test, \
af84459fbf938e508fd10b01cb8d699c79083813takashi test_single_domain_setup, \
af84459fbf938e508fd10b01cb8d699c79083813takashi test_single_domain_teardown)
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi#define new_multi_domain_test(test) \
af84459fbf938e508fd10b01cb8d699c79083813takashi cmocka_unit_test_setup_teardown(test_ ## test, \
af84459fbf938e508fd10b01cb8d699c79083813takashi test_multi_domain_setup, \
af84459fbf938e508fd10b01cb8d699c79083813takashi test_multi_domain_teardown)
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
af84459fbf938e508fd10b01cb8d699c79083813takashi#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
af84459fbf938e508fd10b01cb8d699c79083813takashi TALLOC_CTX *req_mem_ctx; \
af84459fbf938e508fd10b01cb8d699c79083813takashi struct tevent_req *req; \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe errno_t ret; \
af84459fbf938e508fd10b01cb8d699c79083813takashi \
3c13a815670b54d1c17bf02954f7d2b066cde95cnd req_mem_ctx = talloc_new(global_talloc_context); \
af84459fbf938e508fd10b01cb8d699c79083813takashi check_leaks_push(req_mem_ctx); \
af84459fbf938e508fd10b01cb8d699c79083813takashi \
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen req = send_fn(req_mem_ctx, ctx->tctx->ev, ctx->rctx, \
af84459fbf938e508fd10b01cb8d699c79083813takashi ctx->ncache, 10, crp, \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe (dom == NULL ? NULL : dom->name), lookup); \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(req); \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe tevent_req_set_callback(req, done_fn, ctx); \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ret = test_ev_loop(ctx->tctx); \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_int_equal(ret, expret); \
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf assert_true(check_leaks_pop(req_mem_ctx)); \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe talloc_free(req_mem_ctx); \
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe} while (0)
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrinstruct cache_req_test_ctx {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_test_ctx *tctx;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct resp_ctx *rctx;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_nc_ctx *ncache;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct ldb_result *result;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_domain_info *domain;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe char *name;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe bool dp_called;
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen bool create_user;
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen bool create_group;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe};
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wroweconst char *domains[] = {"responder_cache_req_test_a",
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "responder_cache_req_test_b",
4bebf996eb7002ebfe897d46a0e0572390604a77nd "responder_cache_req_test_c",
4bebf996eb7002ebfe897d46a0e0572390604a77nd "responder_cache_req_test_d",
4bebf996eb7002ebfe897d46a0e0572390604a77nd NULL};
4bebf996eb7002ebfe897d46a0e0572390604a77nd
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestruct cli_protocol_version *register_cli_protocol_version(void)
4bebf996eb7002ebfe897d46a0e0572390604a77nd{
9534272616b71aaea50aeec4162e749a96aebd7fsf static struct cli_protocol_version version[] = {
4bebf996eb7002ebfe897d46a0e0572390604a77nd { 0, NULL, NULL }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe };
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi return version;
af84459fbf938e508fd10b01cb8d699c79083813takashi}
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashistatic void cache_req_user_by_name_test_done(struct tevent_req *req)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct cache_req_test_ctx *ctx = NULL;
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->error = cache_req_user_by_name_recv(ctx, req,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->result,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->domain,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->name);
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen talloc_zfree(req);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->done = true;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void cache_req_user_by_id_test_done(struct tevent_req *req)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct cache_req_test_ctx *ctx = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->error = cache_req_user_by_id_recv(ctx, req,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->result, &ctx->domain);
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen talloc_zfree(req);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->done = true;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void cache_req_group_by_name_test_done(struct tevent_req *req)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct cache_req_test_ctx *ctx = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->error = cache_req_group_by_name_recv(ctx, req,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->result,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->domain,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->name);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe talloc_zfree(req);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->done = true;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void cache_req_group_by_id_test_done(struct tevent_req *req)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct cache_req_test_ctx *ctx = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->error = cache_req_group_by_id_recv(ctx, req,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe &ctx->result, &ctx->domain);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe talloc_zfree(req);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->tctx->done = true;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void prepare_user(TALLOC_CTX *mem_ctx,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_domain_info *domain,
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd uint64_t timeout,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe time_t transaction_time)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sysdb_attrs *attrs;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe errno_t ret;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe attrs = sysdb_new_attrs(mem_ctx);
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd assert_non_null(attrs);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, TEST_UPN);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_int_equal(ret, EOK);
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ret = sysdb_store_user(domain, TEST_USER_NAME, "pwd",
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe TEST_USER_ID, TEST_GROUP_ID, NULL, NULL, NULL,
af84459fbf938e508fd10b01cb8d699c79083813takashi "cn=test-user,dc=test", attrs, NULL,
af84459fbf938e508fd10b01cb8d699c79083813takashi timeout, transaction_time);
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen assert_int_equal(ret, EOK);
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void run_user_by_name(struct cache_req_test_ctx *test_ctx,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_domain_info *domain,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe int cache_refresh_percent,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe errno_t exp_ret)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
c8c717fafa0a09ed13469a603a178921b851dd22igalic run_cache_req(test_ctx, cache_req_user_by_name_send,
c8c717fafa0a09ed13469a603a178921b851dd22igalic cache_req_user_by_name_test_done, domain,
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic cache_refresh_percent, TEST_USER_NAME, exp_ret);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic}
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic
b7f8d802ecaed65eada1fc31472d06d8460d5528igalicstatic void run_user_by_upn(struct cache_req_test_ctx *test_ctx,
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic struct sss_domain_info *domain,
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic int cache_refresh_percent,
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic errno_t exp_ret)
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic{
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic run_cache_req(test_ctx, cache_req_user_by_name_send,
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor cache_req_user_by_name_test_done, domain,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe cache_refresh_percent, TEST_UPN, exp_ret);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void run_user_by_id(struct cache_req_test_ctx *test_ctx,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_domain_info *domain,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe int cache_refresh_percent,
c8c717fafa0a09ed13469a603a178921b851dd22igalic errno_t exp_ret)
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor{
4bebf996eb7002ebfe897d46a0e0572390604a77nd run_cache_req(test_ctx, cache_req_user_by_id_send,
4bebf996eb7002ebfe897d46a0e0572390604a77nd cache_req_user_by_id_test_done, domain,
4bebf996eb7002ebfe897d46a0e0572390604a77nd cache_refresh_percent, TEST_USER_ID, exp_ret);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void check_user(struct cache_req_test_ctx *test_ctx,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_domain_info *exp_dom)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf const char *ldbname;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe const char *ldbupn;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe uid_t ldbuid;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(test_ctx->result);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_int_equal(test_ctx->result->count, 1);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(test_ctx->result->msgs);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(test_ctx->result->msgs[0]);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe SYSDB_NAME, NULL);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(ldbname);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_string_equal(ldbname, TEST_USER_NAME);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ldbupn = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe SYSDB_UPN, NULL);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(ldbupn);
8559a67073808d84d85bb5dd552d4247caafe709sf assert_string_equal(ldbupn, TEST_UPN);
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe SYSDB_UIDNUM, 0);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_int_equal(ldbuid, TEST_USER_ID);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(test_ctx->domain);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_string_equal(exp_dom->name, test_ctx->domain->name);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
8559a67073808d84d85bb5dd552d4247caafe709sfstatic void prepare_group(TALLOC_CTX *mem_ctx,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct sss_domain_info *domain,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe uint64_t timeout,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe time_t transaction_time)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
c8c717fafa0a09ed13469a603a178921b851dd22igalic errno_t ret;
c8c717fafa0a09ed13469a603a178921b851dd22igalic
8559a67073808d84d85bb5dd552d4247caafe709sf ret = sysdb_store_group(domain, TEST_GROUP_NAME, TEST_GROUP_ID, NULL,
c8c717fafa0a09ed13469a603a178921b851dd22igalic timeout, transaction_time);
c8c717fafa0a09ed13469a603a178921b851dd22igalic assert_int_equal(ret, EOK);
c8c717fafa0a09ed13469a603a178921b851dd22igalic}
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfstatic void run_group_by_name(struct cache_req_test_ctx *test_ctx,
8559a67073808d84d85bb5dd552d4247caafe709sf struct sss_domain_info *domain,
8559a67073808d84d85bb5dd552d4247caafe709sf int cache_refresh_percent,
8559a67073808d84d85bb5dd552d4247caafe709sf errno_t exp_ret)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf run_cache_req(test_ctx, cache_req_group_by_name_send,
8559a67073808d84d85bb5dd552d4247caafe709sf cache_req_group_by_name_test_done, domain,
8559a67073808d84d85bb5dd552d4247caafe709sf cache_refresh_percent, TEST_GROUP_NAME, exp_ret);
8559a67073808d84d85bb5dd552d4247caafe709sf}
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfstatic void run_group_by_id(struct cache_req_test_ctx *test_ctx,
8559a67073808d84d85bb5dd552d4247caafe709sf struct sss_domain_info *domain,
8559a67073808d84d85bb5dd552d4247caafe709sf int cache_refresh_percent,
8559a67073808d84d85bb5dd552d4247caafe709sf errno_t exp_ret)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf run_cache_req(test_ctx, cache_req_group_by_id_send,
8559a67073808d84d85bb5dd552d4247caafe709sf cache_req_group_by_id_test_done, domain,
8559a67073808d84d85bb5dd552d4247caafe709sf cache_refresh_percent, TEST_GROUP_ID, exp_ret);
8559a67073808d84d85bb5dd552d4247caafe709sf}
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfstatic void check_group(struct cache_req_test_ctx *test_ctx,
8559a67073808d84d85bb5dd552d4247caafe709sf struct sss_domain_info *exp_dom)
8559a67073808d84d85bb5dd552d4247caafe709sf{
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf const char *ldbname;
4bebf996eb7002ebfe897d46a0e0572390604a77nd gid_t ldbgid;
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd assert_non_null(test_ctx->result);
4bebf996eb7002ebfe897d46a0e0572390604a77nd assert_int_equal(test_ctx->result->count, 1);
4bebf996eb7002ebfe897d46a0e0572390604a77nd assert_non_null(test_ctx->result->msgs);
4bebf996eb7002ebfe897d46a0e0572390604a77nd assert_non_null(test_ctx->result->msgs[0]);
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
4bebf996eb7002ebfe897d46a0e0572390604a77nd SYSDB_NAME, NULL);
4bebf996eb7002ebfe897d46a0e0572390604a77nd assert_non_null(ldbname);
4bebf996eb7002ebfe897d46a0e0572390604a77nd assert_string_equal(ldbname, TEST_GROUP_NAME);
4bebf996eb7002ebfe897d46a0e0572390604a77nd
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe SYSDB_GIDNUM, 0);
af84459fbf938e508fd10b01cb8d699c79083813takashi assert_int_equal(ldbgid, TEST_USER_ID);
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi assert_non_null(test_ctx->domain);
af84459fbf938e508fd10b01cb8d699c79083813takashi assert_string_equal(exp_dom->name, test_ctx->domain->name);
af84459fbf938e508fd10b01cb8d699c79083813takashi}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestruct tevent_req *
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic struct resp_ctx *rctx,
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic struct sss_domain_info *dom,
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic bool fast_reply,
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic enum sss_dp_acct_type type,
9534272616b71aaea50aeec4162e749a96aebd7fsf const char *opt_name,
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic uint32_t opt_id,
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic const char *extra)
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic{
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic struct cache_req_test_ctx *ctx = NULL;
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic errno_t ret;
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ctx->dp_called = true;
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen if (ctx->create_user) {
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen prepare_user(ctx, ctx->tctx->dom, 1000, time(NULL));
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen }
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen if (ctx->create_group) {
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen TEST_GROUP_ID, NULL, 1000, time(NULL));
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen assert_int_equal(ret, EOK);
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen }
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen
4126704c4950bfd46d32ad54e3b106ac6d868a73sf return test_req_succeed_send(mem_ctx, rctx->ev);
4126704c4950bfd46d32ad54e3b106ac6d868a73sf}
4126704c4950bfd46d32ad54e3b106ac6d868a73sf
4126704c4950bfd46d32ad54e3b106ac6d868a73sfstatic int test_single_domain_setup(void **state)
4126704c4950bfd46d32ad54e3b106ac6d868a73sf{
4126704c4950bfd46d32ad54e3b106ac6d868a73sf struct cache_req_test_ctx *test_ctx = NULL;
4126704c4950bfd46d32ad54e3b106ac6d868a73sf errno_t ret;
4126704c4950bfd46d32ad54e3b106ac6d868a73sf
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe test_dom_suite_setup(TESTS_PATH);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
af84459fbf938e508fd10b01cb8d699c79083813takashi test_ctx = talloc_zero(NULL, struct cache_req_test_ctx);
af84459fbf938e508fd10b01cb8d699c79083813takashi assert_non_null(test_ctx);
af84459fbf938e508fd10b01cb8d699c79083813takashi *state = test_ctx;
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe TEST_DOM_NAME, TEST_ID_PROVIDER, NULL);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(test_ctx->tctx);
af84459fbf938e508fd10b01cb8d699c79083813takashi
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe test_ctx->tctx->dom, NULL);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(test_ctx->rctx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ret = sss_ncache_init(test_ctx, &test_ctx->ncache);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_int_equal(ret, EOK);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return 0;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic int test_single_domain_teardown(void **state)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe talloc_zfree(*state);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
c8c717fafa0a09ed13469a603a178921b851dd22igalic return 0;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic int test_multi_domain_setup(void **state)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe struct cache_req_test_ctx *test_ctx = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe errno_t ret;
c8c717fafa0a09ed13469a603a178921b851dd22igalic
c8c717fafa0a09ed13469a603a178921b851dd22igalic test_dom_suite_setup(TESTS_PATH);
c8c717fafa0a09ed13469a603a178921b851dd22igalic
c8c717fafa0a09ed13469a603a178921b851dd22igalic test_ctx = talloc_zero(NULL, struct cache_req_test_ctx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe assert_non_null(test_ctx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe *state = test_ctx;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe TEST_CONF_DB, domains,
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe TEST_ID_PROVIDER, NULL);
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe assert_non_null(test_ctx->tctx);
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe
c8c717fafa0a09ed13469a603a178921b851dd22igalic test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
c8c717fafa0a09ed13469a603a178921b851dd22igalic test_ctx->tctx->dom, NULL);
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe assert_non_null(test_ctx->rctx);
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe
c8c717fafa0a09ed13469a603a178921b851dd22igalic ret = sss_ncache_init(test_ctx, &test_ctx->ncache);
c8c717fafa0a09ed13469a603a178921b851dd22igalic assert_int_equal(ret, EOK);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return 0;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic int test_multi_domain_teardown(void **state)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe talloc_zfree(*state);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return 0;
af84459fbf938e508fd10b01cb8d699c79083813takashi}
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashivoid test_user_by_name_multiple_domains_found(void **state)
af84459fbf938e508fd10b01cb8d699c79083813takashi{
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung struct cache_req_test_ctx *test_ctx = NULL;
af84459fbf938e508fd10b01cb8d699c79083813takashi struct sss_domain_info *domain = NULL;
5effc8b39fae5cd169d17f342bfc265705840014rbowen
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd /* Setup user. */
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd domain = find_domain_by_name(test_ctx->tctx->dom,
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd "responder_cache_req_test_d", true);
af84459fbf938e508fd10b01cb8d699c79083813takashi assert_non_null(domain);
prepare_user(test_ctx, domain, 1000, time(NULL));
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
mock_parse_inp(TEST_USER_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, 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(TEST_USER_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 = TEST_USER_NAME;
const char *fqn = NULL;
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(test_ctx, domain, 1000, time(NULL));
/* Append domain name to the username. */
fqn = talloc_asprintf(test_ctx, "%s@%s", name,
"responder_cache_req_test_d");
assert_non_null(fqn);
/* Mock values. */
mock_parse_inp(name, "responder_cache_req_test_d", ERR_OK);
/* Test. */
req_mem_ctx = talloc_new(global_talloc_context);
check_leaks_push(req_mem_ctx);
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);
check_user(test_ctx, domain);
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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 1000, time(NULL));
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_name_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_name_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, 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, TEST_USER_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_user = true;
/* Test. */
run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_name_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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(test_ctx, domain, 1000, time(NULL));
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, 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, test_ctx->tctx->dom, 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, 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, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_upn_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
/* Test. */
run_user_by_upn(test_ctx, NULL, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, 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, TEST_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_user = true;
/* Test. */
run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_upn_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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(test_ctx, domain, 1000, time(NULL));
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
/* Test. */
run_user_by_id(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, 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, test_ctx->tctx->dom, 1000, time(NULL));
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_id_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */
/* DP should be contacted. */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_id_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup user. */
prepare_user(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, 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, TEST_USER_ID);
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_user = true;
/* Test. */
run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_user(test_ctx, test_ctx->tctx->dom);
}
void test_user_by_id_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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(test_ctx, domain, 1000, time(NULL));
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
mock_parse_inp(TEST_GROUP_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, 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(TEST_GROUP_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 = TEST_GROUP_NAME;
const char *fqn = NULL;
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(test_ctx, domain, 1000, time(NULL));
/* Append domain name to the username. */
fqn = talloc_asprintf(test_ctx, "%s@%s", name,
"responder_cache_req_test_d");
assert_non_null(fqn);
/* 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, 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);
check_group(test_ctx, domain);
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;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, 1000, time(NULL));
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_group(test_ctx, test_ctx->tctx->dom);
}
void test_group_by_name_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, test_ctx->tctx->dom);
}
void test_group_by_name_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, 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, TEST_GROUP_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_group = true;
/* Test. */
run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, test_ctx->tctx->dom);
}
void test_group_by_name_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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(test_ctx, domain, 1000, time(NULL));
/* Mock values. */
will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
will_return_always(sss_dp_get_account_recv, 0);
/* Test. */
run_group_by_id(test_ctx, NULL, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, 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, test_ctx->tctx->dom, 1000, time(NULL));
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
check_group(test_ctx, test_ctx->tctx->dom);
}
void test_group_by_id_cache_expired(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, -1000, time(NULL));
/* Mock values. */
/* DP should be contacted */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
mock_account_recv_simple();
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, test_ctx->tctx->dom);
}
void test_group_by_id_cache_midpoint(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
/* Setup group. */
prepare_group(test_ctx, test_ctx->tctx->dom, 50, time(NULL) - 26);
/* Mock values. */
/* DP should be contacted without callback */
will_return(__wrap_sss_dp_get_account_send, test_ctx);
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, 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, TEST_GROUP_ID);
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_group = true;
/* Test. */
run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
assert_true(test_ctx->dp_called);
check_group(test_ctx, test_ctx->tctx->dom);
}
void test_group_by_id_missing_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
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_user = true;
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, time(NULL)-1);
assert_int_equal(ret, EOK);
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*");
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_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_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_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);
}