예제 #1
0
    def setup_class(cls):
        cls.io_loop = ioloop.IOLoop.current()

        app = web.Application([(r".*", TestingApp)])
        cls.http_server, cls.http_port = run_tornado_app(
            app, cls.io_loop, None, "http", cls.http_host
        )

        app = web.Application([(r".*", TestingApp)])
        cls.https_server, cls.https_port = run_tornado_app(
            app, cls.io_loop, cls.https_certs, "https", cls.http_host
        )

        app = web.Application([(r".*", ProxyHandler)])
        cls.proxy_server, cls.proxy_port = run_tornado_app(
            app, cls.io_loop, None, "http", cls.proxy_host
        )

        upstream_ca_certs = cls.https_certs.get("ca_certs", None)
        app = web.Application(
            [(r".*", ProxyHandler)], upstream_ca_certs=upstream_ca_certs
        )
        cls.https_proxy_server, cls.https_proxy_port = run_tornado_app(
            app, cls.io_loop, cls.https_certs, "https", cls.proxy_host
        )

        cls.server_thread = run_loop_in_thread(cls.io_loop)
예제 #2
0
    def setUpClass(cls):
        cls.io_loop = ioloop.IOLoop()

        app = web.Application([(r".*", TestingApp)])
        cls.http_server, cls.http_port = run_tornado_app(app, cls.io_loop, None, "http", cls.http_host)

        app = web.Application([(r".*", TestingApp)])
        cls.https_server, cls.https_port = run_tornado_app(app, cls.io_loop, cls.https_certs, "https", cls.http_host)

        app = web.Application([(r".*", ProxyHandler)])
        cls.proxy_server, cls.proxy_port = run_tornado_app(app, cls.io_loop, None, "http", cls.proxy_host)

        cls.server_thread = run_loop_in_thread(cls.io_loop)
예제 #3
0
    def setUpClass(cls):
        cls.io_loop = ioloop.IOLoop()

        app = web.Application([(r'.*', TestingApp)])
        cls.http_server, cls.http_port = run_tornado_app(
            app, cls.io_loop, None, 'http', cls.http_host)

        app = web.Application([(r'.*', TestingApp)])
        cls.https_server, cls.https_port = run_tornado_app(
            app, cls.io_loop, cls.https_certs, 'https', cls.http_host)

        app = web.Application([(r'.*', ProxyHandler)])
        cls.proxy_server, cls.proxy_port = run_tornado_app(
            app, cls.io_loop, None, 'http', cls.proxy_host)

        cls.server_thread = run_loop_in_thread(cls.io_loop)
예제 #4
0
 def _start_server(cls):
     cls.io_loop = ioloop.IOLoop.current()
     app = web.Application([(r".*", TestingApp)])
     cls.server, cls.port = run_tornado_app(
         app, cls.io_loop, cls.certs, cls.scheme, cls.host
     )
     cls.server_thread = run_loop_in_thread(cls.io_loop)
예제 #5
0
    def setUpClass(cls):
        cls.io_loop = ioloop.IOLoop()

        app = wsgi.WSGIContainer(TestingApp())
        cls.http_server, cls.http_port = run_tornado_app(
            app, cls.io_loop, None, 'http', cls.http_host)

        app = wsgi.WSGIContainer(TestingApp())
        cls.https_server, cls.https_port = run_tornado_app(
            app, cls.io_loop, cls.https_certs, 'https', cls.http_host)

        app = web.Application([(r'.*', ProxyHandler)])
        cls.proxy_server, cls.proxy_port = run_tornado_app(
            app, cls.io_loop, None, 'http', cls.proxy_host)

        cls.server_thread = run_loop_in_thread(cls.io_loop)
예제 #6
0
        def _run_server_in_thread():
            # The event loop MUST be instantiated in the worker thread, or it will
            # interfere with the tests targeting asyncio
            if asyncio:
                asyncio.set_event_loop(asyncio.new_event_loop())

            cls.io_loop = ioloop.IOLoop.current()
            cls.server, cls.port = run_tornado_app(app, cls.io_loop, cls.certs,
                                                   cls.scheme, cls.host)
            ready_event.set()
            cls.io_loop.start()
