[SSSD] [PATCH] TESTS: Add a unit test for matching the secondary objectclass

Jakub Hrozek jhrozek at redhat.com
Wed Sep 24 15:31:31 UTC 2014


I promised Michal to write a unit test for the alternative objectclass
matching, because friends don't let friends commit a feature without
tests.
-------------- next part --------------
>From 44aba3b25966ee002d999356be8169cc4d959bcf Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Wed, 24 Sep 2014 17:28:48 +0200
Subject: [PATCH] TESTS: Add a unit test for matching the secondary objectclass

---
 src/tests/cmocka/test_sdap.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/tests/cmocka/test_sdap.c b/src/tests/cmocka/test_sdap.c
index a1f5188b745af9ede4cc54bc7e1ba5aadc4f07b4..404e100a841dbb157de7fa02864838d0412145f9 100644
--- a/src/tests/cmocka/test_sdap.c
+++ b/src/tests/cmocka/test_sdap.c
@@ -583,6 +583,40 @@ void test_parse_deref_map_mismatch(void **state)
     talloc_free(res);
 }
 
+void test_parse_secondary_oc(void **state)
+{
+    int ret;
+    struct sysdb_attrs *attrs;
+    struct parse_test_ctx *test_ctx = talloc_get_type_abort(*state,
+                                                      struct parse_test_ctx);
+    struct mock_ldap_entry test_rfc2307_group;
+    struct sdap_attr_map *map;
+
+    const char *oc_values[] = { "secondaryOC", NULL };
+    const char *uid_values[] = { "tgroup1", NULL };
+    struct mock_ldap_attr test_rfc2307_group_attrs[] = {
+        { .name = "objectClass", .values = oc_values },
+        { .name = "uid", .values = uid_values },
+        { NULL, NULL }
+    };
+
+    test_rfc2307_group.dn = "cn=testgroup,dc=example,dc=com";
+    test_rfc2307_group.attrs = test_rfc2307_group_attrs;
+    set_entry_parse(&test_rfc2307_group);
+
+    ret = sdap_copy_map(test_ctx, rfc2307_group_map, SDAP_OPTS_GROUP, &map);
+    assert_int_equal(ret, ERR_OK);
+    map[SDAP_OC_GROUP_ALT].name = discard_const("secondaryOC");
+
+    ret = sdap_parse_entry(test_ctx, &test_ctx->sh, &test_ctx->sm,
+                           map, SDAP_OPTS_GROUP,
+                           &attrs, false);
+    assert_int_equal(ret, ERR_OK);
+
+    talloc_free(map);
+    talloc_free(attrs);
+}
+
 /* Negative test - objectclass doesn't match the map */
 void test_parse_bad_oc(void **state)
 {
@@ -713,6 +747,9 @@ int main(int argc, const char *argv[])
         unit_test_setup_teardown(test_parse_deref_no_attrs,
                                  parse_entry_test_setup,
                                  parse_entry_test_teardown),
+        unit_test_setup_teardown(test_parse_secondary_oc,
+                                 parse_entry_test_setup,
+                                 parse_entry_test_teardown),
         /* Negative tests */
         unit_test_setup_teardown(test_parse_no_oc,
                                  parse_entry_test_setup,
-- 
1.9.3



More information about the sssd-devel mailing list