Exemple #1
0
def test_complex_queries():
    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_NEST_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_NEST_3, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_NEST_4, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])
    assert len(result.select("VirtualHost")) == 3
    assert len(result.select(("VirtualHost", "128.39.140.28"))) == 2
    assert len(result.select(("VirtualHost", "128.39.140.30"))) == 1
    assert len(result.select(("VirtualHost", startswith("128.39.140")))) == 3
    assert len(result.select(("VirtualHost", ~startswith("128.39.140")))) == 0
    assert len(result.select(("VirtualHost", endswith("140.30")))) == 1
    assert len(result.select(("VirtualHost", ~endswith("140.30")))) == 2
    assert len(result.select((startswith("Virtual"), ~endswith("140.30")))) == 2
    assert len(result.select("FilesMatch", deep=True, roots=False)) == 3

    # find all IfModule !php5_module stanzas regardless of location
    assert len(result.select(("IfModule", "!php5_module"), deep=True, roots=False)) == 6

    # find all IfModule !php5_module stanzas immediately beneath a VirtualHost
    assert len(result.select("VirtualHost", ("IfModule", "!php5_module"), roots=False)) == 3

    # find all IfModule !php4_module stanzas anywhere beneath a top level VirtualHost
    res = result.select("VirtualHost").select(("IfModule", "!php4_module"), deep=True, roots=False)
    assert len(res) == 3

    assert len(result.select(("VirtualHost", ~is_private))) == 3

    res = result.select(("VirtualHost", in_network("128.39.0.0/16")))
    assert len(res) == 3

    res = result.select(("VirtualHost", ~is_private & in_network("128.39.0.0/16")))
    assert len(res) == 3
