diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /toolkit/components/cleardata/tests/unit | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/cleardata/tests/unit')
-rw-r--r-- | toolkit/components/cleardata/tests/unit/test_cookies.js | 71 |
1 files changed, 71 insertions, 0 deletions
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); +}); |