CORS tests: Some bug fixes
authorOdin Hørthe Omdal <odinho@opera.com>
Fri, 24 Aug 2012 11:03:38 +0200
changeset 71 746643cbf781
parent 70 54aca18ba6c3
child 72 b78c75181d7f
CORS tests: Some bug fixes
tests/cors/submitted/opera/js/credentials-flag.htm
tests/cors/submitted/opera/js/errors-sync.htm
tests/cors/submitted/opera/js/origin.htm
tests/cors/submitted/opera/js/preflight-cache.htm
tests/cors/submitted/opera/js/redirect-preflight.htm
tests/cors/submitted/opera/js/redirect.htm
tests/cors/submitted/opera/js/request.htm
tests/cors/submitted/opera/js/simple-requests.htm
tests/cors/submitted/opera/js/status.htm
tests/cors/submitted/opera/js/support.js
--- a/tests/cors/submitted/opera/js/credentials-flag.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/credentials-flag.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -17,7 +17,7 @@
     /*
      * widthCredentials
      */
-
+// XXX Do some https tests here as well
     test(function () {
         var id = new Date().getTime(),
             client = new XMLHttpRequest()
@@ -82,7 +82,7 @@
                 CROSSDOMAIN + 'resources/cors-makeheader.php?credentials=' + allow,
                 false)
             client.withCredentials = true;
-            assert_throws('NETWORK_ERR', function() { client.send() }, 'send')
+            assert_throws(null, function() { client.send() }, 'send')
         }, 'Access-Control-Allow-Credentials: ' + allow + ' => should throw NETWORK_ERR (sync)')
 
         var resp_test = async_test('Access-Control-Allow-Credentials: ' + allow + ' => should trigger onerror (async)')
--- a/tests/cors/submitted/opera/js/errors-sync.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/errors-sync.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -18,7 +18,7 @@
     test(function() {
         var client = new XMLHttpRequest()
         client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none', false)
-        assert_throws('NETWORK_ERR', function() { client.send() }, 'send');
+        assert_throws(null, function() { client.send() }, 'send');
         assert_equals(client.status, 0, "status")
         assert_equals(client.readyState, client.DONE, "readyState")
     }, 'Failed sync cross origin request')
@@ -32,7 +32,7 @@
             if (client.readyState == client.DONE)
                 t.done()
         })
-        assert_throws('NETWORK_ERR', function() { client.send() }, 'send');
+        assert_throws(null, function() { client.send() }, 'send');
     });
 
     </script>
--- a/tests/cors/submitted/opera/js/origin.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/origin.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -44,7 +44,7 @@
                                 + '/resources/cors-makeheader.php?origin='
                                 + encodeURIComponent(origin),
                         false)
-            assert_throws('NETWORK_ERR', function() { client.send() }, 'send')
+            assert_throws(null, function() { client.send() }, 'send')
         }, 'Allow origin: ' + origin + ' should throw NETWORK_ERR');
     }
 
--- a/tests/cors/submitted/opera/js/preflight-cache.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/preflight-cache.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -53,7 +53,7 @@
         var time = new Date().getTime()
         var client = new XMLHttpRequest()
 
-        did_preflight(true, client, test_c + '_' + time)
+        did_preflight(true,  client, test_c + '_' + time)
         did_preflight(false, client, test_c + '_' + time)
     },
     'preflight for x-print should be cached')
