From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../test_moved_origin_directory_cleanup.py | 11 ++++ .../cleardata/tests/unit/test_cookies.js | 71 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) (limited to 'toolkit/components/cleardata/tests') diff --git a/toolkit/components/cleardata/tests/marionette/test_moved_origin_directory_cleanup.py b/toolkit/components/cleardata/tests/marionette/test_moved_origin_directory_cleanup.py index 876f86cd32..50f4c93f65 100644 --- a/toolkit/components/cleardata/tests/marionette/test_moved_origin_directory_cleanup.py +++ b/toolkit/components/cleardata/tests/marionette/test_moved_origin_directory_cleanup.py @@ -46,6 +46,11 @@ class MovedOriginDirectoryCleanupTestCase(MarionetteTestCase): """ ) + def read_prefs_file(self): + pref_path = Path(self.marionette.profile_path) / "prefs.js" + with open(pref_path) as f: + return f.read() + def removeAllCookies(self): with self.marionette.using_context("chrome"): self.marionette.execute_script( @@ -83,6 +88,12 @@ class MovedOriginDirectoryCleanupTestCase(MarionetteTestCase): message="privacy.sanitize.pending must include offlineApps", ) + # Make sure the pref is written to the file + Wait(self.marionette).until( + lambda _: "offlineApps" in self.read_prefs_file(), + message="prefs.js must include offlineApps", + ) + # Cleanup happens via Sanitizer.onStartup after restart self.marionette.restart(in_app=False) diff --git a/toolkit/components/cleardata/tests/unit/test_cookies.js b/toolkit/components/cleardata/tests/unit/test_cookies.js index 4bcb6d725a..045f6c0b24 100644 --- a/toolkit/components/cleardata/tests/unit/test_cookies.js +++ b/toolkit/components/cleardata/tests/unit/test_cookies.js @@ -391,3 +391,74 @@ add_task(async function test_baseDomain_cookies_subdomain() { // Cleanup Services.cookies.removeAll(); }); + +function addCookiesForHost(host) { + const expiry = Date.now() + 24 * 60 * 60; + Services.cookies.add( + host, + "path", + "name", + "value", + true /* secure */, + true /* http only */, + false /* session */, + expiry, + {}, + Ci.nsICookie.SAMESITE_NONE, + Ci.nsICookie.SCHEME_HTTPS + ); +} + +function addIpv6Cookies() { + addCookiesForHost("[A:B:C:D:E:0:0:1]"); + addCookiesForHost("[a:b:c:d:e:0:0:1]"); + addCookiesForHost("[A:B:C:D:E::1]"); + addCookiesForHost("[000A:000B:000C:000D:000E:0000:0000:0001]"); + addCookiesForHost("A:B:C:D:E:0:0:1"); + addCookiesForHost("a:b:c:d:e:0:0:1"); + addCookiesForHost("A:B:C:D:E::1"); + + Assert.equal(Services.cookies.cookies.length, 7); +} + +// This tests the intermediate fix for Bug 1860033. +// When Bug 1882259 is resolved multiple cookies with same IPv6 host in +// different representation will not be stored anymore and this test needs to +// be removed. +add_task(async function test_ipv6_cookies() { + // Add multiple cookies of same IPv6 address in different representations. + addIpv6Cookies(); + + // Delete cookies using cookie service + Services.cookies.removeCookiesFromExactHost( + "A:B:C:D:E::1", + JSON.stringify({}) + ); + + // Assert that all cookies were removed. + Assert.equal(Services.cookies.cookies.length, 0); + + // Add multiple cookies of same IPv6 address in different representations. + addIpv6Cookies(); + + // Delete cookies by principal from URI + let uri = Services.io.newURI("http://[A:B:C:D:E::1]"); + let principal = Services.scriptSecurityManager.createContentPrincipal( + uri, + {} + ); + await new Promise(aResolve => { + Services.clearData.deleteDataFromPrincipal( + principal, + true /* user request */, + Ci.nsIClearDataService.CLEAR_COOKIES, + value => { + Assert.equal(value, 0); + aResolve(); + } + ); + }); + + // Assert that all cookies were removed. + Assert.equal(Services.cookies.cookies.length, 0); +}); -- cgit v1.2.3