зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1877239 - Support partitioned attribute in cookie service. r=bvandersloot,cookie-reviewers,edgul
Differential Revision: https://phabricator.services.mozilla.com/D200288
This commit is contained in:
Родитель
6cd98ee53a
Коммит
a882785771
|
@ -185,6 +185,10 @@ NS_IMETHODIMP Cookie::GetIsHttpOnly(bool* aHttpOnly) {
|
|||
*aHttpOnly = IsHttpOnly();
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP Cookie::GetIsPartitioned(bool* aPartitioned) {
|
||||
*aPartitioned = IsPartitioned();
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP Cookie::GetCreationTime(int64_t* aCreation) {
|
||||
*aCreation = CreationTime();
|
||||
return NS_OK;
|
||||
|
|
|
@ -90,6 +90,9 @@ class Cookie final : public nsICookie {
|
|||
inline bool IsDomain() const { return *mData.host().get() == '.'; }
|
||||
inline bool IsSecure() const { return mData.isSecure(); }
|
||||
inline bool IsHttpOnly() const { return mData.isHttpOnly(); }
|
||||
inline bool IsPartitioned() const {
|
||||
return !mOriginAttributes.mPartitionKey.IsEmpty();
|
||||
}
|
||||
inline bool RawIsPartitioned() const { return mData.isPartitioned(); }
|
||||
inline const OriginAttributes& OriginAttributesRef() const {
|
||||
return mOriginAttributes;
|
||||
|
|
|
@ -158,4 +158,9 @@ interface nsICookie : nsISupports {
|
|||
* Bitmap of schemes.
|
||||
*/
|
||||
readonly attribute nsICookie_schemeType schemeMap;
|
||||
|
||||
/**
|
||||
* true if the cookie's OriginAttributes PartitionKey is NOT empty
|
||||
*/
|
||||
readonly attribute boolean isPartitioned;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function count_IsPartitioned(bool) {
|
||||
var cookieCountIsPartitioned = 0;
|
||||
Services.cookies.cookies.forEach(cookie => {
|
||||
if (cookie.isPartitioned === bool) {
|
||||
cookieCountIsPartitioned += 1;
|
||||
}
|
||||
});
|
||||
return cookieCountIsPartitioned;
|
||||
}
|
||||
|
||||
add_task(async function test_IsPartitioned() {
|
||||
let profile = do_get_profile();
|
||||
let dbFile = do_get_cookie_file(profile);
|
||||
Assert.ok(!dbFile.exists());
|
||||
|
||||
let schema13db = new CookieDatabaseConnection(dbFile, 13);
|
||||
let now = Date.now() * 1000; // date in microseconds
|
||||
|
||||
// add some non-partitioned cookies for key
|
||||
let nUnpartitioned = 5;
|
||||
let hostNonPartitioned = "cookie-host-non-partitioned.com";
|
||||
for (let i = 0; i < nUnpartitioned; i++) {
|
||||
let cookie = new Cookie(
|
||||
"cookie-name" + i,
|
||||
"cookie-value" + i,
|
||||
hostNonPartitioned,
|
||||
"/", // path
|
||||
now, // expiry
|
||||
now, // last accessed
|
||||
now, // creation time
|
||||
false, // session
|
||||
false, // secure
|
||||
false, // http-only
|
||||
false, // inBrowserElement
|
||||
{} // OA
|
||||
);
|
||||
schema13db.insertCookie(cookie);
|
||||
}
|
||||
|
||||
// add some partitioned cookies
|
||||
let nPartitioned = 5;
|
||||
let hostPartitioned = "host-partitioned.com";
|
||||
for (let i = 0; i < nPartitioned; i++) {
|
||||
let cookie = new Cookie(
|
||||
"cookie-name" + i,
|
||||
"cookie-value" + i,
|
||||
hostPartitioned,
|
||||
"/", // path
|
||||
now, // expiry
|
||||
now, // last accessed
|
||||
now, // creation time
|
||||
false, // session
|
||||
false, // secure
|
||||
false, // http-only
|
||||
false, // inBrowserElement
|
||||
{ partitionKey: "(https,example.com)" }
|
||||
);
|
||||
schema13db.insertCookie(cookie);
|
||||
}
|
||||
|
||||
Assert.equal(do_count_cookies_in_db(schema13db.db), 10);
|
||||
|
||||
// Startup the cookie service and check the cookie counts by OA
|
||||
let cookieCountNonPart =
|
||||
Services.cookies.countCookiesFromHost(hostNonPartitioned); // includes expired cookies
|
||||
Assert.equal(cookieCountNonPart, nUnpartitioned);
|
||||
let cookieCountPart = Services.cookies.getCookiesFromHost(hostPartitioned, {
|
||||
partitionKey: "(https,example.com)",
|
||||
}).length; // includes expired cookies
|
||||
Assert.equal(cookieCountPart, nPartitioned);
|
||||
|
||||
// Startup the cookie service and check the cookie counts by isPartitioned (IsPartitioned())
|
||||
Assert.equal(count_IsPartitioned(false), nUnpartitioned);
|
||||
Assert.equal(count_IsPartitioned(true), nPartitioned);
|
||||
|
||||
schema13db.close();
|
||||
});
|
|
@ -471,6 +471,8 @@ run-sequentially = "http3server"
|
|||
|
||||
["test_cookie_ipv6.js"]
|
||||
|
||||
["test_cookie_partitioned_attribute.js"]
|
||||
|
||||
["test_cookiejars.js"]
|
||||
|
||||
["test_cookiejars_safebrowsing.js"]
|
||||
|
|
Загрузка…
Ссылка в новой задаче