Commit da9e34e tests: fix sss_nss_idmap-tests

4 files Authored by sbose 5 days ago , Committed by fidencio 5 days ago ,
tests: fix sss_nss_idmap-tests

If sss_nss_idmap-tests is complied with -Wl,-Bsymbolic-functions it
fails because sss_nss_make_request_timeout() is not properly wrapped but
the tests expects that the replacement call it provides is picked by the
linker and not the original function.

This patch wraps the call in the corresponding test library. As a
consequence a small helper function had to be added to make dlopen-tests
pass for the test library as well.

Resolves:
https://pagure.io/SSSD/sssd/issue/3801

Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
Tested-by: Andreas Hasenack <andreas.hasenack@canonical.com>

    
 1 @@ -1903,8 +1903,14 @@
 2       $(NULL)
 3   endif
 4   
 5 + # libdlopen_test_providers is a helper library to provide missing symbols for
 6 + # dlopen_tests. It is mainly used for the backend modules but is used as well
 7 + # to provide __wrap_sss_nss_make_request_timeout needed make make dlopen_tests
 8 + # pass for libsss_nss_idmap_tests.
 9   libdlopen_test_providers_la_SOURCES = \
10 -     $(sssd_be_SOURCES)
11 +     $(sssd_be_SOURCES) \
12 +     src/tests/cmocka/wrap_sss_nss_make_request_timeout.c \
13 +     $(NULL)
14   libdlopen_test_providers_la_CFLAGS = \
15       $(AM_CFLAGS) \
16       $(CHECK_CFLAGS) \
17 @@ -1932,6 +1938,7 @@
18       $(libsss_nss_idmap_la_LDFLAGS) \
19       -shared \
20       -rpath $(libdir) \
21 +     -Wl,-wrap,sss_nss_make_request_timeout \
22       -Wl,--version-script,$(srcdir)/src/sss_client/idmap/sss_nss_idmap.unit_tests
23   
24   dist_noinst_DATA += src/sss_client/idmap/sss_nss_idmap.unit_tests
 1 @@ -61,11 +61,12 @@
 2    #error "unknow endianess"
 3   #endif
 4   
 5 - enum nss_status sss_nss_make_request_timeout(enum sss_cli_command cmd,
 6 -                                              struct sss_cli_req_data *rd,
 7 -                                              int timeout,
 8 -                                              uint8_t **repbuf, size_t *replen,
 9 -                                              int *errnop)
10 + enum nss_status __wrap_sss_nss_make_request_timeout(enum sss_cli_command cmd,
11 +                                                     struct sss_cli_req_data *rd,
12 +                                                     int timeout,
13 +                                                     uint8_t **repbuf,
14 +                                                     size_t *replen,
15 +                                                     int *errnop)
16   {
17       struct sss_nss_make_request_test_data *d;
18   
19 @@ -115,7 +116,7 @@
20       sid = NULL;
21   
22       for (c = 0; d[c].d.repbuf != NULL; c++) {
23 -         will_return(sss_nss_make_request_timeout, &d[0].d);
24 +         will_return(__wrap_sss_nss_make_request_timeout, &d[0].d);
25   
26           ret = sss_nss_getsidbyname("test", &sid, &type);
27           assert_int_equal(ret, d[0].ret);
28 @@ -135,7 +136,7 @@
29       enum sss_id_type type;
30       struct sss_nss_make_request_test_data d = {buf_orig1, sizeof(buf_orig1), 0, NSS_STATUS_SUCCESS};
31   
32 -     will_return(sss_nss_make_request_timeout, &d);
33 +     will_return(__wrap_sss_nss_make_request_timeout, &d);
34       ret = sss_nss_getorigbyname("test", &kv_list, &type);
35       assert_int_equal(ret, EOK);
36       assert_int_equal(type, SSS_ID_TYPE_UID);
 1 @@ -0,0 +1,37 @@
 2 + /*
 3 +     Authors:
 4 +         Sumit Bose <sbose@redhat.com>
 5 + 
 6 +     Copyright (C) 2018 Red Hat
 7 + 
 8 +     Helper to make dlopen-tests pass for libsss_nss_idmap_tests.so.
 9 + 
10 +     This program is free software; you can redistribute it and/or modify
11 +     it under the terms of the GNU General Public License as published by
12 +     the Free Software Foundation; either version 3 of the License, or
13 +     (at your option) any later version.
14 + 
15 +     This program is distributed in the hope that it will be useful,
16 +     but WITHOUT ANY WARRANTY; without even the implied warranty of
17 +     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 +     GNU General Public License for more details.
19 + 
20 +     You should have received a copy of the GNU General Public License
21 +     along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 + */
23 + 
24 + #include <stdint.h>
25 + #include <unistd.h>
26 + #include <nss.h>
27 + 
28 + #include "sss_client/sss_cli.h"
29 + 
30 + enum nss_status __wrap_sss_nss_make_request_timeout(enum sss_cli_command cmd,
31 +                                                     struct sss_cli_req_data *rd,
32 +                                                     int timeout,
33 +                                                     uint8_t **repbuf,
34 +                                                     size_t *replen,
35 +                                                     int *errnop)
36 + {
37 +     return NSS_STATUS_SUCCESS;
38 + }
 1 @@ -120,7 +120,8 @@
 2       /* for testing purposes */
 3       { "libdlopen_test_providers.so", { LIBPFX"libdlopen_test_providers.so",
 4                                          NULL } },
 5 -     { "libsss_nss_idmap_tests.so", { LIBPFX"libsss_nss_idmap_tests.so",
 6 +     { "libsss_nss_idmap_tests.so", { LIBPFX"libdlopen_test_providers.so",
 7 +                                      LIBPFX"libsss_nss_idmap_tests.so",
 8                                        NULL } },
 9   #ifdef BUILD_SAMBA
10       { "libdlopen_test_winbind_idmap.so",