summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/resources/access-control-preflight-denied.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/xhr/resources/access-control-preflight-denied.py
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.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/xhr/resources/access-control-preflight-denied.py')
-rw-r--r--testing/web-platform/tests/xhr/resources/access-control-preflight-denied.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/testing/web-platform/tests/xhr/resources/access-control-preflight-denied.py b/testing/web-platform/tests/xhr/resources/access-control-preflight-denied.py
new file mode 100644
index 0000000000..1ec3037f36
--- /dev/null
+++ b/testing/web-platform/tests/xhr/resources/access-control-preflight-denied.py
@@ -0,0 +1,49 @@
+def main(request, response):
+ def fail(message):
+ response.content = b"FAIL: " + message
+ response.status = 400
+
+ def getState(token):
+ server_state = request.server.stash.take(token)
+ if not server_state:
+ return b"Uninitialized"
+ return server_state
+
+ def setState(token, state):
+ request.server.stash.put(token, state)
+
+ def resetState(token):
+ setState(token, b"")
+
+ response.headers.set(b"Cache-Control", b"no-store")
+ response.headers.set(b"Access-Control-Allow-Origin", request.headers.get(b"origin"))
+ response.headers.set(b"Access-Control-Max-Age", 1)
+ token = request.GET.first(b"token", None)
+ state = getState(token)
+ command = request.GET.first(b"command", None)
+
+ if command == b"reset":
+ if request.method == u"GET":
+ resetState(token)
+ response.content = b"Server state reset"
+ else:
+ fail(b"Invalid Method.")
+ elif state == b"Uninitialized":
+ if request.method == u"OPTIONS":
+ response.content = b"This request should not be displayed."
+ setState(token, b"Denied")
+ else:
+ fail(state)
+ elif state == b"Denied":
+ if request.method == u"GET" and command == b"complete":
+ resetState(token)
+ response.content = b"Request successfully blocked."
+ else:
+ setState(token, b"Deny Ignored")
+ fail(b"The request was not denied.")
+ elif state == b"Deny Ignored":
+ resetState(token)
+ fail(state)
+ else:
+ resetState(token)
+ fail(b"Unknown Error.")