Example #1
0
def test_spawn_ipv4():
    cfile = create_config(("listen=127.0.0.1:9999",))
    Config(cfile).load()
    loop = asyncio.new_event_loop()
    with mock.patch("socket.socket.bind"):
        supervisor = Supervisor(loop=loop)
    assert len(supervisor.socks) == 1
    supervisor.close_socks()
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.close()
Example #2
0
def test_create():
    cfile = create_config(("listen=:9999, :::9999", "workers=2"))
    Config(cfile).load()
    loop = asyncio.new_event_loop()
    with mock.patch("socket.socket.bind"), mock.patch(
        "blackhole.worker.Worker.start"
    ):
        supervisor = Supervisor(loop=loop)
        supervisor.start_workers()
        assert len(supervisor.workers) == 2
        supervisor.close_socks()
    loop.run_until_complete(loop.shutdown_asyncgens())
    loop.close()
Example #3
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()
Example #4
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()