537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek Michal Zidek <mzidek@redhat.com>
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek Copyright (C) 2017 Red Hat
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek Config file validators test
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 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 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#define RULES_PATH ABS_SRC_DIR"/src/config/cfg_rules.ini"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_common(const char *cfg_string,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek ret = ini_config_file_from_mem(discard_const(cfg_string),
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek ret = ini_config_create(&(init_data->sssd_config));
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek ret = sss_ini_call_validators_strs(tmp_ctx, init_data,
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek /* Output from validators */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek for (int i = 0; i < num_errors; i++) {
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek /* Keep this printf loop for faster debugging */
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik assert_int_equal(num_errors, num_errors_expected);
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 /* Check if the number of errors is the same */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek assert_int_equal(num_errors_expected, num_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_section_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_sections]: Section [sssssssssssssd] is not allowed. "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židekvoid config_check_test_too_many_subdomains(void **state)
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek char cfg_str[] = "[domain/ad.test/b.test/c.test]";
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek "[rule/allowed_sections]: Section [domain/ad.test/b.test/c.test] is not allowed. "
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek "Check for typos.",
283d589b3025a3cadaaddf330d3fb4dc4175968dMichal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_sssd_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_sssd_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'sssd'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_pam_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_pam_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'pam'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_nss_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_nss_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'nss'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_pac_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_pac_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'pac'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_ifp_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_ifp_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'ifp'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_domain_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[rule/allowed_subdomain_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'domain/A.test'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_appdomain_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
291b6bfd499fd64416b75c05c8846a5102600f3cLukas Slebodnik "[rule/allowed_domain_options]: Attribute 'debug_leTYPOvel' is not "
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "allowed in section 'application/myapp'. Check for typos.",
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_bad_subdom_option_name(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "debug_leTYPOvel = 10\n";
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 config_check_test_common(cfg_str, 1, expected_errors);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židekvoid config_check_test_good_sections(void **state)
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[domain/testdom.test/testsubdom.testdom.test]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek "[secrets]\n"
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek config_check_test_common(cfg_str, 0, expected_errors);
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židekvoid config_check_test_inherit_from_in_normal_dom(void **state)
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "inherit_from = domain\n";
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "[rule/sssd_checks]: Attribute 'inherit_from' is not allowed in "
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "section 'domain/A.test'. Check for typos.",
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek config_check_test_common(cfg_str, 1, expected_errors);
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židekvoid config_check_test_inherit_from_in_app_dom(void **state)
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek "inherit_from = domain\n";
39c5aee02fa36ba1cb78fe7669f272fec5277018Michal Židek config_check_test_common(cfg_str, 0, expected_errors);
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 /* Set debug level to invalid value so we can decide if -d 0 was used. */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek return cmocka_run_group_tests(tests, NULL, NULL);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#else /* !HAVE_LIBINI_CONFIG_V1_3 */
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek fprintf(stderr, "%s requires newer version of libini\n", argv[0]);
537103f296b7112d9fd505af941a6d83d7902eb1Michal Židek#endif /* HAVE_LIBINI_CONFIG_V1_3 */