diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/fetch/api/resources | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/fetch/api/resources')
11 files changed, 270 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/api/resources/authentication.py b/testing/web-platform/tests/fetch/api/resources/authentication.py new file mode 100644 index 000000000..a06d179e5 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/authentication.py @@ -0,0 +1,15 @@ +def main(request, response): + user = request.auth.username + password = request.auth.password + + if user == "user" and password == "password": + return "Authentication done" + + realm = "test" + if "realm" in request.GET: + realm = request.GET.first("realm") + + return ((401, "Unauthorized"), + [("WWW-Authenticate", 'Basic realm="' + realm + '"')], + "Please login with credentials 'user' and 'password'") + diff --git a/testing/web-platform/tests/fetch/api/resources/clean-stash.py b/testing/web-platform/tests/fetch/api/resources/clean-stash.py new file mode 100644 index 000000000..3ae731052 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/clean-stash.py @@ -0,0 +1,6 @@ +def main(request, response): + token = request.GET.first("token") + if request.server.stash.take(token) is not None: + return "1" + else: + return "0" diff --git a/testing/web-platform/tests/fetch/api/resources/data.json b/testing/web-platform/tests/fetch/api/resources/data.json new file mode 100644 index 000000000..76519fa8c --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/data.json @@ -0,0 +1 @@ +{"key": "value"} diff --git a/testing/web-platform/tests/fetch/api/resources/inspect-headers.py b/testing/web-platform/tests/fetch/api/resources/inspect-headers.py new file mode 100644 index 000000000..c4ace18ab --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/inspect-headers.py @@ -0,0 +1,22 @@ +def main(request, response): + headers = [] + request_headers = [] + if "headers" in request.GET: + checked_headers = request.GET.first("headers").split("|") + for header in checked_headers: + if header in request.headers: + headers.append(("x-request-" + header, request.headers.get(header, "") )) + + if "cors" in request.GET: + if "Origin" in request.headers: + headers.append(("Access-Control-Allow-Origin", request.headers.get("Origin", ""))) + else: + headers.append(("Access-Control-Allow-Origin", "*")) + headers.append(("Access-Control-Allow-Credentials", "true")) + headers.append(("Access-Control-Allow-Methods", "GET, POST, HEAD")) + exposed_headers = ["x-request-" + header for header in checked_headers] + headers.append(("Access-Control-Expose-Headers", ", ".join(exposed_headers))) + headers.append(("Access-Control-Allow-Headers", ", ".join(request.headers))) + + headers.append(("content-type", "text/plain")) + return headers, "" diff --git a/testing/web-platform/tests/fetch/api/resources/method.py b/testing/web-platform/tests/fetch/api/resources/method.py new file mode 100644 index 000000000..db234f9d1 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/method.py @@ -0,0 +1,11 @@ +def main(request, response): + headers = [] + if "cors" in request.GET: + headers.append(("Access-Control-Allow-Origin", "*")) + headers.append(("Access-Control-Allow-Credentials", "true")) + headers.append(("Access-Control-Allow-Methods", "GET, POST, PUT, FOO")) + headers.append(("Access-Control-Allow-Headers", "x-test, x-foo")) + headers.append(("Access-Control-Expose-Headers", "x-request-method")) + + headers.append(("x-request-method", request.method)) + return headers, request.body diff --git a/testing/web-platform/tests/fetch/api/resources/preflight.py b/testing/web-platform/tests/fetch/api/resources/preflight.py new file mode 100644 index 000000000..72dceba68 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/preflight.py @@ -0,0 +1,56 @@ +def main(request, response): + headers = [("Content-Type", "text/plain")] + stashed_data = {'control_request_headers': "", 'preflight': "0", 'preflight_referrer': ""} + + if "origin" in request.GET: + for origin in request.GET['origin'].split(", "): + headers.append(("Access-Control-Allow-Origin", origin)) + else: + headers.append(("Access-Control-Allow-Origin", "*")) + + if request.method == "OPTIONS": + if not "Access-Control-Request-Method" in request.headers: + response.set_error(400, "No Access-Control-Request-Method header") + return "ERROR: No access-control-request-method in preflight!" + + if "control_request_headers" in request.GET: + stashed_data['control_request_headers'] = request.headers.get("Access-Control-Request-Headers", "") + + if "max_age" in request.GET: + headers.append(("Access-Control-Max-Age", request.GET['max_age'])) + + if "allow_headers" in request.GET: + headers.append(("Access-Control-Allow-Headers", request.GET['allow_headers'])) + + if "allow_methods" in request.GET: + headers.append(("Access-Control-Allow-Methods", request.GET['allow_methods'])) + + preflight_status = 200 + if "preflight_status" in request.GET: + preflight_status = int(request.GET.first("preflight_status")) + + stashed_data['preflight'] = "1" + stashed_data['preflight_referrer'] = request.headers.get("Referer", "") + request.server.stash.put(request.GET.first("token"), stashed_data) + + return preflight_status, headers, "" + + token = None + if "token" in request.GET: + token = request.GET.first("token") + data = request.server.stash.take(token) + if data: + stashed_data = data + + #use x-* headers for returning value to bodyless responses + headers.append(("Access-Control-Expose-Headers", "x-did-preflight, x-control-request-headers, x-referrer, x-preflight-referrer, x-origin")) + headers.append(("x-did-preflight", stashed_data['preflight'])) + headers.append(("x-control-request-headers", stashed_data['control_request_headers'])) + headers.append(("x-preflight-referrer", stashed_data['preflight_referrer'])) + headers.append(("x-referrer", request.headers.get("Referer", "") )) + headers.append(("x-origin", request.headers.get("Origin", "") )) + + if token: + request.server.stash.put(token, stashed_data) + + return headers, "" diff --git a/testing/web-platform/tests/fetch/api/resources/redirect.py b/testing/web-platform/tests/fetch/api/resources/redirect.py new file mode 100644 index 000000000..46beade1f --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/redirect.py @@ -0,0 +1,54 @@ +from urllib import urlencode +from urlparse import urlparse + +def main(request, response): + stashed_data = {'count': 0, 'preflight': "0"} + status = 302 + headers = [("Content-Type", "text/plain"), + ("Cache-Control", "no-cache"), + ("Pragma", "no-cache"), + ("Access-Control-Allow-Origin", "*")] + token = None + + if "token" in request.GET: + token = request.GET.first("token") + data = request.server.stash.take(token) + if data: + stashed_data = data + + if request.method == "OPTIONS": + if "allow_headers" in request.GET: + headers.append(("Access-Control-Allow-Headers", request.GET['allow_headers'])) + stashed_data['preflight'] = "1" + #Preflight is not redirected: return 200 + if not "redirect_preflight" in request.GET: + if token: + request.server.stash.put(request.GET.first("token"), stashed_data) + return 200, headers, "" + + if "redirect_status" in request.GET: + status = int(request.GET['redirect_status']) + + stashed_data['count'] += 1 + + if "location" in request.GET: + url = request.GET['location'] + scheme = urlparse(url).scheme + if scheme == "" or scheme == "http" or scheme == "https": + url += "&" if '?' in url else "?" + #keep url parameters in location + url += urlencode({key: request.GET.first(key) for key in request.GET.keys()}) + #make sure location changes during redirection loop + url += "&count=" + str(stashed_data['count']) + headers.append(("Location", url)) + + if token: + request.server.stash.put(request.GET.first("token"), stashed_data) + if "max_count" in request.GET: + max_count = int(request.GET['max_count']) + #stop redirecting and return count + if stashed_data['count'] > max_count: + # -1 because the last is not a redirection + return str(stashed_data['count'] - 1) + + return status, headers, "" diff --git a/testing/web-platform/tests/fetch/api/resources/status.py b/testing/web-platform/tests/fetch/api/resources/status.py new file mode 100644 index 000000000..5d72e10b2 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/status.py @@ -0,0 +1,9 @@ +def main(request, response): + code = int(request.GET.first("code", 200)) + text = request.GET.first("text", "OMG") + content = request.GET.first("content", "") + type = request.GET.first("type", "") + status = (code, text) + headers = [("Content-Type", type), + ("X-Request-Method", request.method)] + return status, headers, content diff --git a/testing/web-platform/tests/fetch/api/resources/top.txt b/testing/web-platform/tests/fetch/api/resources/top.txt new file mode 100644 index 000000000..83a3157d1 --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/top.txt @@ -0,0 +1 @@ +top
\ No newline at end of file diff --git a/testing/web-platform/tests/fetch/api/resources/trickle.py b/testing/web-platform/tests/fetch/api/resources/trickle.py new file mode 100644 index 000000000..0e709445c --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/trickle.py @@ -0,0 +1,12 @@ +import time + +def main(request, response): + delay = float(request.GET.first("ms", 500)) / 1E3 + count = int(request.GET.first("count", 50)) + time.sleep(delay) + response.headers.set("Content-type", "text/plain") + response.write_status_headers() + time.sleep(delay); + for i in xrange(count): + response.writer.write_content("TEST_TRICKLE\n") + time.sleep(delay) diff --git a/testing/web-platform/tests/fetch/api/resources/utils.js b/testing/web-platform/tests/fetch/api/resources/utils.js new file mode 100644 index 000000000..86542c7bc --- /dev/null +++ b/testing/web-platform/tests/fetch/api/resources/utils.js @@ -0,0 +1,83 @@ +var inWorker = false; +var RESOURCES_DIR = "../resources/"; + +try { + inWorker = !(self instanceof Window); +} catch (e) { + inWorker = true; +} + +function dirname(path) { + return path.replace(/\/[^\/]*$/, '/') +} + +function checkRequest(request, ExpectedValuesDict) { + for (var attribute in ExpectedValuesDict) { + switch(attribute) { + case "headers": + for (var key in ExpectedValuesDict["headers"].keys()) { + assert_equals(request["headers"].get(key), ExpectedValuesDict["headers"].get(key), + "Check headers attribute has " + key + ":" + ExpectedValuesDict["headers"].get(key)); + } + break; + + case "body": + //for checking body's content, a dedicated asyncronous/promise test should be used + assert_true(request["headers"].has("Content-Type") , "Check request has body using Content-Type header") + break; + + case "method": + case "referrer": + case "referrerPolicy": + case "credentials": + case "cache": + case "redirect": + case "integrity": + case "url": + case "destination": + assert_equals(request[attribute], ExpectedValuesDict[attribute], "Check " + attribute + " attribute") + break; + + default: + break; + } + } +} + +function stringToArray(str) { + var array = new Uint8Array(str.length); + for (var i=0, strLen = str.length; i < strLen; i++) + array[i] = str.charCodeAt(i); + return array; +} + +function validateBufferFromString(buffer, expectedValue, message) +{ + return assert_array_equals(new Uint8Array(buffer !== undefined ? buffer : []), stringToArray(expectedValue), message); +} + +function validateStreamFromString(reader, expectedValue, retrievedArrayBuffer) { + return reader.read().then(function(data) { + if (!data.done) { + assert_true(data.value instanceof Uint8Array, "Fetch ReadableStream chunks should be Uint8Array"); + var newBuffer; + if (retrievedArrayBuffer) { + newBuffer = new ArrayBuffer(data.value.length + retrievedArrayBuffer.length); + newBuffer.set(retrievedArrayBuffer, 0); + newBuffer.set(data.value, retrievedArrayBuffer.length); + } else { + newBuffer = data.value; + } + return validateStreamFromString(reader, expectedValue, newBuffer); + } + validateBufferFromString(retrievedArrayBuffer, expectedValue, "Retrieve and verify stream"); + }); +} + +// From streams tests +function delay(milliseconds) +{ + return new Promise(function(resolve) { + step_timeout(resolve, milliseconds); + }); +} |