diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/worklets/resources/referrer-checker.py | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/worklets/resources/referrer-checker.py')
-rw-r--r-- | testing/web-platform/tests/worklets/resources/referrer-checker.py | 24 |
1 files changed, 24 insertions, 0 deletions
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) |