Ejemplo n.º 1
0
 def test_ports_equal(self):
     from acme.standalone import BaseDualNetworkedServers
     servers = BaseDualNetworkedServers(
         BaseDualNetworkedServersTest.SingleProtocolServer, ('', 0),
         socketserver.BaseRequestHandler)
     socknames = servers.getsocknames()
     prev_port = None
     # assert ports are equal
     for sockname in socknames:
         port = sockname[1]
         if prev_port:
             self.assertEqual(prev_port, port)
         prev_port = port
Ejemplo n.º 2
0
 def test_ports_equal(self):
     from acme.standalone import BaseDualNetworkedServers
     servers = BaseDualNetworkedServers(
         BaseDualNetworkedServersTest.SingleProtocolServer,
         ('', 0),
         socketserver.BaseRequestHandler)
     socknames = servers.getsocknames()
     prev_port = None
     # assert ports are equal
     for sockname in socknames:
         port = sockname[1]
         if prev_port:
             self.assertEqual(prev_port, port)
         prev_port = port
Ejemplo n.º 3
0
    def test_fail_to_bind(self, mock_bind):
        from errno import EADDRINUSE
        from acme.standalone import BaseDualNetworkedServers

        mock_bind.side_effect = socket.error(EADDRINUSE,
                                             "Fake addr in use error")

        with self.assertRaises(socket.error) as em:
            BaseDualNetworkedServers(
                BaseDualNetworkedServersTest.SingleProtocolServer, ('', 0),
                socketserver.BaseRequestHandler)

        self.assertEqual(em.exception.errno, EADDRINUSE)
Ejemplo n.º 4
0
def load_balancer(pebble_settings, minio_boto3_settings, minio_settings):
    class RedirectHandler(BaseHTTPRequestHandler):
        def do_HEAD(s):
            s.send_response(301)
            if not s.path.startswith("/.well-known/acme-challenge/"):
                raise ValueError(f"Got invalid request. path: {s.path}")
            s.send_header(
                "Location",
                f"{minio_boto3_settings['endpoint_url']}/{minio_settings['BUCKET']}{s.path}",
            )
            s.end_headers()

        def do_GET(s):
            s.do_HEAD()

    port = pebble_settings["HTTP_PORT"]
    server = BaseDualNetworkedServers(HTTPServer, ("", port), RedirectHandler)
    server.serve_forever()
    try:
        await_port(port)
        yield {"url": f"http://127.0.0.1:{port}"}
    finally:
        server.shutdown_and_server_close()