150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/*
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek Authors:
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek Copyright (C) 2013 Red Hat
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek SSSD tests: Common utilities for tests that exercise domains
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek This program is free software; you can redistribute it and/or modify
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek it under the terms of the GNU General Public License as published by
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek (at your option) any later version.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek This program is distributed in the hope that it will be useful,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek GNU General Public License for more details.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek You should have received a copy of the GNU General Public License
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek*/
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include "util/util.h"
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek#include "tests/cmocka/common_mock_resp.h"
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Mock a responder context */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstruct resp_ctx *
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekmock_rctx(TALLOC_CTX *mem_ctx,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct tevent_context *ev,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct sss_domain_info *domains,
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek void *pvt_ctx)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct resp_ctx *rctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek errno_t ret;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek rctx = talloc_zero(mem_ctx, struct resp_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (!rctx) return NULL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek ret = sss_hash_create(rctx, 30, &rctx->dp_request_table);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (ret != EOK) {
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek talloc_free(rctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return NULL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech ret = sss_ncache_init(rctx, 10, 0, &rctx->ncache);
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech if (ret != EOK) {
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech talloc_free(rctx);
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech return NULL;
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech }
56c9f8731173eae841a05f31bb03d311076a8485Petr Cech
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek rctx->ev = ev;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek rctx->domains = domains;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek rctx->pvt_ctx = pvt_ctx;
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio if (domains != NULL) {
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio ret = sss_resp_populate_cr_domains(rctx);
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio if (ret != EOK) {
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio return NULL;
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio }
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return rctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek/* Mock a client context */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekstruct cli_ctx *
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozekmock_cctx(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx)
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek{
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek struct cli_ctx *cctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek cctx = talloc_zero(mem_ctx, struct cli_ctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (!cctx) return NULL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce cctx->rctx = rctx;
8d5292227a8d1ab9c6aa5b88d8ac8655cd1223e5Pavel Březina cctx->ev = rctx->ev;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce return cctx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce}
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorcestruct cli_protocol *
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorcemock_prctx(TALLOC_CTX *mem_ctx)
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *prctx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce prctx = talloc_zero(mem_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce if (!prctx) return NULL;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce prctx->creq = talloc_zero(prctx, struct cli_request);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce if (prctx->creq == NULL) {
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce talloc_free(prctx);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek return NULL;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek }
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce return prctx;
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek}