Skip to content

Commit

Permalink
Bug 1484619 [wpt PR 12566] - Add tests for cross-origin redirects get…
Browse files Browse the repository at this point in the history
…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
marco-c committed Oct 3, 2019
1 parent c27b211 commit d32feff
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions testing/web-platform/meta/MANIFEST.json
Expand Up @@ -351537,6 +351537,16 @@
{}
]
],
"fetch/api/redirect/redirect-back-to-original-origin.any.js": [
[
"/fetch/api/redirect/redirect-back-to-original-origin.any.html",
{}
],
[
"/fetch/api/redirect/redirect-back-to-original-origin.any.worker.html",
{}
]
],
"fetch/api/redirect/redirect-count.any.js": [
[
"/fetch/api/redirect/redirect-count.any.html",
Expand Down Expand Up @@ -586074,6 +586084,10 @@
"8e23770bd6040425b33d5f0d4eb8cff362544c33",
"support"
],
"fetch/api/redirect/redirect-back-to-original-origin.any.js": [
"32d413cb2f16db6753bd71cfa0395ff8bd7efea9",
"testharness"
],
"fetch/api/redirect/redirect-count.any.js": [
"7fa6dd1d0ed5579cc66c16297a61a57cbadd1c74",
"testharness"
Expand Down
@@ -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();

0 comments on commit d32feff

Please sign in to comment.