d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech Petr Čech <pcech@redhat.com>
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech Copyright (C) 2016 Red Hat
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech This program is free software; you can redistribute it and/or modify
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech it under the terms of the GNU General Public License as published by
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech the Free Software Foundation; either version 3 of the License, or
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech (at your option) any later version.
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech This program is distributed in the hope that it will be useful,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech but WITHOUT ANY WARRANTY; without even the implied warranty of
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech GNU General Public License for more details.
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech You should have received a copy of the GNU General Public License
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech along with this program. If not, see <http://www.gnu.org/licenses/>.
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech for (int i = 0; i < 2; i++) {
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sysdb_add_user(domain, users[i].name, users[i].uid, users[i].gid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech for (int i = 0; i < 2; i++) {
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = sysdb_add_group(domain, fqname, groups[i].gid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* register_cli_protocol_version is required in test since it links with
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstruct cli_protocol_version *register_cli_protocol_version(void)
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech static struct cli_protocol_version responder_test_cli_protocol_version[] = {
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_zero(global_talloc_context, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int set_user_in_ncache(struct sss_nc_ctx *ctx, bool permanent,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = sss_ncache_set_user(ctx, permanent, dom, fqdn);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int set_group_in_ncache(struct sss_nc_ctx *ctx, bool permanent,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = sss_ncache_set_group(ctx, permanent, dom, fqdn);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int check_user_in_ncache(struct sss_nc_ctx *ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek const char *name)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozekstatic int check_group_in_ncache(struct sss_nc_ctx *ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek const char *name)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek fqdn = sss_create_internal_fqname(ctx, name, dom->name);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* user utils */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void set_users(struct ncache_test_ctx *test_ctx)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = set_user_in_ncache(test_ctx->ncache, false, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = set_user_in_ncache(test_ctx->ncache, false, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void check_users(struct ncache_test_ctx *test_ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_user_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* user tests */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_users(test_ctx, ENOENT, ENOENT, ENOENT, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_users(test_ctx, ENOENT, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_users(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_users(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* uid utils */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void set_uids(struct ncache_test_ctx *test_ctx)
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_set_uid(test_ctx->ncache, false, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_set_uid(test_ctx->ncache, false, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void check_uids(struct ncache_test_ctx *test_ctx,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_uid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_uid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_uid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_uid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* uid tests */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_uids(test_ctx, ENOENT, ENOENT, ENOENT, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_uids(test_ctx, ENOENT, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_uids(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_uids(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* group utils */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void set_groups(struct ncache_test_ctx *test_ctx)
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = set_group_in_ncache(test_ctx->ncache, false, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = set_group_in_ncache(test_ctx->ncache, false, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void check_groups(struct ncache_test_ctx *test_ctx,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
27bf39ed3e197497cf4aca58038d788ea5b5ddbcJakub Hrozek ret = check_group_in_ncache(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* group tests */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_groups(test_ctx, ENOENT, ENOENT, ENOENT, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_groups(test_ctx, ENOENT, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_groups(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_groups(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* gid utils */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void set_gids(struct ncache_test_ctx *test_ctx)
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_set_gid(test_ctx->ncache, false, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_set_gid(test_ctx->ncache, false, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cechstatic void check_gids(struct ncache_test_ctx *test_ctx,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_gid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_gid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_gid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_check_gid(test_ctx->ncache, test_ctx->tctx->dom,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech/* uid tests */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_gids(test_ctx, ENOENT, ENOENT, ENOENT, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, 0, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_gids(test_ctx, ENOENT, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, 0, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_gids(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech test_ctx = talloc_get_type_abort(*state, struct ncache_test_ctx);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech ret = sss_ncache_init(test_ctx, TIMEOUT, TIMEOUT, &test_ctx->ncache);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech check_gids(test_ctx, EEXIST, ENOENT, EEXIST, ENOENT);
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_nocache_user,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_local_user,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_domain_user,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_both_user,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_nocache_uid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_local_uid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_domain_uid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_both_uid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_nocache_group,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_local_group,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_domain_group,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_both_group,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_nocache_gid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_local_gid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_domain_gid,
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech cmocka_unit_test_setup_teardown(test_ncache_both_gid,
49dd8ee2834d9477418961dbaffa4a03cfa9fd1eRené Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
d9e88bddc99bae0542b2179c9b94c968855b0fd0Petr Cech pc = poptGetContext(argv[0], argc, argv, long_options, 0);