Esempio n. 1
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
    assert nginx["http"]["server"]["ssl_certificate"][
        0].value == "/etc/pki/nginx/server.crt"

    # 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"))[0].attrs
    expected = ["GATEWAY_INTERFACE", "CGI/1.1"]
    assert actual == expected
Esempio n. 2
0
def test_nginx_ssl_cert_exception():
    conf1 = _NginxConf(context_wrap(NGINX_CONF, path='/etc/nginx/nginx.conf'))
    conf2 = _NginxConf(
        context_wrap(NGINX_CONF_WITHOUT_SSL,
                     path='/etc/nginx/conf.d/no_ssl.conf'))
    conf_tree = NginxConfTree([conf1, conf2])
    broker1 = {NginxConfTree: conf_tree}
    with pytest.raises(SkipComponent):
        nginx_ssl_certificate_files(broker1)
Esempio n. 3
0
def test_nginx_recursive_includes():
    # the content for both of these is the same to cause recursive include
    nginx_conf = context_wrap(NGINX_CONF, path="/etc/nginx/nginx.conf")
    mime_types_conf = context_wrap(NGINX_CONF, path="/etc/nginx/conf/mime.types")

    main = _NginxConf(nginx_conf)
    mime_types = _NginxConf(mime_types_conf)

    with pytest.raises(Exception):
        NginxConfTree([main, mime_types])
def test_nginx_conf_parser():
    nginxconf = _NginxConf(context_wrap(NGINXCONF))
    assert nginxconf['user'][-1].value == 'root'
    assert nginxconf['events'][-1]['worker_connections'][-1].value == 4096
    assert nginxconf['mail'][-1]['server'][0]['listen'][-1].value == 143
    assert nginxconf['http'][-1]['access_log'][
        -1].value == 'logs/access.log main'
    assert nginxconf['http'][-1]['server'][0]['location'][0]['fastcgi_pass'][
        -1].value == '127.0.0.1:1025'
    assert nginxconf['http'][-1]['server'][1]['location'][-1].value == '/'
    assert nginxconf['http'][-1]['upstream'][1].value == 'big_server_com'
    assert nginxconf["http"][-1]["include"][0].value == 'conf/mime.types'
    assert nginxconf['http'][-1]['upstream'][1]['server'][
        0].value == '127.0.0.3:8000 weight=5'
    assert nginxconf['http'][-1]['log_format'][
        -1].value == 'main $remote_addr - $remote_user [$time_local] "$request"  $status $body_bytes_sent "$http_referer"  "$http_user_agent" "$http_x_forwarded_for"'
    assert nginxconf['http'][-1]['server'][2]['location'][0]['location'][0][
        'limit_except'][-1]['allow'][-1].value == '192.168.2.0/32'
    assert nginxconf['http']['server']['location']['location']['limit_except'][
        'allow'][-1].value == '192.168.2.0/32'
    assert nginxconf['http']['server'][0]['location'][-1].value == '~ \.php$'
    assert nginxconf['http']['server'][1]['location'][
        0].value == '~ ^/(images|javascript|js|css|flash|media|static)/'
    assert nginxconf['http']['server'][1]['location'][-1].value == '/'
    assert nginxconf['http']['server'][-1] == nginxconf['http']['server'][2]
Esempio n. 5
0
def test_nginx_certificate():
    conf1 = _NginxConf(context_wrap(NGINX_CONF, path='/etc/nginx/nginx.conf'))
    conf2 = _NginxConf(context_wrap(NGINX_SSL_CONF, path='/etc/nginx/conf.d/ssl.conf'))
    conf_tree = NginxConfTree([conf1, conf2])

    broker = {
        NginxConfTree: conf_tree
    }
    result = nginx_ssl_certificate_files(broker)
    assert result == ['/a/b/c.rsa.crt', '/a/b/c.cecdsa.crt']

    conf1 = _NginxConf(context_wrap(NGINX_CONF, path='/etc/nginx/nginx.conf'))
    conf2 = _NginxConf(context_wrap(NGINX_SSL_CONF_MULTIPLE_SERVERS, path='/etc/nginx/conf.d/ssl.conf'))
    conf_tree = NginxConfTree([conf1, conf2])

    broker = {
        NginxConfTree: conf_tree
    }
    result = nginx_ssl_certificate_files(broker)
    assert result == ['/a/b/www.example.com.crt', '/a/b/www.example.com.cecdsa.crt', '/a/b/www.example.org.crt']
Esempio n. 6
0
def test_nginx_empty():
    nginx_conf = context_wrap('', path="/etc/nginx/nginx.conf")
    with pytest.raises(SkipException):
        assert _NginxConf(nginx_conf) is None