Changeset 279585 in webkit


Ignore:
Timestamp:
Jul 6, 2021, 9:27:29 AM (4 years ago)
Author:
Chris Dumez
Message:

Resync cookies web-platform-tests from upstream
https://bugs.webkit.org/show_bug.cgi?id=227641

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Resync cookies web-platform-tests from upstream 2c19d6ee62676ac90146.

  • resources/import-expectations.json:
  • web-platform-tests/cookies/*: Updated.

LayoutTests:

Location:
trunk/LayoutTests
Files:
181 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r279582 r279585  
     12021-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Resync cookies web-platform-tests from upstream
     4        https://bugs.webkit.org/show_bug.cgi?id=227641
     5
     6        Reviewed by Darin Adler.
     7
     8        * TestExpectations:
     9        * tests-options.json:
     10
    1112021-07-06  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/LayoutTests/TestExpectations

    r279572 r279585  
    439439imported/w3c/web-platform-tests/clipboard-apis/feature-policy/clipboard-read/clipboard-read-enabled-by-feature-policy.tentative.https.sub.html [ Skip ]
    440440imported/w3c/web-platform-tests/clipboard-apis/feature-policy/clipboard-read/clipboard-read-enabled-on-self-origin-by-feature-policy.tentative.https.sub.html [ Skip ]
     441imported/w3c/web-platform-tests/cookies/domain/domain-attribute-host-with-and-without-leading-period.sub.https.html [ Skip ]
     442imported/w3c/web-platform-tests/cookies/domain/domain-attribute-host-with-leading-period.sub.https.html [ Skip ]
     443imported/w3c/web-platform-tests/cookies/domain/domain-attribute-matches-host.sub.https.html [ Skip ]
     444imported/w3c/web-platform-tests/cookies/domain/domain-attribute-missing.sub.html [ Skip ]
     445imported/w3c/web-platform-tests/cookies/samesite/fetch.https.html [ Skip ]
     446imported/w3c/web-platform-tests/cookies/samesite/form-get-blank-reload.https.html [ Skip ]
     447imported/w3c/web-platform-tests/cookies/samesite/form-get-blank.https.html [ Skip ]
     448imported/w3c/web-platform-tests/cookies/samesite/form-post-blank-reload.https.html [ Skip ]
     449imported/w3c/web-platform-tests/cookies/samesite/form-post-blank.https.html [ Skip ]
     450imported/w3c/web-platform-tests/cookies/samesite/iframe-reload.https.html [ Skip ]
     451imported/w3c/web-platform-tests/cookies/samesite/iframe.https.html [ Skip ]
     452imported/w3c/web-platform-tests/cookies/samesite/img.https.html [ Skip ]
     453imported/w3c/web-platform-tests/cookies/samesite/window-open-reload.https.html [ Skip ]
     454imported/w3c/web-platform-tests/cookies/samesite/window-open.https.html [ Skip ]
    441455imported/w3c/web-platform-tests/geolocation-API/non-secure-contexts.http.html [ Skip ]
    442456imported/w3c/web-platform-tests/geolocation-API/getCurrentPosition_permission_allow.https.html [ Skip ]
     
    646660# Newly imported WPT tests that are flaky.
    647661webkit.org/b/227649 imported/w3c/web-platform-tests/beacon/beacon-basic.https.window.html [ Failure Pass ]
     662imported/w3c/web-platform-tests/cookies/name/name.html [ Failure Pass ]
     663imported/w3c/web-platform-tests/cookies/prefix/__secure.header.https.html [ Failure Pass ]
     664imported/w3c/web-platform-tests/cookies/samesite-none-secure/cookies-without-samesite-must-be-secure.https.tentative.html [ Failure Pass ]
     665imported/w3c/web-platform-tests/cookies/samesite/about-blank-subresource.https.html [ Failure Pass ]
     666imported/w3c/web-platform-tests/cookies/samesite/about-blank-toplevel.https.html [ Failure Pass ]
     667imported/w3c/web-platform-tests/cookies/samesite/iframe.document.https.html [ Failure Pass ]
     668imported/w3c/web-platform-tests/cookies/samesite/multiple-samesite-attributes.https.html [ Failure Pass ]
     669imported/w3c/web-platform-tests/cookies/samesite/sandbox-iframe-nested.https.html [ Failure Pass ]
     670imported/w3c/web-platform-tests/cookies/samesite/sandbox-iframe-subresource.https.html [ Failure Pass ]
     671imported/w3c/web-platform-tests/cookies/samesite/setcookie-lax.https.html [ Failure Pass ]
     672imported/w3c/web-platform-tests/cookies/samesite/setcookie-navigation.https.html [ Failure Pass ]
     673imported/w3c/web-platform-tests/cookies/schemeful-same-site/schemeful-iframe-subresource.tentative.html [ Failure Pass ]
     674imported/w3c/web-platform-tests/cookies/schemeful-same-site/schemeful-navigation.tentative.html [ Failure Pass ]
     675imported/w3c/web-platform-tests/cookies/schemeful-same-site/schemeful-subresource.tentative.html [ Failure Pass ]
    648676imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/microtasks/checkpoint-after-window-onerror-module.html [ Failure Pass ]
    649677imported/w3c/web-platform-tests/html/browsers/windows/targeting-cross-origin-nested-browsing-contexts.html [ Failure Pass ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r279581 r279585  
     12021-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Resync cookies web-platform-tests from upstream
     4        https://bugs.webkit.org/show_bug.cgi?id=227641
     5
     6        Reviewed by Darin Adler.
     7
     8        Resync cookies web-platform-tests from upstream 2c19d6ee62676ac90146.
     9
     10        * resources/import-expectations.json:
     11        * web-platform-tests/cookies/*: Updated.
     12
    1132021-07-06  Antti Koivisto  <antti@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/resources/import-expectations.json

    r279409 r279585  
    7171    "web-platform-tests/console": "import",
    7272    "web-platform-tests/content-security-policy": "import",
    73     "web-platform-tests/cookies": "skip",
     73    "web-platform-tests/cookies": "import",
    7474    "web-platform-tests/cookies/resources": "import",
    7575    "web-platform-tests/cookies/secure": "import",
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/cookie-helper.sub.js

    r253312 r279585  
    22(_ => {
    33  var HOST = "{{host}}";
     4  var INSECURE_PORT = ":{{ports[http][0]}}";
    45  var SECURE_PORT = ":{{ports[https][0]}}";
    5   var PORT = ":{{ports[http][0]}}";
    66  var CROSS_ORIGIN_HOST = "{{hosts[alt][]}}";
    7   var SECURE_CROSS_ORIGIN_HOST = "{{hosts[alt][]}}";
     7
     8  window.INSECURE_ORIGIN = "http://" + HOST + INSECURE_PORT;
    89
    910  //For secure cookie verification
    1011  window.SECURE_ORIGIN = "https://" + HOST + SECURE_PORT;
    11   window.INSECURE_ORIGIN = "http://" + HOST + PORT;
    1212
    1313  //standard references
    14   window.ORIGIN = "http://" + HOST + PORT;
    15   window.WWW_ORIGIN = "http://{{domains[www]}}" + PORT;
    16   window.SUBDOMAIN_ORIGIN = "http://{{domains[www1]}}" + PORT;
    17   window.CROSS_SITE_ORIGIN = "http://" + CROSS_ORIGIN_HOST + PORT;
    18   window.SECURE_CROSS_SITE_ORIGIN = "https://" + SECURE_CROSS_ORIGIN_HOST + SECURE_PORT;
    19   window.CROSS_SITE_HOST = SECURE_CROSS_ORIGIN_HOST;
     14  window.SECURE_SUBDOMAIN_ORIGIN = "https://{{domains[www1]}}" + SECURE_PORT;
     15  window.SECURE_CROSS_SITE_ORIGIN = "https://" + CROSS_ORIGIN_HOST + SECURE_PORT;
     16  window.CROSS_SITE_HOST = CROSS_ORIGIN_HOST;
    2017
    2118  // Set the global cookie name.
    2219  window.HTTP_COOKIE = "cookie_via_http";
    23 
    24   // If we're not on |HOST|, move ourselves there:
    25   if (window.location.hostname != HOST)
    26     window.location.hostname = HOST;
    2720})();
    2821
    2922// A tiny helper which returns the result of fetching |url| with credentials.
    3023function credFetch(url) {
    31   return fetch(url, {"credentials": "include"});
     24  return fetch(url, {"credentials": "include"})
     25    .then(response => {
     26      if (response.status !== 200) {
     27        throw new Error(response.statusText);
     28      }
     29      return response;
     30    });
    3231}
    3332
     
    3534function redirectTo(origin, url) {
    3635  return origin + "/cookies/resources/redirectWithCORSHeaders.py?status=307&location=" + encodeURIComponent(url);
     36}
     37
     38// Returns a URL on |origin| which navigates the window to the given URL (by
     39// setting window.location).
     40function navigateTo(origin, url) {
     41  return origin + "/cookies/resources/navigate.html?location=" + encodeURIComponent(url);
    3742}
    3843
     
    7378  promise_test(t => {
    7479    var name = options.prefix + "prefixtestcookie";
    75     erase_cookie_from_js(name);
     80    erase_cookie_from_js(name, options.params);
     81    t.add_cleanup(() => erase_cookie_from_js(name, options.params));
    7682    var value = "" + Math.random();
    7783    document.cookie = name + "=" + value + ";" + options.params;
     
    8793function set_prefixed_cookie_via_http_test(options) {
    8894  promise_test(t => {
    89     var postDelete = _ => {
    90       var value = "" + Math.random();
    91       return credFetch(options.origin + "/cookies/resources/set.py?" + name + "=" + value + ";" + options.params)
    92         .then(_ => credFetch(options.origin + "/cookies/resources/list.py"))
    93         .then(r => r.json())
    94         .then(cookies => assert_equals(cookies[name], options.shouldExistViaHTTP ? value : undefined));
    95     };
    96 
    9795    var name = options.prefix + "prefixtestcookie";
    98     if (!options.origin) {
    99       options.origin = self.origin;
    100       erase_cookie_from_js(name);
    101       return postDelete;
    102     } else {
    103       return credFetch(options.origin + "/cookies/resources/drop.py?name=" + name)
    104         .then(_ => postDelete());
    105     }
     96    var value = "" + Math.random();
     97
     98    t.add_cleanup(() => {
     99      var cookie = name + "=0;expires=" + new Date(0).toUTCString() + ";" +
     100        options.params;
     101
     102      return credFetch(options.origin + "/cookies/resources/set.py?" + cookie);
     103    });
     104
     105    return credFetch(options.origin + "/cookies/resources/set.py?" + name + "=" + value + ";" + options.params)
     106      .then(_ => credFetch(options.origin + "/cookies/resources/list.py"))
     107      .then(r => r.json())
     108      .then(cookies => assert_equals(cookies[name], options.shouldExistViaHTTP ? value : undefined));
    106109  }, options.title);
    107110}
     
    111114//
    112115
     116// status for "network" cookies.
    113117window.SameSiteStatus = {
    114118  CROSS_SITE: "cross-site",
     
    116120  STRICT: "strict"
    117121};
     122// status for "document.cookie".
     123window.DomSameSiteStatus = {
     124  CROSS_SITE: "cross-site",
     125  SAME_SITE: "same-site",
     126};
     127
     128const wait_for_message = (type, origin) => {
     129  return new Promise((resolve, reject) => {
     130    window.addEventListener('message', e => {
     131      if (origin && e.origin != origin) {
     132        reject("Message from unexpected origin in wait_for_message:" + e.origin);
     133        return;
     134      }
     135
     136      if (e.data.type && e.data.type === type)
     137        resolve(e);
     138    }, { once: true });
     139  });
     140};
    118141
    119142// Reset SameSite test cookies on |origin|. If |origin| matches `self.origin`, assert
    120143// (via `document.cookie`) that they were properly removed and reset.
    121 function resetSameSiteCookies(origin, value) {
    122   return credFetch(origin + "/cookies/resources/dropSameSite.py")
    123     .then(_ => {
    124       if (origin == self.origin) {
    125         assert_dom_cookie("samesite_strict", value, false);
    126         assert_dom_cookie("samesite_lax", value, false);
    127         assert_dom_cookie("samesite_none", value, false);
    128       }
    129     })
    130     .then(_ => {
    131       return credFetch(origin + "/cookies/resources/setSameSite.py?" + value)
    132         .then(_ => {
    133           if (origin == self.origin) {
    134             assert_dom_cookie("samesite_strict", value, true);
    135             assert_dom_cookie("samesite_lax", value, true);
    136             assert_dom_cookie("samesite_none", value, true);
    137           }
    138         })
    139     })
     144async function resetSameSiteCookies(origin, value) {
     145  let w = window.open(origin + "/cookies/samesite/resources/puppet.html");
     146  try {
     147    await wait_for_message("READY", origin);
     148    w.postMessage({type: "drop", useOwnOrigin: true}, "*");
     149    await wait_for_message("drop-complete", origin);
     150    if (origin == self.origin) {
     151      assert_dom_cookie("samesite_strict", value, false);
     152      assert_dom_cookie("samesite_lax", value, false);
     153      assert_dom_cookie("samesite_none", value, false);
     154      assert_dom_cookie("samesite_unspecified", value, false);
     155    }
     156
     157    w.postMessage({type: "set", value: value, useOwnOrigin: true}, "*");
     158    await wait_for_message("set-complete", origin);
     159    if (origin == self.origin) {
     160      assert_dom_cookie("samesite_strict", value, true);
     161      assert_dom_cookie("samesite_lax", value, true);
     162      assert_dom_cookie("samesite_none", value, true);
     163      assert_dom_cookie("samesite_unspecified", value, true);
     164    }
     165  } finally {
     166    w.close();
     167  }
    140168}
    141169
    142170// Given an |expectedStatus| and |expectedValue|, assert the |cookies| contains the
    143 // proper set of cookie names and values.
    144 function verifySameSiteCookieState(expectedStatus, expectedValue, cookies) {
    145     assert_equals(cookies["samesite_none"], expectedValue, "Non-SameSite cookies are always sent.");
     171// proper set of cookie names and values, according to the legacy behavior where
     172// unspecified SameSite attribute defaults to SameSite=None behavior.
     173function verifySameSiteCookieStateLegacy(expectedStatus, expectedValue, cookies, domCookieStatus) {
     174    assert_equals(cookies["samesite_none"], expectedValue, "SameSite=None cookies are always sent.");
     175    assert_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are always sent.");
    146176    if (expectedStatus == SameSiteStatus.CROSS_SITE) {
    147177      assert_not_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are not sent with cross-site requests.");
     
    154184      assert_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are sent with strict requests.");
    155185    }
     186
     187    if (cookies["domcookies"]) {
     188      verifyDocumentCookieLegacy(domCookieStatus, expectedValue, cookies["domcookies"]);
     189    }
     190}
     191
     192// Same as above except this expects samesite_unspecified to act the same as
     193// samesite_lax (which is the behavior expected when SameSiteByDefault is
     194// enabled).
     195function verifySameSiteCookieStateWithSameSiteByDefault(expectedStatus, expectedValue, cookies, domCookieStatus) {
     196    assert_equals(cookies["samesite_none"], expectedValue, "SameSite=None cookies are always sent.");
     197    if (expectedStatus == SameSiteStatus.CROSS_SITE) {
     198      assert_not_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are not sent with cross-site requests.");
     199      assert_not_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are not sent with cross-site requests.");
     200      assert_not_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are not sent with cross-site requests.");
     201    } else if (expectedStatus == SameSiteStatus.LAX) {
     202      assert_not_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are not sent with lax requests.");
     203      assert_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are sent with lax requests.");
     204      assert_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are are sent with lax requests.")
     205    } else if (expectedStatus == SameSiteStatus.STRICT) {
     206      assert_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are sent with strict requests.");
     207      assert_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are sent with strict requests.");
     208      assert_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are are sent with strict requests.")
     209    }
     210
     211    if (cookies["domcookies"]) {
     212      verifyDocumentCookieWithSameSiteByDefault(domCookieStatus, expectedValue, cookies["domcookies"]);
     213    }
     214}
     215
     216function verifyDocumentCookieLegacy(expectedStatus, expectedValue, domcookies) {
     217  const cookies = domcookies.split(";")
     218                            .map(cookie => cookie.trim().split("="))
     219                            .reduce((obj, cookie) => {
     220                              obj[cookie[0]] = cookie[1];
     221                              return obj;
     222                            }, {});
     223
     224  if (expectedStatus == DomSameSiteStatus.SAME_SITE) {
     225    assert_equals(cookies["samesite_none"], expectedValue, "SameSite=None cookies are always included in document.cookie.");
     226    assert_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are always included in document.cookie.");
     227    assert_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are always included in document.cookie.");
     228    assert_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are always included in document.cookie.");
     229  } else if (expectedStatus == DomSameSiteStatus.CROSS_SITE) {
     230    assert_equals(cookies["samesite_none"], expectedValue, "SameSite=None cookies are always included in document.cookie.");
     231    assert_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are always included in document.cookie.");
     232    assert_not_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are not included in document.cookie when cross-site.");
     233    assert_not_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are not included in document.cookie when cross-site.");
     234  }
     235}
     236
     237function verifyDocumentCookieWithSameSiteByDefault(expectedStatus, expectedValue, domcookies) {
     238  const cookies = domcookies.split(";")
     239                            .map(cookie => cookie.trim().split("="))
     240                            .reduce((obj, cookie) => {
     241                              obj[cookie[0]] = cookie[1];
     242                              return obj;
     243                            }, {});
     244
     245  if (expectedStatus == DomSameSiteStatus.SAME_SITE) {
     246    assert_equals(cookies["samesite_none"], expectedValue, "SameSite=None cookies are always included in document.cookie.");
     247    assert_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are always included in document.cookie.");
     248    assert_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are always included in document.cookie.");
     249    assert_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are always included in document.cookie.");
     250  } else if (expectedStatus == DomSameSiteStatus.CROSS_SITE) {
     251    assert_equals(cookies["samesite_none"], expectedValue, "SameSite=None cookies are always included in document.cookie.");
     252    assert_not_equals(cookies["samesite_unspecified"], expectedValue, "Unspecified-SameSite cookies are not included in document.cookie when cross-site.");
     253    assert_not_equals(cookies["samesite_strict"], expectedValue, "SameSite=Strict cookies are not included in document.cookie when cross-site.");
     254    assert_not_equals(cookies["samesite_lax"], expectedValue, "SameSite=Lax cookies are not included in document.cookie when cross-site.");
     255  }
     256}
     257
     258function isLegacySameSite() {
     259  return location.search === "?legacy-samesite";
     260}
     261
     262// Get the proper verifier based on the test's variant type.
     263function getSameSiteVerifier() {
     264  return isLegacySameSite() ?
     265      verifySameSiteCookieStateLegacy : verifySameSiteCookieStateWithSameSiteByDefault;
    156266}
    157267
     
    180290}
    181291
     292// Reset SameSite=None test cookies on |origin|. If |origin| matches
     293// `self.origin`, assert (via `document.cookie`) that they were properly
     294// removed.
     295function resetSameSiteNoneCookies(origin, value) {
     296  return credFetch(origin + "/cookies/resources/dropSameSiteNone.py")
     297    .then(_ => {
     298      if (origin == self.origin) {
     299        assert_dom_cookie("samesite_none_insecure", value, false);
     300        assert_dom_cookie("samesite_none_secure", value, false);
     301      }
     302    })
     303    .then(_ => {
     304      return credFetch(origin + "/cookies/resources/setSameSiteNone.py?" + value);
     305    })
     306}
     307
     308// Reset test cookies with multiple SameSite attributes on |origin|.
     309// If |origin| matches `self.origin`, assert (via `document.cookie`)
     310// that they were properly removed.
     311function resetSameSiteMultiAttributeCookies(origin, value) {
     312  return credFetch(origin + "/cookies/resources/dropSameSiteMultiAttribute.py")
     313    .then(_ => {
     314      if (origin == self.origin) {
     315        assert_dom_cookie("samesite_unsupported", value, false);
     316        assert_dom_cookie("samesite_unsupported_none", value, false);
     317        assert_dom_cookie("samesite_unsupported_lax", value, false);
     318        assert_dom_cookie("samesite_unsupported_strict", value, false);
     319        assert_dom_cookie("samesite_none_unsupported", value, false);
     320        assert_dom_cookie("samesite_lax_unsupported", value, false);
     321        assert_dom_cookie("samesite_strict_unsupported", value, false);
     322        assert_dom_cookie("samesite_lax_none", value, false);
     323      }
     324    })
     325    .then(_ => {
     326      return credFetch(origin + "/cookies/resources/setSameSiteMultiAttribute.py?" + value);
     327    })
     328}
     329
    182330//
    183331// DOM based cookie manipulation APIs
     
    185333
    186334// erase cookie value and set for expiration
    187 function erase_cookie_from_js(name) {
    188   let secure = self.location.protocol == "https:" ? "Secure" : "";
    189   document.cookie = `${name}=0; path=/; expires=${new Date(0).toUTCString()}; ${secure}`;
     335function erase_cookie_from_js(name, params) {
     336  document.cookie = `${name}=0; expires=${new Date(0).toUTCString()}; ${params};`;
    190337  var re = new RegExp("(?:^|; )" + name);
    191338  assert_equals(re.test(document.cookie), false, "Sanity check: " + name + " has been deleted.");
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/drop.py

    r253312 r279585  
    1 from helpers import makeDropCookie, readParameter, setNoCacheAndCORSHeaders
     1from cookies.resources.helpers import makeDropCookie, readParameter, setNoCacheAndCORSHeaders
    22
    33def main(request, response):
     
    66    try:
    77        # Expire the named cookie, and return a JSON-encoded success code.
    8         name = readParameter(request, paramName="name", requireValue=True)
     8        name = readParameter(request, paramName=u"name", requireValue=True)
    99        scheme = request.url_parts.scheme
    10         headers.append(makeDropCookie(name,  "https" == scheme))
    11         return headers, '{"success": true}'
     10        headers.append(makeDropCookie(name, u"https" == scheme))
     11        return headers, b'{"success": true}'
    1212    except:
    13         return 500, headers, '{"error" : "Empty or missing name parameter."}'
     13        return 500, headers, b'{"error" : "Empty or missing name parameter."}'
    1414
    15 
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/dropSameSite.py

    r253312 r279585  
    1 from helpers import makeDropCookie, readParameter, setNoCacheAndCORSHeaders
     1from cookies.resources.helpers import makeDropCookie, setNoCacheAndCORSHeaders
    22
    33def main(request, response):
    44    """Respond to `/cookie/same-site/resources/dropSameSite.py by dropping the
    5     three cookies set by setSameSiteCookies.py"""
     5    four cookies set by setSameSiteCookies.py"""
    66    headers = setNoCacheAndCORSHeaders(request, response)
    77
    88    # Expire the cookies, and return a JSON-encoded success code.
    9     headers.append(makeDropCookie("samesite_strict", False))
    10     headers.append(makeDropCookie("samesite_lax", False))
    11     headers.append(makeDropCookie("samesite_none", False))
    12     return headers, '{"success": true}'
     9    headers.append(makeDropCookie(b"samesite_strict", False))
     10    headers.append(makeDropCookie(b"samesite_lax", False))
     11    headers.append(makeDropCookie(b"samesite_none", False))
     12    headers.append(makeDropCookie(b"samesite_unspecified", False))
     13    return headers, b'{"success": true}'
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/dropSecure.py

    r253312 r279585  
    1 from helpers import makeDropCookie, readParameter, setNoCacheAndCORSHeaders
     1from cookies.resources.helpers import makeDropCookie, setNoCacheAndCORSHeaders
    22
    33def main(request, response):
     
    77
    88    # Expire the cookies, and return a JSON-encoded success code.
    9     headers.append(makeDropCookie("alone_secure", False))
    10     headers.append(makeDropCookie("alone_insecure", False))
    11     return headers, '{"success": true}'
     9    headers.append(makeDropCookie(b"alone_secure", False))
     10    headers.append(makeDropCookie(b"alone_insecure", False))
     11    return headers, b'{"success": true}'
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/echo-cookie.html

    r253312 r279585  
    2020  document.cookie = name + '=0; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=' + path + ';';
    2121};
     22window.getCookies = () => document.cookie;
    2223</script>
    2324</body>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/helpers.py

    r253312 r279585  
    1 import urlparse
     1from urllib.parse import parse_qs
     2
     3from wptserve.utils import isomorphic_encode
    24
    35def setNoCacheAndCORSHeaders(request, response):
    46    """Set Cache-Control, CORS and Content-Type headers appropriate for the cookie tests."""
    5     headers = [("Content-Type", "application/json"),
    6                ("Access-Control-Allow-Credentials", "true")]
     7    headers = [(b"Content-Type", b"application/json"),
     8               (b"Access-Control-Allow-Credentials", b"true")]
    79
    8     origin = "*"
    9     if "origin" in request.headers:
    10         origin = request.headers["origin"]
     10    origin = b"*"
     11    if b"origin" in request.headers:
     12        origin = request.headers[b"origin"]
    1113
    12     headers.append(("Access-Control-Allow-Origin", origin))
     14    headers.append((b"Access-Control-Allow-Origin", origin))
    1315    #headers.append(("Access-Control-Allow-Credentials", "true"))
    14     headers.append(("Cache-Control", "no-cache"))
    15     headers.append(("Expires", "Fri, 01 Jan 1990 00:00:00 GMT"))
     16    headers.append((b"Cache-Control", b"no-cache"))
     17    headers.append((b"Expires", b"Fri, 01 Jan 1990 00:00:00 GMT"))
    1618
    1719    return headers
     
    2022    """Make a Set-Cookie header for a cookie with the name, value and attributes provided."""
    2123    def makeAV(a, v):
    22         if None == v or "" == v:
     24        if None == v or b"" == v:
    2325            return a
    24         return "%s=%s" % (a, v)
     26        if isinstance(v, int):
     27            return b"%s=%i" % (a, v)
     28        else:
     29            return b"%s=%s" % (a, v)
    2530
    2631    # ensure cookie name is always first
    27     attrs = ["%s=%s" % (name, value)]
    28     attrs.extend(makeAV(a, v) for (a,v) in otherAttrs.iteritems())
    29     return ("Set-Cookie", "; ".join(attrs))
     32    attrs = [b"%s=%s" % (name, value)]
     33    attrs.extend(makeAV(a, v) for (a, v) in otherAttrs.items())
     34    return (b"Set-Cookie", b"; ".join((attrs)))
    3035
    3136def makeDropCookie(name, secure):
    32     attrs = {"MaxAge": 0, "path": "/"}
     37    attrs = {b"max-age": 0, b"path": b"/"}
    3338    if secure:
    34         attrs["secure"] = ""
    35     return makeCookieHeader(name, "", attrs)
     39        attrs[b"secure"] = b""
     40    return makeCookieHeader(name, b"", attrs)
    3641
    3742def readParameter(request, paramName, requireValue):
    3843    """Read a parameter from the request. Raise if requireValue is set and the
    3944    parameter has an empty value or is not present."""
    40     params = urlparse.parse_qs(request.url_parts.query)
     45    params = parse_qs(request.url_parts.query)
    4146    param = params[paramName][0].strip()
    4247    if len(param) == 0:
    43         raise Exception("Empty or missing name parameter.")
    44     return param
     48        raise Exception(u"Empty or missing name parameter.")
     49    return isomorphic_encode(param)
    4550
    4651def readCookies(request):
     
    5358            cookies[key] = cookie.value
    5459    return cookies
    55 
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/imgIfMatch.py

    r253312 r279585  
    1 import helpers
     1from cookies.resources import helpers
    22
    33def main(request, response):
     
    55       the cookie isn't present, and a transparent GIF otherwise."""
    66    headers = helpers.setNoCacheAndCORSHeaders(request, response)
    7     name = helpers.readParameter(request, paramName="name", requireValue=True)
    8     value = helpers.readParameter(request, paramName="value", requireValue=True)
     7    name = helpers.readParameter(request, paramName=u"name", requireValue=True)
     8    value = helpers.readParameter(request, paramName=u"value", requireValue=True)
    99    cookiesWithMatchingNames = request.cookies.get_list(name)
    1010    for cookie in cookiesWithMatchingNames:
    1111        if cookie.value == value:
    1212            # From https://github.com/mathiasbynens/small/blob/master/gif-transparent.gif
    13             headers.append(("Content-Type","image/gif"))
    14             gif = "\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\xFF\xFF\xFF\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"
     13            headers.append((b"Content-Type", b"image/gif"))
     14            gif = b"\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\xFF\xFF\xFF\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"
    1515            return headers, gif
    16     return 500, headers, '{"error": {"message": "The cookie\'s value did not match the given value."}}'
     16    return 500, headers, b'{"error": {"message": "The cookie\'s value did not match the given value."}}'
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/list.py

    r253312 r279585  
    11import json
    2 import helpers
     2from cookies.resources import helpers
     3
     4from wptserve.utils import isomorphic_decode
    35
    46def main(request, response):
    57    headers = helpers.setNoCacheAndCORSHeaders(request, response)
    68    cookies = helpers.readCookies(request)
    7     return headers, json.dumps(cookies)
     9    decoded_cookies = {isomorphic_decode(key): isomorphic_decode(val) for key, val in cookies.items()}
     10    return headers, json.dumps(decoded_cookies)
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/postToParent.py

    r253312 r279585  
    11import json
    2 import helpers
     2from cookies.resources import helpers
     3
     4from wptserve.utils import isomorphic_decode
    35
    46def main(request, response):
    57    headers = helpers.setNoCacheAndCORSHeaders(request, response)
    68    cookies = helpers.readCookies(request)
    7     headers.append(("Content-Type", "text/html; charset=utf-8"))
     9    headers.append((b"Content-Type", b"text/html; charset=utf-8"))
    810
    9     tmpl = """
     11    tmpl = u"""
    1012<!DOCTYPE html>
    1113<script>
    1214  var data = %s;
     15  data.type = "COOKIES";
    1316
    14   if (window.parent != window)
     17  try {
     18    data.domcookies = document.cookie;
     19  } catch (e) {}
     20
     21  if (window.parent != window) {
    1522    window.parent.postMessage(data, "*");
     23    if (window.top != window.parent)
     24      window.top.postMessage(data, "*");
     25  }
     26
    1627
    1728  if (window.opener)
     
    2536</script>
    2637"""
    27     return headers, tmpl % json.dumps(cookies)
     38    decoded_cookies = {isomorphic_decode(key): isomorphic_decode(val) for key, val in cookies.items()}
     39    return headers, tmpl % json.dumps(decoded_cookies)
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/redirectWithCORSHeaders.py

    r253312 r279585  
    1 from helpers import setNoCacheAndCORSHeaders
     1from cookies.resources.helpers import setNoCacheAndCORSHeaders
    22
    33def main(request, response):
     
    99    """
    1010    status = 302
    11     if "status" in request.GET:
     11    if b"status" in request.GET:
    1212        try:
    13             status = int(request.GET.first("status"))
     13            status = int(request.GET.first(b"status"))
    1414        except ValueError:
    1515            pass
    1616    headers = setNoCacheAndCORSHeaders(request, response)
    1717
    18     location = request.GET.first("location")
     18    location = request.GET.first(b"location")
    1919
    20     headers.append(("Location", location))
     20    headers.append((b"Location", location))
    2121
    22     return status, headers, ""
     22    return status, headers, b""
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/set.py

    r253312 r279585  
    1 import helpers
     1from cookies.resources import helpers
     2from urllib.parse import unquote
     3
     4from wptserve.utils import isomorphic_encode
    25
    36def main(request, response):
    47    """Respond to `/cookie/set?{cookie}` by echoing `{cookie}` as a `Set-Cookie` header."""
    58    headers = helpers.setNoCacheAndCORSHeaders(request, response)
    6     headers.append(("Set-Cookie", request.url_parts.query))
    7     return headers, '{"success": true}'
     9
     10    # Cookies may require whitespace (e.g. in the `Expires` attribute), so the
     11    # query string should be decoded.
     12    cookie = unquote(request.url_parts.query)
     13    headers.append((b"Set-Cookie", isomorphic_encode(cookie)))
     14
     15    return headers, b'{"success": true}'
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/setSameSite.py

    r253312 r279585  
    1 from helpers import makeCookieHeader, readParameter, setNoCacheAndCORSHeaders
     1from cookies.resources.helpers import makeCookieHeader, setNoCacheAndCORSHeaders
     2
     3from wptserve.utils import isomorphic_encode
    24
    35def main(request, response):
    4     """Respond to `/cookie/set/samesite?{value}` by setting three cookies:
     6    """Respond to `/cookie/set/samesite?{value}` by setting four cookies:
    57    1. `samesite_strict={value};SameSite=Strict;path=/`
    68    2. `samesite_lax={value};SameSite=Lax;path=/`
    7     3. `samesite_none={value};path=/`"""
     9    3. `samesite_none={value};SameSite=None;path=/`
     10    4. `samesite_unspecified={value};path=/`
     11    Then navigate to a page that will post a message back to the opener with the set cookies"""
    812    headers = setNoCacheAndCORSHeaders(request, response)
    9     value = request.url_parts.query
     13    value = isomorphic_encode(request.url_parts.query)
    1014
    11     headers.append(makeCookieHeader("samesite_strict", value, {"SameSite":"Strict","path":"/"}))
    12     headers.append(makeCookieHeader("samesite_lax", value, {"SameSite":"Lax","path":"/"}))
    13     headers.append(makeCookieHeader("samesite_none", value, {"path":"/"}))
    14     return headers, '{"success": true}'
     15    headers.append((b"Content-Type", b"text/html; charset=utf-8"))
     16    headers.append(makeCookieHeader(b"samesite_strict", value, {b"SameSite":b"Strict", b"path":b"/"}))
     17    headers.append(makeCookieHeader(b"samesite_lax", value, {b"SameSite":b"Lax", b"path":b"/"}))
     18    # SameSite=None cookies must be Secure.
     19    headers.append(makeCookieHeader(b"samesite_none", value, {b"SameSite":b"None", b"path":b"/", b"Secure": b""}))
     20    headers.append(makeCookieHeader(b"samesite_unspecified", value, {b"path":b"/"}))
     21
     22    document = b"""
     23<!DOCTYPE html>
     24<script>
     25  // A same-site navigation, which should attach all cookies including SameSite ones.
     26  // This is necessary because this page may have been reached via a cross-site navigation, so
     27  // we might not have access to some SameSite cookies from here.
     28  window.location = "../samesite/resources/echo-cookies.html";
     29</script>
     30"""
     31
     32    return headers, document
  • trunk/LayoutTests/imported/w3c/web-platform-tests/cookies/resources/setSecure.py

    r253312 r279585  
    1 from helpers import makeCookieHeader, readParameter, setNoCacheAndCORSHeaders
     1from cookies.resources.helpers import makeCookieHeader, readParameter, setNoCacheAndCORSHeaders
     2
     3from wptserve.utils import isomorphic_encode
    24
    35def main(request, response):
     
    68    alone_insecure={value};path=/"""
    79    headers = setNoCacheAndCORSHeaders(request, response)
    8     value = request.url_parts.query
     10    value = isomorphic_encode(request.url_parts.query)
    911
    10     headers.append(makeCookieHeader("alone_secure", value, {"secure": "","path": "/"}))
    11     headers.append(makeCookieHeader("alone_insecure", value, {"path": "/"}))
    12     return headers, '{"success": true}'
     12    headers.append(makeCookieHeader(b"alone_secure", value, {b"secure": b"", b"path": b"/"}))
     13    headers.append(makeCookieHeader(b"alone_insecure", value, {b"path": b"/"}))
     14    return headers, b'{"success": true}'
  • trunk/LayoutTests/tests-options.json

    r279427 r279585  
    615615        "slow"
    616616    ],
     617    "imported/w3c/web-platform-tests/cookies/attributes/domain.sub.html": [
     618        "slow"
     619    ],
     620    "imported/w3c/web-platform-tests/cookies/attributes/expires.html": [
     621        "slow"
     622    ],
     623    "imported/w3c/web-platform-tests/cookies/attributes/invalid.html": [
     624        "slow"
     625    ],
     626    "imported/w3c/web-platform-tests/cookies/attributes/max-age.html": [
     627        "slow"
     628    ],
     629    "imported/w3c/web-platform-tests/cookies/attributes/path-redirect.html": [
     630        "slow"
     631    ],
     632    "imported/w3c/web-platform-tests/cookies/attributes/path.html": [
     633        "slow"
     634    ],
     635    "imported/w3c/web-platform-tests/cookies/attributes/resources/domain-child.sub.html": [
     636        "slow"
     637    ],
     638    "imported/w3c/web-platform-tests/cookies/attributes/resources/secure-non-secure-child.html": [
     639        "slow"
     640    ],
     641    "imported/w3c/web-platform-tests/cookies/attributes/secure-non-secure.html": [
     642        "slow"
     643    ],
     644    "imported/w3c/web-platform-tests/cookies/attributes/secure.https.html": [
     645        "slow"
     646    ],
     647    "imported/w3c/web-platform-tests/cookies/encoding/charset.html": [
     648        "slow"
     649    ],
     650    "imported/w3c/web-platform-tests/cookies/name/name-ctl.html": [
     651        "slow"
     652    ],
     653    "imported/w3c/web-platform-tests/cookies/name/name.html": [
     654        "slow"
     655    ],
     656    "imported/w3c/web-platform-tests/cookies/ordering/ordering.sub.html": [
     657        "slow"
     658    ],
     659    "imported/w3c/web-platform-tests/cookies/ordering/resources/ordering-child.sub.html": [
     660        "slow"
     661    ],
     662    "imported/w3c/web-platform-tests/cookies/path/match.html": [
     663        "slow"
     664    ],
     665    "imported/w3c/web-platform-tests/cookies/samesite-none-secure/cookies-without-samesite-must-be-secure.https.tentative.html": [
     666        "slow"
     667    ],
     668    "imported/w3c/web-platform-tests/cookies/samesite/fetch.https.html": [
     669        "slow"
     670    ],
     671    "imported/w3c/web-platform-tests/cookies/samesite/form-get-blank.https.html": [
     672        "slow"
     673    ],
     674    "imported/w3c/web-platform-tests/cookies/samesite/form-post-blank.https.html": [
     675        "slow"
     676    ],
     677    "imported/w3c/web-platform-tests/cookies/samesite/iframe-reload.https.html": [
     678        "slow"
     679    ],
     680    "imported/w3c/web-platform-tests/cookies/samesite/iframe.document.https.html": [
     681        "slow"
     682    ],
     683    "imported/w3c/web-platform-tests/cookies/samesite/iframe.https.html": [
     684        "slow"
     685    ],
     686    "imported/w3c/web-platform-tests/cookies/samesite/img.https.html": [
     687        "slow"
     688    ],
     689    "imported/w3c/web-platform-tests/cookies/samesite/multiple-samesite-attributes.https.html": [
     690        "slow"
     691    ],
     692    "imported/w3c/web-platform-tests/cookies/samesite/setcookie-navigation.https.html": [
     693        "slow"
     694    ],
     695    "imported/w3c/web-platform-tests/cookies/samesite/window-open.https.html": [
     696        "slow"
     697    ],
     698    "imported/w3c/web-platform-tests/cookies/schemeful-same-site/schemeful-navigation.tentative.html": [
     699        "slow"
     700    ],
     701    "imported/w3c/web-platform-tests/cookies/schemeful-same-site/schemeful-subresource.tentative.html": [
     702        "slow"
     703    ],
     704    "imported/w3c/web-platform-tests/cookies/value/value-ctl.html": [
     705        "slow"
     706    ],
     707    "imported/w3c/web-platform-tests/cookies/value/value.html": [
     708        "slow"
     709    ],
    617710    "imported/w3c/web-platform-tests/cors/304.htm": [
    618711        "slow"
Note: See TracChangeset for help on using the changeset viewer.