Line data Source code
1 : /*
2 : Authors:
3 : Jakub Hrozek <jhrozek@redhat.com>
4 :
5 : Copyright (C) 2013 Red Hat
6 :
7 : SSSD tests: Fake Data Provider requests
8 :
9 : This program is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "util/util.h"
24 : #include "tests/cmocka/common_mock_resp.h"
25 :
26 : /* Mock DP requests that finish immediatelly and return
27 : * mocked values as per previous set by mock_account_recv
28 : */
29 : struct tevent_req *
30 20 : sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
31 : struct resp_ctx *rctx,
32 : struct sss_domain_info *dom,
33 : bool fast_reply,
34 : enum sss_dp_acct_type type,
35 : const char *opt_name,
36 : uint32_t opt_id,
37 : const char *extra)
38 : {
39 20 : return test_req_succeed_send(mem_ctx, rctx->ev);
40 : }
41 :
42 :
43 : errno_t
44 75 : sss_dp_get_account_recv(TALLOC_CTX *mem_ctx,
45 : struct tevent_req *req,
46 : dbus_uint16_t *dp_err,
47 : dbus_uint32_t *dp_ret,
48 : char **err_msg)
49 : {
50 : acct_cb_t cb;
51 :
52 75 : *dp_err = sss_mock_type(dbus_uint16_t);
53 75 : *dp_ret = sss_mock_type(dbus_uint32_t);
54 75 : *err_msg = sss_mock_ptr_type(char *);
55 :
56 75 : cb = sss_mock_ptr_type(acct_cb_t);
57 75 : if (cb) {
58 14 : (cb)(sss_mock_ptr_type(void *));
59 : }
60 :
61 75 : return test_request_recv(req);
62 : }
63 :
64 40 : void mock_account_recv(uint16_t dp_err, uint32_t dp_ret, char *msg,
65 : acct_cb_t acct_cb, void *pvt)
66 : {
67 40 : will_return(sss_dp_get_account_recv, dp_err);
68 40 : will_return(sss_dp_get_account_recv, dp_ret);
69 40 : will_return(sss_dp_get_account_recv, msg);
70 :
71 40 : will_return(sss_dp_get_account_recv, acct_cb);
72 40 : if (acct_cb) {
73 14 : will_return(sss_dp_get_account_recv, pvt);
74 : }
75 40 : }
76 :
77 26 : void mock_account_recv_simple(void)
78 : {
79 26 : return mock_account_recv(0, 0, NULL, NULL, NULL);
80 : }
81 :
82 : struct tevent_req *
83 14 : sss_parse_inp_send(TALLOC_CTX *mem_ctx, struct resp_ctx *rctx,
84 : const char *rawinp)
85 : {
86 14 : return test_req_succeed_send(mem_ctx, rctx->ev);
87 : }
88 :
89 14 : errno_t sss_parse_inp_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
90 : char **_name, char **_domname)
91 : {
92 14 : *_name = sss_mock_ptr_type(char *);
93 14 : *_domname = sss_mock_ptr_type(char *);
94 :
95 14 : return sss_mock_type(errno_t);
96 : }
97 :
98 14 : void mock_parse_inp(const char *name, const char *domname, errno_t ret)
99 : {
100 14 : will_return(sss_parse_inp_recv, name);
101 14 : will_return(sss_parse_inp_recv, domname);
102 14 : will_return(sss_parse_inp_recv, ret);
103 14 : }
104 :
105 : /* Mock subdomain requests */
106 : struct tevent_req *
107 38 : sss_dp_get_domains_send(TALLOC_CTX *mem_ctx,
108 : struct resp_ctx *rctx,
109 : bool force,
110 : const char *hint)
111 : {
112 38 : return test_req_succeed_send(mem_ctx, rctx->ev);
113 : }
114 :
115 38 : errno_t sss_dp_get_domains_recv(struct tevent_req *req)
116 : {
117 38 : return test_request_recv(req);
118 : }
|