sysdb-tests.c revision ee8dccf5f0a7de4aba16ab73a53872df9a65175c
/*
SSSD
System Database
Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
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 <stdlib.h>
#include <check.h>
#include <talloc.h>
#include <tevent.h>
#include <popt.h>
#include "confdb/confdb_setup.h"
#include "db/sysdb_private.h"
#include "db/sysdb_services.h"
#include "db/sysdb_autofs.h"
#define TESTS_PATH "tests_sysdb"
#define TEST_CONF_FILE "tests_conf.ldb"
#define TEST_ATTR_NAME "test_attr_name"
#define TEST_ATTR_VALUE "test_attr_value"
#define TEST_ATTR_UPDATE_VALUE "test_attr_update_value"
#define TEST_ATTR_ADD_NAME "test_attr_add_name"
#define TEST_ATTR_ADD_VALUE "test_attr_add_value"
#define CUSTOM_TEST_CONTAINER "custom_test_container"
#define CUSTOM_TEST_OBJECT "custom_test_object"
#define ASQ_TEST_USER "testuser27010"
#define ASQ_TEST_USER_UID 27010
#define MBO_USER_BASE 27500
#define MBO_GROUP_BASE 28500
#define NUM_GHOSTS 10
#define TEST_AUTOFS_MAP_BASE 29500
struct sysdb_test_ctx {
struct confdb_ctx *confdb;
struct tevent_context *ev;
struct sss_domain_info *domain;
};
{
struct sysdb_test_ctx *test_ctx;
char *conf_db;
int ret;
const char *val[2];
/* Create tests directory if it doesn't exist */
/* (relative to current dir) */
return EFAULT;
}
fail("Could not allocate memory for test context");
return ENOMEM;
}
/* Create an event context
* It will not be used except in confdb_init and sysdb_init
*/
fail("Could not create event context");
return EIO;
}
fail("Out of memory, aborting!");
return ENOMEM;
}
/* Connect to the conf db */
fail("Could not initialize connection to the confdb");
return ret;
}
val[0] = "LOCAL";
fail("Could not initialize domains placeholder");
return ret;
}
val[0] = "local";
fail("Could not initialize provider");
return ret;
}
fail("Could not initialize LOCAL domain");
return ret;
}
val[0] = "TRUE";
fail("Could not initialize LOCAL domain");
return ret;
}
return ret;
}
return EOK;
}
struct test_data {
struct tevent_context *ev;
struct sysdb_test_ctx *ctx;
const char *username;
const char *groupname;
const char *netgrname;
const char *autofsmapname;
const char *shell;
bool finished;
int error;
struct sysdb_attrs *attrs;
const char **attrlist;
char **memberlist;
struct ldb_message *msg;
struct ldb_message **msgs;
};
{
char *homedir;
char *gecos;
int ret;
return ret;
}
{
char *homedir;
char *gecos;
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
}
return ret;
}
{
int ret;
return ret;
}
{
const char *username;
int ret;
return ENOMEM;
}
SYSDB_MEMBER_USER, false);
return ret;
}
{
const char *username;
int ret;
return ENOMEM;
}
SYSDB_MEMBER_USER, false);
return ret;
}
{
char *object_name;
int ret;
if (!object_name) {
return ENOMEM;
}
return ret;
}
{
int ret;
return ret;
}
{
int ret;
"LOCAL");
return ENOMEM;
}
LDB_SCOPE_SUBTREE, "objectClass=user",
return ret;
}
{
int ret;
"LOCAL");
if (!dn) {
return ENOMEM;
}
return ret;
}
{
int ret;
char *member;
int i;
if (!attrs) {
return ENOMEM;
}
if (!member) {
return ENOMEM;
}
return ret;
}
}
return ret;
}
{
int ret;
char *member;
int i;
if (!attrs) {
return ENOMEM;
}
if (!member) {
return ENOMEM;
}
return ret;
}
}
data->memberlist[i]);
return ret;
}
}
return ret;
}
{
const char *description;
int ret;
return ret;
}
{
struct ldb_dn *netgroup_dn;
int ret;
if (!netgroup_dn) return ENOMEM;
return ret;
}
{
int ret;
return ret;
}
{
int ret;
const char *description;
if (!attrs) {
return ENOMEM;
}
if (ret) {
return ret;
}
return ret;
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *username;
struct ldb_message *msg;
const char *desc;
const char *desc_in = "testuser_new_id_desc";
/* Setup */
fail("Could not set up the test");
return;
}
username = "testuser_newid";
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
char *membername;
int j;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
for (j = MBO_GROUP_BASE; j < _i; j++) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
const char *username;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (ret) {
fail("sysdb_getpwnam failed for username %s (%d: %s)",
goto done;
}
goto done;
}
/* Search for the user with the wrong case */
if (ret) {
fail("sysdb_getpwnam failed for username %s (%d: %s)",
goto done;
}
fail("The upper-case username search should fail.");
}
done:
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
const char *groupname;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (ret) {
fail("sysdb_getgrnam failed for groupname %s (%d: %s)",
goto done;
}
goto done;
}
"Did not find the expected GID (found %d expected %d)",
/* Search for the group with the wrong case */
if (ret) {
fail("sysdb_getgrnam failed for groupname %s (%d: %s)",
goto done;
}
fail("The upper-case groupname search should fail.");
}
done:
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
const char *e_groupname;
const char *groupname;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (ret) {
fail("sysdb_getgrgid failed for gid %d (%d: %s)",
goto done;
}
if (e_groupname == NULL) {
fail("Cannot allocate memory");
goto done;
}
"Did not find the expected groupname (found %s expected %s)",
done:
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
char *filter;
struct ldb_message **msgs;
/* Setup */
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
const char *e_username;
const char *username;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (ret) {
fail("sysdb_getpwuid failed for uid %d (%d: %s)",
goto done;
}
fail("Cannot allocate memory");
goto done;
}
"Did not find the expected username (found %s expected %s)",
done:
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
&res);
"sysdb_enumgrent failed (%d: %s)",
/* 10 groups + 10 users (we're MPG) */
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
&res);
"sysdb_enumpwent failed (%d: %s)",
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
fail("Could not create the changeset");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
char *filter;
struct ldb_message **msgs;
/* Setup */
_i);
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
char *rmattrs[2];
char *username;
struct ldb_result *res;
const char *shell;
rmattrs);
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
const char *attrval;
char *username;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
&res);
if (ret) {
goto done;
}
"Got bad attribute value for user %s", username);
done:
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
const char *attrval;
const char *username = "test_sysdb_get_user_attr_subdomain";
const char *fq_name;
int ret;
/* Setup */
/* Create subdomain */
false, false, NULL);
"(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
"((?P<name>[^@]+)@(?P<domain>.+$))|" \
"(^(?P<name>[^@\\\\]+)$))",
/* Create user */
-1, 0);
/* Test */
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *username;
struct ldb_result *res;
struct ldb_message *user;
struct ldb_message *group;
/* Setup */
fail("Could not set up the test");
return;
}
/* result should contain 2 messages - user and his group */
/* check if it's the expected user and expected group */
"Did not find the expected UID (found %d expected %d)",
username) == 0,
"Wrong username\n");
"Did not find the expected GID (found %d expected %d)",
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create attribute list");
return;
}
fail("Could not add attribute");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
char *object_name;
/* Setup */
fail("Could not set up the test");
return;
}
&data->msgs_count,
"Wrong number of objects, exptected [1] got [%d]",
data->msgs_count);
"Wrong number of results, expected [1] got [%d]",
"Wrong attribute name");
"Wrong number of attribute values");
"Wrong attribute value");
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create attribute list");
return;
}
fail("Could not add attribute");
return;
}
fail("Could not add attribute");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
char *object_name;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
&data->msgs_count,
"Wrong number of objects, exptected [1] got [%d]",
data->msgs_count);
"Wrong number of results, expected [2] got [%d]",
"Wrong attribute value");
"Wrong attribute value");
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *filter = "(distinguishedName=*)";
/* Setup */
fail("Could not set up the test");
return;
}
&data->msgs_count,
"Wrong number of objects, exptected [10] got [%d]",
data->msgs_count);
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
}
static void cached_authentication_without_expiration(const char *username,
const char *password,
int expected_result)
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *val[2];
/* Setup */
val[0] = "0";
fail("Could not initialize provider");
return;
}
&expire_date, &delayed_until);
"return expected result [%d].",
0, expire_date);
-1, delayed_until);
}
static void cached_authentication_with_expiration(const char *username,
const char *password,
int expected_result)
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *val[2];
/* Setup */
val[0] = "1";
fail("Could not initialize provider");
return;
}
"Setting SYSDB_LAST_ONLINE_AUTH to [%lld].\n", (long long) now);
&expire_date, &delayed_until);
"sysdb_cache_auth request does not return expected "
"Wrong expire date, expected [%d], got [%d]",
-1, delayed_until);
}
{
char *username;
}
{
char *username;
}
{
char *username;
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
struct ldb_message **msgs;
int i;
char *gid_str;
/* Setup */
fail("Could not set up the test");
return;
}
"found [%d] expected [10]", msgs_count);
for (i = 0; i < msgs_count; i++) {
"found [%d] expected [1]",
msgs[i]->num_elements);
"wrong number of values, found [%d] expected [1]",
"wrong value, found [%.*s] expected [%s]",
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
int i;
char *uid_str;
/* Setup */
fail("Could not set up the test");
return;
}
"wrong number of results, found [%d] expected [10]",
data->msgs_count);
for (i = 0; i < data->msgs_count; i++) {
"wrong number of elements, found [%d] expected [1]",
"wrong number of values, found [%d] expected [1]",
"wrong value, found [%.*s] expected [%s]",
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_attrs *attrs;
struct ldb_message_element *el;
int ret;
"sysdb_attrs_replace overwrites existing attribute");
"Wrong number of values for attribute oof, "
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (_i == 0) {
} else {
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (_i == 0) {
} else {
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (_i == 0) {
} else {
}
}
{
struct sysdb_test_ctx *test_ctx;
char *ghostname;
int ret;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
/* Before the add, the groups should not contain the ghost attribute */
/* The first group would have the ghost attribute gone completely */
"Ghost user %s unexpectedly found\n", ghostname);
} else {
}
}
/* Perform the add operation */
/* Before the delete, all groups with gid >= _i have the testuser%_i
* as a member
*/
}
}
{
struct sysdb_test_ctx *test_ctx;
char *ghostname_del;
char *ghostname_add;
int ret;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
/* The test replaces the testuser%i attribute with testghost%i */
/* Before the replace, all groups with gid >= _i have the testuser%_i
* as a member
*/
}
/* Perform the replace operation */
/* After the replace, all groups with gid >= _i have the testghost%_i
* as a member
*/
}
}
{
struct sysdb_test_ctx *test_ctx;
char *ghostname_rep;
char *ghostname_del;
char *ghostname_check;
int ret;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
/* The test replaces the attributes (testusera$gid, testuserb$gid) with
* just testusera$gid. The result should be not only testusera, but also
* all ghost users inherited from child groups
*/
/* Before the replace, all groups with gid >= _i have both testuser a
* and testuserb as a member
*/
/* inherited users must be there */
/* Also check the B user if it hasn't been deleted yet */
}
}
}
/* Perform the replace operation */
/* After the replace, testusera should still be there, but we also need
* to keep ghost users inherited from other groups
*/
/* testusera must still be there */
/* testuserb must be gone */
/* inherited users must still be there */
/* Also check the B user if it hasn't been deleted yet */
}
}
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (_i == 5) {
"sysdb_search_group_by_gid found "
"already deleted group");
} else {
"Wrong number of results, expected [1] got [%d]",
"Wrong attribute name");
"Wrong number of attribute values, "
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
"Wrong number of results, expected [1] got [%d]",
"Wrong attribute name");
"Wrong number of attribute values, expected [%d] got [%d]",
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
"Wrong number of results, expected [1] got [%d]",
"Wrong attribute name");
"Wrong number of attribute values, expected [%d] got [%d]",
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (_i == 5) {
"sysdb_search_group_by_gid_send found "
"already deleted group");
} else {
"Wrong number of results, expected [1] got [%d]",
"Wrong attribute name");
"Wrong number of attribute values, expected [%d] got [%d]",
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
"Wrong attribute name");
"Wrong number of attribute values, expected [%d] got [%d]",
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
"Wrong attribute name");
"Wrong number of attribute values, expected [%d] got [%d]",
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
"Wrong attribute name");
/* Expect our own and our parent's */
"Wrong number of attribute values, expected [%d] got [%d]",
/* Remove the parent */
/* Check the parent again. The inherited ghost user should be gone. */
"Wrong attribute name");
/* Expect our own now only */
"Wrong number of attribute values, expected [%d] got [%d]",
}
{
struct sysdb_test_ctx *test_ctx;
char *ghostname;
int ret;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
/* Before the delete, all groups with gid >= _i have the testuser%_i
* as a member
*/
}
/* Delete the attribute */
/* After the delete, we shouldn't be able to find the ghost attribute */
/* The first group would have the ghost attribute gone completely */
"Ghost user %s unexpectedly found\n", ghostname);
} else {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret, j;
char *expected;
/* Setup */
fail("Could not set up the test");
return;
}
if (_i > MBO_GROUP_BASE) {
/* After the previous test, the first group (gid == MBO_GROUP_BASE)
* has no ghost users. That's a legitimate test case we need to account
* for now.
*/
"Wrong number of results, expected [1] got [%d] for %d",
}
return;
}
"Wrong attribute name");
"Wrong number of attribute values, expected [%d] got [%d]",
for (j = MBO_GROUP_BASE; j < _i; j++) {
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
struct ldb_message_element *ghosts;
struct ldb_message_element *members;
/* Eplicitly disable enumeration during setup as converting the ghost
* users into real ones work only when enumeration is disabled
*/
fail("Could not set up the test");
return;
}
"Wrong number of results, expected [1] got [%d] for %d",
return;
}
}
if (exp_gh < 0) {
exp_gh = 0;
}
if (exp_gh) {
}
}
{
struct sysdb_test_ctx *test_ctx;
char *ghostname_del;
char *ghostname_add;
int ret;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
/* The test replaces the testghost%i attribute with testuser%i */
/* Before the replace, the group has the testghost%_i as a member */
/* Perform the replace operation */
/* After the replace, the group has the testghost%_i as a member */
}
{
struct sysdb_test_ctx *test_ctx;
char *ghostname_del;
char *ghostname_add;
int ret;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create the changeset");
return;
}
/* The test replaces the testghost%i attribute with testuser%i */
/* Before the replace, the group has the testghost%_i as a member */
/* Perform the replace operation */
/* After the replace, the group has the testghost%_i as a member */
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
bool value;
int ret;
const char *attr_val = "BOOL_VALUE";
/* Setup */
fail("Could not set up the test");
return;
}
/* attribute is not created yet */
&value);
"sysdb_get_bool returned %d:[%s], but ENOENT is expected",
/* add attribute */
attr_val, true);
/* successfully obtain attribute */
&value);
fail_unless(value == true);
/* use non-existing DN */
"non-existing domain");
&value);
"sysdb_get_bool returned %d:[%s], but ENOENT is expected",
/* free ctx */
}
{
char **list;
"test_attr", &list);
list[0]);
list[1]);
}
{
struct sysdb_test_ctx *test_ctx;
struct sysdb_attrs *user_attrs;
const char *str;
/* Get real, uncanonicalized name as string */
"RealName", str);
"foo@bar", str);
}
{
struct sysdb_test_ctx *test_ctx;
const char *name;
const char *fromname = "fromgroup";
const char *toname = "togroup";
struct ldb_result *res;
/* Setup */
/* Store and verify the first group */
goto done;
}
"Did not find the expected GID (found %llu expected %llu)",
"Did not find the expected name (found %s expected %s)",
/* Perform rename and check that GID is the same, but name changed */
goto done;
}
"Did not find the expected GID (found %llu expected %llu)",
"Did not find the expected GID (found %s expected %s)",
/* Verify the first name is gone */
done:
}
{
struct sysdb_test_ctx *test_ctx;
const char *name;
const char *fromname = "fromuser";
const char *toname = "touser";
struct ldb_result *res;
/* Setup */
/* Store and verify the first user */
goto done;
}
"Did not find the expected UID (found %llu expected %llu)",
"Did not find the expected name (found %s expected %s)",
/* Perform rename and check that GID is the same, but name changed */
goto done;
}
"Did not find the expected UID (found %llu expected %llu)",
"Did not find the expected name (found %s expected %s)",
/* Verify the first name is gone */
done:
}
{
struct sysdb_test_ctx *test_ctx;
char **add_groups;
char **del_groups;
const char *user = "testuser27000";
/* Setup */
/* Add a user to two groups */
(const char *const *)add_groups, NULL);
/* Remove a user from one group and add to another */
(const char *const *)add_groups,
(const char *const *)del_groups);
/* Remove a user from two groups */
NULL, (const char *const *)del_groups);
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *groupname;
char *parsed;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Out of memory");
return;
}
"Names don't match (got %s)", parsed);
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *netgrname;
struct ldb_message *msg;
struct ldb_dn *netgroup_dn;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
const char *description;
const char *netgrname;
struct ldb_result *res;
const char *attrval;
/* Setup */
fail("Could not set up the test");
return;
}
"Got bad attribute value for netgroup %s", netgrname);
}
{
struct sysdb_test_ctx *test_ctx;
const char *strdn;
"Malformed netgroup baseDN");
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
struct ldb_message *msg;
const char odd_username[] = "*(odd)\\user,name";
const char odd_username_orig_dn[] =
"\\2a\\28odd\\29\\5cuser,name,cn=users,dc=example,dc=com";
const char odd_groupname[] = "*(odd\\*)\\group,name";
const char odd_netgroupname[] = "*(odd\\*)\\netgroup,name";
const char *received_user;
const char *received_group;
static const char *user_attrs[] = SYSDB_PW_ATTRS;
static const char *netgr_attrs[] = SYSDB_NETGR_ATTRS;
/* Setup */
fail("Could not set up the test");
return;
}
/* ===== Groups ===== */
/* Add */
/* Retrieve */
"Expected [%s], got [%s]",
/* ===== Users ===== */
/* Add */
10000, 10000,
"","","");
/* Retrieve */
"Expected [%s] got [%s]\n",
/* Add to the group */
SYSDB_MEMBER_USER, false);
"Expected [%s], got [%s]",
/* Attributes */
user_attrs, &res);
/* Delete User */
/* Delete non existing User */
/* Delete Group */
/* Add */
10000, 0,
"","","",
NULL, 5400, 0);
/* Delete User */
/* ===== Netgroups ===== */
/* Add */
odd_netgroupname, "No description",
/* Retrieve */
/* ===== Arbitrary Entries ===== */
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
const char groupname[] = "test_group";
const char *received_group;
/* Setup */
fail("Could not set up the test");
return;
}
"non-existing-group");
/* Add */
/* Retrieve */
/* Empty filter */
NULL);
/* Non-empty filter */
/* Filter yeilding no results */
"objectClass=nonExistingObjectClass");
/* Non-existing dn */
}
/* == SERVICE TESTS == */
bool by_name,
const char *primary_name,
int port,
const char **aliases,
const char **protocols)
{
unsigned int i, j;
bool matched;
const char *ret_name;
int ret_port;
struct ldb_result *res;
struct ldb_message *msg;
struct ldb_message_element *el;
if (by_name) {
/* Look up the service by name */
} else {
/* Look up the newly-added service by port */
&res);
}
/* Make sure the returned entry matches */
for (i = 0; i < el->num_values; i++) {
matched = false;
for (j = 0; aliases[j]; j++) {
matched = true;
}
}
}
for (i = 0; i < el->num_values; i++) {
matched = false;
for (j = 0; protocols[j]; j++) {
matched = true;
}
}
}
}
do { \
} while(0);
do { \
} while(0);
{
struct sysdb_test_ctx *test_ctx;
char *primary_name;
const char **aliases;
const char **protocols;
int port = 3890;
/* Setup */
NULL);
/* Search by name and make sure the results match */
/* Search by port and make sure the results match */
/* Clean up after ourselves (and test deleting by name)
*
* We have to do this after the transaction, because LDB
* doesn't like adding and deleting the same entry in a
* single transaction.
*/
}
{
struct sysdb_test_ctx *test_ctx;
const char *primary_name = "test_store_service";
const char *alt_primary_name = "alt_test_store_service";
const char **aliases;
const char **protocols;
int port = 3890;
int altport = 3891;
/* Setup */
/* Store this group (which will add it) */
/* Search by name and make sure the results match */
/* Search by port and make sure the results match */
/* Change the service name */
/* Search by port and make sure the results match */
/* Change it back */
/* Change the port number */
/* Search by name and make sure the results match */
/* Search by port and make sure the results match */
/* TODO: Test changing aliases and protocols */
/* Clean up after ourselves (and test deleting by port)
*
* We have to do this after the transaction, because LDB
* doesn't like adding and deleting the same entry in a
* single transaction.
*/
}
const char *alias);
{
struct sysdb_test_ctx *test_ctx;
const char *primary_name = "remove_alias_test";
const char **aliases;
const char **protocols;
int port = 3990;
/* Setup */
NULL);
/* Search by name and make sure the results match */
/* Search by port and make sure the results match */
/* Now remove an alias */
/* Set aliases[1] to NULL to perform validation checks */
/* Search by name and make sure the results match */
/* Search by port and make sure the results match */
}
#define LC_NAME_ALIAS_TEST_VAL "TeSt VaLuE"
#define LC_NAME_ALIAS_CHECK_VAL "test value"
{
int ret;
struct sysdb_attrs *attrs;
const char *str;
"Unexpected value, expected [%s], got [%s]",
}
{
int ret;
struct sysdb_attrs *attrs;
const char **list;
const char *attrname = "test_attr";
/* This test relies on values keeping the same order. It is the case
* with LDB, but if we ever switch from LDB, we need to amend the test
*/
}
{
int ret;
struct sysdb_attrs *attrs;
sizeof(TEST_ATTR_VALUE) - 1};
"Unexpected attribute name.");
"Unexpected number of attribute values.");
TEST_ATTR_VALUE) == 0,
"Unexpected attribute value.");
TEST_ATTR_VALUE) == 0,
"Unexpected attribute value.");
}
{
int ret;
struct sysdb_attrs *attrs;
sizeof(TEST_ATTR_VALUE) - 1};
"Unexpected attribute name.");
"Unexpected number of attribute values.");
TEST_ATTR_VALUE) == 0,
"Unexpected attribute value.");
}
{
int ret;
struct sysdb_attrs *attrs;
"Unexpected attribute name.");
"Unexpected number of attribute values.");
TEST_ATTR_VALUE) == 0,
"Unexpected attribute value.");
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
/* id mapping */
/* Search user */
"nonexisting_user", &str);
/* Search group */
/* Search netgroup */
&res);
/* Search object */
/* Search can return more results */
/* Search custom */
"(distinguishedName=nonexisting)",
"nonexisting",
/* General search */
"objectClass=user", NULL,
/* SSS_LDB_SEARCH */
/* TODO: test sysdb_search_selinux_config */
}
{
struct sysdb_test_ctx *test_ctx;
bool enumerated;
/* Setup */
"Error [%d][%s] checking enumeration ENOENT is expected",
/* Recheck enumeration status */
}
{
struct sysdb_test_ctx *test_ctx;
const char *filter;
struct ldb_message **msgs;
/* Setup */
"case_sensitive_group1", 29000,
"cn=case_sensitive_group1,cn=example,cn=com",
NULL, true, 0);
"case_sensitive_group2", 29001,
"cn=CASE_SENSITIVE_GROUP1,cn=EXAMPLE,cn=COM",
NULL, true, 0);
/* Search by originalDN should yield 2 entries */
"cn=case_sensitive_group1,cn=example,cn=com");
"case insensitive originalDN search");
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_message *msg;
/* Setup */
"group", 29000,
"cn=group,cn=example,cn=com",
"S-1-2-3-4", true, 0);
/* Delete the group by SID */
/* Verify it's gone */
}
{
struct sysdb_test_ctx *test_ctx;
struct ldb_result *res;
/* Setup */
"11111111-2222-3333-4444-555555555555");
"11111111-2222-3333-4444-555555555556",
"Unexpected return code from sysdb_search_object_by_uuid for "
"11111111-2222-3333-4444-555555555555",
SYSDB_NAME, ""),
"UUIDuser") == 0, "Unexpected object found, " \
"expected [%s], got [%s].", "UUIDuser",
}
{
struct sysdb_test_ctx *test_ctx;
/* Setup */
/* Delete the group by SID */
"S-1-2-3-4-NON_EXISTING_SID");
}
{
struct sysdb_test_ctx *test_ctx;
false, false, NULL);
"Unexpected sub-domain found, expected [%s], got [%s]",
false, false, NULL);
"Unexpected sub-domain found, expected [%s], got [%s]",
}
{
struct sysdb_test_ctx *test_ctx;
struct sysdb_attrs *user_attrs;
struct ldb_message *msg;
false, false, NULL);
false, false, NULL);
"/home/subdomuser", "/bin/bash",
"name=SubDomUser,cn=users,cn=test.sub,cn=sysdb");
"expected [%d], got [%d]",
"Unexpedted DN returned");
/* Subdomains are case-insensitive. Test that the lowercased name
* can be found, too */
&msg);
"expected [%d], got [%d]",
}
{
struct sysdb_test_ctx *test_ctx;
false, false, NULL);
false, false, NULL);
"/home/subdomuser", "/bin/bash",
"name=subdomuser,cn=users,cn=test.sub,cn=sysdb");
&msg);
"Unexpedted DN returned");
"Unexpedted DN returned");
}
{
struct sysdb_test_ctx *test_ctx;
struct sysdb_attrs *group_attrs;
false, false, NULL);
false, false, NULL);
"name=subDomGroup,cn=groups,cn=test.sub,cn=sysdb");
&msg);
"Unexpected DN returned");
/* subdomains are case insensitive, so it should be possible to search
the group with a lowercase name version, too */
&msg);
"Unexpected DN returned");
"Unexpedted DN returned");
}
#ifdef BUILD_AUTOFS
{
struct sysdb_test_ctx *test_ctx;
const char *autofsmapname;
autofsmapname, NULL, 0, 0);
}
{
struct sysdb_test_ctx *test_ctx;
const char *autofsmapname;
autofsmapname, &map);
}
{
struct sysdb_test_ctx *test_ctx;
const char *autofsmapname;
}
{
struct sysdb_test_ctx *test_ctx;
const char *autofsmapname;
autofsmapname, &map);
}
{
struct sysdb_test_ctx *test_ctx;
const char *autofsmapname;
const char *autofskey;
const char *autofsval;
int ii;
const int limit = 10;
autofsmapname, ii);
}
}
{
struct sysdb_test_ctx *test_ctx;
const char *autofsmapname;
struct ldb_message **entries;
const int expected = 10;
}
{
struct sysdb_test_ctx *test_ctx;
const char *autofsmapname;
const char *autofskey;
const char *autofsval;
}
{
struct sysdb_test_ctx *test_ctx;
const char *autofskey;
const char *attrs[] = { SYSDB_AUTOFS_ENTRY_KEY,
NULL };
struct ldb_message **msgs;
const char *filter;
const int expected = 10;
}
#endif /* BUILD_AUTOFS */
{
char *conf_db;
int ret;
struct confdb_ctx *confdb;
/* Create tests directory if it doesn't exist */
/* (relative to current dir) */
return NULL;
}
/* Make sure the test domain does not interfere with our testing */
return NULL;
}
/* Connect to the conf db */
return confdb;
}
{
int ret;
struct confdb_ctx *confdb;
char **names;
/* No domain */
}
{
int ret;
struct confdb_ctx *confdb;
char **names;
const char *val[2];
/* One domain */
val[0] = "LOCAL";
val[0] = "local";
}
#define UPN_USER_NAME "upn_user"
#define UPN_PRINC "upn_user@UPN.TEST"
#define UPN_PRINC_WRONG_CASE "UpN_uSeR@uPn.TeSt"
#define UPN_CANON_PRINC "upn_user@UPN.CANON"
#define UPN_CANON_PRINC_WRONG_CASE "uPn_UsEr@UpN.CaNoN"
{
struct sysdb_test_ctx *test_ctx;
struct sysdb_attrs *attrs;
int ret;
struct ldb_message *msg;
const char *str;
/* Setup */
fail("Could not set up the test");
return;
}
UPN_USER_NAME, "x",
"sysdb_search_user_by_upn failed with non-existing UPN.");
UPN_USER_NAME, str);
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
struct ldb_message *msg;
const char *str;
/* Setup */
fail("Could not set up the test");
return;
}
UPN_USER_NAME, str);
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
struct ldb_message *msg;
const char *str;
/* Setup */
fail("Could not set up the test");
return;
}
UPN_USER_NAME, str);
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
struct ldb_message *msg;
const char *str;
/* Setup */
fail("Could not set up the test");
return;
}
UPN_USER_NAME, str);
}
{
struct sysdb_test_ctx *test_ctx;
struct sysdb_attrs *attrs;
int ret;
struct ldb_message *msg;
const char *str;
/* Setup */
fail("Could not set up the test");
return;
}
"sysdb_search_user_by_upn failed for duplicated UPN.");
UPN_USER_NAME, str);
}
{
struct sysdb_test_ctx *test_ctx;
const char *guid;
int version;
static const char *test_guid = "3610EDA5-77EF-11D2-8DC5-00C04FA31A66";
&result);
}
{
struct sysdb_test_ctx *test_ctx;
const char *guid;
int version;
static const char *test_guid = "3610EDA5-77EF-11D2-8DC5-00C04FA31A66";
/* Modify the version */
}
{
struct sysdb_test_ctx *test_ctx;
const char *allow_key = "SeRemoteInteractiveLogonRight";
const char *deny_key = "SeDenyRemoteInteractiveLogonRight";
/* No result in cache */
/* Delete with no result object is a noop */
/* Store an allow value, triggering a new result object */
allow_key, "allow_val1");
/* Now both searches should succeed, but only allow_key should return
* a valid value
*/
/* Updating replaces the original value */
allow_key, "allow_val2");
/* NULL removes the value completely */
/* Delete the result */
/* No result in cache */
}
{
int ret;
struct confdb_ctx *confdb;
char **names;
const char *val[2];
/* Two domains */
val[0] = "LOCAL";
val[0] = "local";
val[0] = "REMOTE";
val[0] = "local";
}
Suite *create_sysdb_suite(void)
{
/* test getting next id works */
/* Add a user with an automatic ID */
/* Create a new user */
/* Verify the users were added */
/* Create a new group */
/* Verify the groups were added */
/* sysdb_group_dn_name returns the name of the group in question */
/* sysdb_store_user allows setting attributes for existing users */
/* test the change */
/* Add and remove users in a group with sysdb_update_members */
/* Remove the other half by gid */
/* Remove the other half by uid */
/* Create a new user */
/* Verify the users were added */
/* Verify the users can be queried by UID */
/* Enumerate the users */
/* Change their attribute */
/* Find the users by their new attribute */
/* Verify the change */
/* Remove the attribute */
/* Create a new group */
/* Verify the groups were added */
/* Verify the groups can be queried by GID */
/* Find the users by GID using a filter */
/* Enumerate the groups */
/* Add some members to the groups */
/* Test that sysdb_initgroups() works */
/* Authenticate with missing cached password */
27010, 27011);
/* Add a cached password */
/* Authenticate against cached password */
27010, 27011);
/* ASQ search test */
/* Test search with more than one result */
/* Remove the members from the groups */
/* Remove the users by name */
/* Remove the groups by name */
/* test the ignore_not_found parameter for users */
/* test the ignore_not_found parameter for groups */
/* Create incomplete groups - remove will fail if the LDB objects don't exist */
/* test custom operations */
/* test recursive delete */
/* Test unusual characters */
/* Test sysdb enumerated flag */
/* Test originalDN searches */
/* Test SID string searches */
/* Test UUID string searches */
/* Test canonicalizing names */
/* Test user and group renames */
/* Test GetUserAttr with subdomain user */
/* ===== NETGROUP TESTS ===== */
/* Create a new netgroup */
/* Verify the netgroups were added */
/* Test setting attributes */
/* Verify they have been changed */
/* Remove half of them by name */
/* Remove the other half by DN */
/* ===== SERVICE TESTS ===== */
/* Create a new service */
/* ===== UTIL TESTS ===== */
/* ===== Test search return empty result ===== */
/* ===== Misc ===== */
/* Add all test cases to the test suite */
suite_add_tcase(s, tc_sysdb);
0, 10);
0, 10);
0, 10);
0, 10);
0, 10);
0, 10);
/* Ghost users tests */
/* Only one group should be left now */
/* ghost users - RFC2307 */
/* Add groups with ghost users */
/* Check the ghost user attribute */
/* Add user entries, converting the ghost attributes to member attributes */
/* We only convert half of the users and keep the ghost attributes for the
* other half as we also want to test if we don't delete any ghost users
* by accident
*/
/* Check the members and ghosts are there as appropriate */
/* Rename the other half */
/* Attempt to replace with the same data to check if noop works correctly */
/* Remove the real users */
/* ghost users - memberof mod_del */
/* ghost users - memberof mod_add */
/* Add groups without ghosts first */
/* Add ghosts to groups so that they propagate */
/* Check if the ghosts in fact propagated */
/* Clean up */
/* ghost users - replace */
/* ghost users - replace but retain inherited */
/* SSS_LDB_SEARCH */
/* This loop counts backwards so the indexing is a little odd */
1 , 11);
#ifdef BUILD_AUTOFS
suite_add_tcase(s, tc_autofs);
#endif
suite_add_tcase(s, tc_upn);
suite_add_tcase(s, tc_gpo);
/* ConfDB tests -- modify confdb, must always be last!! */
suite_add_tcase(s, tc_confdb);
return s;
}
int opt;
int failure_count;
int no_cleanup = 0;
struct poptOption long_options[] = {
_("Do not delete the test database after a test run"), NULL },
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
if (!ldb_modules_path_is_set()) {
"will use LDB plugins installed in system paths.\n");
}
/* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
if (failure_count == 0 && !no_cleanup) {
}
}