-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use async XHR and test that non-2XX preflight responses raise errors
- Loading branch information
Showing
2 changed files
with
74 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<title>CORS - Preflight responds with non-2XX status code</title> | ||
<meta name=author title="Fernando Jiménez Moreno" href="mailto:[email protected]"> | ||
|
||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=support.js?pipe=sub></script> | ||
|
||
<h1>Preflight responds with non-2XX status code</h1> | ||
|
||
<div id=log></div> | ||
<script> | ||
|
||
// Request count for cache busting and easy identifying of request in traffic | ||
// analyzer. | ||
var req_c = 0; | ||
|
||
var CROSSDOMAIN_URL = CROSSDOMAIN + 'resources/cors-makeheader.py?'; | ||
|
||
/* | ||
* Redirection with preflights. | ||
*/ | ||
function preflight_failure(code) { | ||
var desc = 'Should throw error if preflight respond with ' + code; | ||
async_test(desc).step(function() { | ||
var client = new XMLHttpRequest(); | ||
var redirect = | ||
encodeURIComponent(CROSSDOMAIN_URL + 'headers=x-test&' + req_c++); | ||
|
||
client.open('GET', | ||
CROSSDOMAIN_URL + 'headers=x-test&location=' + redirect | ||
+ '&code=' + code + '&preflight=' + code | ||
+ '&' + req_c++, | ||
true /* async */); | ||
client.setRequestHeader('x-test', 'test'); | ||
client.onerror = this.step_func(function() { | ||
this.done(); | ||
}); | ||
client.onreadystatechange = this.step_func(function() { | ||
assert_equals(client.status, 0); | ||
}); | ||
client.onload = this.step_func(function() { | ||
assert_unreached('Unexpected onload'); | ||
}); | ||
client.send(null); | ||
}); | ||
} | ||
[100, 101, | ||
300, 301, 302, 303, 304, 305, 306, 307, 308, | ||
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, | ||
500, 501, 502, 503, 504, 505].forEach(preflight_failure); | ||
|
||
</script> |
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