On 11/09/2015 04:28 PM, Jakub Hrozek wrote:
On Thu, Nov 05, 2015 at 05:29:25PM +0100, Petr Cech wrote:
>On 11/04/2015 11:11 AM, Jakub Hrozek wrote:
> >Hi,
> >
> >Sorry it took so long to get back to the review.  I only have some minor
> >comments, see inline..
> >
> >Because the group patches are more or less equivalent, I'll just comment
> >here. If you agree with the comments, please also change the group tests
> >and resend in a single set.
> >
> >Thanks for the tests!
> >
> >>> From e3dd543eec09f6e4386bfe6f1505538575fe5356 Mon Sep 17 00:00:00 2001
> >>>From: Petr Cech<pc...@redhat.com>
> >>>Date: Fri, 2 Oct 2015 07:34:08 -0400
> >>>Subject: [PATCH 1/3] TEST: Add test_user_by_recent_filter_valid
> >>>
> >>>Test users_by_filter_valid() was removed in past. We will add two new
> >>>tests instead of it. Logic of those tests is connected to RECENT
> >>>filter. It returns only records which have been wrote or updated after
> >>>filter was created (or another given time).
> >>>
> >>>users_by_filter_valid() --> user_by_recent_filter_valid()
> >>>                             users_by_recent_filter_valid()
> >>>
> >>>The first of new tests, user_by_recent_filter_valid(), counts with two
> >>>users. One is stored before filter request creation and the second user
> >>>is stored after filter request creation. So filter returns only one
> >>>user.
> >>>
> >>>The second of new tests, users_by_recent_filter_valid(), counts with
> >>>three users. One is stored before filter request creation and two users
> >>>are stored after filter request creation. So filter returns two users.
> >>>
> >>>This patch adds user_by_recent_filter_valid().
> >>>
> >>>Resolves:
> >>>https://fedorahosted.org/sssd/ticket/2730
> >>>---
> >>>  src/tests/cmocka/test_responder_cache_req.c | 50 
+++++++++++++++++++++++++++++
> >>>  1 file changed, 50 insertions(+)
> >>>
> >>>diff --git a/src/tests/cmocka/test_responder_cache_req.c 
b/src/tests/cmocka/test_responder_cache_req.c
> >>>index 
744c8f4a8f7aa4e08f82aca5aea003438b5b59da..3379b17f7feea521966d6c8646afd9859a3c5255 100644
> >>>--- a/src/tests/cmocka/test_responder_cache_req.c
> >>>+++ b/src/tests/cmocka/test_responder_cache_req.c
> >>>@@ -1239,6 +1239,53 @@ static void 
cache_req_user_by_filter_test_done(struct tevent_req *req)
> >>>      ctx->tctx->done = true;
> >>>  }
> >>>
> >>>+void test_user_by_recent_filter_valid(void **state)
> >>>+{
> >>>+    struct cache_req_test_ctx *test_ctx = NULL;
> >>>+    TALLOC_CTX *req_mem_ctx = NULL;
> >>>+    struct tevent_req *req = NULL;
> >>>+    const char *ldbname = NULL;
> >>>+    errno_t ret;
> >>>+
> >>>+    test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
> >>>+    test_ctx->create_user = true;
> >>>+
> >>>+    ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME2, "pwd", 
1001, 1001,
> >>>+                           NULL, NULL, NULL, 
"cn="TEST_USER_NAME2",dc=test", NULL,
> >>>+                           NULL, 1000, time(NULL));
> >>>+    assert_int_equal(ret, EOK);
> >>>+
> >>>+    sleep(1);
> >The purpose of the sleep() here is just to make sure the entry was
> >created in the past, right? Would it be equally safe to create the user
> >with timestamp time(NULL)-1 to make the test faster?
> >
> >>>+
> >>>+    req_mem_ctx = talloc_new(test_ctx->tctx);
> >>>+    check_leaks_push(req_mem_ctx);
> >>>+
> >>>+    /* Filters always go to DP */
> >>>+    will_return(__wrap_sss_dp_get_account_send, test_ctx);
> >>>+    mock_account_recv_simple();
> >Can you add a comment that the TEST_USER is created with a DP callback
> >here?
> >
> >>>+
> >>>+    req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
> >>>+                                        test_ctx->rctx,
> >>>+                                        test_ctx->tctx->dom->name,
> >>>+                                        "test*");
> >It would read nicer if we had a constant TEST_USER_PREFIX "test_user" 
#defined,
> >or even TEST_USER_FILTER with the asterist.
> >
> >>>+    assert_non_null(req);
> >>>+
> >>>+    tevent_req_set_callback(req, cache_req_user_by_filter_test_done, 
test_ctx);
> >>>+
> >>>+    ret = test_ev_loop(test_ctx->tctx);
> >>>+    assert_int_equal(ret, ERR_OK);
> >>>+    assert_true(check_leaks_pop(req_mem_ctx));
> >>>+
> >>>+    assert_non_null(test_ctx->result);
> >>>+    assert_int_equal(test_ctx->result->count, 1);
> >>>+
> >>>+    ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
> >>>+                                          SYSDB_NAME, NULL);
> >>>+    assert_non_null(ldbname);
> >>>+    assert_string_equal(ldbname, TEST_USER_NAME);
> >>>+}
> >>> From c2e87544dfbc0667e1b935394d697322b34dddeb Mon Sep 17 00:00:00 2001
> >>>From: Petr Cech<pc...@redhat.com>
> >>>Date: Tue, 27 Oct 2015 03:53:18 -0400
> >>>Subject: [PATCH 2/3] TEST: Refactor of test_responder_cache_req.c
> >>>
> >>>We need little more in background of responder_cache_req tests. There
> >>>will be tests which will use three test users. This patch add support
> >>>for it.
> >>>
> >>>Resolves:
> >>>https://fedorahosted.org/sssd/ticket/2730
> >>>---
> >>>  src/tests/cmocka/test_responder_cache_req.c | 59 
+++++++++++++++++++++--------
> >>>  1 file changed, 44 insertions(+), 15 deletions(-)
> >>>
> >>>diff --git a/src/tests/cmocka/test_responder_cache_req.c 
b/src/tests/cmocka/test_responder_cache_req.c
> >>>index 
3379b17f7feea521966d6c8646afd9859a3c5255..a457d5f277314b75cd73b1306995665456df7f9d 100644
> >>>--- a/src/tests/cmocka/test_responder_cache_req.c
> >>>+++ b/src/tests/cmocka/test_responder_cache_req.c
> >>>@@ -39,8 +39,15 @@
> >>>  #define TEST_GROUP_NAME "test-group"
> >>>  #define TEST_GROUP_ID 1000
> >>>
> >>>-#define TEST_USER_NAME2 "test-user2"
> >>>-#define TEST_GROUP_NAME2 "test-group2"
> >>>+#define TEST_USER_ID2 1001
> >>>+#define TEST_USER_NAME2 "test_user2"
> >>>+#define TEST_GROUP_NAME2 "test_group2"
> >>>+#define TEST_GROUP_ID2 1001
> >>>+
> >>>+#define TEST_USER_ID3 1002
> >>>+#define TEST_USER_NAME3 "test_user3"
> >>>+#define TEST_GROUP_NAME3 "test_group3"
> >>>+#define TEST_GROUP_ID3 1002
> >>>
> >>>  #define new_single_domain_test(test) \
> >>>      cmocka_unit_test_setup_teardown(test_ ## test, \
> >>>@@ -82,7 +89,8 @@ struct cache_req_test_ctx {
> >>>      struct sss_domain_info *domain;
> >>>      char *name;
> >>>      bool dp_called;
> >>>-    bool create_user;
> >>>+    bool create_user1;
> >>>+    bool create_user2;
> >With just two booleans this might be OK, but if we end up adding more
> >users, then additional booleans might get clunky and maybe something
> >like a bitshift where the DP callback would test for a particular bit
> >set might be more generic? Can you add a comment so that the
> >next person touching the code won't add another boolean?
> >
> >>> From 99e1932b876186e702fcb20b6d0bdd5c7e07e1ba Mon Sep 17 00:00:00 2001
> >>>From: Petr Cech<pc...@redhat.com>
> >>>Date: Tue, 27 Oct 2015 04:02:46 -0400
> >>>Subject: [PATCH 3/3] TEST: Add test_users_by_recent_filter_valid
> >[...]
> >
> >>>+    assert_non_null(test_ctx->result);
> >>>+    assert_int_equal(test_ctx->result->count, 2);
> >>>+
> >>>+    ldbname1 = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
> >>>+                                           SYSDB_NAME, NULL);
> >>>+    assert_non_null(ldbname1);
> >>>+
> >>>+    ldbname2 = ldb_msg_find_attr_as_string(test_ctx->result->msgs[1],
> >>>+                                           SYSDB_NAME, NULL);
> >>>+    assert_non_null(ldbname2);
> >>>+
> >>>+    assert_string_not_equal(ldbname1, ldbname2);
> >>>+    comparison1 = strcmp(ldbname1, TEST_USER_NAME) == 0 ? true : false;
> >>>+    comparison2 = strcmp(ldbname1, TEST_USER_NAME2) == 0 ? true : false;
> >>>+    comparison3 = strcmp(ldbname2, TEST_USER_NAME) == 0 ? true : false;
> >>>+    comparison4 = strcmp(ldbname2, TEST_USER_NAME2) == 0 ? true : false;
> >>>+    assert_true((comparison1 || comparison2) && (comparison3 || 
comparison4));
> >>>+}
> >Can you extract this part into a common function that would accept a
> >ldb_result pointer and two usernames and would make sure they are in the
> >ldb_messages? The same pattern is used in the group tests.
> >
> >(I wonder if that could also be written in a nice and generic way for N
> >usernames in a string array, but it's not important at the moment)
>
>Hello Jakub,
>
>I addresed all hints. There are fixed patch set attached.
>
>Regards,
>
>Petr
>
>PS: I am still not sure what was the purpose of
>   * users_by_filter_multiple_domains_valid
>   * groups_by_filter_multiple_domains_valid
>tests. How I wrote earlier: "I am afraid I misunderstood their purpose.
>Because users/groups are set with the same domains." Please, do you remember
>their purpose?
Are these removed tests? In general for the wildcard test you're right
that we should try to add users into multiple domains..

These tests are next removed tests. You can see them here:
https://git.fedorahosted.org/cgit/sssd.git/commit/?id=bdf422fde0fd6b40b3412bad3b200f8fd7ea8693

They have broken logic like all removed in this ticket. But there is something more in their names is 'mulitple_domains' but I don't see that they actually work over multiple domains.


> From c380f1c1df0e891e89bded8e68eefb53a05131c7 Mon Sep 17 00:00:00 2001
>From: Petr Cech<pc...@redhat.com>
>Date: Fri, 2 Oct 2015 07:34:08 -0400
>Subject: [PATCH 1/7] TEST: Add test_user_by_recent_filter_valid
ACK except the call to sysdb_store_user() overflows 80 characters.
Fixed.


> From ab97caaf39b3b65416fa8a4a72a104a9a0391a48 Mon Sep 17 00:00:00 2001
>From: Petr Cech<pc...@redhat.com>
>Date: Wed, 4 Nov 2015 06:50:33 -0500
>Subject: [PATCH 2/7] TEST: Refactor of test_responder_cache_req.c
ACK

> From 21f44a019f2e4fcd97d3f3d25f4ab2ddedd1b93e Mon Sep 17 00:00:00 2001
>From: Petr Cech<pc...@redhat.com>
>Date: Tue, 27 Oct 2015 03:53:18 -0400
>Subject: [PATCH 3/7] TEST: Refactor of test_responder_cache_req.c
>
>We need little more in background of responder_cache_req tests. There
>will be tests which will use three test users. This patch add support
>for it.
ACK

> From beb13c2bd236355666127f8476966b29e6f33295 Mon Sep 17 00:00:00 2001
>From: Petr Cech<pc...@redhat.com>
>Date: Tue, 27 Oct 2015 04:02:46 -0400
>Subject: [PATCH 4/7] TEST: Add test_users_by_recent_filter_valid
>
>Test users_by_filter_valid() was removed in past. We will add two new
>tests instead of it. Logic of those tests is connected to RECENT
>filter. It returns only records which have been wrote or updated
>after filter was created (or another given time).
>
>users_by_filter_valid() --> user_by_recent_filter_valid()
>                             users_by_recent_filter_valid()
>
>The first of new tests, user_by_recent_filter_valid(), counts with
>two users. One is stored before filter request creation and the second
>user is stored after filter request creation. So filter returns only one
>user.
>
>The second of new tests, users_by_recent_filter_valid(), counts with
>three users. One is stored before filter request creation and two
>users are stored after filter request creation. So filter returns two
>users.
>
>This patch adds users_by_recent_filter_valid().
>
>Resolves:
>https://fedorahosted.org/sssd/ticket/2730
>---
>  src/tests/cmocka/test_responder_cache_req.c | 88 
++++++++++++++++++++++++++++-
>  1 file changed, 87 insertions(+), 1 deletion(-)
>
>diff --git a/src/tests/cmocka/test_responder_cache_req.c 
b/src/tests/cmocka/test_responder_cache_req.c
>index 
e5f92329fd06019eaccc18aa57756e59b72e815c..c25256a9d4685d66a818512e9d46edcacbdc65bd 
100644
>--- a/src/tests/cmocka/test_responder_cache_req.c
>+++ b/src/tests/cmocka/test_responder_cache_req.c
>@@ -113,6 +113,27 @@ struct cli_protocol_version 
*register_cli_protocol_version(void)
>      return version;
>  }
>
>+/* Return true if all values are in ldb_results */
>+static bool are_values_in_ldb_result(const char **ldb_results,
>+                                     const char **values)
Nice, thanks!
Thanks.


