Blame SOURCES/0035-tests-add-tests-for-sss_get_domain_mappings_content.patch

b2d430
From 16495f6aca6fb1a3f0cdb30b4a50493453e8ca0f Mon Sep 17 00:00:00 2001
b2d430
From: Sumit Bose <sbose@redhat.com>
b2d430
Date: Wed, 20 Jul 2016 12:03:48 +0200
b2d430
Subject: [PATCH 35/44] tests: add tests for sss_get_domain_mappings_content()
b2d430
b2d430
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
b2d430
---
b2d430
 src/tests/cmocka/test_utils.c | 163 ++++++++++++++++++++++++++++++++++++++++++
b2d430
 1 file changed, 163 insertions(+)
b2d430
b2d430
diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c
b2d430
index b08b19708bb59a076a79805fa37a15924152b8e2..4c72a59437105e683cec2d39c36951aeff63767b 100644
b2d430
--- a/src/tests/cmocka/test_utils.c
b2d430
+++ b/src/tests/cmocka/test_utils.c
b2d430
@@ -55,6 +55,95 @@ struct dom_list_test_ctx {
b2d430
     struct sss_domain_info *dom_list;
b2d430
 };
b2d430
 
b2d430
+static int setup_dom_list_with_subdomains(void **state)
b2d430
+{
b2d430
+    struct dom_list_test_ctx *test_ctx;
b2d430
+    struct sss_domain_info *dom = NULL;
b2d430
+    struct sss_domain_info *c = NULL;
b2d430
+
b2d430
+    assert_true(leak_check_setup());
b2d430
+
b2d430
+    test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
b2d430
+    assert_non_null(test_ctx);
b2d430
+
b2d430
+    dom = talloc_zero(test_ctx, struct sss_domain_info);
b2d430
+    assert_non_null(dom);
b2d430
+
b2d430
+    dom->name = talloc_asprintf(dom, "configured.dom");
b2d430
+    assert_non_null(dom->name);
b2d430
+
b2d430
+    dom->realm = talloc_asprintf(dom, "CONFIGURED.DOM");
b2d430
+    assert_non_null(dom->realm);
b2d430
+
b2d430
+    dom->flat_name = talloc_asprintf(dom, "CONFIGURED");
b2d430
+    assert_non_null(dom->flat_name);
b2d430
+
b2d430
+    dom->domain_id = talloc_asprintf(dom, "S-1-5-21-1-2-1");
b2d430
+    assert_non_null(dom->domain_id);
b2d430
+
b2d430
+    DLIST_ADD(test_ctx->dom_list, dom);
b2d430
+
b2d430
+    c = talloc_zero(test_ctx, struct sss_domain_info);
b2d430
+    assert_non_null(c);
b2d430
+
b2d430
+    c->name = talloc_asprintf(c, "subdom1.dom");
b2d430
+    assert_non_null(c->name);
b2d430
+
b2d430
+    c->realm = talloc_asprintf(c, "SUBDOM1.DOM");
b2d430
+    assert_non_null(c->realm);
b2d430
+
b2d430
+    c->flat_name = talloc_asprintf(c, "subdom1");
b2d430
+    assert_non_null(c->flat_name);
b2d430
+
b2d430
+    c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-2");
b2d430
+    assert_non_null(c->domain_id);
b2d430
+
b2d430
+    c->parent = dom;
b2d430
+
b2d430
+    DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
b2d430
+
b2d430
+    c = talloc_zero(test_ctx, struct sss_domain_info);
b2d430
+    assert_non_null(c);
b2d430
+
b2d430
+    c->name = talloc_asprintf(c, "subdom2.dom");
b2d430
+    assert_non_null(c->name);
b2d430
+
b2d430
+    c->realm = talloc_asprintf(c, "SUBDOM2.DOM");
b2d430
+    assert_non_null(c->realm);
b2d430
+
b2d430
+    c->flat_name = talloc_asprintf(c, "subdom2");
b2d430
+    assert_non_null(c->flat_name);
b2d430
+
b2d430
+    c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-3");
b2d430
+    assert_non_null(c->domain_id);
b2d430
+
b2d430
+    c->parent = dom;
b2d430
+
b2d430
+    DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
b2d430
+
b2d430
+    c = talloc_zero(test_ctx, struct sss_domain_info);
b2d430
+    assert_non_null(c);
b2d430
+
b2d430
+    c->name = talloc_asprintf(c, "subdom3.dom");
b2d430
+    assert_non_null(c->name);
b2d430
+
b2d430
+    c->realm = talloc_asprintf(c, "SUBDOM3.DOM");
b2d430
+    assert_non_null(c->realm);
b2d430
+
b2d430
+    c->flat_name = talloc_asprintf(c, "subdom3");
b2d430
+    assert_non_null(c->flat_name);
b2d430
+
b2d430
+    c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-4");
b2d430
+    assert_non_null(c->domain_id);
b2d430
+
b2d430
+    c->parent = dom;
b2d430
+
b2d430
+    DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
b2d430
+
b2d430
+    check_leaks_push(test_ctx);
b2d430
+    *state = test_ctx;
b2d430
+    return 0;
b2d430
+}
b2d430
 
