f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek/*
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek Authors:
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek Copyright (C) 2015 Red Hat
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SSSD tests: IPA subdomain server utils tests
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek This program is free software; you can redistribute it and/or modify
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek it under the terms of the GNU General Public License as published by
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek the Free Software Foundation; either version 3 of the License, or
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek (at your option) any later version.
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek This program is distributed in the hope that it will be useful,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek GNU General Public License for more details.
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek You should have received a copy of the GNU General Public License
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek*/
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <talloc.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <tevent.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <errno.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <popt.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <stdlib.h>
8890a30f5d054187fd7d5b50503f82a49cd025f0Lukas Slebodnik#include <sys/stat.h>
8890a30f5d054187fd7d5b50503f82a49cd025f0Lukas Slebodnik#include <fcntl.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <sys/types.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <ifaddrs.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include <arpa/inet.h>
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
bee2f31ca5d151b7fe35c509fe7eae24ca4f4451Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
bee2f31ca5d151b7fe35c509fe7eae24ca4f4451Lukas Slebodnik
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "providers/ipa/ipa_subdomains.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "providers/ipa/ipa_opts.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "providers/data_provider.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "tests/cmocka/common_mock.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "tests/cmocka/common_mock_resp.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "tests/cmocka/common_mock_krb5.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "tests/cmocka/common_mock_sdap.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#include "tests/cmocka/common_mock_be.h"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define DOM_REALM "DOM.MAIN"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define HOSTNAME "ipaserver.dom.main"
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek#define DOM_FLAT "DOM"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define TEST_AUTHID "host/"HOSTNAME
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define KEYTAB_TEST_PRINC TEST_AUTHID"@"DOM_REALM
bee2f31ca5d151b7fe35c509fe7eae24ca4f4451Lukas Slebodnik#define KEYTAB_PATH TEST_DIR"/"TESTS_PATH"/keytab_test.keytab"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define SUBDOM_NAME "twoway.subdom.test"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define SUBDOM_REALM "TWOWAY.SUBDOM.TEST"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define SUBDOM_FLAT "TWOWAY"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define SUBDOM_SID "S-1-2-3"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define CHILD_NAME "child."SUBDOM_NAME
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define CHILD_REALM "CHILD."SUBDOM_REALM
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define CHILD_FLAT "CHILD"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define CHILD_SID "S-1-2-3-4"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define TEST_CONF_DB "test_ipa_subdom_server.ldb"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define TEST_DOM_NAME "ipa_subdom_server_test"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek#define TEST_ID_PROVIDER "ipa"
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
bee2f31ca5d151b7fe35c509fe7eae24ca4f4451Lukas Slebodnik#define ONEWAY_KEYTAB TEST_DIR"/"TESTS_PATH"/"SUBDOM_REALM".keytab"
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek#define ONEWAY_PRINC DOM_FLAT"$"
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek#define ONEWAY_AUTHID ONEWAY_PRINC"@"SUBDOM_REALM
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekstatic bool global_rename_called;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik#ifdef HAVE_SELINUX
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz/* Provide faster implementation of Kerberos function
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik * krb5int_labeled_[f]?open. Real functions take care also
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik * about SELinux context which is very expensive operation
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * and cause failures due to timeout when executing with Valgrind.
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik * It's approximately 40 times slower with real function
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik */
1510d1264b44c437b8270e0a5a239e8624933c3dLukas SlebodnikFILE *
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnikkrb5int_labeled_fopen(const char *path, const char *mode)
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik{
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik return fopen(path, mode);
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik}
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnikint
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnikkrb5int_labeled_open(const char *path, int flags, mode_t mode)
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik{
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik return open(path, flags, mode);
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik}
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik#endif /* HAVE_SELINUX */
1510d1264b44c437b8270e0a5a239e8624933c3dLukas Slebodnik
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekkrb5_error_code __wrap_krb5_kt_default(krb5_context context, krb5_keytab *id)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return krb5_kt_resolve(context, KEYTAB_PATH, id);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekstatic void create_dummy_keytab(const char *dummy_kt)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek errno_t ret;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_non_null(dummy_kt);
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek mock_keytab_with_contents(global_talloc_context,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek dummy_kt, ONEWAY_AUTHID);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek ret = access(dummy_kt, R_OK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, 0);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekstatic int wrap_exec(void)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek const char *test_kt;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek const char *fail_creating_kt;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_kt = getenv("TEST_KT_ENV");
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek if (test_kt == NULL) {
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek _exit(1);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek }
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek unsetenv("TEST_KT_ENV");
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek fail_creating_kt = getenv("KT_CREATE_FAIL");
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek if (fail_creating_kt != NULL) {
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek _exit(1);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek }
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek create_dummy_keytab(test_kt);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek _exit(0);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek return 1; /* Should not happen */
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek}
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekint __wrap_execle(const char *path, const char *arg, ...)
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek return wrap_exec();
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
323943605c88838f1f86a72f891eb28600bb34e2Lukas Slebodnikint __wrap_execve(const char *path, const char *arg, ...)
323943605c88838f1f86a72f891eb28600bb34e2Lukas Slebodnik{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek return wrap_exec();
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek}
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekerrno_t __real_sss_unique_filename(TALLOC_CTX *owner, char *path_tmpl);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekerrno_t __wrap_sss_unique_filename(TALLOC_CTX *owner, char *path_tmpl)
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek int ret;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek int sret;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek ret = __real_sss_unique_filename(owner, path_tmpl);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek if (ret == EOK) {
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek sret = setenv("TEST_KT_ENV", path_tmpl, 1);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_int_equal(sret, 0);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek }
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek return ret;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek}
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekint __real_rename(const char *old, const char *new);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekint __wrap_rename(const char *old, const char *new)
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek global_rename_called = true;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek return __real_rename(old, new);
323943605c88838f1f86a72f891eb28600bb34e2Lukas Slebodnik}
323943605c88838f1f86a72f891eb28600bb34e2Lukas Slebodnik
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstruct trust_test_ctx {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct sss_test_ctx *tctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct be_ctx *be_ctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct ipa_id_ctx *ipa_ctx;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek bool expect_rename;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek};
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic struct ipa_id_ctx *mock_ipa_ctx(TALLOC_CTX *mem_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct be_ctx *be_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct sss_test_ctx *tctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *krb5_realm,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *hostname)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct ipa_id_ctx *ipa_ctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_ctx = talloc_zero(mem_ctx, struct ipa_id_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(ipa_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_ctx->ipa_options = talloc_zero(ipa_ctx, struct ipa_options);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(ipa_ctx->ipa_options);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_ctx->ipa_options->id = talloc_zero(ipa_ctx->ipa_options,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct sdap_options);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(ipa_ctx->ipa_options->id);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = sdap_copy_map(ipa_ctx->ipa_options->id,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_user_map,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SDAP_OPTS_USER,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek &ipa_ctx->ipa_options->id->user_map);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, ERR_OK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = dp_get_options(ipa_ctx->ipa_options->id,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tctx->confdb,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tctx->conf_dom_path,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_def_ldap_opts,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SDAP_OPTS_BASIC,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek &ipa_ctx->ipa_options->id->basic);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = dp_get_options(ipa_ctx->ipa_options->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tctx->confdb,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tctx->conf_dom_path,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_basic_opts,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek IPA_OPTS_BASIC,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek &ipa_ctx->ipa_options->basic);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = dp_opt_set_string(ipa_ctx->ipa_options->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek IPA_KRB5_REALM, krb5_realm);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = dp_opt_set_string(ipa_ctx->ipa_options->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek IPA_HOSTNAME, hostname);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = dp_opt_set_bool(ipa_ctx->ipa_options->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek IPA_SERVER_MODE, true);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_ctx->sdap_id_ctx = mock_sdap_id_ctx(ipa_ctx, be_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_ctx->ipa_options->id);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(ipa_ctx->sdap_id_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return ipa_ctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic struct ipa_server_mode_ctx *mock_server_mode(TALLOC_CTX *mem_ctx)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct ipa_server_mode_ctx *server_mode;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek server_mode = talloc_zero(mem_ctx, struct ipa_server_mode_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(server_mode);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek server_mode->hostname = HOSTNAME;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek server_mode->realm = DOM_REALM;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return server_mode;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void add_test_subdomains(struct trust_test_ctx *test_ctx,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek uint32_t direction)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* Add two subdomains */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SUBDOM_NAME, SUBDOM_REALM,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek NULL, SUBDOM_SID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek true, false, SUBDOM_REALM,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose direction, NULL);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = sysdb_subdomain_store(test_ctx->tctx->sysdb,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek CHILD_NAME, CHILD_REALM,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek CHILD_FLAT, CHILD_SID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek true, false, SUBDOM_REALM,
20348a30feb4be619b3b691c24c9be8131507c46Sumit Bose direction, NULL);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = sysdb_update_subdomains(test_ctx->tctx->dom, test_ctx->tctx->confdb);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void add_test_2way_subdomains(struct trust_test_ctx *test_ctx)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek return add_test_subdomains(test_ctx, 0x1 | 0x2);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void add_test_1way_subdomains(struct trust_test_ctx *test_ctx)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek return add_test_subdomains(test_ctx, 0x1);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic int test_ipa_server_create_trusts_setup(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx *test_ctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct sss_test_conf_param params[] = {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek { NULL, NULL }, /* Sentinel */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek };
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx = talloc_zero(NULL,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek TEST_CONF_DB, TEST_DOM_NAME,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek TEST_ID_PROVIDER, params);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->tctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->tctx->dom->flat_name = discard_const(DOM_FLAT);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->tctx->dom->realm = discard_const(DOM_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->be_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->ipa_ctx = mock_ipa_ctx(test_ctx, test_ctx->be_ctx, test_ctx->tctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM, HOSTNAME);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->tctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->ipa_ctx->server_mode = mock_server_mode(test_ctx->ipa_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->ipa_ctx->server_mode);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = be_init_failover(test_ctx->be_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek mock_keytab_with_contents(test_ctx, KEYTAB_PATH, KEYTAB_TEST_PRINC);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek global_rename_called = false;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek *state = test_ctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return 0;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic int test_ipa_server_create_trusts_teardown(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = unlink(KEYTAB_PATH);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, 0);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek unlink(ONEWAY_KEYTAB);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek /* Ignore failures */
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek /* If a test needs this variable, it should be set again in
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek * each test
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek */
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek unsetenv("KT_CREATE_FAIL");
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_free(test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return 0;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_ipa_server_create_trusts_none(struct tevent_req *req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_ipa_server_create_trusts_twoway(struct tevent_req *req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_ipa_server_create_trusts(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct tevent_req *req;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek req = ipa_server_create_trusts_send(test_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->tctx->ev,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->be_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->ipa_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->be_ctx->domain);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tevent_req_set_callback(req, test_ipa_server_create_trusts_none, test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = test_ev_loop(test_ctx->tctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, ERR_OK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_ipa_server_create_trusts_none(struct tevent_req *req)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx *test_ctx = \
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tevent_req_callback_data(req, struct trust_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = ipa_server_create_trusts_recv(req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_zfree(req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* Add two subdomains */
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek add_test_2way_subdomains(test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek req = ipa_server_create_trusts_send(test_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->tctx->ev,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->be_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->ipa_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->be_ctx->domain);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tevent_req_set_callback(req, test_ipa_server_create_trusts_twoway, test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void assert_trust_object(struct ipa_ad_server_ctx *trust,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *dom_name,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *dom_realm,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *sid,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *keytab,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *authid,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *sdap_realm)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const char *s;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(trust);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(trust->dom);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_string_equal(trust->dom->name, dom_name);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_string_equal(trust->dom->domain_id, sid);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek s = dp_opt_get_string(trust->ad_id_ctx->ad_options->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek AD_KRB5_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek if (dom_realm != NULL) {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_string_equal(s, dom_realm);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek } else {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek s = dp_opt_get_string(trust->ad_id_ctx->ad_options->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek AD_DOMAIN);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek if (dom_name != NULL) {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_string_equal(s, dom_name);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek } else {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* the system keytab is always used with two-way trusts */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek s = dp_opt_get_string(trust->ad_id_ctx->ad_options->id->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SDAP_KRB5_KEYTAB);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek if (keytab != NULL) {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_string_equal(s, keytab);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek } else {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek s = dp_opt_get_string(trust->ad_id_ctx->ad_options->id->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SDAP_SASL_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek if (sdap_realm != NULL) {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_string_equal(s, sdap_realm);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek } else {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek s = dp_opt_get_string(trust->ad_id_ctx->ad_options->id->basic,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SDAP_SASL_AUTHID);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek if (authid != NULL) {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_string_equal(s, authid);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek } else {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(s);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_ipa_server_create_trusts_twoway(struct tevent_req *req)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx *test_ctx = \
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tevent_req_callback_data(req, struct trust_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct sss_domain_info *child_dom;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose struct ipa_ad_server_ctx *s_trust;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose struct ipa_ad_server_ctx *c_trust;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = ipa_server_create_trusts_recv(req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_zfree(req);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* Trust object should be around now */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->ipa_ctx->server_mode->trusts);
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_non_null(test_ctx->ipa_ctx->server_mode->trusts->next);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose if (strcmp(test_ctx->ipa_ctx->server_mode->trusts->dom->name,
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SUBDOM_NAME) == 0) {
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose s_trust = test_ctx->ipa_ctx->server_mode->trusts;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose c_trust = test_ctx->ipa_ctx->server_mode->trusts->next;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose } else {
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose s_trust = test_ctx->ipa_ctx->server_mode->trusts->next;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose c_trust = test_ctx->ipa_ctx->server_mode->trusts;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* Two-way trusts should use the system realm */
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_trust_object(c_trust,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek CHILD_NAME,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek CHILD_SID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek NULL,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek TEST_AUTHID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_trust_object(s_trust,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SUBDOM_NAME,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SUBDOM_SID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek NULL,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek TEST_AUTHID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* No more trust objects */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts->next->next);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = sysdb_subdomain_delete(test_ctx->tctx->sysdb, CHILD_NAME);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek child_dom = find_domain_by_name(test_ctx->be_ctx->domain, CHILD_NAME, true);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(child_dom);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_ad_subdom_remove(test_ctx->be_ctx, test_ctx->ipa_ctx, child_dom);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_trust_object(test_ctx->ipa_ctx->server_mode->trusts,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SUBDOM_NAME,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SUBDOM_SID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek NULL,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek TEST_AUTHID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts->next);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
eca74a9559ce1b0f123c14906ad8394fc303f468Jakub Hrozek test_ev_done(test_ctx->tctx, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekipa_server_init_done(struct tevent_context *ev,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct tevent_timer *te,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct timeval tv, void *pvt)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(pvt, struct trust_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->tctx->done = true;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_ipa_server_trust_init(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct trust_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct tevent_timer *timeout_handler;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct timeval tv;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose struct ipa_ad_server_ctx *s_trust;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose struct ipa_ad_server_ctx *c_trust;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek add_test_2way_subdomains(test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = ipa_ad_subdom_init(test_ctx->be_ctx, test_ctx->ipa_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tv = tevent_timeval_current_ofs(1, 0);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek timeout_handler = tevent_add_timer(test_ctx->tctx->ev, test_ctx, tv,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ipa_server_init_done, test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(timeout_handler);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = test_ev_loop(test_ctx->tctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, ERR_OK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* Trust object should be around now */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->ipa_ctx->server_mode->trusts);
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_non_null(test_ctx->ipa_ctx->server_mode->trusts->next);
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose if (strcmp(test_ctx->ipa_ctx->server_mode->trusts->dom->name,
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SUBDOM_NAME) == 0) {
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose s_trust = test_ctx->ipa_ctx->server_mode->trusts;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose c_trust = test_ctx->ipa_ctx->server_mode->trusts->next;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose } else {
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose s_trust = test_ctx->ipa_ctx->server_mode->trusts->next;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose c_trust = test_ctx->ipa_ctx->server_mode->trusts;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* Two-way trusts should use the system realm */
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_trust_object(c_trust,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek CHILD_NAME,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek CHILD_SID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek NULL,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek TEST_AUTHID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_trust_object(s_trust,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SUBDOM_NAME,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SUBDOM_SID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek NULL,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek TEST_AUTHID,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DOM_REALM);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* No more trust objects */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts->next->next);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstruct dir_test_ctx {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct ldb_context *ldb;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct sysdb_attrs *tdo;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek};
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic int test_get_trust_direction_setup(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx *test_ctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx = talloc_zero(global_talloc_context,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->ldb = ldb_init(test_ctx, NULL);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->ldb);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ctx->tdo = sysdb_new_attrs(test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_non_null(test_ctx->tdo);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek *state = test_ctx;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return 0;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic int test_get_trust_direction_teardown(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct dir_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_free(test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return 0;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek/* These are stupid tests, but test real data */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_trust_dir_getset(struct dir_test_ctx *test_ctx,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek uint32_t dir_in)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek uint32_t dir;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = sysdb_attrs_add_uint32(test_ctx->tdo, IPA_TRUST_DIRECTION, dir_in);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = ipa_server_get_trust_direction(test_ctx->tdo, test_ctx->ldb, &dir);
9aa384d5b430db1be014c613b61484bdb9f80688Lukas Slebodnik assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(dir, dir_in);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_get_trust_direction_inbound(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct dir_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_trust_dir_getset(test_ctx, 0x1);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_get_trust_direction_outbound(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct dir_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_trust_dir_getset(test_ctx, 0x2);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_get_trust_direction_twoway(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct dir_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_trust_dir_getset(test_ctx, 0x1 | 0x2);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_get_trust_direction_notset_root(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek uint32_t dir;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct dir_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = sysdb_attrs_add_string(test_ctx->tdo, SYSDB_ORIG_DN,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek "cn=AD.DOM,cn=ad,cn=trusts,dc=example,dc=com");
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = ipa_server_get_trust_direction(test_ctx->tdo, test_ctx->ldb, &dir);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* With root domains we assume two-way trust */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(dir, 0x1 | 0x2);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekstatic void test_get_trust_direction_notset_member(void **state)
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek errno_t ret;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek uint32_t dir;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct dir_test_ctx *test_ctx =
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek talloc_get_type(*state, struct dir_test_ctx);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = sysdb_attrs_add_string(test_ctx->tdo, SYSDB_ORIG_DN,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek "cn=SUB.AD.DOM,cn=AD.DOM,cn=ad,cn=trusts,dc=example,dc=com");
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek ret = ipa_server_get_trust_direction(test_ctx->tdo, test_ctx->ldb, &dir);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(ret, EOK);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* With members we set zero and take a look at the parent */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek assert_int_equal(dir, 0);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void test_ipa_server_create_trusts_oneway(struct tevent_req *req);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void test_ipa_server_create_oneway(void **state)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct trust_test_ctx *test_ctx =
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct tevent_req *req;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek errno_t ret;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek add_test_1way_subdomains(test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = access(ONEWAY_KEYTAB, R_OK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_not_equal(ret, 0);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->expect_rename = true;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek req = ipa_server_create_trusts_send(test_ctx,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->tctx->ev,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->be_ctx,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->ipa_ctx,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->be_ctx->domain);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(req);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek tevent_req_set_callback(req, test_ipa_server_create_trusts_oneway, test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = test_ev_loop(test_ctx->tctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, ERR_OK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void test_ipa_server_create_trusts_oneway(struct tevent_req *req)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct trust_test_ctx *test_ctx = \
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek tevent_req_callback_data(req, struct trust_test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek errno_t ret;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose struct ipa_ad_server_ctx *s_trust;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose struct ipa_ad_server_ctx *c_trust;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = ipa_server_create_trusts_recv(req);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek talloc_zfree(req);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, EOK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_true(test_ctx->expect_rename == global_rename_called);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = access(ONEWAY_KEYTAB, R_OK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, 0);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek /* Trust object should be around now */
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(test_ctx->ipa_ctx->server_mode->trusts);
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_non_null(test_ctx->ipa_ctx->server_mode->trusts->next);
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose if (strcmp(test_ctx->ipa_ctx->server_mode->trusts->dom->name,
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose SUBDOM_NAME) == 0) {
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose s_trust = test_ctx->ipa_ctx->server_mode->trusts;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose c_trust = test_ctx->ipa_ctx->server_mode->trusts->next;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose } else {
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose s_trust = test_ctx->ipa_ctx->server_mode->trusts->next;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose c_trust = test_ctx->ipa_ctx->server_mode->trusts;
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose }
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek assert_trust_object(
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose c_trust,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek CHILD_NAME, /* AD domain name */
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek CHILD_REALM, /* AD realm can be child if SDAP realm is parent's */
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek CHILD_SID,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek ONEWAY_KEYTAB, /* Keytab shared with parent AD dom */
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek ONEWAY_PRINC, /* Principal shared with parent AD dom */
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek SUBDOM_REALM); /* SDAP realm must be AD root domain */
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek /* Here all properties point to the AD domain */
0e238c259c066cf997aaa940d33d6bda96c15925Sumit Bose assert_trust_object(s_trust,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek SUBDOM_NAME,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek SUBDOM_REALM,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek SUBDOM_SID,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek ONEWAY_KEYTAB,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek ONEWAY_PRINC,
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek SUBDOM_REALM);
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek
d2c552edde275e6c0de904760147afb2992796e9Jakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts->next->next);
eca74a9559ce1b0f123c14906ad8394fc303f468Jakub Hrozek test_ev_done(test_ctx->tctx, EOK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void test_ipa_server_create_oneway_kt_exists(void **state)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct trust_test_ctx *test_ctx =
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct tevent_req *req;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek errno_t ret;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek add_test_1way_subdomains(test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek create_dummy_keytab(ONEWAY_KEYTAB);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek ret = access(ONEWAY_KEYTAB, R_OK);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_int_equal(ret, 0);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->expect_rename = true;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek req = ipa_server_create_trusts_send(test_ctx,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->tctx->ev,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->be_ctx,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->ipa_ctx,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->be_ctx->domain);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_non_null(req);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek tevent_req_set_callback(req, test_ipa_server_create_trusts_oneway, test_ctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_int_equal(ret, ERR_OK);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek}
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek/* Test scenario where a keytab already exists, but refresh fails. In this case,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek * sssd should attempt to reuse the previous keytab
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek */
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekstatic void test_ipa_server_create_oneway_kt_refresh_fallback(void **state)
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek struct trust_test_ctx *test_ctx =
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek struct tevent_req *req;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek errno_t ret;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek add_test_1way_subdomains(test_ctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek create_dummy_keytab(ONEWAY_KEYTAB);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = access(ONEWAY_KEYTAB, R_OK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, 0);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek setenv("KT_CREATE_FAIL", "1", 1);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->expect_rename = false;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek req = ipa_server_create_trusts_send(test_ctx,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->tctx->ev,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->be_ctx,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->ipa_ctx,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ctx->be_ctx->domain);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(req);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek tevent_req_set_callback(req, test_ipa_server_create_trusts_oneway, test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = test_ev_loop(test_ctx->tctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, ERR_OK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek/* Tests case where there's no keytab and retrieving fails. Just fail the
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek * request in that case
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek */
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekstatic void test_ipa_server_create_trusts_oneway_fail(struct tevent_req *req);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekstatic void test_ipa_server_create_oneway_kt_refresh_fail(void **state)
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek struct trust_test_ctx *test_ctx =
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek struct tevent_req *req;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek errno_t ret;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek add_test_1way_subdomains(test_ctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek setenv("KT_CREATE_FAIL", "1", 1);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->expect_rename = false;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_null(test_ctx->ipa_ctx->server_mode->trusts);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek req = ipa_server_create_trusts_send(test_ctx,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->tctx->ev,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->be_ctx,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->ipa_ctx,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx->be_ctx->domain);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_non_null(req);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek tevent_req_set_callback(req,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ipa_server_create_trusts_oneway_fail,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek ret = test_ev_loop(test_ctx->tctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_int_equal(ret, ERR_OK);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek}
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozekstatic void test_ipa_server_create_trusts_oneway_fail(struct tevent_req *req)
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek{
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek struct trust_test_ctx *test_ctx = \
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek tevent_req_callback_data(req, struct trust_test_ctx);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek errno_t ret;
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek ret = ipa_server_create_trusts_recv(req);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_int_not_equal(ret, EOK);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek assert_true(test_ctx->expect_rename == global_rename_called);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ev_done(test_ctx->tctx, EOK);
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek}
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void test_ipa_server_trust_oneway_init(void **state)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct trust_test_ctx *test_ctx =
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek talloc_get_type(*state, struct trust_test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek errno_t ret;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct tevent_timer *timeout_handler;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek struct timeval tv;
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek add_test_1way_subdomains(test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = ipa_ad_subdom_init(test_ctx->be_ctx, test_ctx->ipa_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, EOK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek tv = tevent_timeval_current_ofs(1, 0);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek timeout_handler = tevent_add_timer(test_ctx->tctx->ev, test_ctx, tv,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ipa_server_init_done, test_ctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(timeout_handler);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek ret = test_ev_loop(test_ctx->tctx);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_int_equal(ret, ERR_OK);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(test_ctx->ipa_ctx->server_mode->trusts);
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekstatic void test_ipa_trust_dir2str(void **state)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek{
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek /* Just make sure the caller can rely on getting a valid string.. */
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(ipa_trust_dir2str(0x00));
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(ipa_trust_dir2str(0x01));
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(ipa_trust_dir2str(0x02));
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek assert_non_null(ipa_trust_dir2str(0x80));
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek}
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozekint main(int argc, const char *argv[])
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek{
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek int rv;
9d69c05084176602c2c0969e51d6a81ed32974caLukas Slebodnik int no_cleanup = 0;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek poptContext pc;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek int opt;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek struct poptOption long_options[] = {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek POPT_AUTOHELP
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek SSSD_DEBUG_OPTS
9d69c05084176602c2c0969e51d6a81ed32974caLukas Slebodnik { "no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
9d69c05084176602c2c0969e51d6a81ed32974caLukas Slebodnik _("Do not delete the test database after a test run"), NULL },
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek POPT_TABLEEND
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek };
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek const struct CMUnitTest tests[] = {
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek cmocka_unit_test(test_ipa_trust_dir2str),
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_server_create_oneway,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ipa_server_create_trusts_setup,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ipa_server_create_trusts_teardown),
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_server_create_oneway_kt_exists,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ipa_server_create_trusts_setup,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ipa_server_create_trusts_teardown),
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_server_create_oneway_kt_refresh_fallback,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ipa_server_create_trusts_setup,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ipa_server_create_trusts_teardown),
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_server_create_oneway_kt_refresh_fail,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ipa_server_create_trusts_setup,
db5f9ab3feb85aa444eab20428ca2b98801b6783Jakub Hrozek test_ipa_server_create_trusts_teardown),
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_server_trust_oneway_init,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ipa_server_create_trusts_setup,
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek test_ipa_server_create_trusts_teardown),
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_server_trust_init,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ipa_server_create_trusts_setup,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ipa_server_create_trusts_teardown),
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek cmocka_unit_test_setup_teardown(test_ipa_server_create_trusts,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ipa_server_create_trusts_setup,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_ipa_server_create_trusts_teardown),
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek cmocka_unit_test_setup_teardown(test_get_trust_direction_inbound,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_setup,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_teardown),
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek cmocka_unit_test_setup_teardown(test_get_trust_direction_outbound,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_setup,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_teardown),
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek cmocka_unit_test_setup_teardown(test_get_trust_direction_twoway,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_setup,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_teardown),
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek cmocka_unit_test_setup_teardown(test_get_trust_direction_notset_root,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_setup,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_teardown),
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek cmocka_unit_test_setup_teardown(test_get_trust_direction_notset_member,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_setup,
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_get_trust_direction_teardown),
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek };
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek debug_level = SSSDBG_INVALID;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek switch(opt) {
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek default:
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek poptPrintUsage(pc, stderr, 0);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return 1;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek }
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek poptFreeContext(pc);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek DEBUG_CLI_INIT(debug_level);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek tests_set_cwd();
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek test_dom_suite_setup(TESTS_PATH);
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
9d69c05084176602c2c0969e51d6a81ed32974caLukas Slebodnik if (rv == 0 && !no_cleanup) {
9d69c05084176602c2c0969e51d6a81ed32974caLukas Slebodnik test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
9d69c05084176602c2c0969e51d6a81ed32974caLukas Slebodnik }
9d69c05084176602c2c0969e51d6a81ed32974caLukas Slebodnik
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek return rv;
f4025ea817b3467be1c2e6092014a11fe4547c0dJakub Hrozek}