>+{
>+    bool is_value_in_result = false;
>+    bool is_value_in_results = false;
>+    bool result = true;
>+
>+    for (unsigned int i = 0; i < talloc_array_length(values); ++i) {
It's just a tradition, but we tend to prefer postfix instead of prefix.

>+        is_value_in_results = false;
>+        for (size_t j = 0; j < talloc_array_length(ldb_results); ++j) {
Please choose size_t or unsigned int for both (unless there is a reason
not to).
Fixed.


>+            is_value_in_result = strcmp(ldb_results[i], values[j]) == 0 ? \
>+                                 true : false;
>+            is_value_in_results = is_value_in_results || is_value_in_result;
>+        }
>+        result = result && is_value_in_results;
>+    }
>+
>+    return result;
>+}
>+
It would be better to split this function into a separate patch and add
it to the common test code, it is generally useful, not just for our
tests.

But I would also like another version of this function that doesn't rely
on talloc. Then the shorthand with talloc_array_lenght could use the
generic function:
     static bool are_values_in_ldb_result(const char **ldb_results,
                                          size_t results_len,
                                          const char **values,
                                          size_t values_len);

     #define tc_are_values_in_ldb_result(ldb_results, values)              \
             are_values_in_ldb_result(ldb_results,                         \
                                      talloc_array_length(ldb_results),    \
                                      values,                              \
                                      talloc_array_length(values))

