939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose Sumit Bose <sbose@redhat.com>
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose Copyright (C) 2013 Red Hat
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose SSSD tests: Tests for utility functions
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 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 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/>.
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bosestatic int setup_dom_list_with_subdomains(void **state)
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->name = talloc_asprintf(dom, "configured.dom");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->realm = talloc_asprintf(dom, "CONFIGURED.DOM");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->flat_name = talloc_asprintf(dom, "CONFIGURED");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose dom->domain_id = talloc_asprintf(dom, "S-1-5-21-1-2-1");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-2");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-3");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = talloc_zero(test_ctx, struct sss_domain_info);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->domain_id = talloc_asprintf(c, "S-1-5-21-1-2-4");
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose DLIST_ADD_END(test_ctx->dom_list, c, struct sss_domain_info *);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom = talloc_zero(test_ctx, struct sss_domain_info);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom->name = talloc_asprintf(dom, DOMNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom->flat_name = talloc_asprintf(dom, FLATNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose dom->domain_id = talloc_asprintf(dom, SID_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Type mismatch\n");
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlvoid test_find_domain_by_name_null(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, NULL, false);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(NULL, "test", false);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, false);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, true);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlvoid test_find_domain_by_name_missing_flat_name(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < mis; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, true);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, false);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichlvoid test_find_domain_by_name_disabled(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < mis; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, true);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, name, false);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, true);
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl dom = find_domain_by_name(test_ctx->dom_list, flat_name, false);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, NULL);
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(NULL, "S-1-5-21-1-2-3");
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, sid);
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichlvoid test_find_domain_by_sid_missing_sid(void **state)
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose for (c = 0; c < mis; c++) {
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, sid);
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichlvoid test_find_domain_by_sid_disabled(void **state)
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose assert_true((mis >= 1 && mis < test_ctx->dom_count));
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose for (c = 0; c < mis; c++) {
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose name = talloc_asprintf(global_talloc_context, DOMNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose flat_name = talloc_asprintf(global_talloc_context, FLATNAME_TMPL, c);
ec7732b91c7ca5367e2ae62a237d975ed1b9763fSumit Bose sid = talloc_asprintf(global_talloc_context, SID_TMPL, c);
9ca0071db0e226e4e65b2a80fdeddd5048ca8990Pavel Reichl dom = find_domain_by_sid(test_ctx->dom_list, sid);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek * dom1 -> sub1a
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek * dom2 -> sub2a -> sub2b
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct dom_list_test_ctx);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek dom = named_domain(test_ctx, "sub2a", head->next);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek dom = named_domain(test_ctx, "sub2b", head->next);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozekstatic void test_get_next_domain_descend(void **state)
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(test_ctx->dom_list, SSS_GND_DESCEND);
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozekstatic void test_get_next_domain_disabled(void **state)
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(test_ctx->dom_list, SSS_GND_DESCEND);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židekstatic void test_get_next_domain_flags(void **state)
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* No flags; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend flag only; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* Incl. disabled flag only; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend and include disabled; all doms enabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_DESCEND | SSS_GND_INCLUDE_DISABLED;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* Now disable dom2 and sub2a */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = find_domain_by_name(test_ctx->dom_list, "dom2", false);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = find_domain_by_name(test_ctx->dom_list, "sub2a", false);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* No flags; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend flag only; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek /* Incl. disabled flag only; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Descend and include disabled; dom2 and sub2a disabled */
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek gnd_flags = SSS_GND_DESCEND | SSS_GND_INCLUDE_DISABLED;
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek dom = get_next_domain(test_ctx->dom_list, gnd_flags);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define GLOBAL_RE_EXPRESSION "(?P<name>[^@]+)@?(?P<domain>[^@]*$)"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose#define DOMAIN_RE_EXPRESSION "(((?P<domain>[^\\\\]+)\\\\(?P<name>.+$))|" \
45ba1e10beddf082c061e0a2950340596817861aSumit Bose "((?P<name>[^@]+)@(?P<domain>.+$))|" \
45ba1e10beddf082c061e0a2950340596817861aSumit Bose "(^(?P<name>[^@\\\\]+)$))"
45ba1e10beddf082c061e0a2950340596817861aSumit Bose test_ctx = talloc_zero(global_talloc_context, struct name_init_test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose conf_db = talloc_asprintf(test_ctx, "%s/%s", TESTS_PATH, TEST_CONF_DB);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = confdb_init(test_ctx, &test_ctx->confdb, conf_db);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose dompath = talloc_asprintf(test_ctx, "config/domain/%s", TEST_DOMAIN_NAME);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose test_ctx = talloc_get_type(*state, struct name_init_test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose test_ctx = talloc_get_type(*state, struct name_init_test_ctx);
45ba1e10beddf082c061e0a2950340596817861aSumit Bose ret = sss_names_init(test_ctx, test_ctx->confdb, 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 ret = sss_names_init(test_ctx, test_ctx->confdb, TEST_DOMAIN_NAME,
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);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("abc", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0-0", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-0-0-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-6", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-6-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-21", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-21-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-21-abc", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32-551", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = well_known_sid_to_name("S-1-5-32-551-", &dom, &name);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("abc", "def", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("BUILTIN", "def", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("NT AUTHORITY", "def", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("LOCAL AUTHORITY", "LOCAL", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid(NULL, "LOCAL", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("BUILTIN", "Cryptographic Operators", &sid);
de38d860e39585486e3ccbb42555196e319c7efdSumit Bose ret = name_to_well_known_sid("NT AUTHORITY", "DIALUP", &sid);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose#define TEST_SANITIZE_INPUT "TestUser@Test.Domain"
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose#define TEST_SANITIZE_LC_INPUT "testuser@test.domain"
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bosevoid test_sss_filter_sanitize_for_dom(void **state)
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose test_ctx = talloc_get_type(*state, struct dom_list_test_ctx);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose ret = sss_filter_sanitize_for_dom(test_ctx, TEST_SANITIZE_INPUT, dom,
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(sanitized, TEST_SANITIZE_INPUT);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(lc_sanitized, TEST_SANITIZE_INPUT);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose ret = sss_filter_sanitize_for_dom(test_ctx, TEST_SANITIZE_INPUT, dom,
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(sanitized, TEST_SANITIZE_INPUT);
15a1519ec9c23f598716ffa89e533cd9bfb2a4f3Sumit Bose assert_string_equal(lc_sanitized, TEST_SANITIZE_LC_INPUT);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnikvoid check_expanded_value(TALLOC_CTX *tmp_ctx,
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir = expand_homedir_template(tmp_ctx, template, false, homedir_ctx);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx= talloc_zero(global_talloc_context,
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir_ctx->username = sss_create_internal_fqname(homedir_ctx,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx->config_homedir_substr = HOMEDIR_SUBSTR;
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx *homedir_ctx = talloc_get_type(*state,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik DEBUG(SSSDBG_CRIT_FAILURE, "Type mismatch\n");
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik assert_true(check_leaks_pop(homedir_ctx) == true);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnikvoid test_expand_homedir_template_NULL(void **state)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* following format strings requires data in homedir_ctx */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik const char *format_strings[] = { "%u", "%U", "%d", "%f", "%F", "%H",
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik homedir_ctx = talloc_zero(tmp_ctx, struct sss_nss_homedir_ctx);
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir = expand_homedir_template(tmp_ctx, NULL, false, NULL);
accff8ebe158251b1d25a95b3b035fe7e08fd1eeJakub Hrozek homedir = expand_homedir_template(tmp_ctx, "template", false, NULL);
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 for (i = 0; format_strings[i] != NULL; ++i) {
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, format_strings[i], NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* flatname requires domain and username */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%f", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%f", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* test unknown format string */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%x", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* test malformed format string */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%", NULL);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnikvoid test_expand_homedir_template(void **state)
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik struct sss_nss_homedir_ctx *homedir_ctx = talloc_get_type(*state,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* string without template */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY, DUMMY);
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 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 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 check_expanded_value(tmp_ctx, homedir_ctx, "%f", USERNAME"@"DOMAIN);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%f",
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%f"DUMMY,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%f"DUMMY2,
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 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 check_expanded_value(tmp_ctx, homedir_ctx, "%H", HOMEDIR_SUBSTR);
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%H",
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, "%H"DUMMY,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik check_expanded_value(tmp_ctx, homedir_ctx, DUMMY"%H"DUMMY2,
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,
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,
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik /* test all format strings */
59af140ef81f6d0f10db9549089998f5e05631cbLukas Slebodnik USERNAME"@"DOMAIN"/"ORIGINAL_HOME"/"FLATNAME"/%/"
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, NULL, NULL, true, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, NULL, NULL, false, &res);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, l1, NULL, false, &res);
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 ret = add_strings_lists(global_talloc_context, l1, NULL, true, &res);
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 ret = add_strings_lists(global_talloc_context, NULL, l1, false, &res);
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 ret = add_strings_lists(global_talloc_context, NULL, l1, true, &res);
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 ret = add_strings_lists(global_talloc_context, l1, l2, false, &res);
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 assert_int_equal(memcmp(&l2[d], &res[c+d], sizeof(char *)), 0);
9ce7a46f6578a86b72f20acd7b0e55b1b4ebea09Sumit Bose ret = add_strings_lists(global_talloc_context, l1, l2, true, &res);
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_int_not_equal(memcmp(&l2[d], &res[c+d], sizeof(char *)), 0);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bosevoid test_sss_write_krb5_conf_snippet(void **state)
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet(NULL, false, false);
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet("abc", false, false);
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet("", false, false);
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet("none", false, false);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose ret = asprintf(&file, "%s/%s/localauth_plugin", cwd, TESTS_PATH);
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet(path, true, true);
4fa184e2c60b377fd71e0115a618bd68dc73627dSumit Bose /* Check if writing a second time will work as well */
6bd6571dfe97fb9c6ce9040c3fcfb4965f95eda1Petr Čech ret = sss_write_krb5_conf_snippet(path, true, true);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_zero(global_talloc_context, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx->filename = talloc_strdup(test_ctx, "test_unique_file_XXXXXX");
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic int unique_file_test_teardown(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void assert_destructor(TALLOC_CTX *owner,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek /* Test that the destructor works */
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek check_filename = talloc_strdup(test_ctx, test_ctx->filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = check_and_open_readonly(test_ctx->filename, &fd,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void sss_unique_file_test(struct unique_file_test_ctx *test_ctx,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek fd = sss_unique_file(owner, test_ctx->filename, &ret);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_file_destruct(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_file_neg(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek fd = sss_unique_file(NULL, discard_const("badpattern"), &ret);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void sss_unique_filename_test(struct unique_file_test_ctx *test_ctx,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek tmp_filename = talloc_strdup(test_ctx, test_ctx->filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = sss_unique_filename(owner, test_ctx->filename);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek ret = check_and_open_readonly(test_ctx->filename, &fd,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_filename(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozekstatic void test_sss_unique_filename_destruct(void **state)
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek test_ctx = talloc_get_type(*state, struct unique_file_test_ctx);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bosestatic void test_parse_cert_verify_opts(void **state)
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, NULL, &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, "wedfkwefjk", &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, "no_ocsp", &cv_opts);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context, "no_verification",
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_null(cv_opts->ocsp_default_responder_signing_cert);
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder_signing_cert=",
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose ret = parse_cert_verify_opts(global_talloc_context,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose "ocsp_default_responder_signing_cert=def",
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 assert_string_equal(cv_opts->ocsp_default_responder, "abc");
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose assert_string_equal(cv_opts->ocsp_default_responder_signing_cert, "def");
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic void assert_parse_fqname(const char *fqname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek ret = sss_parse_internal_fqname(global_talloc_context, fqname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic void assert_fqname_unparseable(const char *fqname, errno_t retval)
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek ret = sss_parse_internal_fqname(global_talloc_context, fqname,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozekstatic void test_sss_parse_internal_fqname(void **state)
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek assert_parse_fqname("foo@bar@baz", "foo@bar", "baz");
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);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozekstatic void test_sss_create_internal_fqname(void **state)
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, "foo", "bar");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, "foo", "BAR");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, "foo", NULL);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, NULL, "bar");
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context, NULL, NULL);
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozekstatic void test_sss_create_internal_fqname_list(void **state)
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek const char *in_list1[] = { "aaa", "bbb", NULL };
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek fqlist = sss_create_internal_fqname_list(global_talloc_context,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek fqname = sss_create_internal_fqname(global_talloc_context,
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek outname = sss_output_name(global_talloc_context, fqname, true, 0);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek outname = sss_output_name(global_talloc_context, fqname, false, 0);
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek outname = sss_output_name(global_talloc_context, fqname, false, '-');
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek assert_true(check_leaks_pop(global_talloc_context) == true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bosestatic void test_sss_get_domain_mappings_content(void **state)
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ret = sss_get_domain_mappings_content(NULL, NULL, NULL);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose test_ctx = talloc_get_type(*state, struct dom_list_test_ctx);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose /* no forest */
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ret = sss_get_domain_mappings_content(test_ctx, dom, &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 /* IPA with forest */
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = find_domain_by_name(dom, "subdom2.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c = find_domain_by_name(dom, "subdom3.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose c->forest_root = find_domain_by_name(dom, "subdom1.dom", true);
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose ret = sss_get_domain_mappings_content(test_ctx, dom, &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 "SUBDOM3.DOM = {\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose " CONFIGURED.DOM = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose "CONFIGURED.DOM = {\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose " SUBDOM2.DOM = SUBDOM1.DOM\n"
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose " SUBDOM3.DOM = SUBDOM1.DOM\n"
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. */
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bosestatic void test_is_email_from_domain(void **state)
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose d = find_domain_by_name(test_ctx->dom_list, "name_0.dom", false);
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_false(is_email_from_domain("hello", NULL));
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose assert_false(is_email_from_domain("hello@hello", d));
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));
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid_missing_sid,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_sid_disabled,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name_null,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name_missing_flat_name,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_find_domain_by_name_disabled,
04d4c4d45f3942a813b7f772737f801f877f4e64Sumit Bose cmocka_unit_test_setup_teardown(test_is_email_from_domain,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_names_init,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek cmocka_unit_test_setup_teardown(test_get_next_domain,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek cmocka_unit_test_setup_teardown(test_get_next_domain_descend,
4f97aaa2fd81e90c2d1f74d8b6619083db4061a5Jakub Hrozek cmocka_unit_test_setup_teardown(test_get_next_domain_disabled,
c84dcaa58449c53cf038311ce63bb2c304081b9dMichal Židek cmocka_unit_test_setup_teardown(test_get_next_domain_flags,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_filter_sanitize_for_dom,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_expand_homedir_template_NULL),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_expand_homedir_template,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_reverse_replace_whitespaces),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_add_strings_lists,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_sss_write_krb5_conf_snippet),
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_file,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_file_destruct,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_filename,
d95bcfe23c574de7b6b7b44b52a0d4db5cc8529aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_unique_filename_destruct,
53ef8f81b60929a6c866efdd133627e7d7d61705Sumit Bose cmocka_unit_test_setup_teardown(test_parse_cert_verify_opts,
31851748aa1c6d7f17afcbf1c36c8feed6d651f8Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_parse_internal_fqname,
35b7aaf0f718390b06be8414258e3fc83326a871Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_create_internal_fqname,
8858d820445cffb67ef8cf790b3a8d37b008d654Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_create_internal_fqname_list,
87c6d9ea92d83460457353cfea6c5bde8744994aJakub Hrozek cmocka_unit_test_setup_teardown(test_sss_output_name,
66588a6241df42a04cb9ead75cf3afb38495d74aSumit Bose cmocka_unit_test_setup_teardown(test_sss_get_domain_mappings_content,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
939246537b0b9a4af6862c513d3919501ad57d92Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
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 */
cb4742876508a08ba90c82466c9dba708e4bf999Pavel Březina test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);