@@ -85,11 +85,11 @@
             dothing = function (url, msg, setrequest, func) {
                 client = new XMLHttpRequest(),
                 client.open('GET', url + test_c + time, true)
-                if (setrequest)
+                if (setrequest.length > 1)
                     client.setRequestHeader('x-print', msg)
                 client.onreadystatechange = test.step_func(function() {
                     if(client.readyState >= 4) {
-                        assert_equals(msg, client.response)
+                        assert_equals(client.response, msg, "response")
                         if (func)
                             test.step(func)
                     }
@@ -98,7 +98,6 @@
                     assert_unreached("Got unexpected error event on the XHR object")
                 })
                 client.send()
-                console.log(client)
             }
 
         test.step(function() {
@@ -127,7 +126,7 @@
                                     test = test;
 
                                     /* Expect that we did indeed do a preflight */
-                                    dothing('resources/checkandremovefromlog.php?ident=',
+                                    dothing('resources/checkandremovefromlog.php?cache_bust&ident=',
                                     '1', false, function(){
                                         test.done()
                                     })
--- a/tests/cors/submitted/opera/js/redirect-preflight.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/redirect-preflight.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -27,7 +27,7 @@
                                + '&code=' + code + '&preflight=' + code + '&' + req_c++,
                         false)
             client.setRequestHeader('x-test', 'test')
-            assert_throws('NETWORK_ERR', function() { client.send(null) });
+            assert_throws(null, function() { client.send(null) });
 
         },
         'Redirect ' + code + ' on preflight')
@@ -49,7 +49,7 @@
                                + encodeURIComponent(redirect) + '&code=' + code + '&' + req_c++,
                         false)
             client.setRequestHeader('x-test', 'test')
-            assert_throws('NETWORK_ERR', function() { client.send(null) });
+            assert_throws(null, function() { client.send(null) });
 
         },
         'Redirect ' + code + ' after succesful (200) preflight')
--- a/tests/cors/submitted/opera/js/redirect.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/redirect.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -17,143 +17,6 @@
      * Redirection
      */
 
