d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek/*
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SSSD
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts - Test for sysdb timestamp cache
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek Copyright (C) 2016 Red Hat
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek This program is free software; you can redistribute it and/or modify
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek it under the terms of the GNU General Public License as published by
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek the Free Software Foundation; either version 3 of the License, or
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek (at your option) any later version.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek This program is distributed in the hope that it will be useful,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek GNU General Public License for more details.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek You should have received a copy of the GNU General Public License
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek*/
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#include <stdarg.h>
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#include <stddef.h>
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#include <setjmp.h>
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#include <cmocka.h>
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#include <popt.h>
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#include "tests/cmocka/common_mock.h"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#include "db/sysdb_private.h"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TESTS_PATH "tp_" BASE_FILE_STEM
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_CONF_DB "tests_conf.ldb"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_ID_PROVIDER "ldap"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_DOM1_NAME "test_sysdb_ts_1"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_NAME "test_group"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_NAME_2 "test_group_2"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_NAME_3 "test_group_3"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_NAME_OLD "test_group_old"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_GID 1234
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_GID_2 1235
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_GID_3 1236
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_GROUP_SID "S-1-5-21-123-456-789-111"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_USER_NAME "test_user"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_USER_UID 4321
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_USER_GID 4322
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_USER_SID "S-1-5-21-123-456-789-222"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_USER_UPN "test_user@TEST_REALM"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_MODSTAMP_1 "20160408132553Z"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_MODSTAMP_2 "20160408142553Z"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_MODSTAMP_3 "20160408152553Z"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_CACHE_TIMEOUT 5
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_NOW_1 100
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_NOW_2 200
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_NOW_3 300
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_NOW_4 400
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_NOW_5 500
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TEST_NOW_6 600
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek#define TS_FILTER_ALL "("SYSDB_CACHE_EXPIRE"=*)"
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstruct sysdb_ts_test_ctx {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sss_test_ctx *tctx;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek};
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekconst char *domains[] = { TEST_DOM1_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL };
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic int test_sysdb_ts_setup(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sss_test_conf_param params[] = {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek { NULL, NULL }, /* Sentinel */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek };
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_true(leak_check_setup());
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx = talloc_zero(global_talloc_context,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_dom_suite_setup(TESTS_PATH);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx = create_multidom_test_ctx(test_ctx, TESTS_PATH,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CONF_DB, domains,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_ID_PROVIDER, params);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(test_ctx->tctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek check_leaks_push(test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek *state = test_ctx;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic int test_sysdb_ts_teardown(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek //assert_true(check_leaks_pop(test_ctx));
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_zfree(test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM1_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic struct sysdb_attrs *create_modstamp_attrs(TALLOC_CTX *mem_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *modstamp)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *attrs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek attrs = sysdb_new_attrs(mem_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (attrs == NULL) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_attrs_add_string(attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_ORIG_MODSTAMP,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek modstamp);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (ret != EOK) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return attrs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic struct sysdb_attrs *create_str_attrs(TALLOC_CTX *mem_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *key,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *value)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *attrs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek attrs = sysdb_new_attrs(mem_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (attrs == NULL) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_attrs_add_string(attrs, key, value);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (ret != EOK) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return attrs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic struct sysdb_attrs *create_sidstr_attrs(TALLOC_CTX *mem_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *sid_str)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return create_str_attrs(mem_ctx, SYSDB_SID_STR, sid_str);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic struct sysdb_attrs *create_upnstr_attrs(TALLOC_CTX *mem_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *upn_str)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return create_str_attrs(mem_ctx, SYSDB_UPN, upn_str);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic struct sysdb_attrs *create_ts_attrs(TALLOC_CTX *mem_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek time_t expiration,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek time_t last_update)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *attrs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek attrs = sysdb_new_attrs(mem_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (attrs == NULL) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_attrs_add_time_t(attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_CACHE_EXPIRE,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek expiration);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (ret != EOK) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_attrs_add_time_t(attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_LAST_UPDATE,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek last_update);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (ret != EOK) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return attrs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic struct ldb_result *sysdb_getgrnam_res(TALLOC_CTX *mem_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sss_domain_info *domain,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getgrnam(mem_ctx, domain, name, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic struct ldb_result *sysdb_getpwnam_res(TALLOC_CTX *mem_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sss_domain_info *domain,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getpwnam(mem_ctx, domain, name, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic uint64_t get_dn_cache_timestamp(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_dn *dn)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *attrs[] = { SYSDB_CACHE_EXPIRE,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek };
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = ldb_search(test_ctx->tctx->sysdb->ldb, test_ctx, &res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek dn, LDB_SCOPE_BASE, attrs, NULL);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (ret != EOK || res == NULL || res->count != 1) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cache_expire_sysdb = ldb_msg_find_attr_as_uint64(res->msgs[0],
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_CACHE_EXPIRE,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic uint64_t get_gr_cache_timestamp(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_dn *dn;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek dn = sysdb_group_dn(test_ctx, test_ctx->tctx->dom, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (dn == NULL) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cache_expire_sysdb = get_dn_cache_timestamp(test_ctx, dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic uint64_t get_pw_cache_timestamp(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_dn *dn;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek dn = sysdb_user_dn(test_ctx, test_ctx->tctx->dom, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (dn == NULL) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cache_expire_sysdb = get_dn_cache_timestamp(test_ctx, dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic uint64_t get_dn_ts_cache_timestamp(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_dn *dn)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek size_t msg_count;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message **msgs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *attrs[] = { SYSDB_CACHE_EXPIRE,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek };
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_entry(test_ctx, test_ctx->tctx->sysdb,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek dn, LDB_SCOPE_BASE, NULL, attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &msg_count, &msgs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (ret != EOK) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (msg_count != 1) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cache_expire_ts = ldb_msg_find_attr_as_uint64(msgs[0],
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_CACHE_EXPIRE, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(msgs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic uint64_t get_gr_ts_cache_timestamp(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_dn *dn;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek dn = sysdb_group_dn(test_ctx, test_ctx->tctx->dom, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (dn == NULL) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cache_expire_ts = get_dn_ts_cache_timestamp(test_ctx, dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic uint64_t get_pw_ts_cache_timestamp(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_dn *dn;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek dn = sysdb_user_dn(test_ctx, test_ctx->tctx->dom, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (dn == NULL) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cache_expire_ts = get_dn_ts_cache_timestamp(test_ctx, dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(dn);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void get_gr_timestamp_attrs(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t *cache_expire_sysdb,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t *cache_expire_ts)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek *cache_expire_sysdb = get_gr_cache_timestamp(test_ctx, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek *cache_expire_ts = get_gr_ts_cache_timestamp(test_ctx, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void get_pw_timestamp_attrs(struct sysdb_ts_test_ctx *test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *name,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t *cache_expire_sysdb,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t *cache_expire_ts)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek *cache_expire_sysdb = get_pw_cache_timestamp(test_ctx, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek *cache_expire_ts = get_pw_ts_cache_timestamp(test_ctx, name);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_sysdb_group_update(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *group_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek char *test_user_member = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Nothing must be stored in either cache at the beginning of the test */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Store a group without a modifyTimestamp. Must not throw an error. This
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * tests that the sysdb timestamp code is able to cope with absence of an
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * attribute it operates on gracefully.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Store a group and add a modifyTimestamp this time.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * Since we want to write the timestamp attributes if they are not present,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * both caches will be bumped.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Update the same attrs and the same modifyTimestamp.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * Only the timestamp cache must be bumped */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Update with different modifyTimestamp but same attrs as previously
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * saved to the timestamp cache. We should detect the 'real' attributes
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * are the same and only bump the timestamp cache
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_4);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_4);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Update with different modifyTimestamp and different attrs (add a
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * member as a real-world example). Both caches must be updated. */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL, NULL, NULL, NULL, NULL, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT, TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_user_member = sysdb_user_strdn(group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom->name,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(test_user_member);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_attrs_add_string(group_attrs, SYSDB_MEMBER, test_user_member);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Try to save the same member again, while it's already saved. Only the
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * timestamps cache must be bumped now
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_6);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_6);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_sysdb_group_delete(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *group_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *ts_res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ts_res = talloc_zero(test_ctx, struct ldb_result);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Nothing must be stored in either cache at the beginning of the test */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_groups(ts_res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_groups(ts_res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ts_res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_delete_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Nothing must be stored in either cache at the end of the test */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_groups(ts_res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_sysdb_group_rename(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *ts_res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek char *filter;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ts_res = talloc_zero(test_ctx, struct ldb_result);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Nothing must be stored in either cache at the beginning of the test */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME_OLD);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter = talloc_asprintf(ts_res, "(|(%s=%s)(%s=%s))",
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_GROUP_NAME_OLD,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_GROUP_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_groups(ts_res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Store an old group */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME_OLD,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME_OLD,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Replace with a new one */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* The old entry must be gone from both caches */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME_OLD,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME_OLD);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void assert_ts_attrs_msg(struct ldb_message *msg,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t exp_expiration,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t exp_last_update)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t expiration;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t last_update;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *modstamp;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Attributes normally requested with getgrnam are merged */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek expiration = ldb_msg_find_attr_as_uint64(msg, SYSDB_CACHE_EXPIRE, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(expiration, exp_expiration);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek last_update = ldb_msg_find_attr_as_uint64(msg, SYSDB_LAST_UPDATE, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(last_update, exp_last_update);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Attributes not requested are not */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek modstamp = ldb_msg_find_attr_as_string(msg, SYSDB_ORIG_MODSTAMP, NULL);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_null(modstamp);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void assert_ts_attrs_res(struct ldb_result *res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t exp_expiration,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t exp_last_update)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return assert_ts_attrs_msg(res->msgs[0], exp_expiration, exp_last_update);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void assert_ts_attrs_msgs_list(size_t msgs_count,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message **msgs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t exp_expiration,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t exp_last_update)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res.count = msgs_count;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res.msgs = msgs;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return assert_ts_attrs_res(&res, exp_expiration, exp_last_update);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_sysdb_getgr_merges(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *group_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *gr_fetch_attrs[] = SYSDB_GRSRC_ATTRS;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek char *filter = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek size_t msgs_count;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message **msgs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message *msg = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getgrnam(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getgrgid(test_ctx, test_ctx->tctx->dom, TEST_GROUP_GID, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter = talloc_asprintf(test_ctx, "(%s=%s)",
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_GROUP_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_groups(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter, gr_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &msgs_count, &msgs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(msgs_count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msgs_list(msgs_count, msgs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(msgs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_ts_attrs(test_ctx, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_set_group_attr(test_ctx->tctx->dom, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs, SYSDB_MOD_REP);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getgrnam(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Make sure sysdb_search_group_by_name includes timestamp attributes */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_group_by_name(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME, gr_fetch_attrs, &msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msg(msg, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_group_by_gid(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID, gr_fetch_attrs, &msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msg(msg, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_merge_ldb_results(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *gr_fetch_attrs[] = SYSDB_GRSRC_ATTRS;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek char *filter;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res1;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res2;
c7c1941f9045531044121520fc2ca0e048732c25Lukas Slebodnik size_t msgs_count;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res1 = talloc_zero(test_ctx, struct ldb_result);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(res1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res2 = talloc_zero(test_ctx, struct ldb_result);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(res2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME_2,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID_2,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME_3,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID_3,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter = talloc_asprintf(test_ctx, "(|(%s=%s)(%s=%s))",
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_GROUP_NAME_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_groups(res1, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter, gr_fetch_attrs,
c7c1941f9045531044121520fc2ca0e048732c25Lukas Slebodnik &msgs_count, &res1->msgs);
c7c1941f9045531044121520fc2ca0e048732c25Lukas Slebodnik res1->count = (unsigned)msgs_count;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res1->count, 2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter = talloc_asprintf(test_ctx, "(|(%s=%s)(%s=%s))",
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_GROUP_NAME_2,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_GROUP_NAME_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_groups(res2, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter, gr_fetch_attrs,
c7c1941f9045531044121520fc2ca0e048732c25Lukas Slebodnik &msgs_count, &res2->msgs);
c7c1941f9045531044121520fc2ca0e048732c25Lukas Slebodnik res2->count = (unsigned)msgs_count;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res2->count, 2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sss_merge_ldb_results(res1, res2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_group_bysid(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *gr_fetch_attrs[] = SYSDB_GRSRC_ATTRS;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *group_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message *msg = NULL;
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik struct ldb_result ts_res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs = create_sidstr_attrs(test_ctx, TEST_GROUP_SID);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_object_by_sid(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek gr_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek group_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(group_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_GID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_object_by_sid(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek gr_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_group_by_sid_str(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek gr_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msg(msg, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_delete_by_sid(test_ctx->tctx->dom->sysdb,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_SID);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_object_by_sid(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_GROUP_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek gr_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_groups(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik &ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_sysdb_user_update(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *user_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Nothing must be stored in either cache at the beginning of the test */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getpwnam_res(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Store a user without a modifyTimestamp. Must not throw an error. This
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * tests that the sysdb timestamp code is able to cope with absence of an
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * attribute it operates on gracefully.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Store a user and add a modifyTimestamp this time.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * Since we want to write the timestamp attributes if they are not present,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * both caches will be bumped.
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Update with different modifyTimestamp but same attrs as previously
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * saved to the timestamp cache. We should detect the 'real' attributes
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * are the same and only bump the timestamp cache
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_4);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_4);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Update with different modifyTimestamp and different attrs (change
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek * the shell as a real-world example). Both caches must be updated. */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/zsh", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_5);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_sysdb_user_delete(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *user_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_sysdb;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek uint64_t cache_expire_ts;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *ts_res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ts_res = talloc_zero(test_ctx, struct ldb_result);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Nothing must be stored in either cache at the beginning of the test */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getpwnam_res(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_users(ts_res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_users(ts_res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ts_res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, TEST_CACHE_TIMEOUT + TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_delete_user(test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Nothing must be stored in either cache at the end of the test */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek res = sysdb_getpwnam_res(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_users(ts_res,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_sysdb, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(cache_expire_ts, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_sysdb_getpw_merges(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *user_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *pw_fetch_attrs[] = SYSDB_PW_ATTRS;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek char *filter = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek size_t msgs_count;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message **msgs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message *msg = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* sysdb cache will have test_now1 and ts cache test_now2 at this point */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* getpwnam must return the timestamp from the ts cache */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getpwnam(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* getpwuid must return the timestamp from the ts cache */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getpwuid(test_ctx, test_ctx->tctx->dom, TEST_USER_UID, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter = talloc_asprintf(test_ctx, "(%s=%s)",
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SYSDB_NAME, TEST_USER_NAME);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_users(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek filter, pw_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &msgs_count, &msgs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(filter);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(msgs_count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msgs_list(msgs_count, msgs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(msgs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* set_user_attrs must bump the ts cache */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_ts_attrs(test_ctx, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_set_user_attr(test_ctx->tctx->dom, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, SYSDB_MOD_REP);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* getpwnam must return the timestamp from the ts cache */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getpwnam(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_initgroups(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_get_user_attr(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_NAME, pw_fetch_attrs, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Make sure sysdb_search_user_by_name includes timestamp attributes */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_user_by_name(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_NAME, pw_fetch_attrs, &msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msg(msg, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_user_by_uid(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, pw_fetch_attrs, &msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msg(msg, TEST_NOW_3 + TEST_CACHE_TIMEOUT, TEST_NOW_3);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_user_bysid(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *pw_fetch_attrs[] = SYSDB_PW_ATTRS;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *user_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message *msg = NULL;
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik struct ldb_result ts_res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_sidstr_attrs(test_ctx, TEST_USER_SID);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_object_by_sid(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek pw_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_zfree(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_object_by_sid(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek pw_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_user_by_sid_str(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek pw_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msg(msg, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_delete_by_sid(test_ctx->tctx->dom->sysdb,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_SID);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_object_by_sid(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_SID,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek pw_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_ts_users(test_ctx,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TS_FILTER_ALL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek sysdb_ts_cache_attrs,
5d0d0f8067fb53285a38fe978cfa36dbeb53be9bLukas Slebodnik &ts_res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, ENOENT);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekstatic void test_user_byupn(void **state)
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int ret;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_ts_test_ctx);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const char *pw_fetch_attrs[] = SYSDB_PW_ATTRS;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct sysdb_attrs *user_attrs = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_result *res;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct ldb_message *msg = NULL;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs = create_upnstr_attrs(test_ctx, TEST_USER_UPN);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_non_null(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_zfree(user_attrs);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek user_attrs, NULL, TEST_CACHE_TIMEOUT,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_getpwupn(test_ctx, test_ctx->tctx->dom, TEST_USER_UPN, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_user_by_upn_res(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UPN, pw_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_search_user_by_upn(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UPN, pw_fetch_attrs,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek &msg);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_msg(msg, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek ret = sysdb_initgroups_by_upn(test_ctx, test_ctx->tctx->dom,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek TEST_USER_UPN, &res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(ret, EOK);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_int_equal(res->count, 1);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek talloc_free(res);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozekstatic void test_sysdb_zero_now(void **state)
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek{
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek int ret;
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek struct sysdb_ts_test_ctx);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek struct ldb_result *res = NULL;
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek uint64_t cache_expire_sysdb;
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek uint64_t cache_expire_ts;
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek struct sysdb_attrs *attrs = NULL;
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek /* Nothing must be stored in either cache at the beginning of the test */
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek res = sysdb_getpwnam_res(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_int_equal(res->count, 0);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek talloc_free(res);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_int_equal(res->count, 0);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek talloc_free(res);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_non_null(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs, NULL, TEST_CACHE_TIMEOUT,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek 0);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek talloc_zfree(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_int_equal(ret, EOK);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_non_null(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_GROUP_NAME,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_GROUP_GID,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_CACHE_TIMEOUT,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek 0);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek talloc_zfree(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_int_equal(ret, EOK);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek talloc_zfree(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_non_null(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek "/home/"TEST_USER_NAME, "/bin/bash", NULL,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs, NULL, TEST_CACHE_TIMEOUT,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek 0);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek talloc_zfree(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_int_equal(ret, EOK);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_non_null(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek ret = sysdb_store_group(test_ctx->tctx->dom,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_GROUP_NAME,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_GROUP_GID,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek attrs,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek TEST_CACHE_TIMEOUT,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek 0);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek talloc_zfree(attrs);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_int_equal(ret, EOK);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek /* Even though we passed zero as the timestamp, the timestamp cache should
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek * have used the current time instead
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek */
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_true(cache_expire_sysdb > TEST_CACHE_TIMEOUT);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_true(cache_expire_ts > TEST_CACHE_TIMEOUT);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek &cache_expire_sysdb, &cache_expire_ts);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_true(cache_expire_sysdb > TEST_CACHE_TIMEOUT);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek assert_true(cache_expire_ts > TEST_CACHE_TIMEOUT);
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek}
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozekint main(int argc, const char *argv[])
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek{
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int rv;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int no_cleanup = 0;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek poptContext pc;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek int opt;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek struct poptOption long_options[] = {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek POPT_AUTOHELP
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek SSSD_DEBUG_OPTS
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek _("Do not delete the test database after a test run"), NULL },
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek POPT_TABLEEND
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek };
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek const struct CMUnitTest tests[] = {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_group_update,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_group_delete,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_group_rename,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_getgr_merges,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_group_bysid,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_merge_ldb_results,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_user_update,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_user_delete,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_getpw_merges,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_user_bysid,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek cmocka_unit_test_setup_teardown(test_user_byupn,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_setup,
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_sysdb_ts_teardown),
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek cmocka_unit_test_setup_teardown(test_sysdb_zero_now,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek test_sysdb_ts_setup,
eb92441b65e0db9e64c88a57eb74358640e85d56Jakub Hrozek test_sysdb_ts_teardown),
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek };
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek /* Set debug level to invalid value so we can deside if -d 0 was used. */
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek debug_level = SSSDBG_INVALID;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek switch(opt) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek default:
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek poptPrintUsage(pc, stderr, 0);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return 1;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek poptFreeContext(pc);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek DEBUG_CLI_INIT(debug_level);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek tests_set_cwd();
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_dom_suite_setup(TESTS_PATH);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek if (rv == 0 && no_cleanup == 0) {
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek test_multidom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, domains);
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek }
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek return rv;
d36f4db9bb5efc63b94190cca25adb08ee56971cJakub Hrozek}