Bug 1848226 - Marionette's driver.sys.mjs uses wrong URL for cookie operations r=edgul,webdriver-reviewers,whimboo

https://w3c.github.io/webdriver/#dfn-get-current-url says:
> For each cookie in all associated cookies of session's
> current browsing context's active document ...

However, the cookie implementations in driver.sys.mjs called _getCurrentURL
which returned the URL of the _top level browsing context_ as specified
in https://w3c.github.io/webdriver/#dfn-get-current-url

As a consequence, the cookie tests that set and deleted cookies
inside an iframe used the top level path for deleting cookies instead of
the path of the iframe, so they failed to find any cookies applicable
to that path.

For example running cookies/encoding/charset.html would set cookies
by calling `fetch('/cookies/resources/cookie.py?...')` then it would
try to delete cookies by calling getAndExpireCookiesForDefaultPathTest
which opened an iframe to /cookies/resources/echo-cookie.html
This iframe would call `setTestContextUsingRootWindow()` then call
`await test_driver.delete_all_cookies();` - but this call attempted to
delete cookies for the top level browing context's path - /cookies/encoding/

Differential Revision: https://phabricator.services.mozilla.com/D211434
This commit is contained in:
Valentin Gosu 2024-06-04 10:43:16 +00:00
parent 0067c27e35
commit 0265423f41
16 changed files with 16 additions and 657 deletions

View file