-    test(function() {
-        var client = new XMLHttpRequest()
-        client.open('GET', 'resources/cors-makeheader.php?origin=none&location='
-                            + CROSSDOMAIN + 'resources/cors-headers.php&' + req_c++,
-                    false)
-        client.send(null)
-
-        assert_equals(client.response, 'TEST')
-    },
-    'Local redirect to remote resource')
-
-    test(function() {
-        var client = new XMLHttpRequest()
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none&location='
-                           + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
-                    false)
-        assert_throws('NETWORK_ERR', function () { client.send(null) } )
-    },
-    'Remote redirect without Allow-Origin')
-
-    test(function() {
-        var client = new XMLHttpRequest()
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=*&location='
-                           + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
-                    false)
-        client.send(null)
-
-        assert_equals(client.response, 'TEST')
-    },
-    'Remote redirect with Allow-Origin * to local resource')
-
-    test(function() {
-        var client = new XMLHttpRequest()
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=&location='
-                           + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
-                    false)
-        assert_throws('NETWORK_ERR', function () { client.send(null) } )
-    },
-    'Remote redirect with empty Allow-Origin to local resource')
-
-    test(function() {
-        var client = new XMLHttpRequest()
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
-                           + location.protocol + "//" + location.host+'&location='
-                           + dirname(location.href) + 'resources/cors-headers.php&' + req_c++,
-                    false)
-        client.send(null)
-
-        assert_equals(client.response, 'TEST')
-    },
-    'Remote redirect with Allow-Origin http://' + location.host +' to local resource')
-
-    test(function() {
-        var client = new XMLHttpRequest()
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
-                           + location.protocol + "//" + location.host + '&location='
-                           + CROSSDOMAIN + 'resources/cors-headers.php&' + req_c++,
-                    false)
-        client.send(null)
-
-        assert_equals(client.response, 'TEST')
-    },
-    'Remote redirect with Allow-Origin http://'
-        + location.host + ' to remote resource')
-
-    test(function() {
-        var client = new XMLHttpRequest(),
-            redir3 = dirname(location.href)
-                    + "resources/cors-makeheader.php?origin=none&get_value=NyanNyan&" + req_c++,
-            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?origin=*&location='
-                     + encodeURIComponent(redir3) + "&" + req_c++
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
-                           + location.protocol + "//" + location.host + '&location='
-                           + encodeURIComponent(redir2) + '&' + req_c++,
-                    false)
-        client.send(null)
-
-        r = JSON.parse(client.response)
-        assert_equals(r['get_value'], 'NyanNyan', 'Should meow')
-    },
-    'Remote redirect with Allow-Origin to remote redirect with Allow-Origin * to local resource')
-
-    test(function() {
-        var client = new XMLHttpRequest(),
-            redir3 = dirname(location.href)
-                    + "resources/cors-makeheader.php?origin=http://example.net&get_value=Cool&" + req_c++,
-            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?location='
-                     + encodeURIComponent(redir3) + '&' + req_c++
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin=*'
-                           + '&location=' + encodeURIComponent(redir2) + '&' + req_c++,
-                    false)
-        client.send(null)
-
-        r = JSON.parse(client.response)
-        assert_equals(r['get_value'], 'Cool')
-    },
-    'Remote redirect with Allow-Origin * to remote redirect with Allow-Origin to local resource with Allow-Origin example.net')
-
-    test(function() {
-        var client = new XMLHttpRequest(),
-            redir2 = dirname(location.href) + 'resources/cors-makeheader.php?origin=none&location='
-                     + CROSSDOMAIN + 'resources/cors-makeheader.php&' + req_c++
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?location='
-                           + encodeURIComponent(redir2) + '&' + req_c++,
-                    false)
-        client.send(null)
-
-        r = JSON.parse(client.response)
-        assert_equals(r['origin'], location.protocol + "//" + location.host)
-    },
-    'Remote redirect with Allow-Origin to local redirect without Allow-Origin to remote resource with Allow_origin')
-
-    test(function() {
-        var client = new XMLHttpRequest(),
-            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?origin=none&' + req_c++
-
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
-                           + location.protocol + "//" + location.host + '&location='
-                           + encodeURIComponent(redir2) + '&' + req_c++,
-                    false)
-        assert_throws('NETWORK_ERR', function () { client.send(null) } )
-    },
-    'Remote redirect with Allow-Origin to remote resource without Allow-Origin')
-
-    test(function() {
-        var client = new XMLHttpRequest(),
-            redir2 = CROSSDOMAIN + 'resources/cors-makeheader.php?origin=null&' + req_c++
-
-        client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?origin='
-                           + location.protocol + "//" + location.host + '&location='
-                           + encodeURIComponent(redir2) + '&' + req_c++,
-                    false)
-        assert_throws('NETWORK_ERR', function () { client.send(null) } )
-    },
-    'Remote redirect with Allow-Origin to remote resource with Allow-Origin null')
-
-
     function redir(code) {
         test(function() {
             var client = new XMLHttpRequest(),
--- a/tests/cors/submitted/opera/js/request.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/request.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -48,7 +48,7 @@
         client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.php?headers=x-print', false)
         client.setRequestHeader('x-print', 'unicorn')
         client.setRequestHeader('y-print', 'unicorn')
-        assert_throws('NETWORK_ERR', function() { client.send(null) })
+        assert_throws(null, function() { client.send(null) })
     }, 'NETWORK_ERR on disallowed request header')
 
     test(function() {
--- a/tests/cors/submitted/opera/js/simple-requests.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/simple-requests.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -39,7 +39,7 @@
             client.send("data")
             assert_equals(client.response, "0", "Found preflight log")
         },
-        'no preflight on ' + method + ' and request headers ' + JSON.stringify(headers))
+        'No preflight ' + method + ' and ' + JSON.stringify(headers))
     }
 
     function check_simple_headers(headers) {
--- a/tests/cors/submitted/opera/js/status.htm	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/status.htm	Fri Aug 24 11:03:38 2012 +0200
@@ -5,6 +5,8 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="support.js"></script>
 
+<h1>The returned status code in different scenarios</h1>
+
 <pre>
    allowed  preflight  response  | status |
    -------  ---------  --------  | ------ |
--- a/tests/cors/submitted/opera/js/support.js	Fri Jun 08 16:09:53 2012 +0200
+++ b/tests/cors/submitted/opera/js/support.js	Fri Aug 24 11:03:38 2012 +0200
@@ -17,7 +17,9 @@
 
 /* This subdomain should point to this same location */
 var SUBDOMAIN = 'www1'
+var SUBDOMAIN2 = 'www2'
 var PORT = "8081"
+var PORTS = "8443"
 
 /* Changes http://example.com/abc/def/cool.htm to http://www1.example.com/abc/def/ */
 var CROSSDOMAIN = dirname(location.href)