On 10/23/2015 12:57 PM, Jakub Hrozek wrote:
Thank you, I think your approach is correct. Your test essentially tests
that testuser2 was on the server but was removed, so only testuser1 is
returned.

It's correct, but because the interface is able to return more users, I
would prefer if we tested that as well.

I have one more minor remark inline, but in general, please go
ahead and add back the other tests..

Hello Jakub and everyone!

The first patch set is attached.

The removed tests were:
 * users_by_filter_valid
 * users_by_filter_multiple_domains_valid
 * groups_by_filter_valid
 * groups_by_filter_multiple_domains_valid

This patch set covers users_by_filter_valid by two new tests:
 * user_by_recent_filter_valid
 * users_by_recent_filter_valid

The first of them tests the recent filter. The seconds tests interface ability to return more users.

Regards,

Petr
>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);
+
+    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();
+
+    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 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;
     bool create_group;
 };
 
@@ -157,10 +165,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;
@@ -171,13 +182,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,
@@ -311,9 +331,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,
@@ -568,7 +592,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);
@@ -721,7 +746,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);
@@ -863,7 +889,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);
@@ -1248,7 +1275,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, "cn="TEST_USER_NAME2",dc=test", NULL,
@@ -1295,7 +1323,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 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

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 | 62 +++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index a457d5f277314b75cd73b1306995665456df7f9d..e4fccdab883f267cced1cf2e9995bd9828242690 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1313,6 +1313,67 @@ 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;
+    struct tevent_req *req = NULL;
+    const char *ldbname1 = NULL;
+    const char *ldbname2 = NULL;
+    bool comparison1 = false;
+    bool comparison2 = false;
+    bool comparison3 = false;
+    bool comparison4 = false;
+    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));
+    assert_int_equal(ret, EOK);
+
+    sleep(1);
+
+    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();
+
+    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, 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));
+}
 
 void test_users_by_filter_filter_old(void **state)
 {
@@ -1553,6 +1614,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

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

Reply via email to