LCOV - code coverage report
Current view: top level - tests/cmocka - common_mock_sdap.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 23 31 74.2 %
Date: 2015-10-19 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Pavel Březina <pbrezina@redhat.com>
       4             : 
       5             :     Copyright (C) 2013 Red Hat
       6             : 
       7             :     This program is free software; you can redistribute it and/or modify
       8             :     it under the terms of the GNU General Public License as published by
       9             :     the Free Software Foundation; either version 3 of the License, or
      10             :     (at your option) any later version.
      11             : 
      12             :     This program is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :     GNU General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include <talloc.h>
      22             : 
      23             : #include "util/util.h"
      24             : #include "providers/ldap/ldap_common.h"
      25             : #include "providers/ldap/sdap.h"
      26             : #include "tests/cmocka/common_mock.h"
      27             : 
      28          14 : struct sdap_id_ctx *mock_sdap_id_ctx(TALLOC_CTX *mem_ctx,
      29             :                                      struct be_ctx *be_ctx,
      30             :                                      struct sdap_options *sdap_opts)
      31             : {
      32             :     struct sdap_id_ctx *sdap_id_ctx;
      33             : 
      34          14 :     sdap_id_ctx = talloc_zero(mem_ctx, struct sdap_id_ctx);
      35          14 :     assert_non_null(sdap_id_ctx);
      36             : 
      37          14 :     sdap_id_ctx->be = be_ctx;
      38          14 :     sdap_id_ctx->opts = sdap_opts;
      39             : 
      40          14 :     return sdap_id_ctx;
      41             : }
      42             : 
      43           7 : struct sdap_options *mock_sdap_options_ldap(TALLOC_CTX *mem_ctx,
      44             :                                             struct sss_domain_info *domain,
      45             :                                             struct confdb_ctx *confdb_ctx,
      46             :                                             const char *conf_path)
      47             : {
      48           7 :     struct sdap_options *opts = NULL;
      49             :     errno_t ret;
      50             : 
      51           7 :     ret = ldap_get_options(mem_ctx, domain, confdb_ctx, conf_path, &opts);
      52           7 :     if (ret != EOK) {
      53           0 :         return NULL;
      54             :     }
      55             : 
      56           7 :     return opts;
      57             : }
      58             : 
      59           7 : struct sdap_handle *mock_sdap_handle(TALLOC_CTX *mem_ctx)
      60             : {
      61           7 :     struct sdap_handle *handle = talloc_zero(mem_ctx, struct sdap_handle);
      62             : 
      63             :     /* we will never connect to any LDAP server and any sdap API that
      64             :      * access sdap_handle should be mocked, thus returning empty structure
      65             :      * is enough */
      66             : 
      67           7 :     return handle;
      68             : }
      69             : 
      70             : /*
      71             :  * Mock sdap_async.c
      72             :  *
      73             :  * Every function that is placed in sdap_async.c module has to be mocked,
      74             :  * to avoid any attempt to communicate with remote servers. Therefore no test
      75             :  * can be compiled with sdap_async.c. If any of these functions is needed,
      76             :  * their mock equivalent shall be used.
      77             :  */
      78             : 
      79           7 : bool sdap_has_deref_support(struct sdap_handle *sh, struct sdap_options *opts)
      80             : {
      81           7 :     return sss_mock_type(bool);
      82             : }
      83             : 
      84          16 : struct tevent_req *sdap_get_generic_send(TALLOC_CTX *mem_ctx,
      85             :                                          struct tevent_context *ev,
      86             :                                          struct sdap_options *opts,
      87             :                                          struct sdap_handle *sh,
      88             :                                          const char *search_base,
      89             :                                          int scope,
      90             :                                          const char *filter,
      91             :                                          const char **attrs,
      92             :                                          struct sdap_attr_map *map,
      93             :                                          int map_num_attrs,
      94             :                                          int timeout,
      95             :                                          bool allow_paging)
      96             : {
      97          16 :     return test_req_succeed_send(mem_ctx, ev);
      98             : }
      99             : 
     100          16 : int sdap_get_generic_recv(struct tevent_req *req,
     101             :                           TALLOC_CTX *mem_ctx,
     102             :                           size_t *reply_count,
     103             :                           struct sysdb_attrs ***reply)
     104             : {
     105          16 :     TEVENT_REQ_RETURN_ON_ERROR(req);
     106             : 
     107          16 :     *reply_count = sss_mock_type(size_t);
     108          16 :     *reply = sss_mock_ptr_type(struct sysdb_attrs **);
     109             : 
     110          16 :     return sss_mock_type(int);
     111             : }
     112             : 
     113           0 : struct tevent_req * sdap_deref_search_send(TALLOC_CTX *mem_ctx,
     114             :                                            struct tevent_context *ev,
     115             :                                            struct sdap_options *opts,
     116             :                                            struct sdap_handle *sh,
     117             :                                            const char *base_dn,
     118             :                                            const char *deref_attr,
     119             :                                            const char **attrs,
     120             :                                            int num_maps,
     121             :                                            struct sdap_attr_map_info *maps,
     122             :                                            int timeout)
     123             : {
     124           0 :     return test_req_succeed_send(mem_ctx, ev);
     125             : }
     126             : 
     127           0 : int sdap_deref_search_recv(struct tevent_req *req,
     128             :                            TALLOC_CTX *mem_ctx,
     129             :                            size_t *reply_count,
     130             :                            struct sdap_deref_attrs ***reply)
     131             : {
     132           0 :     TEVENT_REQ_RETURN_ON_ERROR(req);
     133             : 
     134           0 :     *reply_count = sss_mock_type(size_t);
     135           0 :     *reply = talloc_steal(mem_ctx,
     136             :                           sss_mock_ptr_type(struct sdap_deref_attrs **));
     137             : 
     138           0 :     return EOK;
     139             : }

Generated by: LCOV version 1.10