c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek/*
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek Authors:
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek Copyright (C) 2013 Red Hat
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek SSSD tests: Fake Data Provider requests
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek This program is free software; you can redistribute it and/or modify
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek it under the terms of the GNU General Public License as published by
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek (at your option) any later version.
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek This program is distributed in the hope that it will be useful,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek GNU General Public License for more details.
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek You should have received a copy of the GNU General Public License
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek*/
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek#include "util/util.h"
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio#include "responder/common/responder.h"
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek#include "tests/cmocka/common_mock_resp.h"
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
a02a5ed51178b2cbede0396d66aed716b8898096René Genz/* Mock DP requests that finish immediately and return
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek * mocked values as per previous set by mock_account_recv
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek */
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozekstruct tevent_req *
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozeksss_dp_get_account_send(TALLOC_CTX *mem_ctx,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek struct resp_ctx *rctx,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek struct sss_domain_info *dom,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek bool fast_reply,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek enum sss_dp_acct_type type,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek const char *opt_name,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek uint32_t opt_id,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek const char *extra)
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek{
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek return test_req_succeed_send(mem_ctx, rctx->ev);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek}
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozekerrno_t
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozeksss_dp_get_account_recv(TALLOC_CTX *mem_ctx,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek struct tevent_req *req,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek dbus_uint16_t *dp_err,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek dbus_uint32_t *dp_ret,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek char **err_msg)
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek{
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek acct_cb_t cb;
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek *dp_err = sss_mock_type(dbus_uint16_t);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek *dp_ret = sss_mock_type(dbus_uint32_t);
b1bea7c3d202eb3b53e219c9ccb83161ce47ca6aSumit Bose *err_msg = sss_mock_ptr_type(char *);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek cb = sss_mock_ptr_type(acct_cb_t);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek if (cb) {
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek (cb)(sss_mock_ptr_type(void *));
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek }
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina return test_request_recv(req);
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina}
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březinastruct tevent_req *
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březinasss_dp_get_ssh_host_send(TALLOC_CTX *mem_ctx,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina struct resp_ctx *rctx,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina struct sss_domain_info *dom,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina bool fast_reply,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina const char *name,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina const char *alias)
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina{
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina return test_req_succeed_send(mem_ctx, rctx->ev);
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina}
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březinaerrno_t
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březinasss_dp_get_ssh_host_recv(TALLOC_CTX *mem_ctx,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina struct tevent_req *req,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina dbus_uint16_t *dp_err,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina dbus_uint32_t *dp_ret,
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina char **err_msg)
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina{
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina acct_cb_t cb;
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina *dp_err = sss_mock_type(dbus_uint16_t);
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina *dp_ret = sss_mock_type(dbus_uint32_t);
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina *err_msg = sss_mock_ptr_type(char *);
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina cb = sss_mock_ptr_type(acct_cb_t);
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina if (cb) {
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina (cb)(sss_mock_ptr_type(void *));
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina }
53c31b83e4d06ea4c2813eec2f1e647a613b4a2bPavel Březina
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek return test_request_recv(req);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek}
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březinaerrno_t
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březinasss_dp_req_recv(TALLOC_CTX *mem_ctx,
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina struct tevent_req *req,
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina dbus_uint16_t *dp_err,
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina dbus_uint32_t *dp_ret,
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina char **err_msg)
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina{
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina acct_cb_t cb;
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina *dp_err = sss_mock_type(dbus_uint16_t);
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina *dp_ret = sss_mock_type(dbus_uint32_t);
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina *err_msg = sss_mock_ptr_type(char *);
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina cb = sss_mock_ptr_type(acct_cb_t);
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina if (cb) {
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina (cb)(sss_mock_ptr_type(void *));
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina }
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina return test_request_recv(req);
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina}
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozekvoid mock_account_recv(uint16_t dp_err, uint32_t dp_ret, char *msg,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek acct_cb_t acct_cb, void *pvt)
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek{
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina will_return(sss_dp_req_recv, dp_err);
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina will_return(sss_dp_req_recv, dp_ret);
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina will_return(sss_dp_req_recv, msg);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina will_return(sss_dp_req_recv, acct_cb);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek if (acct_cb) {
4df7aec645f87342f3a5146062abcb15f71f4fd9Pavel Březina will_return(sss_dp_req_recv, pvt);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek }
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek}
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozekvoid mock_account_recv_simple(void)
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek{
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek return mock_account_recv(0, 0, NULL, NULL, NULL);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek}
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekstruct tevent_req *
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březinasss_parse_inp_send(TALLOC_CTX *mem_ctx,
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina struct resp_ctx *rctx,
2b5704cd96a085b99d3b0d4f80f4414adc134750Pavel Březina const char *default_domain,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek const char *rawinp)
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek{
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek return test_req_succeed_send(mem_ctx, rctx->ev);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek}
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozekerrno_t sss_parse_inp_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek char **_name, char **_domname)
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek{
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek *_name = sss_mock_ptr_type(char *);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek *_domname = sss_mock_ptr_type(char *);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina return sss_mock_type(errno_t);
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek}
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březinavoid mock_parse_inp(const char *name, const char *domname, errno_t ret)
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek{
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek will_return(sss_parse_inp_recv, name);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek will_return(sss_parse_inp_recv, domname);
28ebfa4373d1e7ce45b5d70a3619df1c074a661ePavel Březina will_return(sss_parse_inp_recv, ret);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek}
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek/* Mock subdomain requests */
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozekstruct tevent_req *
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozeksss_dp_get_domains_send(TALLOC_CTX *mem_ctx,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek struct resp_ctx *rctx,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek bool force,
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek const char *hint)
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek{
66c8e92eb5a4985bb7f64c349a53b08030a000cfFabiano Fidêncio errno_t ret;
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
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek return test_req_succeed_send(mem_ctx, rctx->ev);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek}
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozekerrno_t sss_dp_get_domains_recv(struct tevent_req *req)
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek{
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek return test_request_recv(req);
c440c424443517b12afa8d56f989d92ca6ba56a3Jakub Hrozek}
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozekstruct tevent_req *
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozeksss_dp_get_account_domain_send(TALLOC_CTX *mem_ctx,
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek struct resp_ctx *rctx,
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek struct sss_domain_info *domain,
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek enum sss_dp_acct_type type,
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek uint32_t opt_id)
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek{
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek return test_req_succeed_send(mem_ctx, rctx->ev);
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek}
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozekerrno_t sss_dp_get_account_domain_recv(TALLOC_CTX *mem_ctx,
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek struct tevent_req *req,
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek char **_domain)
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek{
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek errno_t ret;
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek ret = sss_mock_type(errno_t);
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek if (ret == EOK) {
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek *_domain = sss_mock_ptr_type(char *);
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek }
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek return ret;
a6eb9c4c3ff68d134bc745e8374f182737e9696bJakub Hrozek}