@ -231,10 +231,19 @@ GeckoDriver.prototype.handleOpenModalDialog = function (eventName, data) {
}; };
/** /**
* Get the current visible URL. * Get the current URL.
*
* @param {object} options
* @param {boolean=} options.top
* If set to true return the window's top-level URL,
* otherwise the one from the currently selected frame. Defaults to true.
* @see https://w3c.github.io/webdriver/#get-current-url
*/ */
GeckoDriver.prototype._getCurrentURL = function () { GeckoDriver.prototype._getCurrentURL = function (options = {}) {
const browsingContext = this.getBrowsingContext({ top: true }); if (options.top === undefined) {
options.top = true;
}
const browsingContext = this.getBrowsingContext(options);
return new URL(browsingContext.currentURI.spec); return new URL(browsingContext.currentURI.spec);
}; };
@ -2146,7 +2155,7 @@ GeckoDriver.prototype.addCookie = async function (cmd) {
lazy.assert.open(this.getBrowsingContext()); lazy.assert.open(this.getBrowsingContext());
await this._handleUserPrompts(); await this._handleUserPrompts();
let { protocol, hostname } = this._getCurrentURL(); let { protocol, hostname } = this._getCurrentURL({ top: false });
const networkSchemes = ["http:", "https:"]; const networkSchemes = ["http:", "https:"];
if (!networkSchemes.includes(protocol)) { if (!networkSchemes.includes(protocol)) {
@ -2176,7 +2185,7 @@ GeckoDriver.prototype.getCookies = async function () {
lazy.assert.open(this.getBrowsingContext()); lazy.assert.open(this.getBrowsingContext());
await this._handleUserPrompts(); await this._handleUserPrompts();
let { hostname, pathname } = this._getCurrentURL(); let { hostname, pathname } = this._getCurrentURL({ top: false });
return [...lazy.cookie.iter(hostname, pathname)]; return [...lazy.cookie.iter(hostname, pathname)];
}; };
@ -2195,7 +2204,7 @@ GeckoDriver.prototype.deleteAllCookies = async function () {
lazy.assert.open(this.getBrowsingContext()); lazy.assert.open(this.getBrowsingContext());
await this._handleUserPrompts(); await this._handleUserPrompts();
let { hostname, pathname } = this._getCurrentURL(); let { hostname, pathname } = this._getCurrentURL({ top: false });
for (let toDelete of lazy.cookie.iter(hostname, pathname)) { for (let toDelete of lazy.cookie.iter(hostname, pathname)) {
lazy.cookie.remove(toDelete); lazy.cookie.remove(toDelete);
} }
@ -2216,7 +2225,7 @@ GeckoDriver.prototype.deleteCookie = async function (cmd) {
lazy.assert.open(this.getBrowsingContext()); lazy.assert.open(this.getBrowsingContext());
await this._handleUserPrompts(); await this._handleUserPrompts();
let { hostname, pathname } = this._getCurrentURL(); let { hostname, pathname } = this._getCurrentURL({ top: false });
let name = lazy.assert.string(cmd.parameters.name); let name = lazy.assert.string(cmd.parameters.name);
for (let c of lazy.cookie.iter(hostname, pathname)) { for (let c of lazy.cookie.iter(hostname, pathname)) {
if (c.name === name) { if (c.name === name) {

View file

@ -3,21 +3,3 @@
if (os == "android") and fission: [OK, TIMEOUT] if (os == "android") and fission: [OK, TIMEOUT]
[Ignore `Set-Cookie: =` with other `Set-Cookie` headers] [Ignore `Set-Cookie: =` with other `Set-Cookie` headers]
expected: FAIL expected: FAIL
[Ignore name- and value-less `Set-Cookie: ; bar`]
expected: FAIL
[Ignore `Set-Cookie: =`]
expected: FAIL
[Ignore empty cookie string]
expected: FAIL
[Ignore name- and value-less `Set-Cookie: `]
expected: FAIL
[Ignore name- and value-less `Set-Cookie: \\t`]
expected: FAIL
[Ignore cookie with domain that won't domain match (along with other invalid noise)]
expected: FAIL

View file

@ -4,33 +4,7 @@
[Set multiple cookies with max-age attribute] [Set multiple cookies with max-age attribute]
expected: expected:
if processor == "x86": [FAIL, PASS] if processor == "x86": [FAIL, PASS]
FAIL
[Set mulitiple cookies with valid max-age values] [Set mulitiple cookies with valid max-age values]
expected: expected:
if (os == "android") and not debug: [FAIL, PASS] if (os == "android") and not debug: [FAIL, PASS]
FAIL
[Don't set multiple cookies with max-age=0]
expected: FAIL
[Set no cookie with max-age=0]
expected: FAIL
[Set no cookie with max-age=-1]
expected: FAIL
[Set cookie with age]
expected: FAIL
[Expire later cookie with same name and max-age=0]
expected: FAIL
[Ignore max-age attribute with invalid non-zero-digit (containing a comma)]
expected: FAIL
[Set no cookie with max-age=-20]
expected: FAIL
[Expire later cookie with same name and max-age=0, and don't set cookie with max-age=0]
expected: FAIL

View file

@ -7,38 +7,5 @@
[No cookie sent for redirected path mismatch with trailing '#' after unquoted Path] [No cookie sent for redirected path mismatch with trailing '#' after unquoted Path]
expected: FAIL expected: FAIL
[Cookie sent for redirected path with trailing '/' and the redirected URL is one level deeper]
expected: FAIL
[Cookie sent for redirected path match with a trailing ';' after an unquoted Path]
expected: FAIL
[No cookie sent for redirected path match with a trailing ';' inside a quoted Path]
expected: FAIL
[No cookie sent for redirected path match with partially URL encoded path]
expected: FAIL
[Multiple cookies sent for multiple redirected path matches, sorted by length]
expected: FAIL
[No cookie sent for redirected path mismatch where path and redirected URL begin with same string]
expected: FAIL
[No cookie sent for redirected path mismatch where final path directory component and redirected URL resource begin with same string]
expected: FAIL
[No cookie sent for redirected path mismatch where final path directory component begins with same string as redirected URL final directory component]
expected: FAIL
[No cookie sent for redirected path mismatch for different resources inside the same final directory component]
expected: FAIL
[No cookie sent for redirected path mismatch where final path directory component ends in '/' and does not match redirected URL]
expected: FAIL
[No cookie sent for redirected path mismatch with a similar start to the redirected URL]
expected: FAIL
[No cookie sent for redirected path mismatch with trailing '/' after unquoted Path] [No cookie sent for redirected path mismatch with trailing '/' after unquoted Path]
expected: FAIL expected: FAIL

View file

@ -1,28 +1,18 @@
[path.html] [path.html]
expected: expected:
if (os == "android") and fission: [OK, TIMEOUT] if (os == "android") and fission: [OK, TIMEOUT]
[Set cookie for mismatched and root path]
expected: FAIL
[Return cookie for path= / (whitespace after equals)]
expected: FAIL
[Set cookie for bare Path] [Set cookie for bare Path]
expected: expected:
if (os == "android") and fission: [PASS, FAIL] if (os == "android") and fission: [PASS, FAIL]
FAIL
[No cookie returned for partial path match, return cookie for default path] [No cookie returned for partial path match, return cookie for default path]
expected: expected:
if (os == "android") and fission: [PASS, FAIL] if (os == "android") and fission: [PASS, FAIL]
FAIL
[Set cookie for Path=] [Set cookie for Path=]
expected: expected:
if (os == "android") and fission: [PASS, FAIL] if (os == "android") and fission: [PASS, FAIL]
FAIL
[Return cookie for bare path= (after mismatched path)] [Return cookie for bare path= (after mismatched path)]
expected: expected:
if (os == "android") and fission: [PASS, FAIL] if (os == "android") and fission: [PASS, FAIL]
FAIL

View file

@ -1,33 +0,0 @@
[secure-non-secure.html]
[(non-secure) Ignore cookie for Secure attribute]
expected: FAIL
[(non-secure) Ignore cookie for seCURe attribute]
expected: FAIL
[(non-secure) Ignore cookie for for Secure= attribute]
expected: FAIL
[(non-secure) Ignore cookie for Secure=aaaa]
expected: FAIL
[(non-secure) Ignore cookie for Secure space equals]
expected: FAIL
[(non-secure) Ignore cookie for Secure equals space]
expected: FAIL
[(non-secure) Ignore cookie for spaced Secure]
expected: FAIL
[(non-secure) Ignore cookie for space Secure with ;]
expected: FAIL
[(non-secure) Ignore cookie with __Secure- prefix and Secure]
expected: FAIL
[(non-secure) Ignore cookie with __Secure- prefix and without Secure]
expected: FAIL
[(non-secure) Cookie returned with __%53ecure- prefix and without Secure]
expected: FAIL

View file

@ -1,24 +0,0 @@
[secure.https.html]
[Set cookie for Secure attribute]
expected: FAIL
[Set cookie for seCURe attribute]
expected: FAIL
[Set cookie for for Secure= attribute]
expected: FAIL
[Set cookie for Secure=aaaa]
expected: FAIL
[Set cookie for Secure space equals]
expected: FAIL
[Set cookie for Secure equals space]
expected: FAIL
[Set cookie for spaced Secure]
expected: FAIL
[Set cookie for space Secure with ;]
expected: FAIL

View file

@ -1,15 +0,0 @@
[charset.html]
[utf-8 name and ASCII value]
expected: FAIL
[ASCII name and quoted utf-8 value]
expected: FAIL
[utf-8 name and value]
expected: FAIL
[quoted utf-8 name and value]
expected: FAIL
[utf-8 name and value, with (invalid) utf-8 attribute]
expected: FAIL

View file

@ -14,68 +14,5 @@
[Cookie with %xa in name is rejected or modified (HTTP).] [Cookie with %xa in name is rejected or modified (HTTP).]
expected: FAIL expected: FAIL
[Cookie with %xb in name is rejected (HTTP).]
expected: FAIL
[Cookie with %xc in name is rejected (HTTP).]
expected: FAIL
[Cookie with %xd in name is rejected or modified (HTTP).] [Cookie with %xd in name is rejected or modified (HTTP).]
expected: FAIL expected: FAIL
[Cookie with %xe in name is rejected (HTTP).]
expected: FAIL
[Cookie with %xf in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x10 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x11 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x12 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x13 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x14 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x15 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x16 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x17 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x18 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x19 in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x1a in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x1b in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x1c in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x1d in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x1e in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x1f in name is rejected (HTTP).]
expected: FAIL
[Cookie with %x7f in name is rejected (HTTP).]
expected: FAIL

View file

@ -4,231 +4,3 @@
if (os == "mac") and not debug: FAIL if (os == "mac") and not debug: FAIL
if os == "android": FAIL if os == "android": FAIL
[FAIL, PASS] [FAIL, PASS]
[Use last value for cookies with identical names]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Keep first-in, first-out name order]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Keep first-in, first-out single-char name order]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Keep non-alphabetic first-in, first-out name order]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Keep first-in, first-out order if comma-separated]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Set nameless cookie, given `Set-Cookie: =test16`]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Overwrite nameless cookie]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Ignore cookie with empty name and empty value]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Ignore cookie with no name or value]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for 1=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for $=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for !a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for @a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for #a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for $a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for %a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for ^a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for &a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for *a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for (a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for )a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for -a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for _a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for +=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for "a=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Name is set as expected for "a=b"=test]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[URL-encoded cookie name is not decoded]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Remove trailing WSP characters from the name string]
expected: FAIL
[Remove leading WSP characters from the name string]
expected: FAIL
[Only return the new cookie (with the same name)]
expected: FAIL
[Ignore invalid attributes after nameless cookie]
expected: FAIL
[Ignore invalid attributes after valid name (that looks like Cookie2 Version attribute)]
expected: FAIL
[Set a cookie that has whitespace in its name]
expected: FAIL
[Set a nameless cookie ignoring characters after first ;]
expected: FAIL
[Set a nameless cookie ignoring characters after first ; (2)]
expected: FAIL
[Return the most recent nameless cookie]
expected: FAIL
[Return the most recent nameless cookie, without leading =]
expected: FAIL
[Return the most recent nameless cookie, even if preceded by =]
expected: FAIL
[Ignore nameless cookies that impersonate cookie prefixes]
expected: FAIL
[Set a nameless cookie (that has an = in its value)]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Set a nameless cookie (that has multiple ='s in its value)]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Set a nameless cookie]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]
[Set valueless cookie to its name with empty value]
expected:
if (os == "mac") and not debug: FAIL
if os == "android": FAIL
[FAIL, PASS]

View file

@ -1,6 +0,0 @@
[ordering.sub.html]
[Cookies with longer paths are listed before cookies with shorter paths]
expected: FAIL
[For equal length paths, list the cookie with an earlier creation time first]
expected: FAIL

View file

@ -1,3 +0,0 @@
[default.html]
[Test for default cookie path]
expected: FAIL

View file

@ -19,15 +19,3 @@
[Max length negative Max-Age attribute value (1024 bytes) doesn't get ignored] [Max length negative Max-Age attribute value (1024 bytes) doesn't get ignored]
expected: FAIL expected: FAIL
[Set cookie with max size name/value pair and multiple max size attributes (>8k bytes total)]
expected: FAIL
[Too long negative Max-Age attribute value (>1024 bytes) gets ignored]
expected: FAIL
[Set cookie with max size name/value pair and max size attribute value]
expected: FAIL
[Max size domain attribute (1024 bytes) is not ignored]
expected: FAIL

View file

@ -1,35 +1,3 @@
[name-and-value.html] [name-and-value.html]
expected: expected:
if (os == "android") and fission: [OK, TIMEOUT] if (os == "android") and fission: [OK, TIMEOUT]
[Ignore cookie with name larger than 4096 and 1 byte value]
expected: FAIL
[Set max-size value-less cookie]
expected: FAIL
[Ignore value-less cookie with name larger than 4096 bytes]
expected: FAIL
[Set max-size cookie with largest possible value (4095 bytes)]
expected: FAIL
[Ignore named cookie (with non-zero length) and value larger than 4095 bytes]
expected: FAIL
[Ignore named cookie with length larger than 4095 bytes, and a non-zero value]
expected: FAIL
[Set max-size name-less cookie]
expected: FAIL
[Ignore name-less cookie with value larger than 4096 bytes]
expected: FAIL
[Ignore name-less cookie (without leading =) with value larger than 4096 bytes]
expected: FAIL
[Set max-size cookie that also has an attribute]
expected: FAIL
[Set max-size cookie with largest possible name and value (4096 bytes)]
expected: FAIL

View file

@ -8,68 +8,5 @@
[Cookie with %xa in name is rejected or modified (HTTP).] [Cookie with %xa in name is rejected or modified (HTTP).]
expected: FAIL expected: FAIL
[Cookie with %xb in value is rejected (HTTP).]
expected: FAIL
[Cookie with %xc in value is rejected (HTTP).]
expected: FAIL
[Cookie with %xd in name is rejected or modified (HTTP).] [Cookie with %xd in name is rejected or modified (HTTP).]
expected: FAIL expected: FAIL
[Cookie with %xe in value is rejected (HTTP).]
expected: FAIL
[Cookie with %xf in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x10 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x11 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x12 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x13 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x14 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x15 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x16 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x17 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x18 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x19 in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x1a in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x1b in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x1c in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x1d in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x1e in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x1f in value is rejected (HTTP).]
expected: FAIL
[Cookie with %x7f in value is rejected (HTTP).]
expected: FAIL

View file

@ -1,84 +0,0 @@
[value.html]
[Set nameless cookie to its value]
expected: FAIL
[Set nameless cookie to its value with an escaped quote]
expected: FAIL
[Set value with unbalanced leading quote]
expected: FAIL
[Set nameless cookie followed by '=' to its value]
expected: FAIL
[Set cookie but ignore value after LF]
expected: FAIL
[Set cookie ignoring whitespace after value endquote]
expected: FAIL
[Ignore whitespace and ; after value]
expected: FAIL
[Ignore whitespace preceding value]
expected: FAIL
[Set cookie with quotes in value]
expected: FAIL
[Set cookie keeping whitespace inside quoted value]
expected: FAIL
[Set cookie value ignoring characters after semicolon]
expected: FAIL
[Set cookie with another = inside quoted value]
expected: FAIL
[Set cookie ignoring whitespace surrounding value and characters after first semicolon]
expected: FAIL
[Set valueless cookie, given `Set-Cookie: test22=`]
expected: FAIL
[URL-encoded cookie value is not decoded]
expected: FAIL
[Set cookie with a space character in the value]
expected: FAIL
[Set cookie with large name + value ( = 4kb)]
expected: FAIL
[Set cookie with one = inside an unquoted value]
expected: FAIL
[Set a nameless cookie with a space character in the value]
expected: FAIL
[Set cookie with two = inside an unquoted value]
expected: FAIL
[Set cookie with value set to =]
expected: FAIL
[Ignore cookie with large name + value ( > 4kb)]
expected: FAIL
[Set value with a single quote excluding whitespace]
expected: FAIL
[Ignore values after semicolon]
expected: FAIL
[Set value containing a comma]
expected: FAIL
[Set value including quotes and whitespace up until semicolon]
expected: FAIL
[Set quoted value containing a comma]
expected: FAIL
[Ignore whitespace at the end of value]
expected: FAIL