(I haven't tried this at all, if it's not possible or practical for some
reason, just push back please)
Fixed.

Another useful wrapper might accept just struct ldb_result and find the
attribute like you do find SYSDB_NAME in the test.
It could be done in next patch set.

> From c464211d04e0dd5faff3a69e21808ca23d091309 Mon Sep 17 00:00:00 2001
>From: Petr Cech<pc...@redhat.com>
>Date: Sun, 1 Nov 2015 07:09:28 -0500
>Subject: [PATCH 5/7] TEST: Add test_group_by_recent_filter_valid
ACK

> From 60883b72a6f2d46ca1a20b335ce5658afca327c2 Mon Sep 17 00:00:00 2001
>From: Petr Cech<pc...@redhat.com>
>Date: Sun, 1 Nov 2015 07:21:18 -0500
>Subject: [PATCH 6/7] TEST: Refactor of test_responder_cache_req.c
ACK

> From b84ebcdfbe5786b5ac1e641cefcd3a20cc3c509a Mon Sep 17 00:00:00 2001
>From: Petr Cech<pc...@redhat.com>
>Date: Sun, 1 Nov 2015 07:45:56 -0500
>Subject: [PATCH 7/7] TEST: Add test_groups_by_recent_filter_valid
Mostly ack..
Thanks for review.

>+    ret = test_ev_loop(test_ctx->tctx);
>+    assert_int_equal(ret, ERR_OK);
>+    assert_true(check_leaks_pop(req_mem_ctx));
>+
>+    assert_non_null(test_ctx->result);
>+    assert_int_equal(test_ctx->result->count, 2);
>+
>+    tmp_ctx = talloc_zero(NULL, void *);
you can use test_ctx instead of NULL here. Normally we only use NULL
context to be able to run valgrind and see the leaks, but we might be
moving away from this pattern soon, so please just test_ctx in the
tests...
I refactored it by Pavels opinions.

