|
|
9f2ebf |
From 9a4c06ddf5ec8d610f49acf5d3e231d36b37c50b Mon Sep 17 00:00:00 2001
|
|
|
9f2ebf |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
9f2ebf |
Date: Sun, 19 Nov 2017 17:25:02 +0100
|
|
|
9f2ebf |
Subject: [PATCH 77/83] TESTS: Add tests for the object-by-id cache_req
|
|
|
9f2ebf |
interface
|
|
|
9f2ebf |
MIME-Version: 1.0
|
|
|
9f2ebf |
Content-Type: text/plain; charset=UTF-8
|
|
|
9f2ebf |
Content-Transfer-Encoding: 8bit
|
|
|
9f2ebf |
|
|
|
9f2ebf |
This interface will be extended in later patches, but had no tests at
|
|
|
9f2ebf |
all.
|
|
|
9f2ebf |
|
|
|
9f2ebf |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
9f2ebf |
Reviewed-by: Sumit Bose <sbose@redhat.com>
|
|
|
9f2ebf |
(cherry picked from commit 6cd367da68ff56eb48b8b4167dbdd5e53992d194)
|
|
|
9f2ebf |
---
|
|
|
9f2ebf |
src/tests/cmocka/test_responder_cache_req.c | 385 ++++++++++++++++++++++++++++
|
|
|
9f2ebf |
1 file changed, 385 insertions(+)
|
|
|
9f2ebf |
|
|
|
9f2ebf |
diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
|
|
|
9f2ebf |
index 80086232fd437876c2b190fb972c2ee3194d9efd..f075480a019e476407a3081a795c3c289455aca8 100644
|
|
|
9f2ebf |
--- a/src/tests/cmocka/test_responder_cache_req.c
|
|
|
9f2ebf |
+++ b/src/tests/cmocka/test_responder_cache_req.c
|
|
|
9f2ebf |
@@ -197,6 +197,18 @@ static void cache_req_object_by_sid_test_done(struct tevent_req *req)
|
|
|
9f2ebf |
ctx->tctx->done = true;
|
|
|
9f2ebf |
}
|
|
|
9f2ebf |
|
|
|
9f2ebf |
+static void cache_req_object_by_id_test_done(struct tevent_req *req)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *ctx = NULL;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ ctx = tevent_req_callback_data(req, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ ctx->tctx->error = cache_req_object_by_id_recv(ctx, req, &ctx->result);
|
|
|
9f2ebf |
+ talloc_zfree(req);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ ctx->tctx->done = true;
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
static void prepare_user(struct sss_domain_info *domain,
|
|
|
9f2ebf |
struct test_user *user,
|
|
|
9f2ebf |
uint64_t timeout,
|
|
|
9f2ebf |
@@ -417,6 +429,33 @@ static void run_object_by_sid(struct cache_req_test_ctx *test_ctx,
|
|
|
9f2ebf |
talloc_free(req_mem_ctx);
|
|
|
9f2ebf |
}
|
|
|
9f2ebf |
|
|
|
9f2ebf |
+static void run_object_by_id(struct cache_req_test_ctx *test_ctx,
|
|
|
9f2ebf |
+ struct sss_domain_info *domain,
|
|
|
9f2ebf |
+ id_t id,
|
|
|
9f2ebf |
+ const char **attrs,
|
|
|
9f2ebf |
+ int cache_refresh_percent,
|
|
|
9f2ebf |
+ errno_t exp_ret)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ TALLOC_CTX *req_mem_ctx;
|
|
|
9f2ebf |
+ struct tevent_req *req;
|
|
|
9f2ebf |
+ errno_t ret;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ req_mem_ctx = talloc_new(global_talloc_context);
|
|
|
9f2ebf |
+ check_leaks_push(req_mem_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ req = cache_req_object_by_id_send(req_mem_ctx, test_ctx->tctx->ev,
|
|
|
9f2ebf |
+ test_ctx->rctx, test_ctx->ncache, cache_refresh_percent,
|
|
|
9f2ebf |
+ (domain == NULL ? NULL : domain->name), id, attrs);
|
|
|
9f2ebf |
+ assert_non_null(req);
|
|
|
9f2ebf |
+ tevent_req_set_callback(req, cache_req_object_by_id_test_done, test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ ret = test_ev_loop(test_ctx->tctx);
|
|
|
9f2ebf |
+ assert_int_equal(ret, exp_ret);
|
|
|
9f2ebf |
+ assert_true(check_leaks_pop(req_mem_ctx));
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ talloc_free(req_mem_ctx);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
struct tevent_req *
|
|
|
9f2ebf |
__wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
|
|
|
9f2ebf |
struct resp_ctx *rctx,
|
|
|
9f2ebf |
@@ -2132,6 +2171,334 @@ void test_object_by_sid_group_multiple_domains_notfound(void **state)
|
|
|
9f2ebf |
assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
}
|
|
|
9f2ebf |
|
|
|
9f2ebf |
+void test_object_by_id_user_cache_valid(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ prepare_user(test_ctx->tctx->dom, &users[0], 1000, time(NULL));
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ check_user(test_ctx, &users[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_user_cache_expired(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ prepare_user(test_ctx->tctx->dom, &users[0], -1000, time(NULL));
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ /* DP should be contacted */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ mock_account_recv_simple();
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_user(test_ctx, &users[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_user_cache_midpoint(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ prepare_user(test_ctx->tctx->dom, &users[0], 50, time(NULL) - 26);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ /* DP should be contacted without callback */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 50, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_user(test_ctx, &users[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_user_ncache(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+ errno_t ret;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. We explicitly add the UID into BOTH UID and GID
|
|
|
9f2ebf |
+ * namespaces, because otherwise the cache_req plugin would
|
|
|
9f2ebf |
+ * search the Data Provider anyway, becase it can't be sure
|
|
|
9f2ebf |
+ * the object can be of the other type or not
|
|
|
9f2ebf |
+ */
|
|
|
9f2ebf |
+ ret = sss_ncache_set_uid(test_ctx->ncache,
|
|
|
9f2ebf |
+ false,
|
|
|
9f2ebf |
+ test_ctx->tctx->dom,
|
|
|
9f2ebf |
+ users[0].uid);
|
|
|
9f2ebf |
+ assert_int_equal(ret, EOK);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ ret = sss_ncache_set_gid(test_ctx->ncache,
|
|
|
9f2ebf |
+ false,
|
|
|
9f2ebf |
+ test_ctx->tctx->dom,
|
|
|
9f2ebf |
+ users[0].uid);
|
|
|
9f2ebf |
+ assert_int_equal(ret, EOK);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ENOENT);
|
|
|
9f2ebf |
+ assert_false(test_ctx->dp_called);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_user_missing_found(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ mock_account_recv_simple();
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx->create_user1 = true;
|
|
|
9f2ebf |
+ test_ctx->create_user2 = false;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_user(test_ctx, &users[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_user_missing_notfound(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ mock_account_recv_simple();
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ENOENT);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_user_multiple_domains_found(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ struct sss_domain_info *domain = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ domain = find_domain_by_name(test_ctx->tctx->dom,
|
|
|
9f2ebf |
+ "responder_cache_req_test_d", true);
|
|
|
9f2ebf |
+ assert_non_null(domain);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ prepare_user(domain, &users[0], 1000, time(NULL));
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ will_return_always(sss_dp_req_recv, 0);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_user(test_ctx, &users[0], domain);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_user_multiple_domains_notfound(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_PW_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ will_return_always(sss_dp_req_recv, 0);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, users[0].uid, attrs, 0, ENOENT);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_cache_valid(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ prepare_group(test_ctx->tctx->dom, &groups[0], 1000, time(NULL));
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_cache_expired(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ prepare_group(test_ctx->tctx->dom, &groups[0], -1000, time(NULL));
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ /* DP should be contacted */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ mock_account_recv_simple();
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_cache_midpoint(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ prepare_group(test_ctx->tctx->dom, &groups[0], 50, time(NULL) - 26);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ /* DP should be contacted without callback */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 50, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_ncache(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+ errno_t ret;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup group. We explicitly add the UID into BOTH UID and GID
|
|
|
9f2ebf |
+ * namespaces, because otherwise the cache_req plugin would
|
|
|
9f2ebf |
+ * search the Data Provider anyway, becase it can't be sure
|
|
|
9f2ebf |
+ * the object can be of the other type or not
|
|
|
9f2ebf |
+ */
|
|
|
9f2ebf |
+ ret = sss_ncache_set_uid(test_ctx->ncache,
|
|
|
9f2ebf |
+ false,
|
|
|
9f2ebf |
+ test_ctx->tctx->dom,
|
|
|
9f2ebf |
+ groups[0].gid);
|
|
|
9f2ebf |
+ assert_int_equal(ret, EOK);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ ret = sss_ncache_set_gid(test_ctx->ncache,
|
|
|
9f2ebf |
+ false,
|
|
|
9f2ebf |
+ test_ctx->tctx->dom,
|
|
|
9f2ebf |
+ groups[0].gid);
|
|
|
9f2ebf |
+ assert_int_equal(ret, EOK);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ assert_int_equal(ret, EOK);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ENOENT);
|
|
|
9f2ebf |
+ assert_false(test_ctx->dp_called);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_missing_found(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ mock_account_recv_simple();
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx->create_group1 = true;
|
|
|
9f2ebf |
+ test_ctx->create_group2 = false;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_group(test_ctx, &groups[0], test_ctx->tctx->dom);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_missing_notfound(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ mock_account_recv_simple();
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ENOENT);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_multiple_domains_found(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ struct sss_domain_info *domain = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Setup user. */
|
|
|
9f2ebf |
+ domain = find_domain_by_name(test_ctx->tctx->dom,
|
|
|
9f2ebf |
+ "responder_cache_req_test_d", true);
|
|
|
9f2ebf |
+ assert_non_null(domain);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ prepare_group(domain, &groups[0], 1000, time(NULL));
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ will_return_always(sss_dp_req_recv, 0);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ERR_OK);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+ check_group(test_ctx, &groups[0], domain);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+void test_object_by_id_group_multiple_domains_notfound(void **state)
|
|
|
9f2ebf |
+{
|
|
|
9f2ebf |
+ struct cache_req_test_ctx *test_ctx = NULL;
|
|
|
9f2ebf |
+ const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Mock values. */
|
|
|
9f2ebf |
+ will_return_always(__wrap_sss_dp_get_account_send, test_ctx);
|
|
|
9f2ebf |
+ will_return_always(sss_dp_req_recv, 0);
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ /* Test. */
|
|
|
9f2ebf |
+ run_object_by_id(test_ctx, NULL, groups[0].gid, attrs, 0, ENOENT);
|
|
|
9f2ebf |
+ assert_true(test_ctx->dp_called);
|
|
|
9f2ebf |
+}
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
int main(int argc, const char *argv[])
|
|
|
9f2ebf |
{
|
|
|
9f2ebf |
poptContext pc;
|
|
|
9f2ebf |
@@ -2218,6 +2585,24 @@ int main(int argc, const char *argv[])
|
|
|
9f2ebf |
new_single_domain_test(object_by_sid_group_missing_notfound),
|
|
|
9f2ebf |
new_multi_domain_test(object_by_sid_group_multiple_domains_found),
|
|
|
9f2ebf |
new_multi_domain_test(object_by_sid_group_multiple_domains_notfound),
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_user_cache_valid),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_user_cache_expired),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_user_cache_midpoint),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_user_ncache),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_user_missing_found),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_user_missing_notfound),
|
|
|
9f2ebf |
+ new_multi_domain_test(object_by_id_user_multiple_domains_found),
|
|
|
9f2ebf |
+ new_multi_domain_test(object_by_id_user_multiple_domains_notfound),
|
|
|
9f2ebf |
+
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_group_cache_valid),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_group_cache_expired),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_group_cache_midpoint),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_group_ncache),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_group_missing_found),
|
|
|
9f2ebf |
+ new_single_domain_test(object_by_id_group_missing_notfound),
|
|
|
9f2ebf |
+ new_multi_domain_test(object_by_id_group_multiple_domains_found),
|
|
|
9f2ebf |
+ new_multi_domain_test(object_by_id_group_multiple_domains_notfound),
|
|
|
9f2ebf |
};
|
|
|
9f2ebf |
|
|
|
9f2ebf |
/* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
9f2ebf |
--
|
|
|
9f2ebf |
2.14.3
|
|
|
9f2ebf |
|