sysdb-tests.c revision 9fb59763bce293c2490e0b9f8e97bb1f74ba0910
/*
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"
#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
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;
}
val[0] = "TRUE";
fail("Could not initialize LOCAL domain");
return ret;
}
val[0] = "TRUE";
fail("Could not initialize LOCAL domain");
return ret;
}
fail("Could not retrieve LOCAL domain");
return ret;
}
return ret;
}
return EOK;
}
struct test_data {
struct tevent_context *ev;
struct sysdb_handle *handle;
struct sysdb_test_ctx *ctx;
const char *username;
const char *groupname;
const char *shell;
bool finished;
int error;
struct sysdb_attrs *attrs;
const char *attrval; /* testing sysdb_get_user_attr */
const char **attrlist;
struct ldb_message *msg;
struct ldb_message **msgs;
};
{
}
{
}
{
struct tevent_req *req;
goto fail;
}
if (!req) {
goto fail;
}
return;
fail:
/* free transaction */
}
{
struct test_data);
char *homedir;
char *gecos;
int ret;
}
NULL, 0);
if (!subreq) {
}
}
{
int ret;
}
{
struct tevent_req *subreq;
char *homedir;
char *gecos;
int ret;
}
NULL, -1);
if (!subreq) {
return;
}
}
{
int ret;
}
{
struct tevent_req *subreq;
int ret;
}
}
{
struct test_data);
int ret;
}
{
struct tevent_req *subreq;
int ret;
}
}
{
struct test_data);
int ret;
}
{
struct tevent_req *subreq;
int ret;
}
}
{
struct test_data);
int ret;
}
{
struct tevent_req *subreq;
int ret;
}
}
{
struct test_data);
int ret;
}
{
struct test_data);
struct tevent_req *subreq;
int ret;
}
if (!subreq) {
}
}
{
int ret;
}
{
struct tevent_req *subreq;
int ret;
}
if (!subreq) {
}
}
{
int ret;
}
{
struct tevent_req *subreq;
int ret;
}
}
{
struct test_data);
int ret;
}
{
struct tevent_req *subreq;
int ret;
}
}
{
struct test_data);
int ret;
}
{
return;
}
case 0:
break;
case 1:
break;
default:
break;
}
}
{
return;
}
case 0:
break;
case 1:
break;
default:
break;
}
}
{
return;
}
case 0:
break;
case 1:
break;
default:
break;
}
}
{
return;
}
case 0:
break;
case 1:
break;
default:
break;
}
}
{
return;
}
return;
}
}
{
const int expected = 10;
return;
}
return;
}
}
{
struct tevent_req *subreq;
int ret;
}
}
{
struct test_data);
int ret;
}
{
return;
}
case 0:
break;
case 1:
break;
default:
break;
}
}
{
struct tevent_req *subreq;
const char *username;
int ret;
}
}
if (!subreq) {
}
}
{
struct test_data);
}
{
struct tevent_req *subreq;
const char *username;
int ret;
}
}
if (!subreq) {
}
}
{
struct test_data);
}
{
struct test_data);
int ret;
char *object_name;
}
if (!object_name) {
}
if (!subreq) {
}
}
{
int ret;
}
{
return;
}
{
struct test_data);
int ret;
}
if (!subreq) {
}
}
{
int ret;
}
{
struct test_data);
int ret;
}
"LOCAL");
}
if (!subreq) {
}
}
{
int ret;
return;
}
{
struct test_data);
int ret;
}
"LOCAL");
if (!dn) {
}
false);
if (!subreq) {
}
}
{
int ret;
}
{
struct tevent_req *subreq;
int ret;
char *member;
int i;
}
if (!attrs) {
}
if (!member) {
}
}
}
if (!subreq) {
}
}
{
int ret;
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *subreq;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!subreq) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *subreq;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!subreq) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
data);
}
if (ret) {
fail("sysdb_getpwnam failed for username %s (%d: %s)",
goto done;
}
"Did not find the expected UID");
/* Search for the user with the wrong case */
data_uc);
}
"The upper-case username search should fail. ");
done:
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
data);
}
if (ret) {
fail("sysdb_getgrnam failed for groupname %s (%d: %s)",
goto done;
}
"Did not find the expected GID (found %d expected %d)",
/* Search for the group with the wrong case */
data_uc);
}
"The upper-case groupname search should fail. ");
done:
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Cannot allocate memory");
return;
}
data);
}
if (ret) {
fail("sysdb_getgrgid failed for gid %d (%d: %s)",
goto done;
}
"Did not find the expected groupname (found %s expected %s)",
done:
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Cannot allocate memory");
return;
}
data);
}
if (ret) {
fail("sysdb_getpwuid failed for uid %d (%d: %s)",
goto done;
}
"Did not find the expected username (found %s expected %s)",
done:
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
data);
}
"sysdb_enumgrent failed (%d: %s)",
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
NULL,
data);
}
"sysdb_enumpwent failed (%d: %s)",
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
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;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
data);
}
if (ret) {
goto done;
}
"Got bad attribute value for user %s",
done:
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *subreq;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
fail("Could not create attribute list");
return;
}
fail("Could not add attribute");
return;
}
if (!subreq) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *subreq;
int ret;
char *object_name;
/* Setup */
fail("Could not set up the test");
return;
}
if (!subreq) {
}
"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;
struct tevent_req *subreq;
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;
}
if (!subreq) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *subreq;
int ret;
char *object_name;
struct ldb_message_element *el;
/* Setup */
fail("Could not set up the test");
return;
}
if (!subreq) {
}
"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;
struct tevent_req *subreq;
int ret;
const char *filter = "(distinguishedName=*)";
/* Setup */
fail("Could not set up the test");
return;
}
if (!subreq) {
}
"Wrong number of objects, exptected [10] got [%d]",
data->msgs_count);
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *subreq;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!subreq) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
}
static void cached_authentication_without_expiration(const char *username,
const char *password,
int expected_result)
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
const char *val[2];
/* Setup */
val[0] = "0";
fail("Could not initialize provider");
return;
}
"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;
struct tevent_req *req;
int ret;
const char *val[2];
/* Setup */
val[0] = "1";
fail("Could not initialize provider");
return;
}
"return expected result [%d], got [%d].",
"Wrong expire date, expected [%d], got [%d]",
-1, delayed_until);
}
{
char *username;
}
{
char *username;
}
{
char *username;
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
struct ldb_message **msgs;
int i;
char *gid_str;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
"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;
struct tevent_req *req;
int ret;
int i;
char *uid_str;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
"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;
struct tevent_req *subreq;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!subreq) {
}
}
}
{
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;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (_i == 0) {
} else {
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
if (!req) {
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
_i + MBO_GROUP_BASE,
if (!req) {
}
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, "
}
}
}
{
struct sysdb_test_ctx *test_ctx;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
_i + MBO_GROUP_BASE,
if (!req) {
}
"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;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
_i + MBO_GROUP_BASE,
if (!req) {
}
"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;
struct tevent_req *req;
int ret;
/* Setup */
fail("Could not set up the test");
return;
}
_i + MBO_GROUP_BASE,
if (!req) {
}
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]",
}
}
}
Suite *create_sysdb_suite(void)
{
/* Create a new user */
/* Verify the users were added */
/* Create a new group */
/* Verify the groups were added */
/* sysdb_store_user allows setting attributes for existing users */
/* test the change */
/* 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 */
/* Verify the change */
/* Create a new group */
/* Verify the groups were added */
/* Verify the groups can be queried by GID */
/* Enumerate the groups */
/* Add some members to the groups */
/* 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 */
/* test custom operations */
/* test recursive delete */
/* 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);
return s;
}
int opt;
int ret;
int failure_count;
struct poptOption long_options[] = {
{ NULL }
};
switch(opt) {
default:
return 1;
}
}
return EXIT_FAILURE;
}
/* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
if (failure_count == 0) {
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}