Blob Blame History Raw
From 16495f6aca6fb1a3f0cdb30b4a50493453e8ca0f Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Wed, 20 Jul 2016 12:03:48 +0200
Subject: [PATCH 35/44] tests: add tests for sss_get_domain_mappings_content()

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
---
 src/tests/cmocka/test_utils.c | 163 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 163 insertions(+)

diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c
index b08b19708bb59a076a79805fa37a15924152b8e2..4c72a59437105e683cec2d39c36951aeff63767b 100644
--- a/src/tests/cmocka/test_utils.c
+++ b/src/tests/cmocka/test_utils.c
@@ -55,6 +55,95 @@ struct dom_list_test_ctx {
     struct sss_domain_info *dom_list;
 };
 
+static int setup_dom_list_with_subdomains(void **state)
+{
+    struct dom_list_test_ctx *test_ctx;
+    struct sss_domain_info *dom = NULL;
+    struct sss_domain_info *c = NULL;
+
+    assert_true(leak_check_setup());
+
+    test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
+    assert_non_null(test_ctx);
+
+    dom = talloc_zero(test_ctx, struct sss_domain_info);
+    assert_non_null(dom);
+
+    dom->name = talloc_asprintf(dom, "configured.dom");
+    assert_non_null(dom->name);
+
+    dom->realm = talloc_asprintf(dom, "CONFIGURED.DOM");
+    assert_non_null(dom->realm);
+
+    dom->flat_name = talloc_asprintf(dom, "CONFIGURED");
+    assert_non_null(dom->flat_name);
+
+    dom->domain_id = talloc_asprintf(dom, "S-1-5-21-1-2-1");
+    assert_non_null(dom->domain_id);
+
+    DLIST_ADD(test_ctx->dom_list, dom);
+
+    c = talloc_zero(test_ctx, struct sss_domain_info);
+    assert_non_null(c);
+
+    c->name = talloc_asprintf(c, "subdom1.dom");
+    assert_non_null(c->name);
+
+    c->realm = talloc_asprintf(c, "SUBDOM1.DOM");
+    assert_non_null(c->realm);
+
+    c->flat_name = talloc_asprintf(c, "subdom1");
+    assert_non_null(c->flat_name);
+
+    c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-2");
+    assert_non_null(c->domain_id);
+
+    c->parent = dom;
+
+    DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
+
+    c = talloc_zero(test_ctx, struct sss_domain_info);
+    assert_non_null(c);
+
+    c->name = talloc_asprintf(c, "subdom2.dom");
+    assert_non_null(c->name);
+
+    c->realm = talloc_asprintf(c, "SUBDOM2.DOM");
+    assert_non_null(c->realm);
+
+    c->flat_name = talloc_asprintf(c, "subdom2");
+    assert_non_null(c->flat_name);
+
+    c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-3");
+    assert_non_null(c->domain_id);
+
+    c->parent = dom;
+
+    DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
+
+    c = talloc_zero(test_ctx, struct sss_domain_info);
+    assert_non_null(c);
+
+    c->name = talloc_asprintf(c, "subdom3.dom");
+    assert_non_null(c->name);
+
+    c->realm = talloc_asprintf(c, "SUBDOM3.DOM");
+    assert_non_null(c->realm);
+
+    c->flat_name = talloc_asprintf(c, "subdom3");
+    assert_non_null(c->flat_name);
+
+    c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-4");
+    assert_non_null(c->domain_id);
+
+    c->parent = dom;
+
+    DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
+
+    check_leaks_push(test_ctx);
+    *state = test_ctx;
+    return 0;
+}
 
 static int setup_dom_list(void **state)
 {
@@ -1682,6 +1771,77 @@ static void test_sss_output_name(void **state)
     assert_true(check_leaks_pop(global_talloc_context) == true);
 }
 
+static void test_sss_get_domain_mappings_content(void **state)
+{
+    struct dom_list_test_ctx *test_ctx;
+    int ret;
+    struct sss_domain_info *dom;
+    char *content;
+    struct sss_domain_info *c;
+
+    ret = sss_get_domain_mappings_content(NULL, NULL, NULL);
+    assert_int_equal(ret, EINVAL);
+
+    test_ctx = talloc_get_type(*state, struct dom_list_test_ctx);
+    assert_non_null(test_ctx);
+
+    dom = get_domains_head(test_ctx->dom_list);
+    assert_non_null(dom);
+
+    /* no forest */
+    ret = sss_get_domain_mappings_content(test_ctx, dom, &content);
+    assert_int_equal(ret, EOK);
+    assert_string_equal(content,
+                        "[domain_realm]\n"
+                        ".subdom1.dom = SUBDOM1.DOM\n"
+                        "subdom1.dom = SUBDOM1.DOM\n"
+                        ".subdom2.dom = SUBDOM2.DOM\n"
+                        "subdom2.dom = SUBDOM2.DOM\n"
+                        ".subdom3.dom = SUBDOM3.DOM\n"
+                        "subdom3.dom = SUBDOM3.DOM\n");
+    talloc_free(content);
+
+    /* IPA with forest */
+    c = find_domain_by_name(dom, "subdom2.dom", true);
+    assert_non_null(c);
+    c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
+    assert_non_null(c->forest_root);
+    c->forest = "subdom1.dom";
+
+    c = find_domain_by_name(dom, "subdom3.dom", true);
+    assert_non_null(c);
+    c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
+    assert_non_null(c->forest_root);
+    c->forest = "subdom1.dom";
+
+    ret = sss_get_domain_mappings_content(test_ctx, dom, &content);
+    assert_int_equal(ret, EOK);
+    assert_string_equal(content,
+                        "[domain_realm]\n"
+                        ".subdom1.dom = SUBDOM1.DOM\n"
+                        "subdom1.dom = SUBDOM1.DOM\n"
+                        ".subdom2.dom = SUBDOM2.DOM\n"
+                        "subdom2.dom = SUBDOM2.DOM\n"
+                        ".subdom3.dom = SUBDOM3.DOM\n"
+                        "subdom3.dom = SUBDOM3.DOM\n"
+                        "[capaths]\n"
+                        "SUBDOM2.DOM = {\n"
+                        "  CONFIGURED.DOM = SUBDOM1.DOM\n"
+                        "}\n"
+                        "SUBDOM3.DOM = {\n"
+                        "  CONFIGURED.DOM = SUBDOM1.DOM\n"
+                        "}\n"
+                        "CONFIGURED.DOM = {\n"
+                        "  SUBDOM2.DOM = SUBDOM1.DOM\n"
+                        "  SUBDOM3.DOM = SUBDOM1.DOM\n"
+                        "}\n");
+    talloc_free(content);
+
+    /* Next steps, test AD domain setup. If we join a child domain we have a
+     * similar case as with IPA but if we join the forest root the generate
+     * capaths might not be as expected. */
+}
+
 int main(int argc, const char *argv[])
 {
     poptContext pc;
@@ -1773,6 +1933,9 @@ int main(int argc, const char *argv[])
         cmocka_unit_test_setup_teardown(test_sss_output_name,
                                         setup_leak_tests,
                                         teardown_leak_tests),
+        cmocka_unit_test_setup_teardown(test_sss_get_domain_mappings_content,
+                                        setup_dom_list_with_subdomains,
+                                        teardown_dom_list),
     };
 
     /* Set debug level to invalid value so we can deside if -d 0 was used. */
-- 
2.4.11