This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1464409 [wpt PR 11164] - Origin header and 308 redirect, a=testonly
Automatic update from web-platform-testsOrigin header and 308 redirect For whatwg/fetch#594. -- wpt-commits: 89ae808d4ba430f83f8bc185b69108cf10070599 wpt-pr: 11164
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// META: script=/common/utils.js | ||
// META: script=/common/get-host-info.sub.js | ||
|
||
promise_test(async function() { | ||
const stash = token(), | ||
origins = get_host_info(), | ||
redirectPath = "/fetch/origin/resources/redirect-and-stash.py"; | ||
|
||
// Cross-origin -> same-origin will result in setting the tainted origin flag for the second | ||
// request. | ||
let url = origins.HTTP_ORIGIN + redirectPath + "?stash=" + stash; | ||
url = origins.HTTP_REMOTE_ORIGIN + redirectPath + "?stash=" + stash + "&location=" + encodeURIComponent(url); | ||
|
||
await fetch(url, { mode: "no-cors", method: "POST" }); | ||
|
||
const json = await (await fetch(redirectPath + "?dump&stash=" + stash)).json(); | ||
|
||
assert_equals(json[0], origins.HTTP_ORIGIN, "first origin should equal this origin"); | ||
assert_equals(json[1], "null", "second origin should be opaque and therefore null"); | ||
}, "Origin header and 308 redirect"); |
29 changes: 29 additions & 0 deletions
29
testing/web-platform/tests/fetch/origin/resources/redirect-and-stash.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
|
||
def main(request, response): | ||
key = request.GET.first("stash") | ||
origin = request.headers.get("origin") | ||
if origin is None: | ||
origin = "no Origin header" | ||
|
||
origin_list = request.server.stash.take(key) | ||
|
||
if "dump" in request.GET: | ||
response.headers.set("content-Type", "application/json") | ||
response.content = json.dumps(origin_list) | ||
return | ||
|
||
if origin_list is None: | ||
origin_list = [origin] | ||
else: | ||
origin_list.append(origin) | ||
|
||
request.server.stash.put(key, origin_list) | ||
|
||
if "location" in request.GET: | ||
response.status = 308 | ||
response.headers.set("Location", request.GET.first("location")) | ||
return | ||
|
||
response.headers.set("content-Type", "text/plain") | ||
response.content = "Fix https://github.com/whatwg/fetch/issues/737..." |