Exemple #1
0
def check_hostname_verification(config, toolbox):
    """
    Checks that a user has a hostname in configured for their host if they have ssl_verify_hostname
    set to true.
    Args:
        config (ConfigDict): The config object to check
        toolbox (ConfigTestToolbox): Toolbox used to execute the tests

    Returns:
        list of BaseResult
    """
    problems = []
    try:
        transport_type = config.get_enum("transport", const.AD_TRANSPORTS,
                                         const.AD_TRANSPORT_CLEAR, str.lower)

        if transport_type in const.AD_TRANSPORTS_WITH_SSL:
            hosts = util.get_dynamic_keys(config, "host")
            for host in hosts:
                if ip_util.is_valid_single_ip(config.get_str(
                        host)) and config.get_bool("ssl_verify_hostname"):
                    problems.append(
                        IncompatibleValues(
                            key=host,
                            type="hostname",
                            condition="ssl_verify_hostname is enabled",
                        ))
    except ConfigError:
        problems.append(
            SkippedTest(test=check_hostname_verification.__name__,
                        key="transport"))

    return problems
def validate_radius_client_config(config):
    """Validate radius client config by ensuring that
    a host ip is provided and valid. A radius secret is given.
    Args:
        config: ConfigDict
    Returns:
        ConfigCheckResult with any config problems
    """
    problems = []

    try:
        config.get_protected_str('secret_protected', 'secret')
    except ConfigError:
        problems.append(MissingConfigKeyProblem('secret / secret_protected'))

    try:
        addrs = util.get_addr_port_pairs(config)
    except ConfigError:
        problems.append(MissingConfigKeyProblem('host'))
        return ConfigCheckResult(problems)

    for host, port in addrs:
        valid_ip = ip_util.is_valid_single_ip(host)
        if not valid_ip:
            problems.append(InvalidConfigKeyProblem('radius_ip', host))

    return ConfigCheckResult(problems)
    def test_is_valid_single_ip(self, config, ip_key):
        """
        Check the validity of a single ip address in the config

        Args:
            config (ConfigDict): the section config to check
            ip_key (str): key name for the ip address to check

        Returns:
            Bool: whether or not the ip is well formatted
        """
        ip = config.get(ip_key)
        return ip_util.is_valid_single_ip(ip)