Blame SOURCES/0029-NSS-TESTS-add-unit-tests-for-_EX-requests.patch

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