Petr
>From e3fff09cf7e9c3cf6d6319fdd7cc8c7f99a713a9 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Fri, 2 Oct 2015 07:34:08 -0400
Subject: [PATCH 1/8] TEST: Add test_user_by_recent_filter_valid

Test users_by_filter_valid() was removed in past. We will add two new
tests instead of it. Logic of those tests is connected to RECENT
filter. It returns only records which have been wrote or updated after
filter was created (or another given time).

users_by_filter_valid() --> user_by_recent_filter_valid()
                            users_by_recent_filter_valid()

The first of new tests, user_by_recent_filter_valid(), counts with two
users. One is stored before filter request creation and the second user
is stored after filter request creation. So filter returns only one
user.

The second of new tests, users_by_recent_filter_valid(), counts with
three users. One is stored before filter request creation and two users
are stored after filter request creation. So filter returns two users.

This patch adds user_by_recent_filter_valid().

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 50 +++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index 744c8f4a8f7aa4e08f82aca5aea003438b5b59da..6e0781872ac1d743529496fa48788cba546473d4 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1239,6 +1239,53 @@ static void cache_req_user_by_filter_test_done(struct tevent_req *req)
     ctx->tctx->done = true;
 }
 
+void test_user_by_recent_filter_valid(void **state)
+{
+    struct cache_req_test_ctx *test_ctx = NULL;
+    TALLOC_CTX *req_mem_ctx = NULL;
+    struct tevent_req *req = NULL;
+    const char *ldbname = NULL;
+    errno_t ret;
+
+    test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
+    test_ctx->create_user = true;
+
+    ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME2,
+                           "pwd", 1001, 1001, NULL, NULL, NULL,
+                           "cn="TEST_USER_NAME2",dc=test",
+                           NULL, NULL, 1000, time(NULL)-1);
+    assert_int_equal(ret, EOK);
+
+    req_mem_ctx = talloc_new(test_ctx->tctx);
+    check_leaks_push(req_mem_ctx);
+
+    /* Filters always go to DP */
+    will_return(__wrap_sss_dp_get_account_send, test_ctx);
+    mock_account_recv_simple();
+
+    /* User TEST_USER is created with a DP callback. */
+    req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
+                                        test_ctx->rctx,
+                                        test_ctx->tctx->dom->name,
+                                        "test*");
+    assert_non_null(req);
+
+    tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
+
+    ret = test_ev_loop(test_ctx->tctx);
+    assert_int_equal(ret, ERR_OK);
+    assert_true(check_leaks_pop(req_mem_ctx));
+
+    assert_non_null(test_ctx->result);
+    assert_int_equal(test_ctx->result->count, 1);
+
+    ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
+                                          SYSDB_NAME, NULL);
+    assert_non_null(ldbname);
+    assert_string_equal(ldbname, TEST_USER_NAME);
+}
+
+
 void test_users_by_filter_filter_old(void **state)
 {
     struct cache_req_test_ctx *test_ctx = NULL;
@@ -1476,11 +1523,14 @@ int main(int argc, const char *argv[])
         new_multi_domain_test(group_by_id_multiple_domains_found),
         new_multi_domain_test(group_by_id_multiple_domains_notfound),
 
+        new_single_domain_test(user_by_recent_filter_valid),
+
         new_single_domain_test(users_by_filter_filter_old),
         new_single_domain_test(users_by_filter_notfound),
         new_multi_domain_test(users_by_filter_multiple_domains_notfound),
         new_single_domain_test(groups_by_filter_notfound),
         new_multi_domain_test(groups_by_filter_multiple_domains_notfound),
+
     };
 
     /* Set debug level to invalid value so we can deside if -d 0 was used. */
-- 
2.4.3

>From 02829e5394d7aee88dd000257f006ca714c79230 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Wed, 4 Nov 2015 06:50:33 -0500
Subject: [PATCH 2/8] TEST: Refactor of test_responder_cache_req.c

This patch only defines constant TEST_USER_FILTER. So code will be more
redeable.

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index 6e0781872ac1d743529496fa48788cba546473d4..c28fc4bd6d8d1e7a953519aff2ea85956347a9b4 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -42,6 +42,8 @@
 #define TEST_USER_NAME2 "test-user2"
 #define TEST_GROUP_NAME2 "test-group2"
 
+#define TEST_USER_PREFIX "test*"
+
 #define new_single_domain_test(test) \
     cmocka_unit_test_setup_teardown(test_ ## test, \
                                     test_single_domain_setup, \
@@ -1267,7 +1269,7 @@ void test_user_by_recent_filter_valid(void **state)
     req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
                                         test_ctx->rctx,
                                         test_ctx->tctx->dom->name,
-                                        "test*");
+                                        TEST_USER_PREFIX);
     assert_non_null(req);
 
     tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
@@ -1314,7 +1316,7 @@ void test_users_by_filter_filter_old(void **state)
     req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
                                         test_ctx->rctx,
                                         test_ctx->tctx->dom->name,
-                                        "test*");
+                                        TEST_USER_PREFIX);
     assert_non_null(req);
     tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
 
-- 
2.4.3

>From 8fe78a1a0554b55f4ae822361599bbed67033989 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Tue, 27 Oct 2015 03:53:18 -0400
Subject: [PATCH 3/8] TEST: Refactor of test_responder_cache_req.c

