|
|
74fd62 |
From dc0fb9bc5e1b186b274739389437d68c7b257e1f Mon Sep 17 00:00:00 2001
|
|
|
74fd62 |
From: Tomas Halman <thalman@redhat.com>
|
|
|
74fd62 |
Date: Wed, 18 Nov 2020 13:32:28 +0100
|
|
|
74fd62 |
Subject: [PATCH 60/60] TESTS: Add test for recreating cache timestamp
|
|
|
74fd62 |
MIME-Version: 1.0
|
|
|
74fd62 |
Content-Type: text/plain; charset=UTF-8
|
|
|
74fd62 |
Content-Transfer-Encoding: 8bit
|
|
|
74fd62 |
|
|
|
74fd62 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
74fd62 |
(cherry picked from commit 62b2b4972e41393cd43b58d9e6451a2c58942cb2)
|
|
|
74fd62 |
---
|
|
|
74fd62 |
src/tests/cmocka/test_sysdb_ts_cache.c | 107 +++++++++++++++++++++++++
|
|
|
74fd62 |
1 file changed, 107 insertions(+)
|
|
|
74fd62 |
|
|
|
74fd62 |
diff --git a/src/tests/cmocka/test_sysdb_ts_cache.c b/src/tests/cmocka/test_sysdb_ts_cache.c
|
|
|
74fd62 |
index ae8b1b16c..24b26d950 100644
|
|
|
74fd62 |
--- a/src/tests/cmocka/test_sysdb_ts_cache.c
|
|
|
74fd62 |
+++ b/src/tests/cmocka/test_sysdb_ts_cache.c
|
|
|
74fd62 |
@@ -1606,6 +1606,107 @@ static void test_sysdb_search_with_ts(void **state)
|
|
|
74fd62 |
talloc_free(res);
|
|
|
74fd62 |
}
|
|
|
74fd62 |
|
|
|
74fd62 |
+static void test_sysdb_user_missing_ts(void **state)
|
|
|
74fd62 |
+{
|
|
|
74fd62 |
+ int ret;
|
|
|
74fd62 |
+ struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
74fd62 |
+ struct sysdb_ts_test_ctx);
|
|
|
74fd62 |
+ struct ldb_result *res = NULL;
|
|
|
74fd62 |
+ struct sysdb_attrs *attrs = NULL;
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* Nothing must be stored in either cache at the beginning of the test */
|
|
|
74fd62 |
+ res = sysdb_getpwnam_res(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME);
|
|
|
74fd62 |
+ assert_int_equal(res->count, 0);
|
|
|
74fd62 |
+ talloc_free(res);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* add user to cache */
|
|
|
74fd62 |
+ attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
|
|
|
74fd62 |
+ assert_non_null(attrs);
|
|
|
74fd62 |
+ ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
|
|
|
74fd62 |
+ TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
|
|
|
74fd62 |
+ "/home/"TEST_USER_NAME, "/bin/bash", NULL,
|
|
|
74fd62 |
+ attrs, NULL, TEST_CACHE_TIMEOUT,
|
|
|
74fd62 |
+ TEST_NOW_1);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+ talloc_zfree(attrs);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* remove timestamp */
|
|
|
74fd62 |
+ struct ldb_dn *userdn = sysdb_user_dn(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME);
|
|
|
74fd62 |
+ ret = ldb_delete(test_ctx->tctx->dom->sysdb->ldb_ts, userdn);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* update user */
|
|
|
74fd62 |
+ attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_2);
|
|
|
74fd62 |
+ assert_non_null(attrs);
|
|
|
74fd62 |
+ ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
|
|
|
74fd62 |
+ TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
|
|
|
74fd62 |
+ "/home/"TEST_USER_NAME, "/bin/bash", NULL,
|
|
|
74fd62 |
+ attrs, NULL, TEST_CACHE_TIMEOUT,
|
|
|
74fd62 |
+ TEST_NOW_2);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+ talloc_zfree(attrs);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* check that ts is back */
|
|
|
74fd62 |
+ SSS_LDB_SEARCH(ret, test_ctx->tctx->dom->sysdb->ldb_ts, test_ctx, &res, userdn,
|
|
|
74fd62 |
+ LDB_SCOPE_BASE, NULL, NULL);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+ assert_int_equal(res->count, 1);
|
|
|
74fd62 |
+ talloc_zfree(res);
|
|
|
74fd62 |
+ talloc_zfree(userdn);
|
|
|
74fd62 |
+}
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+static void test_sysdb_group_missing_ts(void **state)
|
|
|
74fd62 |
+{
|
|
|
74fd62 |
+ int ret;
|
|
|
74fd62 |
+ struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
74fd62 |
+ struct sysdb_ts_test_ctx);
|
|
|
74fd62 |
+ struct ldb_result *res = NULL;
|
|
|
74fd62 |
+ struct sysdb_attrs *group_attrs = NULL;
|
|
|
74fd62 |
+ struct ldb_dn *groupdn = NULL;
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* Nothing must be stored in either cache at the beginning of the test */
|
|
|
74fd62 |
+ res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
|
|
|
74fd62 |
+ assert_int_equal(res->count, 0);
|
|
|
74fd62 |
+ talloc_free(res);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* add group to cache */
|
|
|
74fd62 |
+ group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
|
|
|
74fd62 |
+ assert_non_null(group_attrs);
|
|
|
74fd62 |
+ ret = sysdb_store_group(test_ctx->tctx->dom,
|
|
|
74fd62 |
+ TEST_GROUP_NAME,
|
|
|
74fd62 |
+ TEST_GROUP_GID,
|
|
|
74fd62 |
+ group_attrs,
|
|
|
74fd62 |
+ TEST_CACHE_TIMEOUT,
|
|
|
74fd62 |
+ TEST_NOW_1);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+ talloc_zfree(group_attrs);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* remove timestamp */
|
|
|
74fd62 |
+ groupdn = sysdb_group_dn(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
|
|
|
74fd62 |
+ ret = ldb_delete(test_ctx->tctx->dom->sysdb->ldb_ts, groupdn);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* update group */
|
|
|
74fd62 |
+ group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_2);
|
|
|
74fd62 |
+ assert_non_null(group_attrs);
|
|
|
74fd62 |
+ ret = sysdb_store_group(test_ctx->tctx->dom,
|
|
|
74fd62 |
+ TEST_GROUP_NAME,
|
|
|
74fd62 |
+ TEST_GROUP_GID,
|
|
|
74fd62 |
+ group_attrs,
|
|
|
74fd62 |
+ TEST_CACHE_TIMEOUT,
|
|
|
74fd62 |
+ TEST_NOW_2);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+ talloc_zfree(group_attrs);
|
|
|
74fd62 |
+
|
|
|
74fd62 |
+ /* check that ts is back */
|
|
|
74fd62 |
+ SSS_LDB_SEARCH(ret, test_ctx->tctx->dom->sysdb->ldb_ts, test_ctx, &res, groupdn,
|
|
|
74fd62 |
+ LDB_SCOPE_BASE, NULL, NULL);
|
|
|
74fd62 |
+ assert_int_equal(ret, EOK);
|
|
|
74fd62 |
+ assert_int_equal(res->count, 1);
|
|
|
74fd62 |
+ talloc_zfree(res);
|
|
|
74fd62 |
+ talloc_zfree(groupdn);
|
|
|
74fd62 |
+}
|
|
|
74fd62 |
+
|
|
|
74fd62 |
int main(int argc, const char *argv[])
|
|
|
74fd62 |
{
|
|
|
74fd62 |
int rv;
|
|
|
74fd62 |
@@ -1660,6 +1761,12 @@ int main(int argc, const char *argv[])
|
|
|
74fd62 |
cmocka_unit_test_setup_teardown(test_sysdb_search_with_ts,
|
|
|
74fd62 |
test_sysdb_ts_setup,
|
|
|
74fd62 |
test_sysdb_ts_teardown),
|
|
|
74fd62 |
+ cmocka_unit_test_setup_teardown(test_sysdb_user_missing_ts,
|
|
|
74fd62 |
+ test_sysdb_ts_setup,
|
|
|
74fd62 |
+ test_sysdb_ts_teardown),
|
|
|
74fd62 |
+ cmocka_unit_test_setup_teardown(test_sysdb_group_missing_ts,
|
|
|
74fd62 |
+ test_sysdb_ts_setup,
|
|
|
74fd62 |
+ test_sysdb_ts_teardown),
|
|
|
74fd62 |
};
|
|
|
74fd62 |
|
|
|
74fd62 |
/* Set debug level to invalid value so we can decide if -d 0 was used. */
|
|
|
74fd62 |
--
|
|
|
74fd62 |
2.21.3
|
|
|
74fd62 |
|