Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/access-control-and-redirects-async.html

Issue 14557011: Fix problems with cross-origin redirects. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed typo in numbering in a test. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <p>Tests that asynchronous XMLHttpRequests handle redirects according to the COR S standard.</p> 1 <p>Tests that asynchronous XMLHttpRequests handle redirects according to the COR S standard.</p>
2 2
3 <pre id="console"></pre> 3 <pre id="console"></pre>
4 <script> 4 <script>
5 if (window.testRunner) { 5 if (window.testRunner) {
6 testRunner.dumpAsText(); 6 testRunner.dumpAsText();
7 testRunner.waitUntilDone(); 7 testRunner.waitUntilDone();
8 } 8 }
9 9
10 function log(message) 10 function log(message)
11 { 11 {
12 document.getElementById('console').appendChild(document.createTextNode(messa ge + '\n')); 12 document.getElementById('console').appendChild(document.createTextNode(messa ge + '\n'));
13 } 13 }
14 14
15 function runTestAsync(url, addCustomHeader, expectSuccess) { 15 function runTestAsync(url, credentials, addCustomHeader, expectSuccess) {
16 log("Testing " + url); 16 log("Testing " + url + (credentials ? " with " : " without ") + "credentials ");
17 log("Expecting success: " + expectSuccess); 17 log("Expecting success: " + expectSuccess);
18 18
19 xhr = new XMLHttpRequest(); 19 xhr = new XMLHttpRequest();
20 xhr.withCredentials = credentials;
20 xhr.open("GET", url, true); 21 xhr.open("GET", url, true);
21 if (addCustomHeader) 22 if (addCustomHeader)
22 xhr.setRequestHeader("x-webkit", "foo"); 23 xhr.setRequestHeader("x-webkit", "foo");
23 24
24 xhr.onload = function() { 25 xhr.onload = function() {
25 log((expectSuccess ? "PASS" : "FAIL") + ": " + xhr.responseText); 26 log((expectSuccess ? "PASS" : "FAIL") + ": " + xhr.responseText);
26 nextTest(); 27 nextTest();
27 } 28 }
28 xhr.onerror = function() { 29 xhr.onerror = function() {
29 log((expectSuccess ? "FAIL" : "PASS") + ": " + xhr.status); 30 log((expectSuccess ? "FAIL" : "PASS") + ": " + xhr.status);
30 nextTest(); 31 nextTest();
31 } 32 }
32 xhr.send(null); 33 xhr.send(null);
33 } 34 }
34 35
36 var withoutCredentials = false;
37 var withCredentials = true;
35 var noCustomHeader = false; 38 var noCustomHeader = false;
36 var addCustomHeader = true; 39 var addCustomHeader = true;
37 var succeeds = true; 40 var succeeds = true;
38 var fails = false; 41 var fails = false;
39 42
40 var tests = [ 43 var tests = [
41 // 1) Test simple same origin requests that receive cross origin redirects. 44 // 1) Test simple cross origin requests that receive redirects.
42
43 // Request receives a cross-origin redirect response without CORS headers. The r edirect response fails the access check.
44 ["resources/redirect-cors.php?url=http://localhost:8000/xmlhttprequest/resources /access-control-basic-allow-star.cgi",
45 noCustomHeader, fails],
46
47 // Request receives a cross-origin redirect response with CORS headers. The redi rect response passes the access check,
48 // but the resource response fails its access check because the security origin is a globally unique identifier after
49 // the redirect and the same origin XHR has 'allowCredentials' true.
50 ["resources/redirect-cors.php?url=http://localhost:8000/xmlhttprequest/resources /access-control-basic-allow-star.cgi&\
51 access-control-allow-origin=http://localhost:8000&\
52 access-control-allow-credentials=true",
53 noCustomHeader, fails],
54
55 // Same as above, but to a less permissive resource that only allows the request ing origin.
56 ["resources/redirect-cors.php?url=http://localhost:8000/xmlhttprequest/resources /access-control-basic-allow.cgi&\
57 access-control-allow-origin=http://localhost:8000&\
58 access-control-allow-credentials=true",
59 noCustomHeader, fails],
60
61 // 2) Test simple cross origin requests that receive redirects.
62 45
63 // Receives a redirect response without CORS headers. The redirect response fail s the access check. 46 // Receives a redirect response without CORS headers. The redirect response fail s the access check.
64 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=http://lo calhost:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi", 47 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=http://lo calhost:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi",
65 noCustomHeader, fails], 48 withoutCredentials, noCustomHeader, fails],
66 49
67 // Receives a redirect response with CORS headers. The redirect response passes the access check and the resource response 50 // Receives a redirect response with CORS headers. The redirect response passes the access check and the resource response
68 // passes the access check. 51 // passes the access check.
52 // FIXME: this test fails because the redirect is vetoed. There are continued bu gs with redirects when the original
53 // request was cross-origin.
69 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=http://lo calhost:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi&\ 54 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=http://lo calhost:8000/xmlhttprequest/resources/access-control-basic-allow-star.cgi&\
70 access-control-allow-origin=http://localhost:8000", 55 access-control-allow-origin=http://localhost:8000",
71 noCustomHeader, succeeds], 56 withoutCredentials, noCustomHeader, succeeds],
72 57
73 // Receives a redirect response with a URL containing the userinfo production. 58 // Receives a redirect response with a URL containing the userinfo production.
74 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=http://us ername:password@localhost:8000/xmlhttprequest/resources/access-control-basic-all ow-star.cgi&\ 59 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=http://us ername:password@localhost:8000/xmlhttprequest/resources/access-control-basic-all ow-star.cgi&\
75 access-control-allow-origin=http://localhost:8000", 60 access-control-allow-origin=http://localhost:8000",
76 noCustomHeader, fails], 61 withoutCredentials, noCustomHeader, fails],
77 62
78 // Receives a redirect response with a URL with an unsupported scheme. 63 // Receives a redirect response with a URL with an unsupported scheme.
79 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=foo://bar .cgi&\ 64 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?url=foo://bar .cgi&\
80 access-control-allow-origin=http://localhost:8000", 65 access-control-allow-origin=http://localhost:8000",
81 noCustomHeader, fails], 66 withoutCredentials, noCustomHeader, fails],
82 67
83 // 3) Test preflighted cross origin requests that receive redirects. 68 // 2) Test preflighted cross origin requests that receive redirects.
84 69
85 // Receives a redirect response to the preflight request and fails. 70 // Receives a redirect response to the preflight request and fails.
86 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?redirect-pref light=true&\ 71 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?redirect-pref light=true&\
87 url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow- star.cgi&\ 72 url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow- star.cgi&\
88 access-control-allow-origin=*", 73 access-control-allow-origin=*",
89 addCustomHeader, fails], 74 withoutCredentials, addCustomHeader, fails],
90 75
91 // Successful preflight and receives a redirect response to the actual request a nd fails. 76 // Successful preflight and receives a redirect response to the actual request a nd fails.
92 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?redirect-pref light=false&\ 77 ["http://localhost:8000/xmlhttprequest/resources/redirect-cors.php?redirect-pref light=false&\
93 url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow- star.cgi&\ 78 url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow- star.cgi&\
94 access-control-allow-origin=*&\ 79 access-control-allow-origin=*&\
95 access-control-allow-headers=x-webkit", 80 access-control-allow-headers=x-webkit",
96 addCustomHeader, fails], 81 withoutCredentials, addCustomHeader, fails],
97 82
98 // 4) Test same origin requests with a custom header that receive a same origin redirect. 83 // 3) Test same origin requests with a custom header that receive a same origin redirect.
99 ["resources/redirect-cors.php?url=http://127.0.0.1:8000/xmlhttprequest/resources /get.txt", 84 ["resources/redirect-cors.php?url=http://127.0.0.1:8000/xmlhttprequest/resources /get.txt",
100 addCustomHeader, succeeds], 85 withoutCredentials, addCustomHeader, succeeds],
86
101 ] 87 ]
102 88
103 var currentTest = 0; 89 var currentTest = 0;
104 90
105 function nextTest() { 91 function nextTest() {
106 if (currentTest < tests.length) 92 if (currentTest < tests.length)
107 runTestAsync.apply(null, tests[currentTest++]); 93 runTestAsync.apply(null, tests[currentTest++]);
108 else if (window.testRunner) 94 else if (window.testRunner)
109 testRunner.notifyDone(); 95 testRunner.notifyDone();
110 } 96 }
111 97
112 nextTest(); 98 nextTest();
113 </script> 99 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698