360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina/*
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina Authors:
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina Pavel Březina <pbrezina@redhat.com>
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina Copyright (C) 2014 Red Hat
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
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
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
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/>.
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina*/
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#include <talloc.h>
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#include <tevent.h>
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#include <errno.h>
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#include <popt.h>
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#include "tests/cmocka/common_mock.h"
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#include "tests/cmocka/common_mock_resp.h"
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#include "db/sysdb.h"
4169fb26ea2ff93c19ecdad6e09382732ea5deebPavel Březina#include "responder/common/cache_req/cache_req.h"
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
50c9d542e8bf641412debaa82a4dcf67ddb72258Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#define TEST_CONF_DB "test_responder_cache_req_conf.ldb"
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#define TEST_DOM_NAME "responder_cache_req_test"
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#define TEST_ID_PROVIDER "ldap"
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina#define TEST_USER_PREFIX "test*"
bbc34d5a6e84d6c337bd89a22d33e365eb466226Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březinastruct test_user {
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek const char *short_name;
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina const char *upn;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *sid;
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina uid_t uid;
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina gid_t gid;
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 {"test-user2", "upn2@upndomain.com",
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina "S-1-5-21-3623811015-3361044348-30300820-1002", 1002, 1002}};
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březinastruct test_group {
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek const char *short_name;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *sid;
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina gid_t gid;
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}};
b0e8c1802557645e2ff6a88c54c520b0f0ff9ebbPetr Cech
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#define new_single_domain_test(test) \
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_ ## test, \
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_single_domain_setup, \
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_single_domain_teardown)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina#define new_multi_domain_test(test) \
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_ ## test, \
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_multi_domain_setup, \
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek test_multi_domain_teardown)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina#define run_cache_req(ctx, send_fn, done_fn, dom, crp, lookup, expret) do { \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina TALLOC_CTX *req_mem_ctx; \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct tevent_req *req; \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina errno_t ret; \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina req_mem_ctx = talloc_new(global_talloc_context); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina check_leaks_push(req_mem_ctx); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina req = send_fn(req_mem_ctx, ctx->tctx->ev, ctx->rctx, \
beb07d2f45856d4f3135f173cce551a2aa878f57Petr Cech ctx->ncache, crp, \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina (dom == NULL ? NULL : dom->name), lookup); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(req); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina tevent_req_set_callback(req, done_fn, ctx); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ret = test_ev_loop(ctx->tctx); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_int_equal(ret, expret); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_true(check_leaks_pop(req_mem_ctx)); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina talloc_free(req_mem_ctx); \
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina} while (0)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březinastruct cache_req_test_ctx {
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct sss_test_ctx *tctx;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct resp_ctx *rctx;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct sss_nc_ctx *ncache;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct ldb_result *result;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct sss_domain_info *domain;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina char *name;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina bool dp_called;
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech /* NOTE: Please, instead of adding new create_[user|group] bool,
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech * use bitshift. */
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech bool create_user1;
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech bool create_user2;
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech bool create_group1;
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech bool create_group2;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina};
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
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",
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina NULL};
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březinastruct cli_protocol_version *register_cli_protocol_version(void)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina static struct cli_protocol_version version[] = {
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina { 0, NULL, NULL }
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina };
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina return version;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinastatic void cache_req_user_by_name_test_done(struct tevent_req *req)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina ctx->tctx->error = cache_req_user_by_name_recv(ctx, req,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina &ctx->result,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina &ctx->domain,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina &ctx->name);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina talloc_zfree(req);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina ctx->tctx->done = true;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinastatic void cache_req_user_by_id_test_done(struct tevent_req *req)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina ctx->tctx->error = cache_req_user_by_id_recv(ctx, req,
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina &ctx->result, &ctx->domain);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina talloc_zfree(req);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina ctx->tctx->done = true;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinastatic void cache_req_group_by_name_test_done(struct tevent_req *req)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina ctx->tctx->error = cache_req_group_by_name_recv(ctx, req,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina &ctx->result,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina &ctx->domain,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina &ctx->name);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina talloc_zfree(req);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina ctx->tctx->done = true;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinastatic void cache_req_group_by_id_test_done(struct tevent_req *req)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina ctx->tctx->error = cache_req_group_by_id_recv(ctx, req,
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina &ctx->result, &ctx->domain);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina talloc_zfree(req);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina ctx->tctx->done = true;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinastatic void cache_req_object_by_sid_test_done(struct tevent_req *req)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ctx->tctx->error = cache_req_object_by_sid_recv(ctx, req,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina &ctx->result,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina &ctx->domain);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina talloc_zfree(req);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ctx->tctx->done = true;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březinastatic void prepare_user(struct sss_domain_info *domain,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina struct test_user *user,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina uint64_t timeout,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina time_t transaction_time)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct sysdb_attrs *attrs;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina errno_t ret;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *fqname;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina attrs = sysdb_new_attrs(NULL);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(attrs);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, user->upn);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_int_equal(ret, EOK);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, user->sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_int_equal(ret, EOK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(attrs, user->short_name, domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sysdb_store_user(domain, fqname, "pwd",
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina user->uid, user->gid, NULL, NULL, NULL,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina "cn=origdn,dc=test", attrs, NULL,
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik timeout, transaction_time);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(fqname);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_int_equal(ret, EOK);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina talloc_free(attrs);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void run_user_by_name(struct cache_req_test_ctx *test_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct sss_domain_info *domain,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina int cache_refresh_percent,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina errno_t exp_ret)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_cache_req(test_ctx, cache_req_user_by_name_send,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina cache_req_user_by_name_test_done, domain,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek cache_refresh_percent, users[0].short_name, exp_ret);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozekstatic void run_user_by_upn(struct cache_req_test_ctx *test_ctx,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozek struct sss_domain_info *domain,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozek int cache_refresh_percent,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozek errno_t exp_ret)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_cache_req(test_ctx, cache_req_user_by_name_send,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina cache_req_user_by_name_test_done, domain,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina cache_refresh_percent, users[0].upn, exp_ret);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozekstatic void run_user_by_id(struct cache_req_test_ctx *test_ctx,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozek struct sss_domain_info *domain,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozek int cache_refresh_percent,
6c2e507bd1571f9c7e26c5c9d60753b29fb75578Jakub Hrozek errno_t exp_ret)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_cache_req(test_ctx, cache_req_user_by_id_send,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina cache_req_user_by_id_test_done, domain,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina cache_refresh_percent, users[0].uid, exp_ret);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozekstatic void assert_msg_has_shortname(struct cache_req_test_ctx *test_ctx,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek struct ldb_message *msg,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek const char *check_name)
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek{
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek const char *ldbname;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *shortname;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek errno_t ret;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ldbname = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(ldbname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sss_parse_internal_fqname(test_ctx, ldbname, &shortname, NULL);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_int_equal(ret, EOK);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_string_equal(shortname, check_name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(shortname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek}
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void check_user(struct cache_req_test_ctx *test_ctx,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina struct test_user *user,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct sss_domain_info *exp_dom)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina const char *ldbupn;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *ldbsid;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina uid_t ldbuid;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->result);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_int_equal(test_ctx->result->count, 1);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->result->msgs);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->result->msgs[0]);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_msg_has_shortname(test_ctx,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->result->msgs[0],
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek user->short_name);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ldbupn = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina SYSDB_UPN, NULL);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(ldbupn);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina assert_string_equal(ldbupn, user->upn);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina SYSDB_SID_STR, NULL);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_non_null(ldbsid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_string_equal(ldbsid, user->sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ldbuid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina SYSDB_UIDNUM, 0);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina assert_int_equal(ldbuid, user->uid);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->domain);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_string_equal(exp_dom->name, test_ctx->domain->name);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březinastatic void prepare_group(struct sss_domain_info *domain,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina struct test_group *group,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina uint64_t timeout,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina time_t transaction_time)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct sysdb_attrs *attrs;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *fqname;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina errno_t ret;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina attrs = sysdb_new_attrs(NULL);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_non_null(attrs);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sysdb_attrs_add_string(attrs, SYSDB_SID_STR, group->sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_int_equal(ret, EOK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(attrs, group->short_name, domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sysdb_store_group(domain, fqname, group->gid, attrs,
df9e9a1f9b7dc255eb62c390163c25917b08f5a2Lukas Slebodnik timeout, transaction_time);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(fqname);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_int_equal(ret, EOK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina talloc_free(attrs);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void run_group_by_name(struct cache_req_test_ctx *test_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct sss_domain_info *domain,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina int cache_refresh_percent,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina errno_t exp_ret)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_cache_req(test_ctx, cache_req_group_by_name_send,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina cache_req_group_by_name_test_done, domain,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek cache_refresh_percent, groups[0].short_name, exp_ret);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void run_group_by_id(struct cache_req_test_ctx *test_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct sss_domain_info *domain,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina int cache_refresh_percent,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina errno_t exp_ret)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_cache_req(test_ctx, cache_req_group_by_id_send,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina cache_req_group_by_id_test_done, domain,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina cache_refresh_percent, groups[0].gid, exp_ret);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastatic void check_group(struct cache_req_test_ctx *test_ctx,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina struct test_group *group,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct sss_domain_info *exp_dom)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *ldbsid;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina gid_t ldbgid;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->result);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_int_equal(test_ctx->result->count, 1);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->result->msgs);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->result->msgs[0]);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_msg_has_shortname(test_ctx,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->result->msgs[0],
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek group->short_name);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ldbsid = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina SYSDB_SID_STR, NULL);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_non_null(ldbsid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_string_equal(ldbsid, group->sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ldbgid = ldb_msg_find_attr_as_uint(test_ctx->result->msgs[0],
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina SYSDB_GIDNUM, 0);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina assert_int_equal(ldbgid, group->gid);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_non_null(test_ctx->domain);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_string_equal(exp_dom->name, test_ctx->domain->name);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinastatic void run_object_by_sid(struct cache_req_test_ctx *test_ctx,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct sss_domain_info *domain,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *sid,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char **attrs,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina int cache_refresh_percent,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina errno_t exp_ret)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina TALLOC_CTX *req_mem_ctx;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct tevent_req *req;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina errno_t ret;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina req_mem_ctx = talloc_new(global_talloc_context);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_leaks_push(req_mem_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
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 assert_non_null(req);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina tevent_req_set_callback(req, cache_req_object_by_sid_test_done, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = test_ev_loop(test_ctx->tctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_int_equal(ret, exp_ret);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(check_leaks_pop(req_mem_ctx));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina talloc_free(req_mem_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinastruct tevent_req *
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct resp_ctx *rctx,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct sss_domain_info *dom,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina bool fast_reply,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina enum sss_dp_acct_type type,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina const char *opt_name,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina uint32_t opt_id,
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina const char *extra)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct cache_req_test_ctx *ctx = NULL;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina ctx->dp_called = true;
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech if (ctx->create_user1) {
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(ctx->tctx->dom, &users[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina }
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech if (ctx->create_user2) {
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(ctx->tctx->dom, &users[1], 1000, time(NULL));
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech }
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech if (ctx->create_group1) {
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(ctx->tctx->dom, &groups[0], 1000, time(NULL));
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina }
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech if (ctx->create_group2) {
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(ctx->tctx->dom, &groups[1], 1000, time(NULL));
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech }
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina return test_req_succeed_send(mem_ctx, rctx->ev);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_single_domain_setup(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina errno_t ret;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(leak_check_setup());
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_dom_suite_setup(TESTS_PATH);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_non_null(test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina *state = test_ctx;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina TEST_DOM_NAME, TEST_ID_PROVIDER, NULL);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_non_null(test_ctx->tctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->tctx->dom, NULL);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_non_null(test_ctx->rctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_int_equal(ret, EOK);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina check_leaks_push(test_ctx);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_single_domain_teardown(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina struct cache_req_test_ctx *test_ctx;
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina talloc_zfree(test_ctx->result);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina talloc_zfree(test_ctx->name);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(check_leaks_pop(test_ctx));
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina talloc_zfree(test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_multi_domain_setup(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina errno_t ret;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(leak_check_setup());
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_dom_suite_setup(TESTS_PATH);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_zero(global_talloc_context, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_non_null(test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina *state = test_ctx;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina TEST_CONF_DB, domains,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina TEST_ID_PROVIDER, NULL);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_non_null(test_ctx->tctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->rctx = mock_rctx(test_ctx, test_ctx->tctx->ev,
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx->tctx->dom, NULL);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_non_null(test_ctx->rctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(test_ctx, 10, 0, &test_ctx->ncache);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_int_equal(ret, EOK);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
a257259b05d62ebe548b6c798a3aa03a97dbc0c2Jakub Hrozek reset_ldb_errstrings(test_ctx->tctx->dom);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina check_leaks_push(test_ctx);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int test_multi_domain_teardown(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina struct cache_req_test_ctx *test_ctx;
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina talloc_zfree(test_ctx->result);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina talloc_zfree(test_ctx->name);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
a257259b05d62ebe548b6c798a3aa03a97dbc0c2Jakub Hrozek reset_ldb_errstrings(test_ctx->tctx->dom);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(check_leaks_pop(test_ctx));
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina talloc_zfree(test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_multiple_domains_found(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct sss_domain_info *domain = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
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);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_non_null(domain);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return_always(sss_dp_get_account_recv, 0);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(users[0].short_name, NULL, ERR_OK);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, NULL, 0, ERR_OK);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], domain);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_multiple_domains_notfound(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return_always(sss_dp_get_account_recv, 0);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(users[0].short_name, NULL, ERR_OK);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, NULL, 0, ENOENT);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_true(test_ctx->dp_called);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březinavoid test_user_by_name_multiple_domains_parse(void **state)
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina{
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina struct sss_domain_info *domain = NULL;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina TALLOC_CTX *req_mem_ctx = NULL;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina struct tevent_req *req = NULL;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *input_fqn;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *fqname;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina errno_t ret;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
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);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(domain);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, users[0].short_name, domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sysdb_store_user(domain, fqname, "pwd", 2000, 1000,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina NULL, NULL, NULL, "cn=test-user,dc=test", NULL,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina NULL, 1000, time(NULL));
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_zfree(fqname);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_int_equal(ret, EOK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Add test user to the last domain. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina "responder_cache_req_test_d", true);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(domain);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
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 */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek input_fqn = talloc_asprintf(test_ctx, "%s@%s", users[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek "responder_cache_req_test_d");
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(input_fqn);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(users[0].short_name, "responder_cache_req_test_d", ERR_OK);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina /* Test. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req_mem_ctx = talloc_new(global_talloc_context);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina check_leaks_push(req_mem_ctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req = cache_req_user_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
beb07d2f45856d4f3135f173cce551a2aa878f57Petr Cech test_ctx->rctx, test_ctx->ncache, 0,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek NULL, input_fqn);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(req);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina tevent_req_set_callback(req, cache_req_user_by_name_test_done, test_ctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina ret = test_ev_loop(test_ctx->tctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_int_equal(ret, ERR_OK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_true(check_leaks_pop(req_mem_ctx));
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_false(test_ctx->dp_called);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], domain);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(test_ctx->name);
d20a56f2f05a011e62ba921e70124583e3c5b652Jakub Hrozek assert_string_equal(input_fqn, test_ctx->name);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(input_fqn);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina}
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_cache_valid(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
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);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_cache_expired(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
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);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina mock_account_recv_simple();
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_cache_midpoint(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
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);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_ncache(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina errno_t ret;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *fqname;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, users[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->tctx->dom->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina ret = sss_ncache_set_user(test_ctx->ncache, false,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->tctx->dom, fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(fqname);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_int_equal(ret, EOK);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_false(test_ctx->dp_called);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_missing_found(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina mock_account_recv_simple();
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user1 = true;
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user2 = false;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březinavoid test_user_by_name_missing_notfound(void **state)
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina mock_account_recv_simple();
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina assert_true(test_ctx->dp_called);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_multiple_domains_found(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina{
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct sss_domain_info *domain = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
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);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_non_null(domain);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return_always(sss_dp_get_account_recv, 0);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], domain);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_multiple_domains_notfound(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina{
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return_always(sss_dp_get_account_recv, 0);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 0, ENOENT);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_true(test_ctx->dp_called);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_cache_valid(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina{
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_cache_expired(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina{
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
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_account_recv_simple();
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_cache_midpoint(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina{
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
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);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 50, ERR_OK);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_ncache(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina{
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina errno_t ret;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina ret = sss_ncache_set_user(test_ctx->ncache, false,
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina test_ctx->tctx->dom, users[0].upn);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_int_equal(ret, EOK);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 0, ENOENT);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_false(test_ctx->dp_called);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid test_user_by_upn_missing_found(void **state)
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina{
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_account_recv_simple();
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user1 = true;
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user2 = false;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březinavoid test_user_by_upn_missing_notfound(void **state)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_account_recv_simple();
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_upn(test_ctx, NULL, 0, ENOENT);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina assert_true(test_ctx->dp_called);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina}
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_multiple_domains_found(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct sss_domain_info *domain = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
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);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_non_null(domain);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return_always(sss_dp_get_account_recv, 0);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, NULL, 0, ERR_OK);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], domain);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_multiple_domains_notfound(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return_always(sss_dp_get_account_recv, 0);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, NULL, 0, ENOENT);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_true(test_ctx->dp_called);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_cache_valid(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
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řezina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_cache_expired(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
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);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina mock_account_recv_simple();
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_cache_midpoint(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
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);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_ncache(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina errno_t ret;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup user. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina ret = sss_ncache_set_uid(test_ctx->ncache, false, NULL, users[0].uid);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_int_equal(ret, EOK);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_false(test_ctx->dp_called);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_missing_found(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina mock_account_recv_simple();
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user1 = true;
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user2 = false;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březinavoid test_user_by_id_missing_notfound(void **state)
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina{
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina mock_account_recv_simple();
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina assert_true(test_ctx->dp_called);
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina}
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_multiple_domains_found(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct sss_domain_info *domain = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
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);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_non_null(domain);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return_always(sss_dp_get_account_recv, 0);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(groups[0].short_name, NULL, ERR_OK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, NULL, 0, ERR_OK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], domain);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_multiple_domains_notfound(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return_always(sss_dp_get_account_recv, 0);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(groups[0].short_name, NULL, ERR_OK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, NULL, 0, ENOENT);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_true(test_ctx->dp_called);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březinavoid test_group_by_name_multiple_domains_parse(void **state)
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina{
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina struct sss_domain_info *domain = NULL;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina TALLOC_CTX *req_mem_ctx = NULL;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina struct tevent_req *req = NULL;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *input_fqn;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *fqname;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina errno_t ret;
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
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);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(domain);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, users[0].short_name, domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek ret = sysdb_store_group(domain, fqname, 2000, NULL,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina 1000, time(NULL));
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_zfree(fqname);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_int_equal(ret, EOK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Add group to the last domain, with different gid. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina domain = find_domain_by_name(test_ctx->tctx->dom,
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina "responder_cache_req_test_d", true);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(domain);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
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 */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek input_fqn = talloc_asprintf(test_ctx, "%s@%s", groups[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek "responder_cache_req_test_d");
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(input_fqn);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina /* Test. */
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req_mem_ctx = talloc_new(global_talloc_context);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina check_leaks_push(req_mem_ctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek mock_parse_inp(groups[0].short_name, "responder_cache_req_test_d", ERR_OK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina req = cache_req_group_by_name_send(req_mem_ctx, test_ctx->tctx->ev,
beb07d2f45856d4f3135f173cce551a2aa878f57Petr Cech test_ctx->rctx, test_ctx->ncache, 0,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek NULL, input_fqn);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(req);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina tevent_req_set_callback(req, cache_req_group_by_name_test_done, test_ctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina ret = test_ev_loop(test_ctx->tctx);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_int_equal(ret, ERR_OK);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_true(check_leaks_pop(req_mem_ctx));
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_false(test_ctx->dp_called);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], domain);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina assert_non_null(test_ctx->name);
d20a56f2f05a011e62ba921e70124583e3c5b652Jakub Hrozek assert_string_equal(input_fqn, test_ctx->name);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(input_fqn);
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina}
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_cache_valid(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
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řezina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_cache_expired(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
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);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina mock_account_recv_simple();
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_cache_midpoint(void **state)
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina{
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
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);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_ncache(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina errno_t ret;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek char *fqname;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek fqname = sss_create_internal_fqname(test_ctx, groups[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->tctx->dom->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina ret = sss_ncache_set_group(test_ctx->ncache, false,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->tctx->dom, fqname);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(fqname);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_int_equal(ret, EOK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_false(test_ctx->dp_called);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_missing_found(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina mock_account_recv_simple();
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech test_ctx->create_group1 = true;
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech test_ctx->create_group2 = false;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březinavoid test_group_by_name_missing_notfound(void **state)
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina{
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina struct cache_req_test_ctx *test_ctx = NULL;
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina mock_account_recv_simple();
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina assert_true(test_ctx->dp_called);
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina}
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_multiple_domains_found(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct sss_domain_info *domain = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
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);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_non_null(domain);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return_always(sss_dp_get_account_recv, 0);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, NULL, 0, ERR_OK);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], domain);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_multiple_domains_notfound(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return_always(sss_dp_get_account_recv, 0);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, NULL, 0, ENOENT);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_true(test_ctx->dp_called);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_cache_valid(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
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řezina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_cache_expired(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
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);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina mock_account_recv_simple();
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_cache_midpoint(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
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);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 50, ERR_OK);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_ncache(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina errno_t ret;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Setup group. */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina ret = sss_ncache_set_gid(test_ctx->ncache, false, NULL, groups[0].gid);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_int_equal(ret, EOK);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_false(test_ctx->dp_called);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_missing_found(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina mock_account_recv_simple();
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech test_ctx->create_group1 = true;
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech test_ctx->create_group2 = false;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_true(test_ctx->dp_called);
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březinavoid test_group_by_id_missing_notfound(void **state)
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina{
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina struct cache_req_test_ctx *test_ctx = NULL;
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Mock values. */
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina mock_account_recv_simple();
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina /* Test. */
3688374991afb34bbaf2b7843683fc13dd77879dPavel Březina run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ENOENT);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina assert_true(test_ctx->dp_called);
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina}
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekstatic void cache_req_user_by_filter_test_done(struct tevent_req *req)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek{
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct cache_req_test_ctx *ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx->tctx->error = cache_req_user_by_filter_recv(ctx, req,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek &ctx->result,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek &ctx->domain);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek talloc_zfree(req);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx->tctx->done = true;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek}
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cechvoid test_user_by_recent_filter_valid(void **state)
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech{
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech struct cache_req_test_ctx *test_ctx = NULL;
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech TALLOC_CTX *req_mem_ctx = NULL;
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech struct tevent_req *req = NULL;
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech errno_t ret;
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user1 = true;
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user2 = false;
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[1], 1000, time(NULL) - 1);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech req_mem_ctx = talloc_new(test_ctx->tctx);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech check_leaks_push(req_mem_ctx);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech /* Filters always go to DP */
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech mock_account_recv_simple();
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
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 test_ctx->rctx,
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech test_ctx->tctx->dom->name,
b0e8c1802557645e2ff6a88c54c520b0f0ff9ebbPetr Cech TEST_USER_PREFIX);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech assert_non_null(req);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech ret = test_ev_loop(test_ctx->tctx);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech assert_int_equal(ret, ERR_OK);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech assert_true(check_leaks_pop(req_mem_ctx));
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech assert_non_null(test_ctx->result);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech assert_int_equal(test_ctx->result->count, 1);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_msg_has_shortname(test_ctx,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->result->msgs[0],
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek users[0].short_name);
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech}
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cechvoid test_users_by_recent_filter_valid(void **state)
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech{
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech struct cache_req_test_ctx *test_ctx = NULL;
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech TALLOC_CTX *req_mem_ctx = NULL;
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech struct tevent_req *req = NULL;
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina size_t num_users = 2;
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek const char **user_names;
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina const char *ldb_results[num_users];
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech errno_t ret;
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech test_ctx->create_user1 = true;
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech test_ctx->create_user2 = true;
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech req_mem_ctx = talloc_new(test_ctx->tctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech check_leaks_push(req_mem_ctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech /* Filters always go to DP */
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech mock_account_recv_simple();
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
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 test_ctx->rctx,
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech test_ctx->tctx->dom->name,
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech TEST_USER_PREFIX);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech assert_non_null(req);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech ret = test_ev_loop(test_ctx->tctx);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech assert_int_equal(ret, ERR_OK);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech assert_true(check_leaks_pop(req_mem_ctx));
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech assert_non_null(test_ctx->result);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech assert_int_equal(test_ctx->result->count, 2);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek user_names = talloc_zero_array(test_ctx, const char *, num_users);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(user_names);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek user_names[0] = sss_create_internal_fqname(user_names, users[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(user_names[0]);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek user_names[1] = sss_create_internal_fqname(user_names, users[1].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(user_names[1]);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
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],
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina SYSDB_NAME, NULL);
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_non_null(ldb_results[i]);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech }
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech assert_string_not_equal(ldb_results[0], ldb_results[1]);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina assert_true(are_values_in_array(user_names, num_users,
c19374b2a9b676ca534f52ef76d80f0945fe8fb2Pavel Březina ldb_results, num_users));
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(req_mem_ctx);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek talloc_free(user_names);
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech}
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_users_by_filter_filter_old(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek{
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct cache_req_test_ctx *test_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek TALLOC_CTX *req_mem_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct tevent_req *req = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek errno_t ret;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user1 = true;
c4d4fe1603420fe8f3d256a3a446974699563ff3Petr Cech test_ctx->create_user2 = false;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* This user was updated in distant past, so it wont't be reported by
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek * the filter search */
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_user(test_ctx->tctx->dom, &users[1], 1000, 1);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek check_leaks_push(req_mem_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek mock_account_recv_simple();
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->rctx,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->tctx->dom->name,
b0e8c1802557645e2ff6a88c54c520b0f0ff9ebbPetr Cech TEST_USER_PREFIX);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_non_null(req);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_int_equal(ret, ERR_OK);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_true(check_leaks_pop(req_mem_ctx));
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_non_null(test_ctx->result);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_int_equal(test_ctx->result->count, 1);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_msg_has_shortname(test_ctx,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->result->msgs[0],
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek users[0].short_name);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek}
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_users_by_filter_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek{
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct cache_req_test_ctx *test_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek TALLOC_CTX *req_mem_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct tevent_req *req = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek errno_t ret;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek check_leaks_push(req_mem_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek mock_account_recv_simple();
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->rctx,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->tctx->dom->name,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchuser*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_non_null(req);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_int_equal(ret, ENOENT);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_true(check_leaks_pop(req_mem_ctx));
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek}
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekstatic void test_users_by_filter_multiple_domains_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek{
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct cache_req_test_ctx *test_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct sss_domain_info *domain = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek TALLOC_CTX *req_mem_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct tevent_req *req = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek errno_t ret;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek domain = find_domain_by_name(test_ctx->tctx->dom,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "responder_cache_req_test_d", true);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_non_null(domain);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek check_leaks_push(req_mem_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek mock_account_recv_simple();
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->rctx,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek domain->name,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchuser*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_non_null(req);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_int_equal(ret, ENOENT);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_true(check_leaks_pop(req_mem_ctx));
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek}
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekstatic void cache_req_group_by_filter_test_done(struct tevent_req *req)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek{
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct cache_req_test_ctx *ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx->tctx->error = cache_req_group_by_filter_recv(ctx, req,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek &ctx->result,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek &ctx->domain);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek talloc_zfree(req);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ctx->tctx->done = true;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek}
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cechvoid test_group_by_recent_filter_valid(void **state)
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech{
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech struct cache_req_test_ctx *test_ctx = NULL;
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech TALLOC_CTX *req_mem_ctx = NULL;
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech struct tevent_req *req = NULL;
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech errno_t ret;
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech test_ctx->create_group1 = true;
5928fcbb57b92bfd18ad15aaaf4a5e1ab8dabe61Petr Cech test_ctx->create_group2 = false;
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[1], 1001, time(NULL) - 1);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech req_mem_ctx = talloc_new(global_talloc_context);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech check_leaks_push(req_mem_ctx);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech /* Filters always go to DP */
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech mock_account_recv_simple();
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
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 test_ctx->rctx,
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech test_ctx->tctx->dom->name,
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech TEST_USER_PREFIX);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech assert_non_null(req);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech ret = test_ev_loop(test_ctx->tctx);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech assert_int_equal(ret, ERR_OK);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech assert_true(check_leaks_pop(req_mem_ctx));
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech assert_non_null(test_ctx->result);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech assert_int_equal(test_ctx->result->count, 1);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_msg_has_shortname(test_ctx,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->result->msgs[0],
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek groups[0].short_name);
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech}
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cechvoid test_groups_by_recent_filter_valid(void **state)
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech{
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech struct cache_req_test_ctx *test_ctx = NULL;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech TALLOC_CTX *req_mem_ctx = NULL;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech TALLOC_CTX *tmp_ctx = NULL;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech struct tevent_req *req = NULL;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech const char **group_names = NULL;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech const char **ldb_results = NULL;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech const char *ldbname = NULL;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech errno_t ret;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech test_ctx->create_group1 = true;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech test_ctx->create_group2 = true;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
8be4efb91f9af1bf49628c497a9de4b258bb893ePavel Březina prepare_group(test_ctx->tctx->dom, &groups[1], 1001, time(NULL) - 1);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech req_mem_ctx = talloc_new(global_talloc_context);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech check_leaks_push(req_mem_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech /* Filters always go to DP */
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech will_return(__wrap_sss_dp_get_account_send, test_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech mock_account_recv_simple();
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
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 test_ctx->rctx,
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech test_ctx->tctx->dom->name,
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech TEST_USER_PREFIX);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_non_null(req);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech ret = test_ev_loop(test_ctx->tctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_int_equal(ret, ERR_OK);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_true(check_leaks_pop(req_mem_ctx));
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_non_null(test_ctx->result);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_int_equal(test_ctx->result->count, 2);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech tmp_ctx = talloc_new(req_mem_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech group_names = talloc_array(tmp_ctx, const char *, 2);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_non_null(group_names);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek group_names[0] = sss_create_internal_fqname(group_names, groups[0].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(group_names[0]);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek group_names[1] = sss_create_internal_fqname(group_names, groups[1].short_name,
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek test_ctx->domain->name);
187f65802ed26c49dbac2fba5e7cd1508f3db1e8Jakub Hrozek assert_non_null(group_names[1]);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech ldb_results = talloc_array(tmp_ctx, const char *, 2);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_non_null(ldb_results);
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 SYSDB_NAME, NULL);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_non_null(ldbname);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech ldb_results[i] = ldbname;
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech }
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_string_not_equal(ldb_results[0], ldb_results[1]);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech assert_true(tc_are_values_in_array(group_names, ldb_results));
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech talloc_zfree(tmp_ctx);
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech}
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_groups_by_filter_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek{
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct cache_req_test_ctx *test_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek TALLOC_CTX *req_mem_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct tevent_req *req = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek errno_t ret;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek check_leaks_push(req_mem_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek mock_account_recv_simple();
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->rctx,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->tctx->dom->name,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchgroup*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_non_null(req);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_int_equal(ret, ENOENT);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_true(check_leaks_pop(req_mem_ctx));
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek}
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozekvoid test_groups_by_filter_multiple_domains_notfound(void **state)
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek{
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct cache_req_test_ctx *test_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct sss_domain_info *domain = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek TALLOC_CTX *req_mem_ctx = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek struct tevent_req *req = NULL;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek errno_t ret;
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
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 assert_non_null(domain);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req_mem_ctx = talloc_new(global_talloc_context);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek check_leaks_push(req_mem_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek /* Filters always go to DP */
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek will_return(__wrap_sss_dp_get_account_send, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek mock_account_recv_simple();
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek test_ctx->rctx,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek domain->name,
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek "nosuchgroup*");
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_non_null(req);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_int_equal(ret, ENOENT);
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek assert_true(check_leaks_pop(req_mem_ctx));
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek}
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_cache_valid(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina users[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_cache_expired(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
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 mock_account_recv_simple();
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina users[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_cache_midpoint(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
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
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina users[0].sid, attrs, 50, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_ncache(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina errno_t ret;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sss_ncache_set_sid(test_ctx->ncache, false, users[0].sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_int_equal(ret, EOK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina users[0].sid, attrs, 0, ENOENT);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_false(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_missing_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina mock_account_recv_simple();
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx->create_user1 = true;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx->create_user2 = false;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina users[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_missing_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina mock_account_recv_simple();
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina users[0].sid, attrs, 0, ENOENT);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_multiple_domains_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct sss_domain_info *domain = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
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 assert_non_null(domain);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_user(domain, &users[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(sss_dp_get_account_recv, 0);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, users[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_user(test_ctx, &users[0], domain);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_user_multiple_domains_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_PW_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(sss_dp_get_account_recv, 0);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, users[0].sid, attrs, 0, ENOENT);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_cache_valid(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina groups[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_cache_expired(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
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 mock_account_recv_simple();
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina groups[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_cache_midpoint(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
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
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina groups[0].sid, attrs, 50, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_ncache(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina errno_t ret;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Setup user. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina ret = sss_ncache_set_sid(test_ctx->ncache, false, groups[0].sid);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_int_equal(ret, EOK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina groups[0].sid, attrs, 0, ENOENT);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_false(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_missing_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina mock_account_recv_simple();
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx->create_group1 = true;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx->create_group2 = false;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina groups[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_missing_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina mock_account_recv_simple();
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, test_ctx->tctx->dom,
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina groups[0].sid, attrs, 0, ENOENT);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_multiple_domains_found(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct sss_domain_info *domain = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
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 assert_non_null(domain);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina prepare_group(domain, &groups[0], 1000, time(NULL));
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(sss_dp_get_account_recv, 0);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, groups[0].sid, attrs, 0, ERR_OK);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina check_group(test_ctx, &groups[0], domain);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březinavoid test_object_by_sid_group_multiple_domains_notfound(void **state)
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina{
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina struct cache_req_test_ctx *test_ctx = NULL;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina const char *attrs[] = SYSDB_GRSRC_ATTRS;
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Mock values. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina will_return_always(sss_dp_get_account_recv, 0);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina /* Test. */
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina run_object_by_sid(test_ctx, NULL, groups[0].sid, attrs, 0, ENOENT);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina assert_true(test_ctx->dp_called);
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina}
0d111f6975c7e132bf1069d6d7bd6d6afd2127dfPavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březinaint main(int argc, const char *argv[])
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina{
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina poptContext pc;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina int opt;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina struct poptOption long_options[] = {
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina POPT_AUTOHELP
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina SSSD_DEBUG_OPTS
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina POPT_TABLEEND
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina };
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březina new_single_domain_test(user_by_name_cache_valid),
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březina new_single_domain_test(user_by_name_cache_expired),
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březina new_single_domain_test(user_by_name_cache_midpoint),
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březina new_single_domain_test(user_by_name_ncache),
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březina new_single_domain_test(user_by_name_missing_found),
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březina new_single_domain_test(user_by_name_missing_notfound),
54ed1b1214dbf9da1f481e8d193c81ce4312516bPavel Březina new_multi_domain_test(user_by_name_multiple_domains_found),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_multi_domain_test(user_by_name_multiple_domains_notfound),
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina new_multi_domain_test(user_by_name_multiple_domains_parse),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_single_domain_test(user_by_upn_cache_valid),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_single_domain_test(user_by_upn_cache_expired),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_single_domain_test(user_by_upn_cache_midpoint),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_single_domain_test(user_by_upn_ncache),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_single_domain_test(user_by_upn_missing_found),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_single_domain_test(user_by_upn_missing_notfound),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_multi_domain_test(user_by_upn_multiple_domains_found),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina new_multi_domain_test(user_by_upn_multiple_domains_notfound),
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_single_domain_test(user_by_id_cache_valid),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_single_domain_test(user_by_id_cache_expired),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_single_domain_test(user_by_id_cache_midpoint),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_single_domain_test(user_by_id_ncache),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_single_domain_test(user_by_id_missing_found),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_single_domain_test(user_by_id_missing_notfound),
3a5ea81007bd38ce511c37f65cc45d4b6b95ec44Pavel Březina new_multi_domain_test(user_by_id_multiple_domains_found),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_multi_domain_test(user_by_id_multiple_domains_notfound),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_single_domain_test(group_by_name_cache_valid),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_single_domain_test(group_by_name_cache_expired),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_single_domain_test(group_by_name_cache_midpoint),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_single_domain_test(group_by_name_ncache),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_single_domain_test(group_by_name_missing_found),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_single_domain_test(group_by_name_missing_notfound),
641d684ee88c6540a4cf1d74d258614f615699fePavel Březina new_multi_domain_test(group_by_name_multiple_domains_found),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_multi_domain_test(group_by_name_multiple_domains_notfound),
e87b2a6e94c1066b3044fe683825ff5b4f8716c2Pavel Březina new_multi_domain_test(group_by_name_multiple_domains_parse),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_single_domain_test(group_by_id_cache_valid),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_single_domain_test(group_by_id_cache_expired),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_single_domain_test(group_by_id_cache_midpoint),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_single_domain_test(group_by_id_ncache),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_single_domain_test(group_by_id_missing_found),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_single_domain_test(group_by_id_missing_notfound),
71965bb18407ff45ada9e47cb6def086e48663c6Pavel Březina new_multi_domain_test(group_by_id_multiple_domains_found),
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek new_multi_domain_test(group_by_id_multiple_domains_notfound),
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub Hrozek
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech new_single_domain_test(user_by_recent_filter_valid),
a6a5a08a357d2adbb653b81bacc602ca3543c4c4Petr Cech new_single_domain_test(users_by_recent_filter_valid),
fe6dd669d1e8606862879127f92c177bb7fdc1bdPetr Cech new_single_domain_test(group_by_recent_filter_valid),
16212bbb2aaa55d0587515e72c0018479ae51be9Petr Cech new_single_domain_test(groups_by_recent_filter_valid),
da79bee1472a06b89be2df903fb0bd8ce600c610Petr Cech
fd04b25eaa5cd105da4122854d8bc1e702760e60Jakub 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
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
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),
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina };
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina /* Set debug level to invalid value so we can deside if -d 0 was used. */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina debug_level = SSSDBG_INVALID;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina pc = poptGetContext(argv[0], argc, argv, long_options, 0);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina while((opt = poptGetNextOpt(pc)) != -1) {
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina switch(opt) {
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina default:
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina fprintf(stderr, "\nInvalid option %s: %s\n\n",
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina poptBadOption(pc, 0), poptStrerror(opt));
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina poptPrintUsage(pc, stderr, 0);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina return 1;
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina }
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina }
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina poptFreeContext(pc);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina DEBUG_CLI_INIT(debug_level);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina /* Even though normally the tests should clean up after themselves
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina * they might not after a failed run. Remove the old db to be sure */
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina tests_set_cwd();
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);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return cmocka_run_group_tests(tests, NULL, NULL);
360a4be4266d6a72be99dfd252623dc0527f5b84Pavel Březina}