We need little more in background of responder_cache_req tests. There
will be tests which will use three test users. This patch add support
for it.

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 61 ++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 15 deletions(-)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index c28fc4bd6d8d1e7a953519aff2ea85956347a9b4..d7d74972347852eee90f1be3d4d2dd8360e0ce08 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -39,8 +39,15 @@
 #define TEST_GROUP_NAME "test-group"
 #define TEST_GROUP_ID 1000
 
-#define TEST_USER_NAME2 "test-user2"
-#define TEST_GROUP_NAME2 "test-group2"
+#define TEST_USER_ID2 1001
+#define TEST_USER_NAME2 "test_user2"
+#define TEST_GROUP_NAME2 "test_group2"
+#define TEST_GROUP_ID2 1001
+
+#define TEST_USER_ID3 1002
+#define TEST_USER_NAME3 "test_user3"
+#define TEST_GROUP_NAME3 "test_group3"
+#define TEST_GROUP_ID3 1002
 
 #define TEST_USER_PREFIX "test*"
 
@@ -84,7 +91,10 @@ struct cache_req_test_ctx {
     struct sss_domain_info *domain;
     char *name;
     bool dp_called;
-    bool create_user;
+
+    /* NOTE: Please, instead of adding new create_user bool, use bitshift. */
+    bool create_user1;
+    bool create_user2;
     bool create_group;
 };
 
@@ -159,10 +169,13 @@ static void cache_req_group_by_id_test_done(struct tevent_req *req)
     ctx->tctx->done = true;
 }
 