예제 #7
0
def run_server_in_thread(scheme, host, ca_certs, server_certs):
    io_loop = ioloop.IOLoop.current()
    app = web.Application([(r".*", TestingApp)])
    server, port = run_tornado_app(app, io_loop, server_certs, scheme, host)
    server_thread = threading.Thread(target=io_loop.start)
    server_thread.start()

    yield ServerConfig(host, port, ca_certs)

    io_loop.add_callback(server.stop)
    io_loop.add_callback(io_loop.stop)
    server_thread.join()
예제 #8
0
def run_server_and_proxy_in_thread(
    proxy_scheme: str,
    proxy_host: str,
    tmpdir: Path,
    ca: trustme.CA,
    proxy_cert: trustme.LeafCert,
    server_cert: trustme.LeafCert,
) -> Generator[Tuple[ServerConfig, ServerConfig], None, None]:
    ca_cert_path = str(tmpdir / "ca.pem")
    ca.cert_pem.write_to_path(ca_cert_path)

    server_certs = _write_cert_to_dir(server_cert, tmpdir)
    proxy_certs = _write_cert_to_dir(proxy_cert, tmpdir, "proxy")

    io_loop = ioloop.IOLoop.current()
    app = web.Application([(r".*", TestingApp)])
    server_app, port = run_tornado_app(app, io_loop, server_certs, "https",
                                       "localhost")
    server_config = ServerConfig("https", "localhost", port, ca_cert_path)

    proxy = web.Application([(r".*", ProxyHandler)])
    proxy_app, proxy_port = run_tornado_app(proxy, io_loop, proxy_certs,
                                            proxy_scheme, proxy_host)
    proxy_config = ServerConfig(proxy_scheme, proxy_host, proxy_port,
                                ca_cert_path)

    server_thread = threading.Thread(target=io_loop.start)
    server_thread.start()

    yield (proxy_config, server_config)

    io_loop.add_callback(server_app.stop)
    io_loop.add_callback(proxy_app.stop)
    io_loop.add_callback(io_loop.stop)

    server_thread.join()
예제 #9
0
파일: conftest.py 프로젝트: nj-eka/urllib3
def run_server_in_thread(scheme, host, tmpdir, ca, server_cert):
    ca_cert_path = str(tmpdir / "ca.pem")
    server_cert_path = str(tmpdir / "server.pem")
    server_key_path = str(tmpdir / "server.key")
    ca.cert_pem.write_to_path(ca_cert_path)
    server_cert.private_key_pem.write_to_path(server_key_path)
    server_cert.cert_chain_pems[0].write_to_path(server_cert_path)
    server_certs = {"keyfile": server_key_path, "certfile": server_cert_path}

    io_loop = ioloop.IOLoop.current()
    app = web.Application([(r".*", TestingApp)])
    server, port = run_tornado_app(app, io_loop, server_certs, scheme, host)
    server_thread = threading.Thread(target=io_loop.start)
    server_thread.start()

    yield ServerConfig(host, port, ca_cert_path)

    io_loop.add_callback(server.stop)
    io_loop.add_callback(io_loop.stop)
    server_thread.join()
예제 #10
0
 def _start_server(cls):
     cls.io_loop = ioloop.IOLoop()
     app = web.Application([(r".*", TestingApp)])
     cls.server, cls.port = run_tornado_app(app, cls.io_loop, cls.certs,
                                            cls.scheme, cls.host)
     cls.server_thread = run_loop_in_thread(cls.io_loop)
예제 #11
0
 def _start_server(cls):
     cls.io_loop = ioloop.IOLoop()
     app = wsgi.WSGIContainer(TestingApp())
     cls.server, cls.port = run_tornado_app(app, cls.io_loop, cls.certs,
                                            cls.scheme, cls.host)
     cls.server_thread = run_loop_in_thread(cls.io_loop)
예제 #12
0
 def _start_server(cls):
     cls.io_loop = ioloop.IOLoop()
     app = wsgi.WSGIContainer(TestingApp())
     cls.server, cls.port = run_tornado_app(app, cls.io_loop, cls.certs,
                                            cls.scheme, cls.host)
     cls.server_thread = run_loop_in_thread(cls.io_loop)