test_fo_srv.c revision a299f900981343904d7c9c5d148e30b8e0b2c460
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen Jakub Hrozek <jhrozek@redhat.com>
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen Copyright (C) 2014 Red Hat
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen SSSD tests: Resolver tests using a fake resolver library
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen This program is free software; you can redistribute it and/or modify
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen it under the terms of the GNU General Public License as published by
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen the Free Software Foundation; either version 3 of the License, or
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen (at your option) any later version.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen This program is distributed in the hope that it will be useful,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen GNU General Public License for more details.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen You should have received a copy of the GNU General Public License
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenenum host_database default_host_dbs[] = { DB_FILES, DB_DNS, DB_SENTINEL };
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen/* mock resolver interface. The resolver test is separate */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenint resolv_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenresolv_gethostbyname_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenint resolv_gethostbyname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstruct tevent_req *resolv_discover_srv_send(TALLOC_CTX *mem_ctx,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenerrno_t resolv_discover_srv_recv(TALLOC_CTX *mem_ctx,
d868a04630bd7bfe9c1543a7c3f68703b3e276e4Timo Sirainen /* Need to always consume all mocked values */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen reply_list = sss_mock_ptr_type(struct ares_srv_reply *);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstruct ares_srv_reply *pop_lowest_prio(struct ares_srv_reply **r)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen /* iter points to the lowest prio. Prev points to the item before */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenint resolv_sort_srv_reply(struct ares_srv_reply **reply)
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen } while (r != NULL);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstruct tevent_req *resolv_get_domain_send(TALLOC_CTX *mem_ctx,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenerrno_t resolv_get_domain_recv(TALLOC_CTX *mem_ctx,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen/* The unit test */
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen global_mock_context = talloc_new(global_talloc_context);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen ret = resolv_init(test_ctx, test_ctx->ctx->ev,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen test_ctx->fo_ctx = fo_context_init(test_ctx, &fopts);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen ret = fo_new_service(test_ctx->fo_ctx, "ldap",
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen test_ctx->srv_ctx = fo_resolve_srv_dns_ctx_init(test_ctx, test_ctx->resolv,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen ok = fo_set_srv_lookup_plugin(test_ctx->fo_ctx,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen/* reply_list and dns_domain must be a talloc context so it can be used as
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen * talloc_steal argument later
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstatic void mock_srv_results(struct ares_srv_reply *reply_list,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen will_return(resolv_discover_srv_recv, reply_list);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen will_return(resolv_discover_srv_recv, dns_domain);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstatic void check_server(struct test_fo_ctx *ctx,
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen assert_int_equal(fo_get_server_port(srv), port);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainen assert_string_equal(fo_get_server_name(srv), name);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstatic void test_fo_srv_step1(struct test_fo_ctx *test_ctx);
a49d1c2ca3c134c0c62b37a94936c78e9849e044Timo Sirainenstatic void test_fo_srv_done1(struct tevent_req *req);
struct ares_srv_reply *
struct ares_srv_reply *s;
if (s == NULL) {
return NULL;
talloc_free(s);
return NULL;
int ttl)
char *dns_domain;
/* ldap1.sssd.com has lower priority, it must always be first */
/* ldap1.sssd.com has lower priority, it must always be first */
char *dns_domain;
char *dns_domain;
* This is a regression test for https://fedorahosted.org/sssd/ticket/3131
const char *name;
int rv;
int opt;
switch(opt) {
return rv;