-static void prepare_user(TALLOC_CTX *mem_ctx,
-                         struct sss_domain_info *domain,
-                         uint64_t timeout,
-                         time_t time)
+static void prepare_concrete_user(TALLOC_CTX *mem_ctx,
+                                  struct sss_domain_info *domain,
+                                  const char* user_name,
+                                  int user_id,
+                                  int group_id,
+                                  uint64_t timeout,
+                                  time_t time)
 {
     struct sysdb_attrs *attrs;
     errno_t ret;
@@ -173,13 +186,22 @@ static void prepare_user(TALLOC_CTX *mem_ctx,
     ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, TEST_UPN);
     assert_int_equal(ret, EOK);
 
-    ret = sysdb_store_user(domain, TEST_USER_NAME, "pwd",
-                           TEST_USER_ID, TEST_GROUP_ID, NULL, NULL, NULL,
+    ret = sysdb_store_user(domain, user_name, "pwd",
+                           user_id, group_id, NULL, NULL, NULL,
                            "cn=test-user,dc=test", attrs, NULL,
                            timeout, time);
     assert_int_equal(ret, EOK);
 }
 
+static void prepare_user(TALLOC_CTX *mem_ctx,
+                         struct sss_domain_info *domain,
+                         uint64_t timeout,
+                         time_t time)
+{
+    prepare_concrete_user(mem_ctx, domain, TEST_USER_NAME, TEST_USER_ID,
+                          TEST_GROUP_ID, timeout, time);
+}
+
 static void run_user_by_name(struct cache_req_test_ctx *test_ctx,
                              struct sss_domain_info *domain,
                              int cache_refresh_percent,
@@ -313,9 +335,13 @@ __wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
     ctx = sss_mock_ptr_type(struct cache_req_test_ctx*);
     ctx->dp_called = true;
 
-    if (ctx->create_user) {
+    if (ctx->create_user1) {
         prepare_user(ctx, ctx->tctx->dom, 1000, time(NULL));
     }
+    if (ctx->create_user2) {
+        prepare_concrete_user(mem_ctx, ctx->tctx->dom, TEST_USER_NAME2,
+                              TEST_USER_ID2, TEST_GROUP_ID2, 1000, time(NULL));
+    }
 
     if (ctx->create_group) {
         ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
@@ -570,7 +596,8 @@ void test_user_by_name_missing_found(void **state)
     will_return(__wrap_sss_dp_get_account_send, test_ctx);
     mock_account_recv_simple();
 
-    test_ctx->create_user = true;
+    test_ctx->create_user1 = true;
+    test_ctx->create_user2 = false;
 
     /* Test. */
     run_user_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
@@ -723,7 +750,8 @@ void test_user_by_upn_missing_found(void **state)
     mock_account_recv_simple();
     mock_parse_inp(NULL, NULL, ERR_DOMAIN_NOT_FOUND);
 
-    test_ctx->create_user = true;
+    test_ctx->create_user1 = true;
+    test_ctx->create_user2 = false;
 
     /* Test. */
     run_user_by_upn(test_ctx, NULL, 0, ERR_OK);
@@ -865,7 +893,8 @@ void test_user_by_id_missing_found(void **state)
     will_return(__wrap_sss_dp_get_account_send, test_ctx);
     mock_account_recv_simple();
 
-    test_ctx->create_user = true;
+    test_ctx->create_user1 = true;
+    test_ctx->create_user2 = false;
 
     /* Test. */
     run_user_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
@@ -1250,7 +1279,8 @@ void test_user_by_recent_filter_valid(void **state)
     errno_t ret;
 
     test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
-    test_ctx->create_user = true;
+    test_ctx->create_user1 = true;
+    test_ctx->create_user2 = false;
 
     ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME2,
                            "pwd", 1001, 1001, NULL, NULL, NULL,
@@ -1297,7 +1327,8 @@ void test_users_by_filter_filter_old(void **state)
     errno_t ret;
 
     test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
-    test_ctx->create_user = true;
+    test_ctx->create_user1 = true;
+    test_ctx->create_user2 = false;
 
     /* This user was updated in distant past, so it wont't be reported by
      * the filter search */
-- 
2.4.3

>From eb42f31d723f97b703253455649ba5cd80d1d4cf Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Tue, 10 Nov 2015 06:04:45 -0500
Subject: [PATCH 4/8] TEST: Add common function are_values_in_array()

This patch adds function are_values_in_array() to common test code. And
there is tc_are_values_in_array macro defined which is usefull for
talloc allocated values and arrays.

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/common.c | 21 +++++++++++++++++++++
 src/tests/common.h |  8 ++++++++
 2 files changed, 29 insertions(+)

diff --git a/src/tests/common.c b/src/tests/common.c
index 9655cd3ce5f863d8f07c6a186d3f25177eb330af..8ba73a2ef100c69a7e990098d4c77a060a3dd1c3 100644
--- a/src/tests/common.c
+++ b/src/tests/common.c
@@ -118,3 +118,24 @@ bool ldb_modules_path_is_set(void)
 
     return false;
 }
+
+/* Returns true if all values are in array (else returns false) */
+bool are_values_in_array(const char **values, size_t values_len,
+                         const char **array, size_t array_len)
+{
+    bool is_value_in_element = false;
+    bool is_value_in_array = false;
+    bool ret = true;
+
+    for (size_t i = 0; i < values_len; i++) {
+        is_value_in_array = false;
+        for (size_t j = 0; j < array_len; j++) {
+            is_value_in_element = strcmp(values[i], array[j]) == 0 ? \
+                                 true : false;
+            is_value_in_array = is_value_in_array || is_value_in_element;
+        }
+        ret = ret && is_value_in_array;
+    }
+
+    return ret;
+}
diff --git a/src/tests/common.h b/src/tests/common.h
index c0ceebfbf5d9277a422065fbe4ddfdd65c758de8..83fec844528246b0f94d6bc27bf8d950ff83ff08 100644
--- a/src/tests/common.h
+++ b/src/tests/common.h
@@ -138,4 +138,12 @@ struct sss_domain_info *named_domain(TALLOC_CTX *mem_ctx,
                                      const char *name,
                                      struct sss_domain_info *parent);
 
+/* Returns true if all values are in array (else returns false) */
+bool are_values_in_array(const char **values, size_t values_len,
+                         const char **array, size_t array_len);
+
+#define tc_are_values_in_array(values, array) \
+        are_values_in_array(values, talloc_array_length(values), \
+                            array, talloc_array_length(array))
+
 #endif /* !__TESTS_COMMON_H__ */
-- 
2.4.3

>From 8bd77671937b959365384bf3c52e9a5d314389e2 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Tue, 27 Oct 2015 04:02:46 -0400
Subject: [PATCH 5/8] TEST: Add test_users_by_recent_filter_valid

Test users_by_filter_valid() was removed in past. We will add two new
tests instead of it. Logic of those tests is connected to RECENT
filter. It returns only records which have been wrote or updated
after filter was created (or another given time).

users_by_filter_valid() --> user_by_recent_filter_valid()
                            users_by_recent_filter_valid()

The first of new tests, user_by_recent_filter_valid(), counts with
two users. One is stored before filter request creation and the second
user is stored after filter request creation. So filter returns only one
user.

The second of new tests, users_by_recent_filter_valid(), counts with
three users. One is stored before filter request creation and two
users are stored after filter request creation. So filter returns two
users.

This patch adds users_by_recent_filter_valid().

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 68 ++++++++++++++++++++++++++++-
 1 file changed, 67 insertions(+), 1 deletion(-)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index d7d74972347852eee90f1be3d4d2dd8360e0ce08..e9e95bb5978b9037dc250d2f6d84564441364a03 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -318,7 +318,6 @@ static void check_group(struct cache_req_test_ctx *test_ctx,
     assert_string_equal(exp_dom->name, test_ctx->domain->name);
 }
 
-
 struct tevent_req *
 __wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
                                struct resp_ctx *rctx,
@@ -1317,6 +1316,72 @@ void test_user_by_recent_filter_valid(void **state)
     assert_string_equal(ldbname, TEST_USER_NAME);
 }
 
+void test_users_by_recent_filter_valid(void **state)
+{
+    struct cache_req_test_ctx *test_ctx = NULL;
+    TALLOC_CTX *req_mem_ctx = NULL;
+    TALLOC_CTX *tmp_ctx = NULL;
+    struct tevent_req *req = NULL;
+    const char **user_names = NULL;
+    const char **ldb_results = NULL;
+    const char *ldbname = NULL;
+    errno_t ret;
+
+    test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
+    test_ctx->create_user1 = true;
+    test_ctx->create_user2 = true;
+
+    ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME3,
+                           "pwd", 1002, 1002, NULL, NULL, NULL,
+                           "cn="TEST_USER_NAME3",dc=test",
+                           NULL, NULL, 1000, time(NULL)-1);
+    assert_int_equal(ret, EOK);
+
+    req_mem_ctx = talloc_new(test_ctx->tctx);
+    check_leaks_push(req_mem_ctx);
+
+    /* Filters always go to DP */
+    will_return(__wrap_sss_dp_get_account_send, test_ctx);
+    mock_account_recv_simple();
+
+    /* User TEST_USER1 and TEST_USER2 are created with a DP callback. */
+    req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
+                                        test_ctx->rctx,
+                                        test_ctx->tctx->dom->name,
+                                        TEST_USER_PREFIX);
+    assert_non_null(req);
+
+    tevent_req_set_callback(req, cache_req_user_by_filter_test_done, test_ctx);
+
+    ret = test_ev_loop(test_ctx->tctx);
+    assert_int_equal(ret, ERR_OK);
+    assert_true(check_leaks_pop(req_mem_ctx));
+
+    assert_non_null(test_ctx->result);
+    assert_int_equal(test_ctx->result->count, 2);
+
+    tmp_ctx = talloc_new(req_mem_ctx);
+
+    user_names = talloc_array(tmp_ctx, const char *, 2);
+    assert_non_null(user_names);
+    user_names[0] = TEST_USER_NAME;
+    user_names[1] = TEST_USER_NAME2;
+
+    ldb_results = talloc_array(tmp_ctx, const char *, 2);
+    assert_non_null(ldb_results);
+    for (int i = 0; i < 2; ++i) {
+        ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i],
+                                              SYSDB_NAME, NULL);
+        assert_non_null(ldbname);
+        ldb_results[i] = ldbname;
+    }
+
+    assert_string_not_equal(ldb_results[0], ldb_results[1]);
+
+    assert_true(tc_are_values_in_array(user_names, ldb_results));
+
+    talloc_zfree(tmp_ctx);
+}
 
 void test_users_by_filter_filter_old(void **state)
 {
@@ -1557,6 +1622,7 @@ int main(int argc, const char *argv[])
         new_multi_domain_test(group_by_id_multiple_domains_notfound),
 
         new_single_domain_test(user_by_recent_filter_valid),
+        new_single_domain_test(users_by_recent_filter_valid),
 
         new_single_domain_test(users_by_filter_filter_old),
         new_single_domain_test(users_by_filter_notfound),
-- 
2.4.3

>From 56011ccb9c364373ac12eedb29351aec2d05bc0e Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Sun, 1 Nov 2015 07:09:28 -0500
Subject: [PATCH 6/8] TEST: Add test_group_by_recent_filter_valid

Test groups_by_filter_valid() was removed in past. We will add two new
tests instead of it. Logic of those tests is connected to RECENT
filter. It returns only records which have been wrote or updated after
filter was created (or another given time).

groups_by_filter_valid() --> group_by_recent_filter_valid()
                             grous_by_recent_filter_valid()

The first of new tests, group_by_recent_filter_valid(), counts with two
groups. One is stored before filter request creation and the second
group is stored after filter request creation. So filter returns only
one group.

The second of new tests, groups_by_recent_filter_valid(), counts with
three users. One is stored before filter request creation and two
groups are stored after filter request creation. So filter returns two
groups.

This patch adds group_by_recent_filter_valid().

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 44 +++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index e9e95bb5978b9037dc250d2f6d84564441364a03..8db8c34817838efa9e50e2fd45f19657b94c2958 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1503,6 +1503,49 @@ static void cache_req_group_by_filter_test_done(struct tevent_req *req)
     ctx->tctx->done = true;
 }
 
