test_responder_cache_req.c revision a257259b05d62ebe548b6c798a3aa03a97dbc0c2
f3ec420152ca921e4c1ce77782f51b53f659018dnd Pavel Březina <pbrezina@redhat.com>
f3ec420152ca921e4c1ce77782f51b53f659018dnd Copyright (C) 2014 Red Hat
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 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 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/>.
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen#define TEST_CONF_DB "test_responder_cache_req_conf.ldb"
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *name;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *upn;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen const char *sid;
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen "S-1-5-21-3623811015-3361044348-30300820-1001", 1001, 1001},
f3ec420152ca921e4c1ce77782f51b53f659018dnd "S-1-5-21-3623811015-3361044348-30300820-1002", 1002, 1002}};
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *name;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *sid;
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#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
f3ec420152ca921e4c1ce77782f51b53f659018dnd} while (0)
f3ec420152ca921e4c1ce77782f51b53f659018dnd /* NOTE: Please, instead of adding new create_[user|group] bool,
f3ec420152ca921e4c1ce77782f51b53f659018dnd * use bitshift. */
f3ec420152ca921e4c1ce77782f51b53f659018dnd "responder_cache_req_test_b",
f3ec420152ca921e4c1ce77782f51b53f659018dnd "responder_cache_req_test_c",
f3ec420152ca921e4c1ce77782f51b53f659018dnd "responder_cache_req_test_d",
f3ec420152ca921e4c1ce77782f51b53f659018dndstruct cli_protocol_version *register_cli_protocol_version(void)
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_user_by_name_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowenstatic void cache_req_user_by_id_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_group_by_name_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->error = cache_req_group_by_name_recv(ctx, req,
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_group_by_id_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void cache_req_object_by_sid_test_done(struct tevent_req *req)
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd ctx->tctx->error = cache_req_object_by_sid_recv(ctx, req,
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, user->upn);
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, user->sid);
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_user_by_name(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_user_by_upn(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_user_by_id(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void check_user(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbname;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbupn;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbsid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbupn = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(exp_dom->name, test_ctx->domain->name);
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, group->sid);
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sysdb_store_group(domain, group->name, group->gid, attrs,
723b4be7951b76cd58116426912adacf55bf96ednilgunstatic void run_group_by_name(struct cache_req_test_ctx *test_ctx,
723b4be7951b76cd58116426912adacf55bf96ednilgun run_cache_req(test_ctx, cache_req_group_by_name_send,
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_group_by_id(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void check_group(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbname;
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *ldbsid;
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
f3ec420152ca921e4c1ce77782f51b53f659018dnd assert_string_equal(exp_dom->name, test_ctx->domain->name);
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic void run_object_by_sid(struct cache_req_test_ctx *test_ctx,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *sid,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char **attrs,
f3ec420152ca921e4c1ce77782f51b53f659018dnd req = cache_req_object_by_sid_send(req_mem_ctx, test_ctx->tctx->ev,
f3ec420152ca921e4c1ce77782f51b53f659018dnd tevent_req_set_callback(req, cache_req_object_by_sid_test_done, test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *opt_name,
f3ec420152ca921e4c1ce77782f51b53f659018dnd const char *extra)
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_user(ctx->tctx->dom, &users[0], 1000, time(NULL));
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_user(ctx->tctx->dom, &users[1], 1000, time(NULL));
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_group(ctx->tctx->dom, &groups[0], 1000, time(NULL));
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen prepare_group(ctx->tctx->dom, &groups[1], 1000, time(NULL));
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
d1636bdc2e674b84ee46f534b51be18ecac6bef5rbowen test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
f3ec420152ca921e4c1ce77782f51b53f659018dnd ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
f3ec420152ca921e4c1ce77782f51b53f659018dnd test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
2c9e74eac9f72c14535dd65a520e4de2e664d9cdhumbedooh test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
char *fqn;
char *fqn;
for (int i = 0; i < num_users; ++i) {
int opt;
switch(opt) {