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

Side by Side Diff: net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc

Issue 2909533002: Fix loading bad cookies from disk. (Closed)
Patch Set: Rebased on top of latest PS in dependency CL. Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « net/extras/sqlite/sqlite_persistent_cookie_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h" 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
18 #include "base/run_loop.h" 19 #include "base/run_loop.h"
19 #include "base/sequenced_task_runner.h" 20 #include "base/sequenced_task_runner.h"
20 #include "base/synchronization/waitable_event.h" 21 #include "base/synchronization/waitable_event.h"
21 #include "base/task_scheduler/post_task.h" 22 #include "base/task_scheduler/post_task.h"
22 #include "base/test/scoped_task_environment.h" 23 #include "base/test/scoped_task_environment.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "crypto/encryptor.h" 25 #include "crypto/encryptor.h"
25 #include "crypto/symmetric_key.h" 26 #include "crypto/symmetric_key.h"
26 #include "net/cookies/canonical_cookie.h" 27 #include "net/cookies/canonical_cookie.h"
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 474
474 ASSERT_EQ(1U, cookies.size()); 475 ASSERT_EQ(1U, cookies.size());
475 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str()); 476 ASSERT_STREQ("sessioncookie.com", cookies[0]->Domain().c_str());
476 ASSERT_STREQ("C", cookies[0]->Name().c_str()); 477 ASSERT_STREQ("C", cookies[0]->Name().c_str());
477 ASSERT_STREQ("D", cookies[0]->Value().c_str()); 478 ASSERT_STREQ("D", cookies[0]->Value().c_str());
478 ASSERT_EQ(COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority()); 479 ASSERT_EQ(COOKIE_PRIORITY_DEFAULT, cookies[0]->Priority());
479 480
480 cookies.clear(); 481 cookies.clear();
481 } 482 }
482 483
483 // Test loading old session cookies from the disk. 484 // Test refusing to load old session cookies from the disk.
484 // TODO(mattcary): disabled for possibly causing iOS timeouts: crbug.com/727566. 485 // TODO(mattcary): disabled for possibly causing iOS timeouts: crbug.com/727566.
485 TEST_F(SQLitePersistentCookieStoreTest, 486 TEST_F(SQLitePersistentCookieStoreTest,
486 DISABLED_TestDontLoadOldSessionCookies) { 487 DISABLED_TestDontLoadOldSessionCookies) {
487 InitializeStore(false, true); 488 InitializeStore(false, true);
488 489
489 // Add a session cookie. 490 // Add a session cookie.
490 store_->AddCookie( 491 store_->AddCookie(
491 CanonicalCookie("C", "D", "sessioncookie.com", "/", base::Time::Now(), 492 CanonicalCookie("C", "D", "sessioncookie.com", "/", base::Time::Now(),
492 base::Time(), base::Time(), false, false, 493 base::Time(), base::Time(), false, false,
493 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 494 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
(...skipping 10 matching lines...) Expand all
504 // The store should also delete the session cookie. Wait until that has been 505 // The store should also delete the session cookie. Wait until that has been
505 // done. 506 // done.
506 DestroyStore(); 507 DestroyStore();
507 508
508 // Create a store that loads old session cookies and test that the session 509 // Create a store that loads old session cookies and test that the session
509 // cookie is gone. 510 // cookie is gone.
510 CreateAndLoad(false, true, &cookies); 511 CreateAndLoad(false, true, &cookies);
511 ASSERT_EQ(0U, cookies.size()); 512 ASSERT_EQ(0U, cookies.size());
512 } 513 }
513 514
515 // Confirm bad cookies on disk don't get looaded
516 TEST_F(SQLitePersistentCookieStoreTest, FilterBadCookies) {
517 // Create an on-disk store.
518 InitializeStore(false, true);
519 DestroyStore();
520
521 // Add some cookies in by hand.
522 base::FilePath store_name(temp_dir_.GetPath().Append(kCookieFilename));
523 std::unique_ptr<sql::Connection> db(base::MakeUnique<sql::Connection>());
524 ASSERT_TRUE(db->Open(store_name));
525 sql::Statement stmt(db->GetUniqueStatement(
526 "INSERT INTO cookies (creation_utc, host_key, name, value, "
527 "encrypted_value, path, expires_utc, secure, httponly, "
528 "firstpartyonly, last_access_utc, has_expires, persistent, priority) "
529 "VALUES (?,'google.izzle',?,?,'',?,0,0,0,0,0,1,1,0)"));
530 ASSERT_TRUE(stmt.is_valid());
531
532 struct CookieInfo {
533 const char* name;
534 const char* value;
535 const char* path;
536 } cookies_info[] = {// A couple non-canonical cookies.
537 {"A=", "B", "/path"},
538 {"C ", "D", "/path"},
539
540 // A canonical cookie.
541 {"E", "F", "/path"}};
542
543 int64_t creation_time = 1;
544 for (int i = 0;
545 static_cast<unsigned int>(i) < sizeof(cookies_info) / sizeof(CookieInfo);
546 i++) {
mmenke 2017/06/19 17:57:13 for (const auto& cookie_info : cookies_info) (Eve
Randy Smith (Not in Mondays) 2017/06/20 21:17:18 Completely fair. Done.
547 stmt.Reset(true);
548
549 stmt.BindInt64(0, creation_time++);
550 stmt.BindString(1, cookies_info[i].name);
551 stmt.BindString(2, cookies_info[i].value);
552 stmt.BindString(3, cookies_info[i].path);
553 ASSERT_TRUE(stmt.Run());
554 }
555 stmt.Clear();
556 db.reset();
557
558 // Reopen the store and confirm that the only cookie loaded is the
559 // canonical one.
560 CanonicalCookieVector cookies;
561 CreateAndLoad(false, false, &cookies);
562 ASSERT_EQ(1U, cookies.size());
mmenke 2017/06/19 17:57:13 Hrm...Most of this file uses U, but there are a fe
Randy Smith (Not in Mondays) 2017/06/20 21:17:18 I'm not sure if you're requesting a change? 'u' i
563 EXPECT_STREQ("E", cookies[0]->Name().c_str());
564 EXPECT_STREQ("F", cookies[0]->Value().c_str());
565 EXPECT_STREQ("/path", cookies[0]->Path().c_str());
566 DestroyStore();
567 }
568
514 // TODO(mattcary): disabled for possibly causing iOS timeouts: crbug.com/727566. 569 // TODO(mattcary): disabled for possibly causing iOS timeouts: crbug.com/727566.
515 TEST_F(SQLitePersistentCookieStoreTest, DISABLED_PersistIsPersistent) { 570 TEST_F(SQLitePersistentCookieStoreTest, DISABLED_PersistIsPersistent) {
516 InitializeStore(false, true); 571 InitializeStore(false, true);
517 static const char kSessionName[] = "session"; 572 static const char kSessionName[] = "session";
518 static const char kPersistentName[] = "persistent"; 573 static const char kPersistentName[] = "persistent";
519 574
520 // Add a session cookie. 575 // Add a session cookie.
521 store_->AddCookie(CanonicalCookie( 576 store_->AddCookie(CanonicalCookie(
522 kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(), 577 kSessionName, "val", "sessioncookie.com", "/", base::Time::Now(),
523 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, 578 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 EXPECT_TRUE(was_called_with_no_cookies); 878 EXPECT_TRUE(was_called_with_no_cookies);
824 879
825 // Same with trying to load a specific cookie. 880 // Same with trying to load a specific cookie.
826 was_called_with_no_cookies = false; 881 was_called_with_no_cookies = false;
827 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies, 882 store_->LoadCookiesForKey("foo.bar", base::Bind(WasCalledWithNoCookies,
828 &was_called_with_no_cookies)); 883 &was_called_with_no_cookies));
829 EXPECT_TRUE(was_called_with_no_cookies); 884 EXPECT_TRUE(was_called_with_no_cookies);
830 } 885 }
831 886
832 } // namespace net 887 } // namespace net
OLDNEW
« no previous file with comments | « net/extras/sqlite/sqlite_persistent_cookie_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698