test_sysdb_ts_cache.c revision eb92441b65e0db9e64c88a57eb74358640e85d56
/*
SSSD
sysdb_ts - Test for sysdb timestamp cache
Copyright (C) 2016 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <popt.h>
#include "tests/cmocka/common_mock.h"
#include "db/sysdb_private.h"
#define TEST_CONF_DB "tests_conf.ldb"
#define TEST_ID_PROVIDER "ldap"
#define TEST_DOM1_NAME "test_sysdb_ts_1"
#define TEST_GROUP_NAME "test_group"
#define TEST_GROUP_NAME_2 "test_group_2"
#define TEST_GROUP_NAME_3 "test_group_3"
#define TEST_GROUP_NAME_OLD "test_group_old"
#define TEST_GROUP_GID 1234
#define TEST_GROUP_GID_2 1235
#define TEST_GROUP_GID_3 1236
#define TEST_GROUP_SID "S-1-5-21-123-456-789-111"
#define TEST_USER_NAME "test_user"
#define TEST_USER_UID 4321
#define TEST_USER_GID 4322
#define TEST_USER_SID "S-1-5-21-123-456-789-222"
#define TEST_USER_UPN "test_user@TEST_REALM"
#define TEST_MODSTAMP_1 "20160408132553Z"
#define TEST_MODSTAMP_2 "20160408142553Z"
#define TEST_MODSTAMP_3 "20160408152553Z"
#define TEST_CACHE_TIMEOUT 5
#define TEST_NOW_1 100
#define TEST_NOW_2 200
#define TEST_NOW_3 300
#define TEST_NOW_4 400
#define TEST_NOW_5 500
#define TEST_NOW_6 600
struct sysdb_ts_test_ctx {
struct sss_test_ctx *tctx;
};
const char *domains[] = { TEST_DOM1_NAME,
NULL };
static int test_sysdb_ts_setup(void **state)
{
struct sysdb_ts_test_ctx *test_ctx;
struct sss_test_conf_param params[] = {
};
struct sysdb_ts_test_ctx);
return 0;
}
static int test_sysdb_ts_teardown(void **state)
{
struct sysdb_ts_test_ctx);
//assert_true(check_leaks_pop(test_ctx));
return 0;
}
const char *modstamp)
{
int ret;
struct sysdb_attrs *attrs;
return NULL;
}
modstamp);
return NULL;
}
return attrs;
}
const char *key,
const char *value)
{
int ret;
struct sysdb_attrs *attrs;
return NULL;
}
return NULL;
}
return attrs;
}
const char *sid_str)
{
}
const char *upn_str)
{
}
{
int ret;
struct sysdb_attrs *attrs;
return NULL;
}
return NULL;
}
return NULL;
}
return attrs;
}
struct sss_domain_info *domain,
const char *name)
{
int ret;
return res;
}
struct sss_domain_info *domain,
const char *name)
{
int ret;
return res;
}
{
int ret;
struct ldb_result *res;
const char *attrs[] = { SYSDB_CACHE_EXPIRE,
NULL,
};
return 0;
}
0);
return cache_expire_sysdb;
}
const char *name)
{
return 0;
}
return cache_expire_sysdb;
}
const char *name)
{
return 0;
}
return cache_expire_sysdb;
}
{
struct ldb_message **msgs;
const char *attrs[] = { SYSDB_CACHE_EXPIRE,
NULL,
};
int ret;
return 0;
}
if (msg_count != 1) {
return 0;
}
SYSDB_CACHE_EXPIRE, 0);
return cache_expire_ts;
}
const char *name)
{
return 0;
}
return cache_expire_ts;
}
const char *name)
{
return 0;
}
return cache_expire_ts;
}
const char *name,
{
}
const char *name,
{
}
static void test_sysdb_group_update(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
char *test_user_member = NULL;
/* Nothing must be stored in either cache at the beginning of the test */
/* Store a group without a modifyTimestamp. Must not throw an error. This
* tests that the sysdb timestamp code is able to cope with absence of an
* attribute it operates on gracefully.
*/
/* Store a group and add a modifyTimestamp this time.
* Since we want to write the timestamp attributes if they are not present,
* both caches will be bumped.
*/
/* Update the same attrs and the same modifyTimestamp.
* Only the timestamp cache must be bumped */
/* Update with different modifyTimestamp but same attrs as previously
* saved to the timestamp cache. We should detect the 'real' attributes
* are the same and only bump the timestamp cache
*/
/* Update with different modifyTimestamp and different attrs (add a
* member as a real-world example). Both caches must be updated. */
NULL,
/* Try to save the same member again, while it's already saved. Only the
* timestamps cache must be bumped now
*/
}
static void test_sysdb_group_delete(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
struct ldb_result *ts_res;
/* Nothing must be stored in either cache at the beginning of the test */
ts_res);
ts_res);
/* Nothing must be stored in either cache at the end of the test */
ts_res);
}
static void test_sysdb_group_rename(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
struct ldb_result *ts_res;
char *filter;
/* Nothing must be stored in either cache at the beginning of the test */
ts_res);
/* Store an old group */
NULL,
/* Replace with a new one */
NULL,
/* The old entry must be gone from both caches */
}
{
const char *modstamp;
/* Attributes normally requested with getgrnam are merged */
/* Attributes not requested are not */
}
{
}
struct ldb_message **msgs,
{
struct ldb_result res;
}
static void test_sysdb_getgr_merges(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
const char *gr_fetch_attrs[] = SYSDB_GRSRC_ATTRS;
&msgs_count, &msgs);
/* Make sure sysdb_search_group_by_name includes timestamp attributes */
}
static void test_merge_ldb_results(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
const char *gr_fetch_attrs[] = SYSDB_GRSRC_ATTRS;
char *filter;
struct ldb_result *res;
struct ldb_result *res1;
struct ldb_result *res2;
NULL,
NULL,
NULL,
}
static void test_group_bysid(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
const char *gr_fetch_attrs[] = SYSDB_GRSRC_ATTRS;
struct ldb_result *res;
struct ldb_result ts_res;
&res);
NULL,
&res);
&msg);
&res);
&ts_res);
}
static void test_sysdb_user_update(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
/* Nothing must be stored in either cache at the beginning of the test */
/* Store a user without a modifyTimestamp. Must not throw an error. This
* tests that the sysdb timestamp code is able to cope with absence of an
* attribute it operates on gracefully.
*/
/* Store a user and add a modifyTimestamp this time.
* Since we want to write the timestamp attributes if they are not present,
* both caches will be bumped.
*/
/* Update the same attrs and the same modifyTimestamp.
* Only the timestamp cache must be bumped */
/* Update with different modifyTimestamp but same attrs as previously
* saved to the timestamp cache. We should detect the 'real' attributes
* are the same and only bump the timestamp cache
*/
/* Update with different modifyTimestamp and different attrs (change
* the shell as a real-world example). Both caches must be updated. */
}
static void test_sysdb_user_delete(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
struct ldb_result *ts_res;
/* Nothing must be stored in either cache at the beginning of the test */
ts_res);
ts_res);
/* Nothing must be stored in either cache at the end of the test */
ts_res);
}
static void test_sysdb_getpw_merges(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
const char *pw_fetch_attrs[] = SYSDB_PW_ATTRS;
/* sysdb cache will have test_now1 and ts cache test_now2 at this point */
/* getpwnam must return the timestamp from the ts cache */
/* getpwuid must return the timestamp from the ts cache */
&msgs_count, &msgs);
/* set_user_attrs must bump the ts cache */
/* getpwnam must return the timestamp from the ts cache */
/* Make sure sysdb_search_user_by_name includes timestamp attributes */
}
static void test_user_bysid(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
const char *pw_fetch_attrs[] = SYSDB_PW_ATTRS;
struct ldb_result *res;
struct ldb_result ts_res;
&res);
&res);
&msg);
&res);
&ts_res);
}
static void test_user_byupn(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
const char *pw_fetch_attrs[] = SYSDB_PW_ATTRS;
struct ldb_result *res;
&res);
&msg);
TEST_USER_UPN, &res);
}
static void test_sysdb_zero_now(void **state)
{
int ret;
struct sysdb_ts_test_ctx);
/* Nothing must be stored in either cache at the beginning of the test */
0);
0);
0);
0);
/* Even though we passed zero as the timestamp, the timestamp cache should
* have used the current time instead
*/
}
{
int rv;
int no_cleanup = 0;
int opt;
struct poptOption long_options[] = {
_("Do not delete the test database after a test run"), NULL },
};
const struct CMUnitTest tests[] = {
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
if (rv == 0 && no_cleanup == 0) {
}
return rv;
}