>From aa0b0ab7c0a95ff47d5003907730c5432ff7bb85 Mon Sep 17 00:00:00 2001
From: Petr Cech <pcech@redhat.com>
Date: Fri, 2 Oct 2015 07:34:08 -0400
Subject: [PATCH] TEST: recent_valid filter testing

Some tests were removed in past. This is only WiP, not regular patch.
I rewrote one of the removed test. Is it this right way?

We speak about RECENT filter. It returns only records which
have been wrote or updated after filter was created (or another given
time). Some notes are written in comments of this patch.

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

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index bb79fd10eefd7186f17a1f9306b57ddca2e3279f..c01d92fd9f3f078d853da1642e63cdbc3a1aed7b 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1239,6 +1239,58 @@ static void cache_req_user_by_filter_test_done(struct tevent_req *req)
     ctx->tctx->done = true;
 }
 
+/* NOTE better name is filter_recent_valid */
+void test_users_by_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;
+
+    /* NOTE This user (#2) is stored before filter creation. */
+    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);
+
+    /* NOTE To make sure that the times of user/filter creation will vary.*/
+    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();
+
+    /* NOTE During this call the TEST_USER_NAME (#1) will be stored. */
+    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));
+
+    /* NOTE We receive only user #1, because #2 was stored before filter was created. */
+    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;
@@ -1429,7 +1481,7 @@ int main(int argc, const char *argv[])
     };
 
     const struct CMUnitTest tests[] = {
-        new_single_domain_test(user_by_name_cache_valid),
+/*        new_single_domain_test(user_by_name_cache_valid),
         new_single_domain_test(user_by_name_cache_expired),
         new_single_domain_test(user_by_name_cache_midpoint),
         new_single_domain_test(user_by_name_ncache),
@@ -1475,13 +1527,17 @@ int main(int argc, const char *argv[])
         new_single_domain_test(group_by_id_missing_notfound),
         new_multi_domain_test(group_by_id_multiple_domains_found),
         new_multi_domain_test(group_by_id_multiple_domains_notfound),
+*/
+        new_single_domain_test(users_by_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. */
     debug_level = SSSDBG_INVALID;
-- 
2.4.3

