360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina Pavel Březina <pbrezina@redhat.com>
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina Copyright (C) 2014 Red Hat
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina This program is free software; you can redistribute it and/or modify
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina it under the terms of the GNU General Public License as published by
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina the Free Software Foundation; either version 3 of the License, or
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina (at your option) any later version.
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina This program is distributed in the hope that it will be useful,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina GNU General Public License for more details.
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina You should have received a copy of the GNU General Public License
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
4169fb26ea2ff93c19ecdad6e09382732ea5deebPavel Březina#include "responder/common/cache_req/cache_req.h"
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek#include "db/sysdb_private.h" /* new_subdomain() */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#define TEST_CONF_DB "test_responder_cache_req_conf.ldb"
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#define TEST_DOM_NAME "responder_cache_req_test"
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina} users[] = {{"test-user1", "upn1@upndomain.com",
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina "S-1-5-21-3623811015-3361044348-30300820-1001", 1001, 1001},
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina "S-1-5-21-3623811015-3361044348-30300820-1002", 1002, 1002}};
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina} groups[] = {{"test-group1", "S-1-5-21-3623811015-3361044348-30300820-2001", 2001},
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina {"test-group2", "S-1-5-21-3623811015-3361044348-30300820-2002", 2002}};
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_ ## test, \
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_ ## test, \
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek cmocka_unit_test_setup_teardown(test_ ## test, \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina req_mem_ctx = talloc_new(global_talloc_context); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina req = send_fn(req_mem_ctx, ctx->tctx->ev, ctx->rctx, \
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek#define run_cache_req_domtype(ctx, send_fn, done_fn, dom, crp, domtype, lookup, expret) do { \
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context); \
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek req = send_fn(req_mem_ctx, ctx->tctx->ev, ctx->rctx, \
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech /* NOTE: Please, instead of adding new create_[user|group] bool,
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech * use bitshift. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březinaconst char *domains[] = {"responder_cache_req_test_a",
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina "responder_cache_req_test_b",
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina "responder_cache_req_test_c",
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina "responder_cache_req_test_d",
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekconst char *subdomain_name = "responder_cache_req_test_a_sub";
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březinastruct cli_protocol_version *register_cli_protocol_version(void)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina static struct cli_protocol_version version[] = {
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinastatic void cache_req_user_by_name_test_done(struct tevent_req *req)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ctx->tctx->error = cache_req_user_by_name_recv(ctx, req, &ctx->result);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinastatic void cache_req_user_by_id_test_done(struct tevent_req *req)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ctx->tctx->error = cache_req_user_by_id_recv(ctx, req, &ctx->result);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinastatic void cache_req_group_by_name_test_done(struct tevent_req *req)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ctx->tctx->error = cache_req_group_by_name_recv(ctx, req, &ctx->result);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinastatic void cache_req_group_by_id_test_done(struct tevent_req *req)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ctx->tctx->error = cache_req_group_by_id_recv(ctx, req, &ctx->result);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinastatic void cache_req_object_by_sid_test_done(struct tevent_req *req)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ctx->tctx->error = cache_req_object_by_sid_recv(ctx, req, &ctx->result);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekstatic void cache_req_object_by_id_test_done(struct tevent_req *req)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek ctx->tctx->error = cache_req_object_by_id_recv(ctx, req, &ctx->result);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březinastatic void prepare_user(struct sss_domain_info *domain,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, user->upn);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, user->sid);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(attrs, user->short_name, domain->name);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void run_user_by_name(struct cache_req_test_ctx *test_ctx,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek run_cache_req_domtype(test_ctx, cache_req_user_by_name_send,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozekstatic void run_user_by_upn(struct cache_req_test_ctx *test_ctx,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek run_cache_req_domtype(test_ctx, cache_req_user_by_name_send,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozekstatic void run_user_by_id(struct cache_req_test_ctx *test_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_cache_req(test_ctx, cache_req_user_by_id_send,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina cache_refresh_percent, users[0].uid, exp_ret);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozekstatic void assert_msg_has_shortname(struct cache_req_test_ctx *test_ctx,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ldbname = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sss_parse_internal_fqname(test_ctx, ldbname, &shortname, NULL);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void check_user(struct cache_req_test_ctx *test_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ldbupn = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina assert_string_equal(exp_dom->name, test_ctx->result->domain->name);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březinastatic void prepare_group(struct sss_domain_info *domain,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, group->sid);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(attrs, group->short_name, domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sysdb_store_group(domain, fqname, group->gid, attrs,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void run_group_by_name(struct cache_req_test_ctx *test_ctx,
cee85e8fb9534ec997e5388fce59f392cf029573Jakub Hrozek run_cache_req_domtype(test_ctx, cache_req_group_by_name_send,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void run_group_by_id(struct cache_req_test_ctx *test_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_cache_req(test_ctx, cache_req_group_by_id_send,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina cache_refresh_percent, groups[0].gid, exp_ret);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void check_group(struct cache_req_test_ctx *test_ctx,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina assert_string_equal(exp_dom->name, test_ctx->result->domain->name);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinastatic void run_object_by_sid(struct cache_req_test_ctx *test_ctx,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *sid,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char **attrs,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina req_mem_ctx = talloc_new(global_talloc_context);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina req = cache_req_object_by_sid_send(req_mem_ctx, test_ctx->tctx->ev,
beb07d2f45856d4f3135f173cce551a2aa878f57Petr Cech test_ctx->rctx, test_ctx->ncache, cache_refresh_percent,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina (domain == NULL ? NULL : domain->name), sid, attrs);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina tevent_req_set_callback(req, cache_req_object_by_sid_test_done, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekstatic void run_object_by_id(struct cache_req_test_ctx *test_ctx,
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek const char **attrs,
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek req = cache_req_object_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx->rctx, test_ctx->ncache, cache_refresh_percent,
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek (domain == NULL ? NULL : domain->name), id, attrs);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek tevent_req_set_callback(req, cache_req_object_by_id_test_done, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(ctx->tctx->dom, &users[0], 1000, time(NULL));
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(ctx->tctx->dom, &users[1], 1000, time(NULL));
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(ctx->tctx->dom, &groups[0], 1000, time(NULL));
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(ctx->tctx->dom, &groups[1], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina return test_req_succeed_send(mem_ctx, rctx->ev);
2af80640f18966d65cf82106059ce3c060df93bfamitkumastatic int test_single_domain_setup_common(void **state,
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
2af80640f18966d65cf82106059ce3c060df93bfamitkuma return test_single_domain_setup_common(state, NULL);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_single_domain_teardown(void **state)
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
2af80640f18966d65cf82106059ce3c060df93bfamitkumastatic int test_single_domain_id_limits_setup(void **state)
2af80640f18966d65cf82106059ce3c060df93bfamitkuma return test_single_domain_setup_common(state, params);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_multi_domain_setup(void **state)
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
2af80640f18966d65cf82106059ce3c060df93bfamitkuma test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
2af80640f18966d65cf82106059ce3c060df93bfamitkuma /* Test. */
2af80640f18966d65cf82106059ce3c060df93bfamitkuma cache_req_user_by_id_test_done, test_ctx->tctx->dom,
2af80640f18966d65cf82106059ce3c060df93bfamitkuma test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
2af80640f18966d65cf82106059ce3c060df93bfamitkuma /* Test. */
2af80640f18966d65cf82106059ce3c060df93bfamitkuma cache_req_user_by_id_test_done, test_ctx->tctx->dom,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_multi_domain_teardown(void **state)
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek const char *const testdom[4] = { subdomain_name, "TEST_A.SUB", "test_a", "S-3" };
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx->subdomain = new_subdomain(test_ctx, test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek testdom[0], testdom[1], testdom[2], testdom[3],
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek testdom[0], testdom[1], testdom[2], testdom[3],
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek ret = sysdb_update_subdomains(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekstatic int test_subdomain_teardown(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_multiple_domains_found(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina "responder_cache_req_test_d", true);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(users[0].short_name, NULL, ERR_OK);
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_multiple_domains_notfound(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(users[0].short_name, NULL, ERR_OK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březinavoid test_user_by_name_multiple_domains_parse(void **state)
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Add user to the first domain with different uid then test user. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina "responder_cache_req_test_a", true);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, users[0].short_name, domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sysdb_store_user(domain, fqname, "pwd", 2000, 1000,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Add test user to the last domain. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina "responder_cache_req_test_d", true);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek /* Append domain name to the username to form the qualified input.
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek * We don't use the internal fqname here on purpose, because this is
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek * the user's input.
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek input_fqn = talloc_asprintf(test_ctx, "%s@%s", users[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek "responder_cache_req_test_d");
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(users[0].short_name, "responder_cache_req_test_d", ERR_OK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req_mem_ctx = talloc_new(global_talloc_context);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina assert_non_null(test_ctx->result->lookup_name);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina assert_string_equal(input_fqn, test_ctx->result->lookup_name);
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_cache_valid(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_cache_expired(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina /* DP should be contacted */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_cache_midpoint(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina /* DP should be contacted without callback */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, users[0].short_name,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina ret = sss_ncache_set_user(test_ctx->ncache, false,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_missing_found(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_missing_notfound(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_multiple_domains_found(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina "responder_cache_req_test_d", true);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_multiple_domains_notfound(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_cache_valid(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_cache_expired(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina /* DP should be contacted */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_cache_midpoint(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina /* DP should be contacted without callback */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose /* Setup user's UPN. */
54039570d26e29444c398aa4ad6ba638f1713566Sumit Bose ret = sss_ncache_set_upn(test_ctx->ncache, false,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_missing_found(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinavoid test_user_by_upn_missing_notfound(void **state)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_multiple_domains_found(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina "responder_cache_req_test_d", true);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_multiple_domains_notfound(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_multiple_domains_locator_cache_valid(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the locator tells us to skip all domains except d, the domains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * are standalone and the result of the locator request is only valid within
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * the subdomains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_multiple_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_sub_domains_locator_cache_valid(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the ID is present in the last domain,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * we're not calling sss_dp_get_account_send,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will cause cache_req to skip
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * all domains except _d
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_sub_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_sub_domains_locator_cache_midpoint(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], 50, time(NULL) - 26);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once and we're not waiting
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * for the results (so, we're not mocking _recv)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_sub_domains_locator_missing_found(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
2af80640f18966d65cf82106059ce3c060df93bfamitkuma test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
2af80640f18966d65cf82106059ce3c060df93bfamitkuma /* Test. */
2af80640f18966d65cf82106059ce3c060df93bfamitkuma run_cache_req(test_ctx, cache_req_group_by_id_send,
2af80640f18966d65cf82106059ce3c060df93bfamitkuma cache_req_group_by_id_test_done, test_ctx->tctx->dom,
2af80640f18966d65cf82106059ce3c060df93bfamitkuma test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
2af80640f18966d65cf82106059ce3c060df93bfamitkuma /* Test. */
2af80640f18966d65cf82106059ce3c060df93bfamitkuma run_cache_req(test_ctx, cache_req_group_by_id_send,
2af80640f18966d65cf82106059ce3c060df93bfamitkuma cache_req_group_by_id_test_done, test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_sub_domains_locator_missing_notfound(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, ERR_NOT_FOUND);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_user_by_id_sub_domains_locator_cache_expired_two_calls(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Request the same user again */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_cache_expired(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* DP should be contacted. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_cache_midpoint(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina /* DP should be contacted without callback */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina ret = sss_ncache_set_uid(test_ctx->ncache, false, NULL, users[0].uid);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_missing_found(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_missing_notfound(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_multiple_domains_found(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina "responder_cache_req_test_d", true);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(groups[0].short_name, NULL, ERR_OK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_multiple_domains_notfound(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(groups[0].short_name, NULL, ERR_OK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březinavoid test_group_by_name_multiple_domains_parse(void **state)
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Add group to the first domain. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina "responder_cache_req_test_a", true);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, users[0].short_name, domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sysdb_store_group(domain, fqname, 2000, NULL,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Add group to the last domain, with different gid. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina "responder_cache_req_test_d", true);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek /* Append domain name to the groupname.
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek * We don't use the internal fqname here on purpose, because this is
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek * the user's input.
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek input_fqn = talloc_asprintf(test_ctx, "%s@%s", groups[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek "responder_cache_req_test_d");
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req_mem_ctx = talloc_new(global_talloc_context);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(groups[0].short_name, "responder_cache_req_test_d", ERR_OK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina assert_non_null(test_ctx->result->lookup_name);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina assert_string_equal(input_fqn, test_ctx->result->lookup_name);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_cache_valid(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_cache_expired(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina /* DP should be contacted */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_cache_midpoint(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina /* DP should be contacted without callback */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, groups[0].short_name,
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina ret = sss_ncache_set_group(test_ctx->ncache, false,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_missing_found(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_missing_notfound(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_multiple_domains_found(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina "responder_cache_req_test_d", true);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_multiple_domains_notfound(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_multiple_domains_locator_cache_valid(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the locator tells us to skip all domains except d, the domains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * are standalone and the result of the locator request is only valid within
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * the subdomains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_multiple_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_sub_domains_locator_cache_valid(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the ID is present in the last domain,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * we're not calling sss_dp_get_account_send,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will cause cache_req to skip
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * all domains except _d
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_sub_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_sub_domains_locator_cache_midpoint(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], 50, time(NULL) - 26);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once and we're not waiting
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * for the results (so, we're not mocking _recv)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_sub_domains_locator_missing_found(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_sub_domains_locator_missing_notfound(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, ERR_NOT_FOUND);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_sub_domains_locator_cache_expired_two_calls(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Request the same group again */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_group_by_id_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina /* DP should be contacted */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_cache_midpoint(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina /* DP should be contacted without callback */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina ret = sss_ncache_set_gid(test_ctx->ncache, false, NULL, groups[0].gid);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_missing_found(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_missing_notfound(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekstatic void cache_req_user_by_filter_test_done(struct tevent_req *req)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ctx->tctx->error = cache_req_user_by_filter_recv(ctx, req, &ctx->result);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cechvoid test_user_by_recent_filter_valid(void **state)
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[1], 1000, time(NULL) - 1);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech /* Filters always go to DP */
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech /* User TEST_USER is created with a DP callback. */
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cechvoid test_users_by_recent_filter_valid(void **state)
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech /* Filters always go to DP */
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech /* User TEST_USER1 and TEST_USER2 are created with a DP callback. */
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek user_names = talloc_zero_array(test_ctx, const char *, num_users);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek user_names[0] = sss_create_internal_fqname(user_names, users[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek user_names[1] = sss_create_internal_fqname(user_names, users[1].short_name,
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina for (int i = 0; i < num_users; ++i) {
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina ldb_results[i] = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i],
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech assert_string_not_equal(ldb_results[0], ldb_results[1]);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(are_values_in_array(user_names, num_users,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_users_by_filter_filter_old(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* This user was updated in distant past, so it won't be reported by
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek * the filter search */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[1], 1000, 1);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_users_by_filter_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchuser*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekstatic void test_users_by_filter_multiple_domains_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "responder_cache_req_test_d", true);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchuser*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekstatic void cache_req_group_by_filter_test_done(struct tevent_req *req)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
b206e1abb7f6ea373d12537b3338552aed6b656dPavel Březina ctx->tctx->error = cache_req_group_by_filter_recv(ctx, req, &ctx->result);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cechvoid test_group_by_recent_filter_valid(void **state)
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[1], 1001, time(NULL) - 1);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech /* Filters always go to DP */
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech /* Group TEST_GROUP is created with a DP callback. */
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cechvoid test_groups_by_recent_filter_valid(void **state)
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[1], 1001, time(NULL) - 1);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech /* Filters always go to DP */
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech /* Group TEST_GROUP1 and TEST_GROUP2 are created with a DP callback. */
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech group_names = talloc_array(tmp_ctx, const char *, 2);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek group_names[0] = sss_create_internal_fqname(group_names, groups[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek group_names[1] = sss_create_internal_fqname(group_names, groups[1].short_name,
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech ldb_results = talloc_array(tmp_ctx, const char *, 2);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech for (int i = 0; i < 2; ++i) {
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i],
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_string_not_equal(ldb_results[0], ldb_results[1]);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_true(tc_are_values_in_array(group_names, ldb_results));
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_groups_by_filter_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchgroup*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_groups_by_filter_multiple_domains_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "responder_cache_req_test_d", true);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchgroup*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_cache_valid(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_cache_expired(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* DP should be contacted */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_cache_midpoint(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* DP should be contacted without callback */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_ncache(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sss_ncache_set_sid(test_ctx->ncache, false, users[0].sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_missing_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_missing_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_multiple_domains_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina "responder_cache_req_test_d", true);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, users[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_multiple_domains_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, users[0].sid, attrs, 0, ENOENT);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_cache_valid(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_cache_expired(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* DP should be contacted */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_cache_midpoint(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* DP should be contacted without callback */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_ncache(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sss_ncache_set_sid(test_ctx->ncache, false, groups[0].sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_missing_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_missing_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_multiple_domains_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina "responder_cache_req_test_d", true);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, groups[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_multiple_domains_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, groups[0].sid, attrs, 0, ENOENT);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_cache_valid(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_user(test_ctx, &users[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_cache_expired(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* DP should be contacted */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_user(test_ctx, &users[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_cache_midpoint(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* DP should be contacted without callback */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 50, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_user(test_ctx, &users[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_ncache(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. We explicitly add the UID into BOTH UID and GID
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek * namespaces, because otherwise the cache_req plugin would
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * search the Data Provider anyway, because it can't be sure
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek * the object can be of the other type or not
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ENOENT);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_missing_found(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_user(test_ctx, &users[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_missing_notfound(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ENOENT);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_multiple_domains_found(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek "responder_cache_req_test_d", true);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_user(domain, &users[0], 1000, time(NULL));
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_user_multiple_domains_notfound(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ENOENT);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_cache_valid(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_cache_expired(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* DP should be contacted */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_cache_midpoint(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* DP should be contacted without callback */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 50, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_ncache(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup group. We explicitly add the UID into BOTH UID and GID
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek * namespaces, because otherwise the cache_req plugin would
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * search the Data Provider anyway, because it can't be sure
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek * the object can be of the other type or not
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ENOENT);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_missing_found(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_missing_notfound(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ENOENT);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_multiple_domains_found(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Setup user. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek "responder_cache_req_test_d", true);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek prepare_group(domain, &groups[0], 1000, time(NULL));
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozekvoid test_object_by_id_group_multiple_domains_notfound(void **state)
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek /* Mock values. */
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ENOENT);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_multiple_domains_locator_cache_valid(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the locator tells us to skip all domains except d, the domains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * are standalone and the result of the locator request is only valid within
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * the subdomains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_multiple_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_sub_domains_locator_cache_valid(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the ID is present in the last domain,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * we're not calling sss_dp_get_account_send,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will cause cache_req to skip
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * all domains except _d
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_sub_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_sub_domains_locator_cache_midpoint(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], 50, time(NULL) - 26);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once and we're not waiting
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * for the results (so, we're not mocking _recv)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 50, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_sub_domains_locator_missing_found(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_sub_domains_locator_missing_notfound(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, ERR_NOT_FOUND);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* The test won't even ask the DP for the object, just iterate
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * over the domains using the negative cache and quit
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ENOENT);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_user_sub_domains_locator_cache_expired_two_calls(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup user. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_user(domain, &users[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Request the same user again */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_multiple_domains_locator_cache_valid(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the locator tells us to skip all domains except d, the domains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * are standalone and the result of the locator request is only valid within
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * the subdomains
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_multiple_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, "responder_cache_req_test_d");
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek "responder_cache_req_test_d", true);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return_always(sss_dp_get_account_domain_recv, ERR_GET_ACCT_DOM_NOT_SUPPORTED);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_sub_domains_locator_cache_valid(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], 1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Even though the ID is present in the last domain,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * we're not calling sss_dp_get_account_send,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will cause cache_req to skip
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * all domains except _d
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_sub_domains_locator_cache_expired(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_sub_domains_locator_cache_midpoint(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], 50, time(NULL) - 26);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once and we're not waiting
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * for the results (so, we're not mocking _recv)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 50, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_sub_domains_locator_missing_found(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_sub_domains_locator_missing_notfound(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, ERR_NOT_FOUND);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* The test won't even ask the DP for the object, just iterate
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * over the domains using the negative cache and quit
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ENOENT);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozekvoid test_object_by_id_group_sub_domains_locator_cache_expired_two_calls(void **state)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek locator_domain = talloc_strdup(tmp_ctx, subdomain_name);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Setup group. */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek prepare_group(domain, &groups[0], -1000, time(NULL));
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Note - DP will only be called once (so, we're not using will_return_always)
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * because the locator will tell us which domain to look into. For the recv
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek * function, we use always b/c internally it mocks several values.
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek will_return(sss_dp_get_account_domain_recv, locator_domain);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek /* Request the same group again */
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, EOK);
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_name_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_name_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_name_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_name_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_name_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_name_multiple_domains_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_name_multiple_domains_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_name_multiple_domains_parse),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_upn_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_upn_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_upn_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_upn_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_upn_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_upn_multiple_domains_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_upn_multiple_domains_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_id_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_id_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_id_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_id_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_id_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_id_multiple_domains_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_id_multiple_domains_notfound),
2af80640f18966d65cf82106059ce3c060df93bfamitkuma new_single_domain_id_limit_test(user_by_id_below_id_range),
2af80640f18966d65cf82106059ce3c060df93bfamitkuma new_single_domain_id_limit_test(user_by_id_above_id_range),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_name_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_name_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_name_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_name_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_name_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(group_by_name_multiple_domains_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(group_by_name_multiple_domains_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(group_by_name_multiple_domains_parse),
2af80640f18966d65cf82106059ce3c060df93bfamitkuma new_single_domain_id_limit_test(group_by_id_below_id_range),
2af80640f18966d65cf82106059ce3c060df93bfamitkuma new_single_domain_id_limit_test(group_by_id_above_id_range),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_id_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_id_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_id_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_id_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_id_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(group_by_id_multiple_domains_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(group_by_id_multiple_domains_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(group_by_id_multiple_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(group_by_id_multiple_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(group_by_id_sub_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(group_by_id_sub_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(group_by_id_sub_domains_locator_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(group_by_id_sub_domains_locator_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(group_by_id_sub_domains_locator_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(group_by_id_sub_domains_locator_cache_expired_two_calls),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_id_multiple_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(user_by_id_multiple_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(user_by_id_sub_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(user_by_id_sub_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(user_by_id_sub_domains_locator_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(user_by_id_sub_domains_locator_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(user_by_id_sub_domains_locator_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(user_by_id_sub_domains_locator_cache_expired_two_calls),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(user_by_recent_filter_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(users_by_recent_filter_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(group_by_recent_filter_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(groups_by_recent_filter_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_single_domain_test(users_by_filter_filter_old),
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek new_single_domain_test(users_by_filter_notfound),
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek new_multi_domain_test(users_by_filter_multiple_domains_notfound),
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek new_single_domain_test(groups_by_filter_notfound),
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek new_multi_domain_test(groups_by_filter_multiple_domains_notfound),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_user_cache_valid),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_user_cache_expired),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_user_cache_midpoint),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_user_ncache),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_user_missing_found),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_user_missing_notfound),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_multi_domain_test(object_by_sid_user_multiple_domains_found),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_multi_domain_test(object_by_sid_user_multiple_domains_notfound),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_group_cache_valid),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_group_cache_expired),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_group_cache_midpoint),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_group_ncache),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_group_missing_found),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_single_domain_test(object_by_sid_group_missing_notfound),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_multi_domain_test(object_by_sid_group_multiple_domains_found),
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina new_multi_domain_test(object_by_sid_group_multiple_domains_notfound),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_user_cache_valid),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_user_cache_expired),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_user_cache_midpoint),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_user_ncache),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_user_missing_found),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_user_missing_notfound),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_multi_domain_test(object_by_id_user_multiple_domains_found),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_multi_domain_test(object_by_id_user_multiple_domains_notfound),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_group_cache_valid),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_group_cache_expired),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_group_cache_midpoint),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_group_ncache),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_group_missing_found),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_single_domain_test(object_by_id_group_missing_notfound),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_multi_domain_test(object_by_id_group_multiple_domains_found),
6cd367da68ff56eb48b8b4167dbdd5e53992d194Jakub Hrozek new_multi_domain_test(object_by_id_group_multiple_domains_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(object_by_id_user_multiple_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(object_by_id_user_multiple_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_user_sub_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_user_sub_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_user_sub_domains_locator_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_user_sub_domains_locator_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_user_sub_domains_locator_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_user_sub_domains_locator_cache_expired_two_calls),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(object_by_id_group_multiple_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_multi_domain_test(object_by_id_group_multiple_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_group_sub_domains_locator_cache_valid),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_group_sub_domains_locator_cache_expired),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_group_sub_domains_locator_cache_midpoint),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_group_sub_domains_locator_missing_found),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_group_sub_domains_locator_missing_notfound),
f2a5e29f063f9d623c1336d76f4b2bc500c1a5e2Jakub Hrozek new_subdomain_test(object_by_id_group_sub_domains_locator_cache_expired_two_calls),
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina pc = poptGetContext(argv[0], argc, argv, long_options, 0);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina fprintf(stderr, "\nInvalid option %s: %s\n\n",
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);