b2d430
 static int setup_dom_list(void **state)
b2d430
 {
b2d430
@@ -1682,6 +1771,77 @@ static void test_sss_output_name(void **state)
b2d430
     assert_true(check_leaks_pop(global_talloc_context) == true);
b2d430
 }
b2d430
 
b2d430
+static void test_sss_get_domain_mappings_content(void **state)
b2d430
+{
b2d430
+    struct dom_list_test_ctx *test_ctx;
b2d430
+    int ret;
b2d430
+    struct sss_domain_info *dom;
b2d430
+    char *content;
b2d430
+    struct sss_domain_info *c;
b2d430
+
b2d430
+    ret = sss_get_domain_mappings_content(NULL, NULL, NULL);
b2d430
+    assert_int_equal(ret, EINVAL);
b2d430
+
b2d430
+    test_ctx = talloc_get_type(*state, struct dom_list_test_ctx);
b2d430
+    assert_non_null(test_ctx);
b2d430
+
b2d430
+    dom = get_domains_head(test_ctx->dom_list);
b2d430
+    assert_non_null(dom);
b2d430
+
b2d430
+    /* no forest */
b2d430
+    ret = sss_get_domain_mappings_content(test_ctx, dom, &content);
b2d430
+    assert_int_equal(ret, EOK);
b2d430
+    assert_string_equal(content,
b2d430
+                        "[domain_realm]\n"
b2d430
+                        ".subdom1.dom = SUBDOM1.DOM\n"
b2d430
+                        "subdom1.dom = SUBDOM1.DOM\n"
b2d430
+                        ".subdom2.dom = SUBDOM2.DOM\n"
b2d430
+                        "subdom2.dom = SUBDOM2.DOM\n"
b2d430
+                        ".subdom3.dom = SUBDOM3.DOM\n"
b2d430
+                        "subdom3.dom = SUBDOM3.DOM\n");
b2d430
+    talloc_free(content);
b2d430
+
b2d430
+    /* IPA with forest */
b2d430
+    c = find_domain_by_name(dom, "subdom2.dom", true);
b2d430
+    assert_non_null(c);
b2d430
+    c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
b2d430
+    assert_non_null(c->forest_root);
b2d430
+    c->forest = "subdom1.dom";
b2d430
+
b2d430
+    c = find_domain_by_name(dom, "subdom3.dom", true);
b2d430
+    assert_non_null(c);
b2d430
+    c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
b2d430
+    assert_non_null(c->forest_root);
b2d430
+    c->forest = "subdom1.dom";
b2d430
+
b2d430
+    ret = sss_get_domain_mappings_content(test_ctx, dom, &content);
b2d430
+    assert_int_equal(ret, EOK);
b2d430
+    assert_string_equal(content,
b2d430
+                        "[domain_realm]\n"
b2d430
+                        ".subdom1.dom = SUBDOM1.DOM\n"
b2d430
+                        "subdom1.dom = SUBDOM1.DOM\n"
b2d430
+                        ".subdom2.dom = SUBDOM2.DOM\n"
b2d430
+                        "subdom2.dom = SUBDOM2.DOM\n"
b2d430
+                        ".subdom3.dom = SUBDOM3.DOM\n"
b2d430
+                        "subdom3.dom = SUBDOM3.DOM\n"
b2d430
+                        "[capaths]\n"
b2d430
+                        "SUBDOM2.DOM = {\n"
b2d430
+                        "  CONFIGURED.DOM = SUBDOM1.DOM\n"
b2d430
+                        "}\n"
b2d430
+                        "SUBDOM3.DOM = {\n"
b2d430
+                        "  CONFIGURED.DOM = SUBDOM1.DOM\n"
b2d430
+                        "}\n"
b2d430
+                        "CONFIGURED.DOM = {\n"
b2d430
+                        "  SUBDOM2.DOM = SUBDOM1.DOM\n"
b2d430
+                        "  SUBDOM3.DOM = SUBDOM1.DOM\n"
b2d430
+                        "}\n");
b2d430
+    talloc_free(content);
b2d430
+
b2d430
+    /* Next steps, test AD domain setup. If we join a child domain we have a
b2d430
+     * similar case as with IPA but if we join the forest root the generate
b2d430
+     * capaths might not be as expected. */
b2d430
+}
b2d430
+
b2d430
 int main(int argc, const char *argv[])
b2d430
 {
b2d430
     poptContext pc;
b2d430
@@ -1773,6 +1933,9 @@ int main(int argc, const char *argv[])
b2d430
         cmocka_unit_test_setup_teardown(test_sss_output_name,
b2d430
                                         setup_leak_tests,
b2d430
                                         teardown_leak_tests),
b2d430
+        cmocka_unit_test_setup_teardown(test_sss_get_domain_mappings_content,
b2d430
+                                        setup_dom_list_with_subdomains,
b2d430
+                                        teardown_dom_list),
b2d430
     };
b2d430
 
b2d430
     /* Set debug level to invalid value so we can deside if -d 0 was used. */
b2d430
-- 
b2d430
2.4.11
b2d430