da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek Copyright (C) 2013 Red Hat
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek SSSD tests: Common utilities for tests that exercise domains
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek This program is free software; you can redistribute it and/or modify
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek it under the terms of the GNU General Public License as published by
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek (at your option) any later version.
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek This program is distributed in the hope that it will be useful,
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek GNU General Public License for more details.
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek You should have received a copy of the GNU General Public License
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek/* Including private header makes sure we can initialize test domains. */
c02b8482375837b57cb618ed56d4bede0e006d9dPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina cdb_path = talloc_asprintf(tmp_ctx, "%s/%s", tests_path, cdb_file);
919cfb623e9b725eaa654c6e1b513d1305057314Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf failed\n");
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* connect to the confdb */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "confdb_init failed: %d\n", ret);
c02b8482375837b57cb618ed56d4bede0e006d9dPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* get current domain list */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina ret = confdb_get_string(cdb, tmp_ctx, "config/sssd", "domains",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* check if the domain is already in */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina ret = split_on_separator(tmp_ctx, list, ',', true, true, &array, NULL);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* add domain to the list of enabled domains */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina list = talloc_asprintf_append(list, ", %s", name);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina ret = confdb_add_param(cdb, true, "config/sssd", "domains", val);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to change domain list [%d]: %s\n",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* create domain section */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina cdb_path = talloc_asprintf(tmp_ctx, CONFDB_DOMAIN_PATH_TMPL, name);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina ret = confdb_add_param(cdb, true, cdb_path, "id_provider", val);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add id_provider [%d]: %s\n",
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina ret = confdb_add_param(cdb, true, cdb_path, params[i].key, val);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add parameter %s [%d]: "
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina "%s\n", params[i].key, ret, sss_strerror(ret));
dd285415d7a8d8376207960cfa3e977524c3b98cJakub Hrozekvoid reset_ldb_errstrings(struct sss_domain_info *dom)
dd285415d7a8d8376207960cfa3e977524c3b98cJakub Hrozek ldb_reset_err_string(sysdb_ctx_get_ldb(dom->sysdb));
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* initialize sysdb */
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina ret = sssd_domain_init(mem_ctx, cdb, name, db_path, &domain);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "sssd_domain_init() of %s failed "
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina /* init with an AD-style regex to be able to test flat name */
e4b4b669e0c1ef5ec3be04768edf2565a7bac5a1Jakub Hrozek "(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
e4b4b669e0c1ef5ec3be04768edf2565a7bac5a1Jakub Hrozek "((?P<name>[^@]+)@(?P<domain>.+$))|" \
e4b4b669e0c1ef5ec3be04768edf2565a7bac5a1Jakub Hrozek "(^(?P<name>[^@\\\\]+)$))",
e4b4b669e0c1ef5ec3be04768edf2565a7bac5a1Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "cannot create names context\n");
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina const char **domains,
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "create_ev_test_ctx() failed\n");
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina ret = mock_confdb(test_ctx, tests_path, cdb_file, &test_ctx->confdb);
dbb990fb29e7178a3cce53474e48ce69ab3a97a0Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to initialize confdb [%d]: %s\n",
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina /* create confdb objects for the domains */
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina ret = mock_confdb_domain(test_ctx, test_ctx->confdb, tests_path,
f1e3364a72eb75673d10cf8c97ba8f1d7a385405Petr Čech domains[i], id_provider, params != NULL ? params[i] : NULL,
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to initialize confdb domain "
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina /* initialize domain list and sysdb of the domains */
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina ret = mock_domain(test_ctx, test_ctx->confdb, tests_path, domains[i],
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add new domain [%d]: %s\n",
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina /* the first domain we obtained is already head of the complete list */
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina /* set data from the first domain */
acc1c0c07fc76bc05d91c0bd2f172cd638ff3546Pavel Březina return create_multidom_test_ctx(mem_ctx, tests_path, confdb_path, domains,
629a188ec71155911301fddc36e360831045d2c6Pavel Březinavoid test_multidom_suite_cleanup(const char *tests_path,
629a188ec71155911301fddc36e360831045d2c6Pavel Březina const char **domains)
629a188ec71155911301fddc36e360831045d2c6Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
629a188ec71155911301fddc36e360831045d2c6Pavel Březina cdb_path = talloc_asprintf(tmp_ctx, "%s/%s", tests_path, cdb_file);
629a188ec71155911301fddc36e360831045d2c6Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Could not contruct cdb path\n");
629a188ec71155911301fddc36e360831045d2c6Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Could not delete the test config "
629a188ec71155911301fddc36e360831045d2c6Pavel Březina "ldb file [%d]: (%s)\n", ret, sss_strerror(ret));
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina if (strcmp(domains[i], LOCAL_SYSDB_FILE) == 0) {
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina /* local domain */
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = sysdb_get_db_file(tmp_ctx, "local", domains[i], tests_path,
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek /* The mocked database doesn't really care about its provider type, just
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek * distinguishes between a local and non-local databases
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek ret = sysdb_get_db_file(tmp_ctx, "fake_nonlocal", domains[i], tests_path,
629a188ec71155911301fddc36e360831045d2c6Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Could not construct sysdb path\n");
629a188ec71155911301fddc36e360831045d2c6Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Could not delete the test domain "
629a188ec71155911301fddc36e360831045d2c6Pavel Březina "ldb file [%d]: (%s)\n", ret, sss_strerror(ret));
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Could not delete the test domain "
f983b400bf4f6fb14a2174d6f58071e06e9ec832Jakub Hrozek "ldb timestamp file [%d]: (%s)\n", ret, sss_strerror(ret));
629a188ec71155911301fddc36e360831045d2c6Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Could not delete the test dir (%d) (%s)\n",
da33a9d7742d45975bd97d33dd8ad04a843e7656Jakub Hrozekvoid test_dom_suite_cleanup(const char *tests_path,
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_multidom_suite_cleanup(tests_path, cdb_file, domains);
cffe3defa3cb5011efc92a7773fe113a1e69774fJakub Hrozekstruct sss_domain_info *named_domain(TALLOC_CTX *mem_ctx,
cffe3defa3cb5011efc92a7773fe113a1e69774fJakub Hrozek const char *name,