+void test_group_by_recent_filter_valid(void **state)
+{
+    struct cache_req_test_ctx *test_ctx = NULL;
+    TALLOC_CTX *req_mem_ctx = NULL;
+    struct tevent_req *req = NULL;
+    const char *ldbname = NULL;
+    errno_t ret;
+
+    test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
+    test_ctx->create_group = true;
+
+    ret = sysdb_store_group(test_ctx->tctx->dom, TEST_GROUP_NAME2,
+                            1001, NULL, 1001, time(NULL)-1);
+    assert_int_equal(ret, EOK);
+
+    req_mem_ctx = talloc_new(global_talloc_context);
+    check_leaks_push(req_mem_ctx);
+
+    /* Filters always go to DP */
+    will_return(__wrap_sss_dp_get_account_send, test_ctx);
+    mock_account_recv_simple();
+
+    /* Group TEST_GROUP is created with a DP callback. */
+    req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
+                                         test_ctx->rctx,
+                                         test_ctx->tctx->dom->name,
+                                         TEST_USER_PREFIX);
+    assert_non_null(req);
+    tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
+
+    ret = test_ev_loop(test_ctx->tctx);
+    assert_int_equal(ret, ERR_OK);
+    assert_true(check_leaks_pop(req_mem_ctx));
+
+    assert_non_null(test_ctx->result);
+    assert_int_equal(test_ctx->result->count, 1);
+
+    ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
+                                          SYSDB_NAME, NULL);
+    assert_non_null(ldbname);
+    assert_string_equal(ldbname, TEST_GROUP_NAME);
+}
+
 void test_groups_by_filter_notfound(void **state)
 {
     struct cache_req_test_ctx *test_ctx = NULL;
@@ -1623,6 +1666,7 @@ int main(int argc, const char *argv[])
 
         new_single_domain_test(user_by_recent_filter_valid),
         new_single_domain_test(users_by_recent_filter_valid),
+        new_single_domain_test(group_by_recent_filter_valid),
 
         new_single_domain_test(users_by_filter_filter_old),
         new_single_domain_test(users_by_filter_notfound),
-- 
2.4.3

>From ec90c9480aebcc4386b5a04da916b5901469f2d6 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Sun, 1 Nov 2015 07:21:18 -0500
Subject: [PATCH 7/8] TEST: Refactor of test_responder_cache_req.c

We need little more in backroung of responder_cache_req tests. There
will be tests which will use three test groups. This patch add support
for it.

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index 8db8c34817838efa9e50e2fd45f19657b94c2958..d68f5276dfe92f218f50cc10e406c9d68cd3759c 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -92,10 +92,12 @@ struct cache_req_test_ctx {
     char *name;
     bool dp_called;
 
-    /* NOTE: Please, instead of adding new create_user bool, use bitshift. */
+    /* NOTE: Please, instead of adding new create_[user|group] bool,
+     * use bitshift. */
     bool create_user1;
     bool create_user2;
-    bool create_group;
+    bool create_group1;
+    bool create_group2;
 };
 
 const char *domains[] = {"responder_cache_req_test_a",
@@ -342,11 +344,17 @@ __wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
                               TEST_USER_ID2, TEST_GROUP_ID2, 1000, time(NULL));
     }
 
