On Mon, May 26, 2014 at 10:36:35PM +0200, Pavel Březina wrote:
> On 05/26/2014 07:05 PM, Jakub Hrozek wrote:
> >On Thu, May 22, 2014 at 07:57:28PM +0200, Pavel Březina wrote:
> >>On 05/21/2014 11:03 PM, Jakub Hrozek wrote:
> >>>Hi,
> >>>
> >>>the attaches two patches implement DBus methods to retrieve SSSD domains
> >>>using the system bus as well as two example getters that leverage the
> >>>infrastructure to Get and GetAll the object properties.
> >>>
> >>>Pavel, I know you have a large patchset in a private tree that
> >>>implements the other getters and moves the domain methods into a
> >>>separate file. I'm fine with merging your and mine patches, I just
> >>>wanted to get the ball rolling on the list. Feel free to reply with your
> >>>patchset.
> >>
> >>Hi,
> >>see the attachment.
> >>
> >>I squash all my patches to these five - mainly discarded the moving
> >>the code around.
> >>
> >>I kept you as the author for the methods as I made only very minor
> >>changes there. However, I took the ownership for the properties
> >>since there only very little of your original code remains there - I
> >>hope you don't mind.
> >>
> >>The next three patches implements the SSSD components interface
> >>required for the OpenLMI provider. I'm sending it to this thread
> >>since it depends on the domain patches anyway - there is enough
> >>dependency fuzz already.
> >>
> >
> >> From 0f1e1adba39f203ad6405531a21d28d5c9bfa9ac Mon Sep 17 00:00:00 2001
> >>From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <[email protected]>
> >>Date: Mon, 5 May 2014 13:28:34 +0200
> >>Subject: [PATCH 3/5] confdb: add confdb_list_all_domain_names()
> >
> >ACK.
> >
> >See attached unit test I used for testing.
> 
> Hi,
> the tests looks good, however there are three tests in one test. It
> should be split.

OK, done, hopefully there is not too much duplication.
>From c1f67c4744c73112353d8cf33fd35ac6cb37c470 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <[email protected]>
Date: Mon, 26 May 2014 19:04:41 +0200
Subject: [PATCH] tests: Add test for confdb_list_all_domain_names

---
 src/responder/ifp/ifp_iface_generated.c | 460 ++++++++++++++++----------------
 src/tests/sysdb-tests.c                 | 149 +++++++++++
 2 files changed, 379 insertions(+), 230 deletions(-)

diff --git a/src/responder/ifp/ifp_iface_generated.c 
b/src/responder/ifp/ifp_iface_generated.c
index 
20ad563733c2774cdd8e73924e00c2f0b608c67e..62a21e911030c0c5fd1a700804cd01ebba186141
 100644
--- a/src/responder/ifp/ifp_iface_generated.c
+++ b/src/responder/ifp/ifp_iface_generated.c
@@ -356,103 +356,6 @@ const struct sbus_method_meta 
infopipe_component__methods[] = {
     { NULL, }
 };
 
