25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek Michal Zidek <mzidek@redhat.com>
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek Stephen Gallagher <sgallagh@redhat.com>
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek This program is free software; you can redistribute it and/or modify
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek it under the terms of the GNU General Public License as published by
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek the Free Software Foundation; either version 3 of the License, or
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek (at your option) any later version.
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek This program is distributed in the hope that it will be useful,
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek but WITHOUT ANY WARRANTY; without even the implied warranty of
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek GNU General Public License for more details.
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek You should have received a copy of the GNU General Public License
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek along with this program. If not, see <http://www.gnu.org/licenses/>.
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidekstatic int setup_sysdb_tests(struct sysdb_test_ctx **ctx)
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek /* Create tests directory if it doesn't exist */
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek /* (relative to current dir) */
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail("Could not create %s directory", TESTS_PATH);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek test_ctx = talloc_zero(NULL, struct sysdb_test_ctx);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail("Could not allocate memory for test context");
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek /* Create an event context
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek * It will not be used except in confdb_init and sysdb_init
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "CONFDB: %s\n", conf_db);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek /* Connect to the conf db */
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail("Could not initialize connection to the confdb");
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail("Could not initialize domains placeholder");
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek "config/domain/LOCAL", "cache_credentials", val);
234958be042980242fff6da936af674da877c5efSimo Sorce ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail("Could not initialize connection to the sysdb (%d)", ret);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fprintf(stderr, "Unable to remove all test files from %s\n",TESTS_PATH);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidekstatic int test_sysdb_store_ssh_host(struct test_data *data)
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidekstatic int test_sysdb_delete_ssh_host(struct test_data *data)
19d8bc19b5b5597427878645644fa354ef6cb54dMichal Zidek ret = sysdb_delete_ssh_host(data->ctx->domain, data->hostname);
2d6836a90bd326391782a5753f70e8ba666b5defJan Cholastastatic int test_sysdb_get_ssh_host(struct test_data *data)
19d8bc19b5b5597427878645644fa354ef6cb54dMichal Zidek ret = sysdb_get_ssh_host(data->ctx, data->ctx->domain, data->hostname,
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data = talloc_zero(test_ctx, struct test_data);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data->hostname = talloc_strdup(test_ctx, TEST_HOSTNAME);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail_if(ret != EOK, "Could not store host into database");
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data = talloc_zero(test_ctx, struct test_data);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data->hostname = talloc_strdup(test_ctx, TEST_HOSTNAME);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail_if(ret != EOK, "Could not delete host from database");
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data = talloc_zero(test_ctx, struct test_data);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data->hostname = talloc_strdup(test_ctx, "nonexistent_host");
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail_if(ret != EOK, "Deletion of nonexistent host returned code %d", ret);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data = talloc_zero(test_ctx, struct test_data);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek data->hostname = talloc_strdup(test_ctx, TEST_HOSTNAME);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail("Could not store host '%s' to database", TEST_HOSTNAME);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek fail_if(ret != EOK, "Could not find host '%s'",TEST_HOSTNAME);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek TCase *tc_sysdb_ssh = tcase_create("SYSDB_SSH Tests");
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek tcase_add_test(tc_sysdb_ssh, store_one_host_test);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek tcase_add_test(tc_sysdb_ssh, delete_existing_host_test);
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek tcase_add_test(tc_sysdb_ssh, delete_nonexistent_host_test);
2d6836a90bd326391782a5753f70e8ba666b5defJan Cholasta tcase_add_test(tc_sysdb_ssh, sysdb_get_ssh_host_test);
49dd8ee2834d9477418961dbaffa4a03cfa9fd1eRené Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
25f8fac2489fd209d603acb2b494f7c72968e9bbMichal Zidek pc = poptGetContext(argv[0], argc, (const char **) argv, long_options, 0);
dfe84158c49e44f2207b94d25e61ab4f3fe38366Michal Zidek fprintf(stderr, "Warning: LDB_MODULES_PATH is not set, "
dfe84158c49e44f2207b94d25e61ab4f3fe38366Michal Zidek "will use LDB plugins installed in system paths.\n");