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