/*
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"
#include "db/sysdb_private.h" /* new_subdomain() */
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 tevent_req *req; \
\
\
domtype, \
assert_non_null(req); \
\
\
} while (0)
struct cache_req_test_ctx {
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;
bool create_subgroup1;
bool create_subuser1;
};
"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 sss_domain_info *domain,
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) {
}
if (ctx->create_subgroup1) {
true);
}
if (ctx->create_subuser1) {
true);
}
}
struct sss_test_conf_param *params)
{
return 0;
}
{
}
{
return 0;
}
{
{ "min_id", "100" },
{ "max_id", "10000" },
};
}
{
return 0;
}
{
/* Test. */
0, 10, ENOENT);
}
{
/* Test. */
0, 100000, ENOENT);
}
{
return 0;
}
{
int ret;
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. */
0,
}
{
/* 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's UPN. */
/* 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. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
"responder_cache_req_test_d", true);
/* Test. */
/* Even though the locator tells us to skip all domains except d, the domains
* are standalone and the result of the locator request is only valid within
* the subdomains
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
"responder_cache_req_test_d", true);
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
/* Test. */
/* Even though the ID is present in the last domain,
* we're not calling sss_dp_get_account_send,
* because the locator will cause cache_req to skip
* all domains except _d
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
/* Note - DP will only be called once and we're not waiting
* for the results (so, we're not mocking _recv)
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
test_ctx->create_subuser1 = true;
true);
}
{
/* Test. */
0, 10, ENOENT);
}
{
/* Test. */
0, 100000, ENOENT);
}
{
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
test_ctx->create_subuser1 = true;
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
/* Request the same user again */
}
{
/* 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. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
"responder_cache_req_test_d", true);
/* Test. */
/* Even though the locator tells us to skip all domains except d, the domains
* are standalone and the result of the locator request is only valid within
* the subdomains
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
"responder_cache_req_test_d", true);
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
/* Test. */
/* Even though the ID is present in the last domain,
* we're not calling sss_dp_get_account_send,
* because the locator will cause cache_req to skip
* all domains except _d
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
/* Note - DP will only be called once and we're not waiting
* for the results (so, we're not mocking _recv)
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
test_ctx->create_subgroup1 = true;
true);
}
{
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
test_ctx->create_subgroup1 = true;
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
/* Request the same group again */
}
{
/* 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 won'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. */
}
{
/* 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. We explicitly add the UID into BOTH UID and GID
* namespaces, because otherwise the cache_req plugin would
* search the Data Provider anyway, because it can't be sure
* the object can be of the other type or not
*/
false,
false,
/* 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 group. We explicitly add the UID into BOTH UID and GID
* namespaces, because otherwise the cache_req plugin would
* search the Data Provider anyway, because it can't be sure
* the object can be of the other type or not
*/
false,
false,
/* 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. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
"responder_cache_req_test_d", true);
/* Test. */
/* Even though the locator tells us to skip all domains except d, the domains
* are standalone and the result of the locator request is only valid within
* the subdomains
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
"responder_cache_req_test_d", true);
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
/* Test. */
/* Even though the ID is present in the last domain,
* we're not calling sss_dp_get_account_send,
* because the locator will cause cache_req to skip
* all domains except _d
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
/* Note - DP will only be called once and we're not waiting
* for the results (so, we're not mocking _recv)
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
test_ctx->create_subuser1 = true;
true);
}
{
/* The test won't even ask the DP for the object, just iterate
* over the domains using the negative cache and quit
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup user. */
true);
test_ctx->create_subuser1 = true;
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
/* Request the same user again */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
"responder_cache_req_test_d", true);
/* Test. */
/* Even though the locator tells us to skip all domains except d, the domains
* are standalone and the result of the locator request is only valid within
* the subdomains
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
"responder_cache_req_test_d", true);
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
/* Test. */
/* Even though the ID is present in the last domain,
* we're not calling sss_dp_get_account_send,
* because the locator will cause cache_req to skip
* all domains except _d
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
/* Note - DP will only be called once and we're not waiting
* for the results (so, we're not mocking _recv)
*/
/* Test. */
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
test_ctx->create_subgroup1 = true;
true);
}
{
/* The test won't even ask the DP for the object, just iterate
* over the domains using the negative cache and quit
*/
}
{
const char *locator_domain;
/* Has to be a talloc ptr, not just const, so it's stealable inside cache_req */
/* Setup group. */
true);
test_ctx->create_subgroup1 = true;
/* Note - DP will only be called once (so, we're not using will_return_always)
* because the locator will tell us which domain to look into. For the recv
* function, we use always b/c internally it mocks several values.
*/
/* Test. */
/* Request the same group again */
}
{
int opt;
};
};
/* Set debug level to invalid value so we can decide 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 */
}