/*
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/cache_req/cache_req.h"
struct test_user {
const char *short_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 *short_name;
const char *sid;
{"test-group2", "S-1-5-21-3623811015-3361044348-30300820-2002", 2002}};
struct tevent_req *req; \
\
\
assert_non_null(req); \
\
\
} while (0)
struct cache_req_test_ctx {
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;
};
"responder_cache_req_test_b",
"responder_cache_req_test_c",
"responder_cache_req_test_d",
NULL};
{
};
return version;
}
{
}
{
}
{
}
{
}
{
}
{
char *fqname;
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct ldb_message *msg,
const char *check_name)
{
const char *ldbname;
char *shortname;
}
struct sss_domain_info *exp_dom)
{
const char *ldbupn;
const char *ldbsid;
user->short_name);
SYSDB_UIDNUM, 0);
}
struct test_group *group,
{
char *fqname;
}
struct sss_domain_info *domain,
{
}
struct sss_domain_info *domain,
{
}
struct test_group *group,
struct sss_domain_info *exp_dom)
{
const char *ldbsid;
group->short_name);
SYSDB_GIDNUM, 0);
}
struct sss_domain_info *domain,
const char *sid,
const char **attrs,
{
}
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) {
}
}
{
return 0;
}
{
return 0;
}
{
return 0;
}
{
return 0;
}
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
char *input_fqn;
char *fqname;
/* 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 to form the qualified input.
* We don't use the internal fqname here on purpose, because this is
* the user's input.
*/
"responder_cache_req_test_d");
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
{
char *fqname;
/* Setup user. */
/* Test. */
}
{
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted. */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
{
/* Setup user. */
/* Test. */
}
{
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup group. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
char *input_fqn;
char *fqname;
/* 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 groupname.
* We don't use the internal fqname here on purpose, because this is
* the user's input.
*/
"responder_cache_req_test_d");
/* Test. */
}
{
/* Setup group. */
/* Test. */
}
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
{
char *fqname;
/* Setup group. */
/* Test. */
}
{
/* Mock values. */
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup group. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup group. */
/* Test. */
}
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
{
/* Setup group. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
{
/* Setup group. */
/* Test. */
}
{
/* Mock values. */
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
}
{
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Filters always go to DP */
/* User TEST_USER is created with a DP callback. */
users[0].short_name);
}
{
const char **user_names;
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));
}
{
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 */
users[0].short_name);
}
{
/* Filters always go to DP */
"nosuchuser*");
}
{
"responder_cache_req_test_d", true);
/* Filters always go to DP */
"nosuchuser*");
}
{
}
{
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Filters always go to DP */
/* Group TEST_GROUP is created with a DP callback. */
groups[0].short_name);
}
{
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;
}
}
{
/* Filters always go to DP */
"nosuchgroup*");
}
{
"responder_cache_req_test_d", true);
/* Filters always go to DP */
"nosuchgroup*");
}
{
/* Setup user. */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
{
/* Setup user. */
/* Test. */
}
{
/* Mock values. */
test_ctx->create_user1 = true;
test_ctx->create_user2 = false;
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted */
/* Test. */
}
{
/* Setup user. */
/* Mock values. */
/* DP should be contacted without callback */
/* Test. */
}
{
/* Setup user. */
/* Test. */
}
{
/* Mock values. */
test_ctx->create_group1 = true;
test_ctx->create_group2 = false;
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
/* Setup user. */
"responder_cache_req_test_d", true);
/* Mock values. */
/* Test. */
}
{
/* Mock values. */
/* Test. */
}
{
int opt;
};
};
/* 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 */
}