LCOV - code coverage report
Current view: top level - tests/cmocka - test_sysdb_subdomains.c (source / functions) Hit Total Coverage
Test: .coverage.total Lines: 217 220 98.6 %
Date: 2015-10-19 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     sysdb_subdomains - Tests for subdomains and related calls
       5             : 
       6             :     Authors:
       7             :         Jakub Hrozek <jhrozek@redhat.com>
       8             : 
       9             :     Copyright (C) 2015 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 "tests/common.h"
      33             : #include "db/sysdb_private.h" /* for sysdb->ldb member */
      34             : 
      35             : #define TESTS_PATH "tp_" BASE_FILE_STEM
      36             : #define TEST_CONF_DB "test_sysdb_subdomains.ldb"
      37             : 
      38             : #define TEST_DOM1_NAME "test_sysdb_subdomains_1"
      39             : 
      40             : #define TEST_FLAT_NAME "TEST_1"
      41             : #define TEST_SID    "S-1"
      42             : #define TEST_REALM "TEST_SYSDB_SUBDOMAINS"
      43             : #define TEST_FOREST TEST_REALM
      44             : #define TEST_ID_PROVIDER "ldap"
      45             : 
      46             : #define TEST_DOM2_NAME "child2.test_sysdb_subdomains_2"
      47             : #define TEST_FLAT_NAME2 "CHILD2"
      48             : #define TEST_SID2    "S-2"
      49             : #define TEST_REALM2 "TEST_SYSDB_SUBDOMAINS2"
      50             : #define TEST_FOREST2 TEST_REALM2
      51             : 
      52             : const char *domains[] = { TEST_DOM1_NAME,
      53             :                           TEST_DOM2_NAME,
      54             :                           NULL };
      55             : 
      56             : struct subdom_test_ctx {
      57             :     struct sss_test_ctx *tctx;
      58             : };
      59             : 
      60           6 : static int test_sysdb_subdom_setup(void **state)
      61             : {
      62             :     struct subdom_test_ctx *test_ctx;
      63           6 :     struct sss_test_conf_param params[] = {
      64             :         { NULL, NULL },             /* Sentinel */
      65             :     };
      66             : 
      67           6 :     assert_true(leak_check_setup());
      68             : 
      69           6 :     test_ctx = talloc_zero(global_talloc_context,
      70             :                            struct subdom_test_ctx);
      71           6 :     assert_non_null(test_ctx);
      72             : 
      73           6 :     test_dom_suite_setup(TESTS_PATH);
      74             : 
      75           6 :     test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
      76             :                                               TEST_CONF_DB, domains,
      77             :                                               TEST_ID_PROVIDER, params);
      78           6 :     assert_non_null(test_ctx->tctx);
      79             : 
      80           6 :     *state = test_ctx;
      81           6 :     return 0;
      82             : }
      83             : 
      84           6 : static int test_sysdb_subdom_teardown(void **state)
      85             : {
      86           6 :     struct subdom_test_ctx *test_ctx =
      87           6 :         talloc_get_type(*state, struct subdom_test_ctx);
      88             : 
      89           6 :     test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
      90           6 :     talloc_free(test_ctx);
      91           6 :     assert_true(leak_check_teardown());
      92           6 :     return 0;
      93             : }
      94             : 
      95           1 : static void test_sysdb_subdomain_create(void **state)
      96             : {
      97             :     errno_t ret;
      98           1 :     struct subdom_test_ctx *test_ctx =
      99           1 :         talloc_get_type(*state, struct subdom_test_ctx);
     100             : 
     101             :     const char *const dom1[4] = { "dom1.sub", "DOM1.SUB", "dom1", "S-1" };
     102             :     const char *const dom2[4] = { "dom2.sub", "DOM2.SUB", "dom2", "S-2" };
     103             : 
     104           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     105             :                                 dom1[0], dom1[1], dom1[2], dom1[3],
     106             :                                 false, false, NULL, 0);
     107           1 :     assert_int_equal(ret, EOK);
     108             : 
     109           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom);
     110           1 :     assert_int_equal(ret, EOK);
     111             : 
     112           1 :     assert_non_null(test_ctx->tctx->dom->subdomains);
     113           1 :     assert_string_equal(test_ctx->tctx->dom->subdomains->name, dom1[0]);
     114           1 :     assert_int_equal(test_ctx->tctx->dom->subdomains->trust_direction, 0);
     115             : 
     116           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     117             :                                 dom2[0], dom2[1], dom2[2], dom2[3],
     118             :                                 false, false, NULL, 1);
     119           1 :     assert_int_equal(ret, EOK);
     120             : 
     121           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom);
     122           1 :     assert_int_equal(ret, EOK);
     123             : 
     124           1 :     assert_non_null(test_ctx->tctx->dom->subdomains->next);
     125           1 :     assert_string_equal(test_ctx->tctx->dom->subdomains->next->name, dom2[0]);
     126           1 :     assert_int_equal(test_ctx->tctx->dom->subdomains->next->trust_direction, 1);
     127             : 
     128             :     /* Reverse the trust directions */
     129           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     130             :                                 dom1[0], dom1[1], dom1[2], dom1[3],
     131             :                                 false, false, NULL, 1);
     132           1 :     assert_int_equal(ret, EOK);
     133             : 
     134           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     135             :                                 dom2[0], dom2[1], dom2[2], dom2[3],
     136             :                                 false, false, NULL, 0);
     137           1 :     assert_int_equal(ret, EOK);
     138             : 
     139           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom);
     140           1 :     assert_int_equal(ret, EOK);
     141             : 
     142           1 :     assert_int_equal(test_ctx->tctx->dom->subdomains->trust_direction, 1);
     143           1 :     assert_int_equal(test_ctx->tctx->dom->subdomains->next->trust_direction, 0);
     144             : 
     145           1 :     ret = sysdb_subdomain_delete(test_ctx->tctx->sysdb, dom2[0]);
     146           1 :     assert_int_equal(ret, EOK);
     147             : 
     148           1 :     ret = sysdb_subdomain_delete(test_ctx->tctx->sysdb, dom1[0]);
     149           1 :     assert_int_equal(ret, EOK);
     150             : 
     151           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom);
     152           1 :     assert_int_equal(ret, EOK);
     153             : 
     154           1 :     assert_int_equal(sss_domain_get_state(test_ctx->tctx->dom->subdomains),
     155             :                      DOM_DISABLED);
     156           1 :     assert_int_equal(
     157             :             sss_domain_get_state(test_ctx->tctx->dom->subdomains->next),
     158             :             DOM_DISABLED);
     159           1 : }
     160             : 
     161           1 : static void test_sysdb_master_domain_ops(void **state)
     162             : {
     163             :     errno_t ret;
     164           1 :     struct subdom_test_ctx *test_ctx =
     165           1 :         talloc_get_type(*state, struct subdom_test_ctx);
     166             : 
     167           1 :     ret = sysdb_master_domain_add_info(test_ctx->tctx->dom,
     168             :                                        "realm1", "flat1", "id1", "forest1");
     169           1 :     assert_int_equal(ret, EOK);
     170             : 
     171           1 :     ret = sysdb_master_domain_update(test_ctx->tctx->dom);
     172           1 :     assert_int_equal(ret, EOK);
     173             : 
     174           1 :     assert_string_equal(test_ctx->tctx->dom->realm, "realm1");
     175           1 :     assert_string_equal(test_ctx->tctx->dom->flat_name, "flat1");
     176           1 :     assert_string_equal(test_ctx->tctx->dom->domain_id, "id1");
     177           1 :     assert_string_equal(test_ctx->tctx->dom->forest, "forest1");
     178             : 
     179           1 :     ret = sysdb_master_domain_add_info(test_ctx->tctx->dom,
     180             :                                        "realm2", "flat2", "id2", "forest2");
     181           1 :     assert_int_equal(ret, EOK);
     182             : 
     183           1 :     ret = sysdb_master_domain_update(test_ctx->tctx->dom);
     184           1 :     assert_int_equal(ret, EOK);
     185             : 
     186           1 :     assert_string_equal(test_ctx->tctx->dom->realm, "realm2");
     187           1 :     assert_string_equal(test_ctx->tctx->dom->flat_name, "flat2");
     188           1 :     assert_string_equal(test_ctx->tctx->dom->domain_id, "id2");
     189           1 :     assert_string_equal(test_ctx->tctx->dom->forest, "forest2");
     190           1 : }
     191             : 
     192             : /* Parent domain totally separate from subdomains that imitate
     193             :  * IPA domain and two forests
     194             :  */
     195           1 : static void test_sysdb_link_forest_root_ipa(void **state)
     196             : {
     197             :     errno_t ret;
     198           1 :     struct subdom_test_ctx *test_ctx =
     199           1 :         talloc_get_type(*state, struct subdom_test_ctx);
     200             :     struct sss_domain_info *main_dom;
     201             :     struct sss_domain_info *sub;
     202             :     struct sss_domain_info *child;
     203             : 
     204             :     /* name, realm, flat, SID, forest */
     205             :     const char *const dom1[5] = { "dom1.sub", "DOM1.SUB",
     206             :                                   "DOM1", "S-1", "DOM1.SUB" };
     207             :     const char *const child_dom1[5] = { "child1.dom1.sub", "CHILD1.DOM1.SUB",
     208             :                                         "CHILD1.DOM1", "S-1-2", "DOM1.SUB" };
     209             :     const char *const dom2[5] = { "dom2.sub", "DOM2.SUB",
     210             :                                   "DOM2", "S-2", "DOM2.SUB" };
     211             :     const char *const child_dom2[5] = { "child2.dom2.sub", "CHILD2.DOM1.SUB",
     212             :                                         "CHILD2.DOM1", "S-2-2", "DOM2.SUB" };
     213             : 
     214           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     215             :                                 dom1[0], dom1[1], dom1[2], dom1[3],
     216             :                                 false, false, dom1[4], 0);
     217           1 :     assert_int_equal(ret, EOK);
     218             : 
     219           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     220             :                                 child_dom1[0], child_dom1[1],
     221             :                                 child_dom1[2], child_dom1[3],
     222             :                                 false, false, child_dom1[4],
     223             :                                 0);
     224           1 :     assert_int_equal(ret, EOK);
     225             : 
     226           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     227             :                                 dom2[0], dom2[1], dom2[2], dom2[3],
     228             :                                 false, false, dom2[4],
     229             :                                 0);
     230           1 :     assert_int_equal(ret, EOK);
     231             : 
     232           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     233             :                                 child_dom2[0], child_dom2[1],
     234             :                                 child_dom2[2], child_dom2[3],
     235             :                                 false, false, child_dom2[4],
     236             :                                 0);
     237           1 :     assert_int_equal(ret, EOK);
     238             : 
     239           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom);
     240           1 :     assert_int_equal(ret, EOK);
     241             : 
     242             :     /* Also update dom2 */
     243           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom->next);
     244           1 :     assert_int_equal(ret, EOK);
     245             : 
     246           1 :     sub = find_domain_by_name(test_ctx->tctx->dom, dom1[0], true);
     247           1 :     assert_non_null(sub->forest_root);
     248           1 :     assert_true(sub->forest_root = sub);
     249             : 
     250           1 :     child = find_domain_by_name(test_ctx->tctx->dom, child_dom1[0], true);
     251           1 :     assert_non_null(child->forest_root);
     252           1 :     assert_true(child->forest_root = sub);
     253             : 
     254           1 :     sub = find_domain_by_name(test_ctx->tctx->dom, dom2[0], true);
     255           1 :     assert_non_null(sub->forest_root);
     256           1 :     assert_true(sub->forest_root = sub);
     257             : 
     258           1 :     child = find_domain_by_name(test_ctx->tctx->dom, child_dom2[0], true);
     259           1 :     assert_non_null(child->forest_root);
     260           1 :     assert_true(child->forest_root = sub);
     261             : 
     262           1 :     main_dom = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM1_NAME, true);
     263           1 :     assert_non_null(main_dom);
     264           1 :     assert_non_null(main_dom->forest_root);
     265           1 :     assert_true(main_dom->forest_root == main_dom);
     266             : 
     267           1 :     main_dom = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM2_NAME, true);
     268           1 :     assert_non_null(main_dom);
     269           1 :     assert_non_null(main_dom->forest_root);
     270           1 :     assert_true(main_dom->forest_root == main_dom);
     271           1 : }
     272             : 
     273             : /* Parent domain is an AD forest root and there are two subdomains
     274             :  * child and parallel
     275             :  */
     276           1 : static void test_sysdb_link_forest_root_ad(void **state)
     277             : {
     278             :     errno_t ret;
     279           1 :     struct subdom_test_ctx *test_ctx =
     280           1 :         talloc_get_type(*state, struct subdom_test_ctx);
     281             :     struct sss_domain_info *main_dom;
     282             :     struct sss_domain_info *sub;
     283             :     struct sss_domain_info *child;
     284             : 
     285             :     const char *const child_dom[5] = { "child.test_sysdb_subdomains",/* name  */
     286             :                                        "CHILD.TEST_SYSDB_SUBDOMAINS",/* realm */
     287             :                                        "CHILD",                      /* flat  */
     288             :                                        "S-1-2",                      /* sid   */
     289             :                                        TEST_FOREST };               /* forest */
     290             : 
     291             :     const char *const sub_dom[5] = { "another.subdomain",         /* name   */
     292             :                                      "ANOTHER.SUBDOMAIN",         /* realm  */
     293             :                                      "ANOTHER",                   /* flat   */
     294             :                                      "S-1-3",                     /* sid    */
     295             :                                      TEST_FOREST };               /* forest */
     296             : 
     297           1 :     ret = sysdb_master_domain_add_info(test_ctx->tctx->dom,
     298             :                                        TEST_REALM,
     299             :                                        TEST_FLAT_NAME,
     300             :                                        TEST_SID,
     301             :                                        TEST_FOREST);
     302           1 :     assert_int_equal(ret, EOK);
     303             : 
     304           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     305             :                                 child_dom[0], child_dom[1],
     306             :                                 child_dom[2], child_dom[3],
     307             :                                 false, false, child_dom[4],
     308             :                                 0);
     309           1 :     assert_int_equal(ret, EOK);
     310             : 
     311           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     312             :                                 sub_dom[0], sub_dom[1],
     313             :                                 sub_dom[2], sub_dom[3],
     314             :                                 false, false, sub_dom[4],
     315             :                                 0);
     316           1 :     assert_int_equal(ret, EOK);
     317             : 
     318           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom);
     319           1 :     assert_int_equal(ret, EOK);
     320             : 
     321             :     /* Also update dom2 */
     322           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom->next);
     323           1 :     assert_int_equal(ret, EOK);
     324             : 
     325           1 :     assert_non_null(test_ctx->tctx->dom->forest_root);
     326           1 :     assert_true(test_ctx->tctx->dom->forest_root == test_ctx->tctx->dom);
     327           1 :     assert_string_equal(test_ctx->tctx->dom->name, TEST_DOM1_NAME);
     328             : 
     329           1 :     child = find_domain_by_name(test_ctx->tctx->dom, child_dom[0], true);
     330           1 :     assert_non_null(child->forest_root);
     331           1 :     assert_true(child->forest_root = test_ctx->tctx->dom);
     332             : 
     333           1 :     sub = find_domain_by_name(test_ctx->tctx->dom, sub_dom[0], true);
     334           1 :     assert_non_null(sub->forest_root);
     335           1 :     assert_true(sub->forest_root = test_ctx->tctx->dom);
     336             : 
     337             :     /* Another separate domain is a forest of its own */
     338           1 :     main_dom = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM2_NAME, true);
     339           1 :     assert_non_null(main_dom);
     340           1 :     assert_non_null(main_dom->forest_root);
     341           1 :     assert_true(main_dom->forest_root == main_dom);
     342           1 : }
     343             : 
     344             : /* Parent domain is an AD member domain connected to a root domain
     345             :  */
     346           1 : static void test_sysdb_link_forest_member_ad(void **state)
     347             : {
     348             :     errno_t ret;
     349           1 :     struct subdom_test_ctx *test_ctx =
     350           1 :         talloc_get_type(*state, struct subdom_test_ctx);
     351             :     struct sss_domain_info *main_dom;
     352             :     struct sss_domain_info *sub;
     353             :     struct sss_domain_info *root;
     354             : 
     355           1 :     const char *const forest_root[5] = { test_ctx->tctx->dom->name, /* name  */
     356             :                                          TEST_FOREST,               /* realm */
     357             :                                          TEST_FLAT_NAME,            /* flat  */
     358             :                                          TEST_SID,                  /* sid   */
     359             :                                          TEST_FOREST };               /* forest */
     360             : 
     361             :     const char *const child_dom[5] = { "child.test_sysdb_subdomains",/* name  */
     362             :                                        "CHILD.TEST_SYSDB_SUBDOMAINS",/* realm */
     363             :                                        "CHILD",                      /* flat  */
     364             :                                        "S-1-2",                      /* sid   */
     365             :                                        TEST_FOREST };               /* forest */
     366             : 
     367             :     const char *const sub_dom[5] = { "another.subdomain",         /* name   */
     368             :                                      "ANOTHER.SUBDOMAIN",         /* realm  */
     369             :                                      "ANOTHER",                   /* flat   */
     370             :                                      "S-1-3",                     /* sid    */
     371             :                                      TEST_FOREST };               /* forest */
     372             : 
     373           1 :     ret = sysdb_master_domain_add_info(test_ctx->tctx->dom,
     374             :                                        child_dom[1],
     375             :                                        child_dom[2],
     376             :                                        child_dom[3],
     377             :                                        TEST_FOREST);
     378           1 :     assert_int_equal(ret, EOK);
     379             : 
     380           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     381             :                                 sub_dom[0], sub_dom[1],
     382             :                                 sub_dom[2], sub_dom[3],
     383             :                                 false, false, sub_dom[4],
     384             :                                 0);
     385           1 :     assert_int_equal(ret, EOK);
     386             : 
     387           1 :     ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
     388             :                                 forest_root[0], forest_root[1],
     389             :                                 forest_root[2], forest_root[3],
     390             :                                 false, false, forest_root[4],
     391             :                                 0);
     392           1 :     assert_int_equal(ret, EOK);
     393             : 
     394           1 :     ret = sysdb_master_domain_update(test_ctx->tctx->dom);
     395           1 :     assert_int_equal(ret, EOK);
     396             : 
     397           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom);
     398           1 :     assert_int_equal(ret, EOK);
     399             : 
     400             :     /* Also update dom2 */
     401           1 :     ret = sysdb_master_domain_update(test_ctx->tctx->dom->next);
     402           1 :     assert_int_equal(ret, EOK);
     403             : 
     404           1 :     ret = sysdb_update_subdomains(test_ctx->tctx->dom->next);
     405           1 :     assert_int_equal(ret, EOK);
     406             : 
     407             :     /* Checks */
     408           1 :     root = find_domain_by_name(test_ctx->tctx->dom, forest_root[0], true);
     409           1 :     assert_non_null(root->forest_root);
     410           1 :     assert_true(root->forest_root = root);
     411             : 
     412           1 :     assert_non_null(test_ctx->tctx->dom->forest_root);
     413           1 :     assert_true(test_ctx->tctx->dom->forest_root == root);
     414             : 
     415           1 :     sub = find_domain_by_name(test_ctx->tctx->dom, sub_dom[0], true);
     416           1 :     assert_non_null(sub->forest_root);
     417           1 :     assert_true(sub->forest_root = root);
     418             : 
     419             :     /* Another separate domain is a forest of its own */
     420           1 :     main_dom = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM2_NAME, true);
     421           1 :     assert_non_null(main_dom);
     422           1 :     assert_non_null(main_dom->forest_root);
     423           1 :     assert_true(main_dom->forest_root == main_dom);
     424           1 : }
     425             : 
     426             : 
     427             : /* Each parent domain has a subdomain. One parent domain is a root domain,
     428             :  * the other is not.
     429             :  */
     430           1 : static void test_sysdb_link_ad_multidom(void **state)
     431             : {
     432             :     errno_t ret;
     433           1 :     struct subdom_test_ctx *test_ctx =
     434           1 :         talloc_get_type(*state, struct subdom_test_ctx);
     435             :     struct sss_domain_info *main_dom1;
     436             :     struct sss_domain_info *main_dom2;
     437             :     struct sss_domain_info *root;
     438             : 
     439             :     const char *const child_dom[5] = { "child.test_sysdb_subdomains",/* name  */
     440             :                                        "CHILD.TEST_SYSDB_SUBDOMAINS",/* realm */
     441             :                                        "CHILD",                      /* flat  */
     442             :                                        "S-1-2",                      /* sid   */
     443             :                                        TEST_FOREST };               /* forest */
     444             : 
     445             :     const char *const dom2_forest_root[5] = \
     446             :                                   { "test_sysdb_subdomains_2", /* name  */
     447             :                                      TEST_FOREST2,             /* realm */
     448             :                                      "TEST2",                  /* flat  */
     449             :                                      TEST_SID2,                /* sid   */
     450             :                                      TEST_FOREST2 };           /* forest */
     451             : 
     452             : 
     453           1 :     main_dom1 = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM1_NAME, true);
     454           1 :     main_dom2 = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM2_NAME, true);
     455             : 
     456           1 :     ret = sysdb_master_domain_add_info(main_dom1,
     457             :                                        TEST_REALM,
     458             :                                        TEST_FLAT_NAME,
     459             :                                        TEST_SID,
     460             :                                        TEST_FOREST);
     461           1 :     assert_int_equal(ret, EOK);
     462             : 
     463           1 :     ret = sysdb_subdomain_store(main_dom1->sysdb,
     464             :                                 child_dom[0], child_dom[1],
     465             :                                 child_dom[2], child_dom[3],
     466             :                                 false, false, child_dom[4],
     467             :                                 0);
     468           1 :     assert_int_equal(ret, EOK);
     469             : 
     470           1 :     ret = sysdb_master_domain_update(main_dom1);
     471           1 :     assert_int_equal(ret, EOK);
     472             : 
     473           1 :     ret = sysdb_update_subdomains(main_dom1);
     474           1 :     assert_int_equal(ret, EOK);
     475             : 
     476           1 :     ret = sysdb_master_domain_add_info(main_dom2,
     477             :                                        TEST_REALM2,
     478             :                                        TEST_FLAT_NAME2,
     479             :                                        TEST_SID2,
     480             :                                        TEST_FOREST2);
     481           1 :     assert_int_equal(ret, EOK);
     482             : 
     483           1 :     ret = sysdb_subdomain_store(main_dom2->sysdb,
     484             :                                 dom2_forest_root[0], dom2_forest_root[1],
     485             :                                 dom2_forest_root[2], dom2_forest_root[3],
     486             :                                 false, false, dom2_forest_root[4], 0);
     487           1 :     assert_int_equal(ret, EOK);
     488             : 
     489           1 :     ret = sysdb_master_domain_update(main_dom2);
     490           1 :     assert_int_equal(ret, EOK);
     491             : 
     492           1 :     ret = sysdb_update_subdomains(main_dom2);
     493           1 :     assert_int_equal(ret, EOK);
     494             : 
     495           1 :     main_dom1 = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM1_NAME, true);
     496           1 :     assert_non_null(main_dom1);
     497           1 :     assert_non_null(main_dom1->forest_root);
     498           1 :     assert_true(main_dom1->forest_root == main_dom1);
     499             : 
     500           1 :     main_dom2 = find_domain_by_name(test_ctx->tctx->dom, TEST_DOM2_NAME, true);
     501           1 :     assert_non_null(main_dom1);
     502           1 :     assert_non_null(main_dom1->forest_root);
     503           1 :     assert_true(main_dom1->forest_root == main_dom1);
     504             : 
     505           1 :     root = find_domain_by_name(test_ctx->tctx->dom, dom2_forest_root[0], true);
     506           1 :     assert_non_null(root);
     507           1 :     assert_non_null(root->forest_root);
     508           1 :     assert_true(root->forest_root = main_dom2);
     509             : 
     510           1 : }
     511             : 
     512           1 : int main(int argc, const char *argv[])
     513             : {
     514             :     int rv;
     515           1 :     int no_cleanup = 0;
     516             :     poptContext pc;
     517             :     int opt;
     518           7 :     struct poptOption long_options[] = {
     519             :         POPT_AUTOHELP
     520           5 :         SSSD_DEBUG_OPTS
     521             :         {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
     522           1 :          _("Do not delete the test database after a test run"), NULL },
     523             :         POPT_TABLEEND
     524             :     };
     525             : 
     526           1 :     const struct CMUnitTest tests[] = {
     527             :         cmocka_unit_test_setup_teardown(test_sysdb_master_domain_ops,
     528             :                                         test_sysdb_subdom_setup,
     529             :                                         test_sysdb_subdom_teardown),
     530             :         cmocka_unit_test_setup_teardown(test_sysdb_subdomain_create,
     531             :                                         test_sysdb_subdom_setup,
     532             :                                         test_sysdb_subdom_teardown),
     533             :         cmocka_unit_test_setup_teardown(test_sysdb_link_forest_root_ipa,
     534             :                                         test_sysdb_subdom_setup,
     535             :                                         test_sysdb_subdom_teardown),
     536             :         cmocka_unit_test_setup_teardown(test_sysdb_link_forest_root_ad,
     537             :                                         test_sysdb_subdom_setup,
     538             :                                         test_sysdb_subdom_teardown),
     539             :         cmocka_unit_test_setup_teardown(test_sysdb_link_forest_member_ad,
     540             :                                         test_sysdb_subdom_setup,
     541             :                                         test_sysdb_subdom_teardown),
     542             :         cmocka_unit_test_setup_teardown(test_sysdb_link_ad_multidom,
     543             :                                         test_sysdb_subdom_setup,
     544             :                                         test_sysdb_subdom_teardown),
     545             :     };
     546             : 
     547             :     /* Set debug level to invalid value so we can deside if -d 0 was used. */
     548           1 :     debug_level = SSSDBG_INVALID;
     549             : 
     550           1 :     pc = poptGetContext(argv[0], argc, argv, long_options, 0);
     551           1 :     while((opt = poptGetNextOpt(pc)) != -1) {
     552             :         switch(opt) {
     553             :         default:
     554           0 :             fprintf(stderr, "\nInvalid option %s: %s\n\n",
     555             :                     poptBadOption(pc, 0), poptStrerror(opt));
     556           0 :             poptPrintUsage(pc, stderr, 0);
     557           0 :             return 1;
     558             :         }
     559             :     }
     560           1 :     poptFreeContext(pc);
     561             : 
     562           1 :     DEBUG_CLI_INIT(debug_level);
     563             : 
     564           1 :     tests_set_cwd();
     565           1 :     test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
     566           1 :     test_dom_suite_setup(TESTS_PATH);
     567           1 :     rv = cmocka_run_group_tests(tests, NULL, NULL);
     568             : 
     569           1 :     if (rv == 0 && no_cleanup == 0) {
     570           1 :         test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, LOCAL_SYSDB_FILE);
     571             :     }
     572           1 :     return rv;
     573             : }

Generated by: LCOV version 1.10