test_sysdb_views.c revision 2fe140d3a41e1ac66400069d35adc9379348c1e5
640b2adac05bb7f5e9fba064434c91852c3a72e6nd/*
8e34905974b7a442a55adac3b3fdb196c389e807takashi SSSD
640b2adac05bb7f5e9fba064434c91852c3a72e6nd
640b2adac05bb7f5e9fba064434c91852c3a72e6nd sysdb_views - Tests for view and override related sysdb calls
8e34905974b7a442a55adac3b3fdb196c389e807takashi
640b2adac05bb7f5e9fba064434c91852c3a72e6nd Authors:
640b2adac05bb7f5e9fba064434c91852c3a72e6nd Sumit Bose <sbose@redhat.com>
6e89d4f6c259afc94f8806c74a33a8fe81392499sf
640b2adac05bb7f5e9fba064434c91852c3a72e6nd Copyright (C) 2014 Red Hat
8e34905974b7a442a55adac3b3fdb196c389e807takashi
8e34905974b7a442a55adac3b3fdb196c389e807takashi This program is free software; you can redistribute it and/or modify
640b2adac05bb7f5e9fba064434c91852c3a72e6nd it under the terms of the GNU General Public License as published by
640b2adac05bb7f5e9fba064434c91852c3a72e6nd the Free Software Foundation; either version 3 of the License, or
640b2adac05bb7f5e9fba064434c91852c3a72e6nd (at your option) any later version.
8e34905974b7a442a55adac3b3fdb196c389e807takashi
8e34905974b7a442a55adac3b3fdb196c389e807takashi This program is distributed in the hope that it will be useful,
640b2adac05bb7f5e9fba064434c91852c3a72e6nd but WITHOUT ANY WARRANTY; without even the implied warranty of
640b2adac05bb7f5e9fba064434c91852c3a72e6nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
640b2adac05bb7f5e9fba064434c91852c3a72e6nd GNU General Public License for more details.
640b2adac05bb7f5e9fba064434c91852c3a72e6nd
640b2adac05bb7f5e9fba064434c91852c3a72e6nd You should have received a copy of the GNU General Public License
640b2adac05bb7f5e9fba064434c91852c3a72e6nd along with this program. If not, see <http://www.gnu.org/licenses/>.
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive*/
8e34905974b7a442a55adac3b3fdb196c389e807takashi
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#include <stdarg.h>
ef685e00a47967e27d89709461728a229d762172nd#include <stddef.h>
ef685e00a47967e27d89709461728a229d762172nd#include <setjmp.h>
ef685e00a47967e27d89709461728a229d762172nd#include <cmocka.h>
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#include <popt.h>
6e89d4f6c259afc94f8806c74a33a8fe81392499sf
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#include "tests/cmocka/common_mock.h"
51853aa2ebfdf9903a094467e1d02099f143639daaron#include "providers/ipa/ipa_id.h"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#include "db/sysdb_private.h" /* for sysdb->ldb member */
51853aa2ebfdf9903a094467e1d02099f143639daaron
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TESTS_PATH "tests_sysdb_views"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_CONF_FILE "tests_conf.ldb"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive
51853aa2ebfdf9903a094467e1d02099f143639daaron#define TEST_ANCHOR_PREFIX ":ANCHOR:"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_VIEW_NAME "test view"
51853aa2ebfdf9903a094467e1d02099f143639daaron#define TEST_VIEW_CONTAINER "cn=" TEST_VIEW_NAME ",cn=views,cn=sysdb"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_USER_NAME "test_user"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_USER_UID 1234
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_USER_GID 5678
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_USER_GECOS "Gecos field"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_USER_HOMEDIR "/home/home"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_USER_SHELL "/bin/shell"
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive#define TEST_USER_SID "S-1-2-3-4"
8e34905974b7a442a55adac3b3fdb196c389e807takashi
a27e9e05958bc51ea09edb8d8d862fe8b125313bslivestruct sysdb_test_ctx {
ef685e00a47967e27d89709461728a229d762172nd struct sysdb_ctx *sysdb;
ef685e00a47967e27d89709461728a229d762172nd struct confdb_ctx *confdb;
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive struct tevent_context *ev;
6e89d4f6c259afc94f8806c74a33a8fe81392499sf struct sss_domain_info *domain;
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive};
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slivestatic int _setup_sysdb_tests(struct sysdb_test_ctx **ctx, bool enumerate)
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive{
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive struct sysdb_test_ctx *test_ctx;
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive char *conf_db;
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive int ret;
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive const char *val[2];
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive val[1] = NULL;
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive /* Create tests directory if it doesn't exist */
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive /* (relative to current dir) */
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive ret = mkdir(TESTS_PATH, 0775);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive assert_true(ret == 0 || errno == EEXIST);
069aec3ea15c5ad699f98f50091aad653b1c6021rbowen
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive test_ctx = talloc_zero(global_talloc_context, struct sysdb_test_ctx);
17ca00f92106c825382359ebf0a754f8df21e316rbowen assert_non_null(test_ctx);
069aec3ea15c5ad699f98f50091aad653b1c6021rbowen
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive /* Create an event context
6e89d4f6c259afc94f8806c74a33a8fe81392499sf * It will not be used except in confdb_init and sysdb_init
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive */
17ca00f92106c825382359ebf0a754f8df21e316rbowen test_ctx->ev = tevent_context_init(test_ctx);
069aec3ea15c5ad699f98f50091aad653b1c6021rbowen assert_non_null(test_ctx->ev);
069aec3ea15c5ad699f98f50091aad653b1c6021rbowen
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive assert_non_null(conf_db);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive DEBUG(SSSDBG_MINOR_FAILURE, "CONFDB: %s\n", conf_db);
17ca00f92106c825382359ebf0a754f8df21e316rbowen
17ca00f92106c825382359ebf0a754f8df21e316rbowen /* Connect to the conf db */
17ca00f92106c825382359ebf0a754f8df21e316rbowen ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive assert_int_equal(ret, EOK);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive val[0] = "LOCAL";
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive ret = confdb_add_param(test_ctx->confdb, true,
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive "config/sssd", "domains", val);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive assert_int_equal(ret, EOK);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive
8e34905974b7a442a55adac3b3fdb196c389e807takashi val[0] = "local";
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive ret = confdb_add_param(test_ctx->confdb, true,
ef685e00a47967e27d89709461728a229d762172nd "config/domain/LOCAL", "id_provider", val);
ef685e00a47967e27d89709461728a229d762172nd assert_int_equal(ret, EOK);
ef685e00a47967e27d89709461728a229d762172nd
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive val[0] = enumerate ? "TRUE" : "FALSE";
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = confdb_add_param(test_ctx->confdb, true,
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive "config/domain/LOCAL", "enumerate", val);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive assert_int_equal(ret, EOK);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive val[0] = "TRUE";
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = confdb_add_param(test_ctx->confdb, true,
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive "config/domain/LOCAL", "cache_credentials", val);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive assert_int_equal(ret, EOK);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive TESTS_PATH, &test_ctx->domain);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive assert_int_equal(ret, EOK);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive test_ctx->sysdb = test_ctx->domain->sysdb;
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive *ctx = test_ctx;
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive return EOK;
95e8cab14596a61826fa52477dcaebc07bfbad00colm}
8e34905974b7a442a55adac3b3fdb196c389e807takashi
95e8cab14596a61826fa52477dcaebc07bfbad00colm#define setup_sysdb_tests(ctx) _setup_sysdb_tests((ctx), false)
95e8cab14596a61826fa52477dcaebc07bfbad00colm
95e8cab14596a61826fa52477dcaebc07bfbad00colmstatic void test_sysdb_setup(void **state)
95e8cab14596a61826fa52477dcaebc07bfbad00colm{
6e89d4f6c259afc94f8806c74a33a8fe81392499sf int ret;
95e8cab14596a61826fa52477dcaebc07bfbad00colm struct sysdb_test_ctx *test_ctx;
95e8cab14596a61826fa52477dcaebc07bfbad00colm
95e8cab14596a61826fa52477dcaebc07bfbad00colm assert_true(leak_check_setup());
95e8cab14596a61826fa52477dcaebc07bfbad00colm
95e8cab14596a61826fa52477dcaebc07bfbad00colm ret = setup_sysdb_tests(&test_ctx);
95e8cab14596a61826fa52477dcaebc07bfbad00colm assert_int_equal(ret, EOK);
95e8cab14596a61826fa52477dcaebc07bfbad00colm
95e8cab14596a61826fa52477dcaebc07bfbad00colm *state = (void *) test_ctx;
95e8cab14596a61826fa52477dcaebc07bfbad00colm}
95e8cab14596a61826fa52477dcaebc07bfbad00colm
95e8cab14596a61826fa52477dcaebc07bfbad00colmstatic void test_sysdb_teardown(void **state)
95e8cab14596a61826fa52477dcaebc07bfbad00colm{
95e8cab14596a61826fa52477dcaebc07bfbad00colm struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
95e8cab14596a61826fa52477dcaebc07bfbad00colm struct sysdb_test_ctx);
95e8cab14596a61826fa52477dcaebc07bfbad00colm
95e8cab14596a61826fa52477dcaebc07bfbad00colm talloc_free(test_ctx);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_true(leak_check_teardown());
8e34905974b7a442a55adac3b3fdb196c389e807takashi}
17efa6b5344b7574597eec03f02ef28103e19265nd
17efa6b5344b7574597eec03f02ef28103e19265ndvoid test_sysdb_add_overrides_to_object(void **state)
17efa6b5344b7574597eec03f02ef28103e19265nd{
ef685e00a47967e27d89709461728a229d762172nd int ret;
b2a8f444bd02b73948298f92036f693afcfee95eerikabele struct ldb_message *orig;
6e89d4f6c259afc94f8806c74a33a8fe81392499sf struct ldb_message *override;
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx struct ldb_message_element *el;
17efa6b5344b7574597eec03f02ef28103e19265nd char *tmp_str;
17efa6b5344b7574597eec03f02ef28103e19265nd struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx struct sysdb_test_ctx);
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx orig = ldb_msg_new(test_ctx);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_non_null(orig);
17efa6b5344b7574597eec03f02ef28103e19265nd
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx tmp_str = talloc_strdup(orig, "ORIGNAME");
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx ret = ldb_msg_add_string(orig, SYSDB_NAME, tmp_str);
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx assert_int_equal(ret, EOK);
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx
17efa6b5344b7574597eec03f02ef28103e19265nd tmp_str = talloc_strdup(orig, "ORIGGECOS");
cd51960ffc0f49d7a9e702162ed49b3eb0909276dirkx ret = ldb_msg_add_string(orig, SYSDB_GECOS, tmp_str);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai assert_int_equal(ret, EOK);
8e34905974b7a442a55adac3b3fdb196c389e807takashi
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai override = ldb_msg_new(test_ctx);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai assert_non_null(override);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai tmp_str = talloc_strdup(override, "OVERRIDENAME");
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = ldb_msg_add_string(override, SYSDB_NAME, tmp_str);
6e89d4f6c259afc94f8806c74a33a8fe81392499sf assert_int_equal(ret, EOK);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai
8e34905974b7a442a55adac3b3fdb196c389e807takashi tmp_str = talloc_strdup(override, "OVERRIDEGECOS");
8e34905974b7a442a55adac3b3fdb196c389e807takashi ret = ldb_msg_add_string(override, SYSDB_GECOS, tmp_str);
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_int_equal(ret, EOK);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai tmp_str = talloc_strdup(override, "OVERRIDEKEY1");
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_int_equal(ret, EOK);
8e34905974b7a442a55adac3b3fdb196c389e807takashi
8e34905974b7a442a55adac3b3fdb196c389e807takashi tmp_str = talloc_strdup(override, "OVERRIDEKEY2");
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai assert_int_equal(ret, EOK);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, override, NULL);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai assert_int_equal(ret, EOK);
17efa6b5344b7574597eec03f02ef28103e19265nd
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_string_equal(ldb_msg_find_attr_as_string(orig, SYSDB_NAME, NULL),
17efa6b5344b7574597eec03f02ef28103e19265nd "ORIGNAME");
17efa6b5344b7574597eec03f02ef28103e19265nd assert_string_equal(ldb_msg_find_attr_as_string(orig, SYSDB_GECOS, NULL),
8e34905974b7a442a55adac3b3fdb196c389e807takashi "ORIGGECOS");
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick assert_string_equal(ldb_msg_find_attr_as_string(orig,
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick OVERRIDE_PREFIX SYSDB_NAME,
6e89d4f6c259afc94f8806c74a33a8fe81392499sf NULL),
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick "OVERRIDENAME");
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_string_equal(ldb_msg_find_attr_as_string(orig,
8e34905974b7a442a55adac3b3fdb196c389e807takashi OVERRIDE_PREFIX SYSDB_GECOS,
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick NULL),
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick "OVERRIDEGECOS");
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick
8e34905974b7a442a55adac3b3fdb196c389e807takashi el = ldb_msg_find_element(orig, OVERRIDE_PREFIX SYSDB_SSH_PUBKEY);
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_non_null(el);
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick assert_int_equal(el->num_values, 2);
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick assert_int_equal(ldb_val_string_cmp(&el->values[0], "OVERRIDEKEY1"), 0);
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick assert_int_equal(ldb_val_string_cmp(&el->values[1], "OVERRIDEKEY2"), 0);
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick}
17efa6b5344b7574597eec03f02ef28103e19265nd
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawickvoid test_split_ipa_anchor(void **state)
17efa6b5344b7574597eec03f02ef28103e19265nd{
8e34905974b7a442a55adac3b3fdb196c389e807takashi int ret;
17efa6b5344b7574597eec03f02ef28103e19265nd char *dom;
17efa6b5344b7574597eec03f02ef28103e19265nd char *uuid;
17efa6b5344b7574597eec03f02ef28103e19265nd struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
ef685e00a47967e27d89709461728a229d762172nd struct sysdb_test_ctx);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = split_ipa_anchor(test_ctx, NULL, &dom, &uuid);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive assert_int_equal(ret, EINVAL);
17efa6b5344b7574597eec03f02ef28103e19265nd
17efa6b5344b7574597eec03f02ef28103e19265nd ret = split_ipa_anchor(test_ctx, "fwfkwjfkw", &dom, &uuid);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive assert_int_equal(ret, ENOMSG);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = split_ipa_anchor(test_ctx, ":IPA:", &dom, &uuid);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_int_equal(ret, EINVAL);
17efa6b5344b7574597eec03f02ef28103e19265nd
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = split_ipa_anchor(test_ctx, ":IPA:abc", &dom, &uuid);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive assert_int_equal(ret, EINVAL);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = split_ipa_anchor(test_ctx, ":IPA:abc:", &dom, &uuid);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_int_equal(ret, EINVAL);
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele
17efa6b5344b7574597eec03f02ef28103e19265nd ret = split_ipa_anchor(test_ctx, ":IPA:abc:def", &dom, &uuid);
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_int_equal(ret, EOK);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_string_equal(dom, "abc");
17efa6b5344b7574597eec03f02ef28103e19265nd assert_string_equal(uuid, "def");
1f666f93c91dbb492dc7706573b369cd03b84265poirier}
ef685e00a47967e27d89709461728a229d762172nd
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabelevoid test_sysdb_delete_view_tree(void **state)
6e89d4f6c259afc94f8806c74a33a8fe81392499sf{
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele int ret;
1f666f93c91dbb492dc7706573b369cd03b84265poirier struct ldb_message *msg;
17efa6b5344b7574597eec03f02ef28103e19265nd struct ldb_message **msgs = NULL;
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele struct sysdb_attrs *attrs;
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele size_t count;
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele struct ldb_dn *views_dn;
1f666f93c91dbb492dc7706573b369cd03b84265poirier
1f666f93c91dbb492dc7706573b369cd03b84265poirier struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele struct sysdb_test_ctx);
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele test_ctx->domain->mpg = false;
1f2a7403f1389cbf2da0a53a2b2fb425dea75506erikabele
17efa6b5344b7574597eec03f02ef28103e19265nd ret = sysdb_update_view_name(test_ctx->domain->sysdb, TEST_VIEW_NAME);
81622596373177e079337e956f7a5800895443b3erikabele assert_int_equal(ret, EOK);
81622596373177e079337e956f7a5800895443b3erikabele
8e34905974b7a442a55adac3b3fdb196c389e807takashi ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
81622596373177e079337e956f7a5800895443b3erikabele TEST_USER_UID, TEST_USER_GID, TEST_USER_GECOS,
ef685e00a47967e27d89709461728a229d762172nd TEST_USER_HOMEDIR, TEST_USER_SHELL, NULL, NULL, NULL,
ef685e00a47967e27d89709461728a229d762172nd 0,0);
ef685e00a47967e27d89709461728a229d762172nd assert_int_equal(ret, EOK);
81622596373177e079337e956f7a5800895443b3erikabele
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
81622596373177e079337e956f7a5800895443b3erikabele NULL, &msg);
81622596373177e079337e956f7a5800895443b3erikabele assert_int_equal(ret, EOK);
81622596373177e079337e956f7a5800895443b3erikabele assert_non_null(msg);
81622596373177e079337e956f7a5800895443b3erikabele
81622596373177e079337e956f7a5800895443b3erikabele attrs = sysdb_new_attrs(test_ctx);
81622596373177e079337e956f7a5800895443b3erikabele assert_non_null(attrs);
81622596373177e079337e956f7a5800895443b3erikabele
81622596373177e079337e956f7a5800895443b3erikabele ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
8e48ffd77ffe2edea5cae0dc77ae44df5e904fdfrbowen TEST_ANCHOR_PREFIX TEST_USER_SID);
81622596373177e079337e956f7a5800895443b3erikabele assert_int_equal(ret, EOK);
81622596373177e079337e956f7a5800895443b3erikabele
81622596373177e079337e956f7a5800895443b3erikabele ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
81622596373177e079337e956f7a5800895443b3erikabele SYSDB_MEMBER_USER, attrs, msg->dn);
81622596373177e079337e956f7a5800895443b3erikabele assert_int_equal(ret, EOK);
81622596373177e079337e956f7a5800895443b3erikabele
81622596373177e079337e956f7a5800895443b3erikabele views_dn = ldb_dn_new(test_ctx, test_ctx->domain->sysdb->ldb,
ef685e00a47967e27d89709461728a229d762172nd SYSDB_TMPL_VIEW_BASE);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_non_null(views_dn);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen LDB_SCOPE_SUBTREE, NULL, NULL, &count, &msgs);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_int_equal(ret, EOK);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_true(count > 1);
6e89d4f6c259afc94f8806c74a33a8fe81392499sf assert_non_null(msgs);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen ret = sysdb_delete_view_tree(test_ctx->domain->sysdb, TEST_VIEW_NAME);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_int_equal(ret, EOK);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen LDB_SCOPE_SUBTREE, NULL, NULL, &count, &msgs);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_int_equal(ret, EOK);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_int_equal(count, 1);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_true(ldb_dn_compare(views_dn, msgs[0]->dn) == 0);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen}
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowenvoid test_sysdb_invalidate_overrides(void **state)
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen{
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen int ret;
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen struct ldb_message *msg;
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele struct sysdb_attrs *attrs;
8e34905974b7a442a55adac3b3fdb196c389e807takashi struct ldb_dn *views_dn;
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele const char *user_attrs[] = { SYSDB_NAME,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele SYSDB_CACHE_EXPIRE,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele SYSDB_OVERRIDE_DN,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele NULL};
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele
6e89d4f6c259afc94f8806c74a33a8fe81392499sf struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele struct sysdb_test_ctx);
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele test_ctx->domain->mpg = false;
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele ret = sysdb_update_view_name(test_ctx->domain->sysdb, TEST_VIEW_NAME);
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele assert_int_equal(ret, EOK);
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele TEST_USER_UID, TEST_USER_GID, TEST_USER_GECOS,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele TEST_USER_HOMEDIR, TEST_USER_SHELL, NULL, NULL, NULL,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele 10,0);
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele assert_int_equal(ret, EOK);
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd NULL, &msg);
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_int_equal(ret, EOK);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd assert_non_null(msg);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd
8e34905974b7a442a55adac3b3fdb196c389e807takashi attrs = sysdb_new_attrs(test_ctx);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd assert_non_null(attrs);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd TEST_ANCHOR_PREFIX TEST_USER_SID);
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_int_equal(ret, EOK);
8e34905974b7a442a55adac3b3fdb196c389e807takashi
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd SYSDB_MEMBER_USER, attrs, msg->dn);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd assert_int_equal(ret, EOK);
8e34905974b7a442a55adac3b3fdb196c389e807takashi
8e34905974b7a442a55adac3b3fdb196c389e807takashi views_dn = ldb_dn_new(test_ctx, test_ctx->domain->sysdb->ldb,
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd SYSDB_TMPL_VIEW_BASE);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd assert_non_null(views_dn);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd ret = sysdb_delete_view_tree(test_ctx->domain->sysdb, TEST_VIEW_NAME);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd assert_int_equal(ret, EOK);
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd
17efa6b5344b7574597eec03f02ef28103e19265nd ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
8e34905974b7a442a55adac3b3fdb196c389e807takashi user_attrs, &msg);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_int_equal(ret, EOK);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_non_null(msg);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_true(ldb_msg_find_attr_as_uint64(msg, SYSDB_CACHE_EXPIRE, 0) > 1);
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki assert_non_null(ldb_msg_find_attr_as_string(msg, SYSDB_OVERRIDE_DN, NULL));
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = sysdb_invalidate_overrides(test_ctx->domain->sysdb);
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki assert_int_equal(ret, EOK);
17efa6b5344b7574597eec03f02ef28103e19265nd
17efa6b5344b7574597eec03f02ef28103e19265nd ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
17efa6b5344b7574597eec03f02ef28103e19265nd user_attrs, &msg);
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki assert_int_equal(ret, EOK);
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki assert_non_null(msg);
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki assert_int_equal(ldb_msg_find_attr_as_uint64(msg, SYSDB_CACHE_EXPIRE, 0),
17efa6b5344b7574597eec03f02ef28103e19265nd 1);
17efa6b5344b7574597eec03f02ef28103e19265nd assert_null(ldb_msg_find_attr_as_string(msg, SYSDB_OVERRIDE_DN, NULL));
17efa6b5344b7574597eec03f02ef28103e19265nd}
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshikiint main(int argc, const char *argv[])
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki{
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki int rv;
17efa6b5344b7574597eec03f02ef28103e19265nd int no_cleanup = 0;
e9e8e471353eaa5576e1e96530968d02f208e39fnd poptContext pc;
e9e8e471353eaa5576e1e96530968d02f208e39fnd int opt;
8e34905974b7a442a55adac3b3fdb196c389e807takashi struct poptOption long_options[] = {
e9e8e471353eaa5576e1e96530968d02f208e39fnd POPT_AUTOHELP
e9e8e471353eaa5576e1e96530968d02f208e39fnd SSSD_DEBUG_OPTS
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
e9e8e471353eaa5576e1e96530968d02f208e39fnd _("Do not delete the test database after a test run"), NULL },
e9e8e471353eaa5576e1e96530968d02f208e39fnd POPT_TABLEEND
6e89d4f6c259afc94f8806c74a33a8fe81392499sf };
e9e8e471353eaa5576e1e96530968d02f208e39fnd
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun const UnitTest tests[] = {
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun unit_test_setup_teardown(test_sysdb_add_overrides_to_object,
e9e8e471353eaa5576e1e96530968d02f208e39fnd test_sysdb_setup, test_sysdb_teardown),
e9e8e471353eaa5576e1e96530968d02f208e39fnd unit_test_setup_teardown(test_split_ipa_anchor,
e9e8e471353eaa5576e1e96530968d02f208e39fnd test_sysdb_setup, test_sysdb_teardown),
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun unit_test_setup_teardown(test_sysdb_delete_view_tree,
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun test_sysdb_setup, test_sysdb_teardown),
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun unit_test_setup_teardown(test_sysdb_invalidate_overrides,
e9e8e471353eaa5576e1e96530968d02f208e39fnd test_sysdb_setup, test_sysdb_teardown),
e9e8e471353eaa5576e1e96530968d02f208e39fnd };
e9e8e471353eaa5576e1e96530968d02f208e39fnd
e9e8e471353eaa5576e1e96530968d02f208e39fnd /* Set debug level to invalid value so we can deside if -d 0 was used. */
e9e8e471353eaa5576e1e96530968d02f208e39fnd debug_level = SSSDBG_INVALID;
pc = poptGetContext(argv[0], argc, argv, long_options, 0);
while((opt = poptGetNextOpt(pc)) != -1) {
switch(opt) {
default:
fprintf(stderr, "\nInvalid option %s: %s\n\n",
poptBadOption(pc, 0), poptStrerror(opt));
poptPrintUsage(pc, stderr, 0);
return 1;
}
}
poptFreeContext(pc);
DEBUG_CLI_INIT(debug_level);
tests_set_cwd();
test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_FILE, LOCAL_SYSDB_FILE);
test_dom_suite_setup(TESTS_PATH);
rv = run_tests(tests);
if (rv == 0 && no_cleanup == 0) {
test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_FILE, LOCAL_SYSDB_FILE);
}
return rv;
}