test_responder_cache_req.c revision 0d111f6975c7e132bf1069d6d7bd6d6afd2127df
/*
Authors:
Pavel Březina <pbrezina@redhat.com>
Copyright (C) 2014 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 <talloc.h>
#include <tevent.h>
#include <errno.h>
#include <popt.h>
#include "tests/cmocka/common_mock.h"
#include "tests/cmocka/common_mock_resp.h"
#include "responder/common/responder_cache_req.h"
#define TEST_CONF_DB "test_responder_cache_req_conf.ldb"
#define TEST_DOM_NAME "responder_cache_req_test"
#define TEST_ID_PROVIDER "ldap"
#define TEST_USER_PREFIX "test*"
struct test_user {
const char *name;
const char *upn;
const char *sid;
"S-1-5-21-3623811015-3361044348-30300820-1001", 1001, 1001},
{"test-user2", "upn2@upndomain.com",
"S-1-5-21-3623811015-3361044348-30300820-1002", 1002, 1002}};
struct test_group {
const char *name;
const char *sid;
{"test-group2", "S-1-5-21-3623811015-3361044348-30300820-2002", 2002}};
#define new_single_domain_test(test) \
#define new_multi_domain_test(test) \
struct tevent_req *req; \
\
\
assert_non_null(req); \
\
\
} while (0)
struct cache_req_test_ctx {
struct sss_test_ctx *tctx;
struct sss_nc_ctx *ncache;
struct ldb_result *result;
struct sss_domain_info *domain;
char *name;
bool dp_called;
/* NOTE: Please, instead of adding new create_[user|group] bool,
* use bitshift. */
bool create_user1;
bool create_user2;
bool create_group1;
bool create_group2;
};
const char *domains[] = {"responder_cache_req_test_a",
"responder_cache_req_test_b",
"responder_cache_req_test_c",
"responder_cache_req_test_d",
NULL};
struct cli_protocol_version *register_cli_protocol_version(void)
{
static struct cli_protocol_version version[] = {
};
return version;
}
{
}
{
}
{
}
{
}
{
}
{
struct sysdb_attrs *attrs;
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *exp_dom)
{
const char *ldbname;
const char *ldbupn;
const char *ldbsid;
SYSDB_NAME, NULL);
SYSDB_UIDNUM, 0);
}
struct test_group *group,
{
struct sysdb_attrs *attrs;
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct test_group *group,
struct sss_domain_info *exp_dom)
{
const char *ldbname;
const char *ldbsid;
SYSDB_NAME, NULL);
SYSDB_GIDNUM, 0);
}
struct sss_domain_info *domain,
const char *sid,
const char **attrs,
{
struct tevent_req *req;
}
struct tevent_req *
struct sss_domain_info *dom,
bool fast_reply,
enum sss_dp_acct_type type,
const char *opt_name,
const char *extra)
{
if (ctx->create_user1) {
}
if (ctx->create_user2) {
}
if (ctx->create_group1) {
}
if (ctx->create_group2) {
}
}
static int test_single_domain_setup(void **state)
{
return 0;
}
static int test_single_domain_teardown(void **state)
{
struct cache_req_test_ctx *test_ctx;
return 0;
}
static int test_multi_domain_setup(void **state)
{
return 0;
}
static int test_multi_domain_teardown(void **state)
{
struct cache_req_test_ctx *test_ctx;
return 0;
}
void test_user_by_name_multiple_domains_found(void **state)
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
void test_user_by_name_multiple_domains_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_user_by_name_multiple_domains_parse(void **state)
{
char *fqn;
/* Add user to the first domain with different uid then test user. */
"responder_cache_req_test_a", true);
/* Add test user to the last domain. */
"responder_cache_req_test_d", true);
/* Append domain name to the username. */
"responder_cache_req_test_d");
/* Mock values. */
/* Test. */
}
void test_user_by_name_cache_valid(void **state)
{
/* Setup user. */
/* Test. */
}
void test_user_by_name_cache_expired(void **state)
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
void test_user_by_name_cache_midpoint(void **state)
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
void test_user_by_name_ncache(void **state)
{
/* Setup user. */
/* Test. */
}
void test_user_by_name_missing_found(void **state)
{
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
void test_user_by_name_missing_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_user_by_upn_multiple_domains_found(void **state)
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
void test_user_by_upn_multiple_domains_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_user_by_upn_cache_valid(void **state)
{
/* Setup user. */
/* Mock values. */
/* Test. */
}
void test_user_by_upn_cache_expired(void **state)
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
void test_user_by_upn_cache_midpoint(void **state)
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
void test_user_by_upn_ncache(void **state)
{
/* Setup user. */
/* Mock values. */
/* Test. */
}
void test_user_by_upn_missing_found(void **state)
{
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
void test_user_by_upn_missing_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_user_by_id_multiple_domains_found(void **state)
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
void test_user_by_id_multiple_domains_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_user_by_id_cache_valid(void **state)
{
/* Setup user. */
/* Test. */
}
void test_user_by_id_cache_expired(void **state)
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted. */
/* Test. */
}
void test_user_by_id_cache_midpoint(void **state)
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
void test_user_by_id_ncache(void **state)
{
/* Setup user. */
/* Test. */
}
void test_user_by_id_missing_found(void **state)
{
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
void test_user_by_id_missing_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_group_by_name_multiple_domains_found(void **state)
{
/* Setup group. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
void test_group_by_name_multiple_domains_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_group_by_name_multiple_domains_parse(void **state)
{
char *fqn;
/* Add group to the first domain. */
"responder_cache_req_test_a", true);
/* Add group to the last domain, with different gid. */
"responder_cache_req_test_d", true);
/* Append domain name to the username. */
"responder_cache_req_test_d");
/* Test. */
}
void test_group_by_name_cache_valid(void **state)
{
/* Setup group. */
/* Test. */
}
void test_group_by_name_cache_expired(void **state)
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
void test_group_by_name_cache_midpoint(void **state)
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
void test_group_by_name_ncache(void **state)
{
/* Setup group. */
/* Test. */
}
void test_group_by_name_missing_found(void **state)
{
/* Mock values. */
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
}
void test_group_by_name_missing_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_group_by_id_multiple_domains_found(void **state)
{
/* Setup group. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
void test_group_by_id_multiple_domains_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
void test_group_by_id_cache_valid(void **state)
{
/* Setup group. */
/* Test. */
}
void test_group_by_id_cache_expired(void **state)
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
void test_group_by_id_cache_midpoint(void **state)
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
void test_group_by_id_ncache(void **state)
{
/* Setup group. */
/* Test. */
}
void test_group_by_id_missing_found(void **state)
{
/* Mock values. */
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
}
void test_group_by_id_missing_notfound(void **state)
{
/* Mock values. */
/* Test. */
}
{
}
void test_user_by_recent_filter_valid(void **state)
{
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Filters always go to DP */
/* User TEST_USER is created with a DP callback. */
SYSDB_NAME, NULL);
}
void test_users_by_recent_filter_valid(void **state)
{
const char *user_names[num_users];
const char *ldb_results[num_users];
test_ctx->create_user1 = true;
test_ctx->create_user2 = true;
/* Filters always go to DP */
/* User TEST_USER1 and TEST_USER2 are created with a DP callback. */
for (int i = 0; i < num_users; ++i) {
SYSDB_NAME, NULL);
}
ldb_results, num_users));
}
void test_users_by_filter_filter_old(void **state)
{
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* This user was updated in distant past, so it wont't be reported by
* the filter search */
/* Filters always go to DP */
SYSDB_NAME, NULL);
}
void test_users_by_filter_notfound(void **state)
{
/* Filters always go to DP */
"nosuchuser*");
}
static void test_users_by_filter_multiple_domains_notfound(void **state)
{
"responder_cache_req_test_d", true);
/* Filters always go to DP */
"nosuchuser*");
}
{
}
void test_group_by_recent_filter_valid(void **state)
{
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Filters always go to DP */
/* Group TEST_GROUP is created with a DP callback. */
SYSDB_NAME, NULL);
}
void test_groups_by_recent_filter_valid(void **state)
{
const char **group_names = NULL;
const char **ldb_results = NULL;
test_ctx->create_group1 = true;
test_ctx->create_group2 = true;
/* Filters always go to DP */
/* Group TEST_GROUP1 and TEST_GROUP2 are created with a DP callback. */
for (int i = 0; i < 2; ++i) {
SYSDB_NAME, NULL);
ldb_results[i] = ldbname;
}
}
void test_groups_by_filter_notfound(void **state)
{
/* Filters always go to DP */
"nosuchgroup*");
}
void test_groups_by_filter_multiple_domains_notfound(void **state)
{
"responder_cache_req_test_d", true);
/* Filters always go to DP */
"nosuchgroup*");
}
void test_object_by_sid_user_cache_valid(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Setup user. */
/* Test. */
}
void test_object_by_sid_user_cache_expired(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
void test_object_by_sid_user_cache_midpoint(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
void test_object_by_sid_user_ncache(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Setup user. */
/* Test. */
}
void test_object_by_sid_user_missing_found(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
void test_object_by_sid_user_missing_notfound(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Mock values. */
/* Test. */
}
void test_object_by_sid_user_multiple_domains_found(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
void test_object_by_sid_user_multiple_domains_notfound(void **state)
{
const char *attrs[] = SYSDB_PW_ATTRS;
/* Mock values. */
/* Test. */
}
void test_object_by_sid_group_cache_valid(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Setup user. */
/* Test. */
}
void test_object_by_sid_group_cache_expired(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
void test_object_by_sid_group_cache_midpoint(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
void test_object_by_sid_group_ncache(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Setup user. */
/* Test. */
}
void test_object_by_sid_group_missing_found(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Mock values. */
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
}
void test_object_by_sid_group_missing_notfound(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Mock values. */
/* Test. */
}
void test_object_by_sid_group_multiple_domains_found(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
void test_object_by_sid_group_multiple_domains_notfound(void **state)
{
const char *attrs[] = SYSDB_GRSRC_ATTRS;
/* Mock values. */
/* Test. */
}
{
int opt;
struct poptOption long_options[] = {
};
const struct CMUnitTest tests[] = {
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
/* Even though normally the tests should clean up after themselves
* they might not after a failed run. Remove the old db to be sure */
}