Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1484619 [wpt PR 12566] - Add tests for cross-origin redirects get…
…ting back to the original origin, a=testonly Automatic update from web-platform-testsAdd tests for cross-origin redirects getting back to the original origin (#12566) This is discussed at whatwg/fetch#737, but currently implementors have a somewhat consistent behavior. I will update the test if we change the behavior. -- wpt-commits: c5400eeca28ce5b1dd10d442f0c39a6274d8522d wpt-pr: 12566 UltraBlame original commit: b17979968e272b9e46c009a8cdbba327f0885f0a
- Loading branch information
Showing
2 changed files
with
51 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
37 changes: 37 additions & 0 deletions
37
testing/web-platform/tests/fetch/api/redirect/redirect-back-to-original-origin.any.js
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,37 @@ | ||
|
||
|
||
const BASE = location.href; | ||
const IS_HTTPS = new URL(BASE).protocol === 'https:'; | ||
const REMOTE_HOST = get_host_info()['REMOTE_HOST']; | ||
const REMOTE_PORT = | ||
IS_HTTPS ? get_host_info()['HTTPS_PORT'] : get_host_info()['HTTP_PORT']; | ||
|
||
const REMOTE_ORIGIN = | ||
new URL(`//${REMOTE_HOST}:${REMOTE_PORT}`, BASE).origin; | ||
const DESTINATION = new URL('../resources/cors-top.txt', BASE); | ||
|
||
function CreateURL(url, BASE, params) { | ||
const u = new URL(url, BASE); | ||
for (const {name, value} of params) { | ||
u.searchParams.append(name, value); | ||
} | ||
return u; | ||
} | ||
|
||
const redirect = | ||
CreateURL('/fetch/api/resources/redirect.py', REMOTE_ORIGIN, | ||
[{name: 'redirect_status', value: 303}, | ||
{name: 'location', value: DESTINATION.href}]); | ||
|
||
promise_test(async (test) => { | ||
const res = await fetch(redirect.href, {mode: 'no-cors'}); | ||
|
||
assert_equals(res.type, 'opaque'); | ||
}, 'original => remote => original with mode: "no-cors"'); | ||
|
||
promise_test(async (test) => { | ||
const res = await fetch(redirect.href, {mode: 'cors'}); | ||
assert_equals(res.type, 'cors'); | ||
}, 'original => remote => original with mode: "cors"'); | ||
|
||
done(); |