Bug 1206124 - P2 Test fetch() with credentials and redirects. r=ehsan, a=test-only
authorBen Kelly <ben@wanderview.com>
Wed, 07 Oct 2015 14:33:31 -0700
changeset 296358 60f2b7ff359d8f61fc82f144192f25afb3955132
parent 296357 59ab27502812102915fad249f9cc6aa18f36dd4f
child 296359 ff125ed4c17497db3502be57cb23f68d649a6186
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, test-only
bugs1206124
milestone43.0a2
Bug 1206124 - P2 Test fetch() with credentials and redirects. r=ehsan, a=test-only
dom/tests/mochitest/fetch/test_fetch_cors.js
--- a/dom/tests/mochitest/fetch/test_fetch_cors.js
+++ b/dom/tests/mochitest/fetch/test_fetch_cors.js
@@ -795,16 +795,17 @@ function testModeCors() {
       });
     })(test));
   }
 
   return Promise.all(fetches);
 }
 
 function testCrossOriginCredentials() {
+  var origin = "http://mochi.test:8888";
   var tests = [
            { pass: 1,
              method: "GET",
              withCred: "include",
              allowCred: 1,
            },
            { pass: 0,
              method: "GET",
@@ -885,30 +886,144 @@ function testCrossOriginCredentials() {
              // cookie should be sent cross origin. This test checks the same
              // thing as above, but uses the noCookie check on the server
              // instead, and expects a valid response.
              pass: 1,
              method: "GET",
              noCookie: 1,
              withCred: "same-origin",
            },
+           {
+             // Initialize by setting a cookies for same- and cross- origins.
+             pass: 1,
+             hops: [{ server: origin,
+                      setCookie: escape("a=1"),
+                    },
+                    { server: "http://example.com",
+                      allowOrigin: origin,
+                      allowCred: 1,
+                      setCookie: escape("a=2"),
+                    },
+                    ],
+             withCred: "include",
+           },
+           { pass: 1,
+             method: "GET",
+             hops: [{ server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: "http://example.com",
+                      allowOrigin: origin,
+                      noCookie: 1,
+                    },
+                    ],
+             withCred: "same-origin",
+           },
+           { pass: 1,
+             method: "GET",
+             hops: [{ server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: "http://example.com",
+                      allowOrigin: origin,
+                      allowCred: 1,
+                      cookie: escape("a=2"),
+                    },
+                    ],
+             withCred: "include",
+           },
+           { pass: 1,
+             method: "GET",
+             hops: [{ server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: "http://example.com",
+                      allowOrigin: '*',
+                      noCookie: 1,
+                    },
+                    ],
+             withCred: "same-origin",
+           },
+           { pass: 0,
+             method: "GET",
+             hops: [{ server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: "http://example.com",
+                      allowOrigin: '*',
+                      allowCred: 1,
+                      cookie: escape("a=2"),
+                    },
+                    ],
+             withCred: "include",
+           },
+           // fails because allow-credentials CORS header is not set by server
+           { pass: 0,
+             method: "GET",
+             hops: [{ server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: origin,
+                      cookie: escape("a=1"),
+                    },
+                    { server: "http://example.com",
+                      allowOrigin: origin,
+                      cookie: escape("a=2"),
+                    },
+                    ],
+             withCred: "include",
+           },
+           { pass: 1,
+             method: "GET",
+             hops: [{ server: origin,
+                      noCookie: 1,
+                    },
+                    { server: origin,
+                      noCookie: 1,
+                    },
+                    { server: "http://example.com",
+                      allowOrigin: origin,
+                      noCookie: 1,
+                    },
+                    ],
+             withCred: "omit",
+           },
            ];
 
   var baseURL = "http://example.org" + corsServerPath;
   var origin = "http://mochi.test:8888";
 
   var finalPromiseResolve, finalPromiseReject;
   var finalPromise = new Promise(function(res, rej) {
     finalPromiseResolve = res;
     finalPromiseReject = rej;
   });
 
   function makeRequest(test) {
+    var url;
+    if (test.hops) {
+      url = test.hops[0].server + corsServerPath + "hop=1&hops=" +
+            escape(test.hops.toSource());
+    } else {
+      url = baseURL + "allowOrigin=" + escape(test.origin || origin);
+    }
     req = {
-      url: baseURL + "allowOrigin=" + escape(test.origin || origin),
+      url: url,
       method: test.method,
       headers: test.headers,
       withCred: test.withCred,
     };
 
     if (test.allowCred)
       req.url += "&allowCred";