test_nss_srv.c revision e4549c5364461644723361d688badde7fe137a25
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen Jakub Hrozek <jhrozek@redhat.com>
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen Copyright (C) 2013 Red Hat
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen SSSD tests: NSS responder tests
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen This program is free software; you can redistribute it and/or modify
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen it under the terms of the GNU General Public License as published by
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen the Free Software Foundation; either version 3 of the License, or
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen (at your option) any later version.
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen This program is distributed in the hope that it will be useful,
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen GNU General Public License for more details.
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen You should have received a copy of the GNU General Public License
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
d43c646d4b84635aa795946555be04a553d5413aTimo Sirainen#define TEST_SYSDB_FILE "cache_"TEST_DOM_NAME".ldb"
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainenconst char *global_extra_attrs[] = {"phone", "mobile", NULL};
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen/* Mock NSS structure */
e80203675151ef9d4f3f850cf02041042eb13096Timo Sirainen err = sss_idmap_init(sss_idmap_talloc, nctx, sss_idmap_talloc_free,
e80203675151ef9d4f3f850cf02041042eb13096Timo Sirainen DEBUG(SSSDBG_FATAL_FAILURE, "sss_idmap_init failed.\n");
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainen/* Mock reading requests from a client. Use values passed from mock
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainenvoid __real_sss_packet_get_body(struct sss_packet *packet,
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenvoid __wrap_sss_packet_get_body(struct sss_packet *packet,
09ea3aa6bc03544a9e712d263f07976255aaaaf0Timo Sirainen enum sss_test_wrapper_call wtype = sss_mock_type(enum sss_test_wrapper_call);
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainen return __real_sss_packet_get_body(packet, body, blen);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen/* Mock returning result to client. Terminate the unit test instead. */
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainentypedef int (*cmd_cb_fn_t)(uint32_t, uint8_t *, size_t );
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenvoid __wrap_sss_cmd_done(struct cli_ctx *cctx, void *freectx)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen __real_sss_packet_get_body(packet, &body, &blen);
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainen nss_test_ctx->tctx->error = check_cb(sss_packet_get_status(packet),
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainenenum sss_cli_command __wrap_sss_packet_get_cmd(struct sss_packet *packet)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenint __wrap_sss_cmd_send_empty(struct cli_ctx *cctx, TALLOC_CTX *freectx)
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainen/* Intercept negative cache lookups */
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainenint __real_sss_ncache_check_user(struct sss_nc_ctx *ctx, int ttl,
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainen struct sss_domain_info *dom, const char *name);
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainenint __wrap_sss_ncache_check_user(struct sss_nc_ctx *ctx, int ttl,
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainen struct sss_domain_info *dom, const char *name)
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainen ret = __real_sss_ncache_check_user(ctx, ttl, dom, name);
e80203675151ef9d4f3f850cf02041042eb13096Timo Sirainenint __real_sss_ncache_check_uid(struct sss_nc_ctx *ctx, int ttl, uid_t uid);
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainenint __wrap_sss_ncache_check_uid(struct sss_nc_ctx *ctx, int ttl, uid_t uid)
517d1e7142d57299c733b30423e35e7e1f8d01d6Timo Sirainen ret = __real_sss_ncache_check_uid(ctx, ttl, uid);
1e21e6be70994b1aa9e52ca0e2f51afefca6d0dfTimo Sirainen/* Mock input from the client library */
1e21e6be70994b1aa9e52ca0e2f51afefca6d0dfTimo Sirainenstatic void mock_input_user_or_group(const char *username)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen will_return(__wrap_sss_packet_get_body, username);
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainenstatic void mock_input_id(TALLOC_CTX *mem_ctx, uint32_t id)
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen body = talloc_zero_array(mem_ctx, uint8_t, 4);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
1704aa6b56b6a97bab6e995bcf7170b0c6527291Timo Sirainen will_return(__wrap_sss_packet_get_body, body);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, sizeof(uint32_t));
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainenstatic void mock_fill_user(void)
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen /* One packet for the entry and one for num entries */
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
1704aa6b56b6a97bab6e995bcf7170b0c6527291Timo Sirainenstatic void mock_fill_group_with_members(unsigned members)
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen if (members == 0) return;
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
97c339398f1aba6f315b55a9b6ee6b020e33bea4Timo Sirainen /* Member header , one per member */
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen for (i=0; i<members; i++) {
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic int parse_user_packet(uint8_t *body, size_t blen, struct passwd *pwd)
97c339398f1aba6f315b55a9b6ee6b020e33bea4Timo Sirainen SAFEALIGN_COPY_UINT32(&pwd->pw_uid, body+rp, &rp);
97c339398f1aba6f315b55a9b6ee6b020e33bea4Timo Sirainen SAFEALIGN_COPY_UINT32(&pwd->pw_gid, body+rp, &rp);
97c339398f1aba6f315b55a9b6ee6b020e33bea4Timo Sirainen /* Sequence of null terminated strings (name, passwd, gecos, dir, shell) */
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic int parse_group_packet(uint8_t *body, size_t blen, struct group *gr, uint32_t *nmem)
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen size_t rp = 2 * sizeof(uint32_t); /* Len and reserved */
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen SAFEALIGN_COPY_UINT32(&gr->gr_gid, body+rp, &rp);
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen gr->gr_mem = talloc_zero_array(nss_test_ctx, char *, *nmem);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen for (i = 0; i < *nmem; i++) {
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen gr->gr_mem[i] = talloc_strdup(gr->gr_mem, (char *) body+rp);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen /* Make sure we exactly matched the end of the packet */
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen/* ====================== The tests =============================== */
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;
return EOK;
false, false, NULL);
false, false, NULL);
int rv;
int no_cleanup = 0;
int opt;
switch(opt) {
return rv;