537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek/*
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek Authors:
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek Michal Zidek <mzidek@redhat.com>
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek Copyright (C) 2017 Red Hat
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek Config file validators test
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek This program is free software; you can redistribute it and/or modify
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek it under the terms of the GNU General Public License as published by
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek the Free Software Foundation; either version 3 of the License, or
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek (at your option) any later version.
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek This program is distributed in the hope that it will be useful,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek but WITHOUT ANY WARRANTY; without even the implied warranty of
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek GNU General Public License for more details.
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek You should have received a copy of the GNU General Public License
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek along with this program. If not, see <http://www.gnu.org/licenses/>.
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek*/
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#include <popt.h>
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#include <talloc.h>
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#include <ini_configobj.h>
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#include "util/sss_ini.h"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#include "tests/cmocka/common_mock.h"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#ifdef HAVE_LIBINI_CONFIG_V1_3
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#define RULES_PATH ABS_SRC_DIR"/src/config/cfg_rules.ini"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekstruct sss_ini_initdata {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char **error_list;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek struct ref_array *ra_success_list;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek struct ref_array *ra_error_list;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek struct ini_cfgobj *sssd_config;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek struct value_obj *obj;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const struct stat *cstat;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek struct ini_cfgfile *file;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek};
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_common(const char *cfg_string,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek size_t num_errors_expected,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char **errors_expected)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek struct sss_ini_initdata *init_data;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek size_t num_errors;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char **strs;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek int ret;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek TALLOC_CTX *tmp_ctx;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek tmp_ctx = talloc_new(NULL);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_non_null(tmp_ctx);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek init_data = sss_ini_initdata_init(tmp_ctx);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek ret = ini_config_file_from_mem(discard_const(cfg_string),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek strlen(cfg_string),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek &init_data->file);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_int_equal(ret, EOK);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek ret = ini_config_create(&(init_data->sssd_config));
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_int_equal(ret, EOK);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek ret = ini_config_parse(init_data->file,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek INI_STOP_ON_ANY,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek INI_MV1S_OVERWRITE,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek INI_PARSE_NOWRAP,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek init_data->sssd_config);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_int_equal(ret, EOK);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek ret = sss_ini_call_validators_strs(tmp_ctx, init_data,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek RULES_PATH,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek &strs, &num_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_int_equal(ret, EOK);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek /* Output from validators */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek for (int i = 0; i < num_errors; i++) {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek /* Keep this printf loop for faster debugging */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek printf("%s\n", strs[i]);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek }
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik assert_int_equal(num_errors, num_errors_expected);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek for (int i = 0; i < num_errors && i <= num_errors_expected; i++) {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_string_equal(strs[i], errors_expected[i]);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek }
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek /* Check if the number of errors is the same */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_int_equal(num_errors_expected, num_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek sss_ini_close_file(init_data);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek sss_ini_config_destroy(init_data);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek talloc_free(tmp_ctx);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_section_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[sssssssssssssd]";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_sections]: Section [sssssssssssssd] is not allowed. "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židekvoid config_check_test_too_many_subdomains(void **state)
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek{
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek char cfg_str[] = "[domain/ad.test/b.test/c.test]";
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek const char *expected_errors[] = {
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek "[rule/allowed_sections]: Section [domain/ad.test/b.test/c.test] is not allowed. "
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek "Check for typos.",
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek };
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek config_check_test_common(cfg_str, 1, expected_errors);
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek}
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_sssd_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[sssd]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_sssd_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'sssd'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_pam_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[pam]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_pam_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'pam'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_nss_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[nss]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_nss_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'nss'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_pac_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[pac]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_pac_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'pac'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_ifp_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[ifp]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_ifp_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'ifp'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_domain_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik char cfg_str[] = "[domain/A.test]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_subdomain_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'domain/A.test'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_appdomain_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik char cfg_str[] = "[application/myapp]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik "[rule/allowed_domain_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'application/myapp'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_subdom_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[domain/A.test/B.A.test]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = {
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik "[rule/allowed_subdomain_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'domain/A.test/B.A.test'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_good_sections(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek char cfg_str[] = "[sssd]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[pam]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[nss]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[domain/testdom.test]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[domain/testdom.test/testsubdom.testdom.test]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[application/myapp]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[secrets]\n"
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik "[secrets/users/1000]\n"
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik "[ssh]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[ifp]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[pac]\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const char *expected_errors[] = { NULL };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 0, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židekvoid config_check_test_inherit_from_in_normal_dom(void **state)
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek{
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek char cfg_str[] = "[domain/A.test]\n"
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "inherit_from = domain\n";
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek const char *expected_errors[] = {
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "[rule/sssd_checks]: Attribute 'inherit_from' is not allowed in "
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "section 'domain/A.test'. Check for typos.",
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek };
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek}
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židekvoid config_check_test_inherit_from_in_app_dom(void **state)
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek{
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek char cfg_str[] = "[application/A.test]\n"
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "inherit_from = domain\n";
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek const char *expected_errors[] = { NULL };
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek config_check_test_common(cfg_str, 0, expected_errors);
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek}
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekint main(int argc, const char *argv[])
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek poptContext pc;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek int opt;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek struct poptOption long_options[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek POPT_AUTOHELP
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek SSSD_DEBUG_OPTS
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek POPT_TABLEEND
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek const struct CMUnitTest tests[] = {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek cmocka_unit_test(config_check_test_bad_section_name),
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek cmocka_unit_test(config_check_test_too_many_subdomains),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek cmocka_unit_test(config_check_test_bad_sssd_option_name),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek cmocka_unit_test(config_check_test_bad_pam_option_name),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek cmocka_unit_test(config_check_test_bad_nss_option_name),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek cmocka_unit_test(config_check_test_bad_pac_option_name),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek cmocka_unit_test(config_check_test_bad_ifp_option_name),
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik cmocka_unit_test(config_check_test_bad_appdomain_option_name),
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik cmocka_unit_test(config_check_test_bad_subdom_option_name),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek cmocka_unit_test(config_check_test_good_sections),
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek cmocka_unit_test(config_check_test_inherit_from_in_normal_dom),
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik cmocka_unit_test(config_check_test_inherit_from_in_app_dom),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek };
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek /* Set debug level to invalid value so we can decide if -d 0 was used. */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek debug_level = SSSDBG_INVALID;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek while ((opt = poptGetNextOpt(pc)) != -1) {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek switch (opt) {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek default:
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek fprintf(stderr, "\nInvalid option %s: %s\n\n",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek poptBadOption(pc, 0), poptStrerror(opt));
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek poptPrintUsage(pc, stderr, 0);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek return 1;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek }
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek }
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek poptFreeContext(pc);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek DEBUG_CLI_INIT(debug_level);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek tests_set_cwd();
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek return cmocka_run_group_tests(tests, NULL, NULL);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#else /* !HAVE_LIBINI_CONFIG_V1_3 */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekint main(int argc, const char *argv[])
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek{
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek fprintf(stderr, "%s requires newer version of libini\n", argv[0]);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek return 0;
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek}
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#endif /* HAVE_LIBINI_CONFIG_V1_3 */