LCOV - code coverage report
Current view: top level - tests/cmocka - test_sysdb_views.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 501 506 99.0 %
Date: 2015-10-19 Functions: 33 33 100.0 %

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     sysdb_views - Tests for view and override related sysdb calls
       5             : 
       6             :     Authors:
       7             :         Sumit Bose <sbose@redhat.com>
       8             : 
       9             :     Copyright (C) 2014 Red Hat
      10             : 
      11             :     This program is free software; you can redistribute it and/or modify
      12             :     it under the terms of the GNU General Public License as published by
      13             :     the Free Software Foundation; either version 3 of the License, or
      14             :     (at your option) any later version.
      15             : 
      16             :     This program is distributed in the hope that it will be useful,
      17             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :     GNU General Public License for more details.
      20             : 
      21             :     You should have received a copy of the GNU General Public License
      22             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include <stdarg.h>
      26             : #include <stddef.h>
      27             : #include <setjmp.h>
      28             : #include <cmocka.h>
      29             : #include <popt.h>
      30             : 
      31             : #include "tests/cmocka/common_mock.h"
      32             : #include "providers/ipa/ipa_id.h"
      33             : #include "db/sysdb_private.h" /* for sysdb->ldb member */
      34             : 
      35             : #define TESTS_PATH "tp_" BASE_FILE_STEM
      36             : #define TEST_CONF_FILE "tests_conf.ldb"
      37             : 
      38             : #define TEST_ANCHOR_PREFIX ":ANCHOR:"
      39             : #define TEST_VIEW_NAME "test view"
      40             : #define TEST_VIEW_CONTAINER "cn=" TEST_VIEW_NAME ",cn=views,cn=sysdb"
      41             : #define TEST_USER_NAME "test_user"
      42             : #define TEST_USER_UID 1234
      43             : #define TEST_USER_GID 5678
      44             : #define TEST_USER_GECOS "Gecos field"
      45             : #define TEST_USER_HOMEDIR "/home/home"
      46             : #define TEST_USER_SHELL "/bin/shell"
      47             : #define TEST_USER_SID "S-1-2-3-4"
      48             : #define TEST_GID_OVERRIDE_BASE 100
      49             : 
      50             : struct sysdb_test_ctx {
      51             :     struct sysdb_ctx *sysdb;
      52             :     struct confdb_ctx *confdb;
      53             :     struct tevent_context *ev;
      54             :     struct sss_domain_info *domain;
      55             : };
      56             : 
      57          15 : static int _setup_sysdb_tests(struct sysdb_test_ctx **ctx, bool enumerate)
      58             : {
      59             :     struct sysdb_test_ctx *test_ctx;
      60             :     char *conf_db;
      61             :     int ret;
      62             : 
      63             :     const char *val[2];
      64          15 :     val[1] = NULL;
      65             : 
      66             :     /* Create tests directory if it doesn't exist */
      67             :     /* (relative to current dir) */
      68          15 :     ret = mkdir(TESTS_PATH, 0775);
      69          15 :     assert_true(ret == 0 || errno == EEXIST);
      70             : 
      71          15 :     test_ctx = talloc_zero(global_talloc_context, struct sysdb_test_ctx);
      72          15 :     assert_non_null(test_ctx);
      73             : 
      74             :     /* Create an event context
      75             :      * It will not be used except in confdb_init and sysdb_init
      76             :      */
      77          15 :     test_ctx->ev = tevent_context_init(test_ctx);
      78          15 :     assert_non_null(test_ctx->ev);
      79             : 
      80          15 :     conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
      81          15 :     assert_non_null(conf_db);
      82          15 :     DEBUG(SSSDBG_MINOR_FAILURE, "CONFDB: %s\n", conf_db);
      83             : 
      84             :     /* Connect to the conf db */
      85          15 :     ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
      86          15 :     assert_int_equal(ret, EOK);
      87             : 
      88          15 :     val[0] = "LOCAL";
      89          15 :     ret = confdb_add_param(test_ctx->confdb, true,
      90             :                            "config/sssd", "domains", val);
      91          15 :     assert_int_equal(ret, EOK);
      92             : 
      93          15 :     val[0] = "local";
      94          15 :     ret = confdb_add_param(test_ctx->confdb, true,
      95             :                            "config/domain/LOCAL", "id_provider", val);
      96          15 :     assert_int_equal(ret, EOK);
      97             : 
      98          15 :     val[0] = enumerate ? "TRUE" : "FALSE";
      99          15 :     ret = confdb_add_param(test_ctx->confdb, true,
     100             :                            "config/domain/LOCAL", "enumerate", val);
     101          15 :     assert_int_equal(ret, EOK);
     102             : 
     103          15 :     val[0] = "TRUE";
     104          15 :     ret = confdb_add_param(test_ctx->confdb, true,
     105             :                            "config/domain/LOCAL", "cache_credentials", val);
     106          15 :     assert_int_equal(ret, EOK);
     107             : 
     108          15 :     ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
     109             :                            TESTS_PATH, &test_ctx->domain);
     110          15 :     assert_int_equal(ret, EOK);
     111             : 
     112          15 :     test_ctx->domain->has_views = true;
     113          15 :     test_ctx->sysdb = test_ctx->domain->sysdb;
     114             : 
     115          15 :     *ctx = test_ctx;
     116          15 :     return EOK;
     117             : }
     118             : 
     119             : #define setup_sysdb_tests(ctx) _setup_sysdb_tests((ctx), false)
     120             : #define setup_sysdb_enum_tests(ctx) _setup_sysdb_tests((ctx), true)
     121             : 
     122           7 : static int test_sysdb_setup(void **state)
     123             : {
     124             :     int ret;
     125             :     struct sysdb_test_ctx *test_ctx;
     126             : 
     127           7 :     assert_true(leak_check_setup());
     128             : 
     129           7 :     ret = setup_sysdb_tests(&test_ctx);
     130           7 :     assert_int_equal(ret, EOK);
     131             : 
     132           7 :     *state = (void *) test_ctx;
     133           7 :     return 0;
     134             : }
     135             : 
     136          15 : static int test_sysdb_teardown(void **state)
     137             : {
     138          15 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     139             :                                                          struct sysdb_test_ctx);
     140             : 
     141          15 :     talloc_free(test_ctx);
     142          15 :     assert_true(leak_check_teardown());
     143          15 :     return 0;
     144             : }
     145             : 
     146           1 : static void test_sysdb_store_override(void **state)
     147             : {
     148             :     int ret;
     149             :     struct ldb_message *msg;
     150             :     struct ldb_message **msgs;
     151             :     struct sysdb_attrs *attrs;
     152             :     size_t count;
     153           1 :     const char override_dn_str[] = SYSDB_OVERRIDE_ANCHOR_UUID "=" \
     154             :                        TEST_ANCHOR_PREFIX TEST_USER_SID "," TEST_VIEW_CONTAINER;
     155             : 
     156           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     157             :                                                          struct sysdb_test_ctx);
     158             : 
     159           1 :     test_ctx->domain->mpg = false;
     160             : 
     161           1 :     ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
     162             :                            TEST_USER_UID, TEST_USER_GID, TEST_USER_GECOS,
     163             :                            TEST_USER_HOMEDIR, TEST_USER_SHELL, NULL, NULL, NULL,
     164             :                            0,0);
     165           1 :     assert_int_equal(ret, EOK);
     166             : 
     167           1 :     ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
     168             :                                     NULL, &msg);
     169           1 :     assert_int_equal(ret, EOK);
     170           1 :     assert_non_null(msg);
     171             : 
     172             :     /* No override exists */
     173           1 :     ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
     174           1 :                                SYSDB_MEMBER_USER, NULL, msg->dn);
     175           1 :     assert_int_equal(ret, EOK);
     176             : 
     177           1 :     ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb,msg->dn,
     178             :                              LDB_SCOPE_BASE, NULL, NULL, &count, &msgs);
     179           1 :     assert_int_equal(ret, EOK);
     180           1 :     assert_int_equal(count, 1);
     181           1 :     assert_string_equal(ldb_dn_get_linearized(msg->dn),
     182             :                         ldb_msg_find_attr_as_string(msgs[0],
     183             :                                                     SYSDB_OVERRIDE_DN, NULL));
     184             : 
     185           1 :     ret = sysdb_invalidate_overrides(test_ctx->domain->sysdb);
     186           1 :     assert_int_equal(ret, EOK);
     187             : 
     188           1 :     attrs = sysdb_new_attrs(test_ctx);
     189           1 :     assert_non_null(attrs);
     190             : 
     191             :     /* Missing anchor attribute */
     192           1 :     ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
     193           1 :                                SYSDB_MEMBER_USER, attrs, msg->dn);
     194           1 :     assert_int_equal(ret, EINVAL);
     195             : 
     196             :     /* With anchor */
     197           1 :     ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
     198             :                                  TEST_ANCHOR_PREFIX TEST_USER_SID);
     199           1 :     assert_int_equal(ret, EOK);
     200             : 
     201           1 :     ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
     202           1 :                                SYSDB_MEMBER_USER, attrs, msg->dn);
     203           1 :     assert_int_equal(ret, EOK);
     204             : 
     205           1 :     ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb,msg->dn,
     206             :                              LDB_SCOPE_BASE, NULL, NULL, &count, &msgs);
     207           1 :     assert_int_equal(ret, EOK);
     208           1 :     assert_int_equal(count, 1);
     209           1 :     assert_string_equal(override_dn_str, ldb_msg_find_attr_as_string(msgs[0],
     210             :                                                       SYSDB_OVERRIDE_DN, NULL));
     211             : 
     212           1 : }
     213             : 
     214           1 : void test_sysdb_add_overrides_to_object(void **state)
     215             : {
     216             :     int ret;
     217             :     struct ldb_message *orig;
     218             :     struct ldb_message *override;
     219             :     struct ldb_message_element *el;
     220             :     char *tmp_str;
     221           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     222             :                                                          struct sysdb_test_ctx);
     223             : 
     224           1 :     orig = ldb_msg_new(test_ctx);
     225           1 :     assert_non_null(orig);
     226             : 
     227           1 :     tmp_str = talloc_strdup(orig,  "ORIGNAME");
     228           1 :     assert_non_null(tmp_str);
     229           1 :     ret = ldb_msg_add_string(orig, SYSDB_NAME, tmp_str);
     230           1 :     assert_int_equal(ret, EOK);
     231             : 
     232           1 :     tmp_str = talloc_strdup(orig,  "ORIGGECOS");
     233           1 :     assert_non_null(tmp_str);
     234           1 :     ret = ldb_msg_add_string(orig, SYSDB_GECOS, tmp_str);
     235           1 :     assert_int_equal(ret, EOK);
     236             : 
     237           1 :     override = ldb_msg_new(test_ctx);
     238           1 :     assert_non_null(override);
     239             : 
     240           1 :     tmp_str = talloc_strdup(override, "OVERRIDENAME");
     241           1 :     assert_non_null(tmp_str);
     242           1 :     ret = ldb_msg_add_string(override, SYSDB_NAME, tmp_str);
     243           1 :     assert_int_equal(ret, EOK);
     244             : 
     245           1 :     tmp_str = talloc_strdup(override, "OVERRIDEGECOS");
     246           1 :     assert_non_null(tmp_str);
     247           1 :     ret = ldb_msg_add_string(override, SYSDB_GECOS, tmp_str);
     248           1 :     assert_int_equal(ret, EOK);
     249             : 
     250           1 :     tmp_str = talloc_strdup(override, "OVERRIDEKEY1");
     251           1 :     assert_non_null(tmp_str);
     252           1 :     ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
     253           1 :     assert_int_equal(ret, EOK);
     254             : 
     255           1 :     tmp_str = talloc_strdup(override, "OVERRIDEKEY2");
     256           1 :     assert_non_null(tmp_str);
     257           1 :     ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
     258           1 :     assert_int_equal(ret, EOK);
     259             : 
     260             : 
     261           1 :     ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, override, NULL);
     262           1 :     assert_int_equal(ret, EOK);
     263             : 
     264           1 :     assert_string_equal(ldb_msg_find_attr_as_string(orig, SYSDB_NAME, NULL),
     265             :                         "ORIGNAME");
     266           1 :     assert_string_equal(ldb_msg_find_attr_as_string(orig, SYSDB_GECOS, NULL),
     267             :                         "ORIGGECOS");
     268           1 :     assert_string_equal(ldb_msg_find_attr_as_string(orig,
     269             :                                                     OVERRIDE_PREFIX SYSDB_NAME,
     270             :                                                     NULL),
     271             :                         "OVERRIDENAME");
     272           1 :     assert_string_equal(ldb_msg_find_attr_as_string(orig,
     273             :                                                     OVERRIDE_PREFIX SYSDB_GECOS,
     274             :                                                     NULL),
     275             :                         "OVERRIDEGECOS");
     276             : 
     277           1 :     el = ldb_msg_find_element(orig, OVERRIDE_PREFIX SYSDB_SSH_PUBKEY);
     278           1 :     assert_non_null(el);
     279           1 :     assert_int_equal(el->num_values, 2);
     280           1 :     assert_int_equal(ldb_val_string_cmp(&el->values[0], "OVERRIDEKEY1"), 0);
     281           1 :     assert_int_equal(ldb_val_string_cmp(&el->values[1], "OVERRIDEKEY2"), 0);
     282           1 : }
     283             : 
     284           1 : void test_sysdb_add_overrides_to_object_local(void **state)
     285             : {
     286             :     int ret;
     287             :     struct ldb_message *orig;
     288             :     char *tmp_str;
     289           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     290             :                                                          struct sysdb_test_ctx);
     291             : 
     292           1 :     orig = ldb_msg_new(test_ctx);
     293           1 :     assert_non_null(orig);
     294             : 
     295           1 :     tmp_str = talloc_strdup(orig,  "ORIGNAME");
     296           1 :     assert_non_null(tmp_str);
     297           1 :     ret = ldb_msg_add_string(orig, SYSDB_NAME, tmp_str);
     298           1 :     assert_int_equal(ret, EOK);
     299             : 
     300           1 :     tmp_str = talloc_strdup(orig,  "ORIGGECOS");
     301           1 :     assert_non_null(tmp_str);
     302           1 :     ret = ldb_msg_add_string(orig, SYSDB_GECOS, tmp_str);
     303           1 :     assert_int_equal(ret, EOK);
     304             : 
     305           1 :     test_ctx->domain->has_views = true;
     306           1 :     test_ctx->domain->view_name = "LOCAL";
     307             : 
     308           1 :     ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, NULL, NULL);
     309           1 :     assert_int_equal(ret, EOK);
     310           1 : }
     311             : 
     312           1 : void test_sysdb_add_overrides_to_object_missing_overridedn(void **state)
     313             : {
     314             :     int ret;
     315             :     struct ldb_message *orig;
     316             :     char *tmp_str;
     317           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     318             :                                                          struct sysdb_test_ctx);
     319             : 
     320           1 :     orig = ldb_msg_new(test_ctx);
     321           1 :     assert_non_null(orig);
     322             : 
     323           1 :     orig->dn = ldb_dn_new(orig, test_ctx->domain->sysdb->ldb,
     324             :                           "cn=somedn,dc=example,dc=com");
     325           1 :     assert_non_null(orig->dn);
     326             : 
     327           1 :     tmp_str = talloc_strdup(orig,  "ORIGNAME");
     328           1 :     assert_non_null(tmp_str);
     329           1 :     ret = ldb_msg_add_string(orig, SYSDB_NAME, tmp_str);
     330           1 :     assert_int_equal(ret, EOK);
     331             : 
     332           1 :     tmp_str = talloc_strdup(orig,  "ORIGGECOS");
     333           1 :     assert_non_null(tmp_str);
     334           1 :     ret = ldb_msg_add_string(orig, SYSDB_GECOS, tmp_str);
     335           1 :     assert_int_equal(ret, EOK);
     336             : 
     337           1 :     test_ctx->domain->has_views = true;
     338           1 :     test_ctx->domain->view_name = "NON-LOCAL";
     339             : 
     340           1 :     ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, NULL, NULL);
     341           1 :     assert_int_equal(ret, ENOENT);
     342           1 : }
     343             : 
     344           1 : void test_split_ipa_anchor(void **state)
     345             : {
     346             :     int ret;
     347             :     char *dom;
     348             :     char *uuid;
     349           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     350             :                                                          struct sysdb_test_ctx);
     351             : 
     352           1 :     ret = split_ipa_anchor(test_ctx, NULL, &dom, &uuid);
     353           1 :     assert_int_equal(ret, EINVAL);
     354             : 
     355           1 :     ret = split_ipa_anchor(test_ctx, "fwfkwjfkw", &dom, &uuid);
     356           1 :     assert_int_equal(ret, ENOMSG);
     357             : 
     358           1 :     ret = split_ipa_anchor(test_ctx, ":IPA:", &dom, &uuid);
     359           1 :     assert_int_equal(ret, EINVAL);
     360             : 
     361           1 :     ret = split_ipa_anchor(test_ctx, ":IPA:abc", &dom, &uuid);
     362           1 :     assert_int_equal(ret, EINVAL);
     363             : 
     364           1 :     ret = split_ipa_anchor(test_ctx, ":IPA:abc:", &dom, &uuid);
     365           1 :     assert_int_equal(ret, EINVAL);
     366             : 
     367           1 :     ret = split_ipa_anchor(test_ctx, ":IPA:abc:def", &dom, &uuid);
     368           1 :     assert_int_equal(ret, EOK);
     369           1 :     assert_string_equal(dom, "abc");
     370           1 :     assert_string_equal(uuid, "def");
     371           1 : }
     372             : 
     373           1 : void test_sysdb_delete_view_tree(void **state)
     374             : {
     375             :     int ret;
     376             :     struct ldb_message *msg;
     377           1 :     struct ldb_message **msgs = NULL;
     378             :     struct sysdb_attrs *attrs;
     379             :     size_t count;
     380             :     struct ldb_dn *views_dn;
     381             : 
     382           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     383             :                                                          struct sysdb_test_ctx);
     384             : 
     385           1 :     test_ctx->domain->mpg = false;
     386             : 
     387           1 :     ret = sysdb_update_view_name(test_ctx->domain->sysdb, TEST_VIEW_NAME);
     388           1 :     assert_int_equal(ret, EOK);
     389             : 
     390           1 :     ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
     391             :                            TEST_USER_UID, TEST_USER_GID, TEST_USER_GECOS,
     392             :                            TEST_USER_HOMEDIR, TEST_USER_SHELL, NULL, NULL, NULL,
     393             :                            0,0);
     394           1 :     assert_int_equal(ret, EOK);
     395             : 
     396           1 :     ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
     397             :                                     NULL, &msg);
     398           1 :     assert_int_equal(ret, EOK);
     399           1 :     assert_non_null(msg);
     400             : 
     401           1 :     attrs = sysdb_new_attrs(test_ctx);
     402           1 :     assert_non_null(attrs);
     403             : 
     404           1 :     ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
     405             :                                  TEST_ANCHOR_PREFIX TEST_USER_SID);
     406           1 :     assert_int_equal(ret, EOK);
     407             : 
     408           1 :     ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
     409           1 :                                SYSDB_MEMBER_USER, attrs, msg->dn);
     410           1 :     assert_int_equal(ret, EOK);
     411             : 
     412           1 :     views_dn = ldb_dn_new(test_ctx, test_ctx->domain->sysdb->ldb,
     413             :                           SYSDB_TMPL_VIEW_BASE);
     414           1 :     assert_non_null(views_dn);
     415             : 
     416           1 :     ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
     417             :                              LDB_SCOPE_SUBTREE, NULL, NULL, &count, &msgs);
     418           1 :     assert_int_equal(ret, EOK);
     419           1 :     assert_true(count > 1);
     420           1 :     assert_non_null(msgs);
     421             : 
     422           1 :     ret = sysdb_delete_view_tree(test_ctx->domain->sysdb, TEST_VIEW_NAME);
     423           1 :     assert_int_equal(ret, EOK);
     424             : 
     425           1 :     ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
     426             :                              LDB_SCOPE_SUBTREE, NULL, NULL, &count, &msgs);
     427           1 :     assert_int_equal(ret, EOK);
     428           1 :     assert_int_equal(count, 1);
     429           1 :     assert_true(ldb_dn_compare(views_dn, msgs[0]->dn) == 0);
     430             : 
     431           1 : }
     432             : 
     433           1 : void test_sysdb_invalidate_overrides(void **state)
     434             : {
     435             :     int ret;
     436             :     struct ldb_message *msg;
     437             :     struct sysdb_attrs *attrs;
     438             :     struct ldb_dn *views_dn;
     439           1 :     const char *user_attrs[] = { SYSDB_NAME,
     440             :                                  SYSDB_CACHE_EXPIRE,
     441             :                                  SYSDB_OVERRIDE_DN,
     442             :                                  NULL};
     443             : 
     444           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     445             :                                                          struct sysdb_test_ctx);
     446             : 
     447           1 :     test_ctx->domain->mpg = false;
     448             : 
     449           1 :     ret = sysdb_update_view_name(test_ctx->domain->sysdb, TEST_VIEW_NAME);
     450           1 :     assert_int_equal(ret, EOK);
     451             : 
     452           1 :     ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
     453             :                            TEST_USER_UID, TEST_USER_GID, TEST_USER_GECOS,
     454             :                            TEST_USER_HOMEDIR, TEST_USER_SHELL, NULL, NULL, NULL,
     455             :                            10,0);
     456           1 :     assert_int_equal(ret, EOK);
     457             : 
     458           1 :     ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
     459             :                                     NULL, &msg);
     460           1 :     assert_int_equal(ret, EOK);
     461           1 :     assert_non_null(msg);
     462             : 
     463           1 :     attrs = sysdb_new_attrs(test_ctx);
     464           1 :     assert_non_null(attrs);
     465             : 
     466           1 :     ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
     467             :                                  TEST_ANCHOR_PREFIX TEST_USER_SID);
     468           1 :     assert_int_equal(ret, EOK);
     469             : 
     470           1 :     ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
     471           1 :                                SYSDB_MEMBER_USER, attrs, msg->dn);
     472           1 :     assert_int_equal(ret, EOK);
     473             : 
     474           1 :     views_dn = ldb_dn_new(test_ctx, test_ctx->domain->sysdb->ldb,
     475             :                           SYSDB_TMPL_VIEW_BASE);
     476           1 :     assert_non_null(views_dn);
     477             : 
     478           1 :     ret = sysdb_delete_view_tree(test_ctx->domain->sysdb, TEST_VIEW_NAME);
     479           1 :     assert_int_equal(ret, EOK);
     480             : 
     481           1 :     ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
     482             :                                     user_attrs, &msg);
     483           1 :     assert_int_equal(ret, EOK);
     484           1 :     assert_non_null(msg);
     485           1 :     assert_true(ldb_msg_find_attr_as_uint64(msg, SYSDB_CACHE_EXPIRE, 0) > 1);
     486           1 :     assert_non_null(ldb_msg_find_attr_as_string(msg, SYSDB_OVERRIDE_DN, NULL));
     487             : 
     488           1 :     ret = sysdb_invalidate_overrides(test_ctx->domain->sysdb);
     489           1 :     assert_int_equal(ret, EOK);
     490             : 
     491           1 :     ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
     492             :                                     user_attrs, &msg);
     493           1 :     assert_int_equal(ret, EOK);
     494           1 :     assert_non_null(msg);
     495           1 :     assert_int_equal(ldb_msg_find_attr_as_uint64(msg, SYSDB_CACHE_EXPIRE, 0),
     496             :                      1);
     497           1 :     assert_null(ldb_msg_find_attr_as_string(msg, SYSDB_OVERRIDE_DN, NULL));
     498             : 
     499           1 :     ret = sysdb_delete_user(test_ctx->domain, TEST_USER_NAME, 0);
     500           1 :     assert_int_equal(ret, EOK);
     501           1 : }
     502             : 
     503             : static const char *users[] = { "alice", "bob", "barney", NULL };
     504             : 
     505          12 : static void enum_test_user_override(struct sysdb_test_ctx *test_ctx,
     506             :                                     const char *name)
     507             : {
     508             :     int ret;
     509             :     struct sysdb_attrs *attrs;
     510             :     struct ldb_dn *dn;
     511             :     TALLOC_CTX *tmp_ctx;
     512             :     const char *anchor;
     513             :     const char *override_gecos;
     514             : 
     515          12 :     tmp_ctx = talloc_new(test_ctx);
     516          12 :     assert_non_null(tmp_ctx);
     517             : 
     518          12 :     attrs = sysdb_new_attrs(tmp_ctx);
     519          12 :     assert_non_null(attrs);
     520             : 
     521          12 :     dn = sysdb_user_dn(tmp_ctx, test_ctx->domain, name);
     522          12 :     assert_non_null(dn);
     523             : 
     524          12 :     anchor = talloc_asprintf(tmp_ctx, "%s%s", TEST_ANCHOR_PREFIX, name);
     525          12 :     ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID, anchor);
     526          12 :     assert_int_equal(ret, EOK);
     527             : 
     528          12 :     override_gecos = talloc_asprintf(attrs, "%s_GECOS_OVERRIDE", name);
     529          12 :     ret = sysdb_attrs_add_string(attrs, SYSDB_GECOS, override_gecos);
     530          12 :     assert_int_equal(ret, EOK);
     531             : 
     532          12 :     ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
     533             :                                SYSDB_MEMBER_USER, attrs, dn);
     534          12 :     assert_int_equal(ret, EOK);
     535             : 
     536          12 :     talloc_free(tmp_ctx);
     537          12 : }
     538             : 
     539           4 : static void enum_test_add_users(struct sysdb_test_ctx *test_ctx,
     540             :                                 const char *usernames[])
     541             : {
     542             :     int i;
     543             :     int ret;
     544             :     struct sysdb_attrs *attrs;
     545             : 
     546          16 :     for (i = 0; usernames[i] != NULL; i++) {
     547          12 :         attrs = talloc(test_ctx, struct sysdb_attrs);
     548          12 :         assert_non_null(attrs);
     549             : 
     550          24 :         ret = sysdb_store_user(test_ctx->domain, usernames[i],
     551          12 :                                NULL, 0, 0, usernames[i], "/", "/bin/sh",
     552          12 :                                NULL, NULL, NULL, 1, 1234 + i);
     553          12 :         assert_int_equal(ret, EOK);
     554             : 
     555          12 :         enum_test_user_override(test_ctx, usernames[i]);
     556             : 
     557          12 :         talloc_free(attrs);
     558             :     }
     559           4 : }
     560             : 
     561           4 : static void enum_test_del_users(struct sss_domain_info *dom,
     562             :                                const char *usernames[])
     563             : {
     564             :     int i;
     565             :     int ret;
     566             : 
     567          16 :     for (i = 0; usernames[i] != NULL; i++) {
     568          12 :         ret = sysdb_delete_user(dom, usernames[i], 0);
     569          12 :         if (ret != EOK && ret != ENOENT) {
     570           0 :             fail();
     571             :         }
     572             :     }
     573           4 : }
     574             : 
     575           4 : static int test_enum_users_setup(void **state)
     576             : {
     577             :     int ret;
     578             :     struct sysdb_test_ctx *test_ctx;
     579             : 
     580           4 :     assert_true(leak_check_setup());
     581             : 
     582           4 :     ret = setup_sysdb_enum_tests(&test_ctx);
     583           4 :     assert_int_equal(ret, EOK);
     584             : 
     585           4 :     enum_test_add_users(test_ctx, users);
     586             : 
     587           4 :     *state = (void *) test_ctx;
     588           4 :     return 0;
     589             : }
     590             : 
     591          17 : static void assert_user_attrs(struct ldb_message *msg,
     592             :                               const char *name,
     593             :                               bool has_views)
     594             : {
     595             :     const char *str;
     596             : 
     597          17 :     str = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
     598          17 :     assert_string_equal(str, name);
     599          17 :     str = ldb_msg_find_attr_as_string(msg, SYSDB_GECOS, NULL);
     600          17 :     assert_string_equal(str, name);
     601             : 
     602          17 :     str = ldb_msg_find_attr_as_string(msg, OVERRIDE_PREFIX SYSDB_GECOS, NULL);
     603          17 :     if (has_views) {
     604             :         char *override;
     605             : 
     606          10 :         assert_non_null(str);
     607          10 :         override = talloc_asprintf(msg, "%s_GECOS_OVERRIDE", name);
     608          10 :         assert_non_null(override);
     609             : 
     610          10 :         assert_string_equal(str, override);
     611          10 :         talloc_free(override);
     612             :     } else {
     613           7 :         assert_null(str);
     614             :     }
     615          17 : }
     616             : 
     617           4 : static int test_enum_users_teardown(void **state)
     618             : {
     619           4 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     620             :                                                         struct sysdb_test_ctx);
     621             : 
     622           4 :     enum_test_del_users(test_ctx->domain, users);
     623           4 :     return test_sysdb_teardown(state);
     624             : }
     625             : 
     626           3 : static void check_enumpwent(int ret, struct ldb_result *res, bool views)
     627             : {
     628           3 :     assert_int_equal(ret, EOK);
     629           3 :     assert_int_equal(res->count, N_ELEMENTS(users)-1);
     630           3 :     assert_user_attrs(res->msgs[0], "barney", views);
     631           3 :     assert_user_attrs(res->msgs[1], "alice", views);
     632           3 :     assert_user_attrs(res->msgs[2], "bob", views);
     633           3 : }
     634             : 
     635           1 : static void test_sysdb_enumpwent(void **state)
     636             : {
     637             :     int ret;
     638           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     639             :                                                         struct sysdb_test_ctx);
     640             :     struct ldb_result *res;
     641             : 
     642           1 :     ret = sysdb_enumpwent(test_ctx, test_ctx->domain, &res);
     643           1 :     check_enumpwent(ret, res, false);
     644           1 : }
     645             : 
     646           1 : static void test_sysdb_enumpwent_views(void **state)
     647             : {
     648             :     int ret;
     649           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     650             :                                                         struct sysdb_test_ctx);
     651             :     struct ldb_result *res;
     652             : 
     653           1 :     ret = sysdb_enumpwent_with_views(test_ctx, test_ctx->domain, &res);
     654           1 :     check_enumpwent(ret, res, true);
     655           1 : }
     656             : 
     657           1 : static void test_sysdb_enumpwent_filter(void **state)
     658             : {
     659             :     int ret;
     660           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     661             :                                                         struct sysdb_test_ctx);
     662             :     struct ldb_result *res;
     663             :     char *addtl_filter;
     664             : 
     665           1 :     ret = sysdb_enumpwent_filter(test_ctx, test_ctx->domain, "a*", 0, &res);
     666           1 :     assert_int_equal(ret, EOK);
     667           1 :     assert_int_equal(res->count, 1);
     668           1 :     assert_user_attrs(res->msgs[0], "alice", false);
     669             : 
     670           1 :     ret = sysdb_enumpwent_filter(test_ctx, test_ctx->domain, "b*", 0, &res);
     671           1 :     assert_int_equal(ret, EOK);
     672           1 :     assert_int_equal(res->count, 2);
     673           1 :     assert_user_attrs(res->msgs[0], "barney", false);
     674           1 :     assert_user_attrs(res->msgs[1], "bob", false);
     675             : 
     676           1 :     ret = sysdb_enumpwent_filter(test_ctx, test_ctx->domain, "c*", 0, &res);
     677           1 :     assert_int_equal(ret, EOK);
     678           1 :     assert_int_equal(res->count, 0);
     679             : 
     680           1 :     ret = sysdb_enumpwent_filter(test_ctx, test_ctx->domain, "*", 0, &res);
     681           1 :     assert_int_equal(ret, EOK);
     682           1 :     assert_int_equal(res->count, N_ELEMENTS(users)-1);
     683             : 
     684             :     /* Test searching based on time as well */
     685           1 :     addtl_filter = talloc_asprintf(test_ctx, "(%s<=%d)",
     686             :                                    SYSDB_LAST_UPDATE, 1233);
     687           1 :     ret = sysdb_enumpwent_filter(test_ctx, test_ctx->domain, "a*", addtl_filter, &res);
     688           1 :     talloc_free(addtl_filter);
     689           1 :     assert_int_equal(ret, EOK);
     690           1 :     assert_int_equal(res->count, 0);
     691             : 
     692           1 :     addtl_filter = talloc_asprintf(test_ctx, "(%s<=%d)",
     693             :                                    SYSDB_LAST_UPDATE, 1234);
     694           1 :     ret = sysdb_enumpwent_filter(test_ctx, test_ctx->domain, "a*", addtl_filter, &res);
     695           1 :     talloc_free(addtl_filter);
     696           1 :     assert_int_equal(ret, EOK);
     697           1 :     assert_int_equal(res->count, 1);
     698           1 :     assert_user_attrs(res->msgs[0], "alice", false);
     699           1 : }
     700             : 
     701           1 : static void test_sysdb_enumpwent_filter_views(void **state)
     702             : {
     703             :     int ret;
     704           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     705             :                                                         struct sysdb_test_ctx);
     706             :     struct ldb_result *res;
     707             :     char *addtl_filter;
     708             : 
     709           1 :     ret = sysdb_enumpwent_filter_with_views(test_ctx, test_ctx->domain,
     710             :                                             "a*", NULL, &res);
     711           1 :     assert_int_equal(ret, EOK);
     712           1 :     assert_int_equal(res->count, 1);
     713           1 :     assert_user_attrs(res->msgs[0], "alice", true);
     714             : 
     715           1 :     ret = sysdb_enumpwent_filter_with_views(test_ctx, test_ctx->domain,
     716             :                                             "b*", NULL, &res);
     717           1 :     assert_int_equal(ret, EOK);
     718           1 :     assert_int_equal(res->count, 2);
     719           1 :     assert_user_attrs(res->msgs[0], "barney", true);
     720           1 :     assert_user_attrs(res->msgs[1], "bob", true);
     721             : 
     722           1 :     addtl_filter = talloc_asprintf(test_ctx, "(%s<=%d)",
     723             :                                    SYSDB_LAST_UPDATE, 1235);
     724           1 :     ret = sysdb_enumpwent_filter_with_views(test_ctx, test_ctx->domain,
     725             :                                             "b*", addtl_filter, &res);
     726           1 :     talloc_free(addtl_filter);
     727           1 :     assert_int_equal(ret, EOK);
     728           1 :     assert_int_equal(res->count, 1);
     729           1 :     assert_user_attrs(res->msgs[0], "bob", true);
     730             : 
     731           1 :     ret = sysdb_enumpwent_filter_with_views(test_ctx,
     732             :                                             test_ctx->domain, "c*", NULL, &res);
     733           1 :     assert_int_equal(ret, EOK);
     734           1 :     assert_int_equal(res->count, 0);
     735             : 
     736           1 :     ret = sysdb_enumpwent_filter_with_views(test_ctx,
     737             :                                             test_ctx->domain, "*", NULL, &res);
     738           1 :     check_enumpwent(ret, res, true);
     739           1 : }
     740             : 
     741             : static const char *groups[] = { "one", "two", "three", NULL };
     742             : 
     743          12 : static void enum_test_group_override(struct sysdb_test_ctx *test_ctx,
     744             :                                      const char *name,
     745             :                                      unsigned override_gid)
     746             : {
     747             :     int ret;
     748             :     struct sysdb_attrs *attrs;
     749             :     struct ldb_dn *dn;
     750             :     TALLOC_CTX *tmp_ctx;
     751             :     const char *anchor;
     752             : 
     753          12 :     tmp_ctx = talloc_new(test_ctx);
     754          12 :     assert_non_null(tmp_ctx);
     755             : 
     756          12 :     attrs = sysdb_new_attrs(tmp_ctx);
     757          12 :     assert_non_null(attrs);
     758             : 
     759          12 :     dn = sysdb_group_dn(tmp_ctx, test_ctx->domain, name);
     760          12 :     assert_non_null(dn);
     761             : 
     762          12 :     anchor = talloc_asprintf(tmp_ctx, "%s%s", TEST_ANCHOR_PREFIX, name);
     763          12 :     ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID, anchor);
     764          12 :     assert_int_equal(ret, EOK);
     765             : 
     766          12 :     ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, override_gid);
     767          12 :     assert_int_equal(ret, EOK);
     768             : 
     769          12 :     ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
     770             :                                SYSDB_MEMBER_GROUP, attrs, dn);
     771          12 :     assert_int_equal(ret, EOK);
     772             : 
     773          12 :     talloc_free(tmp_ctx);
     774          12 : }
     775             : 
     776           4 : static void enum_test_add_groups(struct sysdb_test_ctx *test_ctx,
     777             :                                  const char *groupnames[])
     778             : {
     779             :     int i;
     780             :     int ret;
     781             :     struct sysdb_attrs *attrs;
     782             : 
     783          16 :     for (i = 0; groupnames[i] != NULL; i++) {
     784          12 :         attrs = talloc(test_ctx, struct sysdb_attrs);
     785          12 :         assert_non_null(attrs);
     786             : 
     787          12 :         ret = sysdb_store_group(test_ctx->domain, groupnames[i],
     788          12 :                                 0, NULL, 1, 1234 + i);
     789          12 :         assert_int_equal(ret, EOK);
     790             : 
     791          12 :         enum_test_group_override(test_ctx, groupnames[i],
     792          12 :                                  TEST_GID_OVERRIDE_BASE + i);
     793          12 :         talloc_free(attrs);
     794             :     }
     795           4 : }
     796             : 
     797           4 : static void enum_test_del_groups(struct sss_domain_info *dom,
     798             :                                  const char *groupnames[])
     799             : {
     800             :     int i;
     801             :     int ret;
     802             : 
     803          16 :     for (i = 0; groupnames[i] != NULL; i++) {
     804          12 :         ret = sysdb_delete_group(dom, groupnames[i], 0);
     805          12 :         if (ret != EOK && ret != ENOENT) {
     806           0 :             fail();
     807             :         }
     808             :     }
     809           4 : }
     810             : 
     811           4 : static int test_enum_groups_setup(void **state)
     812             : {
     813             :     int ret;
     814             :     struct sysdb_test_ctx *test_ctx;
     815             : 
     816           4 :     assert_true(leak_check_setup());
     817             : 
     818           4 :     ret = setup_sysdb_enum_tests(&test_ctx);
     819           4 :     assert_int_equal(ret, EOK);
     820             : 
     821           4 :     enum_test_add_groups(test_ctx, groups);
     822             : 
     823           4 :     *state = (void *) test_ctx;
     824           4 :     return 0;
     825             : }
     826             : 
     827           4 : static int test_enum_groups_teardown(void **state)
     828             : {
     829           4 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     830             :                                                         struct sysdb_test_ctx);
     831             : 
     832           4 :     enum_test_del_groups(test_ctx->domain, groups);
     833           4 :     return test_sysdb_teardown(state);
     834             : }
     835             : 
     836          20 : static void assert_group_attrs(struct ldb_message *msg,
     837             :                                const char *name,
     838             :                                unsigned expected_override_gid)
     839             : {
     840             :     const char *str;
     841             :     unsigned gid;
     842             : 
     843          20 :     str = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
     844          20 :     assert_string_equal(str, name);
     845             : 
     846          20 :     if (expected_override_gid) {
     847          10 :         gid = ldb_msg_find_attr_as_uint64(msg,
     848             :                                           OVERRIDE_PREFIX SYSDB_GIDNUM, 0);
     849          10 :         assert_int_equal(gid, expected_override_gid);
     850             :     }
     851          20 : }
     852             : 
     853           4 : static void check_enumgrent(int ret, struct ldb_result *res, bool views)
     854             : {
     855           4 :     assert_int_equal(ret, EOK);
     856           4 :     assert_int_equal(res->count, N_ELEMENTS(groups)-1);
     857           4 :     assert_group_attrs(res->msgs[0], "three", views ? TEST_GID_OVERRIDE_BASE + 2 : 0);
     858           4 :     assert_group_attrs(res->msgs[1], "one", views ? TEST_GID_OVERRIDE_BASE : 0);
     859           4 :     assert_group_attrs(res->msgs[2], "two", views ? TEST_GID_OVERRIDE_BASE + 1 : 0);
     860           4 : }
     861             : 
     862           1 : static void test_sysdb_enumgrent(void **state)
     863             : {
     864             :     int ret;
     865           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     866             :                                                         struct sysdb_test_ctx);
     867             :     struct ldb_result *res;
     868             : 
     869           1 :     ret = sysdb_enumgrent(test_ctx, test_ctx->domain, &res);
     870           1 :     check_enumgrent(ret, res, false);
     871           1 : }
     872             : 
     873           1 : static void test_sysdb_enumgrent_views(void **state)
     874             : {
     875             :     int ret;
     876           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     877             :                                                         struct sysdb_test_ctx);
     878             :     struct ldb_result *res;
     879             : 
     880           1 :     ret = sysdb_enumgrent_with_views(test_ctx, test_ctx->domain, &res);
     881           1 :     check_enumgrent(ret, res, true);
     882           1 : }
     883             : 
     884           1 : static void test_sysdb_enumgrent_filter(void **state)
     885             : {
     886             :     int ret;
     887           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     888             :                                                         struct sysdb_test_ctx);
     889             :     struct ldb_result *res;
     890             :     char *addtl_filter;
     891             : 
     892           1 :     ret = sysdb_enumgrent_filter(test_ctx, test_ctx->domain, "o*", 0, &res);
     893           1 :     assert_int_equal(ret, EOK);
     894           1 :     assert_int_equal(res->count, 1);
     895           1 :     assert_group_attrs(res->msgs[0], "one", 0);
     896             : 
     897           1 :     ret = sysdb_enumgrent_filter(test_ctx, test_ctx->domain, "t*", 0, &res);
     898           1 :     assert_int_equal(ret, EOK);
     899           1 :     assert_int_equal(res->count, 2);
     900           1 :     assert_group_attrs(res->msgs[0], "three", 0);
     901           1 :     assert_group_attrs(res->msgs[1], "two", 0);
     902             : 
     903           1 :     ret = sysdb_enumgrent_filter(test_ctx, test_ctx->domain, "x*", 0, &res);
     904           1 :     assert_int_equal(ret, EOK);
     905           1 :     assert_int_equal(res->count, 0);
     906             : 
     907           1 :     ret = sysdb_enumgrent_filter(test_ctx, test_ctx->domain, "*", 0, &res);
     908           1 :     check_enumgrent(ret, res, false);
     909             : 
     910           1 :     addtl_filter = talloc_asprintf(test_ctx, "(%s<=%d)",
     911             :                                    SYSDB_LAST_UPDATE, 1233);
     912           1 :     ret = sysdb_enumgrent_filter(test_ctx, test_ctx->domain, "o*", addtl_filter, &res);
     913           1 :     talloc_free(addtl_filter);
     914           1 :     assert_int_equal(ret, EOK);
     915           1 :     assert_int_equal(res->count, 0);
     916             : 
     917           1 :     addtl_filter = talloc_asprintf(test_ctx, "(%s<=%d)",
     918             :                                    SYSDB_LAST_UPDATE, 1234);
     919           1 :     ret = sysdb_enumgrent_filter(test_ctx, test_ctx->domain, "o*", addtl_filter, &res);
     920           1 :     talloc_free(addtl_filter);
     921           1 :     assert_int_equal(ret, EOK);
     922           1 :     assert_int_equal(res->count, 1);
     923           1 :     assert_group_attrs(res->msgs[0], "one", 0);
     924             : 
     925           1 : }
     926             : 
     927           1 : static void test_sysdb_enumgrent_filter_views(void **state)
     928             : {
     929             :     int ret;
     930           1 :     struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
     931             :                                                         struct sysdb_test_ctx);
     932             :     struct ldb_result *res;
     933             :     char *addtl_filter;
     934             : 
     935           1 :     ret = sysdb_enumgrent_filter_with_views(test_ctx, test_ctx->domain,
     936             :                                             "o*", NULL, &res);
     937           1 :     assert_int_equal(ret, EOK);
     938           1 :     assert_int_equal(res->count, 1);
     939           1 :     assert_group_attrs(res->msgs[0], "one", TEST_GID_OVERRIDE_BASE);
     940             : 
     941           1 :     ret = sysdb_enumgrent_filter_with_views(test_ctx, test_ctx->domain,
     942             :                                             "t*", NULL, &res);
     943           1 :     assert_int_equal(ret, EOK);
     944           1 :     assert_int_equal(res->count, 2);
     945           1 :     assert_group_attrs(res->msgs[0], "three", TEST_GID_OVERRIDE_BASE + 2);
     946           1 :     assert_group_attrs(res->msgs[1], "two", TEST_GID_OVERRIDE_BASE + 1);
     947             : 
     948           1 :     addtl_filter = talloc_asprintf(test_ctx, "(%s<=%d)",
     949             :                                    SYSDB_LAST_UPDATE, 1235);
     950           1 :     ret = sysdb_enumgrent_filter_with_views(test_ctx, test_ctx->domain,
     951             :                                             "t*", addtl_filter, &res);
     952           1 :     talloc_free(addtl_filter);
     953           1 :     assert_int_equal(ret, EOK);
     954           1 :     assert_int_equal(res->count, 1);
     955           1 :     assert_group_attrs(res->msgs[0], "two", TEST_GID_OVERRIDE_BASE + 1);
     956             : 
     957           1 :     ret = sysdb_enumgrent_filter_with_views(test_ctx, test_ctx->domain,
     958             :                                             "x*", NULL, &res);
     959           1 :     assert_int_equal(ret, EOK);
     960           1 :     assert_int_equal(res->count, 0);
     961             : 
     962           1 :     ret = sysdb_enumgrent_filter_with_views(test_ctx, test_ctx->domain,
     963             :                                             "*", NULL, &res);
     964           1 :     check_enumgrent(ret, res, true);
     965           1 : }
     966             : 
     967           1 : int main(int argc, const char *argv[])
     968             : {
     969             :     int rv;
     970           1 :     int no_cleanup = 0;
     971             :     poptContext pc;
     972             :     int opt;
     973           7 :     struct poptOption long_options[] = {
     974             :         POPT_AUTOHELP
     975           5 :         SSSD_DEBUG_OPTS
     976             :         {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
     977           1 :          _("Do not delete the test database after a test run"), NULL },
     978             :         POPT_TABLEEND
     979             :     };
     980             : 
     981           1 :     const struct CMUnitTest tests[] = {
     982             :         cmocka_unit_test_setup_teardown(test_sysdb_store_override,
     983             :                                         test_sysdb_setup, test_sysdb_teardown),
     984             :         cmocka_unit_test_setup_teardown(test_sysdb_add_overrides_to_object,
     985             :                                         test_sysdb_setup, test_sysdb_teardown),
     986             :         cmocka_unit_test_setup_teardown(test_sysdb_add_overrides_to_object_local,
     987             :                                         test_sysdb_setup, test_sysdb_teardown),
     988             :         cmocka_unit_test_setup_teardown(test_sysdb_add_overrides_to_object_missing_overridedn,
     989             :                                         test_sysdb_setup, test_sysdb_teardown),
     990             :         cmocka_unit_test_setup_teardown(test_split_ipa_anchor,
     991             :                                         test_sysdb_setup, test_sysdb_teardown),
     992             :         cmocka_unit_test_setup_teardown(test_sysdb_delete_view_tree,
     993             :                                         test_sysdb_setup, test_sysdb_teardown),
     994             :         cmocka_unit_test_setup_teardown(test_sysdb_invalidate_overrides,
     995             :                                         test_sysdb_setup, test_sysdb_teardown),
     996             :         cmocka_unit_test_setup_teardown(test_sysdb_enumpwent,
     997             :                                         test_enum_users_setup,
     998             :                                         test_enum_users_teardown),
     999             :         cmocka_unit_test_setup_teardown(test_sysdb_enumpwent_views,
    1000             :                                         test_enum_users_setup,
    1001             :                                         test_enum_users_teardown),
    1002             :         cmocka_unit_test_setup_teardown(test_sysdb_enumpwent_filter,
    1003             :                                         test_enum_users_setup,
    1004             :                                         test_enum_users_teardown),
    1005             :         cmocka_unit_test_setup_teardown(test_sysdb_enumpwent_filter_views,
    1006             :                                         test_enum_users_setup,
    1007             :                                         test_enum_users_teardown),
    1008             :         cmocka_unit_test_setup_teardown(test_sysdb_enumgrent,
    1009             :                                         test_enum_groups_setup,
    1010             :                                         test_enum_groups_teardown),
    1011             :         cmocka_unit_test_setup_teardown(test_sysdb_enumgrent_views,
    1012             :                                         test_enum_groups_setup,
    1013             :                                         test_enum_groups_teardown),
    1014             :         cmocka_unit_test_setup_teardown(test_sysdb_enumgrent_filter,
    1015             :                                         test_enum_groups_setup,
    1016             :                                         test_enum_groups_teardown),
    1017             :         cmocka_unit_test_setup_teardown(test_sysdb_enumgrent_filter_views,
    1018             :                                         test_enum_groups_setup,
    1019             :                                         test_enum_groups_teardown),
    1020             :     };
    1021             : 
    1022             :     /* Set debug level to invalid value so we can deside if -d 0 was used. */
    1023           1 :     debug_level = SSSDBG_INVALID;
    1024             : 
    1025           1 :     pc = poptGetContext(argv[0], argc, argv, long_options, 0);
    1026           1 :     while((opt = poptGetNextOpt(pc)) != -1) {
    1027             :         switch(opt) {
    1028             :         default:
    1029           0 :             fprintf(stderr, "\nInvalid option %s: %s\n\n",
    1030             :                     poptBadOption(pc, 0), poptStrerror(opt));
    1031           0 :             poptPrintUsage(pc, stderr, 0);
    1032           0 :             return 1;
    1033             :         }
    1034             :     }
    1035           1 :     poptFreeContext(pc);
    1036             : 
    1037           1 :     DEBUG_CLI_INIT(debug_level);
    1038             : 
    1039           1 :     tests_set_cwd();
    1040           1 :     test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_FILE, LOCAL_SYSDB_FILE);
    1041           1 :     test_dom_suite_setup(TESTS_PATH);
    1042           1 :     rv = cmocka_run_group_tests(tests, NULL, NULL);
    1043             : 
    1044           1 :     if (rv == 0 && no_cleanup == 0) {
    1045           1 :         test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_FILE, LOCAL_SYSDB_FILE);
    1046             :     }
    1047           1 :     return rv;
    1048             : }

Generated by: LCOV version 1.10