summaryrefslogtreecommitdiff
path: root/chromium/net/extras
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-08-24 12:15:48 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-08-28 13:30:04 +0000
commitb014812705fc80bff0a5c120dfcef88f349816dc (patch)
tree25a2e2d9fa285f1add86aa333389a839f81a39ae /chromium/net/extras
parent9f4560b1027ae06fdb497023cdcaf91b8511fa74 (diff)
downloadqtwebengine-chromium-b014812705fc80bff0a5c120dfcef88f349816dc.tar.gz
BASELINE: Update Chromium to 68.0.3440.125
Change-Id: I23f19369e01f688e496f5bf179abb521ad73874f Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/net/extras')
-rw-r--r--chromium/net/extras/sqlite/sqlite_channel_id_store_unittest.cc3
-rw-r--r--chromium/net/extras/sqlite/sqlite_persistent_cookie_store.cc52
-rw-r--r--chromium/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc61
3 files changed, 84 insertions, 32 deletions
diff --git a/chromium/net/extras/sqlite/sqlite_channel_id_store_unittest.cc b/chromium/net/extras/sqlite/sqlite_channel_id_store_unittest.cc
index fa940a1396b..b83bbe52e61 100644
--- a/chromium/net/extras/sqlite/sqlite_channel_id_store_unittest.cc
+++ b/chromium/net/extras/sqlite/sqlite_channel_id_store_unittest.cc
@@ -20,6 +20,7 @@
#include "net/test/cert_test_util.h"
#include "net/test/channel_id_test_util.h"
#include "net/test/test_data_directory.h"
+#include "net/test/test_with_scoped_task_environment.h"
#include "sql/statement.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -28,7 +29,7 @@ namespace net {
const base::FilePath::CharType kTestChannelIDFilename[] =
FILE_PATH_LITERAL("ChannelID");
-class SQLiteChannelIDStoreTest : public testing::Test {
+class SQLiteChannelIDStoreTest : public TestWithScopedTaskEnvironment {
public:
void Load(std::vector<std::unique_ptr<DefaultChannelIDStore::ChannelID>>*
channel_ids) {
diff --git a/chromium/net/extras/sqlite/sqlite_persistent_cookie_store.cc b/chromium/net/extras/sqlite/sqlite_persistent_cookie_store.cc
index 90afe861f9b..7313ddfac9d 100644
--- a/chromium/net/extras/sqlite/sqlite_persistent_cookie_store.cc
+++ b/chromium/net/extras/sqlite/sqlite_persistent_cookie_store.cc
@@ -47,6 +47,7 @@ enum CookieLoadProblem {
COOKIE_LOAD_PROBLEM_DECRYPT_TIMEOUT = 1,
COOKIE_LOAD_PROBLEM_NON_CANONICAL = 2,
COOKIE_LOAD_PROBLEM_OPEN_DB = 3,
+ COOKIE_LOAD_PROBLEM_RECOVERY_FAILED = 4,
COOKIE_LOAD_PROBLEM_LAST_ENTRY
};
@@ -183,8 +184,9 @@ class SQLitePersistentCookieStore::Backend
const LoadedCallback& loaded_callback);
// Steps through all results of |smt|, makes a cookie from each, and adds the
- // cookie to |cookies|. This method also updates |num_cookies_read_|.
- void MakeCookiesFromSQLStatement(
+ // cookie to |cookies|. Returns true if everything loaded successfully.
+ // Always updates |num_cookies_read_|.
+ bool MakeCookiesFromSQLStatement(
std::vector<std::unique_ptr<CanonicalCookie>>* cookies,
sql::Statement* statement);
@@ -289,7 +291,8 @@ class SQLitePersistentCookieStore::Backend
// all domains are loaded).
void ChainLoadCookies(const LoadedCallback& loaded_callback);
- // Load all cookies for a set of domains/hosts
+ // Load all cookies for a set of domains/hosts. The error recovery code
+ // assumes |key| includes all related domains within an eTLD + 1.
bool LoadCookiesForDomains(const std::set<std::string>& key);
// Batch a cookie operation (add or delete)
@@ -347,7 +350,8 @@ class SQLitePersistentCookieStore::Backend
base::TimeDelta cookie_load_duration_;
// The total number of cookies read. Incremented and reported on the
- // background runner.
+ // background runner. Includes those that were malformed, not decrypted
+ // correctly, etc.
int num_cookies_read_;
scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
@@ -857,7 +861,7 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
const std::set<std::string>& domains) {
DCHECK(background_task_runner_->RunsTasksInCurrentSequence());
- sql::Statement smt;
+ sql::Statement smt, del_smt;
if (restore_old_session_cookies_) {
smt.Assign(db_->GetCachedStatement(
SQL_FROM_HERE,
@@ -873,7 +877,10 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
"has_expires, is_persistent, priority FROM cookies WHERE host_key = ? "
"AND is_persistent = 1"));
}
- if (!smt.is_valid()) {
+ del_smt.Assign(db_->GetCachedStatement(
+ SQL_FROM_HERE, "DELETE FROM cookies WHERE host_key = ?"));
+ if (!smt.is_valid() || !del_smt.is_valid()) {
+ del_smt.Clear();
smt.Clear(); // Disconnect smt_ref from db_.
meta_table_.Reset();
db_.reset();
@@ -882,24 +889,44 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
std::vector<std::unique_ptr<CanonicalCookie>> cookies;
std::set<std::string>::const_iterator it = domains.begin();
- for (; it != domains.end(); ++it) {
+ bool ok = true;
+ for (; it != domains.end() && ok; ++it) {
smt.BindString(0, *it);
- MakeCookiesFromSQLStatement(&cookies, &smt);
+ ok = MakeCookiesFromSQLStatement(&cookies, &smt);
smt.Reset(true);
}
- {
+
+ if (ok) {
base::AutoLock locked(lock_);
std::move(cookies.begin(), cookies.end(), std::back_inserter(cookies_));
+ } else {
+ // There were some cookies that were in database but could not be loaded
+ // and handed over to CookieMonster. This is trouble since it means that
+ // if some website tries to send them again, CookieMonster won't know to
+ // issue a delete, and then the addition would violate the uniqueness
+ // constraints and not go through.
+ //
+ // For data consistency, we drop the entire eTLD group.
+ for (const std::string& domain : domains) {
+ del_smt.BindString(0, domain);
+ if (!del_smt.Run()) {
+ // TODO(morlovich): Is something more drastic called for here?
+ RecordCookieLoadProblem(COOKIE_LOAD_PROBLEM_RECOVERY_FAILED);
+ }
+ del_smt.Reset(true);
+ }
}
return true;
}
-void SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement(
+bool SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement(
std::vector<std::unique_ptr<CanonicalCookie>>* cookies,
sql::Statement* statement) {
DCHECK(background_task_runner_->RunsTasksInCurrentSequence());
sql::Statement& smt = *statement;
+ bool ok = true;
while (smt.Step()) {
+ ++num_cookies_read_;
std::string value;
std::string encrypted_value = smt.ColumnString(4);
if (!encrypted_value.empty() && crypto_) {
@@ -909,6 +936,7 @@ void SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement(
timeout_tracker->End();
if (!decrypt_ok) {
RecordCookieLoadProblem(COOKIE_LOAD_PROBLEM_DECRYPT_FAILED);
+ ok = false;
continue;
}
} else {
@@ -934,9 +962,11 @@ void SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement(
cookies->push_back(std::move(cc));
} else {
RecordCookieLoadProblem(COOKIE_LOAD_PROBLEM_NON_CANONICAL);
+ ok = false;
}
- ++num_cookies_read_;
}
+
+ return ok;
}
bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() {
diff --git a/chromium/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc b/chromium/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
index 8af4c6461d8..7ec588bc394 100644
--- a/chromium/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
+++ b/chromium/net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc
@@ -20,8 +20,8 @@
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
#include "base/task_scheduler/post_task.h"
-#include "base/test/scoped_task_environment.h"
#include "base/threading/thread_restrictions.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "crypto/encryptor.h"
#include "crypto/symmetric_key.h"
@@ -30,7 +30,7 @@
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_store_test_callbacks.h"
#include "net/extras/sqlite/cookie_crypto_delegate.h"
-#include "net/test/net_test_suite.h"
+#include "net/test/test_with_scoped_task_environment.h"
#include "sql/connection.h"
#include "sql/meta_table.h"
#include "sql/statement.h"
@@ -90,7 +90,7 @@ bool CookieCryptor::DecryptString(const std::string& ciphertext,
typedef std::vector<std::unique_ptr<CanonicalCookie>> CanonicalCookieVector;
-class SQLitePersistentCookieStoreTest : public testing::Test {
+class SQLitePersistentCookieStoreTest : public TestWithScopedTaskEnvironment {
public:
SQLitePersistentCookieStoreTest()
: loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
@@ -128,7 +128,7 @@ class SQLitePersistentCookieStoreTest : public testing::Test {
store_ = nullptr;
// Make sure we wait until the destructor has run by running all
// ScopedTaskEnvironment tasks.
- NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle();
+ RunUntilIdle();
}
void Create(bool crypt_cookies,
@@ -415,7 +415,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestLoadCookiesForKey) {
db_thread_event_.Signal();
- NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle();
+ RunUntilIdle();
EXPECT_TRUE(loaded_event_.IsSignaled());
for (CanonicalCookieVector::const_iterator it = cookies_.begin();
@@ -450,7 +450,7 @@ TEST_F(SQLitePersistentCookieStoreTest, TestBeforeFlushCallback) {
AddCookie(base::StringPrintf("%d", i), "foo", "example.com", "/", t);
}
- NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle();
+ RunUntilIdle();
EXPECT_GT(counter.count, 0);
DestroyStore();
@@ -538,8 +538,9 @@ TEST_F(SQLitePersistentCookieStoreTest, TestDontLoadOldSessionCookies) {
ASSERT_EQ(0U, cookies.size());
}
-// Confirm bad cookies on disk don't get looaded
-TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookies) {
+// Confirm bad cookies on disk don't get looaded, and that we also remove them
+// from the database.
+TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookiesAndFixupDb) {
// Create an on-disk store.
InitializeStore(false, true);
DestroyStore();
@@ -552,42 +553,62 @@ TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookies) {
"INSERT INTO cookies (creation_utc, host_key, name, value, "
"encrypted_value, path, expires_utc, is_secure, is_httponly, "
"firstpartyonly, last_access_utc, has_expires, is_persistent, priority) "
- "VALUES (?,'google.izzle',?,?,'',?,0,0,0,0,0,1,1,0)"));
+ "VALUES (?,?,?,?,'',?,0,0,0,0,0,1,1,0)"));
ASSERT_TRUE(stmt.is_valid());
struct CookieInfo {
+ const char* domain;
const char* name;
const char* value;
const char* path;
} cookies_info[] = {// A couple non-canonical cookies.
- {"A=", "B", "/path"},
- {"C ", "D", "/path"},
+ {"google.izzle", "A=", "B", "/path"},
+ {"google.izzle", "C ", "D", "/path"},
- // A canonical cookie.
- {"E", "F", "/path"}};
+ // A canonical cookie for same eTLD+1. This one will get
+ // dropped out of precaution to avoid confusing the site,
+ // even though there is nothing wrong with it.
+ {"sub.google.izzle", "E", "F", "/path"},
+
+ // A canonical cookie for another eTLD+1
+ {"chromium.org", "G", "H", "/dir"}};
int64_t creation_time = 1;
for (auto& cookie_info : cookies_info) {
stmt.Reset(true);
stmt.BindInt64(0, creation_time++);
- stmt.BindString(1, cookie_info.name);
- stmt.BindString(2, cookie_info.value);
- stmt.BindString(3, cookie_info.path);
+ stmt.BindString(1, cookie_info.domain);
+ stmt.BindString(2, cookie_info.name);
+ stmt.BindString(3, cookie_info.value);
+ stmt.BindString(4, cookie_info.path);
ASSERT_TRUE(stmt.Run());
}
stmt.Clear();
db.reset();
// Reopen the store and confirm that the only cookie loaded is the
- // canonical one.
+ // canonical one on an unrelated domain.
CanonicalCookieVector cookies;
CreateAndLoad(false, false, &cookies);
ASSERT_EQ(1U, cookies.size());
- EXPECT_STREQ("E", cookies[0]->Name().c_str());
- EXPECT_STREQ("F", cookies[0]->Value().c_str());
- EXPECT_STREQ("/path", cookies[0]->Path().c_str());
+ EXPECT_STREQ("chromium.org", cookies[0]->Domain().c_str());
+ EXPECT_STREQ("G", cookies[0]->Name().c_str());
+ EXPECT_STREQ("H", cookies[0]->Value().c_str());
+ EXPECT_STREQ("/dir", cookies[0]->Path().c_str());
DestroyStore();
+
+ // Make sure that we only have one row left.
+ db = std::make_unique<sql::Connection>();
+ ASSERT_TRUE(db->Open(store_name));
+ sql::Statement verify_stmt(db->GetUniqueStatement("SELECT * FROM COOKIES"));
+ ASSERT_TRUE(verify_stmt.is_valid());
+ int found = 0;
+ while (verify_stmt.Step()) {
+ ++found;
+ }
+ EXPECT_TRUE(verify_stmt.Succeeded());
+ EXPECT_EQ(1, found);
}
TEST_F(SQLitePersistentCookieStoreTest, PersistIsPersistent) {