示例#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
示例#2
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
示例#3
0
def test_nginx_includes():
    nginx_conf = context_wrap(NGINX_CONF, path="/etc/nginx/nginx.conf")
    mime_types_conf = context_wrap(MIME_TYPES, path="/etc/nginx/conf/mime.types")
    proxy_conf = context_wrap(PROXY_CONF, path="/etc/nginx/proxy.conf")
    fastcgi_conf = context_wrap(FASTCGI_CONF, path="/etc/nginx/fastcgi.conf")

    # individual parsers
    main = _NginxConf(nginx_conf)
    mime_types = _NginxConf(mime_types_conf)
    proxy = _NginxConf(proxy_conf)
    fastcgi = _NginxConf(fastcgi_conf)

    # combine them
    nginx = NginxConfTree([main, mime_types, proxy, fastcgi])

    # test /etc/nginx/nginx.conf
    assert nginx["events"]["worker_connections"][0].value == 4096

    # test inclusion of conf/mime.types (note relative path)
    text = nginx["http"]["types"][startswith("text/")]
    assert len(text) == 6

    # test inclusion of /etc/nginx/proxy.conf
    assert nginx.find("proxy_send_timeout").value == 90

    # test inclusion of /etc/nginx/fastcgi.conf
    assert nginx.find("fastcgi_pass").value == "127.0.0.1:1025"
    actual = nginx.find(("fastcgi_param", "GATEWAY_INTERFACE")).attrs
    expected = ["GATEWAY_INTERFACE", "CGI/1.1"]
    assert actual == expected
示例#4
0
 def __init__(self, confs):
     includes = startswith("Include")
     super(HttpdConfTree, self).__init__(confs, "httpd.conf", includes)
示例#5
0
def test_startswith():
    data = ["abc", "abrd", "ed"]
    assert startswith("ab")(data)
    assert startswith("ab")("abcde")
    assert not startswith("de")(data)