|
|
ced1f5 |
From e0f1d81bc24416da1d6d646a0cd3a14bd7e3e02d Mon Sep 17 00:00:00 2001
|
|
|
ced1f5 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
ced1f5 |
Date: Wed, 25 Oct 2017 21:31:54 +0200
|
|
|
ced1f5 |
Subject: [PATCH 29/31] NSS/TESTS: add unit tests for *_EX requests
|
|
|
ced1f5 |
|
|
|
ced1f5 |
The patch adds unit tests for the new *_EX requests with different input
|
|
|
ced1f5 |
types and flags.
|
|
|
ced1f5 |
|
|
|
ced1f5 |
Related to https://pagure.io/SSSD/sssd/issue/2478
|
|
|
ced1f5 |
|
|
|
ced1f5 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
ced1f5 |
(cherry picked from commit 85da8a5e90bffc8b0fef5e0ea364a8d3cb50de86)
|
|
|
ced1f5 |
---
|
|
|
ced1f5 |
src/tests/cmocka/test_nss_srv.c | 539 ++++++++++++++++++++++++++++++++++++++++
|
|
|
ced1f5 |
1 file changed, 539 insertions(+)
|
|
|
ced1f5 |
|
|
|
ced1f5 |
diff --git a/src/tests/cmocka/test_nss_srv.c b/src/tests/cmocka/test_nss_srv.c
|
|
|
ced1f5 |
index ccedf96beaecfaa4232bbe456d5e5a8394098483..6aa726153183b5a871a75d398727ea7132358ca6 100644
|
|
|
ced1f5 |
--- a/src/tests/cmocka/test_nss_srv.c
|
|
|
ced1f5 |
+++ b/src/tests/cmocka/test_nss_srv.c
|
|
|
ced1f5 |
@@ -255,6 +255,45 @@ static void mock_input_user_or_group(const char *input)
|
|
|
ced1f5 |
mock_parse_inp(shortname, domname, EOK);
|
|
|
ced1f5 |
}
|
|
|
ced1f5 |
|
|
|
ced1f5 |
+static void mock_input_user_or_group_ex(bool do_parse_inp, const char *input,
|
|
|
ced1f5 |
+ uint32_t flags)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ const char *copy;
|
|
|
ced1f5 |
+ const char *shortname;
|
|
|
ced1f5 |
+ const char *domname;
|
|
|
ced1f5 |
+ char *separator;
|
|
|
ced1f5 |
+ uint8_t *data;
|
|
|
ced1f5 |
+ size_t len;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ len = strlen(input);
|
|
|
ced1f5 |
+ len++;
|
|
|
ced1f5 |
+ data = talloc_size(nss_test_ctx, len + sizeof(uint32_t));
|
|
|
ced1f5 |
+ assert_non_null(data);
|
|
|
ced1f5 |
+ memcpy(data, input, len);
|
|
|
ced1f5 |
+ SAFEALIGN_COPY_UINT32(data + len, &flags, NULL);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, data);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, len + sizeof(uint32_t));
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ if (do_parse_inp) {
|
|
|
ced1f5 |
+ copy = talloc_strdup(nss_test_ctx, input);
|
|
|
ced1f5 |
+ assert_non_null(copy);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ separator = strrchr(copy, '@');
|
|
|
ced1f5 |
+ if (separator == NULL) {
|
|
|
ced1f5 |
+ shortname = input;
|
|
|
ced1f5 |
+ domname = NULL;
|
|
|
ced1f5 |
+ } else {
|
|
|
ced1f5 |
+ *separator = '\0';
|
|
|
ced1f5 |
+ shortname = copy;
|
|
|
ced1f5 |
+ domname = separator + 1;
|
|
|
ced1f5 |
+ }
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ mock_parse_inp(shortname, domname, EOK);
|
|
|
ced1f5 |
+ }
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
static void mock_input_upn(const char *upn)
|
|
|
ced1f5 |
{
|
|
|
ced1f5 |
will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
|
|
|
ced1f5 |
@@ -291,6 +330,20 @@ static void mock_input_id(TALLOC_CTX *mem_ctx, uint32_t id)
|
|
|
ced1f5 |
will_return(__wrap_sss_packet_get_body, sizeof(uint32_t));
|
|
|
ced1f5 |
}
|
|
|
ced1f5 |
|
|
|
ced1f5 |
+static void mock_input_id_ex(TALLOC_CTX *mem_ctx, uint32_t id, uint32_t flags)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ uint8_t *body;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ body = talloc_zero_array(mem_ctx, uint8_t, 8);
|
|
|
ced1f5 |
+ if (body == NULL) return;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ SAFEALIGN_SETMEM_UINT32(body, id, NULL);
|
|
|
ced1f5 |
+ SAFEALIGN_SETMEM_UINT32(body + sizeof(uint32_t), flags, NULL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, body);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, 2 * sizeof(uint32_t));
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
static void mock_fill_user(void)
|
|
|
ced1f5 |
{
|
|
|
ced1f5 |
/* One packet for the entry and one for num entries */
|
|
|
ced1f5 |
@@ -4143,6 +4196,482 @@ void test_nss_getsidbyname_neg(void **state)
|
|
|
ced1f5 |
assert_int_equal(ret, ENOENT);
|
|
|
ced1f5 |
}
|
|
|
ced1f5 |
|
|
|
ced1f5 |
+static int test_nss_EINVAL_check(uint32_t status, uint8_t *body, size_t blen)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ assert_int_equal(status, EINVAL);
|
|
|
ced1f5 |
+ assert_int_equal(blen, 0);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ return EOK;
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+#define RESET_TCTX do { \
|
|
|
ced1f5 |
+ nss_test_ctx->tctx->done = false; \
|
|
|
ced1f5 |
+ nss_test_ctx->tctx->error = EIO; \
|
|
|
ced1f5 |
+} while (0)
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+void test_nss_getpwnam_ex(void **state)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ errno_t ret;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
|
|
|
ced1f5 |
+ &getpwnam_usr, NULL, 0);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, "testuser", 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Query for that user, call a callback when command finishes */
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getpwnam_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use old input format, expect EINVAL */
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, "testuser");
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use unsupported flag combination, expect EINVAL */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(false, "testuser",
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_NO_CACHE
|
|
|
ced1f5 |
+ |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
|
|
|
ced1f5 |
+ * will cause a backend lookup -> mock_account_recv_simple() */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, "testuser", SSS_NSS_EX_FLAG_NO_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+ mock_account_recv_simple();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getpwnam_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, "testuser",
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWNAM_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getpwnam_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+void test_nss_getpwuid_ex(void **state)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ errno_t ret;
|
|
|
ced1f5 |
+ uint32_t id = 101;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Prime the cache with a valid user */
|
|
|
ced1f5 |
+ ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
|
|
|
ced1f5 |
+ &getpwuid_usr, NULL, 0);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, id, 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Query for that id, call a callback when command finishes */
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getpwuid_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use old input format, expect failure */
|
|
|
ced1f5 |
+ mock_input_id(nss_test_ctx, id);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use unsupported flag combination, expect EINVAL */
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, id, SSS_NSS_EX_FLAG_NO_CACHE
|
|
|
ced1f5 |
+ |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
|
|
|
ced1f5 |
+ * will cause a backend lookup -> mock_account_recv_simple() */
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, id, SSS_NSS_EX_FLAG_NO_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+ mock_account_recv_simple();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getpwuid_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, id, SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETPWUID_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getpwuid_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETPWUID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+void test_nss_getgrnam_ex_no_members(void **state)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ errno_t ret;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Test group is still in the cache */
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, getgrnam_no_members.gr_name, 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Query for that group, call a callback when command finishes */
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getgrnam_no_members_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use old input format, expect failure */
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, "testgroup");
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use unsupported flag combination, expect EINVAL */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(false, getgrnam_no_members.gr_name,
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_NO_CACHE
|
|
|
ced1f5 |
+ |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
|
|
|
ced1f5 |
+ * will cause a backend lookup -> mock_account_recv_simple() */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, getgrnam_no_members.gr_name,
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_NO_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ mock_account_recv_simple();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getgrnam_no_members_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, getgrnam_no_members.gr_name,
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRNAM_EX);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getgrnam_no_members_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRNAM_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+void test_nss_getgrgid_ex_no_members(void **state)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ errno_t ret;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Test group is still in the cache */
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid, 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ mock_account_recv_simple();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Query for that group, call a callback when command finishes */
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getgrnam_no_members_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use old input format, expect failure */
|
|
|
ced1f5 |
+ mock_input_id(nss_test_ctx, getgrnam_no_members.gr_gid);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use unsupported flag combination, expect EINVAL */
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid,
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_NO_CACHE
|
|
|
ced1f5 |
+ |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
|
|
|
ced1f5 |
+ * will cause a backend lookup -> mock_account_recv_simple() */
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid,
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_NO_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ mock_account_recv_simple();
|
|
|
ced1f5 |
+ mock_account_recv_simple();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getgrnam_no_members_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
|
|
|
ced1f5 |
+ mock_input_id_ex(nss_test_ctx, getgrnam_no_members.gr_gid,
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_GETGRGID_EX);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_REAL);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_getgrnam_no_members_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_GETGRGID_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+void test_nss_initgroups_ex(void **state)
|
|
|
ced1f5 |
+{
|
|
|
ced1f5 |
+ errno_t ret;
|
|
|
ced1f5 |
+ struct sysdb_attrs *attrs;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ attrs = sysdb_new_attrs(nss_test_ctx);
|
|
|
ced1f5 |
+ assert_non_null(attrs);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_INITGR_EXPIRE,
|
|
|
ced1f5 |
+ time(NULL) + 300);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_UPN, "upninitgr@upndomain.test");
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ ret = store_user(nss_test_ctx, nss_test_ctx->tctx->dom,
|
|
|
ced1f5 |
+ &testinitgr_usr, attrs, 0);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, "testinitgr", 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Query for that user, call a callback when command finishes */
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_initgr_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use old input format, expect failure */
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, WRAP_CALL_WRAPPER);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, "testinitgr");
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_body, 0);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use unsupported flag combination, expect EINVAL */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(false, "testinitgr",
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_NO_CACHE
|
|
|
ced1f5 |
+ |SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_EINVAL_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_NO_CACHE,
|
|
|
ced1f5 |
+ * will cause a backend lookup -> mock_account_recv_simple() */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, "testinitgr",
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_NO_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+ mock_account_recv_simple();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_initgr_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+ RESET_TCTX;
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Use flag SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
|
|
|
ced1f5 |
+ mock_input_user_or_group_ex(true, "testinitgr",
|
|
|
ced1f5 |
+ SSS_NSS_EX_FLAG_INVALIDATE_CACHE);
|
|
|
ced1f5 |
+ will_return(__wrap_sss_packet_get_cmd, SSS_NSS_INITGR_EX);
|
|
|
ced1f5 |
+ mock_fill_user();
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ set_cmd_cb(test_nss_initgr_check);
|
|
|
ced1f5 |
+ ret = sss_cmd_execute(nss_test_ctx->cctx, SSS_NSS_INITGR_EX,
|
|
|
ced1f5 |
+ nss_test_ctx->nss_cmds);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
+ /* Wait until the test finishes with EOK */
|
|
|
ced1f5 |
+ ret = test_ev_loop(nss_test_ctx->tctx);
|
|
|
ced1f5 |
+ assert_int_equal(ret, EOK);
|
|
|
ced1f5 |
+}
|
|
|
ced1f5 |
+
|
|
|
ced1f5 |
int main(int argc, const char *argv[])
|
|
|
ced1f5 |
{
|
|
|
ced1f5 |
int rv;
|
|
|
ced1f5 |
@@ -4288,6 +4817,16 @@ int main(int argc, const char *argv[])
|
|
|
ced1f5 |
nss_test_setup, nss_test_teardown),
|
|
|
ced1f5 |
cmocka_unit_test_setup_teardown(test_nss_getsidbyname_neg,
|
|
|
ced1f5 |
nss_test_setup, nss_test_teardown),
|
|
|
ced1f5 |
+ cmocka_unit_test_setup_teardown(test_nss_getpwnam_ex,
|
|
|
ced1f5 |
+ nss_test_setup, nss_test_teardown),
|
|
|
ced1f5 |
+ cmocka_unit_test_setup_teardown(test_nss_getpwuid_ex,
|
|
|
ced1f5 |
+ nss_test_setup, nss_test_teardown),
|
|
|
ced1f5 |
+ cmocka_unit_test_setup_teardown(test_nss_getgrnam_ex_no_members,
|
|
|
ced1f5 |
+ nss_test_setup, nss_test_teardown),
|
|
|
ced1f5 |
+ cmocka_unit_test_setup_teardown(test_nss_getgrgid_ex_no_members,
|
|
|
ced1f5 |
+ nss_test_setup, nss_test_teardown),
|
|
|
ced1f5 |
+ cmocka_unit_test_setup_teardown(test_nss_initgroups_ex,
|
|
|
ced1f5 |
+ nss_test_setup, nss_test_teardown),
|
|
|
ced1f5 |
};
|
|
|
ced1f5 |
|
|
|
ced1f5 |
/* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
ced1f5 |
--
|
|
|
ced1f5 |
2.13.6
|
|
|
ced1f5 |
|