Bug 1407695 - Do not return expiry key for session cookies; r?whimboo draft
authorØyvind Strømmen <insula.ventus@gmail.com>
Mon, 16 Oct 2017 22:42:48 +0200
changeset 685555 7962edeab31b69446997f72b4558d4967b7e0c41
parent 684402 87fabdfb091511300f89b0b51d8f472459d4a41c
child 685556 77658db2e3dbb1ce91a0702cc044eac14ea470aa
push id85969
push userbmo:insula.ventus@gmail.com
push dateTue, 24 Oct 2017 20:00:56 +0000
reviewerswhimboo
bugs1407695
milestone58.0a1
Bug 1407695 - Do not return expiry key for session cookies; r?whimboo MozReview-Commit-ID: H1CctBpOOdM
testing/marionette/cookie.js
testing/marionette/test_cookie.js
--- a/testing/marionette/cookie.js
+++ b/testing/marionette/cookie.js
@@ -201,22 +201,27 @@ cookie.iter = function* (host, currentPa
   let en = cookie.manager.getCookiesFromHost(host, {});
   while (en.hasMoreElements()) {
     let cookie = en.getNext().QueryInterface(Ci.nsICookie2);
     // take the hostname and progressively shorten
     let hostname = host;
     do {
       if ((cookie.host == "." + hostname || cookie.host == hostname) &&
           isForCurrentPath(cookie.path)) {
-        yield {
+        let data = {
           "name": cookie.name,
           "value": cookie.value,
           "path": cookie.path,
           "domain": cookie.host,
           "secure": cookie.isSecure,
           "httpOnly": cookie.isHttpOnly,
-          "expiry": cookie.expiry,
         };
+
+        if (!cookie.isSession) {
+          data.expiry = cookie.expiry;
+        }
+
+        yield data;
       }
       hostname = hostname.replace(/^.*?\./, "");
     } while (hostname.indexOf(".") != -1);
   }
 };
--- a/testing/marionette/test_cookie.js
+++ b/testing/marionette/test_cookie.js
@@ -19,17 +19,17 @@ cookie.manager = {
       isHttpOnly: httpOnly,
       isSession: session,
       expiry: expiry,
       originAttributes: originAttributes,
     };
     cookie.manager.cookies.push(newCookie);
   },
 
-  remove: function (host, name, path, blocked, originAttributes) {;
+  remove: function (host, name, path, blocked, originAttributes) {
     for (let i = 0; i < this.cookies.length; ++i) {
       let candidate = this.cookies[i];
       if (candidate.host === host &&
           candidate.name === name &&
           candidate.path === path) {
         return this.cookies.splice(i, 1);
       }
     }
@@ -243,16 +243,44 @@ add_test(function test_remove() {
   equal(undefined, cookie.manager.cookies[0]);
 
   run_next_test();
 });
 
 add_test(function test_iter() {
   cookie.manager.cookies = [];
 
-  cookie.add({name: "0", value: "", domain: "foo.example.com"});
-  cookie.add({name: "1", value: "", domain: "bar.example.com"});
+  cookie.add({
+    session: false,
+    name: "0",
+    value: "",
+    domain: "foo.example.com",
+  });
+  cookie.add({
+    session: false,
+    name: "1",
+    value: "",
+    domain: "bar.example.com",
+  });
+
   let fooCookies = [...cookie.iter("foo.example.com")];
   equal(1, fooCookies.length);
   equal(".foo.example.com", fooCookies[0].domain);
+  equal(true, fooCookies[0].hasOwnProperty("expiry"));
+
+  // here we're explicitly setting session to true as a workaround until
+  // bug 1408962 has been fixed. when that bug has been fixed the cookie
+  // will be created as session cookie simply by leaving out the 'expiry'
+  // property.
+  cookie.add({
+    session: true,
+    name: "aSessionCookie",
+    value: "",
+    domain: "session.com",
+  });
+
+  let sessionCookies = [...cookie.iter("session.com")];
+  equal(1, sessionCookies.length);
+  equal("aSessionCookie", sessionCookies[0].name);
+  equal(false, sessionCookies[0].hasOwnProperty("expiry"));
 
   run_next_test();
 });