test_sysdb_views.c revision 2fe140d3a41e1ac66400069d35adc9379348c1e5
640b2adac05bb7f5e9fba064434c91852c3a72e6nd sysdb_views - Tests for view and override related sysdb calls
640b2adac05bb7f5e9fba064434c91852c3a72e6nd Sumit Bose <sbose@redhat.com>
640b2adac05bb7f5e9fba064434c91852c3a72e6nd Copyright (C) 2014 Red Hat
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 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 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#include "db/sysdb_private.h" /* for sysdb->ldb member */
51853aa2ebfdf9903a094467e1d02099f143639daaron#define TEST_VIEW_CONTAINER "cn=" TEST_VIEW_NAME ",cn=views,cn=sysdb"
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slivestatic int _setup_sysdb_tests(struct sysdb_test_ctx **ctx, bool enumerate)
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive /* Create tests directory if it doesn't exist */
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive /* (relative to current dir) */
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive test_ctx = talloc_zero(global_talloc_context, struct sysdb_test_ctx);
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive /* Create an event context
6e89d4f6c259afc94f8806c74a33a8fe81392499sf * It will not be used except in confdb_init and sysdb_init
a27e9e05958bc51ea09edb8d8d862fe8b125313bslive conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_FILE);
17ca00f92106c825382359ebf0a754f8df21e316rbowen /* Connect to the conf db */
17ca00f92106c825382359ebf0a754f8df21e316rbowen ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
95e8cab14596a61826fa52477dcaebc07bfbad00colm#define setup_sysdb_tests(ctx) _setup_sysdb_tests((ctx), false)
95e8cab14596a61826fa52477dcaebc07bfbad00colm struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
17efa6b5344b7574597eec03f02ef28103e19265nd struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = ldb_msg_add_string(override, SYSDB_NAME, tmp_str);
8e34905974b7a442a55adac3b3fdb196c389e807takashi ret = ldb_msg_add_string(override, SYSDB_GECOS, tmp_str);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = ldb_msg_add_string(override, SYSDB_SSH_PUBKEY, tmp_str);
86bb9693d63dfc1be14519a5b444467e4b0cdaf8kawai ret = sysdb_add_overrides_to_object(test_ctx->domain, orig, override, NULL);
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 "OVERRIDENAME");
8e34905974b7a442a55adac3b3fdb196c389e807takashi assert_string_equal(ldb_msg_find_attr_as_string(orig,
b5468eddc0cb1691af19ddc70a6e205daf00a94ctrawick "OVERRIDEGECOS");
8e34905974b7a442a55adac3b3fdb196c389e807takashi el = ldb_msg_find_element(orig, OVERRIDE_PREFIX SYSDB_SSH_PUBKEY);
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);
17efa6b5344b7574597eec03f02ef28103e19265nd struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
17efa6b5344b7574597eec03f02ef28103e19265nd ret = split_ipa_anchor(test_ctx, "fwfkwjfkw", &dom, &uuid);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = split_ipa_anchor(test_ctx, ":IPA:", &dom, &uuid);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = split_ipa_anchor(test_ctx, ":IPA:abc", &dom, &uuid);
222f0f03c2f9ee6343c18f80f0cb6e9aad21bc58slive ret = split_ipa_anchor(test_ctx, ":IPA:abc:", &dom, &uuid);
17efa6b5344b7574597eec03f02ef28103e19265nd ret = split_ipa_anchor(test_ctx, ":IPA:abc:def", &dom, &uuid);
1f666f93c91dbb492dc7706573b369cd03b84265poirier struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
17efa6b5344b7574597eec03f02ef28103e19265nd ret = sysdb_update_view_name(test_ctx->domain->sysdb, TEST_VIEW_NAME);
8e34905974b7a442a55adac3b3fdb196c389e807takashi ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
81622596373177e079337e956f7a5800895443b3erikabele ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
81622596373177e079337e956f7a5800895443b3erikabele ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
81622596373177e079337e956f7a5800895443b3erikabele views_dn = ldb_dn_new(test_ctx, test_ctx->domain->sysdb->ldb,
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen ret = sysdb_delete_view_tree(test_ctx->domain->sysdb, TEST_VIEW_NAME);
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
e554dd2dae4ba2c32dbd05fc0d4e0a42ef4ba902rbowen assert_true(ldb_dn_compare(views_dn, msgs[0]->dn) == 0);
6e89d4f6c259afc94f8806c74a33a8fe81392499sf struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele ret = sysdb_update_view_name(test_ctx->domain->sysdb, TEST_VIEW_NAME);
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
f0eae6f6191f5730fa8db049f7391e93b4ff41b9erikabele TEST_USER_HOMEDIR, TEST_USER_SHELL, NULL, NULL, NULL,
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
8e34905974b7a442a55adac3b3fdb196c389e807takashi views_dn = ldb_dn_new(test_ctx, test_ctx->domain->sysdb->ldb,
f4166cb2bf5e48c1b0f18b0d1f6757fce82230a8nd ret = sysdb_delete_view_tree(test_ctx->domain->sysdb, TEST_VIEW_NAME);
17efa6b5344b7574597eec03f02ef28103e19265nd ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
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));
6e89d4f6c259afc94f8806c74a33a8fe81392499sf ret = sysdb_invalidate_overrides(test_ctx->domain->sysdb);
17efa6b5344b7574597eec03f02ef28103e19265nd ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
4a67c5c0053e1c1c2202122e46a42987f6fd28dfyoshiki assert_int_equal(ldb_msg_find_attr_as_uint64(msg, SYSDB_CACHE_EXPIRE, 0),
17efa6b5344b7574597eec03f02ef28103e19265nd assert_null(ldb_msg_find_attr_as_string(msg, SYSDB_OVERRIDE_DN, NULL));
e9e8e471353eaa5576e1e96530968d02f208e39fnd _("Do not delete the test database after a test run"), NULL },
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun unit_test_setup_teardown(test_sysdb_add_overrides_to_object,
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun unit_test_setup_teardown(test_sysdb_delete_view_tree,
1e1be8a0871405df3c1ec4d6d33aab71996ad0c9nilgun unit_test_setup_teardown(test_sysdb_invalidate_overrides,
e9e8e471353eaa5576e1e96530968d02f208e39fnd /* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
return rv;