-    if (ctx->create_group) {
+    if (ctx->create_group1) {
         ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
                                 TEST_GROUP_ID, NULL, 1000, time(NULL));
         assert_int_equal(ret, EOK);
     }
+    if (ctx->create_group2) {
+        ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME2,
+                                TEST_GROUP_ID2, NULL, 1000, time(NULL));
+        assert_int_equal(ret, EOK);
+    }
+
 
     return test_req_succeed_send(mem_ctx, rctx->ev);
 }
@@ -1093,7 +1101,8 @@ void test_group_by_name_missing_found(void **state)
     will_return(__wrap_sss_dp_get_account_send, test_ctx);
     mock_account_recv_simple();
 
-    test_ctx->create_group = true;
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = false;
 
     /* Test. */
     run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
@@ -1233,7 +1242,8 @@ void test_group_by_id_missing_found(void **state)
     will_return(__wrap_sss_dp_get_account_send, test_ctx);
     mock_account_recv_simple();
 
-    test_ctx->create_group = true;
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = false;
 
     /* Test. */
     run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
@@ -1512,7 +1522,8 @@ void test_group_by_recent_filter_valid(void **state)
     errno_t ret;
 
     test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
-    test_ctx->create_group = true;
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = false;
 
     ret = sysdb_store_group(test_ctx->tctx->dom, TEST_GROUP_NAME2,
                             1001, NULL, 1001, time(NULL)-1);
-- 
2.4.3

>From a41aedd80a9ad7e01f7b49b4ed9df1acd12b3e0a Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Sun, 1 Nov 2015 07:45:56 -0500
Subject: [PATCH 8/8] TEST: Add test_groups_by_recent_filter_valid

Test groups_by_filter_valid() was removed in past. We will add two new
tests instead of it. Logic of those tests is connected to RECENT
filter. It returns only records which have been wrote or updated after
filter was created (or another given time).

groups_by_filter_valid() --> group_by_recent_filter_valid()
                             grous_by_recent_filter_valid()

The first of new tests, group_by_recent_filter_valid(), counts with two
groups. One is stored before filter request creation and the second
group is stored after filter request creation. So filter returns only
one group.

The second of new tests, groups_by_recent_filter_valid(), counts with
three users. One is stored before filter request creation and two
groups are stored after filter request creation. So filter returns two
groups.

This patch adds groups_by_recent_filter_valid().

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 68 +++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index d68f5276dfe92f218f50cc10e406c9d68cd3759c..289600e2d86dd1cc8034985452e255093164643b 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1557,6 +1557,73 @@ void test_group_by_recent_filter_valid(void **state)
     assert_string_equal(ldbname, TEST_GROUP_NAME);
 }
 
+void test_groups_by_recent_filter_valid(void **state)
+{
+    struct cache_req_test_ctx *test_ctx = NULL;
+    TALLOC_CTX *req_mem_ctx = NULL;
+    TALLOC_CTX *tmp_ctx = NULL;
+    struct tevent_req *req = NULL;
+    const char **group_names = NULL;
+    const char **ldb_results = NULL;
+    const char *ldbname = NULL;
+    errno_t ret;
+
+    test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = true;
+
+    ret = sysdb_store_group(test_ctx->tctx->dom, TEST_GROUP_NAME2,
+                            1001, NULL, 1001, time(NULL));
+    assert_int_equal(ret, EOK);
+
+    sleep(1);
+
+    req_mem_ctx = talloc_new(global_talloc_context);
+    check_leaks_push(req_mem_ctx);
+
+    /* Filters always go to DP */
+    will_return(__wrap_sss_dp_get_account_send, test_ctx);
+    mock_account_recv_simple();
+
+    /* Group TEST_GROUP1 and TEST_GROUP2 are created with a DP callback. */
+    req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
+                                         test_ctx->rctx,
+                                         test_ctx->tctx->dom->name,
+                                         TEST_USER_PREFIX);
+    assert_non_null(req);
+
+    tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
+
+    ret = test_ev_loop(test_ctx->tctx);
+    assert_int_equal(ret, ERR_OK);
+    assert_true(check_leaks_pop(req_mem_ctx));
+
+    assert_non_null(test_ctx->result);
+    assert_int_equal(test_ctx->result->count, 2);
+
+    tmp_ctx = talloc_new(req_mem_ctx);
+
+    group_names = talloc_array(tmp_ctx, const char *, 2);
+    assert_non_null(group_names);
+    group_names[0] = TEST_GROUP_NAME;
+    group_names[1] = TEST_GROUP_NAME2;
+
+    ldb_results = talloc_array(tmp_ctx, const char *, 2);
+    assert_non_null(ldb_results);
+    for (int i = 0; i < 2; ++i) {
+        ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i],
+                                              SYSDB_NAME, NULL);
+        assert_non_null(ldbname);
+        ldb_results[i] = ldbname;
+    }
+
+    assert_string_not_equal(ldb_results[0], ldb_results[1]);
+
+    assert_true(tc_are_values_in_array(group_names, ldb_results));
+
+    talloc_zfree(tmp_ctx);
+}
+
 void test_groups_by_filter_notfound(void **state)
 {
     struct cache_req_test_ctx *test_ctx = NULL;
@@ -1678,6 +1745,7 @@ int main(int argc, const char *argv[])
         new_single_domain_test(user_by_recent_filter_valid),
         new_single_domain_test(users_by_recent_filter_valid),
         new_single_domain_test(group_by_recent_filter_valid),
+        new_single_domain_test(groups_by_recent_filter_valid),
 
         new_single_domain_test(users_by_filter_filter_old),
         new_single_domain_test(users_by_filter_notfound),
-- 
2.4.3

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to