Skip to content

Commit

Permalink
TESTS: Removing part of responder_cache_req-tests
Browse files Browse the repository at this point in the history
If you call cache_req_[user|group]_by_filter_send() it than later calls
updated_[users|groups]_by_filter(), which adds filter that is called
"recent". This filter causes that only [users|groups] added after the
request started are returned.

This patch removes tests which use
cache_req_[user|group]_by_filter_send(), because the logic of those
tests is corrupted. The tests create [users|groups] and after it, they
call cache_req_[user|group]_by_filter_send(). So it is obvious that it
is not in the right manner.

Possible fix is rewrite the tests to create the entries in the callback.

Works around:
https://fedorahosted.org/sssd/ticket/2730

Reviewed-by: Michal Židek <mzidek@redhat.com>
  • Loading branch information
Petr Cech authored and jhrozek committed Aug 31, 2015
1 parent e0f2a78 commit bdf422f
Showing 1 changed file with 0 additions and 211 deletions.
211 changes: 0 additions & 211 deletions src/tests/cmocka/test_responder_cache_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -1710,54 +1710,6 @@ static void cache_req_user_by_filter_test_done(struct tevent_req *req)
ctx->tctx->done = true;
}

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;

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);

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();

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);

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_NAME2);

ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[1],
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;
Expand Down Expand Up @@ -1831,63 +1783,6 @@ void test_users_by_filter_notfound(void **state)
assert_true(check_leaks_pop(req_mem_ctx));
}

static void test_users_by_filter_multiple_domains_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
struct sss_domain_info *domain = 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);

domain = find_domain_by_name(test_ctx->tctx->dom,
"responder_cache_req_test_d", true);
assert_non_null(domain);

ret = sysdb_store_user(domain, TEST_USER_NAME, "pwd", 1000, 1000,
NULL, NULL, NULL, "cn="TEST_USER_NAME",dc=test", NULL,
NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);

ret = sysdb_store_user(domain, 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);

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();

req = cache_req_user_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
domain->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);

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_NAME2);

ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[1],
SYSDB_NAME, NULL);
assert_non_null(ldbname);
assert_string_equal(ldbname, TEST_USER_NAME);
}

static void test_users_by_filter_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
Expand Down Expand Up @@ -1934,53 +1829,6 @@ static void cache_req_group_by_filter_test_done(struct tevent_req *req)
ctx->tctx->done = true;
}

void test_groups_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_group = true;

ret = sysdb_store_group(test_ctx->tctx->dom, TEST_GROUP_NAME2,
1001, NULL, 1001, time(NULL));
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();

req = cache_req_group_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_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);

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_NAME2);

ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[1],
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;
Expand Down Expand Up @@ -2009,61 +1857,6 @@ void test_groups_by_filter_notfound(void **state)
assert_true(check_leaks_pop(req_mem_ctx));
}

void test_groups_by_filter_multiple_domains_valid(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
struct sss_domain_info *domain = 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);

domain = find_domain_by_name(test_ctx->tctx->dom,
"responder_cache_req_test_d", true);
assert_non_null(domain);

ret = sysdb_store_group(domain, TEST_GROUP_NAME,
1000, NULL, 1000, time(NULL));
assert_int_equal(ret, EOK);

ret = sysdb_store_group(domain, TEST_GROUP_NAME2,
1001, NULL, 1001, time(NULL));
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();

req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
test_ctx->rctx,
domain->name,
"test*");
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);

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_NAME2);

ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[1],
SYSDB_NAME, NULL);
assert_non_null(ldbname);
assert_string_equal(ldbname, TEST_GROUP_NAME);
}

void test_groups_by_filter_multiple_domains_notfound(void **state)
{
struct cache_req_test_ctx *test_ctx = NULL;
Expand Down Expand Up @@ -2145,14 +1938,10 @@ 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(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_valid),
new_multi_domain_test(users_by_filter_multiple_domains_notfound),
new_single_domain_test(groups_by_filter_valid),
new_single_domain_test(groups_by_filter_notfound),
new_multi_domain_test(groups_by_filter_multiple_domains_valid),
new_multi_domain_test(groups_by_filter_multiple_domains_notfound),
};

Expand Down

0 comments on commit bdf422f

Please sign in to comment.