Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Unified Diff: net/cookies/canonical_cookie_unittest.cc

Issue 2633663003: Implements strict secure cookies as the default behavior in //net (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/cookies/canonical_cookie_unittest.cc
diff --git a/net/cookies/canonical_cookie_unittest.cc b/net/cookies/canonical_cookie_unittest.cc
index fa9eb6caa83145b5c3bace04a89c253dbe88027e..3cf5c007985fbdf19efbab75d74e41b82f0a5e6b 100644
--- a/net/cookies/canonical_cookie_unittest.cc
+++ b/net/cookies/canonical_cookie_unittest.cc
@@ -20,7 +20,7 @@ TEST(CanonicalCookieTest, Constructor) {
std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
url, "A", "2", std::string(), "/test", current_time, base::Time(), false,
- false, CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT));
+ false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
EXPECT_EQ("www.example.com", cookie->Domain());
@@ -31,7 +31,7 @@ TEST(CanonicalCookieTest, Constructor) {
std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create(
url, "A", "2", ".www.example.com", std::string(), current_time,
- base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false,
+ base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
COOKIE_PRIORITY_DEFAULT));
EXPECT_EQ("A", cookie2->Name());
EXPECT_EQ("2", cookie2->Value());
@@ -93,10 +93,9 @@ TEST(CanonicalCookieTest, Create) {
// Test the creating cookies using specific parameter instead of a cookie
// string.
- cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test",
- creation_time, base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, false,
- COOKIE_PRIORITY_DEFAULT);
+ cookie = CanonicalCookie::Create(
+ url, "A", "2", "www.example.com", "/test", creation_time, base::Time(),
+ false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
EXPECT_EQ(".www.example.com", cookie->Domain());
@@ -105,10 +104,9 @@ TEST(CanonicalCookieTest, Create) {
EXPECT_FALSE(cookie->IsHttpOnly());
EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
- cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test",
- creation_time, base::Time(), false, false,
- CookieSameSite::DEFAULT_MODE, false,
- COOKIE_PRIORITY_DEFAULT);
+ cookie = CanonicalCookie::Create(
+ url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(),
+ false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT);
EXPECT_EQ("A", cookie->Name());
EXPECT_EQ("2", cookie->Value());
EXPECT_EQ(".www.example.com", cookie->Domain());
@@ -181,25 +179,22 @@ TEST(CanonicalCookieTest, IsEquivalent) {
// Test that a cookie is equivalent to itself.
std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
- expiration_time, secure, httponly, same_site, false,
- COOKIE_PRIORITY_MEDIUM));
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM));
EXPECT_TRUE(cookie->IsEquivalent(*cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie));
// Test that two identical cookies are equivalent.
std::unique_ptr<CanonicalCookie> other_cookie(CanonicalCookie::Create(
url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time,
- expiration_time, secure, httponly, same_site, false,
- COOKIE_PRIORITY_MEDIUM));
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM));
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
// Tests that use different variations of attribute values that
// DON'T affect cookie equivalence.
- other_cookie =
- CanonicalCookie::Create(url, cookie_name, "2", cookie_domain, cookie_path,
- creation_time, expiration_time, secure, httponly,
- same_site, false, COOKIE_PRIORITY_HIGH);
+ other_cookie = CanonicalCookie::Create(
+ url, cookie_name, "2", cookie_domain, cookie_path, creation_time,
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_HIGH);
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
@@ -208,29 +203,28 @@ TEST(CanonicalCookieTest, IsEquivalent) {
creation_time + base::TimeDelta::FromMinutes(2);
other_cookie = CanonicalCookie::Create(
url, cookie_name, "2", cookie_domain, cookie_path, other_creation_time,
- expiration_time, secure, httponly, same_site, false,
- COOKIE_PRIORITY_MEDIUM);
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM);
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
- expiration_time, true, httponly, same_site, false, COOKIE_PRIORITY_LOW);
+ expiration_time, true, httponly, same_site, COOKIE_PRIORITY_LOW);
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
- expiration_time, secure, true, same_site, false, COOKIE_PRIORITY_LOW);
+ expiration_time, secure, true, same_site, COOKIE_PRIORITY_LOW);
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time,
- expiration_time, secure, httponly, CookieSameSite::STRICT_MODE, false,
+ expiration_time, secure, httponly, CookieSameSite::STRICT_MODE,
COOKIE_PRIORITY_LOW);
EXPECT_TRUE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
@@ -239,8 +233,7 @@ TEST(CanonicalCookieTest, IsEquivalent) {
// Cookies whose names mismatch are not equivalent.
other_cookie = CanonicalCookie::Create(
url, "B", cookie_value, cookie_domain, cookie_path, creation_time,
- expiration_time, secure, httponly, same_site, false,
- COOKIE_PRIORITY_MEDIUM);
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM);
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
@@ -250,8 +243,7 @@ TEST(CanonicalCookieTest, IsEquivalent) {
// rules of 'IsEquivalentForSecureCookieMatching'.
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_value, std::string(), cookie_path, creation_time,
- expiration_time, secure, httponly, same_site, false,
- COOKIE_PRIORITY_MEDIUM);
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM);
EXPECT_TRUE(cookie->IsDomainCookie());
EXPECT_FALSE(other_cookie->IsDomainCookie());
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
@@ -262,7 +254,7 @@ TEST(CanonicalCookieTest, IsEquivalent) {
// 'www.example.com', but they are equivalent for secure cookie matching.
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_value, ".example.com", cookie_path,
- creation_time, expiration_time, secure, httponly, same_site, false,
+ creation_time, expiration_time, secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM);
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
@@ -275,15 +267,14 @@ TEST(CanonicalCookieTest, IsEquivalent) {
// equivalent for secure cookie matching to |other_cookie| set on '/'.
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_value, cookie_domain, "/test", creation_time,
- expiration_time, secure, httponly, same_site, false,
- COOKIE_PRIORITY_MEDIUM);
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM);
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath",
- creation_time, expiration_time, secure, httponly, same_site, false,
+ creation_time, expiration_time, secure, httponly, same_site,
COOKIE_PRIORITY_MEDIUM);
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
@@ -291,8 +282,7 @@ TEST(CanonicalCookieTest, IsEquivalent) {
other_cookie = CanonicalCookie::Create(
url, cookie_name, cookie_value, cookie_domain, "/", creation_time,
- expiration_time, secure, httponly, same_site, false,
- COOKIE_PRIORITY_MEDIUM);
+ expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM);
EXPECT_FALSE(cookie->IsEquivalent(*other_cookie));
EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie));
EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie));
@@ -575,7 +565,6 @@ TEST(CanonicalCookieTest, EnforceSecureCookiesRequireSecureScheme) {
GURL https_url("https://www.example.com");
base::Time creation_time = base::Time::Now();
CookieOptions options;
- options.set_enforce_strict_secure();
std::unique_ptr<CanonicalCookie> http_cookie_no_secure(
CanonicalCookie::Create(http_url, "a=b", creation_time, options));
@@ -594,19 +583,19 @@ TEST(CanonicalCookieTest, EnforceSecureCookiesRequireSecureScheme) {
std::unique_ptr<CanonicalCookie> http_cookie_no_secure_extended(
CanonicalCookie::Create(
http_url, "a", "b", "", "", creation_time, creation_time, false,
- false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
+ false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
std::unique_ptr<CanonicalCookie> http_cookie_secure_extended(
CanonicalCookie::Create(
http_url, "a", "b", "", "", creation_time, creation_time, true, false,
- CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
+ CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
std::unique_ptr<CanonicalCookie> https_cookie_no_secure_extended(
CanonicalCookie::Create(
https_url, "a", "b", "", "", creation_time, creation_time, false,
- false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
+ false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
std::unique_ptr<CanonicalCookie> https_cookie_secure_extended(
CanonicalCookie::Create(
https_url, "a", "b", "", "", creation_time, creation_time, true,
- false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT));
+ false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
EXPECT_TRUE(http_cookie_no_secure_extended.get());
EXPECT_FALSE(http_cookie_secure_extended.get());

Powered by Google App Engine
This is Rietveld 408576698