From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../tests/worklets/resources/referrer-checker.py | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 testing/web-platform/tests/worklets/resources/referrer-checker.py (limited to 'testing/web-platform/tests/worklets/resources/referrer-checker.py') diff --git a/testing/web-platform/tests/worklets/resources/referrer-checker.py b/testing/web-platform/tests/worklets/resources/referrer-checker.py new file mode 100644 index 0000000000..4c6ea6e5c2 --- /dev/null +++ b/testing/web-platform/tests/worklets/resources/referrer-checker.py @@ -0,0 +1,24 @@ +# Returns a valid response when request's |referrer| matches +# |expected_referrer|. +def main(request, response): + # We want |referrer| to be the referrer header with no query params, + # because |expected_referrer| will not contain any query params, and + # thus cannot be compared with the actual referrer header if it were to + # contain query params. This works fine if the actual referrer has no + # query params too. + referrer = request.headers.get(b"referer", b"").split(b"?")[0] + referrer_policy = request.GET.first(b"referrer_policy") + expected_referrer = request.GET.first(b"expected_referrer", b"") + response_headers = [(b"Content-Type", b"text/javascript"), + (b"Access-Control-Allow-Origin", b"*")] + + if referrer_policy == b"no-referrer" or referrer_policy == b"origin": + if referrer == expected_referrer: + return (200, response_headers, u"") + return (404, response_headers) + + if referrer_policy == b"same-origin": + if referrer == expected_referrer: + return (200, response_headers, u"") + return (404, response_headers) + return (404, response_headers) -- cgit v1.2.3