#!/usr/bin/env python # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. """Specialisation of wptserver.server.WebTestHttpd for testing Marionette. """ import argparse import os import select import sys import time from six.moves.urllib import parse as urlparse from wptserve import handlers, request, server from wptserve import routes as default_routes root = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) default_doc_root = os.path.join(root, "www") default_ssl_cert = os.path.join(root, "certificates", "test.cert") default_ssl_key = os.path.join(root, "certificates", "test.key") @handlers.handler def http_auth_handler(req, response): # Allow the test to specify the username and password params = dict(urlparse.parse_qsl(req.url_parts.query)) username = params.get("username", "guest") password = params.get("password", "guest") auth = request.Authentication(req.headers) content = """
{}
""" if auth.username == username and auth.password == password: response.status = 200 response.content = content.format("success") else: response.status = 401 response.headers.set("WWW-Authenticate", 'Basic realm="secret"') response.content = content.format("restricted") @handlers.handler def upload_handler(request, response): return 200, [], [request.headers.get("Content-Type")] or [] @handlers.handler def slow_loading_handler(request, response): # Allow the test specify the delay for delivering the content params = dict(urlparse.parse_qsl(request.url_parts.query)) delay = int(params.get("delay", 5)) time.sleep(delay) # Do not allow the page to be cached to circumvent the bfcache of the browser response.headers.set("Cache-Control", "no-cache, no-store") response.content = f"""Delay: {delay}
""" @handlers.handler def slow_coop_handler(request, response): # Allow the test specify the delay for delivering the content params = dict(urlparse.parse_qsl(request.url_parts.query)) delay = int(params.get("delay", 5)) time.sleep(delay) # Isolate the browsing context exclusively to same-origin documents response.headers.set("Cross-Origin-Opener-Policy", "same-origin") response.headers.set("Cache-Control", "no-cache, no-store") response.content = f"""Delay: {delay}
""" @handlers.handler def update_xml_handler(request, response): response.headers.set("Content-Type", "text/xml") mar_digest = ( "75cd68e6c98c84c435cd27e353f5b4f6a3f2c50f6802aa9bf62b47e47138757306769fd9befa08793635ee649" "2319253480860b4aa8ed9ee1caaa4c83ebc90b9" ) response.content = f"""