common_mock_sdap.c revision 3f32406640d89face5e79244b4d8dab34adb6c7c
842ae4bd224140319ae7feec1872b93dfd491143fielding/*
842ae4bd224140319ae7feec1872b93dfd491143fielding Authors:
842ae4bd224140319ae7feec1872b93dfd491143fielding Pavel Březina <pbrezina@redhat.com>
842ae4bd224140319ae7feec1872b93dfd491143fielding
842ae4bd224140319ae7feec1872b93dfd491143fielding Copyright (C) 2013 Red Hat
842ae4bd224140319ae7feec1872b93dfd491143fielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding This program is free software; you can redistribute it and/or modify
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd it under the terms of the GNU General Public License as published by
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding the Free Software Foundation; either version 3 of the License, or
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd (at your option) any later version.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd This program is distributed in the hope that it will be useful,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd but WITHOUT ANY WARRANTY; without even the implied warranty of
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding GNU General Public License for more details.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding You should have received a copy of the GNU General Public License
36a72c96fc2dda27eadbae8a108fa428cc1419c1wrowe along with this program. If not, see <http://www.gnu.org/licenses/>.
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm*/
59b96ad34c087942eea06884c97d12c2796a977amturk
c0a549c3f6e8edc87e921cf76fac95d04feba72bwrowe#include <talloc.h>
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#include "util/util.h"
70535d6421eb979ac79d8f49d31cd94d75dd8b2fjorton#include "providers/ldap/ldap_common.h"
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#include "providers/ldap/sdap.h"
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe#include "tests/cmocka/common_mock.h"
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe
79d97c2c5e2d3f8bb2a92cd21b3b4900d7bf04d6mturkerrno_t krb5_try_kdcip(struct confdb_ctx *cdb,
79d97c2c5e2d3f8bb2a92cd21b3b4900d7bf04d6mturk const char *conf_path,
79d97c2c5e2d3f8bb2a92cd21b3b4900d7bf04d6mturk struct dp_option *opts,
79d97c2c5e2d3f8bb2a92cd21b3b4900d7bf04d6mturk int opt_id)
2555a6b5da21d61804f47084d8fcc98eb4acbc42wrowe{
1723d9ccdd3b647f5b7bae44cab9ab3eca7a4874dougm return EOK;
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick}
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawick
e9501b71b8a1e76384cb010b1e41e76a1e47aacctrawickstruct sdap_options *mock_sdap_options_ldap(TALLOC_CTX *mem_ctx,
6335eb31f0f0ed54628a04ed32946360b8b77684minfrin struct sss_domain_info *domain,
7a3f81622e6b6995e0e879b1c0279ba68130b4b1jfclere struct confdb_ctx *confdb_ctx,
7a3f81622e6b6995e0e879b1c0279ba68130b4b1jfclere const char *conf_path)
7a3f81622e6b6995e0e879b1c0279ba68130b4b1jfclere{
7a3f81622e6b6995e0e879b1c0279ba68130b4b1jfclere struct sdap_options *opts = NULL;
7a3f81622e6b6995e0e879b1c0279ba68130b4b1jfclere errno_t ret;
7a3f81622e6b6995e0e879b1c0279ba68130b4b1jfclere
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = ldap_get_options(mem_ctx, domain, confdb_ctx, conf_path, &opts);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ret != EOK) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe return opts;
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe}
2ceedfca3a2fdfdb5ff60ca17f030ce91f6331cbwrowe
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstruct sdap_handle *mock_sdap_handle(TALLOC_CTX *mem_ctx)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct sdap_handle *handle = talloc_zero(mem_ctx, struct sdap_handle);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* we will never connect to any LDAP server and any sdap API that
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * access sdap_handle should be mocked, thus returning empty structure
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * is enough */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return handle;
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe}
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe/*
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * Mock sdap_async.c
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe *
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * Every function that is placed in sdap_async.c module has to be mocked,
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * to avoid any attempt to communicate with remote servers. Therefore no test
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * can be compiled with sdap_async.c. If any of these functions is needed,
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe * their mock equivalent shall be used.
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe */
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowe
eee895b02dd7867622afd0a8a94f2efc7de9c618wrowebool sdap_has_deref_support(struct sdap_handle *sh, struct sdap_options *opts)
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe{
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe return sss_mock_type(bool);
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe}
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestruct tevent_req *sdap_get_generic_send(TALLOC_CTX *mem_ctx,
90f18725dbb9bdfba94da22aa60f94dfb759a8ferpluem struct tevent_context *ev,
90f18725dbb9bdfba94da22aa60f94dfb759a8ferpluem struct sdap_options *opts,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe struct sdap_handle *sh,
9f1a88897168c3f1e5009acb585daf01e38a0299jim const char *search_base,
9f1a88897168c3f1e5009acb585daf01e38a0299jim int scope,
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk const char *filter,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe const char **attrs,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe struct sdap_attr_map *map,
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe int map_num_attrs,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe int timeout,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe bool allow_paging)
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk{
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk return test_req_succeed_send(mem_ctx, ev);
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk}
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk
38fd849bd99e2765ee633b6dc576b5f17acdc455wroweint sdap_get_generic_recv(struct tevent_req *req,
f251b576aa9caeb8876ce9f78fb10bf65eddc97emturk TALLOC_CTX *mem_ctx,
f251b576aa9caeb8876ce9f78fb10bf65eddc97emturk size_t *reply_count,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe struct sysdb_attrs ***reply)
f251b576aa9caeb8876ce9f78fb10bf65eddc97emturk{
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe TEVENT_REQ_RETURN_ON_ERROR(req);
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk *reply_count = sss_mock_type(size_t);
0c888b8088644f3a39dcf1998e0304c289532057jim *reply = talloc_steal(mem_ctx,
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk sss_mock_ptr_type(struct sysdb_attrs **));
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe return EOK;
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe}
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowestruct tevent_req * sdap_deref_search_send(TALLOC_CTX *mem_ctx,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe struct tevent_context *ev,
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk struct sdap_options *opts,
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk struct sdap_handle *sh,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe const char *base_dn,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe const char *deref_attr,
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe const char **attrs,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe int num_maps,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe struct sdap_attr_map_info *maps,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe int timeout)
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk{
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk return test_req_succeed_send(mem_ctx, ev);
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe}
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wroweint sdap_deref_search_recv(struct tevent_req *req,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe TALLOC_CTX *mem_ctx,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe size_t *reply_count,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe struct sdap_deref_attrs ***reply)
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe{
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk TEVENT_REQ_RETURN_ON_ERROR(req);
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk
01261c7d9578aadd1891f94c8ee03f32ba51db3dmturk *reply_count = sss_mock_type(size_t);
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe *reply = talloc_steal(mem_ctx,
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe sss_mock_ptr_type(struct sdap_deref_attrs **));
1dac466bcc84f8ebf410016dcf2a4cd4312e8611wrowe
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe return EOK;
38fd849bd99e2765ee633b6dc576b5f17acdc455wrowe}
9621e4c4056383e4a2b844b14687bae500b33a82wrowe