Ejemplo n.º 1
0
def test_tls_context_less_secure():
    tls_cert = create_file('cert.cert')
    tls_key = create_file('key.key')
    cfile = create_config(('listen=127.0.0.1:25', 'tls_listen=127.0.0.1:9000',
                           'tls_cert={}'.format(tls_cert),
                           'tls_key={}'.format(tls_key), ))
    conf = Config(cfile).load()
    conf.args = Args((('less_secure', True), ))
    with mock.patch('ssl.SSLContext.load_cert_chain'):
        _context(use_tls=True)
Ejemplo n.º 2
0
def test_create_server_tls_ipv6_bind_works():
    cfile = create_config(('listen=:::25',
                           'tls_listen=:::9000', ))
    conf = Config(cfile).load()
    conf.args = Args((('less_secure', False), ))
    with mock.patch('socket.socket.bind') as mock_sock, \
            mock.patch('ssl.create_default_context') as mock_ssl:
        server('::', 9000, socket.AF_INET6, {}, use_tls=True)
    assert mock_sock.called is True
    assert mock_sock.call_count is 1
    assert mock_ssl.called is True
    assert mock_ssl.call_count is 1
Ejemplo n.º 3
0
def test_create_server_tls_ipv6_bind_works():
    cfile = create_config(("listen=:::25", "tls_listen=:::9000"))
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", False),))
    with mock.patch("socket.socket.bind") as mock_sock, mock.patch(
        "ssl.create_default_context"
    ) as mock_ssl:
        _server = server("::", 9000, socket.AF_INET6, use_tls=True)
        _server["sock"].close()
    assert mock_sock.called is True
    assert mock_sock.call_count is 1
    assert mock_ssl.called is True
    assert mock_ssl.call_count is 1
Ejemplo n.º 4
0
def test_create_server_tls_ipv6_bind_works():
    cfile = create_config(("listen=:::25", "tls_listen=:::9000"))
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", False),))
    with mock.patch("socket.socket.bind") as mock_sock, mock.patch(
        "ssl.create_default_context"
    ) as mock_ssl:
        _server = server("::", 9000, socket.AF_INET6, use_tls=True)
        _server["sock"].close()
    assert mock_sock.called is True
    assert mock_sock.call_count is 1
    assert mock_ssl.called is True
    assert mock_ssl.call_count is 1
Ejemplo n.º 5
0
def test_spawn_ipv6_tls_less_secure():
    cert = create_file('cert.pem')
    key = create_file('key.key')
    cfile = create_config(('listen=::9998',
                           'tls_listen=:::9999',
                           'tls_cert={}'.format(cert),
                           'tls_key={}'.format(key)))
    conf = Config(cfile).load()
    conf.args = Args((('less_secure', False), ))
    with mock.patch('socket.socket.bind'), \
            mock.patch('ssl.create_default_context'):
        supervisor = Supervisor()
    assert len(supervisor.socks) == 2
Ejemplo n.º 6
0
def test_spawn_ipv4_tls_dhparams():
    cert = create_file('test.pem', cert_data)
    key = create_file('test.key', key_data)
    dhparams = create_file('dhparams.pem', dhparams_data)
    cfile = create_config(('listen=127.0.0.1:9998',
                           'tls_listen=127.0.0.1:9999',
                           'tls_cert={}'.format(cert),
                           'tls_key={}'.format(key),
                           'tls_dhparams={}'.format(dhparams)))
    conf = Config(cfile).load()
    conf.args = Args((('less_secure', False), ))
    with mock.patch('socket.socket.bind'):
        supervisor = Supervisor()
    assert len(supervisor.socks) == 2
Ejemplo n.º 7
0
def test_tls_context_dhparams():
    tls_cert = create_file('cert.cert')
    tls_key = create_file('key.key')
    tls_dhparams = create_file('dhparams.pem')
    cfile = create_config(('listen=127.0.0.1:25', 'tls_listen=127.0.0.1:9000',
                           'tls_cert={}'.format(tls_cert),
                           'tls_key={}'.format(tls_key),
                           'tls_dhparams={}'.format(tls_dhparams)))
    conf = Config(cfile).load()
    conf.args = Args((('less_secure', False), ))
    with mock.patch('ssl.SSLContext.load_cert_chain'), \
            mock.patch('ssl.SSLContext.load_dh_params') as dh:
        _context(use_tls=True)
    assert dh.called is True