-/* invokes GetAll for the 'org.freedesktop.sssd.infopipe.Components' interface 
*/
-static int invoke_infopipe_component_get_all(struct sbus_request *dbus_req, 
void *function_ptr)
-{
-    struct sbus_interface *intf = dbus_req->intf;
-    const struct sbus_property_meta *property;
-    DBusMessage *reply;
-    dbus_bool_t dbret;
-    DBusMessageIter iter;
-    DBusMessageIter iter_dict;
-    int ret;
-    const char * s_prop_val;
-    const char * s_out_val;
-    void (*s_handler)(struct sbus_request *, void *data, const char * *);
-    bool b_prop_val;
-    dbus_bool_t b_out_val;
-    void (*b_handler)(struct sbus_request *, void *data, bool *);
-    uint32_t u_prop_val;
-    uint32_t u_out_val;
-    void (*u_handler)(struct sbus_request *, void *data, uint32_t *);
-    const char * *as_prop_val;
-    int as_prop_len;
-    const char * *as_out_val;
-    void (*as_handler)(struct sbus_request *, void *data, const char * * *, 
int *);
-
-    reply = dbus_message_new_method_return(dbus_req->message);
-    if (!reply) return ENOMEM;
-    dbus_message_iter_init_append(reply, &iter);
-    dbret = dbus_message_iter_open_container(
-                                     &iter, DBUS_TYPE_ARRAY,
-                                     DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-                                     DBUS_TYPE_STRING_AS_STRING
-                                     DBUS_TYPE_VARIANT_AS_STRING
-                                     DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
-                                     &iter_dict);
-    if (!dbret) return ENOMEM;
-
-    property = sbus_meta_find_property(intf->vtable->meta, "name");
-    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
-        s_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
-        if (s_handler) {
-            (s_handler)(dbus_req, dbus_req->intf->instance_data, &s_prop_val);
-            s_out_val = s_prop_val == NULL ? "" : s_prop_val;
-            ret = sbus_add_variant_to_dict(&iter_dict, "name", 
DBUS_TYPE_STRING, &s_out_val);
-            if (ret != EOK) return ret;
-        }
-    }
-
-    property = sbus_meta_find_property(intf->vtable->meta, "debug_level");
-    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
-        u_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
-        if (u_handler) {
-            (u_handler)(dbus_req, dbus_req->intf->instance_data, &u_prop_val);
-            u_out_val = u_prop_val;
-            ret = sbus_add_variant_to_dict(&iter_dict, "debug_level", 
DBUS_TYPE_UINT32, &u_out_val);
-            if (ret != EOK) return ret;
-        }
-    }
-
-    property = sbus_meta_find_property(intf->vtable->meta, "enabled");
-    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
-        b_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
-        if (b_handler) {
-            (b_handler)(dbus_req, dbus_req->intf->instance_data, &b_prop_val);
-            b_out_val = b_prop_val;
-            ret = sbus_add_variant_to_dict(&iter_dict, "enabled", 
DBUS_TYPE_BOOLEAN, &b_out_val);
-            if (ret != EOK) return ret;
-        }
-    }
-
-    property = sbus_meta_find_property(intf->vtable->meta, "type");
-    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
-        s_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
-        if (s_handler) {
-            (s_handler)(dbus_req, dbus_req->intf->instance_data, &s_prop_val);
-            s_out_val = s_prop_val == NULL ? "" : s_prop_val;
-            ret = sbus_add_variant_to_dict(&iter_dict, "type", 
DBUS_TYPE_STRING, &s_out_val);
-            if (ret != EOK) return ret;
-        }
-    }
-
-    property = sbus_meta_find_property(intf->vtable->meta, "providers");
-    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
-        as_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
-        if (as_handler) {
-            (as_handler)(dbus_req, dbus_req->intf->instance_data, 
&as_prop_val, &as_prop_len);
-            as_out_val = as_prop_val;
-            ret = sbus_add_array_as_variant_to_dict(&iter_dict, "providers", 
DBUS_TYPE_STRING, (uint8_t*)as_out_val, as_prop_len, sizeof(const char *));
-            if (ret != EOK) return ret;
-        }
-    }
-
-    dbret = dbus_message_iter_close_container(&iter, &iter_dict);
-    if (!dbret) return ENOMEM;
-
-    return sbus_request_finish(dbus_req, reply);
-}
-
 /* property info for org.freedesktop.sssd.infopipe.Components */
 const struct sbus_property_meta infopipe_component__properties[] = {
     {
@@ -503,6 +406,103 @@ const struct sbus_property_meta 
infopipe_component__properties[] = {
     { NULL, }
 };
 
+/* invokes GetAll for the 'org.freedesktop.sssd.infopipe.Components' interface 
*/
+static int invoke_infopipe_component_get_all(struct sbus_request *dbus_req, 
void *function_ptr)
+{
+    DBusMessage *reply;
+    dbus_bool_t dbret;
+    DBusMessageIter iter;
+    DBusMessageIter iter_dict;
+    int ret;
+    struct sbus_interface *intf = dbus_req->intf;
+    const struct sbus_property_meta *property;
+    const char * s_prop_val;
+    const char * s_out_val;
+    void (*s_handler)(struct sbus_request *, void *data, const char * *);
+    bool b_prop_val;
+    dbus_bool_t b_out_val;
+    void (*b_handler)(struct sbus_request *, void *data, bool *);
+    uint32_t u_prop_val;
+    uint32_t u_out_val;
+    void (*u_handler)(struct sbus_request *, void *data, uint32_t *);
+    const char * *as_prop_val;
+    int as_prop_len;
+    const char * *as_out_val;
+    void (*as_handler)(struct sbus_request *, void *data, const char * * *, 
int *);
+
+    reply = dbus_message_new_method_return(dbus_req->message);
+    if (!reply) return ENOMEM;
+    dbus_message_iter_init_append(reply, &iter);
+    dbret = dbus_message_iter_open_container(
+                                     &iter, DBUS_TYPE_ARRAY,
+                                     DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                                     DBUS_TYPE_STRING_AS_STRING
+                                     DBUS_TYPE_VARIANT_AS_STRING
+                                     DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+                                     &iter_dict);
+    if (!dbret) return ENOMEM;
+
+    property = sbus_meta_find_property(intf->vtable->meta, "name");
+    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
+        s_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
+        if (s_handler) {
+            (s_handler)(dbus_req, dbus_req->intf->instance_data, &s_prop_val);
+            s_out_val = s_prop_val == NULL ? "" : s_prop_val;
+            ret = sbus_add_variant_to_dict(&iter_dict, "name", 
DBUS_TYPE_STRING, &s_out_val);
+            if (ret != EOK) return ret;
+        }
+    }
+
+    property = sbus_meta_find_property(intf->vtable->meta, "debug_level");
+    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
+        u_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
+        if (u_handler) {
+            (u_handler)(dbus_req, dbus_req->intf->instance_data, &u_prop_val);
+            u_out_val = u_prop_val;
+            ret = sbus_add_variant_to_dict(&iter_dict, "debug_level", 
DBUS_TYPE_UINT32, &u_out_val);
+            if (ret != EOK) return ret;
+        }
+    }
+
+    property = sbus_meta_find_property(intf->vtable->meta, "enabled");
+    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
+        b_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
+        if (b_handler) {
+            (b_handler)(dbus_req, dbus_req->intf->instance_data, &b_prop_val);
+            b_out_val = b_prop_val;
+            ret = sbus_add_variant_to_dict(&iter_dict, "enabled", 
DBUS_TYPE_BOOLEAN, &b_out_val);
+            if (ret != EOK) return ret;
+        }
+    }
+
+    property = sbus_meta_find_property(intf->vtable->meta, "type");
+    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
+        s_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
+        if (s_handler) {
+            (s_handler)(dbus_req, dbus_req->intf->instance_data, &s_prop_val);
+            s_out_val = s_prop_val == NULL ? "" : s_prop_val;
+            ret = sbus_add_variant_to_dict(&iter_dict, "type", 
DBUS_TYPE_STRING, &s_out_val);
+            if (ret != EOK) return ret;
+        }
+    }
+
+    property = sbus_meta_find_property(intf->vtable->meta, "providers");
+    if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {
+        as_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);
+        if (as_handler) {
+            (as_handler)(dbus_req, dbus_req->intf->instance_data, 
&as_prop_val, &as_prop_len);
+            as_out_val = as_prop_val;
+            ret = sbus_add_array_as_variant_to_dict(&iter_dict, "providers", 
DBUS_TYPE_STRING, (uint8_t*)as_out_val, as_prop_len, sizeof(const char *));
+            if (ret != EOK) return ret;
+        }
+    }
+
+    dbret = dbus_message_iter_close_container(&iter, &iter_dict);
+    if (!dbret) return ENOMEM;
+
+    return sbus_request_finish(dbus_req, reply);
+}
+
 /* interface info for org.freedesktop.sssd.infopipe.Components */
 const struct sbus_interface_meta infopipe_component_meta = {
     "org.freedesktop.sssd.infopipe.Components", /* name */
@@ -512,16 +512,147 @@ const struct sbus_interface_meta infopipe_component_meta 
= {
     invoke_infopipe_component_get_all, /* GetAll invoker */
 };
 
+/* property info for org.freedesktop.sssd.infopipe.Domains */
+const struct sbus_property_meta infopipe_domain__properties[] = {
+    {
+        "name", /* name */
+        "s", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_name),
+        invoke_get_s,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "provider", /* name */
+        "s", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_provider),
+        invoke_get_s,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "primary_servers", /* name */
+        "as", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_primary_servers),
+        invoke_get_as,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "backup_servers", /* name */
+        "as", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_backup_servers),
+        invoke_get_as,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "min_id", /* name */
+        "u", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_min_id),
+        invoke_get_u,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "max_id", /* name */
+        "u", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_max_id),
+        invoke_get_u,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "realm", /* name */
+        "s", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_realm),
+        invoke_get_s,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "forest", /* name */
+        "s", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_forest),
+        invoke_get_s,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "login_format", /* name */
+        "s", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_login_format),
+        invoke_get_s,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "fully_qualified_name_format", /* name */
+        "s", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, 
infopipe_domain_get_fully_qualified_name_format),
+        invoke_get_s,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "enumerable", /* name */
+        "b", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_enumerable),
+        invoke_get_b,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "use_fully_qualified_names", /* name */
+        "b", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, 
infopipe_domain_get_use_fully_qualified_names),
+        invoke_get_b,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "subdomain", /* name */
+        "b", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_subdomain),
+        invoke_get_b,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    {
+        "parent_domain", /* name */
+        "o", /* type */
+        SBUS_PROPERTY_READABLE,
+        offsetof(struct infopipe_domain, infopipe_domain_get_parent_domain),
+        invoke_get_o,
+        0, /* not writable */
+        NULL, /* no invoker */
+    },
+    { NULL, }
+};
+
 /* invokes GetAll for the 'org.freedesktop.sssd.infopipe.Domains' interface */
 static int invoke_infopipe_domain_get_all(struct sbus_request *dbus_req, void 
*function_ptr)
 {
-    struct sbus_interface *intf = dbus_req->intf;
-    const struct sbus_property_meta *property;
     DBusMessage *reply;
     dbus_bool_t dbret;
     DBusMessageIter iter;
     DBusMessageIter iter_dict;
     int ret;
+    struct sbus_interface *intf = dbus_req->intf;
+    const struct sbus_property_meta *property;
     const char * s_prop_val;
     const char * s_out_val;
     void (*s_handler)(struct sbus_request *, void *data, const char * *);
@@ -711,137 +842,6 @@ static int invoke_infopipe_domain_get_all(struct 
sbus_request *dbus_req, void *f
     return sbus_request_finish(dbus_req, reply);
 }
 
-/* property info for org.freedesktop.sssd.infopipe.Domains */
-const struct sbus_property_meta infopipe_domain__properties[] = {
-    {
-        "name", /* name */
-        "s", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_name),
-        invoke_get_s,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "provider", /* name */
-        "s", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_provider),
-        invoke_get_s,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "primary_servers", /* name */
-        "as", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_primary_servers),
-        invoke_get_as,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "backup_servers", /* name */
-        "as", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_backup_servers),
-        invoke_get_as,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "min_id", /* name */
-        "u", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_min_id),
-        invoke_get_u,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "max_id", /* name */
-        "u", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_max_id),
-        invoke_get_u,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "realm", /* name */
-        "s", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_realm),
-        invoke_get_s,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "forest", /* name */
-        "s", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_forest),
-        invoke_get_s,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "login_format", /* name */
-        "s", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_login_format),
-        invoke_get_s,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "fully_qualified_name_format", /* name */
-        "s", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, 
infopipe_domain_get_fully_qualified_name_format),
-        invoke_get_s,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "enumerable", /* name */
-        "b", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_enumerable),
-        invoke_get_b,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "use_fully_qualified_names", /* name */
-        "b", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, 
infopipe_domain_get_use_fully_qualified_names),
-        invoke_get_b,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "subdomain", /* name */
-        "b", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_subdomain),
-        invoke_get_b,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    {
-        "parent_domain", /* name */
-        "o", /* type */
-        SBUS_PROPERTY_READABLE,
-        offsetof(struct infopipe_domain, infopipe_domain_get_parent_domain),
-        invoke_get_o,
-        0, /* not writable */
-        NULL, /* no invoker */
-    },
-    { NULL, }
-};
-
 /* interface info for org.freedesktop.sssd.infopipe.Domains */
 const struct sbus_interface_meta infopipe_domain_meta = {
     "org.freedesktop.sssd.infopipe.Domains", /* name */
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 
3e4d5f7f0f4e7ba887fab8ccf00d4f89771776f0..625461663de12092cd3fd39862aaee943d144ec2
 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -4988,6 +4988,147 @@ END_TEST
 
 #endif /* BUILD_AUTOFS */
 
+static struct confdb_ctx *test_cdb_domains_prep(TALLOC_CTX *mem_ctx)
+{
+    char *conf_db;
+    int ret;
+    struct confdb_ctx *confdb;
+
+    /* Create tests directory if it doesn't exist */
+    /* (relative to current dir) */
+    ret = mkdir(TESTS_PATH, 0775);
+    if (ret == -1 && errno != EEXIST) {
+        fail("Could not create %s directory", TESTS_PATH);
+        return NULL;
+    }
+
+    conf_db = talloc_asprintf(mem_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
+    ck_assert(conf_db != NULL);
+
+    /* Make sure the test domain does not interfere with our testing */
+    ret = unlink(TESTS_PATH"/"TEST_CONF_FILE);
+    if (ret != EOK && errno != ENOENT) {
+        fail("Could not remove confdb %s\n", TESTS_PATH"/"TEST_CONF_FILE);
+        return NULL;
+    }
+
+    /* Connect to the conf db */
+    ret = confdb_init(mem_ctx, &confdb, conf_db);
+    ck_assert_int_eq(ret, EOK);
+
+    return confdb;
+}
+
+START_TEST(test_confdb_list_all_domain_names_no_dom)
+{
+    int ret;
+    TALLOC_CTX *tmp_ctx;
+    struct confdb_ctx *confdb;
+    char **names;
+
+    const char *val[2];
+    val[1] = NULL;
+
+    tmp_ctx = talloc_new(NULL);
+    ck_assert(tmp_ctx != NULL);
+
+    confdb = test_cdb_domains_prep(tmp_ctx);
+    ck_assert(confdb != NULL);
+
+    /* No domain */
+    ret = confdb_list_all_domain_names(tmp_ctx, confdb, &names);
+    ck_assert_int_eq(ret, EOK);
+    ck_assert(names != NULL);
+    ck_assert(names[0] == NULL);
+
+    talloc_free(tmp_ctx);
+}
+END_TEST
+
+START_TEST(test_confdb_list_all_domain_names_single_dom)
+{
+    int ret;
+    TALLOC_CTX *tmp_ctx;
+    struct confdb_ctx *confdb;
+    char **names;
+
+    const char *val[2];
+    val[1] = NULL;
+
+    tmp_ctx = talloc_new(NULL);
+    ck_assert(tmp_ctx != NULL);
+
+    confdb = test_cdb_domains_prep(tmp_ctx);
+    ck_assert(confdb != NULL);
+
+    /* One domain */
+    val[0] = "LOCAL";
+    ret = confdb_add_param(confdb, true,
+                           "config/sssd", "domains", val);
+    ck_assert_int_eq(ret, EOK);
+
+    val[0] = "local";
+    ret = confdb_add_param(confdb, true,
+                           "config/domain/LOCAL", "id_provider", val);
+    ck_assert_int_eq(ret, EOK);
+
+    ret = confdb_list_all_domain_names(tmp_ctx, confdb, &names);
+    ck_assert_int_eq(ret, EOK);
+    ck_assert(names != NULL);
+    ck_assert_str_eq(names[0], "LOCAL");
+    ck_assert(names[1] == NULL);
+
+    talloc_free(tmp_ctx);
+}
+END_TEST
+
+START_TEST(test_confdb_list_all_domain_names_multi_dom)
+{
+    int ret;
+    TALLOC_CTX *tmp_ctx;
+    struct confdb_ctx *confdb;
+    char **names;
+
+    const char *val[2];
+    val[1] = NULL;
+
+    tmp_ctx = talloc_new(NULL);
+    ck_assert(tmp_ctx != NULL);
+
+    confdb = test_cdb_domains_prep(tmp_ctx);
+    ck_assert(confdb != NULL);
+
+    /* Two domains */
+    val[0] = "LOCAL";
+    ret = confdb_add_param(confdb, true,
+                           "config/sssd", "domains", val);
+    ck_assert_int_eq(ret, EOK);
+
+    val[0] = "local";
+    ret = confdb_add_param(confdb, true,
+                           "config/domain/LOCAL", "id_provider", val);
+    ck_assert_int_eq(ret, EOK);
+
+    val[0] = "REMOTE";
+    ret = confdb_add_param(confdb, true,
+                           "config/sssd", "domains", val);
+    ck_assert_int_eq(ret, EOK);
+
+    val[0] = "local";
+    ret = confdb_add_param(confdb, true,
+                           "config/domain/REMOTE", "id_provider", val);
+    ck_assert_int_eq(ret, EOK);
+
+    ret = confdb_list_all_domain_names(tmp_ctx, confdb, &names);
+    ck_assert_int_eq(ret, EOK);
+    ck_assert(names != NULL);
+    ck_assert_str_eq(names[0], "LOCAL");
+    ck_assert_str_eq(names[1], "REMOTE");
+    ck_assert(names[2] == NULL);
+    talloc_free(tmp_ctx);
+}
+END_TEST
+
 Suite *create_sysdb_suite(void)
 {
     Suite *s = suite_create("sysdb");
@@ -5334,6 +5475,14 @@ Suite *create_sysdb_suite(void)
     suite_add_tcase(s, tc_autofs);
 #endif
 
+    /* ConfDB tests -- modify confdb, must always be last!! */
+    TCase *tc_confdb = tcase_create("confDB tests");
+
+    tcase_add_test(tc_confdb, test_confdb_list_all_domain_names_no_dom);
+    tcase_add_test(tc_confdb, test_confdb_list_all_domain_names_single_dom);
+    tcase_add_test(tc_confdb, test_confdb_list_all_domain_names_multi_dom);
+    suite_add_tcase(s, tc_confdb);
+
     return s;
 }
 
-- 
1.9.0

_______________________________________________
sssd-devel mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to