Exemple #1
0
def start_https_server(host, port, paths, routes, bind_address, config,
                       **kwargs):
    return wptserve.WebTestHttpd(
        host=host,
        port=port,
        doc_root=paths["doc_root"],
        routes=routes,
        rewrites=rewrites,
        bind_address=bind_address,
        config=config,
        use_ssl=True,
        key_file=config.ssl_config["key_path"],
        certificate=config.ssl_config["cert_path"],
        encrypt_after_connect=config.ssl_config["encrypt_after_connect"],
        latency=kwargs.get("latency"))
Exemple #2
0
 def start(self, block=False):
     if self.alive:
         return
     routes = [("POST", "/file_upload", upload_handler),
               ("GET", "/slow", slow_loading_document)]
     routes.extend(default_routes.routes)
     self._server = server.WebTestHttpd(
         port=self.port,
         doc_root=self.root,
         routes=routes,
         host=self.host,
     )
     self._server.start(block=block)
     self.port = self._server.httpd.server_port
     self.base_url = self.get_url()
Exemple #3
0
def start_http_server(host, port, paths, routes, bind_address, config, **kwargs):
    try:
        return wptserve.WebTestHttpd(host=host,
                                     port=port,
                                     doc_root=paths["doc_root"],
                                     routes=routes,
                                     rewrites=rewrites,
                                     bind_address=bind_address,
                                     config=config,
                                     use_ssl=False,
                                     key_file=None,
                                     certificate=None,
                                     latency=kwargs.get("latency"))
    except Exception:
        startup_failed()
def httpd():
    HERE = os.path.dirname(os.path.abspath(__file__))
    routes = [
        ("GET", "/basic_auth", basic_auth_handler),
    ]
    routes.extend(default_routes.routes)
    httpd = server.WebTestHttpd(
        host="127.0.0.1",
        port=8080,
        doc_root=os.path.join(HERE, 'data'),
        routes=routes,
    )
    httpd.start(block=False)
    yield httpd
    httpd.stop()
Exemple #5
0
def setup_webserver(webserver):
    """Set up a new web server with wptserve."""
    LOG.info("starting webserver on %r" % webserver)

    @handler
    def tracemonkey_pdf_handler(request, response):
        """Handler for the talos pdfpaint test."""
        headers = [("Content-Type", "application/pdf")]
        with open("%s/tests/pdfpaint/tracemonkey.pdf" % here, "rb") as file:
            content = file.read()
        return headers, content

    host, port = webserver.split(":")
    httpd = server.WebTestHttpd(host=host, port=int(port), doc_root=here)
    httpd.router.register("GET", "tests/pdfpaint/tracemonkey.pdf",
                          tracemonkey_pdf_handler)
    return httpd
Exemple #6
0
def start_http2_server(host, port, paths, routes, bind_address, config, **kwargs):
    try:
        return wptserve.WebTestHttpd(host=host,
                                     port=port,
                                     handler_cls=wptserve.Http2WebTestRequestHandler,
                                     doc_root=paths["doc_root"],
                                     routes=routes,
                                     rewrites=rewrites,
                                     bind_address=bind_address,
                                     config=config,
                                     use_ssl=True,
                                     key_file=config.ssl_config["key_path"],
                                     certificate=config.ssl_config["cert_path"],
                                     encrypt_after_connect=config.ssl_config["encrypt_after_connect"],
                                     latency=kwargs.get("latency"),
                                     http2=True)
    except Exception:
        startup_failed()
Exemple #7
0
def test_read_prefs_ttw():
    """test reading preferences through the web via wptserve"""

    # create a WebTestHttpd instance
    docroot = os.path.join(here, 'files')
    host = '127.0.0.1'
    port = 8888
    httpd = server.WebTestHttpd(host=host, port=port, doc_root=docroot)

    # create a preferences instance
    prefs = Preferences()

    try:
        # start server
        httpd.start(block=False)

        # read preferences through the web
        read = prefs.read_prefs('http://%s:%d/prefs_with_comments.js' % (host, port))
        assert dict(read) == _prefs_with_comments
    finally:
        httpd.stop()
Exemple #8
0
    def __init__(
        self,
        doc_root,
        url="http://127.0.0.1:0",
        use_ssl=False,
        ssl_cert=None,
        ssl_key=None,
    ):
        if not os.path.isdir(doc_root):
            raise ValueError("Server root is not a directory: %s" % doc_root)

        url = urlparse.urlparse(url)
        if url.scheme is None:
            raise ValueError("Server scheme not provided")

        scheme, host, port = url.scheme, url.hostname, url.port
        if host is None:
            host = "127.0.0.1"
        if port is None:
            port = 0

        routes = [
            ("POST", "/file_upload", upload_handler),
            ("GET", "/http_auth", http_auth_handler),
            ("GET", "/slow", slow_loading_handler),
        ]
        routes.extend(default_routes.routes)

        self._httpd = server.WebTestHttpd(
            host=host,
            port=port,
            bind_address=True,
            doc_root=doc_root,
            routes=routes,
            use_ssl=True if scheme == "https" else False,
            certificate=ssl_cert,
            key_file=ssl_key,
        )
Exemple #9
0
    def setUpClass(cls):
        cls.driver = create_driver()

        cls.webserver = server.WebTestHttpd(host=get_lan_ip())
        cls.webserver.start()
        cls.webserver.where_is = cls.webserver.get_url
Exemple #10
0
 def setUpClass(cls):
     cls.driver = base_test.create_driver()
     cls.webserver = server.WebTestHttpd(routes=[(any_method, "*",
                                                  basic_auth_handler)])
     cls.webserver.start()
Exemple #11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Flask server to listen for Travis webhooks and post GitHub PR comments."""

import urllib

from webhook_handler import webhook_handler
from wptserve import server
from wptserve.handlers import handler


@handler
def travis_handler(request, response):
    """Respond with the output of the webhook handler."""
    payload = urllib.unquote_plus(request.body).split('payload=')[1]
    signature = request.headers.get('signature')
    message, code = webhook_handler(payload, signature)
    return code, [("Content-Type", "text/plain")], message


httpd = server.WebTestHttpd(host='45.55.224.178',
                            doc_root='.',
                            port=80,
                            routes=[("POST", "/prbuildbot/travis/",
                                     travis_handler)])

if __name__ == '__main__':
    httpd.start(block=True)
    def setup_webserver(self, webserver):
        self.log.info("starting webserver on %r" % webserver)
        self.host, self.port = webserver.split(':')

        return server.WebTestHttpd(port=int(self.port), doc_root=self.gecko_profile_dir,
                            routes=[("GET", "*", handlers.file_handler)])