test_responder_cache_req.c revision a6a5a08a357d2adbb653b81bacc602ca3543c4c4
/*
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_NAME "test-user"
#define TEST_UPN "upn@upndomain.com"
#define TEST_USER_ID 1000
#define TEST_GROUP_NAME "test-group"
#define TEST_GROUP_ID 1000
#define TEST_USER_ID2 1001
#define TEST_USER_NAME2 "test_user2"
#define TEST_GROUP_NAME2 "test_group2"
#define TEST_GROUP_ID2 1001
#define TEST_USER_ID3 1002
#define TEST_USER_NAME3 "test_user3"
#define TEST_GROUP_NAME3 "test_group3"
#define TEST_GROUP_ID3 1002
#define TEST_USER_PREFIX "test*"
#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 bool, use bitshift. */
bool create_user1;
bool create_user2;
bool create_group;
};
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 sss_domain_info *domain,
const char* user_name,
int user_id,
int group_id,
{
struct sysdb_attrs *attrs;
}
struct sss_domain_info *domain,
{
}
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;
SYSDB_NAME, NULL);
SYSDB_UIDNUM, 0);
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *exp_dom)
{
const char *ldbname;
SYSDB_NAME, NULL);
SYSDB_GIDNUM, 0);
}
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_group) {
}
}
static int test_single_domain_setup(void **state)
{
return 0;
}
static int test_single_domain_teardown(void **state)
{
return 0;
}
static int test_multi_domain_setup(void **state)
{
return 0;
}
static int test_multi_domain_teardown(void **state)
{
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)
{
const char *name = TEST_USER_NAME;
/* 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)
{
const char *name = TEST_GROUP_NAME;
/* 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_group = true;
/* 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_group = true;
/* 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 = NULL;
const char **ldb_results = NULL;
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. */
user_names[0] = TEST_USER_NAME;
for (int i = 0; i < 2; ++i) {
SYSDB_NAME, NULL);
ldb_results[i] = ldbname;
}
}
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_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*");
}
{
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 */
}