diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/xhr/resources/access-control-basic-preflight-cache-timeout.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/xhr/resources/access-control-basic-preflight-cache-timeout.py')
-rw-r--r-- | testing/web-platform/tests/xhr/resources/access-control-basic-preflight-cache-timeout.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/web-platform/tests/xhr/resources/access-control-basic-preflight-cache-timeout.py b/testing/web-platform/tests/xhr/resources/access-control-basic-preflight-cache-timeout.py new file mode 100644 index 0000000000..00c319f082 --- /dev/null +++ b/testing/web-platform/tests/xhr/resources/access-control-basic-preflight-cache-timeout.py @@ -0,0 +1,50 @@ +from wptserve.utils import isomorphic_encode + +def main(request, response): + def fail(message): + response.content = b"FAIL " + isomorphic_encode(request.method) + b": " + message + + def getState(token): + server_state = request.server.stash.take(token) + if not server_state: + return b"Uninitialized" + return server_state + + def setState(state, token): + request.server.stash.put(token, state) + + response.headers.set(b"Access-Control-Allow-Origin", request.headers.get(b"origin")) + response.headers.set(b"Access-Control-Allow-Credentials", b"true") + token = request.GET.first(b"token", None) + state = getState(token) + + if state == b"Uninitialized": + if request.method == u"OPTIONS": + response.headers.set(b"Access-Control-Allow-Methods", b"PUT") + response.headers.set(b"Access-Control-Allow-Headers", b"x-test") + response.headers.set(b"Access-Control-Max-Age", 1) + setState(b"OPTIONSSent", token) + else: + fail(state) + elif state == b"OPTIONSSent": + if request.method == u"PUT": + response.content = b"PASS: First PUT request." + setState(b"FirstPUTSent", token) + else: + fail(state) + elif state == b"FirstPUTSent": + if request.method == u"OPTIONS": + response.headers.set(b"Access-Control-Allow-Methods", b"PUT") + response.headers.set(b"Access-Control-Allow-Headers", b"x-test") + setState(b"SecondOPTIONSSent", token) + elif request.method == u"PUT": + fail(b"Second PUT request sent without preflight") + else: + fail(state) + elif state == b"SecondOPTIONSSent": + if request.method == u"PUT": + response.content = b"PASS: Second OPTIONS request was sent." + else: + fail(state) + else: + fail(state) |