939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose/*
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose Authors:
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose Sumit Bose <sbose@redhat.com>
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose Copyright (C) 2013 Red Hat
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose SSSD tests: Tests for utility functions
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose This program is free software; you can redistribute it and/or modify
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose it under the terms of the GNU General Public License as published by
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose the Free Software Foundation; either version 3 of the License, or
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose (at your option) any later version.
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose This program is distributed in the hope that it will be useful,
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose GNU General Public License for more details.
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose You should have received a copy of the GNU General Public License
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose*/
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose#define _GNU_SOURCE
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose#include <stdio.h>
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose#include <popt.h>
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose#include "tests/cmocka/common_mock.h"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#include "util/sss_nss.h"
462db32918a05097652f8232cd6c8d78a826e63cLukas Slebodnik#include "test_utils.h"
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
50c9d542e8bf641412debaa82a4dcf67ddb72258Lukas Slebodnik#define TESTS_PATH "tp_" BASE_FILE_STEM
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define TEST_CONF_DB "test_utils_conf.ldb"
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina#define TEST_DOM_NAME "utils_test.ldb"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose#define DOM_COUNT 10
f64296c40e07614668c4ac4c978bc8980fb6a7dbLukas Slebodnik#define DOMNAME_TMPL "name_%zu.dom"
f64296c40e07614668c4ac4c978bc8980fb6a7dbLukas Slebodnik#define FLATNAME_TMPL "name_%zu"
f64296c40e07614668c4ac4c978bc8980fb6a7dbLukas Slebodnik#define SID_TMPL "S-1-5-21-1-2-%zu"
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define MACRO_EXPAND(tok) #tok
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define STR(tok) MACRO_EXPAND(tok)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define USERNAME "sssduser"
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik#define FIRST_LETTER "s"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define UID 1234
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define DOMAIN "sssddomain"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define ORIGINAL_HOME "/home/user"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define FLATNAME "flatname"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define HOMEDIR_SUBSTR "/mnt/home"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define DUMMY "dummy"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik#define DUMMY2 "dummy2"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bosestruct dom_list_test_ctx {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose size_t dom_count;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct sss_domain_info *dom_list;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose};
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bosestatic int setup_dom_list_with_subdomains(void **state)
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose{
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose struct dom_list_test_ctx *test_ctx;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose struct sss_domain_info *dom = NULL;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose struct sss_domain_info *c = NULL;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_true(leak_check_setup());
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(test_ctx);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(dom);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->name = talloc_asprintf(dom, "configured.dom");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(dom->name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->realm = talloc_asprintf(dom, "CONFIGURED.DOM");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(dom->realm);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->flat_name = talloc_asprintf(dom, "CONFIGURED");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(dom->flat_name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->domain_id = talloc_asprintf(dom, "S-1-5-21-1-2-1");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(dom->domain_id);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose DLIST_ADD(test_ctx->dom_list, dom);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->name = talloc_asprintf(c, "subdom1.dom");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->realm = talloc_asprintf(c, "SUBDOM1.DOM");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->realm);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->flat_name = talloc_asprintf(c, "subdom1");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->flat_name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-2");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->domain_id);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->parent = dom;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->name = talloc_asprintf(c, "subdom2.dom");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->realm = talloc_asprintf(c, "SUBDOM2.DOM");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->realm);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->flat_name = talloc_asprintf(c, "subdom2");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->flat_name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-3");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->domain_id);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->parent = dom;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->name = talloc_asprintf(c, "subdom3.dom");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->realm = talloc_asprintf(c, "SUBDOM3.DOM");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->realm);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->flat_name = talloc_asprintf(c, "subdom3");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->flat_name);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-4");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->domain_id);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->parent = dom;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose check_leaks_push(test_ctx);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose *state = test_ctx;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose return 0;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose}
b5f61c9b3f5ea79bf319c18ff59394070c04d607Pavel Reichl
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int setup_dom_list(void **state)
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose{
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct sss_domain_info *dom = NULL;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose size_t c;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_true(leak_check_setup());
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose test_ctx->dom_count = DOM_COUNT;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose for (c = 0; c < test_ctx->dom_count; c++) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom = talloc_zero(test_ctx, struct sss_domain_info);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom->name = talloc_asprintf(dom, DOMNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom->name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom->flat_name = talloc_asprintf(dom, FLATNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom->flat_name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom->domain_id = talloc_asprintf(dom, SID_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom->domain_id);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose DLIST_ADD(test_ctx->dom_list, dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose check_leaks_push(test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose *state = test_ctx;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose}
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int teardown_dom_list(void **state)
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose{
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose if (test_ctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Type mismatch\n");
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 1;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_true(check_leaks_pop(test_ctx) == true);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose talloc_free(test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose}
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlvoid test_find_domain_by_name_null(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose{
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct sss_domain_info *dom;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(NULL, NULL, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, NULL, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(NULL, "test", false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose}
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlvoid test_find_domain_by_name(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose{
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct sss_domain_info *dom;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose size_t c;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *flat_name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *sid;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < test_ctx->dom_count; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, true);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose}
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlvoid test_find_domain_by_name_missing_flat_name(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose{
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct sss_domain_info *dom;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose size_t c;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *flat_name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *sid;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose size_t mis;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose mis = test_ctx->dom_count/2;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose dom = test_ctx->dom_list;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < mis; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose dom = dom->next;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose dom->flat_name = NULL;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < test_ctx->dom_count; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, true);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (c == mis - 1) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose } else {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (c == mis - 1) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose } else {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (c == mis - 1) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose } else {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose}
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlvoid test_find_domain_by_name_disabled(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose{
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct sss_domain_info *dom;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose size_t c;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *flat_name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *sid;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose size_t mis;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose mis = test_ctx->dom_count/2;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose dom = test_ctx->dom_list;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < mis; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose dom = dom->next;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek sss_domain_set_state(dom, DOM_DISABLED);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < test_ctx->dom_count; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, true);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (c == mis - 1) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose } else {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (c == mis - 1) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose } else {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (c == mis - 1) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose } else {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose}
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichlvoid test_find_domain_by_sid_null(void **state)
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose{
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct sss_domain_info *dom;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(NULL, NULL);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, NULL);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(NULL, "S-1-5-21-1-2-3");
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose}
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichlvoid test_find_domain_by_sid(void **state)
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose{
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct sss_domain_info *dom;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose size_t c;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose char *name;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose char *flat_name;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose char *sid;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose for (c = 0; c < test_ctx->dom_count; c++) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(flat_name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(sid);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, sid);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_string_equal(name, dom->name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_string_equal(flat_name, dom->flat_name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_string_equal(sid, dom->domain_id);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose talloc_free(name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose talloc_free(flat_name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose talloc_free(sid);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose}
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichlvoid test_find_domain_by_sid_missing_sid(void **state)
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose{
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct sss_domain_info *dom;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose size_t c;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose char *name;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose char *flat_name;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose char *sid;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose size_t mis;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose mis = test_ctx->dom_count/2;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom = test_ctx->dom_list;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose for (c = 0; c < mis; c++) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom = dom->next;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom->domain_id = NULL;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose for (c = 0; c < test_ctx->dom_count; c++) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(flat_name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(sid);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, sid);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose if (c == mis - 1) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose } else {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_non_null(dom);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_string_equal(name, dom->name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_string_equal(flat_name, dom->flat_name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_string_equal(sid, dom->domain_id);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose talloc_free(name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose talloc_free(flat_name);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose talloc_free(sid);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose}
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichlvoid test_find_domain_by_sid_disabled(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose{
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct sss_domain_info *dom;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose size_t c;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *flat_name;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose char *sid;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose size_t mis;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose mis = test_ctx->dom_count/2;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose dom = test_ctx->dom_list;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < mis; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose dom = dom->next;
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek sss_domain_set_state(dom, DOM_DISABLED);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < test_ctx->dom_count; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose if (c == mis - 1) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose } else {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_non_null(dom);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(name, dom->name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(flat_name, dom->flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_string_equal(sid, dom->domain_id);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(flat_name);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose talloc_free(sid);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose }
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose}
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek/*
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek * dom1 -> sub1a
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek * |
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek * dom2 -> sub2a -> sub2b
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek *
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek */
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozekstatic int setup_dom_tree(void **state)
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek{
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct sss_domain_info *head = NULL;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct sss_domain_info *dom = NULL;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_true(leak_check_setup());
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek dom = named_domain(test_ctx, "dom1", NULL);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek head = dom;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek dom = named_domain(test_ctx, "sub1a", head);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek head->subdomains = dom;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek dom = named_domain(test_ctx, "dom2", NULL);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek head->next = dom;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek dom = named_domain(test_ctx, "sub2a", head->next);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek head->next->subdomains = dom;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek dom = named_domain(test_ctx, "sub2b", head->next);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek head->next->subdomains->next = dom;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek test_ctx->dom_count = 2;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek test_ctx->dom_list = head;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek check_leaks_push(test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek *state = test_ctx;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek return 0;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek}
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozekstatic int teardown_dom_tree(void **state)
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek{
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek if (test_ctx == NULL) {
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Type mismatch\n");
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek return 1;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek }
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_true(check_leaks_pop(test_ctx));
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek talloc_free(test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_true(leak_check_teardown());
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek return 0;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek}
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozekstatic void test_get_next_domain(void **state)
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek{
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct sss_domain_info *dom = NULL;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(test_ctx->dom_list, 0);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_string_equal(dom->name, "dom2");
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, 0);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek}
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozekstatic void test_get_next_domain_descend(void **state)
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek{
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct sss_domain_info *dom = NULL;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(test_ctx->dom_list, SSS_GND_DESCEND);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_string_equal(dom->name, "sub1a");
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_string_equal(dom->name, "dom2");
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_string_equal(dom->name, "sub2a");
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_non_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_string_equal(dom->name, "sub2b");
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, 0);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek}
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozekstatic void test_get_next_domain_disabled(void **state)
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek{
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct sss_domain_info *dom = NULL;
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek for (dom = test_ctx->dom_list; dom;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, SSS_GND_DESCEND)) {
b5825c74b6bf7a99ae2172392dbecb51179013a6Jakub Hrozek sss_domain_set_state(dom, DOM_DISABLED);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek }
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(test_ctx->dom_list, SSS_GND_DESCEND);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek assert_null(dom);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek}
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židekstatic void test_get_next_domain_flags(void **state)
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek{
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek struct dom_list_test_ctx);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek struct sss_domain_info *dom = NULL;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek uint32_t gnd_flags;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* No flags; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = 0;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "dom2");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend flag only; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_DESCEND;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub1a");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "dom2");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub2a");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub2b");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* Incl. disabled flag only; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_INCLUDE_DISABLED;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "dom2");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend and include disabled; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_DESCEND | SSS_GND_INCLUDE_DISABLED;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub1a");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "dom2");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub2a");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub2b");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* Now disable dom2 and sub2a */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = find_domain_by_name(test_ctx->dom_list, "dom2", false);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek sss_domain_set_state(dom, DOM_DISABLED);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = find_domain_by_name(test_ctx->dom_list, "sub2a", false);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek sss_domain_set_state(dom, DOM_DISABLED);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* No flags; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = 0;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend flag only; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_DESCEND;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub1a");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub2b");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* Incl. disabled flag only; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_INCLUDE_DISABLED;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "dom2");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend and include disabled; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_DESCEND | SSS_GND_INCLUDE_DISABLED;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub1a");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "dom2");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub2a");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_non_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_string_equal(dom->name, "sub2b");
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(dom, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek assert_null(dom);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek}
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek
45ba1e10beddf082c061e0a2950340596817861aSumit Bosestruct name_init_test_ctx {
45ba1e10beddf082c061e0a2950340596817861aSumit Bose struct confdb_ctx *confdb;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose};
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define GLOBAL_FULL_NAME_FORMAT "%1$s@%2$s"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define GLOBAL_RE_EXPRESSION "(?P<name>[^@]+)@?(?P<domain>[^@]*$)"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define TEST_DOMAIN_NAME "test.dom"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define DOMAIN_FULL_NAME_FORMAT "%3$s\\%1$s"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define DOMAIN_RE_EXPRESSION "(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
45ba1e10beddf082c061e0a2950340596817861aSumit Bose "((?P<name>[^@]+)@(?P<domain>.+$))|" \
45ba1e10beddf082c061e0a2950340596817861aSumit Bose "(^(?P<name>[^@\\\\]+)$))"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int confdb_test_setup(void **state)
45ba1e10beddf082c061e0a2950340596817861aSumit Bose{
45ba1e10beddf082c061e0a2950340596817861aSumit Bose struct name_init_test_ctx *test_ctx;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose char *conf_db = NULL;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose char *dompath = NULL;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose int ret;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose const char *val[2];
45ba1e10beddf082c061e0a2950340596817861aSumit Bose val[1] = NULL;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_true(leak_check_setup());
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose test_ctx = talloc_zero(global_talloc_context, struct name_init_test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_non_null(test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_DB);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_non_null(conf_db);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose talloc_free(conf_db);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose val[0] = TEST_DOMAIN_NAME;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_add_param(test_ctx->confdb, true,
45ba1e10beddf082c061e0a2950340596817861aSumit Bose "config/sssd", "domains", val);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose val[0] = GLOBAL_FULL_NAME_FORMAT;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_add_param(test_ctx->confdb, true,
45ba1e10beddf082c061e0a2950340596817861aSumit Bose "config/sssd", "full_name_format", val);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose val[0] = GLOBAL_RE_EXPRESSION;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_add_param(test_ctx->confdb, true,
45ba1e10beddf082c061e0a2950340596817861aSumit Bose "config/sssd", "re_expression", val);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose dompath = talloc_asprintf(test_ctx, "config/domain/%s", TEST_DOMAIN_NAME);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_non_null(dompath);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose val[0] = "ldap";
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_add_param(test_ctx->confdb, true,
45ba1e10beddf082c061e0a2950340596817861aSumit Bose dompath, "id_provider", val);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose val[0] = DOMAIN_FULL_NAME_FORMAT;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_add_param(test_ctx->confdb, true,
45ba1e10beddf082c061e0a2950340596817861aSumit Bose dompath, "full_name_format", val);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose val[0] = DOMAIN_RE_EXPRESSION;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_add_param(test_ctx->confdb, true,
45ba1e10beddf082c061e0a2950340596817861aSumit Bose dompath, "re_expression", val);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose talloc_free(dompath);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose check_leaks_push(test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose *state = test_ctx;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose}
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int confdb_test_teardown(void **state)
45ba1e10beddf082c061e0a2950340596817861aSumit Bose{
45ba1e10beddf082c061e0a2950340596817861aSumit Bose struct name_init_test_ctx *test_ctx;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose test_ctx = talloc_get_type(*state, struct name_init_test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_true(check_leaks_pop(test_ctx) == true);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose talloc_free(test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose}
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bosevoid test_sss_names_init(void **state)
45ba1e10beddf082c061e0a2950340596817861aSumit Bose{
45ba1e10beddf082c061e0a2950340596817861aSumit Bose struct name_init_test_ctx *test_ctx;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose struct sss_names_ctx *names_ctx;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose int ret;
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose test_ctx = talloc_get_type(*state, struct name_init_test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = sss_names_init(test_ctx, test_ctx->confdb, NULL, &names_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_non_null(names_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_string_equal(names_ctx->re_pattern, GLOBAL_RE_EXPRESSION);
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Walter assert_string_equal(names_ctx->fq_fmt, GLOBAL_FULL_NAME_FORMAT);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose talloc_free(names_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = sss_names_init(test_ctx, test_ctx->confdb, TEST_DOMAIN_NAME,
45ba1e10beddf082c061e0a2950340596817861aSumit Bose &names_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_int_equal(ret, EOK);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_non_null(names_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose assert_string_equal(names_ctx->re_pattern, DOMAIN_RE_EXPRESSION);
c86904baad32fbf9e66bf1cdc667aa5e683b48baStef Walter assert_string_equal(names_ctx->fq_fmt, DOMAIN_FULL_NAME_FORMAT);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
45ba1e10beddf082c061e0a2950340596817861aSumit Bose talloc_free(names_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose}
45ba1e10beddf082c061e0a2950340596817861aSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bosevoid test_well_known_sid_to_name(void **state)
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose{
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose int ret;
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose const char *name;
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose const char *dom;
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name(NULL, NULL, NULL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("abc", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0-0", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EOK);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(dom, "NULL AUTHORITY");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(name, "NULL SID");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0-0-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-6", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EOK);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(dom, "NT AUTHORITY");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(name, "SERVICE");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-6-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-21", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-21-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, ENOENT);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-21-abc", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, ENOENT);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32-551", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EOK);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(dom, "BUILTIN");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(name, "Backup Operators");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32-551-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose}
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bosevoid test_name_to_well_known_sid(void **state)
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose{
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose int ret;
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose const char *sid;
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid(NULL, NULL, NULL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("abc", "def", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, ENOENT);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("", "def", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, ENOENT);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("BUILTIN", "def", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("NT AUTHORITY", "def", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("LOCAL AUTHORITY", "LOCAL", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EOK);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(sid, "S-1-2-0");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid(NULL, "LOCAL", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EINVAL);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("BUILTIN", "Cryptographic Operators", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EOK);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(sid, "S-1-5-32-569");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("NT AUTHORITY", "DIALUP", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_int_equal(ret, EOK);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose assert_string_equal(sid, "S-1-5-1");
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose}
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose#define TEST_SANITIZE_INPUT "TestUser@Test.Domain"
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose#define TEST_SANITIZE_LC_INPUT "testuser@test.domain"
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bosevoid test_sss_filter_sanitize_for_dom(void **state)
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose{
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose struct dom_list_test_ctx *test_ctx;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose int ret;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose char *sanitized;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose char *lc_sanitized;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose struct sss_domain_info *dom;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose test_ctx = talloc_get_type(*state, struct dom_list_test_ctx);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose dom = test_ctx->dom_list;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose dom->case_sensitive = true;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose ret = sss_filter_sanitize_for_dom(test_ctx, TEST_SANITIZE_INPUT, dom,
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose &sanitized, &lc_sanitized);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_int_equal(ret, EOK);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(sanitized, TEST_SANITIZE_INPUT);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(lc_sanitized, TEST_SANITIZE_INPUT);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose talloc_free(sanitized);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose talloc_free(lc_sanitized);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose dom->case_sensitive = false;
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose ret = sss_filter_sanitize_for_dom(test_ctx, TEST_SANITIZE_INPUT, dom,
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose &sanitized, &lc_sanitized);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_int_equal(ret, EOK);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(sanitized, TEST_SANITIZE_INPUT);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(lc_sanitized, TEST_SANITIZE_LC_INPUT);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose talloc_free(sanitized);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose talloc_free(lc_sanitized);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose}
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnikvoid check_expanded_value(TALLOC_CTX *tmp_ctx,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx *homedir_ctx,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik const char *template, const char *exp_val)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik{
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik char *homedir;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir = expand_homedir_template(tmp_ctx, template, false, homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik if (exp_val != NULL) {
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_string_equal(homedir, exp_val);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik } else {
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_null(homedir);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik }
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik talloc_free(homedir);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik}
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int setup_homedir_ctx(void **state)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik{
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx *homedir_ctx;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_true(leak_check_setup());
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx= talloc_zero(global_talloc_context,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_non_null(homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir_ctx->username = sss_create_internal_fqname(homedir_ctx,
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek USERNAME, DOMAIN);
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek if (homedir_ctx->username == NULL) {
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek talloc_free(homedir_ctx);
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek return 1;
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek }
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->uid = UID;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->original = ORIGINAL_HOME;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->domain = DOMAIN;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->flatname = FLATNAME;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->config_homedir_substr = HOMEDIR_SUBSTR;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_leaks_push(homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik *state = homedir_ctx;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik}
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int teardown_homedir_ctx(void **state)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik{
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx *homedir_ctx = talloc_get_type(*state,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik if (homedir_ctx == NULL) {
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DEBUG(SSSDBG_CRIT_FAILURE, "Type mismatch\n");
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 1;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik }
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_true(check_leaks_pop(homedir_ctx) == true);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik talloc_free(homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik}
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnikvoid test_expand_homedir_template_NULL(void **state)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik{
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik TALLOC_CTX *tmp_ctx;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik char *homedir;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx *homedir_ctx;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* following format strings requires data in homedir_ctx */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik const char *format_strings[] = { "%u", "%U", "%d", "%f", "%F", "%H",
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik NULL };
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik int i;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik tmp_ctx = talloc_new(NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_non_null(tmp_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx = talloc_zero(tmp_ctx, struct sss_nss_homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_non_null(homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir = expand_homedir_template(tmp_ctx, NULL, false, NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_null(homedir);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir = expand_homedir_template(tmp_ctx, "template", false, NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_null(homedir);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* missing data in homedir_ctx */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%%", "%");
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%o", "");
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik for (i = 0; format_strings[i] != NULL; ++i) {
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, format_strings[i], NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik }
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* flatname requires domain and username */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->username = DUMMY;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%f", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->username = NULL;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->domain = DUMMY;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%f", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* test unknown format string */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%x", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* test malformed format string */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik talloc_free(tmp_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik}
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnikvoid test_expand_homedir_template(void **state)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik{
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx *homedir_ctx = talloc_get_type(*state,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik TALLOC_CTX *tmp_ctx;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik tmp_ctx = talloc_new(NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_non_null(tmp_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* string without template */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY, DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%u", USERNAME);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%u", DUMMY USERNAME);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%u"DUMMY, USERNAME DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%u"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY USERNAME DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%U", STR(UID));
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%U", DUMMY STR(UID));
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%U"DUMMY, STR(UID) DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%U"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY STR(UID) DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%d", DOMAIN);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%d", DUMMY DOMAIN);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%d"DUMMY, DOMAIN DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%d"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY DOMAIN DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%f", USERNAME"@"DOMAIN);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%f",
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY USERNAME"@"DOMAIN);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%f"DUMMY,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik USERNAME"@"DOMAIN DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%f"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY USERNAME"@"DOMAIN DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%o", ORIGINAL_HOME);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%o", DUMMY ORIGINAL_HOME);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%o"DUMMY, ORIGINAL_HOME DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%o"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY ORIGINAL_HOME DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%F", FLATNAME);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%F", DUMMY FLATNAME);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%F"DUMMY, FLATNAME DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%F"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY FLATNAME DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%H", HOMEDIR_SUBSTR);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%H",
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY HOMEDIR_SUBSTR);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%H"DUMMY,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik HOMEDIR_SUBSTR DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%H"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY HOMEDIR_SUBSTR DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%%", "%");
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%%", DUMMY"%");
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%%"DUMMY, "%"DUMMY);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%%"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY"%"DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%l", FIRST_LETTER);
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%l", DUMMY FIRST_LETTER);
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%l"DUMMY, FIRST_LETTER DUMMY);
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%l"DUMMY2,
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik DUMMY FIRST_LETTER DUMMY2);
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* test all format strings */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx,
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik DUMMY"/%u/%U/%d/%f/%o/%F/%%/%H/%l/"DUMMY2,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DUMMY"/"USERNAME"/" STR(UID) "/"DOMAIN"/"
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik USERNAME"@"DOMAIN"/"ORIGINAL_HOME"/"FLATNAME"/%/"
f8d34835b4b97cff751677e911f26eae6a6d7381Lukas Slebodnik HOMEDIR_SUBSTR"/"FIRST_LETTER"/"DUMMY2);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik talloc_free(tmp_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik}
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic int setup_leak_tests(void **state)
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose{
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_true(leak_check_setup());
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose}
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic int teardown_leak_tests(void **state)
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose{
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose}
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bosevoid test_add_strings_lists(void **state)
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose{
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose const char *l1[] = {"a", "b", "c", NULL};
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose const char *l2[] = {"1", "2", "3", NULL};
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose char **res;
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose int ret;
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose size_t c;
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose size_t d;
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, NULL, NULL, true, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[0]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, NULL, NULL, false, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[0]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, l1, NULL, false, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (c = 0; l1[c] != NULL; c++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose /* 'copy_strings' is 'false', pointers must be equal */
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(memcmp(&l1[c], &res[c], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[c]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, l1, NULL, true, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (c = 0; l1[c] != NULL; c++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose /* 'copy_strings' is 'true', pointers must be different, but strings
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose * must be equal */
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_not_equal(memcmp(&l1[c], &res[c], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_string_equal(l1[c], res[c]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[c]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, NULL, l1, false, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (c = 0; l1[c] != NULL; c++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose /* 'copy_strings' is 'false', pointers must be equal */
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(memcmp(&l1[c], &res[c], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[c]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, NULL, l1, true, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (c = 0; l1[c] != NULL; c++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose /* 'copy_strings' is 'true', pointers must be different, but strings
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose * must be equal */
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_not_equal(memcmp(&l1[c], &res[c], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_string_equal(l1[c], res[c]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[c]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, l1, l2, false, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (c = 0; l1[c] != NULL; c++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose /* 'copy_strings' is 'false', pointers must be equal */
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(memcmp(&l1[c], &res[c], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (d = 0; l2[d] != NULL; d++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(memcmp(&l2[d], &res[c+d], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[c+d]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, l1, l2, true, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_equal(ret, EOK);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_non_null(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (c = 0; l1[c] != NULL; c++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose /* 'copy_strings' is 'true', pointers must be different, but strings
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose * must be equal */
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_not_equal(memcmp(&l1[c], &res[c], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_string_equal(l1[c], res[c]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose for (d = 0; l2[d] != NULL; d++) {
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_int_not_equal(memcmp(&l2[d], &res[c+d], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_string_equal(l2[d], res[c+d]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose }
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose assert_null(res[c+d]);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose talloc_free(res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose}
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bosevoid test_sss_write_krb5_conf_snippet(void **state)
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose{
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose int ret;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose char buf[PATH_MAX];
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose char *cwd;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose char *path;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose char *file;
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik char *file_krb5_libdefaults;
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet(NULL, false, false);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_int_equal(ret, EINVAL);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet("abc", false, false);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_int_equal(ret, EINVAL);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet("", false, false);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_int_equal(ret, EOK);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet("none", false, false);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_int_equal(ret, EOK);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose cwd = getcwd(buf, PATH_MAX);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_non_null(cwd);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = asprintf(&path, "%s/%s", cwd, TESTS_PATH);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_true(ret > 0);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = asprintf(&file, "%s/%s/localauth_plugin", cwd, TESTS_PATH);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_true(ret > 0);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik ret = asprintf(&file_krb5_libdefaults,
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik "%s/%s/krb5_libdefaults", cwd, TESTS_PATH);
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik assert_true(ret > 0);
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet(path, true, true);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_int_equal(ret, EOK);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose /* Check if writing a second time will work as well */
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet(path, true, true);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_int_equal(ret, EOK);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose#ifdef HAVE_KRB5_LOCALAUTH_PLUGIN
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = unlink(file);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose assert_int_equal(ret, EOK);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose#endif
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik ret = unlink(file_krb5_libdefaults);
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik assert_int_equal(ret, EOK);
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose free(file);
059904af2d20debcb8ffe1c6f45b996c2c57574eLukas Slebodnik free(file_krb5_libdefaults);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose free(path);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose}
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose
dd5ebcde05442422f39084acb49b28cf47002d1eSumit Bose
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstruct unique_file_test_ctx {
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek char *filename;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek};
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic int unique_file_test_setup(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct unique_file_test_ctx *test_ctx;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_true(leak_check_setup());
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_non_null(test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx->filename = talloc_strdup(test_ctx, "test_unique_file_XXXXXX");
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_non_null(test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek *state = test_ctx;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek return 0;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic int unique_file_test_teardown(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct unique_file_test_ctx *test_ctx;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek errno_t ret;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek errno = 0;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = unlink(test_ctx->filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek if (ret != 0 && errno != ENOENT) {
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek fail();
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek }
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek talloc_free(test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_true(leak_check_teardown());
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek return 0;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void assert_destructor(TALLOC_CTX *owner,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct unique_file_test_ctx *test_ctx)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek int fd;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek errno_t ret;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek char *check_filename;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek /* Test that the destructor works */
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek if (owner == NULL) {
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek return;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek }
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek check_filename = talloc_strdup(test_ctx, test_ctx->filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_non_null(check_filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek talloc_free(owner);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = check_and_open_readonly(test_ctx->filename, &fd,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek geteuid(), getegid(),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek (S_IRUSR | S_IWUSR | S_IFREG), 0);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek close(fd);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_not_equal(ret, EOK);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void sss_unique_file_test(struct unique_file_test_ctx *test_ctx,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek bool test_destructor)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek int fd;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek errno_t ret;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct stat sb;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek TALLOC_CTX *owner = NULL;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek if (test_destructor) {
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek owner = talloc_new(test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_non_null(owner);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek }
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek fd = sss_unique_file(owner, test_ctx->filename, &ret);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_not_equal(fd, -1);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_equal(ret, EOK);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = check_fd(fd, geteuid(), getegid(),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek (S_IRUSR | S_IWUSR | S_IFREG), 0, &sb);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek close(fd);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_equal(ret, EOK);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_destructor(owner, test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_file(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct unique_file_test_ctx *test_ctx;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek sss_unique_file_test(test_ctx, false);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_file_destruct(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct unique_file_test_ctx *test_ctx;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek sss_unique_file_test(test_ctx, true);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_file_neg(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek int fd;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek errno_t ret;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek fd = sss_unique_file(NULL, discard_const("badpattern"), &ret);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_equal(fd, -1);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_equal(ret, EINVAL);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void sss_unique_filename_test(struct unique_file_test_ctx *test_ctx,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek bool test_destructor)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek int fd;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek errno_t ret;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek char *tmp_filename;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek TALLOC_CTX *owner = NULL;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek tmp_filename = talloc_strdup(test_ctx, test_ctx->filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_non_null(tmp_filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek if (test_destructor) {
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek owner = talloc_new(test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_non_null(owner);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek }
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = sss_unique_filename(owner, test_ctx->filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_equal(ret, EOK);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_equal(strncmp(test_ctx->filename,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek tmp_filename,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek strlen(tmp_filename) - sizeof("XXXXXX")),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek 0);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = check_and_open_readonly(test_ctx->filename, &fd,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek geteuid(), getegid(),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek (S_IRUSR | S_IWUSR | S_IFREG), 0);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek close(fd);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_int_equal(ret, EOK);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek assert_destructor(owner, test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_filename(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct unique_file_test_ctx *test_ctx;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek sss_unique_filename_test(test_ctx, false);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_filename_destruct(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek{
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek struct unique_file_test_ctx *test_ctx;
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek sss_unique_filename_test(test_ctx, true);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek}
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bosestatic void test_parse_cert_verify_opts(void **state)
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose{
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose int ret;
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose struct cert_verify_opts *cv_opts;
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, NULL, &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EOK);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_verification);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_ocsp);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose talloc_free(cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, "wedfkwefjk", &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EOK);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_verification);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_ocsp);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose talloc_free(cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, "no_ocsp", &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EOK);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_verification);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_false(cv_opts->do_ocsp);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose talloc_free(cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, "no_verification",
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EOK);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_false(cv_opts->do_verification);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_ocsp);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose talloc_free(cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "no_ocsp,no_verification", &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EOK);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_false(cv_opts->do_verification);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_false(cv_opts->do_ocsp);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose talloc_free(cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder=", &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EINVAL);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder_signing_cert=",
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EINVAL);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder=abc", &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EINVAL);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder_signing_cert=def",
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EINVAL);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder=abc,"
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder_signing_cert=def",
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_int_equal(ret, EOK);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_verification);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_true(cv_opts->do_ocsp);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_string_equal(cv_opts->ocsp_default_responder, "abc");
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_string_equal(cv_opts->ocsp_default_responder_signing_cert, "def");
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose talloc_free(cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose}
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic void assert_parse_fqname(const char *fqname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek const char *exp_shortname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek const char *exp_domname)
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek{
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek errno_t ret;
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek char *shortname = NULL;
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek char *domname = NULL;
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek check_leaks_push(global_talloc_context);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek ret = sss_parse_internal_fqname(global_talloc_context, fqname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek exp_shortname ? &shortname : NULL,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek exp_domname ? &domname : NULL);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_int_equal(ret, EOK);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek if (exp_shortname) {
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_string_equal(shortname, exp_shortname);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek }
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek if (exp_domname) {
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_string_equal(domname, exp_domname);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek }
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek talloc_free(shortname);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek talloc_free(domname);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek}
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic void assert_fqname_unparseable(const char *fqname, errno_t retval)
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek{
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek errno_t ret;
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek char *shortname = NULL;
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek char *domname = NULL;
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek check_leaks_push(global_talloc_context);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek ret = sss_parse_internal_fqname(global_talloc_context, fqname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek &shortname, &domname);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_int_equal(ret, retval);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_null(shortname);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_null(domname);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek}
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic void test_sss_parse_internal_fqname(void **state)
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek{
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_parse_fqname("foo@bar", "foo", "bar");
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_parse_fqname("foo@bar", NULL, "bar");
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_parse_fqname("foo@bar", "foo", NULL);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_parse_fqname("foo@bar", NULL, NULL);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_parse_fqname("foo@bar@baz", "foo@bar", "baz");
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_fqname_unparseable("foo", ERR_WRONG_NAME_FORMAT);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_fqname_unparseable("foo@", ERR_WRONG_NAME_FORMAT);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_fqname_unparseable("@", ERR_WRONG_NAME_FORMAT);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_fqname_unparseable("@bar", ERR_WRONG_NAME_FORMAT);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_fqname_unparseable(NULL, EINVAL);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek}
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozekstatic void test_sss_create_internal_fqname(void **state)
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek{
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek char *fqname = NULL;
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek check_leaks_push(global_talloc_context);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, "foo", "bar");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek assert_string_equal(fqname, "foo@bar");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek talloc_zfree(fqname);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, "foo", "BAR");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek assert_string_equal(fqname, "foo@bar");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek talloc_zfree(fqname);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, "foo", NULL);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek assert_null(fqname);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, NULL, "bar");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek assert_null(fqname);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, NULL, NULL);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek assert_null(fqname);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek}
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozekstatic void test_sss_create_internal_fqname_list(void **state)
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek{
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek char **fqlist = NULL;
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek const char *in_list1[] = { "aaa", "bbb", NULL };
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek check_leaks_push(global_talloc_context);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek in_list1, "DOM");
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_string_equal(fqlist[0], "aaa@dom");
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_string_equal(fqlist[1], "bbb@dom");
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_null(fqlist[2]);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek talloc_zfree(fqlist);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek in_list1, NULL);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_null(fqlist);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek NULL, "DOM");
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_null(fqlist);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek NULL, NULL);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_null(fqlist);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek}
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozekstatic void test_sss_output_name(void **state)
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek{
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek char *outname;
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek char *fqname;
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek check_leaks_push(global_talloc_context);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context,
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek "Foo Bar", "DOM");
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_non_null(fqname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek outname = sss_output_name(global_talloc_context, fqname, true, 0);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_non_null(outname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_string_equal(outname, "Foo Bar");
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek talloc_zfree(outname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek outname = sss_output_name(global_talloc_context, fqname, false, 0);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_non_null(outname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_string_equal(outname, "foo bar");
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek talloc_zfree(outname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek outname = sss_output_name(global_talloc_context, fqname, false, '-');
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_non_null(outname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_string_equal(outname, "foo-bar");
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek talloc_zfree(outname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek talloc_free(fqname);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek}
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bosestatic void test_sss_get_domain_mappings_content(void **state)
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose{
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose struct dom_list_test_ctx *test_ctx;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose int ret;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose struct sss_domain_info *dom;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose char *content;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose struct sss_domain_info *c;
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ret = sss_get_domain_mappings_content(NULL, NULL, NULL);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_int_equal(ret, EINVAL);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose test_ctx = talloc_get_type(*state, struct dom_list_test_ctx);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(test_ctx);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom = get_domains_head(test_ctx->dom_list);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(dom);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose /* no forest */
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ret = sss_get_domain_mappings_content(test_ctx, dom, &content);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_int_equal(ret, EOK);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_string_equal(content,
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "[domain_realm]\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ".subdom1.dom = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "subdom1.dom = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ".subdom2.dom = SUBDOM2.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "subdom2.dom = SUBDOM2.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ".subdom3.dom = SUBDOM3.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "subdom3.dom = SUBDOM3.DOM\n");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose talloc_free(content);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose /* IPA with forest */
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = find_domain_by_name(dom, "subdom2.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->forest_root);
19bb5bfc2821c5644e10614c5730ca5c180c2856Petr Cech c->forest = discard_const_p(char, "subdom1.dom");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = find_domain_by_name(dom, "subdom3.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_non_null(c->forest_root);
19bb5bfc2821c5644e10614c5730ca5c180c2856Petr Cech c->forest = discard_const_p(char, "subdom1.dom");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ret = sss_get_domain_mappings_content(test_ctx, dom, &content);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_int_equal(ret, EOK);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose assert_string_equal(content,
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "[domain_realm]\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ".subdom1.dom = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "subdom1.dom = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ".subdom2.dom = SUBDOM2.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "subdom2.dom = SUBDOM2.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ".subdom3.dom = SUBDOM3.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "subdom3.dom = SUBDOM3.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "[capaths]\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "SUBDOM2.DOM = {\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose " CONFIGURED.DOM = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "}\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "SUBDOM3.DOM = {\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose " CONFIGURED.DOM = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "}\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "CONFIGURED.DOM = {\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose " SUBDOM2.DOM = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose " SUBDOM3.DOM = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "}\n");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose talloc_free(content);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose /* Next steps, test AD domain setup. If we join a child domain we have a
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose * similar case as with IPA but if we join the forest root the generate
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose * capaths might not be as expected. */
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose}
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bosestatic void test_is_email_from_domain(void **state)
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose{
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose struct dom_list_test_ctx);
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose struct sss_domain_info *d;
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose d = find_domain_by_name(test_ctx->dom_list, "name_0.dom", false);
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_non_null(d);
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_false(is_email_from_domain(NULL, NULL));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_false(is_email_from_domain("hello", NULL));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_false(is_email_from_domain(NULL, d));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_false(is_email_from_domain("hello", d));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_false(is_email_from_domain("hello@hello", d));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_true(is_email_from_domain("hello@name_0.dom", d));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_true(is_email_from_domain("hello@NaMe_0.DoM", d));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose}
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Boseint main(int argc, const char *argv[])
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose{
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose poptContext pc;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose int opt;
3e64f9f6c551dc25327d4ff552757304da3066ebLukas Slebodnik int rv;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct poptOption long_options[] = {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose POPT_AUTOHELP
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose SSSD_DEBUG_OPTS
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose POPT_TABLEEND
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose };
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid_missing_sid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid_disabled,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name_missing_flat_name,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name_disabled,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list, teardown_dom_list),
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose cmocka_unit_test_setup_teardown(test_is_email_from_domain,
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose setup_dom_list, teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_names_init,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek confdb_test_setup,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek confdb_test_teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek cmocka_unit_test_setup_teardown(test_get_next_domain,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek setup_dom_tree, teardown_dom_tree),
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek cmocka_unit_test_setup_teardown(test_get_next_domain_descend,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek setup_dom_tree, teardown_dom_tree),
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek cmocka_unit_test_setup_teardown(test_get_next_domain_disabled,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek setup_dom_tree, teardown_dom_tree),
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek cmocka_unit_test_setup_teardown(test_get_next_domain_flags,
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek setup_dom_tree, teardown_dom_tree),
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_well_known_sid_to_name),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_name_to_well_known_sid),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_filter_sanitize_for_dom,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_dom_list,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek teardown_dom_list),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_expand_homedir_template_NULL),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_expand_homedir_template,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup_homedir_ctx,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek teardown_homedir_ctx),
d82ffa52dd4c3bb11115b1687edc189284797329Lukas Slebodnik#ifdef BUILD_SSH
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_textual_public_key),
d82ffa52dd4c3bb11115b1687edc189284797329Lukas Slebodnik#endif
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_replace_whitespaces),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_reverse_replace_whitespaces),
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose cmocka_unit_test(test_guid_blob_to_string_buf),
a99845006f96f9d1e7af871ec67c71cee8408a62Sumit Bose cmocka_unit_test(test_get_last_x_chars),
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose cmocka_unit_test(test_concatenate_string_array),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_add_strings_lists,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek setup_leak_tests,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek teardown_leak_tests),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_sss_write_krb5_conf_snippet),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_file,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_setup,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_teardown),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_file_destruct,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_setup,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_teardown),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test(test_sss_unique_file_neg),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_filename,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_setup,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_teardown),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_filename_destruct,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_setup,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek unique_file_test_teardown),
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose cmocka_unit_test_setup_teardown(test_parse_cert_verify_opts,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek setup_leak_tests,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek teardown_leak_tests),
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_parse_internal_fqname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek setup_leak_tests,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek teardown_leak_tests),
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_create_internal_fqname,
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek setup_leak_tests,
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek teardown_leak_tests),
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_create_internal_fqname_list,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek setup_leak_tests,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek teardown_leak_tests),
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_output_name,
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek setup_leak_tests,
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek teardown_leak_tests),
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose cmocka_unit_test_setup_teardown(test_sss_get_domain_mappings_content,
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose setup_dom_list_with_subdomains,
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose teardown_dom_list),
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose };
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose debug_level = SSSDBG_INVALID;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose switch(opt) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose default:
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose poptPrintUsage(pc, stderr, 0);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose return 1;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose }
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose poptFreeContext(pc);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug_level);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose /* 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 */
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose tests_set_cwd();
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose test_dom_suite_setup(TESTS_PATH);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
3e64f9f6c551dc25327d4ff552757304da3066ebLukas Slebodnik if (rv == 0) {
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
3e64f9f6c551dc25327d4ff552757304da3066ebLukas Slebodnik }
3e64f9f6c551dc25327d4ff552757304da3066ebLukas Slebodnik return rv;
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose}