test_nss_srv.c revision 229c292143dcd4120acb022682b5b7d0aca622dd
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz Jakub Hrozek <jhrozek@redhat.com>
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz Copyright (C) 2013 Red Hat
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd SSSD tests: NSS responder tests
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd This program is free software; you can redistribute it and/or modify
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd it under the terms of the GNU General Public License as published by
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen the Free Software Foundation; either version 3 of the License, or
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen (at your option) any later version.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen This program is distributed in the hope that it will be useful,
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd but WITHOUT ANY WARRANTY; without even the implied warranty of
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd GNU General Public License for more details.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd You should have received a copy of the GNU General Public License
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd along with this program. If not, see <http://www.gnu.org/licenses/>.
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirin/* Mock NSS structure */
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirin err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz DEBUG(SSSDBG_FATAL_FAILURE, "sss_idmap_init failed.\n");
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf/* Mock reading requests from a client. Use values passed from mock
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirinvoid __real_sss_packet_get_body(struct sss_packet *packet,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalicvoid __wrap_sss_packet_get_body(struct sss_packet *packet,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic enum sss_test_wrapper_call wtype = sss_mock_type(enum sss_test_wrapper_call);
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirin return __real_sss_packet_get_body(packet, body, blen);
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic if (len == 0) {
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic/* Mock returning result to client. Terminate the unit test instead. */
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirintypedef int (*cmd_cb_fn_t)(uint32_t, uint8_t *, size_t );
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsfvoid __wrap_sss_cmd_done(struct cli_ctx *cctx, void *freectx)
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirin nss_test_ctx->tctx->error = check_cb(sss_packet_get_status(packet),
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalicenum sss_cli_command __wrap_sss_packet_get_cmd(struct sss_packet *packet)
d8c20b2218b1aff46358f67ae5e9c66a67982efbminfrinint __wrap_sss_cmd_send_empty(struct cli_ctx *cctx, TALLOC_CTX *freectx)
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf/* Intercept negative cache lookups */
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsfint __real_sss_ncache_check_user(struct sss_nc_ctx *ctx, int ttl,
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirinint __wrap_sss_ncache_check_user(struct sss_nc_ctx *ctx, int ttl,
f0fa55ff14fa0bf8fd72d989f6625de6dc3260c8igalic ret = __real_sss_ncache_check_user(ctx, ttl, dom, name);
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirinint __real_sss_ncache_check_uid(struct sss_nc_ctx *ctx, int ttl, uid_t uid);
8951c7d73bfa2ae5a2c8fe5bd27f3e677be02564noirinint __wrap_sss_ncache_check_uid(struct sss_nc_ctx *ctx, int ttl, uid_t uid)
1b390add6886fb1c0acdea82be0ef0920f1158casf/* Mock input from the client library */
1b390add6886fb1c0acdea82be0ef0920f1158casfstatic void mock_input_user_or_group(const char *username)
1b390add6886fb1c0acdea82be0ef0920f1158casf will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
1b390add6886fb1c0acdea82be0ef0920f1158casfstatic void mock_input_id(TALLOC_CTX *mem_ctx, uint32_t id)
1b390add6886fb1c0acdea82be0ef0920f1158casf will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
5f9231b22f11ab2ba17c96400438fd1244087efdrbowen will_return(__wrap_sss_packet_get_body, sizeof(uint32_t));
5f9231b22f11ab2ba17c96400438fd1244087efdrbowenstatic void mock_fill_user(void)
5f9231b22f11ab2ba17c96400438fd1244087efdrbowen /* One packet for the entry and one for num entries */
5f9231b22f11ab2ba17c96400438fd1244087efdrbowen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
5f9231b22f11ab2ba17c96400438fd1244087efdrbowen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
5f9231b22f11ab2ba17c96400438fd1244087efdrbowenstatic void mock_fill_group_with_members(unsigned members)
bdd978e5ecd8daa2542d4d4e1988c78a622cd7f4nd unsigned i;
0066eddda7203f6345b56f77d146a759298dc635gryzor will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
0d0ba3a410038e179b695446bb149cce6264e0abnd if (members == 0) return;
ccb709596bad11241fad96d128bbaae408ad78a7rbowen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh /* Member header , one per member */
ccb709596bad11241fad96d128bbaae408ad78a7rbowen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
0d0ba3a410038e179b695446bb149cce6264e0abnd for (i=0; i<members; i++) {
0d0ba3a410038e179b695446bb149cce6264e0abndstatic int parse_user_packet(uint8_t *body, size_t blen, struct passwd *pwd)
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh SAFEALIGN_COPY_UINT32(&pwd->pw_uid, body+rp, &rp);
0d0ba3a410038e179b695446bb149cce6264e0abnd /* Sequence of null terminated strings (name, passwd, gecos, dir, shell) */
return EOK;
if (*nmem > 0) {
for (i = 0; i < *nmem; i++) {
return EOK;
return EOK;
return EOK;
return EOK;
return EOK;
return EOK;
const char *shell;
return EOK;
return EOK;
return EOK;
return EOK;
return EOK;
return EOK;
return EOK;
return EOK;
return EOK;
const char *shell;
void **state)
for (i = 0; i < nmem; i++) {
return EOK;
int ret;
return EOK;
int ret;
return EOK;
SYSDB_MEMBER_USER, false);
SYSDB_MEMBER_USER, false);
int ret;
return EOK;
int ret;
return EOK;
SYSDB_MEMBER_USER, false);
SYSDB_MEMBER_USER, false);
int ret;
return EOK;
int ret;
return EOK;
int ret;
return EOK;
int ret;
return EOK;
int ret;
return EOK;
const char *name;
return EOK;
return EOK;
false, false, NULL);
false, false, NULL);
int rv;
int no_cleanup = 0;
int opt;
switch(opt) {
return rv;