Ejemplo n.º 8
0
def test_tls_context_less_secure():
    tls_cert = create_file("cert.cert")
    tls_key = create_file("key.key")
    cfile = create_config(
        (
            "listen=127.0.0.1:25",
            "tls_listen=127.0.0.1:9000",
            "tls_cert={}".format(tls_cert),
            "tls_key={}".format(tls_key),
        )
    )
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", True),))
    with mock.patch("ssl.SSLContext.load_cert_chain"):
        _context(use_tls=True)
Ejemplo n.º 9
0
def test_tls_context_less_secure():
    tls_cert = create_file("cert.cert")
    tls_key = create_file("key.key")
    cfile = create_config(
        (
            "listen=127.0.0.1:25",
            "tls_listen=127.0.0.1:9000",
            "tls_cert={}".format(tls_cert),
            "tls_key={}".format(tls_key),
        )
    )
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", True),))
    with mock.patch("ssl.SSLContext.load_cert_chain"):
        _context(use_tls=True)
Ejemplo n.º 10
0
def test_tls_context_dhparams():
    tls_cert = create_file("cert.cert")
    tls_key = create_file("key.key")
    tls_dhparams = create_file("dhparams.pem")
    cfile = create_config(
        (
            "listen=127.0.0.1:25",
            "tls_listen=127.0.0.1:9000",
            "tls_cert={}".format(tls_cert),
            "tls_key={}".format(tls_key),
            "tls_dhparams={}".format(tls_dhparams),
        )
    )
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", False),))
    with mock.patch("ssl.SSLContext.load_cert_chain"), mock.patch(
        "ssl.SSLContext.load_dh_params"
    ) as dh:
        _context(use_tls=True)
    assert dh.called is True
Ejemplo n.º 11
0
def test_tls_context_dhparams():
    tls_cert = create_file("cert.cert")
    tls_key = create_file("key.key")
    tls_dhparams = create_file("dhparams.pem")
    cfile = create_config(
        (
            "listen=127.0.0.1:25",
            "tls_listen=127.0.0.1:9000",
            "tls_cert={}".format(tls_cert),
            "tls_key={}".format(tls_key),
            "tls_dhparams={}".format(tls_dhparams),
        )
    )
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", False),))
    with mock.patch("ssl.SSLContext.load_cert_chain"), mock.patch(
        "ssl.SSLContext.load_dh_params"
    ) as dh:
        _context(use_tls=True)
    assert dh.called is True
Ejemplo n.º 12
0
def test_spawn_ipv4_tls():
    cert = create_file("cert.pem")
    key = create_file("key.key")
    cfile = create_config(
        (
            "listen=127.0.0.1:9998",
            "tls_listen=127.0.0.1:9999",
            "tls_cert={}".format(cert),
            "tls_key={}".format(key),
        )
    )
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", True),))
    loop = asyncio.new_event_loop()
    with mock.patch("socket.socket.bind"), mock.patch(
        "ssl.create_default_context"
    ):
        supervisor = Supervisor(loop=loop)
    assert len(supervisor.socks) == 2
    supervisor.close_socks()
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.close()
Ejemplo n.º 13
0
def test_spawn_ipv4_tls_dhparams():
    cert = create_file("test.pem", cert_data)
    key = create_file("test.key", key_data)
    dhparams = create_file("dhparams.pem", dhparams_data)
    cfile = create_config(
        (
            "listen=127.0.0.1:9998",
            "tls_listen=127.0.0.1:9999",
            "tls_cert={}".format(cert),
            "tls_key={}".format(key),
            "tls_dhparams={}".format(dhparams),
        )
    )
    conf = Config(cfile).load()
    conf.args = Args((("less_secure", False),))
    loop = asyncio.new_event_loop()
    with mock.patch("socket.socket.bind"):
        supervisor = Supervisor(loop=loop)
    assert len(supervisor.socks) == 2
    supervisor.close_socks()
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.close()