def test_multiple_includes():
    httpd1 = _HttpdConf(
        context_wrap(MULTIPLE_INCLUDES, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(
        context_wrap(UNICODE_COMMENTS,
                     path='/etc/httpd/conf.d/05-foreman.d/hello.conf'))
    result = HttpdConfTree([httpd1, httpd2])
    assert len(result["IfVersion"]["DNSSDEnable"]) == 2
def test_recursive_includes():
    with pytest.raises(Exception):
        httpd1 = _HttpdConf(
            context_wrap(MULTIPLE_INCLUDES, path='/etc/httpd/conf/httpd.conf'))
        httpd2 = _HttpdConf(
            context_wrap(MULTIPLE_INCLUDES,
                         path='/etc/httpd/conf.d/05-foreman.d/hello.conf'))
        HttpdConfTree([httpd1, httpd2])
Exemple #4
0
def test_httpd_certificate_info_in_nss_exception():
    conf1 = _HttpdConf(
        context_wrap(HTTPD_CONF, path='/etc/httpd/conf/httpd.conf'))
    conf2 = _HttpdConf(
        context_wrap(HTTPD_WITH_NSS_OFF, path='/etc/httpd/conf.d/nss.conf'))
    conf_tree = HttpdConfTree([conf1, conf2])
    broker = {HttpdConfTree: conf_tree}
    with pytest.raises(SkipComponent):
        httpd_certificate_info_in_nss(broker)
Exemple #5
0
def test_httpd_certificate_info_in_nss():
    conf1 = _HttpdConf(
        context_wrap(HTTPD_CONF, path='/etc/httpd/conf/httpd.conf'))
    conf2 = _HttpdConf(
        context_wrap(HTTPD_WITH_NSS, path='/etc/httpd/conf.d/nss.conf'))
    conf_tree = HttpdConfTree([conf1, conf2])
    broker = {HttpdConfTree: conf_tree}
    result = httpd_certificate_info_in_nss(broker)
    assert result == [('/etc/httpd/aliasa', 'testcerta'),
                      ('/etc/httpd/aliasb', 'testcertb')]
def test_httpd_nested_conf_file():
    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_MAIN_3, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/d1/hello.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    server_root = result['ServerRoot'][-1]
    assert server_root.value == '/home/skontar/www'
    assert server_root.line == 'ServerRoot "/home/skontar/www"'
    assert server_root.file_name == 'hello.conf'
    assert server_root.file_path == '/etc/httpd/conf.d/d1/hello.conf'
def test_active_httpd():
    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf.d/00-z.conf'))
    httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_3, path='/etc/httpd/conf.d/z-z.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    assert result['IfModule', 'prefork.c']['MaxClients'][-1].value == 512
    assert result['IfModule', 'prefork.c']['MaxClients'][-1].file_path == '/etc/httpd/conf.d/z-z.conf'
    assert result['IfModule', 'prefork.c']['ThreadsPerChild'][-1].value == 16
    assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 256
    assert result['IfModule', 'prefork.c']['JustForTest'][-1].file_name == '00-z.conf'
    assert result['JustForTest_NoSec'][0].line == 'JustForTest_NoSec "/var/www/cgi"'
def test_splits():
    httpd1 = _HttpdConf(
        context_wrap(HTTPD_CONF_MAIN_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(
        context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    server_root = result['ServerRoot'][last]
    assert server_root.value == '/home/skontar/www'
    assert server_root.line == 'ServerRoot "/home/skontar/www"'
    assert server_root.file_name == '01-b.conf'
    assert server_root.file_path == '/etc/httpd/conf.d/01-b.conf'

    listen = result["Listen"][last]
    assert listen.value == 8080
    assert listen.line == 'Listen 8080'
    assert listen.file_name == '00-a.conf'
    assert listen.file_path == '/etc/httpd/conf.d/00-a.conf'

    httpd1 = _HttpdConf(
        context_wrap(HTTPD_CONF_MAIN_2, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(
        context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    server_root = result['ServerRoot'][last]
    assert server_root.value == '/etc/httpd'
    assert server_root.line == 'ServerRoot "/etc/httpd"'
    assert server_root.file_name == 'httpd.conf'
    assert server_root.file_path == '/etc/httpd/conf/httpd.conf'

    listen = result["Listen"][last]
    assert listen.value == 80
    assert listen.line == 'Listen 80'
    assert listen.file_name == 'httpd.conf'
    assert listen.file_path == '/etc/httpd/conf/httpd.conf'

    httpd1 = _HttpdConf(
        context_wrap(HTTPD_CONF_MAIN_3, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(
        context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    server_root = result['ServerRoot'][last]
    assert server_root.value == '/home/skontar/www'
    assert server_root.line == 'ServerRoot "/home/skontar/www"'
    assert server_root.file_name == '01-b.conf'
    assert server_root.file_path == '/etc/httpd/conf.d/01-b.conf'
    assert listen.value == 80
    assert listen.line == 'Listen 80'
    assert listen.file_name == 'httpd.conf'
    assert listen.file_path == '/etc/httpd/conf/httpd.conf'
Exemple #9
0
def test_directives_and_sections():
    httpd1 = _HttpdConf(
        context_wrap(HTTPD_CONF_NEST_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_NEST_3, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(
        context_wrap(HTTPD_CONF_NEST_4, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])
    assert len(result.directives) == 3
    assert len(result.sections) == 7
    assert len(result.find_all(startswith("Dir")).directives) == 1
    assert len(result.find_all(startswith("Dir")).sections) == 1
def test_indented_lines_and_comments():
    httpd = _HttpdConf(
        context_wrap(HTTPD_EMBEDDED_QUOTES, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd])

    request_headers = result['RequestHeader']
    assert len(request_headers) == 2
def test_unicode_comments():
    httpd = _HttpdConf(
        context_wrap(UNICODE_COMMENTS, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd])

    rewrite_cond = result["DNSSDEnable"]
    assert len(rewrite_cond) == 1
def test_get_httpd_conf_nest_1():
    context = context_wrap(HTTPD_CONF_NEST_1, path=HTTPD_CONF_PATH)
    result = _HttpdConf(context)
    assert result["VirtualHost", "192.0.2.1"]["IfModule", "mod_php4.c"]['php_admin_flag'][last].value == "safe_mode Off"
    assert result["VirtualHost", "192.0.2.1"]["IfModule", "mod_rewrite.c"]['RewriteEngine'][last].value is False
    assert result["VirtualHost", "192.0.2.1"]["IfModule", "mod_rewrite.c"]['RewriteRule'][last].value == ".* /index.php"
    assert result["VirtualHost", "192.0.2.1"]['ServerName'][last].value == "www.example.com"
Exemple #13
0
def test_httpd_ssl_cert_exception():
    conf1 = _HttpdConf(context_wrap(HTTPD_CONF, path='/etc/httpd/conf/httpd.conf'))
    conf2 = _HttpdConf(context_wrap(HTTPD_CONF_WITHOUT_SSL, path='/etc/httpd/conf.d/no_ssl.conf'))
    conf_tree = HttpdConfTree([conf1, conf2])
    broker1 = {
        HttpdConfTree: conf_tree
    }
    conf1 = _HttpdConf(context_wrap(HTTPD_CONF, path='/etc/httpd/conf/httpd.conf'))
    conf2 = _HttpdConf(context_wrap(HTTPD_SSL_CONF_NO_VALUE, path='/etc/httpd/conf.d/no_ssl.conf'))
    conf_tree = HttpdConfTree([conf1, conf2])
    broker2 = {
        HttpdConfTree: conf_tree
    }
    with pytest.raises(SkipComponent):
        httpd_ssl_certificate_files(broker1)
        httpd_ssl_certificate_files(broker2)
def test_empty_last_line():
    httpd = _HttpdConf(
        context_wrap(HTTPD_EMPTY_LAST, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd])

    index_options = result['IndexOptions'][-1]
    assert index_options.value == 'FancyIndexing HTMLTable VersionSort'
def test_splits():
    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_MAIN_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    server_root = result['ServerRoot'][-1]
    assert server_root.value == '/home/skontar/www'
    assert server_root.line == 'ServerRoot "/home/skontar/www"'
    assert server_root.file_name == '01-b.conf'
    assert server_root.file_path == '/etc/httpd/conf.d/01-b.conf'

    listen = result["Listen"][-1]
    assert listen.value == 8080
    assert listen.line == 'Listen 8080'
    assert listen.file_name == '00-a.conf'
    assert listen.file_path == '/etc/httpd/conf.d/00-a.conf'

    ssl_proto = result['SSLProtocol'][-1]
    assert ssl_proto.attrs == ["-ALL", "+TLSv1.2", "#", "SSLv3"]

    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_MAIN_2, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    server_root = result['ServerRoot'][-1]
    assert server_root.value == '/etc/httpd'
    assert server_root.line == 'ServerRoot "/etc/httpd"'
    assert server_root.file_name == 'httpd.conf'
    assert server_root.file_path == '/etc/httpd/conf/httpd.conf'

    listen = result["Listen"][-1]
    assert listen.value == 80
    assert listen.line == 'Listen 80'
    assert listen.file_name == 'httpd.conf'
    assert listen.file_path == '/etc/httpd/conf/httpd.conf'

    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_MAIN_3, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    server_root = result['ServerRoot'][-1]
    assert server_root.value == '/home/skontar/www'
    assert server_root.line == 'ServerRoot "/home/skontar/www"'
    assert server_root.file_name == '01-b.conf'
    assert server_root.file_path == '/etc/httpd/conf.d/01-b.conf'
    assert listen.value == 80
    assert listen.line == 'Listen 80'
    assert listen.file_name == 'httpd.conf'
    assert listen.file_path == '/etc/httpd/conf/httpd.conf'
def test_shadowing():
    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_SHADOWTEST_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_SHADOWTEST_2, path='/etc/httpd/conf.d/00-z.conf'))
    httpd3 = _HttpdConf(context_wrap(HTTPD_CONF_SHADOWTEST_3, path='/etc/httpd/conf.d/z-z.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])

    assert len(result["Foo"]) == 9
    assert len(result["IfModule"]) == 3
    assert len(result["IfModule"]["Foo"]) == 9
    assert len(result["IfModule"]["Bar"]) == 9
    assert len(result["IfModule", "prefork.c"]) == 2
    assert len(result["IfModule", "prefork.c"]["Foo"]) == 6
    assert len(result["IfModule", "prefork.c"]["Bar"]) == 6
    assert len(result["IfModule", "prefork.c"][0]["Foo"]) == 3
    assert len(result["IfModule", "prefork.c"][1]["Foo"]) == 3
    assert len(result["IfModule", "prefork.c"][0]["Bar"]) == 3
    assert len(result["IfModule", "prefork.c"][1]["Bar"]) == 3
def test_line_continuation():
    httpd = _HttpdConf(
        context_wrap(HTTPD_CONF_CONTINUATION,
                     path='/etc/httpd/conf/httpd.conf'))
    val = httpd.find("CustomLog")[0].attrs
    assert val == [
        r'logs/ssl_request_log',
        r'%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b'
    ], val
def test_regex_and_op_attrs():
    httpd = _HttpdConf(context_wrap(HTTPD_REGEX_AND_OP_ATTRS, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd])

    rewrite_cond = result["RewriteCond"]
    assert len(rewrite_cond) == 3

    if_version = result["IfVersion"]
    assert len(if_version) == 1
def test_multiple_values_for_directive():
    context = context_wrap(HTTPD_CONF_MORE, path=HTTPD_CONF_PATH)
    result = _HttpdConf(context)

    assert result.file_path == HTTPD_CONF_PATH
    assert result.file_name == "httpd.conf"
    assert len(result['UserDir']) == 2
    assert result['UserDir'][0].value == 'disable'
    assert result['UserDir'][1].value == 'enable bob'
Exemple #20
0
def test_simple_queries():
    httpd1 = _HttpdConf(context_wrap(HTTPD_CONF_NEST_1, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd1])
    assert result["EnableSendfile"][first].value
    assert len(result["VirtualHost"]) == 1
    assert len(result["VirtualHost"]["Directory"]) == 1
    assert len(result["VirtualHost"]["IfModule"]) == 4
    assert len(result["VirtualHost"]["IfModule"]["RewriteEngine"]) == 2
    assert len(result["VirtualHost"]["IfModule", "mod_rewrite.c"]) == 2
def test_get_httpd_conf_2():
    context = context_wrap(HTTPD_CONF_D_1, path=HTTPD_CONF_D_PATH)
    result = _HttpdConf(context)

    except_SSLC = 'ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW'
    assert result["SSLCipherSuite"][last].value == except_SSLC
    assert "NSSProtocol" not in result
    assert result.file_path == HTTPD_CONF_D_PATH
    assert result.file_name == "default.conf"
    assert result["SSLProtocol"][last].value == '-ALL +SSLv3'
    assert result["SSLProtocol"][last].line == 'SSLProtocol -ALL +SSLv3'
Exemple #22
0
def test_httpd_certificate():
    conf1 = _HttpdConf(context_wrap(HTTPD_CONF, path='/etc/httpd/conf/httpd.conf'))
    conf2 = _HttpdConf(context_wrap(HTTPD_SSL_CONF, path='/etc/httpd/conf.d/ssl.conf'))
    conf_tree = HttpdConfTree([conf1, conf2])

    broker = {
        HttpdConfTree: conf_tree
    }
    result = httpd_ssl_certificate_files(broker)
    assert result == ['/etc/pki/katello/certs/katello-apache.crt']

    conf1 = _HttpdConf(context_wrap(HTTPD_CONF, path='/etc/httpd/conf/httpd.conf'))
    conf2 = _HttpdConf(context_wrap(HTTPD_SSL_CONF_2, path='/etc/httpd/conf.d/ssl.conf'))
    conf_tree = HttpdConfTree([conf1, conf2])

    broker = {
        HttpdConfTree: conf_tree
    }
    result = httpd_ssl_certificate_files(broker)
    assert result == ['/etc/pki/katello/certs/katello-apache.crt', '/etc/pki/katello/certs/katello-apache_d.crt']
def test_get_httpd_conf_1():
    context = context_wrap(HTTPD_CONF_1, path=HTTPD_CONF_PATH)
    result = _HttpdConf(context)

    assert "SSLCipherSuite" not in result
    assert result['ServerRoot'][first].value == '/etc/httpd'
    assert result["NSSProtocol"][first].value == "SSLV3 TLSV1.0"
    assert result["IfModule", "prefork.c"]["MaxClients"][last].value == 256
    assert result["IfModule", "worker.c"]["MaxClients"][last].value == 300
    assert result.file_path == HTTPD_CONF_PATH
    assert 'ThreadsPerChild' not in result['IfModule', 'prefork.c']
    assert result['IfModule', 'prefork.c']['MaxRequestsPerChild'][last].value == 200
    assert result.file_name == "httpd.conf"
    assert result['LoadModule'][first].value == 'auth_basic_module modules/mod_auth_basic.so'
    assert result['LoadModule'][last].value == 'auth_digest_module modules/mod_auth_digest.so'
    assert result['Directory', '/']['Options'][last].value == 'FollowSymLinks'
def test_httpd_one_file_overwrites():
    httpd = _HttpdConf(context_wrap(HTTPD_CONF_MORE, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd])

    active_setting = result['UserDir'][-1]
    assert active_setting.value == 'enable bob'
    assert active_setting.file_path == '/etc/httpd/conf/httpd.conf'
    assert active_setting.file_name == 'httpd.conf'
    assert active_setting.line == 'UserDir enable bob', active_setting.line

    setting_list = result['UserDir']
    assert len(setting_list) == 2
    assert setting_list[0].value == 'disable'
    assert setting_list[0].line == 'UserDir disable'
    assert setting_list[0].file_path == '/etc/httpd/conf/httpd.conf'
    assert setting_list[0].file_name == 'httpd.conf'
    assert setting_list[0].section is None
    assert setting_list[1].value == 'enable bob'
    assert setting_list[1].line == 'UserDir enable bob'
    assert setting_list[1].file_path == '/etc/httpd/conf/httpd.conf'
    assert setting_list[1].file_name == 'httpd.conf'
    assert setting_list[1].section_name is None
def test_no_name_section():
    context = context_wrap(HTTPD_CONF_NO_NAME_SEC, path=HTTPD_CONF_PATH)
    result = _HttpdConf(context)

    assert result["RequireAll"]["AuthName"][last].value == "NAME Access"
    assert result["RequireAll"]["Require"][last].value == "valid-user"
Exemple #26
0
def test_mixed_name():
    httpd1 = _HttpdConf(
        context_wrap(HTTPD_CONF_MIXED_NAME, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd1])
    assert len(result.doc["H2Push"]) == 1
def test_nopath():
    # no path
    httpd2 = _HttpdConf(context_wrap(HTTPD_CONF_2))
    try:
        result = HttpdConfTree([httpd2])
        # assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 1024
        exception_happened = False
    except:
        exception_happened = True
    assert exception_happened

    # no httpd.conf
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf.d/00-z.conf'))
    try:
        result = HttpdConfTree([httpd2])
        # assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 1024
        exception_happened = False
    except:
        exception_happened = True
    assert exception_happened

    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfTree([httpd2])
    assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 1024

    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/laaalalalala/blablabla/httpd.conf'))
    result = HttpdConfTree([httpd2])
    assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 1024

    # no include in httpd.conf
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf/httpd.conf'))
    httpd3 = _HttpdConf(
        context_wrap(HTTPD_CONF_3, path='/etc/httpd/conf.d/z-z.conf'))
    result = HttpdConfTree([httpd2, httpd3])
    assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 1024

    # no include in httpd.conf
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf/httpd.conf'))
    httpd3 = _HttpdConf(
        context_wrap(HTTPD_CONF_3, path='/etc/httpd/conf.d/aaa.conf'))
    result = HttpdConfTree([httpd3, httpd2])
    assert len(result['IfModule', 'prefork.c']['ServerLimit']) == 1
    assert result['IfModule', 'prefork.c']['ServerLimit'][0].value == 1024
    assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 1024

    # with an include
    httpd1 = _HttpdConf(
        context_wrap(HTTPD_CONF_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf.d/00-z.conf'))
    result = HttpdConfTree([httpd1, httpd2])
    assert len(result['IfModule', 'prefork.c']['ServerLimit']) == 2
    assert result['IfModule', 'prefork.c']['ServerLimit'][0].value == 256
    assert result['IfModule', 'prefork.c']['ServerLimit'][-1].value == 1024

    # colliding filenames
    httpd1 = _HttpdConf(
        context_wrap(HTTPD_CONF_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = _HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf.d/00-z.conf'))
    httpd3 = _HttpdConf(
        context_wrap(HTTPD_CONF_3, path='/etc/httpd/conf.d/00-z.conf'))
    result = HttpdConfTree([httpd1, httpd2, httpd3])
    assert len(result['IfModule', 'prefork.c']['ServerLimit']) == 3
    assert result['IfModule',
                  'prefork.c']['ServerLimit'][0].value == 256  # httpd1
    assert result['IfModule',
                  'prefork.c']['ServerLimit'][1].value == 1024  # httpd2
    assert result['IfModule',
                  'prefork.c']['ServerLimit'][-1].value == 256  # httpd3
    assert len(result['IfModule', 'prefork.c']['MaxClients']) == 3
    assert result['IfModule',
                  'prefork.c']['MaxClients'][0].value == 256  # httpd1
    assert result['IfModule',
                  'prefork.c']['MaxClients'][1].value == 1024  # httpd2
    assert result['IfModule',
                  'prefork.c']['MaxClients'][-1].value == 512  # httpd3

    # testing other ways to access the same indices
    assert result['IfModule',
                  'prefork.c']['MaxClients'][0].value == 256  # httpd1
    assert result['IfModule',
                  'prefork.c']['MaxClients'][2].value == 512  # httpd3
    assert result['IfModule',
                  'prefork.c']['MaxClients'][-1].value == 512  # httpd3
def test_mixed_case_tags():
    httpd = _HttpdConf(
        context_wrap(HTTPD_CONF_MIXED, path='/etc/httpd/conf/httpd.conf'))
    assert httpd.find("ServerLimit").value == 256
def test_httpd_conf_empty():
    with pytest.raises(SkipException):
        assert _HttpdConf(context_wrap('',
                                       path='/etc/httpd/httpd.conf')) is None