Commit 9d8225a5 authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

net_unittests: update some tests for upcoming cookie changes.

We will restrict cookies from 3rd party contexts when they don't explicitly
grant such access, and require those accessible there to be secure, so some
tests need updated to mark their partiness correctly, and to not try to use
insecure 3rd-party accessible cookies.

Bug: 1016512
Change-Id: I86659cf72d64d26597a0be3b74793b009d5c8a6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872572Reviewed-by: default avatarLily Chen <chlily@chromium.org>
Commit-Queue: Maksim Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708257}
parent 39f4ff30
...@@ -583,7 +583,7 @@ TEST(CanonicalCookieTest, GetEffectiveSameSite) { ...@@ -583,7 +583,7 @@ TEST(CanonicalCookieTest, GetEffectiveSameSite) {
TEST(CanonicalCookieTest, IncludeForRequestURL) { TEST(CanonicalCookieTest, IncludeForRequestURL) {
GURL url("http://www.example.com"); GURL url("http://www.example.com");
base::Time creation_time = base::Time::Now(); base::Time creation_time = base::Time::Now();
CookieOptions options; CookieOptions options = CookieOptions::MakeAllInclusive();
base::Optional<base::Time> server_time = base::nullopt; base::Optional<base::Time> server_time = base::nullopt;
std::unique_ptr<CanonicalCookie> cookie( std::unique_ptr<CanonicalCookie> cookie(
......
...@@ -206,22 +206,22 @@ class CookieMonsterTestBase : public CookieStoreTest<T> { ...@@ -206,22 +206,22 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"dom_1", "A", ".harvard.edu", "/", base::Time(), base::Time(), "dom_1", "A", ".harvard.edu", "/", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::LAX_MODE,
COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie( EXPECT_TRUE(this->SetCanonicalCookie(
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"dom_2", "B", ".math.harvard.edu", "/", base::Time(), base::Time(), "dom_2", "B", ".math.harvard.edu", "/", base::Time(), base::Time(),
base::Time(), false, false, CookieSameSite::NO_RESTRICTION, base::Time(), false, false, CookieSameSite::LAX_MODE,
COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie( EXPECT_TRUE(this->SetCanonicalCookie(
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"dom_3", "C", ".bourbaki.math.harvard.edu", "/", base::Time(), "dom_3", "C", ".bourbaki.math.harvard.edu", "/", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
// Host cookies // Host cookies
...@@ -229,22 +229,22 @@ class CookieMonsterTestBase : public CookieStoreTest<T> { ...@@ -229,22 +229,22 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"host_1", "A", url_top_level_domain_plus_1, "/", base::Time(), "host_1", "A", url_top_level_domain_plus_1, "/", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie( EXPECT_TRUE(this->SetCanonicalCookie(
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"host_2", "B", url_top_level_domain_plus_2, "/", base::Time(), "host_2", "B", url_top_level_domain_plus_2, "/", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie( EXPECT_TRUE(this->SetCanonicalCookie(
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"host_3", "C", url_top_level_domain_plus_3, "/", base::Time(), "host_3", "C", url_top_level_domain_plus_3, "/", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
// http_only cookie // http_only cookie
...@@ -252,8 +252,8 @@ class CookieMonsterTestBase : public CookieStoreTest<T> { ...@@ -252,8 +252,8 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"httpo_check", "A", url_top_level_domain_plus_2, "/", base::Time(), "httpo_check", "A", url_top_level_domain_plus_2, "/", base::Time(),
base::Time(), base::Time(), false, true, base::Time(), base::Time(), false, true, CookieSameSite::LAX_MODE,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
// same-site cookie // same-site cookie
...@@ -287,15 +287,15 @@ class CookieMonsterTestBase : public CookieStoreTest<T> { ...@@ -287,15 +287,15 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"dom_path_1", "A", ".math.harvard.edu", "/dir1", base::Time(), "dom_path_1", "A", ".math.harvard.edu", "/dir1", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie( EXPECT_TRUE(this->SetCanonicalCookie(
cm, cm,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"dom_path_2", "B", ".math.harvard.edu", "/dir1/dir2", base::Time(), "dom_path_2", "B", ".math.harvard.edu", "/dir1/dir2", base::Time(),
base::Time(), base::Time(), false, false, base::Time(), base::Time(), false, false, CookieSameSite::LAX_MODE,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
// Host path cookies // Host path cookies
...@@ -304,7 +304,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> { ...@@ -304,7 +304,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"host_path_1", "A", url_top_level_domain_plus_2, "/dir1", "host_path_1", "A", url_top_level_domain_plus_2, "/dir1",
base::Time(), base::Time(), base::Time(), false, false, base::Time(), base::Time(), base::Time(), false, false,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
EXPECT_TRUE(this->SetCanonicalCookie( EXPECT_TRUE(this->SetCanonicalCookie(
...@@ -312,7 +312,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> { ...@@ -312,7 +312,7 @@ class CookieMonsterTestBase : public CookieStoreTest<T> {
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"host_path_2", "B", url_top_level_domain_plus_2, "/dir1/dir2", "host_path_2", "B", url_top_level_domain_plus_2, "/dir1/dir2",
base::Time(), base::Time(), base::Time(), false, false, base::Time(), base::Time(), base::Time(), false, false,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT),
"http", true /*modify_httponly*/)); "http", true /*modify_httponly*/));
EXPECT_EQ(14U, this->GetAllCookies(cm).size()); EXPECT_EQ(14U, this->GetAllCookies(cm).size());
......
...@@ -420,7 +420,7 @@ TYPED_TEST_P(CookieStoreTest, FilterTest) { ...@@ -420,7 +420,7 @@ TYPED_TEST_P(CookieStoreTest, FilterTest) {
std::unique_ptr<CanonicalCookie> cc(CanonicalCookie::CreateSanitizedCookie( std::unique_ptr<CanonicalCookie> cc(CanonicalCookie::CreateSanitizedCookie(
this->www_foo_foo_.url(), "A", "B", std::string(), "/foo", one_hour_ago, this->www_foo_foo_.url(), "A", "B", std::string(), "/foo", one_hour_ago,
one_hour_from_now, base::Time(), false, false, one_hour_from_now, base::Time(), false, false,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT)); CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
ASSERT_TRUE(cc); ASSERT_TRUE(cc);
EXPECT_TRUE(this->SetCanonicalCookie(cs, std::move(cc), "https", EXPECT_TRUE(this->SetCanonicalCookie(cs, std::move(cc), "https",
true /*modify_httponly*/)); true /*modify_httponly*/));
...@@ -430,7 +430,7 @@ TYPED_TEST_P(CookieStoreTest, FilterTest) { ...@@ -430,7 +430,7 @@ TYPED_TEST_P(CookieStoreTest, FilterTest) {
cc = CanonicalCookie::CreateSanitizedCookie( cc = CanonicalCookie::CreateSanitizedCookie(
this->www_foo_bar_.url(), "C", "D", this->www_foo_bar_.domain(), "/bar", this->www_foo_bar_.url(), "C", "D", this->www_foo_bar_.domain(), "/bar",
two_hours_ago, base::Time(), one_hour_ago, false, true, two_hours_ago, base::Time(), one_hour_ago, false, true,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT); CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT);
ASSERT_TRUE(cc); ASSERT_TRUE(cc);
EXPECT_TRUE(this->SetCanonicalCookie(cs, std::move(cc), "https", EXPECT_TRUE(this->SetCanonicalCookie(cs, std::move(cc), "https",
true /*modify_httponly*/)); true /*modify_httponly*/));
...@@ -547,7 +547,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { ...@@ -547,7 +547,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"A", "B", foo_foo_host, "/foo", one_hour_ago, one_hour_from_now, "A", "B", foo_foo_host, "/foo", one_hour_ago, one_hour_from_now,
base::Time(), false /* secure */, false /* httponly */, base::Time(), false /* secure */, false /* httponly */,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT),
"http", true)); "http", true));
// Note that for the creation time to be set exactly, without modification, // Note that for the creation time to be set exactly, without modification,
// it must be different from the one set by the line above. // it must be different from the one set by the line above.
...@@ -555,7 +555,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { ...@@ -555,7 +555,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
cs, cs,
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"C", "D", "." + foo_bar_domain, "/bar", two_hours_ago, base::Time(), "C", "D", "." + foo_bar_domain, "/bar", two_hours_ago, base::Time(),
one_hour_ago, false, true, CookieSameSite::NO_RESTRICTION, one_hour_ago, false, true, CookieSameSite::LAX_MODE,
COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", true)); "http", true));
...@@ -614,7 +614,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { ...@@ -614,7 +614,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), "G", "H", http_foo_host, "/unique", base::Time(),
base::Time(), base::Time(), false /* secure */, base::Time(), base::Time(), false /* secure */,
true /* httponly */, CookieSameSite::NO_RESTRICTION, true /* httponly */, CookieSameSite::LAX_MODE,
COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", false /* modify_http_only */) "http", false /* modify_http_only */)
.HasExclusionReason( .HasExclusionReason(
...@@ -641,7 +641,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { ...@@ -641,7 +641,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), base::Time(), "G", "H", http_foo_host, "/unique", base::Time(), base::Time(),
base::Time(), false /* secure */, true /* httponly */, base::Time(), false /* secure */, true /* httponly */,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT),
"http", true /* modify_http_only */)); "http", true /* modify_http_only */));
EXPECT_TRUE( EXPECT_TRUE(
...@@ -650,7 +650,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { ...@@ -650,7 +650,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), "G", "H", http_foo_host, "/unique", base::Time(),
base::Time(), base::Time(), false /* secure */, base::Time(), base::Time(), false /* secure */,
true /* httponly */, CookieSameSite::NO_RESTRICTION, true /* httponly */, CookieSameSite::LAX_MODE,
COOKIE_PRIORITY_DEFAULT), COOKIE_PRIORITY_DEFAULT),
"http", false /* modify_http_only */) "http", false /* modify_http_only */)
.HasExclusionReason( .HasExclusionReason(
...@@ -662,7 +662,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) { ...@@ -662,7 +662,7 @@ TYPED_TEST_P(CookieStoreTest, SetCanonicalCookieTest) {
std::make_unique<CanonicalCookie>( std::make_unique<CanonicalCookie>(
"G", "H", http_foo_host, "/unique", base::Time(), base::Time(), "G", "H", http_foo_host, "/unique", base::Time(), base::Time(),
base::Time(), false /* secure */, true /* httponly */, base::Time(), false /* secure */, true /* httponly */,
CookieSameSite::NO_RESTRICTION, COOKIE_PRIORITY_DEFAULT), CookieSameSite::LAX_MODE, COOKIE_PRIORITY_DEFAULT),
"http", true /* modify_http_only */)); "http", true /* modify_http_only */));
} }
......
...@@ -1239,7 +1239,7 @@ TEST_F(SQLitePersistentCookieStoreTest, KeyInconsistency) { ...@@ -1239,7 +1239,7 @@ TEST_F(SQLitePersistentCookieStoreTest, KeyInconsistency) {
GURL("ftp://subdomain.ftperiffic.com/page"), "A=B; max-age=3600", GURL("ftp://subdomain.ftperiffic.com/page"), "A=B; max-age=3600",
base::Time::Now(), base::nullopt /* server_time */); base::Time::Now(), base::nullopt /* server_time */);
cookie_monster->SetCanonicalCookieAsync( cookie_monster->SetCanonicalCookieAsync(
std::move(cookie), "ftp", CookieOptions(), std::move(cookie), "ftp", CookieOptions::MakeAllInclusive(),
base::BindOnce(&ResultSavingCookieCallback< base::BindOnce(&ResultSavingCookieCallback<
CanonicalCookie::CookieInclusionStatus>::Run, CanonicalCookie::CookieInclusionStatus>::Run,
base::Unretained(&set_cookie_callback))); base::Unretained(&set_cookie_callback)));
...@@ -1256,7 +1256,7 @@ TEST_F(SQLitePersistentCookieStoreTest, KeyInconsistency) { ...@@ -1256,7 +1256,7 @@ TEST_F(SQLitePersistentCookieStoreTest, KeyInconsistency) {
"A=B; max-age=3600", base::Time::Now(), "A=B; max-age=3600", base::Time::Now(),
base::nullopt /* server_time */); base::nullopt /* server_time */);
cookie_monster->SetCanonicalCookieAsync( cookie_monster->SetCanonicalCookieAsync(
std::move(canonical_cookie), "http", CookieOptions(), std::move(canonical_cookie), "http", CookieOptions::MakeAllInclusive(),
base::BindOnce(&ResultSavingCookieCallback< base::BindOnce(&ResultSavingCookieCallback<
CanonicalCookie::CookieInclusionStatus>::Run, CanonicalCookie::CookieInclusionStatus>::Run,
base::Unretained(&set_cookie_callback2))); base::Unretained(&set_cookie_callback2)));
...@@ -1284,7 +1284,8 @@ TEST_F(SQLitePersistentCookieStoreTest, KeyInconsistency) { ...@@ -1284,7 +1284,8 @@ TEST_F(SQLitePersistentCookieStoreTest, KeyInconsistency) {
// Now try to get the cookie back. // Now try to get the cookie back.
GetCookieListCallback get_callback; GetCookieListCallback get_callback;
cookie_monster->GetCookieListWithOptionsAsync( cookie_monster->GetCookieListWithOptionsAsync(
GURL("ftp://subdomain.ftperiffic.com/page"), CookieOptions(), GURL("ftp://subdomain.ftperiffic.com/page"),
CookieOptions::MakeAllInclusive(),
base::BindOnce(&GetCookieListCallback::Run, base::BindOnce(&GetCookieListCallback::Run,
base::Unretained(&get_callback))); base::Unretained(&get_callback)));
get_callback.WaitUntilDone(); get_callback.WaitUntilDone();
...@@ -1311,7 +1312,7 @@ TEST_F(SQLitePersistentCookieStoreTest, OpsIfInitFailed) { ...@@ -1311,7 +1312,7 @@ TEST_F(SQLitePersistentCookieStoreTest, OpsIfInitFailed) {
"A=B; max-age=3600", base::Time::Now(), "A=B; max-age=3600", base::Time::Now(),
base::nullopt /* server_time */); base::nullopt /* server_time */);
cookie_monster->SetCanonicalCookieAsync( cookie_monster->SetCanonicalCookieAsync(
std::move(cookie), "http", CookieOptions(), std::move(cookie), "http", CookieOptions::MakeAllInclusive(),
base::BindOnce(&ResultSavingCookieCallback< base::BindOnce(&ResultSavingCookieCallback<
CanonicalCookie::CookieInclusionStatus>::Run, CanonicalCookie::CookieInclusionStatus>::Run,
base::Unretained(&set_cookie_callback))); base::Unretained(&set_cookie_callback)));
......
...@@ -452,7 +452,7 @@ TEST_F(ReportingUploaderTest, DontSendCookies) { ...@@ -452,7 +452,7 @@ TEST_F(ReportingUploaderTest, DontSendCookies) {
auto cookie = CanonicalCookie::Create(url, "foo=bar", base::Time::Now(), auto cookie = CanonicalCookie::Create(url, "foo=bar", base::Time::Now(),
base::nullopt /* server_time */); base::nullopt /* server_time */);
context_.cookie_store()->SetCanonicalCookieAsync( context_.cookie_store()->SetCanonicalCookieAsync(
std::move(cookie), url.scheme(), CookieOptions(), std::move(cookie), url.scheme(), CookieOptions::MakeAllInclusive(),
cookie_callback.MakeCallback()); cookie_callback.MakeCallback());
cookie_callback.WaitUntilDone(); cookie_callback.WaitUntilDone();
ASSERT_TRUE(cookie_callback.result().IsInclude()); ASSERT_TRUE(cookie_callback.result().IsInclude());
...@@ -485,7 +485,7 @@ TEST_F(ReportingUploaderTest, DontSaveCookies) { ...@@ -485,7 +485,7 @@ TEST_F(ReportingUploaderTest, DontSaveCookies) {
GetCookieListCallback cookie_callback; GetCookieListCallback cookie_callback;
context_.cookie_store()->GetCookieListWithOptionsAsync( context_.cookie_store()->GetCookieListWithOptionsAsync(
server_.GetURL("/"), CookieOptions(), server_.GetURL("/"), CookieOptions::MakeAllInclusive(),
base::BindOnce(&GetCookieListCallback::Run, base::BindOnce(&GetCookieListCallback::Run,
base::Unretained(&cookie_callback))); base::Unretained(&cookie_callback)));
cookie_callback.WaitUntilDone(); cookie_callback.WaitUntilDone();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment