sysdb-tests.c revision 88e7576d8bf00bfd0eaed8731b7eee1d6b6e05a1
97a9a944b5887e91042b019776c41d5dd74557aferikabele/*
97a9a944b5887e91042b019776c41d5dd74557aferikabele SSSD
97a9a944b5887e91042b019776c41d5dd74557aferikabele
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive System Database
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is free software; you can redistribute it and/or modify
fe64b2ba25510d8c9dba5560a2d537763566cf40nd it under the terms of the GNU General Public License as published by
fe64b2ba25510d8c9dba5560a2d537763566cf40nd the Free Software Foundation; either version 3 of the License, or
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (at your option) any later version.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is distributed in the hope that it will be useful,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd but WITHOUT ANY WARRANTY; without even the implied warranty of
fe64b2ba25510d8c9dba5560a2d537763566cf40nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52fff662005b1866a3ff09bb6c902800c5cc6dedjerenkrantz GNU General Public License for more details.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd You should have received a copy of the GNU General Public License
fe64b2ba25510d8c9dba5560a2d537763566cf40nd along with this program. If not, see <http://www.gnu.org/licenses/>.
4b5981e276e93df97c34e4da05ca5cf8bbd937dand*/
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd#include <stdlib.h>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd#include <check.h>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd#include <talloc.h>
4aa805f8500255bc52a4c03259fe46df10a1d07cyoshiki#include <tevent.h>
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen#include <popt.h>
dfb59c684345700bf9186b8d44936f8b1ba082ffgryzor#include <sys/stat.h>
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi#include <sys/types.h>
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi#include "util/util.h"
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd#include "confdb/confdb_setup.h"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include "db/sysdb_private.h"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include "tests/common.h"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define TESTS_PATH "tests_sysdb"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define TEST_CONF_FILE "tests_conf.ldb"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna#define TEST_ATTR_NAME "test_attr_name"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#define TEST_ATTR_VALUE "test_attr_value"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define TEST_ATTR_UPDATE_VALUE "test_attr_update_value"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define TEST_ATTR_ADD_NAME "test_attr_add_name"
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd#define TEST_ATTR_ADD_VALUE "test_attr_add_value"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define CUSTOM_TEST_CONTAINER "custom_test_container"
bed3c2e56e8f3328e780200466b9d009093db468sf#define CUSTOM_TEST_OBJECT "custom_test_object"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define ASQ_TEST_USER "testuser27010"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define ASQ_TEST_USER_UID 27010
9597f440430d8c876dd64f5f78066804650a18ecnoodl
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define MBO_USER_BASE 27500
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define MBO_GROUP_BASE 28500
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
8559a67073808d84d85bb5dd552d4247caafe709sfstruct sysdb_test_ctx {
8559a67073808d84d85bb5dd552d4247caafe709sf struct sysdb_ctx *sysdb;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct confdb_ctx *confdb;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh struct tevent_context *ev;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick struct sss_domain_info *domain;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd};
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfstatic int setup_sysdb_tests(struct sysdb_test_ctx **ctx)
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin{
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sysdb_test_ctx *test_ctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *conf_db;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd int ret;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener const char *val[2];
117c1f888a14e73cdd821dc6c23eb0411144a41cnd val[1] = NULL;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* Create tests directory if it doesn't exist */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* (relative to current dir) */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = mkdir(TESTS_PATH, 0775);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (ret == -1 && errno != EEXIST) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd fail("Could not create %s directory", TESTS_PATH);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return EFAULT;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd test_ctx = talloc_zero(NULL, struct sysdb_test_ctx);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (test_ctx == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd fail("Could not allocate memory for test context");
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* Create an event context
117c1f888a14e73cdd821dc6c23eb0411144a41cnd * It will not be used except in confdb_init and sysdb_init
117c1f888a14e73cdd821dc6c23eb0411144a41cnd */
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim test_ctx->ev = tevent_context_init(test_ctx);
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim if (test_ctx->ev == NULL) {
6beba165aeced2ca77a6f1593ee08c47a32099efcovener fail("Could not create event context");
709e3a21ba73b8433462959cd56c773454b34441trawick talloc_free(test_ctx);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return EIO;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen
117c1f888a14e73cdd821dc6c23eb0411144a41cnd conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (conf_db == NULL) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd fail("Out of memory, aborting!");
117c1f888a14e73cdd821dc6c23eb0411144a41cnd talloc_free(test_ctx);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin return ENOMEM;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd DEBUG(3, ("CONFDB: %s\n", conf_db));
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd /* Connect to the conf db */
117c1f888a14e73cdd821dc6c23eb0411144a41cnd ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd if (ret != EOK) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd fail("Could not initialize connection to the confdb");
117c1f888a14e73cdd821dc6c23eb0411144a41cnd talloc_free(test_ctx);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd return ret;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd }
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
b00fe3c3354db01001b8eddfd9b88441380f837dwrowe val[0] = "LOCAL";
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin ret = confdb_add_param(test_ctx->confdb, true,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd "config/sssd", "domains", val);
a38b5f73e7f0f3b8726fb47d27b145f37036ead0jim if (ret != EOK) {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd fail("Could not initialize domains placeholder");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna val[0] = "local";
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = confdb_add_param(test_ctx->confdb, true,
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna "config/domain/LOCAL", "id_provider", val);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != EOK) {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna fail("Could not initialize provider");
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna talloc_free(test_ctx);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna return ret;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen }
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna val[0] = "TRUE";
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen ret = confdb_add_param(test_ctx->confdb, true,
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen "config/domain/LOCAL", "enumerate", val);
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen if (ret != EOK) {
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen fail("Could not initialize LOCAL domain");
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen talloc_free(test_ctx);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor return ret;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe }
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe val[0] = "TRUE";
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = confdb_add_param(test_ctx->confdb, true,
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe "config/domain/LOCAL", "cache_credentials", val);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe if (ret != EOK) {
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe fail("Could not initialize LOCAL domain");
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna talloc_free(test_ctx);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener return ret;
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener }
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener ret = confdb_get_domain(test_ctx->confdb, "local", &test_ctx->domain);
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener if (ret != EOK) {
6fad623c3cc52b4a84d4d36538f6eed886f49f98covener fail("Could not retrieve LOCAL domain");
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna talloc_free(test_ctx);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna return ret;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = sysdb_domain_init(test_ctx, test_ctx->ev,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor test_ctx->domain, TESTS_PATH, &test_ctx->sysdb);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna if (ret != EOK) {
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor fail("Could not initialize connection to the sysdb (%d)", ret);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor talloc_free(test_ctx);
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna return ret;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor }
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna *ctx = test_ctx;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna return EOK;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna}
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquernastruct test_data {
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna struct tevent_context *ev;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna struct sysdb_handle *handle;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna struct sysdb_test_ctx *ctx;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor const char *username;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna const char *groupname;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor uid_t uid;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna gid_t gid;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna const char *shell;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe bool finished;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe int error;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe struct sysdb_attrs *attrs;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe const char **attrlist;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe struct ldb_message *msg;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe size_t msgs_count;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe struct ldb_message **msgs;
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe};
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowestatic int test_loop(struct test_data *data)
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe{
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe while (!data->finished)
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe tevent_loop_once(data->ctx->ev);
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe return data->error;
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen}
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe
5ae609a8a09239d20f48a4a95c4f21b713995babwrowestatic int test_add_user(struct test_data *data)
5ae609a8a09239d20f48a4a95c4f21b713995babwrowe{
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor char *homedir;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna char *gecos;
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna int ret;
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen homedir = talloc_asprintf(data, "/home/testuser%d", data->uid);
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen gecos = talloc_asprintf(data, "Test User %d", data->uid);
9f19223e8fb7b99f5f1cc02c8c3c2c6567793262rbowen
7e8f5c6496b3825b6b128e2aacc4b1b09d28553dpquerna ret = sysdb_add_user(data, data->ctx->sysdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx->domain, data->username,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->uid, 0, gecos, homedir, "/bin/bash",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd NULL, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic int test_store_user(struct test_data *data)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *homedir;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *gecos;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive homedir = talloc_asprintf(data, "/home/testuser%d", data->uid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive gecos = talloc_asprintf(data, "Test User %d", data->uid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_store_user(data, data->ctx->sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ctx->domain, data->username, "x",
fb77c505254b6e9c925e23e734463e87574f8f40kess data->uid, 0, gecos, homedir,
fb77c505254b6e9c925e23e734463e87574f8f40kess data->shell ? data->shell : "/bin/bash",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive NULL, -1);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic int test_remove_user(struct test_data *data)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ldb_dn *user_dn;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive user_dn = sysdb_user_dn(data->ctx->sysdb, data, "LOCAL", data->username);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!user_dn) return ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_delete_entry(data->ctx->sysdb, user_dn, true);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic int test_remove_user_by_uid(struct test_data *data)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_delete_user(data, data->ctx->sysdb,
fb77c505254b6e9c925e23e734463e87574f8f40kess data->ctx->domain, NULL, data->uid);
fb77c505254b6e9c925e23e734463e87574f8f40kess return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
fb77c505254b6e9c925e23e734463e87574f8f40kess
bc4b55ec8f31569d606d5680d50189a355bcd7a6rbowenstatic int test_remove_nonexistent_group(struct test_data *data)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_delete_group(data, data->ctx->sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ctx->domain, NULL, data->uid);
fb77c505254b6e9c925e23e734463e87574f8f40kess return ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kessstatic int test_remove_nonexistent_user(struct test_data *data)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = sysdb_delete_user(data, data->ctx->sysdb,
130d299c4b2b15be45532a176604c71fdc7bea5bnd data->ctx->domain, NULL, data->uid);
130d299c4b2b15be45532a176604c71fdc7bea5bnd return ret;
130d299c4b2b15be45532a176604c71fdc7bea5bnd}
130d299c4b2b15be45532a176604c71fdc7bea5bnd
ef8e89e090461194ecadd31e8796a2c51e0531a2kessstatic int test_add_group(struct test_data *data)
130d299c4b2b15be45532a176604c71fdc7bea5bnd{
130d299c4b2b15be45532a176604c71fdc7bea5bnd int ret;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sysdb_add_group(data, data->ctx->sysdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx->domain, data->groupname,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->gid, NULL, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic int test_store_group(struct test_data *data)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_store_group(data, data->ctx->sysdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx->domain, data->groupname,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->gid, NULL, -1);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess return ret;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive}
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
6b64034fa2a644ba291c484c0c01c7df5b8d982ckessstatic int test_remove_group(struct test_data *data)
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct ldb_dn *group_dn;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd group_dn = sysdb_group_dn(data->ctx->sysdb, data, "LOCAL", data->groupname);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (!group_dn) return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_delete_entry(data->ctx->sysdb, group_dn, true);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic int test_remove_group_by_gid(struct test_data *data)
130d299c4b2b15be45532a176604c71fdc7bea5bnd{
130d299c4b2b15be45532a176604c71fdc7bea5bnd int ret;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = sysdb_delete_group(data, data->ctx->sysdb,
130d299c4b2b15be45532a176604c71fdc7bea5bnd data->ctx->domain, NULL, data->gid);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret == ENOENT) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic int test_set_user_attr(struct test_data *data)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_set_user_attr(data, data->ctx->sysdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx->domain, data->username,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->attrs, SYSDB_MOD_REP);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd return ret;
627c978514c54179736d152923478be7c8707f9bnd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic int test_add_group_member(struct test_data *data)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *username;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd username = talloc_asprintf(data, "testuser%d", data->uid);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (username == NULL) {
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd return ENOMEM;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd }
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd
b95ae799514ad86a15610ad75808d7065e9847c9kess ret = sysdb_add_group_member(data, data->ctx->sysdb,
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd data->ctx->domain,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd data->groupname, username);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd return ret;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd}
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dndstatic int test_remove_group_member(struct test_data *data)
604c89126c27104f659d7a51b0113e3bd435faf8fielding{
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd const char *username;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd username = talloc_asprintf(data, "testuser%d", data->uid);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (username == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
888b616027180cc8aaa4d2bee5ecc6acec175bc5nd }
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd ret = sysdb_remove_group_member(data, data->ctx->sysdb,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd data->ctx->domain,
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd data->groupname, username);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd return ret;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd}
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dndstatic int test_store_custom(struct test_data *data)
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd{
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd char *object_name;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd int ret;
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, data->uid);
5224ff8eae5156a05f676f1dad8add2e2f2efe1dnd if (!object_name) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_store_custom(data, data->ctx->sysdb,
9583adab6bc4b3758e41963c905d9dad9f067131nd data->ctx->domain, object_name,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd CUSTOM_TEST_CONTAINER, data->attrs);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier return ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd}
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268ndstatic int test_delete_custom(struct test_data *data)
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd{
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier int ret;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_delete_custom(data, data->ctx->sysdb, data->ctx->domain,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd CUSTOM_TEST_OBJECT, CUSTOM_TEST_CONTAINER);
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd return ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd}
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirierstatic int test_search_all_users(struct test_data *data)
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier{
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier struct ldb_dn *base_dn;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier int ret;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier base_dn = ldb_dn_new_fmt(data, data->ctx->sysdb->ldb, SYSDB_TMPL_USER_BASE,
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier "LOCAL");
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier if (base_dn == NULL) {
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier return ENOMEM;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd }
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd ret = sysdb_search_entry(data, data->ctx->sysdb, base_dn,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd LDB_SCOPE_SUBTREE, "objectClass=user",
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd data->attrlist, &data->msgs_count, &data->msgs);
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier return ret;
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier}
2509f1cd3be884abbe4852e15b8da00bebaad5b1poirier
4335f1cbf345c91bb996eec540c11ba8ce5d4268ndstatic int test_delete_recursive(struct test_data *data)
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd{
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd struct ldb_dn *dn;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd int ret;
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd dn = ldb_dn_new_fmt(data, data->ctx->sysdb->ldb, SYSDB_DOM_BASE,
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd "LOCAL");
4335f1cbf345c91bb996eec540c11ba8ce5d4268nd if (!dn) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
627c978514c54179736d152923478be7c8707f9bnd ret = sysdb_delete_recursive(data, data->ctx->sysdb, dn, false);
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_unless(ret == EOK, "sysdb_delete_recursive returned [%d]", ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
6f7c18e70781deff3d1129774221de81b43c828end}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic int test_memberof_store_group(struct test_data *data)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct sysdb_attrs *attrs = NULL;
fb77c505254b6e9c925e23e734463e87574f8f40kess char *member;
fb77c505254b6e9c925e23e734463e87574f8f40kess int i;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive attrs = sysdb_new_attrs(data);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (!attrs) {
10673857794a4b3d9568ca2d983722a87ed352f1rbowen return ENOMEM;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
ed0dae472b518c553c923a86fb4322d4c50d86a6nd for (i = 0; data->attrlist && data->attrlist[i]; i++) {
ed0dae472b518c553c923a86fb4322d4c50d86a6nd member = sysdb_group_strdn(data, data->ctx->domain->name,
10673857794a4b3d9568ca2d983722a87ed352f1rbowen data->attrlist[i]);
10673857794a4b3d9568ca2d983722a87ed352f1rbowen if (!member) {
bed3c2e56e8f3328e780200466b9d009093db468sf return ENOMEM;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf ret = sysdb_attrs_steal_string(attrs, SYSDB_MEMBER, member);
bed3c2e56e8f3328e780200466b9d009093db468sf if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_store_group(data, data->ctx->sysdb,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->ctx->domain, data->groupname,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->gid, attrs, -1);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_store_user)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz struct test_data *data;
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz int ret;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl /* Setup */
9335f6d807d76d60e54af4ededdebebddb3e3d13noodl ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding data = talloc_zero(test_ctx, struct test_data);
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->ctx = test_ctx;
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->ev = test_ctx->ev;
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->uid = _i;
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->gid = _i;
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->username = talloc_asprintf(data, "testuser%d", _i);
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = test_store_user(data);
909ce17e2bd0faef7b1c294f2307f009793fd493nd
909ce17e2bd0faef7b1c294f2307f009793fd493nd fail_if(ret != EOK, "Could not store user %s", data->username);
909ce17e2bd0faef7b1c294f2307f009793fd493nd talloc_free(test_ctx);
909ce17e2bd0faef7b1c294f2307f009793fd493nd}
06ba4a61654b3763ad65f52283832ebf058fdf1csliveEND_TEST
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_store_user_existing)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
97a9a944b5887e91042b019776c41d5dd74557aferikabele struct test_data *data;
97a9a944b5887e91042b019776c41d5dd74557aferikabele int ret;
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data = talloc_zero(test_ctx, struct test_data);
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak data->ctx = test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ev = test_ctx->ev;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->uid = _i;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->gid = _i;
97a9a944b5887e91042b019776c41d5dd74557aferikabele data->username = talloc_asprintf(data, "testuser%d", _i);
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak data->shell = talloc_asprintf(data, "/bin/ksh");
8e31885fc494b603e0650113dde9e29d1b1d2602maczniak
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener ret = test_store_user(data);
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener fail_if(ret != EOK, "Could not store user %s", data->username);
2b6565aedca9e9c10691b12fd2f3689bf4c85bc7jim talloc_free(test_ctx);
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener}
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covenerEND_TEST
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covenerSTART_TEST (test_sysdb_store_group)
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener{
a011221d1a3bfb6ec07a3596c6dc962c58041ee6covener struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = setup_sysdb_tests(&test_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail("Could not set up the test");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
ed0dae472b518c553c923a86fb4322d4c50d86a6nd }
ed0dae472b518c553c923a86fb4322d4c50d86a6nd
ed0dae472b518c553c923a86fb4322d4c50d86a6nd data = talloc_zero(test_ctx, struct test_data);
ed0dae472b518c553c923a86fb4322d4c50d86a6nd data->ctx = test_ctx;
da637bcae7b6e150470e701af29da5604a34a17erbowen data->ev = test_ctx->ev;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor data->gid = _i;
da637bcae7b6e150470e701af29da5604a34a17erbowen data->groupname = talloc_asprintf(data, "testgroup%d", _i);
da637bcae7b6e150470e701af29da5604a34a17erbowen
da637bcae7b6e150470e701af29da5604a34a17erbowen ret = test_store_group(data);
da637bcae7b6e150470e701af29da5604a34a17erbowen
da637bcae7b6e150470e701af29da5604a34a17erbowen fail_if(ret != EOK, "Could not store POSIX group #%d", _i);
da637bcae7b6e150470e701af29da5604a34a17erbowen talloc_free(test_ctx);
7802d43d20007fa575e43b6ae77d5177ceffdb71sf}
7802d43d20007fa575e43b6ae77d5177ceffdb71sfEND_TEST
7802d43d20007fa575e43b6ae77d5177ceffdb71sf
7802d43d20007fa575e43b6ae77d5177ceffdb71sfSTART_TEST (test_sysdb_remove_local_user)
7802d43d20007fa575e43b6ae77d5177ceffdb71sf{
7802d43d20007fa575e43b6ae77d5177ceffdb71sf struct sysdb_test_ctx *test_ctx;
7802d43d20007fa575e43b6ae77d5177ceffdb71sf struct test_data *data;
bed3c2e56e8f3328e780200466b9d009093db468sf int ret;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf /* Setup */
bed3c2e56e8f3328e780200466b9d009093db468sf ret = setup_sysdb_tests(&test_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf if (ret != EOK) {
bed3c2e56e8f3328e780200466b9d009093db468sf fail("Could not set up the test");
bed3c2e56e8f3328e780200466b9d009093db468sf return;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf data = talloc_zero(test_ctx, struct test_data);
bed3c2e56e8f3328e780200466b9d009093db468sf data->ctx = test_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf data->ev = test_ctx->ev;
bed3c2e56e8f3328e780200466b9d009093db468sf data->username = talloc_asprintf(data, "testuser%d", _i);
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf ret = test_remove_user(data);
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf fail_if(ret != EOK, "Could not remove user %s", data->username);
bed3c2e56e8f3328e780200466b9d009093db468sf talloc_free(test_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf}
bed3c2e56e8f3328e780200466b9d009093db468sfEND_TEST
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sfSTART_TEST (test_sysdb_remove_local_user_by_uid)
bed3c2e56e8f3328e780200466b9d009093db468sf{
bed3c2e56e8f3328e780200466b9d009093db468sf struct sysdb_test_ctx *test_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf struct test_data *data;
bed3c2e56e8f3328e780200466b9d009093db468sf int ret;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf /* Setup */
bed3c2e56e8f3328e780200466b9d009093db468sf ret = setup_sysdb_tests(&test_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf if (ret != EOK) {
bed3c2e56e8f3328e780200466b9d009093db468sf fail("Could not set up the test");
bed3c2e56e8f3328e780200466b9d009093db468sf return;
bed3c2e56e8f3328e780200466b9d009093db468sf }
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf data = talloc_zero(test_ctx, struct test_data);
bed3c2e56e8f3328e780200466b9d009093db468sf data->ctx = test_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf data->ev = test_ctx->ev;
bed3c2e56e8f3328e780200466b9d009093db468sf data->uid = _i;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf ret = test_remove_user_by_uid(data);
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf fail_if(ret != EOK, "Could not remove user with uid %d", _i);
bed3c2e56e8f3328e780200466b9d009093db468sf talloc_free(test_ctx);
bed3c2e56e8f3328e780200466b9d009093db468sf}
bed3c2e56e8f3328e780200466b9d009093db468sfEND_TEST
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sfSTART_TEST (test_sysdb_remove_local_group)
bed3c2e56e8f3328e780200466b9d009093db468sf{
bed3c2e56e8f3328e780200466b9d009093db468sf struct sysdb_test_ctx *test_ctx;
bed3c2e56e8f3328e780200466b9d009093db468sf struct test_data *data;
bed3c2e56e8f3328e780200466b9d009093db468sf int ret;
bed3c2e56e8f3328e780200466b9d009093db468sf
bed3c2e56e8f3328e780200466b9d009093db468sf /* Setup */
bed3c2e56e8f3328e780200466b9d009093db468sf ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("Could not set up the test");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
bed3c2e56e8f3328e780200466b9d009093db468sf }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data = talloc_zero(test_ctx, struct test_data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx = test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ev = test_ctx->ev;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->groupname = talloc_asprintf(data, "testgroup%d", _i);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = test_remove_group(data);
fb77c505254b6e9c925e23e734463e87574f8f40kess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not remove group %s", data->groupname);
fb77c505254b6e9c925e23e734463e87574f8f40kess talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40ndEND_TEST
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndSTART_TEST (test_sysdb_remove_local_group_by_gid)
c985aca104389df30d6ec0a637ce0ccaac904362nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_test_ctx *test_ctx;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen struct test_data *data;
fb77c505254b6e9c925e23e734463e87574f8f40kess int ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Setup */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("Could not set up the test");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
627c978514c54179736d152923478be7c8707f9bnd data = talloc_zero(test_ctx, struct test_data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx = test_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess data->ev = test_ctx->ev;
fb77c505254b6e9c925e23e734463e87574f8f40kess data->gid = _i;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = test_remove_group_by_gid(data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not remove group with gid %d", _i);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1csliveEND_TEST
5bb5fba250bf526bc51d13b25378d54acb93c1cbnoodl
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_add_user)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data = talloc_zero(test_ctx, struct test_data);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ctx = test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ev = test_ctx->ev;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->uid = _i;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->gid = _i;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->username = talloc_asprintf(data, "testuser%d", _i);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = test_add_user(data);
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_if(ret != EOK, "Could not add user %s", data->username);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40ndEND_TEST
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndSTART_TEST (test_sysdb_add_group)
604c89126c27104f659d7a51b0113e3bd435faf8fielding{
604c89126c27104f659d7a51b0113e3bd435faf8fielding struct sysdb_test_ctx *test_ctx;
604c89126c27104f659d7a51b0113e3bd435faf8fielding struct test_data *data;
604c89126c27104f659d7a51b0113e3bd435faf8fielding int ret;
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fielding /* Setup */
604c89126c27104f659d7a51b0113e3bd435faf8fielding ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("Could not set up the test");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data = talloc_zero(test_ctx, struct test_data);
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->ctx = test_ctx;
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->ev = test_ctx->ev;
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->uid = _i;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->gid = _i;
22265f1724519886e2a2b5e0ebd61477506b7379noodl data->groupname = talloc_asprintf(data, "testgroup%d", _i);
22265f1724519886e2a2b5e0ebd61477506b7379noodl
22265f1724519886e2a2b5e0ebd61477506b7379noodl ret = test_add_group(data);
22265f1724519886e2a2b5e0ebd61477506b7379noodl
604c89126c27104f659d7a51b0113e3bd435faf8fielding fail_if(ret != EOK, "Could not add group %s", data->groupname);
604c89126c27104f659d7a51b0113e3bd435faf8fielding talloc_free(test_ctx);
604c89126c27104f659d7a51b0113e3bd435faf8fielding}
604c89126c27104f659d7a51b0113e3bd435faf8fieldingEND_TEST
604c89126c27104f659d7a51b0113e3bd435faf8fielding
604c89126c27104f659d7a51b0113e3bd435faf8fieldingSTART_TEST (test_sysdb_getpwnam)
604c89126c27104f659d7a51b0113e3bd435faf8fielding{
604c89126c27104f659d7a51b0113e3bd435faf8fielding struct sysdb_test_ctx *test_ctx;
604c89126c27104f659d7a51b0113e3bd435faf8fielding struct ldb_result *res;
604c89126c27104f659d7a51b0113e3bd435faf8fielding const char *username;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd uid_t uid;
9597f440430d8c876dd64f5f78066804650a18ecnoodl int ret;
9597f440430d8c876dd64f5f78066804650a18ecnoodl
9597f440430d8c876dd64f5f78066804650a18ecnoodl /* Setup */
9597f440430d8c876dd64f5f78066804650a18ecnoodl ret = setup_sysdb_tests(&test_ctx);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if (ret != EOK) {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf fail("Could not set up the test");
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf return;
9597f440430d8c876dd64f5f78066804650a18ecnoodl }
9597f440430d8c876dd64f5f78066804650a18ecnoodl
9597f440430d8c876dd64f5f78066804650a18ecnoodl username = talloc_asprintf(test_ctx, "testuser%d", _i);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf ret = sysdb_getpwnam(test_ctx,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf test_ctx->sysdb,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf test_ctx->domain,
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf username, &res);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if (ret) {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf fail("sysdb_getpwnam failed for username %s (%d: %s)",
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf username, ret, strerror(ret));
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf goto done;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf }
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf if (res->count != 1) {
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf fail("Invalid number of replies. Expected 1, got %d", res->count);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf goto done;
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf }
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf uid = ldb_msg_find_attr_as_uint(res->msgs[0], SYSDB_UIDNUM, 0);
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf fail_unless(uid == _i, "Did not find the expected UID");
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf /* Search for the user with the wrong case */
141fd59714368d3bbe3a3d8f5b8dc8a516c48f9fsf username = talloc_asprintf(test_ctx, "TESTUSER%d", _i);
9597f440430d8c876dd64f5f78066804650a18ecnoodl
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf ret = sysdb_getpwnam(test_ctx,
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf test_ctx->sysdb,
cba8c0896ba04d42cf9a9e50df5040fd6bae14a4sf test_ctx->domain,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd username, &res);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("sysdb_getpwnam failed for username %s (%d: %s)",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd username, ret, strerror(ret));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (res->count != 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("The upper-case username search should fail.");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowenEND_TEST
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowenSTART_TEST (test_sysdb_getgrnam)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive struct sysdb_test_ctx *test_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct ldb_result *res;
fb77c505254b6e9c925e23e734463e87574f8f40kess const char *groupname;
fb77c505254b6e9c925e23e734463e87574f8f40kess gid_t gid;
fb77c505254b6e9c925e23e734463e87574f8f40kess int ret;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive /* Setup */
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive ret = setup_sysdb_tests(&test_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd fail("Could not set up the test");
130d299c4b2b15be45532a176604c71fdc7bea5bnd return;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd groupname = talloc_asprintf(test_ctx, "testgroup%d", _i);
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = sysdb_getgrnam(test_ctx,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd test_ctx->sysdb,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd test_ctx->domain,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd groupname, &res);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if (ret) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail("sysdb_getgrnam failed for groupname %s (%d: %s)",
fb77c505254b6e9c925e23e734463e87574f8f40kess groupname, ret, strerror(ret));
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
b06660a3ed3d885e15d99c0209a46c4657df33fbrbowen if (res->count != 1) {
d1348237b33bc1755b9f1165eea52317465a7671nd fail("Invalid number of replies. Expected 1, got %d", res->count);
d1348237b33bc1755b9f1165eea52317465a7671nd goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd gid = ldb_msg_find_attr_as_uint(res->msgs[0], SYSDB_GIDNUM, 0);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail_unless(gid == _i,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "Did not find the expected GID (found %d expected %d)",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd gid, _i);
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Search for the group with the wrong case */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive groupname = talloc_asprintf(test_ctx, "TESTGROUP%d", _i);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess ret = sysdb_getgrnam(test_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive test_ctx->sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive test_ctx->domain,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive groupname, &res);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd fail("sysdb_getgrnam failed for groupname %s (%d: %s)",
130d299c4b2b15be45532a176604c71fdc7bea5bnd groupname, ret, strerror(ret));
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (res->count != 0) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd fail("The upper-case groupname search should fail.");
df70c4445a86c43993e578fd1212c69ac52587a1rbowen }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnddone:
130d299c4b2b15be45532a176604c71fdc7bea5bnd talloc_free(test_ctx);
130d299c4b2b15be45532a176604c71fdc7bea5bnd}
130d299c4b2b15be45532a176604c71fdc7bea5bndEND_TEST
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_getgrgid)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct ldb_result *res;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *e_groupname;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *groupname;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (ret != EOK) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess fail("Could not set up the test");
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_getgrgid(test_ctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive test_ctx->sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive test_ctx->domain,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _i, &res);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd fail("sysdb_getgrgid failed for gid %d (%d: %s)",
130d299c4b2b15be45532a176604c71fdc7bea5bnd _i, ret, strerror(ret));
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd groupname = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, 0);
130d299c4b2b15be45532a176604c71fdc7bea5bnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive e_groupname = talloc_asprintf(test_ctx, "testgroup%d", _i);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (e_groupname == NULL) {
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess fail("Cannot allocate memory");
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess goto done;
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess }
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess fail_unless(strcmp(groupname, e_groupname) == 0,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Did not find the expected groupname (found %s expected %s)",
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen groupname, e_groupname);
4e10c61d7f924071cad435df940a8f325015b2d3rbowendone:
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen talloc_free(test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1csliveEND_TEST
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
130d299c4b2b15be45532a176604c71fdc7bea5bndSTART_TEST (test_sysdb_getpwuid)
130d299c4b2b15be45532a176604c71fdc7bea5bnd{
130d299c4b2b15be45532a176604c71fdc7bea5bnd struct sysdb_test_ctx *test_ctx;
4e10c61d7f924071cad435df940a8f325015b2d3rbowen struct ldb_result *res;
130d299c4b2b15be45532a176604c71fdc7bea5bnd const char *e_username;
130d299c4b2b15be45532a176604c71fdc7bea5bnd const char *username;
130d299c4b2b15be45532a176604c71fdc7bea5bnd int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
fb77c505254b6e9c925e23e734463e87574f8f40kess return;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
97a9a944b5887e91042b019776c41d5dd74557aferikabele
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_getpwuid(test_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd test_ctx->sysdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd test_ctx->domain,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess _i, &res);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (ret) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("sysdb_getpwuid failed for uid %d (%d: %s)",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd _i, ret, strerror(ret));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd username = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess e_username = talloc_asprintf(test_ctx, "testuser%d", _i);
cb43ec0a02f97651bf2f46c9f4b9b48d5cb22df7rbowen if (username == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("Cannot allocate memory");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strcmp(username, e_username) == 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Did not find the expected username (found %s expected %s)",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive username, e_username);
06ba4a61654b3763ad65f52283832ebf058fdf1cslivedone:
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor talloc_free(test_ctx);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor}
031bbbc0d1189b07330e38d0c126820a9ab7795egryzorEND_TEST
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cndSTART_TEST (test_sysdb_enumgrent)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
6954edc623ca2c179eb5b33e97e4304d06fd649frbowen struct sysdb_test_ctx *test_ctx;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd struct ldb_result *res;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = setup_sysdb_tests(&test_ctx);
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener if (ret != EOK) {
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener fail("Could not set up the test");
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener return;
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener }
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener ret = sysdb_enumgrent(test_ctx,
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener test_ctx->sysdb,
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener test_ctx->domain,
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener &res);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor fail_unless(ret == EOK,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor "sysdb_enumgrent failed (%d: %s)",
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener ret, strerror(ret));
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener
fa1c7ce09927decc1eecd1e9a35cc5331078a052covener /* 10 groups + 10 users (we're MPG) */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(res->count != 20, "Expected 20 users, got %d", res->count);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessEND_TEST
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessSTART_TEST (test_sysdb_enumpwent)
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_test_ctx *test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct ldb_result *res;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("Could not set up the test");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_enumpwent(test_ctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd test_ctx->sysdb,
9bcfc3697a91b5215893a7d0206865b13fc72148nd test_ctx->domain,
fb77c505254b6e9c925e23e734463e87574f8f40kess &res);
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_unless(ret == EOK,
fb77c505254b6e9c925e23e734463e87574f8f40kess "sysdb_enumpwent failed (%d: %s)",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret, strerror(ret));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail_if(res->count != 10, "Expected 10 users, got %d", res->count);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
d565edaec710102f7e7d06252aaf1de67b7ddd25rbowenEND_TEST
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_set_user_attr)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct test_data *data;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen /* Setup */
1b01d1ee11c612226cb3141eed4581dc179266c1rbowen ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("Could not set up the test");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf data = talloc_zero(test_ctx, struct test_data);
8559a67073808d84d85bb5dd552d4247caafe709sf data->ctx = test_ctx;
8559a67073808d84d85bb5dd552d4247caafe709sf data->ev = test_ctx->ev;
8559a67073808d84d85bb5dd552d4247caafe709sf data->username = talloc_asprintf(data, "testuser%d", _i);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf data->attrs = sysdb_new_attrs(test_ctx);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf fail("Could not create the changeset");
8559a67073808d84d85bb5dd552d4247caafe709sf return;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = sysdb_attrs_add_string(data->attrs,
8559a67073808d84d85bb5dd552d4247caafe709sf SYSDB_SHELL,
8559a67073808d84d85bb5dd552d4247caafe709sf "/bin/ksh");
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf fail("Could not create the changeset");
8559a67073808d84d85bb5dd552d4247caafe709sf return;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = test_set_user_attr(data);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf fail_if(ret != EOK, "Could not modify user %s", data->username);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf talloc_free(test_ctx);
8559a67073808d84d85bb5dd552d4247caafe709sf}
8559a67073808d84d85bb5dd552d4247caafe709sfEND_TEST
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfSTART_TEST (test_sysdb_get_user_attr)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf struct sysdb_test_ctx *test_ctx;
8559a67073808d84d85bb5dd552d4247caafe709sf const char *attrs[] = { SYSDB_SHELL, NULL };
8559a67073808d84d85bb5dd552d4247caafe709sf struct ldb_result *res;
8559a67073808d84d85bb5dd552d4247caafe709sf const char *attrval;
8559a67073808d84d85bb5dd552d4247caafe709sf char *username;
8559a67073808d84d85bb5dd552d4247caafe709sf int ret;
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Setup */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = setup_sysdb_tests(&test_ctx);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf fail("Could not set up the test");
8559a67073808d84d85bb5dd552d4247caafe709sf return;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf username = talloc_asprintf(test_ctx, "testuser%d", _i);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = sysdb_get_user_attr(test_ctx, test_ctx->sysdb,
8559a67073808d84d85bb5dd552d4247caafe709sf test_ctx->domain, username,
8559a67073808d84d85bb5dd552d4247caafe709sf attrs, &res);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret) {
8559a67073808d84d85bb5dd552d4247caafe709sf fail("Could not get attributes for user %s", username);
8559a67073808d84d85bb5dd552d4247caafe709sf goto done;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf fail_if(res->count != 1,
8559a67073808d84d85bb5dd552d4247caafe709sf "Invalid number of entries, expected 1, got %d", res->count);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf attrval = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_SHELL, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf fail_if(strcmp(attrval, "/bin/ksh"),
8559a67073808d84d85bb5dd552d4247caafe709sf "Got bad attribute value for user %s", username);
8559a67073808d84d85bb5dd552d4247caafe709sfdone:
8559a67073808d84d85bb5dd552d4247caafe709sf talloc_free(test_ctx);
8559a67073808d84d85bb5dd552d4247caafe709sf}
8559a67073808d84d85bb5dd552d4247caafe709sfEND_TEST
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfSTART_TEST (test_sysdb_add_group_member)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf struct sysdb_test_ctx *test_ctx;
8559a67073808d84d85bb5dd552d4247caafe709sf struct test_data *data;
8559a67073808d84d85bb5dd552d4247caafe709sf int ret;
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* Setup */
8559a67073808d84d85bb5dd552d4247caafe709sf ret = setup_sysdb_tests(&test_ctx);
8559a67073808d84d85bb5dd552d4247caafe709sf if (ret != EOK) {
8559a67073808d84d85bb5dd552d4247caafe709sf fail("Could not set up the test");
8559a67073808d84d85bb5dd552d4247caafe709sf return;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf data = talloc_zero(test_ctx, struct test_data);
8559a67073808d84d85bb5dd552d4247caafe709sf data->ctx = test_ctx;
8559a67073808d84d85bb5dd552d4247caafe709sf data->ev = test_ctx->ev;
8559a67073808d84d85bb5dd552d4247caafe709sf data->groupname = talloc_asprintf(data, "testgroup%d", _i);
8559a67073808d84d85bb5dd552d4247caafe709sf data->uid = _i - 1000; /* the UID of user to add */
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = test_add_group_member(data);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf fail_if(ret != EOK, "Could not modify group %s", data->groupname);
8559a67073808d84d85bb5dd552d4247caafe709sf talloc_free(test_ctx);
8559a67073808d84d85bb5dd552d4247caafe709sf}
8559a67073808d84d85bb5dd552d4247caafe709sfEND_TEST
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfSTART_TEST (test_sysdb_remove_group_member)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf struct sysdb_test_ctx *test_ctx;
8559a67073808d84d85bb5dd552d4247caafe709sf struct test_data *data;
8559a67073808d84d85bb5dd552d4247caafe709sf int ret;
8559a67073808d84d85bb5dd552d4247caafe709sf
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fb77c505254b6e9c925e23e734463e87574f8f40kess fail("Could not set up the test");
fb77c505254b6e9c925e23e734463e87574f8f40kess return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data = talloc_zero(test_ctx, struct test_data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx = test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ev = test_ctx->ev;
9bcfc3697a91b5215893a7d0206865b13fc72148nd data->groupname = talloc_asprintf(data, "testgroup%d", _i);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive data->uid = _i - 1000; /* the UID of user to add */
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = test_remove_group_member(data);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(test_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cndEND_TEST
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cndSTART_TEST (test_sysdb_remove_nonexistent_user)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
9bcfc3697a91b5215893a7d0206865b13fc72148nd int ret;
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier /* Setup */
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier ret = setup_sysdb_tests(&test_ctx);
e4286c93598ad346ac365e59ac9c6f9e6e9fd324poirier if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data = talloc_zero(test_ctx, struct test_data);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->ctx = test_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess data->ev = test_ctx->ev;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->uid = 12345;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = test_remove_nonexistent_user(data);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh fail_if(ret != ENOENT, "Unexpected return code %d, expected ENOENT", ret);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh talloc_free(test_ctx);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh}
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessEND_TEST
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkessSTART_TEST (test_sysdb_remove_nonexistent_group)
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh{
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh struct sysdb_test_ctx *test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct test_data *data;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fb77c505254b6e9c925e23e734463e87574f8f40kess fail("Could not set up the test");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data = talloc_zero(test_ctx, struct test_data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx = test_ctx;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->ev = test_ctx->ev;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->uid = 12345;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
9bcfc3697a91b5215893a7d0206865b13fc72148nd ret = test_remove_nonexistent_group(data);
9bcfc3697a91b5215893a7d0206865b13fc72148nd
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh fail_if(ret != ENOENT, "Unexpected return code %d, expected ENOENT", ret);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh talloc_free(test_ctx);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen}
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejeshEND_TEST
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawickSTART_TEST (test_sysdb_store_custom)
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess{
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess struct sysdb_test_ctx *test_ctx;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh struct test_data *data;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh int ret;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh /* Setup */
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh ret = setup_sysdb_tests(&test_ctx);
9fb925624300c864fe3969a264e52aa83f3c2dd0slive if (ret != EOK) {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess fail("Could not set up the test");
78f4d313fd5edf76dc5cfb8725e082a08cd29740jwoolley return;
78f4d313fd5edf76dc5cfb8725e082a08cd29740jwoolley }
f653ca260580e6d64d92ae29963f207b94e87353nd
f653ca260580e6d64d92ae29963f207b94e87353nd data = talloc_zero(test_ctx, struct test_data);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->ctx = test_ctx;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess data->ev = test_ctx->ev;
9fb925624300c864fe3969a264e52aa83f3c2dd0slive data->uid = _i;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh data->attrs = sysdb_new_attrs(test_ctx);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh if (ret != EOK) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail("Could not create attribute list");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf return;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh }
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = sysdb_attrs_add_string(data->attrs,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh TEST_ATTR_NAME,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh TEST_ATTR_VALUE);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (ret != EOK) {
9fb925624300c864fe3969a264e52aa83f3c2dd0slive fail("Could not add attribute");
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh return;
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = test_store_custom(data);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess fail_if(ret != EOK, "Could not add custom object");
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh talloc_free(test_ctx);
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh}
832853bb93c1831daf24e4727c5ca0e1b1786e83larsEND_TEST
832853bb93c1831daf24e4727c5ca0e1b1786e83lars
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrinSTART_TEST (test_sysdb_search_custom_by_name)
832853bb93c1831daf24e4727c5ca0e1b1786e83lars{
832853bb93c1831daf24e4727c5ca0e1b1786e83lars struct sysdb_test_ctx *test_ctx;
832853bb93c1831daf24e4727c5ca0e1b1786e83lars struct test_data *data;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick char *object_name;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick /* Setup */
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = setup_sysdb_tests(&test_ctx);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick if (ret != EOK) {
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail("Could not set up the test");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick return;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick }
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data = talloc_zero(test_ctx, struct test_data);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_unless(data != NULL, "talloc_zero failed");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->ctx = test_ctx;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->ev = test_ctx->ev;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->attrlist = talloc_array(test_ctx, const char *, 2);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_unless(data->attrlist != NULL, "talloc_array failed");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->attrlist[0] = TEST_ATTR_NAME;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->attrlist[1] = NULL;
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, 29010);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_unless(object_name != NULL, "talloc_asprintf failed");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick ret = sysdb_search_custom_by_name(data, data->ctx->sysdb,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->ctx->domain,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick object_name,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick CUSTOM_TEST_CONTAINER,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->attrlist,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick &data->msgs_count,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick &data->msgs);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_if(ret != EOK, "Could not search custom object");
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_unless(data->msgs_count == 1,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick "Wrong number of objects, exptected [1] got [%d]",
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick data->msgs_count);
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick fail_unless(data->msgs[0]->num_elements == 1,
dce2bc31f4940687c7ffabb80570bc37ea7296d8trawick "Wrong number of results, expected [1] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs[0]->num_elements);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strcmp(data->msgs[0]->elements[0].name, TEST_ATTR_NAME) == 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong attribute name");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msgs[0]->elements[0].num_values == 1,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strncmp((const char *)data->msgs[0]->elements[0].values[0].data,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TEST_ATTR_VALUE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs[0]->elements[0].values[0].length) == 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong attribute value");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowenEND_TEST
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_update_custom)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail("Could not set up the test");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data = talloc_zero(test_ctx, struct test_data);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ctx = test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ev = test_ctx->ev;
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen data->uid = 29010;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->attrs = sysdb_new_attrs(test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
59cd19c3d75e35ae820e23f6b0161910784fce4eslive fail("Could not create attribute list");
59cd19c3d75e35ae820e23f6b0161910784fce4eslive return;
59cd19c3d75e35ae820e23f6b0161910784fce4eslive }
59cd19c3d75e35ae820e23f6b0161910784fce4eslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_add_string(data->attrs,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd TEST_ATTR_NAME,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd TEST_ATTR_UPDATE_VALUE);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail("Could not add attribute");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd ret = sysdb_attrs_add_string(data->attrs,
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen TEST_ATTR_ADD_NAME,
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd TEST_ATTR_ADD_VALUE);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if (ret != EOK) {
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd fail("Could not add attribute");
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd return;
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd }
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd ret = test_store_custom(data);
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd fail_if(ret != EOK, "Could not add custom object");
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd talloc_free(test_ctx);
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd}
7a497a1b89d0b52f5284854eb12662b4bd80ba5cndEND_TEST
7a497a1b89d0b52f5284854eb12662b4bd80ba5cnd
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_search_custom_update)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char *object_name;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct ldb_message_element *el;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data = talloc_zero(test_ctx, struct test_data);
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_unless(data != NULL, "talloc_zero failed");
fb77c505254b6e9c925e23e734463e87574f8f40kess data->ctx = test_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess data->ev = test_ctx->ev;
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive data->attrlist = talloc_array(test_ctx, const char *, 3);
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive fail_unless(data->attrlist != NULL, "talloc_array failed");
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive data->attrlist[0] = TEST_ATTR_NAME;
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick data->attrlist[1] = TEST_ATTR_ADD_NAME;
4f854c24127e28f7ad72ce9a39d4448aaf910fc1slive data->attrlist[2] = NULL;
59cd19c3d75e35ae820e23f6b0161910784fce4eslive
59cd19c3d75e35ae820e23f6b0161910784fce4eslive object_name = talloc_asprintf(data, "%s_%d", CUSTOM_TEST_OBJECT, 29010);
59cd19c3d75e35ae820e23f6b0161910784fce4eslive fail_unless(object_name != NULL, "talloc_asprintf failed");
59cd19c3d75e35ae820e23f6b0161910784fce4eslive
59cd19c3d75e35ae820e23f6b0161910784fce4eslive ret = sysdb_search_custom_by_name(data, data->ctx->sysdb,
59cd19c3d75e35ae820e23f6b0161910784fce4eslive data->ctx->domain,
59cd19c3d75e35ae820e23f6b0161910784fce4eslive object_name,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor CUSTOM_TEST_CONTAINER,
b5d3d68a9f683722eac7a3ca507c3e571908dfc0rbowen data->attrlist,
b5d3d68a9f683722eac7a3ca507c3e571908dfc0rbowen &data->msgs_count,
b5d3d68a9f683722eac7a3ca507c3e571908dfc0rbowen &data->msgs);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
59cd19c3d75e35ae820e23f6b0161910784fce4eslive fail_if(ret != EOK, "Could not search custom object");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msgs_count == 1,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of objects, exptected [1] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs_count);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msgs[0]->num_elements == 2,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of results, expected [2] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs[0]->num_elements);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_NAME);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_NAME);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) "
c1fcddc76fd5db5ac4ccd7c6ae839d53d128f354minfrin "of attribute values for [%s]", el->num_values,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TEST_ATTR_NAME);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strncmp((const char *) el->values[0].data,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TEST_ATTR_UPDATE_VALUE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd el->values[0].length) == 0,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "Wrong attribute value");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor el = ldb_msg_find_element(data->msgs[0], TEST_ATTR_ADD_NAME);
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess fail_unless(el != NULL, "Attribute [%s] not found", TEST_ATTR_ADD_NAME);
fb109b84906e3ee61680aa289953c2f9e859354erbowen fail_unless(el->num_values == 1, "Wrong number ([%d] instead of 1) "
fb109b84906e3ee61680aa289953c2f9e859354erbowen "of attribute values for [%s]", el->num_values,
fb109b84906e3ee61680aa289953c2f9e859354erbowen TEST_ATTR_ADD_NAME);
fb109b84906e3ee61680aa289953c2f9e859354erbowen fail_unless(strncmp((const char *) el->values[0].data,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess TEST_ATTR_ADD_VALUE,
fb109b84906e3ee61680aa289953c2f9e859354erbowen el->values[0].length) == 0,
db2474c3448fc75c325aa43ba0144fced1a38c53rjung "Wrong attribute value");
db2474c3448fc75c325aa43ba0144fced1a38c53rjung
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb109b84906e3ee61680aa289953c2f9e859354erbowen talloc_free(test_ctx);
fb109b84906e3ee61680aa289953c2f9e859354erbowen}
fb109b84906e3ee61680aa289953c2f9e859354erbowenEND_TEST
fb109b84906e3ee61680aa289953c2f9e859354erbowen
db2474c3448fc75c325aa43ba0144fced1a38c53rjungSTART_TEST (test_sysdb_search_custom)
db2474c3448fc75c325aa43ba0144fced1a38c53rjung{
db2474c3448fc75c325aa43ba0144fced1a38c53rjung struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *filter = "(distinguishedName=*)";
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
5155e92c6100b47513159eee1b2b9914ab204a5acovener ret = setup_sysdb_tests(&test_ctx);
5155e92c6100b47513159eee1b2b9914ab204a5acovener if (ret != EOK) {
5155e92c6100b47513159eee1b2b9914ab204a5acovener fail("Could not set up the test");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
fb109b84906e3ee61680aa289953c2f9e859354erbowen }
fb109b84906e3ee61680aa289953c2f9e859354erbowen
fb109b84906e3ee61680aa289953c2f9e859354erbowen data = talloc_zero(test_ctx, struct test_data);
fb109b84906e3ee61680aa289953c2f9e859354erbowen fail_unless(data != NULL, "talloc_zero failed");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ctx = test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ev = test_ctx->ev;
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick data->attrlist = talloc_array(test_ctx, const char *, 3);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_unless(data->attrlist != NULL, "talloc_array failed");
c023f60e35022146373e40249f0c8c8d623b6fcfnd data->attrlist[0] = TEST_ATTR_NAME;
c023f60e35022146373e40249f0c8c8d623b6fcfnd data->attrlist[1] = TEST_ATTR_ADD_NAME;
d972e4a0688f66b1402473dd9dacfecefa2132a8rbowen data->attrlist[2] = NULL;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
c023f60e35022146373e40249f0c8c8d623b6fcfnd ret = sysdb_search_custom(data, data->ctx->sysdb,
c023f60e35022146373e40249f0c8c8d623b6fcfnd data->ctx->domain,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd filter,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd CUSTOM_TEST_CONTAINER,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->attrlist,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd &data->msgs_count,
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen &data->msgs);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin fail_if(ret != EOK, "Could not search custom object");
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(data->msgs_count == 10,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf "Wrong number of objects, exptected [10] got [%d]",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->msgs_count);
2851546ce44280e54301016a7e92b00a87745509sf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf talloc_free(test_ctx);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf}
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfEND_TEST
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfSTART_TEST (test_sysdb_delete_custom)
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf{
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct sysdb_test_ctx *test_ctx;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct test_data *data;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf int ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf /* Setup */
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = setup_sysdb_tests(&test_ctx);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (ret != EOK) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail("Could not set up the test");
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf return;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf }
2bb4320391b88748dc6e851deca941b058231664rbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data = talloc_zero(test_ctx, struct test_data);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->ctx = test_ctx;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->ev = test_ctx->ev;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = test_delete_custom(data);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_if(ret != EOK, "Could not delete custom object");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf talloc_free(test_ctx);
2bb4320391b88748dc6e851deca941b058231664rbowen}
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfEND_TEST
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfSTART_TEST (test_sysdb_cache_password)
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf{
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct sysdb_test_ctx *test_ctx;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct test_data *data;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf int ret;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf /* Setup */
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = setup_sysdb_tests(&test_ctx);
2bb4320391b88748dc6e851deca941b058231664rbowen fail_unless(ret == EOK, "Could not set up the test");
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data = talloc_zero(test_ctx, struct test_data);
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen data->ctx = test_ctx;
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen data->ev = test_ctx->ev;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->username = talloc_asprintf(data, "testuser%d", _i);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen ret = sysdb_cache_password(data, test_ctx->sysdb,
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen test_ctx->domain, data->username,
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen data->username);
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen fail_unless(ret == EOK, "sysdb_cache_password request failed [%d].", ret);
2bb4320391b88748dc6e851deca941b058231664rbowen
2bb4320391b88748dc6e851deca941b058231664rbowen talloc_free(test_ctx);
2bb4320391b88748dc6e851deca941b058231664rbowen}
2bb4320391b88748dc6e851deca941b058231664rbowenEND_TEST
2bb4320391b88748dc6e851deca941b058231664rbowen
2bb4320391b88748dc6e851deca941b058231664rbowenstatic void cached_authentication_without_expiration(const char *username,
2bb4320391b88748dc6e851deca941b058231664rbowen const char *password,
2bb4320391b88748dc6e851deca941b058231664rbowen int expected_result)
2bb4320391b88748dc6e851deca941b058231664rbowen{
2bb4320391b88748dc6e851deca941b058231664rbowen struct sysdb_test_ctx *test_ctx;
2bb4320391b88748dc6e851deca941b058231664rbowen struct test_data *data;
2bb4320391b88748dc6e851deca941b058231664rbowen int ret;
2bb4320391b88748dc6e851deca941b058231664rbowen time_t expire_date = -1;
2bb4320391b88748dc6e851deca941b058231664rbowen time_t delayed_until = -1;
2bb4320391b88748dc6e851deca941b058231664rbowen const char *val[2];
2bb4320391b88748dc6e851deca941b058231664rbowen val[1] = NULL;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf /* Setup */
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = setup_sysdb_tests(&test_ctx);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == EOK, "Could not set up the test");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
2bb4320391b88748dc6e851deca941b058231664rbowen data = talloc_zero(test_ctx, struct test_data);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->ctx = test_ctx;
2bb4320391b88748dc6e851deca941b058231664rbowen data->ev = test_ctx->ev;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->username = username;
2bb4320391b88748dc6e851deca941b058231664rbowen
0b5f11662dee7135ff8dd04311a4ee6df7fe2b1crbowen val[0] = "0";
2bb4320391b88748dc6e851deca941b058231664rbowen ret = confdb_add_param(test_ctx->confdb, true, CONFDB_PAM_CONF_ENTRY,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf CONFDB_PAM_CRED_TIMEOUT, val);
2bb4320391b88748dc6e851deca941b058231664rbowen if (ret != EOK) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail("Could not initialize provider");
2bb4320391b88748dc6e851deca941b058231664rbowen talloc_free(test_ctx);
0b5f11662dee7135ff8dd04311a4ee6df7fe2b1crbowen return;
2bb4320391b88748dc6e851deca941b058231664rbowen }
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
2bb4320391b88748dc6e851deca941b058231664rbowen ret = sysdb_cache_auth(data, test_ctx->sysdb,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf test_ctx->domain, data->username,
2bb4320391b88748dc6e851deca941b058231664rbowen (const uint8_t *)password, strlen(password),
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf test_ctx->confdb, &expire_date, &delayed_until);
2bb4320391b88748dc6e851deca941b058231664rbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == expected_result, "sysdb_cache_auth request does not "
2bb4320391b88748dc6e851deca941b058231664rbowen "return expected result [%d].",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf expected_result);
2bb4320391b88748dc6e851deca941b058231664rbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(expire_date == 0, "Wrong expire date, expected [%d], got [%d]",
dd2f29c187db35e7635ce67a83dddceb75be87a4minfrin 0, expire_date);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
2bb4320391b88748dc6e851deca941b058231664rbowen fail_unless(delayed_until == -1, "Wrong delay, expected [%d], got [%d]",
0b5f11662dee7135ff8dd04311a4ee6df7fe2b1crbowen -1, delayed_until);
2bb4320391b88748dc6e851deca941b058231664rbowen
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf talloc_free(test_ctx);
2bb4320391b88748dc6e851deca941b058231664rbowen}
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
2bb4320391b88748dc6e851deca941b058231664rbowenstatic void cached_authentication_with_expiration(const char *username,
ffb01336be79c64046b636e59fa8ddca8ec029edsf const char *password,
ffb01336be79c64046b636e59fa8ddca8ec029edsf int expected_result)
2bb4320391b88748dc6e851deca941b058231664rbowen{
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf struct sysdb_test_ctx *test_ctx;
2bb4320391b88748dc6e851deca941b058231664rbowen struct test_data *data;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf int ret;
2bb4320391b88748dc6e851deca941b058231664rbowen time_t expire_date = -1;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf const char *val[2];
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf val[1] = NULL;
2bb4320391b88748dc6e851deca941b058231664rbowen time_t now;
e80f65dadea03d04ee5b9e2d3de8c5fcef9e6714minfrin time_t expected_expire_date;
e80f65dadea03d04ee5b9e2d3de8c5fcef9e6714minfrin time_t delayed_until = -1;
2bb4320391b88748dc6e851deca941b058231664rbowen
e80f65dadea03d04ee5b9e2d3de8c5fcef9e6714minfrin /* Setup */
e80f65dadea03d04ee5b9e2d3de8c5fcef9e6714minfrin ret = setup_sysdb_tests(&test_ctx);
e80f65dadea03d04ee5b9e2d3de8c5fcef9e6714minfrin fail_unless(ret == EOK, "Could not set up the test");
ffb01336be79c64046b636e59fa8ddca8ec029edsf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data = talloc_zero(test_ctx, struct test_data);
ffb01336be79c64046b636e59fa8ddca8ec029edsf data->ctx = test_ctx;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->ev = test_ctx->ev;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf data->username = username;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf val[0] = "1";
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = confdb_add_param(test_ctx->confdb, true, CONFDB_PAM_CONF_ENTRY,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf CONFDB_PAM_CRED_TIMEOUT, val);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf if (ret != EOK) {
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail("Could not initialize provider");
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalic talloc_free(test_ctx);
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalic return;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf }
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen now = time(NULL);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf expected_expire_date = now + (24 * 60 * 60);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf DEBUG(9, ("Setting SYSDB_LAST_ONLINE_AUTH to [%lld].\n", (long long) now));
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen data->attrs = sysdb_new_attrs(data);
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen ret = sysdb_attrs_add_time_t(data->attrs, SYSDB_LAST_ONLINE_AUTH, now);
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen ret = sysdb_set_user_attr(data, data->ctx->sysdb,
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen data->ctx->domain, data->username,
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen data->attrs, SYSDB_MOD_REP);
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen fail_unless(ret == EOK, "Could not modify user %s", data->username);
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen
abdaaa23d72ef7e7ff91eab9c5581d40130680c1rbowen ret = sysdb_cache_auth(data, test_ctx->sysdb,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf test_ctx->domain, data->username,
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen (const uint8_t *) password, strlen(password),
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf test_ctx->confdb, &expire_date, &delayed_until);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == expected_result,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf "sysdb_cache_auth request does not return expected "
a547340d7d0f0e79c9ba921c7dec7b18d0c800ffrbowen "result [%d], got [%d].", expected_result, ret);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(expire_date == expected_expire_date,
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf "Wrong expire date, expected [%d], got [%d]",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf expected_expire_date, expire_date);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(delayed_until == -1, "Wrong delay, expected [%d], got [%d]",
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf -1, delayed_until);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf talloc_free(test_ctx);
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf}
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csfSTART_TEST (test_sysdb_cached_authentication_missing_password)
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf{
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf TALLOC_CTX *tmp_ctx;
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf char *username;
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin tmp_ctx = talloc_new(NULL);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor fail_unless(tmp_ctx != NULL, "talloc_new failed.");
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin username = talloc_asprintf(tmp_ctx, "testuser%d", _i);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin fail_unless(username != NULL, "talloc_asprintf failed.");
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin cached_authentication_without_expiration(username, "abc", ENOENT);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin cached_authentication_with_expiration(username, "abc", ENOENT);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin talloc_free(tmp_ctx);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor}
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrinEND_TEST
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrinSTART_TEST (test_sysdb_cached_authentication_wrong_password)
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin{
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin TALLOC_CTX *tmp_ctx;
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin char *username;
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin tmp_ctx = talloc_new(NULL);
e797af4d7b0cada1278d72d6c8ac77210ef78632minfrin fail_unless(tmp_ctx != NULL, "talloc_new failed.");
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor username = talloc_asprintf(tmp_ctx, "testuser%d", _i);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin fail_unless(username != NULL, "talloc_asprintf failed.");
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin cached_authentication_without_expiration(username, "abc", EINVAL);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin cached_authentication_with_expiration(username, "abc", EINVAL);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin talloc_free(tmp_ctx);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin}
fe64b2ba25510d8c9dba5560a2d537763566cf40ndEND_TEST
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndSTART_TEST (test_sysdb_cached_authentication)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TALLOC_CTX *tmp_ctx;
a5f060e0c74a44cb8896ae794c08f94f7c9a46a7covener char *username;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tmp_ctx = talloc_new(NULL);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(tmp_ctx != NULL, "talloc_new failed.");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd username = talloc_asprintf(tmp_ctx, "testuser%d", _i);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(username != NULL, "talloc_asprintf failed.");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive cached_authentication_without_expiration(username, username, EOK);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive cached_authentication_with_expiration(username, username, EOK);
fb77c505254b6e9c925e23e734463e87574f8f40kess
a5f060e0c74a44cb8896ae794c08f94f7c9a46a7covener talloc_free(tmp_ctx);
fb77c505254b6e9c925e23e734463e87574f8f40kess
c976a7c7d20f2be319b128dd7d0b1568da224c0arbowen}
fb77c505254b6e9c925e23e734463e87574f8f40kessEND_TEST
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_prepare_asq_test_user)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess data = talloc_zero(test_ctx, struct test_data);
fb77c505254b6e9c925e23e734463e87574f8f40kess data->ctx = test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ev = test_ctx->ev;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->groupname = talloc_asprintf(data, "testgroup%d", _i);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->uid = ASQ_TEST_USER_UID;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = test_add_group_member(data);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail_if(ret != EOK, "Could not modify group %s", data->groupname);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(test_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cndEND_TEST
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cnd
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_asq_search)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
db99fa79ac42b9cc42b63386eb289aecb0f3cb9cnd struct sysdb_test_ctx *test_ctx;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem struct test_data *data;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem struct ldb_dn *user_dn;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem int ret;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem size_t msgs_count;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem struct ldb_message **msgs;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem int i;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem char *gid_str;
8010b66c363b5b847dc83d9d23f12c68e5bf3a56rpluem
a5f060e0c74a44cb8896ae794c08f94f7c9a46a7covener /* Setup */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = setup_sysdb_tests(&test_ctx);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor if (ret != EOK) {
a5f060e0c74a44cb8896ae794c08f94f7c9a46a7covener fail("Could not set up the test");
a5f060e0c74a44cb8896ae794c08f94f7c9a46a7covener return;
a5f060e0c74a44cb8896ae794c08f94f7c9a46a7covener }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data = talloc_zero(test_ctx, struct test_data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx = test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ev = test_ctx->ev;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->attrlist = talloc_array(data, const char *, 2);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->attrlist != NULL, "talloc_array failed");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->attrlist[0] = "gidNumber";
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->attrlist[1] = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd user_dn = sysdb_user_dn(data->ctx->sysdb, data, "LOCAL", ASQ_TEST_USER);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(user_dn != NULL, "sysdb_user_dn failed");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_asq_search(data, test_ctx->sysdb,
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess test_ctx->domain, user_dn, NULL, "memberof",
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess data->attrlist, &msgs_count, &msgs);
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess fail_if(ret != EOK, "Failed to send ASQ search request.\n");
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess fail_unless(msgs_count == 10, "wrong number of results, "
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "found [%d] expected [10]", msgs_count);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele for (i = 0; i < msgs_count; i++) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele fail_unless(msgs[i]->num_elements == 1, "wrong number of elements, "
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "found [%d] expected [1]",
97a9a944b5887e91042b019776c41d5dd74557aferikabele msgs[i]->num_elements);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_unless(msgs[i]->elements[0].num_values == 1,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "wrong number of values, found [%d] expected [1]",
fb77c505254b6e9c925e23e734463e87574f8f40kess msgs[i]->elements[0].num_values);
d1348237b33bc1755b9f1165eea52317465a7671nd
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor gid_str = talloc_asprintf(data, "%d", 28010 + i);
d1348237b33bc1755b9f1165eea52317465a7671nd fail_unless(gid_str != NULL, "talloc_asprintf failed.");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_unless(strncmp(gid_str,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd (const char *) msgs[i]->elements[0].values[0].data,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd msgs[i]->elements[0].values[0].length) == 0,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd "wrong value, found [%.*s] expected [%s]",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd msgs[i]->elements[0].values[0].length,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd msgs[i]->elements[0].values[0].data, gid_str);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(test_ctx);
97a9a944b5887e91042b019776c41d5dd74557aferikabele}
fb77c505254b6e9c925e23e734463e87574f8f40kessEND_TEST
fb77c505254b6e9c925e23e734463e87574f8f40kess
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_search_all_users)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_test_ctx *test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct test_data *data;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess int ret;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess int i;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess char *uid_str;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = setup_sysdb_tests(&test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail("Could not set up the test");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data = talloc_zero(test_ctx, struct test_data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ctx = test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->ev = test_ctx->ev;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->attrlist = talloc_array(data, const char *, 2);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->attrlist != NULL, "talloc_array failed");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess data->attrlist[0] = "uidNumber";
6b64034fa2a644ba291c484c0c01c7df5b8d982ckess data->attrlist[1] = NULL;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
d1348237b33bc1755b9f1165eea52317465a7671nd ret = test_search_all_users(data);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail_if(ret != EOK, "Search failed");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail_unless(data->msgs_count == 10,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "wrong number of results, found [%d] expected [10]",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->msgs_count);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd for (i = 0; i < data->msgs_count; i++) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msgs[i]->num_elements == 1,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess "wrong number of elements, found [%d] expected [1]",
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess data->msgs[i]->num_elements);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msgs[i]->elements[0].num_values == 1,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "wrong number of values, found [%d] expected [1]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs[i]->elements[0].num_values);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd uid_str = talloc_asprintf(data, "%d", 27010 + i);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(uid_str != NULL, "talloc_asprintf failed.");
604c89126c27104f659d7a51b0113e3bd435faf8fielding fail_unless(strncmp(uid_str,
604c89126c27104f659d7a51b0113e3bd435faf8fielding (char *) data->msgs[i]->elements[0].values[0].data,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs[i]->elements[0].values[0].length) == 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "wrong value, found [%.*s] expected [%s]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs[i]->elements[0].values[0].length,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msgs[i]->elements[0].values[0].data, uid_str);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(test_ctx);
97a9a944b5887e91042b019776c41d5dd74557aferikabele}
fb77c505254b6e9c925e23e734463e87574f8f40kessEND_TEST
97a9a944b5887e91042b019776c41d5dd74557aferikabele
06ba4a61654b3763ad65f52283832ebf058fdf1csliveSTART_TEST (test_sysdb_delete_recursive)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
604c89126c27104f659d7a51b0113e3bd435faf8fielding struct sysdb_test_ctx *test_ctx;
fb77c505254b6e9c925e23e734463e87574f8f40kess struct test_data *data;
fb77c505254b6e9c925e23e734463e87574f8f40kess int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = setup_sysdb_tests(&test_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
604c89126c27104f659d7a51b0113e3bd435faf8fielding return;
604c89126c27104f659d7a51b0113e3bd435faf8fielding }
604c89126c27104f659d7a51b0113e3bd435faf8fielding
7654193c1faf603feec999850322ad79e6c551bcnd data = talloc_zero(test_ctx, struct test_data);
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->ctx = test_ctx;
604c89126c27104f659d7a51b0113e3bd435faf8fielding data->ev = test_ctx->ev;
c97e8972ab1f4dd167e3dc4db87daf91114009fbnd
7654193c1faf603feec999850322ad79e6c551bcnd ret = test_delete_recursive(data);
7654193c1faf603feec999850322ad79e6c551bcnd
7654193c1faf603feec999850322ad79e6c551bcnd fail_if(ret != EOK, "Recursive delete failed");
7654193c1faf603feec999850322ad79e6c551bcnd talloc_free(test_ctx);
7654193c1faf603feec999850322ad79e6c551bcnd}
7654193c1faf603feec999850322ad79e6c551bcndEND_TEST
7654193c1faf603feec999850322ad79e6c551bcnd
7654193c1faf603feec999850322ad79e6c551bcndSTART_TEST (test_sysdb_attrs_replace_name)
7654193c1faf603feec999850322ad79e6c551bcnd{
7654193c1faf603feec999850322ad79e6c551bcnd struct sysdb_attrs *attrs;
7654193c1faf603feec999850322ad79e6c551bcnd struct ldb_message_element *el;
7654193c1faf603feec999850322ad79e6c551bcnd int ret;
c97e8972ab1f4dd167e3dc4db87daf91114009fbnd
7654193c1faf603feec999850322ad79e6c551bcnd attrs = sysdb_new_attrs(NULL);
7654193c1faf603feec999850322ad79e6c551bcnd fail_unless(attrs != NULL, "sysdb_new_attrs failed");
7654193c1faf603feec999850322ad79e6c551bcnd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_attrs_add_string(attrs, "foo", "bar");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == EOK, "sysdb_attrs_add_string failed");
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor ret = sysdb_attrs_add_string(attrs, "fool", "bool");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf fail_unless(ret == EOK, "sysdb_attrs_add_string failed");
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf
29b517f9fe7f32a2c3fbdc53e359b6db6f8e8c2csf ret = sysdb_attrs_add_string(attrs, "foot", "boot");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_add_string failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener ret = sysdb_attrs_replace_name(attrs, "foo", "foot");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EEXIST,
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener "sysdb_attrs_replace overwrites existing attribute");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener ret = sysdb_attrs_replace_name(attrs, "foo", "oof");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_replace failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener ret = sysdb_attrs_get_el(attrs, "foo", &el);
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_get_el failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(el->num_values == 0, "Attribute foo is not empty.");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener ret = sysdb_attrs_get_el(attrs, "oof", &el);
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(ret == EOK, "sysdb_attrs_get_el failed");
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(el->num_values == 1,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor "Wrong number of values for attribute oof, "
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic "expected [1] got [%d].", el->num_values);
c3e2e664a67b1adb9b6a6b91ff161f4f562cecf6covener fail_unless(strncmp("bar", (char *) el->values[0].data,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd el->values[0].length) == 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong value, expected [bar] got [%.*s]", el->values[0].length,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd el->values[0].data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(attrs);
fb77c505254b6e9c925e23e734463e87574f8f40kess}
fb77c505254b6e9c925e23e734463e87574f8f40kessEND_TEST
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndSTART_TEST (test_sysdb_memberof_store_group)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Setup */
9b5e2c5e769dc678a1aca06df75c32022b2f1492trawick ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data = talloc_zero(test_ctx, struct test_data);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ctx = test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ev = test_ctx->ev;
fb77c505254b6e9c925e23e734463e87574f8f40kess data->gid = MBO_GROUP_BASE + _i;
fb77c505254b6e9c925e23e734463e87574f8f40kess data->groupname = talloc_asprintf(data, "testgroup%d", data->gid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (_i == 0) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->attrlist = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
fb77c505254b6e9c925e23e734463e87574f8f40kess data->attrlist = talloc_array(data, const char *, 2);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_unless(data->attrlist != NULL, "talloc_array failed.");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->attrlist[0] = talloc_asprintf(data, "testgroup%d", data->gid - 1);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->attrlist[1] = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
9bcfc3697a91b5215893a7d0206865b13fc72148nd ret = test_memberof_store_group(data);
9bcfc3697a91b5215893a7d0206865b13fc72148nd
9bcfc3697a91b5215893a7d0206865b13fc72148nd fail_if(ret != EOK, "Could not store POSIX group #%d", data->gid);
9bcfc3697a91b5215893a7d0206865b13fc72148nd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodlEND_TEST
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodlSTART_TEST (test_sysdb_memberof_close_loop)
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl{
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl struct sysdb_test_ctx *test_ctx;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl struct test_data *data;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl int ret;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl /* Setup */
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl ret = setup_sysdb_tests(&test_ctx);
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl if (ret != EOK) {
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl fail("Could not set up the test");
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl return;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl }
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data = talloc_zero(test_ctx, struct test_data);
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data->ctx = test_ctx;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data->ev = test_ctx->ev;
8559a67073808d84d85bb5dd552d4247caafe709sf data->gid = MBO_GROUP_BASE;
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data->groupname = talloc_asprintf(data, "testgroup%d", data->gid);
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl
8559a67073808d84d85bb5dd552d4247caafe709sf data->attrlist = talloc_array(data, const char *, 2);
8559a67073808d84d85bb5dd552d4247caafe709sf fail_unless(data->attrlist != NULL, "talloc_array failed.");
8559a67073808d84d85bb5dd552d4247caafe709sf data->attrlist[0] = talloc_asprintf(data, "testgroup%d", data->gid + 9);
8559a67073808d84d85bb5dd552d4247caafe709sf data->attrlist[1] = NULL;
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf ret = test_memberof_store_group(data);
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalic
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalic fail_if(ret != EOK, "Could not store POSIX group #%d", data->gid);
011e567af90fe9d72bbabf8cc5e373b4436b9d08rbowen talloc_free(test_ctx);
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalic}
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalicEND_TEST
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfSTART_TEST (test_sysdb_memberof_store_user)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf struct sysdb_test_ctx *test_ctx;
8559a67073808d84d85bb5dd552d4247caafe709sf struct test_data *data;
8559a67073808d84d85bb5dd552d4247caafe709sf int ret;
1a0ca5f6b566a5eb77d63f466fcf78fb388a4182igalic
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl /* Setup */
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl ret = setup_sysdb_tests(&test_ctx);
c8c717fafa0a09ed13469a603a178921b851dd22igalic if (ret != EOK) {
c8c717fafa0a09ed13469a603a178921b851dd22igalic fail("Could not set up the test");
8559a67073808d84d85bb5dd552d4247caafe709sf return;
8559a67073808d84d85bb5dd552d4247caafe709sf }
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data = talloc_zero(test_ctx, struct test_data);
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data->ctx = test_ctx;
8559a67073808d84d85bb5dd552d4247caafe709sf data->ev = test_ctx->ev;
8559a67073808d84d85bb5dd552d4247caafe709sf data->uid = MBO_USER_BASE + _i;
8559a67073808d84d85bb5dd552d4247caafe709sf data->gid = 0; /* MPG domain */
3cc4ff86e6cc4cfd7d4ccfc58dedff599091444bnoodl data->username = talloc_asprintf(data, "testuser%d", data->uid);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = test_store_user(data);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not store user %s", data->username);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40ndEND_TEST
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndSTART_TEST (test_sysdb_memberof_add_group_member)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_test_ctx *test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct test_data *data;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = setup_sysdb_tests(&test_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail("Could not set up the test");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data = talloc_zero(test_ctx, struct test_data);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->ctx = test_ctx;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->ev = test_ctx->ev;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->groupname = talloc_asprintf(data, "testgroup%d", _i + MBO_GROUP_BASE);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->uid = MBO_USER_BASE + _i;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = test_add_group_member(data);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_if(ret != EOK, "Could not modify group %s", data->groupname);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_free(test_ctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd}
06ba4a61654b3763ad65f52283832ebf058fdf1csliveEND_TEST
9597f440430d8c876dd64f5f78066804650a18ecnoodl
9597f440430d8c876dd64f5f78066804650a18ecnoodlSTART_TEST (test_sysdb_memberof_check_memberuid_without_group_5)
9597f440430d8c876dd64f5f78066804650a18ecnoodl{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = setup_sysdb_tests(&test_ctx);
46f74e65e6051e6e9391c8e17c5116317210facetakashi if (ret != EOK) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd fail("Could not set up the test");
130d299c4b2b15be45532a176604c71fdc7bea5bnd return;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
46f74e65e6051e6e9391c8e17c5116317210facetakashi data = talloc_zero(test_ctx, struct test_data);
46f74e65e6051e6e9391c8e17c5116317210facetakashi data->ctx = test_ctx;
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi data->ev = test_ctx->ev;
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi data->gid = _i + MBO_GROUP_BASE;
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi data->attrlist = talloc_array(data, const char *, 2);
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi fail_unless(data->attrlist != NULL, "tallo_array failed.");
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi data->attrlist[0] = "memberuid";
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi data->attrlist[1] = NULL;
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi ret = sysdb_search_group_by_gid(data, test_ctx->sysdb,
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi data->ctx->domain, _i + MBO_GROUP_BASE,
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin data->attrlist, &data->msg);
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi if (_i == 5) {
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi fail_unless(ret == ENOENT,
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi "sysdb_search_group_by_gid found "
6f93a0120b20c42e90d5ab61766c0e36fc024636takashi "already deleted group");
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret == ENOENT) ret = EOK;
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd fail_if(ret != EOK, "Could not check group %d", data->gid);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_if(ret != EOK, "Could not check group %d", data->gid);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msg->num_elements == 1,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of results, expected [1] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msg->num_elements);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
a850a44a7d6af013c766944483e00c2a1c8b183dnd "Wrong attribute name");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd fail_unless(data->msg->elements[0].num_values == ((_i + 1) % 6),
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values, "
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "expected [%d] got [%d]", ((_i + 1) % 6),
fe64b2ba25510d8c9dba5560a2d537763566cf40nd data->msg->elements[0].num_values);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
a850a44a7d6af013c766944483e00c2a1c8b183dnd
a850a44a7d6af013c766944483e00c2a1c8b183dnd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cndEND_TEST
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kessSTART_TEST (test_sysdb_memberof_check_memberuid)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd{
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Setup */
a850a44a7d6af013c766944483e00c2a1c8b183dnd ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
a850a44a7d6af013c766944483e00c2a1c8b183dnd fail("Could not set up the test");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a850a44a7d6af013c766944483e00c2a1c8b183dnd data = talloc_zero(test_ctx, struct test_data);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen data->ctx = test_ctx;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->ev = test_ctx->ev;
a850a44a7d6af013c766944483e00c2a1c8b183dnd data->gid = _i + MBO_GROUP_BASE;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->attrlist = talloc_array(data, const char *, 2);
a850a44a7d6af013c766944483e00c2a1c8b183dnd fail_unless(data->attrlist != NULL, "tallo_array failed.");
a850a44a7d6af013c766944483e00c2a1c8b183dnd data->attrlist[0] = "memberuid";
a850a44a7d6af013c766944483e00c2a1c8b183dnd data->attrlist[1] = NULL;
a850a44a7d6af013c766944483e00c2a1c8b183dnd
a850a44a7d6af013c766944483e00c2a1c8b183dnd ret = sysdb_search_group_by_gid(data, test_ctx->sysdb,
bea526116133aa3d7dabd1924bfc580b37fbf22aslive data->ctx->domain, _i + MBO_GROUP_BASE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive data->attrlist, &data->msg);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail_if(ret != EOK, "Could not check group %d", data->gid);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bea526116133aa3d7dabd1924bfc580b37fbf22aslive fail_unless(data->msg->num_elements == 1,
bea526116133aa3d7dabd1924bfc580b37fbf22aslive "Wrong number of results, expected [1] got [%d]",
bea526116133aa3d7dabd1924bfc580b37fbf22aslive data->msg->num_elements);
fb77c505254b6e9c925e23e734463e87574f8f40kess fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
bea526116133aa3d7dabd1924bfc580b37fbf22aslive "Wrong attribute name");
bea526116133aa3d7dabd1924bfc580b37fbf22aslive fail_unless(data->msg->elements[0].num_values == _i + 1,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values, expected [%d] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd _i + 1, data->msg->elements[0].num_values);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40ndEND_TEST
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowenSTART_TEST (test_sysdb_memberof_check_memberuid_loop)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_test_ctx *test_ctx;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct test_data *data;
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin int ret;
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Setup */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = setup_sysdb_tests(&test_ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fail("Could not set up the test");
5b258a8d58679c6587757189339bb3c2d0488f93poirier return;
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin }
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data = talloc_zero(test_ctx, struct test_data);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen data->ctx = test_ctx;
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->ev = test_ctx->ev;
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->gid = _i + MBO_GROUP_BASE;
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->attrlist = talloc_array(data, const char *, 2);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin fail_unless(data->attrlist != NULL, "tallo_array failed.");
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->attrlist[0] = "memberuid";
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen data->attrlist[1] = NULL;
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen ret = sysdb_search_group_by_gid(data, test_ctx->sysdb,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen data->ctx->domain, _i + MBO_GROUP_BASE,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen data->attrlist, &data->msg);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_if(ret != EOK, "Could not check group %d", data->gid);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(data->msg->num_elements == 1,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong number of results, expected [1] got [%d]",
2bb4320391b88748dc6e851deca941b058231664rbowen data->msg->num_elements);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong attribute name");
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(data->msg->elements[0].num_values == 10,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong number of attribute values, expected [%d] got [%d]",
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen 10, data->msg->elements[0].num_values);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen talloc_free(test_ctx);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin}
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrinEND_TEST
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen
cd75115baac4df586f9a346dc1c2c9d9bd3d58aaminfrinSTART_TEST (test_sysdb_memberof_check_memberuid_loop_without_group_5)
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor{
c68acc9d712af079afa2bd1a5a4aeef9a3ea573ckess struct sysdb_test_ctx *test_ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct test_data *data;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive int ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* Setup */
7b5535ed88e0f561b3bfb3330137bd804846afd4slive ret = setup_sysdb_tests(&test_ctx);
7b5535ed88e0f561b3bfb3330137bd804846afd4slive if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd fail("Could not set up the test");
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return;
7b5535ed88e0f561b3bfb3330137bd804846afd4slive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data = talloc_zero(test_ctx, struct test_data);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->ctx = test_ctx;
7b5535ed88e0f561b3bfb3330137bd804846afd4slive data->ev = test_ctx->ev;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd data->gid = _i + MBO_GROUP_BASE;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->attrlist = talloc_array(data, const char *, 2);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(data->attrlist != NULL, "tallo_array failed.");
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen data->attrlist[0] = "memberuid";
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen data->attrlist[1] = NULL;
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin ret = sysdb_search_group_by_gid(data, test_ctx->sysdb,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen data->ctx->domain, _i + MBO_GROUP_BASE,
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin data->attrlist, &data->msg);
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin if (_i == 5) {
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(ret == ENOENT,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "sysdb_search_group_by_gid_send found "
09b49da7bdbc59b56fb52d19a092e30d7d4a1bbaminfrin "already deleted group");
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen if (ret == ENOENT) ret = EOK;
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_if(ret != EOK, "Could not check group %d", data->gid);
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor } else {
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_if(ret != EOK, "Could not check group %d", data->gid);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen
cd75115baac4df586f9a346dc1c2c9d9bd3d58aaminfrin fail_unless(data->msg->num_elements == 1,
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen "Wrong number of results, expected [1] got [%d]",
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen data->msg->num_elements);
d68b7e44d489058bcb5b18992a0f247a80f52f9frbowen fail_unless(strcmp(data->msg->elements[0].name, "memberuid") == 0,
cd75115baac4df586f9a346dc1c2c9d9bd3d58aaminfrin "Wrong attribute name");
cd75115baac4df586f9a346dc1c2c9d9bd3d58aaminfrin fail_unless(data->msg->elements[0].num_values == ((_i + 5) % 10),
fe64b2ba25510d8c9dba5560a2d537763566cf40nd "Wrong number of attribute values, expected [%d] got [%d]",
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ((_i + 5) % 10), data->msg->elements[0].num_values);
9bcfc3697a91b5215893a7d0206865b13fc72148nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(test_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40ndEND_TEST
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndSuite *create_sysdb_suite(void)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd Suite *s = suite_create("sysdb");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd TCase *tc_sysdb = tcase_create("SYSDB Tests");
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Create a new user */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_add_user,27000,27010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Verify the users were added */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_getpwnam, 27000, 27010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Create a new group */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tcase_add_loop_test(tc_sysdb, test_sysdb_add_group, 28000, 28010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Verify the groups were added */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_getgrnam, 28000, 28010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* sysdb_store_user allows setting attributes for existing users */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_store_user_existing, 27000, 27010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* test the change */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_get_user_attr, 27000, 27010);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Remove the other half by gid */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_group_by_gid, 28000, 28010);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
7a9fd3b88382052ae000d95ff0d35a1f318d6b23pquerna /* Remove the other half by uid */
4a31db3c3a0202003c1b9f87affa7cc143e120e5sf tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_user_by_uid, 27000, 27010);
7a9fd3b88382052ae000d95ff0d35a1f318d6b23pquerna
7a9fd3b88382052ae000d95ff0d35a1f318d6b23pquerna /* Create a new user */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_store_user, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Verify the users were added */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_getpwnam, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Verify the users can be queried by UID */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_getpwuid, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Enumerate the users */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_test(tc_sysdb, test_sysdb_enumpwent);
50cb7e2b30597f481fee57bac945190f06ebcc58jorton
ee1af2aeb57527f33baa4737aa431e4aef997855rbowen /* Change their attribute */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_set_user_attr, 27010, 27020);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Verify the change */
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor tcase_add_loop_test(tc_sysdb, test_sysdb_get_user_attr, 27010, 27020);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Create a new group */
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen tcase_add_loop_test(tc_sysdb, test_sysdb_store_group, 28010, 28020);
50cb7e2b30597f481fee57bac945190f06ebcc58jorton
50cb7e2b30597f481fee57bac945190f06ebcc58jorton /* Verify the groups were added */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele /* Verify the groups can be queried by GID */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_getgrgid, 28010, 28020);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Enumerate the groups */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_test(tc_sysdb, test_sysdb_enumgrent);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor /* Add some members to the groups */
e23d878014f00a27b043a25e59f809c7af497e5ctakashi tcase_add_loop_test(tc_sysdb, test_sysdb_add_group_member, 28010, 28020);
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Authenticate with missing cached password */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_cached_authentication_missing_password,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd 27010, 27011);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Add a cached password */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_cache_password, 27010, 27011);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Authenticate against cached password */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_cached_authentication_wrong_password,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem 27010, 27011);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_sysdb, test_sysdb_cached_authentication, 27010, 27011);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* ASQ search test */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_loop_test(tc_sysdb, test_sysdb_prepare_asq_test_user, 28011, 28020);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_test(tc_sysdb, test_sysdb_asq_search);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Test search with more than one result */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_test(tc_sysdb, test_sysdb_search_all_users);
130d299c4b2b15be45532a176604c71fdc7bea5bnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Remove the members from the groups */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tcase_add_loop_test(tc_sysdb, test_sysdb_remove_group_member, 28010, 28020);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive /* Remove the users by name */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_user, 27010, 27020);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess /* Remove the groups by name */
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_group, 28010, 28020);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* test the ignore_not_found parameter for users */
130d299c4b2b15be45532a176604c71fdc7bea5bnd tcase_add_test(tc_sysdb, test_sysdb_remove_nonexistent_user);
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* test the ignore_not_found parameter for groups */
130d299c4b2b15be45532a176604c71fdc7bea5bnd tcase_add_test(tc_sysdb, test_sysdb_remove_nonexistent_group);
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* test custom operations */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tcase_add_loop_test(tc_sysdb, test_sysdb_store_custom, 29010, 29020);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tcase_add_test(tc_sysdb, test_sysdb_search_custom_by_name);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tcase_add_test(tc_sysdb, test_sysdb_update_custom);
6c5c651b0b97607b8c8b4965c1385c67699f217fnd tcase_add_test(tc_sysdb, test_sysdb_search_custom_update);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tcase_add_test(tc_sysdb, test_sysdb_search_custom);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd tcase_add_test(tc_sysdb, test_sysdb_delete_custom);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd /* test recursive delete */
6c5c651b0b97607b8c8b4965c1385c67699f217fnd tcase_add_test(tc_sysdb, test_sysdb_delete_recursive);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tcase_add_test(tc_sysdb, test_sysdb_attrs_replace_name);
4bb78e7cdd53f50240cff4ad7a97c7ed36483797slive
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem/* Add all test cases to the test suite */
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem suite_add_tcase(s, tc_sysdb);
4bb78e7cdd53f50240cff4ad7a97c7ed36483797slive
4bb78e7cdd53f50240cff4ad7a97c7ed36483797slive TCase *tc_memberof = tcase_create("SYSDB member/memberof/memberuid Tests");
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_group, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_user, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_add_group_member,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_check_memberuid,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem MBO_GROUP_BASE + 5, MBO_GROUP_BASE + 6);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem test_sysdb_memberof_check_memberuid_without_group_5,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem MBO_GROUP_BASE , MBO_GROUP_BASE + 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_group, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_test(tc_memberof, test_sysdb_memberof_close_loop);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_store_user, 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_add_group_member,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_memberof_check_memberuid_loop,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor MBO_GROUP_BASE + 5, MBO_GROUP_BASE + 6);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem test_sysdb_memberof_check_memberuid_loop_without_group_5,
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem 0, 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem tcase_add_loop_test(tc_memberof, test_sysdb_remove_local_group_by_gid,
031bbbc0d1189b07330e38d0c126820a9ab7795egryzor MBO_GROUP_BASE , MBO_GROUP_BASE + 10);
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem suite_add_tcase(s, tc_memberof);
4bb78e7cdd53f50240cff4ad7a97c7ed36483797slive
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return s;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndint main(int argc, const char *argv[]) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int opt;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd poptContext pc;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int failure_count;
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem Suite *sysdb_suite;
5f00eedb74adc88b8282475faf6275dad390c9a3rpluem SRunner *sr;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct poptOption long_options[] = {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd POPT_AUTOHELP
06ba4a61654b3763ad65f52283832ebf058fdf1cslive SSSD_MAIN_OPTS
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { NULL }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive };
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
97a9a944b5887e91042b019776c41d5dd74557aferikabele pc = poptGetContext(argv[0], argc, argv, long_options, 0);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive while((opt = poptGetNextOpt(pc)) != -1) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele switch(opt) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive default:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive fprintf(stderr, "\nInvalid option %s: %s\n\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive poptBadOption(pc, 0), poptStrerror(opt));
130d299c4b2b15be45532a176604c71fdc7bea5bnd poptPrintUsage(pc, stderr, 0);
130d299c4b2b15be45532a176604c71fdc7bea5bnd return 1;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd poptFreeContext(pc);
7ef9b6763ad87846cf83c3f71467f43e349d080aerikabele
130d299c4b2b15be45532a176604c71fdc7bea5bnd tests_set_cwd();
97a9a944b5887e91042b019776c41d5dd74557aferikabele
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = unlink(TESTS_PATH"/"LOCAL_SYSDB_FILE);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd if (ret != EOK && errno != ENOENT) {
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd fprintf(stderr, "Could not delete the test ldb file (%d) (%s)\n",
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd errno, strerror(errno));
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd return EXIT_FAILURE;
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd }
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd sysdb_suite = create_sysdb_suite();
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd sr = srunner_create(sysdb_suite);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd srunner_run_all(sr, CK_ENV);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd failure_count = srunner_ntests_failed(sr);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen srunner_free(sr);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd if (failure_count == 0) {
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd ret = unlink(TESTS_PATH"/"TEST_CONF_FILE);
88d86cfadffe2275a3dfb67a4d7bdc018630b661rbowen if (ret != EOK) {
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd fprintf(stderr, "Could not delete the test config ldb file (%d) (%s)\n",
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd errno, strerror(errno));
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd return EXIT_FAILURE;
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd }
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd ret = unlink(TESTS_PATH"/"LOCAL_SYSDB_FILE);
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd if (ret != EOK) {
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd fprintf(stderr, "Could not delete the test config ldb file (%d) (%s)\n",
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd errno, strerror(errno));
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd return EXIT_FAILURE;
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd }
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd return EXIT_SUCCESS;
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd }
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd return EXIT_FAILURE;
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd}
6c45910d5394acbc3f20ab3f2615d9ed2b4e6533nd