| OLD | NEW |
| 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/cookies/cookie_monster.h" | 5 #include "net/cookies/cookie_monster.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 static std::unique_ptr<CookieStore> Create() { | 100 static std::unique_ptr<CookieStore> Create() { |
| 101 return base::MakeUnique<CookieMonster>(nullptr, nullptr); | 101 return base::MakeUnique<CookieMonster>(nullptr, nullptr); |
| 102 } | 102 } |
| 103 | 103 |
| 104 static const bool supports_http_only = true; | 104 static const bool supports_http_only = true; |
| 105 static const bool supports_non_dotted_domains = true; | 105 static const bool supports_non_dotted_domains = true; |
| 106 static const bool preserves_trailing_dots = true; | 106 static const bool preserves_trailing_dots = true; |
| 107 static const bool filters_schemes = true; | 107 static const bool filters_schemes = true; |
| 108 static const bool has_path_prefix_bug = false; | 108 static const bool has_path_prefix_bug = false; |
| 109 static const int creation_time_granularity_in_ms = 0; | 109 static const int creation_time_granularity_in_ms = 0; |
| 110 static const bool enforce_strict_secure = false; | |
| 111 }; | |
| 112 | |
| 113 struct CookieMonsterEnforcingStrictSecure { | |
| 114 static std::unique_ptr<CookieStore> Create() { | |
| 115 return base::MakeUnique<CookieMonster>(nullptr, nullptr); | |
| 116 } | |
| 117 | |
| 118 static const bool supports_http_only = true; | |
| 119 static const bool supports_non_dotted_domains = true; | |
| 120 static const bool preserves_trailing_dots = true; | |
| 121 static const bool filters_schemes = true; | |
| 122 static const bool has_path_prefix_bug = false; | |
| 123 static const int creation_time_granularity_in_ms = 0; | |
| 124 static const bool enforce_strict_secure = true; | |
| 125 }; | 110 }; |
| 126 | 111 |
| 127 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 112 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
| 128 CookieStoreTest, | 113 CookieStoreTest, |
| 129 CookieMonsterTestTraits); | 114 CookieMonsterTestTraits); |
| 130 | 115 |
| 131 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonsterStrictSecure, | |
| 132 CookieStoreTest, | |
| 133 CookieMonsterEnforcingStrictSecure); | |
| 134 | |
| 135 template <typename T> | 116 template <typename T> |
| 136 class CookieMonsterTestBase : public CookieStoreTest<T> { | 117 class CookieMonsterTestBase : public CookieStoreTest<T> { |
| 137 public: | 118 public: |
| 138 using CookieStoreTest<T>::SetCookie; | 119 using CookieStoreTest<T>::SetCookie; |
| 139 | 120 |
| 140 protected: | 121 protected: |
| 141 using CookieStoreTest<T>::http_www_google_; | 122 using CookieStoreTest<T>::http_www_google_; |
| 142 using CookieStoreTest<T>::https_www_google_; | 123 using CookieStoreTest<T>::https_www_google_; |
| 143 | 124 |
| 144 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, | 125 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 it->Priority() == cookie.Priority()) { | 778 it->Priority() == cookie.Priority()) { |
| 798 return true; | 779 return true; |
| 799 } | 780 } |
| 800 } | 781 } |
| 801 | 782 |
| 802 return false; | 783 return false; |
| 803 } | 784 } |
| 804 }; | 785 }; |
| 805 | 786 |
| 806 using CookieMonsterTest = CookieMonsterTestBase<CookieMonsterTestTraits>; | 787 using CookieMonsterTest = CookieMonsterTestBase<CookieMonsterTestTraits>; |
| 807 using CookieMonsterStrictSecureTest = | |
| 808 CookieMonsterTestBase<CookieMonsterEnforcingStrictSecure>; | |
| 809 | 788 |
| 810 // TODO(erikwright): Replace the other callbacks and synchronous helper methods | 789 // TODO(erikwright): Replace the other callbacks and synchronous helper methods |
| 811 // in this test suite with these Mocks. | 790 // in this test suite with these Mocks. |
| 812 template <typename T, typename C> | 791 template <typename T, typename C> |
| 813 class MockCookieCallback { | 792 class MockCookieCallback { |
| 814 public: | 793 public: |
| 815 C AsCallback() { | 794 C AsCallback() { |
| 816 return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this))); | 795 return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this))); |
| 817 } | 796 } |
| 818 }; | 797 }; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 delete_begin, | 867 delete_begin, |
| 889 delete_end, | 868 delete_end, |
| 890 callback) { | 869 callback) { |
| 891 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, | 870 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, |
| 892 callback->AsCallback()); | 871 callback->AsCallback()); |
| 893 } | 872 } |
| 894 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { | 873 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { |
| 895 cookie_monster->SetCookieWithDetailsAsync( | 874 cookie_monster->SetCookieWithDetailsAsync( |
| 896 cc.url, cc.name, cc.value, cc.domain, cc.path, base::Time(), | 875 cc.url, cc.name, cc.value, cc.domain, cc.path, base::Time(), |
| 897 cc.expiration_time, base::Time(), cc.secure, cc.http_only, cc.same_site, | 876 cc.expiration_time, base::Time(), cc.secure, cc.http_only, cc.same_site, |
| 898 false /* enforces strict secure cookies */, cc.priority, | 877 cc.priority, callback->AsCallback()); |
| 899 callback->AsCallback()); | |
| 900 } | 878 } |
| 901 | 879 |
| 902 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { | 880 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
| 903 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); | 881 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); |
| 904 } | 882 } |
| 905 | 883 |
| 906 ACTION_P5(DeleteAllCreatedBetweenWithPredicateAction, | 884 ACTION_P5(DeleteAllCreatedBetweenWithPredicateAction, |
| 907 cookie_monster, | 885 cookie_monster, |
| 908 delete_begin, | 886 delete_begin, |
| 909 delete_end, | 887 delete_end, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 CompleteLoading(); | 1066 CompleteLoading(); |
| 1089 loop.Run(); | 1067 loop.Run(); |
| 1090 } | 1068 } |
| 1091 | 1069 |
| 1092 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { | 1070 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { |
| 1093 MockSetCookiesCallback set_cookies_callback; | 1071 MockSetCookiesCallback set_cookies_callback; |
| 1094 CookieList list; | 1072 CookieList list; |
| 1095 list.push_back(*CanonicalCookie::Create( | 1073 list.push_back(*CanonicalCookie::Create( |
| 1096 http_www_google_.url(), "A", "B", http_www_google_.domain(), "/", | 1074 http_www_google_.url(), "A", "B", http_www_google_.domain(), "/", |
| 1097 base::Time::Now(), base::Time(), false, true, | 1075 base::Time::Now(), base::Time(), false, true, |
| 1098 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 1076 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 1099 list.push_back(*CanonicalCookie::Create( | 1077 list.push_back(*CanonicalCookie::Create( |
| 1100 http_www_google_.url(), "C", "D", http_www_google_.domain(), "/", | 1078 http_www_google_.url(), "C", "D", http_www_google_.domain(), "/", |
| 1101 base::Time::Now(), base::Time(), false, true, | 1079 base::Time::Now(), base::Time(), false, true, |
| 1102 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 1080 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 1103 | 1081 |
| 1104 BeginWith( | 1082 BeginWith( |
| 1105 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1083 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
| 1106 | 1084 |
| 1107 WaitForLoadCall(); | 1085 WaitForLoadCall(); |
| 1108 | 1086 |
| 1109 EXPECT_CALL(set_cookies_callback, Invoke(true)) | 1087 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
| 1110 .WillOnce( | 1088 .WillOnce( |
| 1111 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1089 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
| 1112 base::RunLoop loop; | 1090 base::RunLoop loop; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 } | 1568 } |
| 1591 | 1569 |
| 1592 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionNonSecure) { | 1570 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionNonSecure) { |
| 1593 TestPriorityAwareGarbageCollectHelperNonSecure(); | 1571 TestPriorityAwareGarbageCollectHelperNonSecure(); |
| 1594 } | 1572 } |
| 1595 | 1573 |
| 1596 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionSecure) { | 1574 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionSecure) { |
| 1597 TestPriorityAwareGarbageCollectHelperSecure(); | 1575 TestPriorityAwareGarbageCollectHelperSecure(); |
| 1598 } | 1576 } |
| 1599 | 1577 |
| 1600 TEST_F(CookieMonsterStrictSecureTest, TestPriorityAwareGarbageCollectionMixed) { | 1578 TEST_F(CookieMonsterTest, TestPriorityAwareGarbageCollectionMixed) { |
| 1601 TestPriorityAwareGarbageCollectHelperMixed(); | 1579 TestPriorityAwareGarbageCollectHelperMixed(); |
| 1602 } | 1580 } |
| 1603 | 1581 |
| 1604 TEST_F(CookieMonsterTest, SetCookieableSchemes) { | 1582 TEST_F(CookieMonsterTest, SetCookieableSchemes) { |
| 1605 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 1583 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 1606 std::unique_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); | 1584 std::unique_ptr<CookieMonster> cm_foo(new CookieMonster(nullptr, nullptr)); |
| 1607 | 1585 |
| 1608 // Only cm_foo should allow foo:// cookies. | 1586 // Only cm_foo should allow foo:// cookies. |
| 1609 std::vector<std::string> schemes; | 1587 std::vector<std::string> schemes; |
| 1610 schemes.push_back("foo"); | 1588 schemes.push_back("foo"); |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2582 cm->SetPersistSessionCookies(true); | 2560 cm->SetPersistSessionCookies(true); |
| 2583 | 2561 |
| 2584 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2562 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
| 2585 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2563 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
| 2586 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2564 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
| 2587 | 2565 |
| 2588 CookieList list; | 2566 CookieList list; |
| 2589 list.push_back(*CanonicalCookie::Create( | 2567 list.push_back(*CanonicalCookie::Create( |
| 2590 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2568 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", |
| 2591 base::Time::Now(), base::Time(), false, false, | 2569 base::Time::Now(), base::Time(), false, false, |
| 2592 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2570 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2593 list.push_back(*CanonicalCookie::Create( | 2571 list.push_back(*CanonicalCookie::Create( |
| 2594 http_www_google_.url(), "W", "X", http_www_google_.url().host(), "/bar", | 2572 http_www_google_.url(), "W", "X", http_www_google_.url().host(), "/bar", |
| 2595 base::Time::Now(), base::Time(), false, false, | 2573 base::Time::Now(), base::Time(), false, false, |
| 2596 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2574 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2597 list.push_back(*CanonicalCookie::Create( | 2575 list.push_back(*CanonicalCookie::Create( |
| 2598 http_www_google_.url(), "Y", "Z", http_www_google_.url().host(), "/", | 2576 http_www_google_.url(), "Y", "Z", http_www_google_.url().host(), "/", |
| 2599 base::Time::Now(), base::Time(), false, false, | 2577 base::Time::Now(), base::Time(), false, false, |
| 2600 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2578 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2601 | 2579 |
| 2602 // SetAllCookies must not flush. | 2580 // SetAllCookies must not flush. |
| 2603 ASSERT_EQ(0, store->flush_count()); | 2581 ASSERT_EQ(0, store->flush_count()); |
| 2604 EXPECT_TRUE(SetAllCookies(cm.get(), list)); | 2582 EXPECT_TRUE(SetAllCookies(cm.get(), list)); |
| 2605 EXPECT_EQ(0, store->flush_count()); | 2583 EXPECT_EQ(0, store->flush_count()); |
| 2606 | 2584 |
| 2607 CookieList cookies = GetAllCookies(cm.get()); | 2585 CookieList cookies = GetAllCookies(cm.get()); |
| 2608 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. | 2586 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. |
| 2609 EXPECT_EQ(expected_size, cookies.size()); | 2587 EXPECT_EQ(expected_size, cookies.size()); |
| 2610 CookieList::iterator it = cookies.begin(); | 2588 CookieList::iterator it = cookies.begin(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2625 | 2603 |
| 2626 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2604 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
| 2627 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2605 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 2628 | 2606 |
| 2629 base::Time now = base::Time::Now(); | 2607 base::Time now = base::Time::Now(); |
| 2630 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2608 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
| 2631 | 2609 |
| 2632 std::unique_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( | 2610 std::unique_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( |
| 2633 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2611 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", |
| 2634 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2612 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2635 false, COOKIE_PRIORITY_DEFAULT)); | 2613 COOKIE_PRIORITY_DEFAULT)); |
| 2636 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( | 2614 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( |
| 2637 http_www_google_.url(), "C", "D", http_www_google_.url().host(), "/", | 2615 http_www_google_.url(), "C", "D", http_www_google_.url().host(), "/", |
| 2638 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2616 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2639 false, COOKIE_PRIORITY_DEFAULT)); | 2617 COOKIE_PRIORITY_DEFAULT)); |
| 2640 std::unique_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( | 2618 std::unique_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( |
| 2641 http_www_google_.url(), "E", "F", http_www_google_.url().host(), "/", | 2619 http_www_google_.url(), "E", "F", http_www_google_.url().host(), "/", |
| 2642 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2620 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2643 false, COOKIE_PRIORITY_DEFAULT)); | 2621 COOKIE_PRIORITY_DEFAULT)); |
| 2644 std::unique_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( | 2622 std::unique_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( |
| 2645 http_www_google_.url(), "G", "H", http_www_google_.url().host(), "/", | 2623 http_www_google_.url(), "G", "H", http_www_google_.url().host(), "/", |
| 2646 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2624 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2647 false, COOKIE_PRIORITY_DEFAULT)); | 2625 COOKIE_PRIORITY_DEFAULT)); |
| 2648 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( | 2626 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( |
| 2649 CanonicalCookie::Create( | 2627 CanonicalCookie::Create( |
| 2650 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), | 2628 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), |
| 2651 "/", creation_time, base::Time(), false, false, | 2629 "/", creation_time, base::Time(), false, false, |
| 2652 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2630 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2653 std::unique_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( | 2631 std::unique_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( |
| 2654 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2632 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", |
| 2655 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2633 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2656 false, COOKIE_PRIORITY_DEFAULT)); | 2634 COOKIE_PRIORITY_DEFAULT)); |
| 2657 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( | 2635 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( |
| 2658 CanonicalCookie::Create( | 2636 CanonicalCookie::Create( |
| 2659 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2637 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", |
| 2660 now, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false, | 2638 now, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2661 COOKIE_PRIORITY_DEFAULT)); | 2639 COOKIE_PRIORITY_DEFAULT)); |
| 2662 std::unique_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( | 2640 std::unique_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( |
| 2663 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/foo", | 2641 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/foo", |
| 2664 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2642 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2665 false, COOKIE_PRIORITY_DEFAULT)); | 2643 COOKIE_PRIORITY_DEFAULT)); |
| 2666 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( | 2644 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( |
| 2667 CanonicalCookie::Create( | 2645 CanonicalCookie::Create( |
| 2668 http_www_google_.url(), "K", "L", http_www_google_.url().host(), | 2646 http_www_google_.url(), "K", "L", http_www_google_.url().host(), |
| 2669 "/bar", creation_time, base::Time(), false, false, | 2647 "/bar", creation_time, base::Time(), false, false, |
| 2670 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2648 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2671 std::unique_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( | 2649 std::unique_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( |
| 2672 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/foo", | 2650 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/foo", |
| 2673 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2651 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
| 2674 false, COOKIE_PRIORITY_DEFAULT)); | 2652 COOKIE_PRIORITY_DEFAULT)); |
| 2675 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( | 2653 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( |
| 2676 CanonicalCookie::Create( | 2654 CanonicalCookie::Create( |
| 2677 http_www_google_.url(), "M", "N", http_www_google_.url().host(), | 2655 http_www_google_.url(), "M", "N", http_www_google_.url().host(), |
| 2678 "/bar", creation_time, base::Time(), false, false, | 2656 "/bar", creation_time, base::Time(), false, false, |
| 2679 CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 2657 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
| 2680 | 2658 |
| 2681 CookieList old_cookies; | 2659 CookieList old_cookies; |
| 2682 old_cookies.push_back(*cookie1); | 2660 old_cookies.push_back(*cookie1); |
| 2683 old_cookies.push_back(*cookie2); | 2661 old_cookies.push_back(*cookie2); |
| 2684 old_cookies.push_back(*cookie4); | 2662 old_cookies.push_back(*cookie4); |
| 2685 old_cookies.push_back(*cookie5); | 2663 old_cookies.push_back(*cookie5); |
| 2686 old_cookies.push_back(*cookie6); | 2664 old_cookies.push_back(*cookie6); |
| 2687 old_cookies.push_back(*cookie7); | 2665 old_cookies.push_back(*cookie7); |
| 2688 | 2666 |
| 2689 CookieList new_cookies; | 2667 CookieList new_cookies; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2886 | 2864 |
| 2887 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); | 2865 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); |
| 2888 | 2866 |
| 2889 // We have to manually build this cookie because it contains a control | 2867 // We have to manually build this cookie because it contains a control |
| 2890 // character, and our cookie line parser rejects control characters. | 2868 // character, and our cookie line parser rejects control characters. |
| 2891 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( | 2869 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( |
| 2892 url, "baz", | 2870 url, "baz", |
| 2893 "\x05" | 2871 "\x05" |
| 2894 "boo", | 2872 "boo", |
| 2895 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, | 2873 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, |
| 2896 false, COOKIE_PRIORITY_DEFAULT); | 2874 COOKIE_PRIORITY_DEFAULT); |
| 2897 initial_cookies.push_back(std::move(cc)); | 2875 initial_cookies.push_back(std::move(cc)); |
| 2898 | 2876 |
| 2899 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); | 2877 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); |
| 2900 | 2878 |
| 2901 // Inject our initial cookies into the mock PersistentCookieStore. | 2879 // Inject our initial cookies into the mock PersistentCookieStore. |
| 2902 store->SetLoadExpectation(true, std::move(initial_cookies)); | 2880 store->SetLoadExpectation(true, std::move(initial_cookies)); |
| 2903 | 2881 |
| 2904 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2882 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2905 | 2883 |
| 2906 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2884 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2925 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2903 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| 2926 | 2904 |
| 2927 // Set a non-secure cookie on a cryptographic scheme. | 2905 // Set a non-secure cookie on a cryptographic scheme. |
| 2928 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "C=D; path=/;")); | 2906 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "C=D; path=/;")); |
| 2929 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2907 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2930 histograms.ExpectBucketCount( | 2908 histograms.ExpectBucketCount( |
| 2931 cookie_source_histogram, | 2909 cookie_source_histogram, |
| 2932 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2910 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| 2933 | 2911 |
| 2934 // Set a secure cookie on a non-cryptographic scheme. | 2912 // Set a secure cookie on a non-cryptographic scheme. |
| 2935 EXPECT_TRUE( | 2913 EXPECT_FALSE( |
| 2936 SetCookie(cm.get(), http_www_google_.url(), "D=E; path=/; Secure")); | 2914 SetCookie(cm.get(), http_www_google_.url(), "D=E; path=/; Secure")); |
| 2937 histograms.ExpectTotalCount(cookie_source_histogram, 3); | 2915 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2938 histograms.ExpectBucketCount( | 2916 histograms.ExpectBucketCount( |
| 2939 cookie_source_histogram, | 2917 cookie_source_histogram, |
| 2940 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2918 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); |
| 2941 | 2919 |
| 2942 // Overwrite a secure cookie (set by a cryptographic scheme) on a | 2920 // Overwrite a secure cookie (set by a cryptographic scheme) on a |
| 2943 // non-cryptographic scheme. | 2921 // non-cryptographic scheme. |
| 2944 EXPECT_TRUE( | 2922 EXPECT_FALSE( |
| 2945 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/; Secure")); | 2923 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/; Secure")); |
| 2946 histograms.ExpectTotalCount(cookie_source_histogram, 4); | 2924 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2947 histograms.ExpectBucketCount( | 2925 histograms.ExpectBucketCount( |
| 2948 cookie_source_histogram, | 2926 cookie_source_histogram, |
| 2949 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); | 2927 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); |
| 2950 histograms.ExpectBucketCount( | 2928 histograms.ExpectBucketCount( |
| 2951 cookie_source_histogram, | 2929 cookie_source_histogram, |
| 2952 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 2); | 2930 CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 0); |
| 2953 | 2931 |
| 2954 // Test that clearing a secure cookie on a http:// URL does not get | 2932 // Test that attempting to clear a secure cookie on a http:// URL does |
| 2955 // counted. | 2933 // nothing. |
| 2956 EXPECT_TRUE( | 2934 EXPECT_TRUE( |
| 2957 SetCookie(cm.get(), https_www_google_.url(), "F=G; path=/; Secure")); | 2935 SetCookie(cm.get(), https_www_google_.url(), "F=G; path=/; Secure")); |
| 2958 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2936 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
| 2959 std::string cookies1 = GetCookies(cm.get(), https_www_google_.url()); | 2937 std::string cookies1 = GetCookies(cm.get(), https_www_google_.url()); |
| 2960 EXPECT_NE(std::string::npos, cookies1.find("F=G")); | 2938 EXPECT_NE(std::string::npos, cookies1.find("F=G")); |
| 2961 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), | 2939 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), |
| 2962 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); | 2940 "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); |
| 2963 std::string cookies2 = GetCookies(cm.get(), https_www_google_.url()); | 2941 std::string cookies2 = GetCookies(cm.get(), https_www_google_.url()); |
| 2964 EXPECT_EQ(std::string::npos, cookies2.find("F=G")); | 2942 EXPECT_NE(std::string::npos, cookies2.find("F=G")); |
| 2965 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2943 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
| 2966 | 2944 |
| 2967 // Set a non-secure cookie on a non-cryptographic scheme. | 2945 // Set a non-secure cookie on a non-cryptographic scheme. |
| 2968 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/")); | 2946 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "H=I; path=/")); |
| 2969 histograms.ExpectTotalCount(cookie_source_histogram, 6); | 2947 histograms.ExpectTotalCount(cookie_source_histogram, 4); |
| 2970 histograms.ExpectBucketCount( | 2948 histograms.ExpectBucketCount( |
| 2971 cookie_source_histogram, | 2949 cookie_source_histogram, |
| 2972 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); | 2950 CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); |
| 2973 } | 2951 } |
| 2974 | 2952 |
| 2975 // Test that cookie delete equivalent histograms are recorded correctly when | 2953 // Test that cookie delete equivalent histograms are recorded correctly. |
| 2976 // strict secure cookies are not enabled. | |
| 2977 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { | 2954 TEST_F(CookieMonsterTest, CookieDeleteEquivalentHistogramTest) { |
| 2978 base::HistogramTester histograms; | 2955 base::HistogramTester histograms; |
| 2979 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | 2956 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; |
| 2980 | 2957 |
| 2981 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2958 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2982 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2959 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2983 | 2960 |
| 2984 // Set a secure cookie from a secure origin | 2961 // Set a secure cookie from a secure origin |
| 2985 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | 2962 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); |
| 2986 histograms.ExpectTotalCount(cookie_source_histogram, 1); | 2963 histograms.ExpectTotalCount(cookie_source_histogram, 1); |
| 2987 histograms.ExpectBucketCount(cookie_source_histogram, | 2964 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2988 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2965 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2989 1); | 2966 1); |
| 2990 | 2967 |
| 2991 // Set a new cookie with a different name from a variety of origins (including | 2968 // Set a new cookie with a different name from a variety of origins (including |
| 2992 // the same one). | 2969 // the same one). |
| 2993 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "B=A;")); | 2970 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "B=A;")); |
| 2994 histograms.ExpectTotalCount(cookie_source_histogram, 2); | 2971 histograms.ExpectTotalCount(cookie_source_histogram, 2); |
| 2995 histograms.ExpectBucketCount(cookie_source_histogram, | 2972 histograms.ExpectBucketCount(cookie_source_histogram, |
| 2996 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2973 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 2997 2); | 2974 2); |
| 2998 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=A;")); | 2975 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=A;")); |
| 2999 histograms.ExpectTotalCount(cookie_source_histogram, 3); | 2976 histograms.ExpectTotalCount(cookie_source_histogram, 3); |
| 3000 histograms.ExpectBucketCount(cookie_source_histogram, | 2977 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3001 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2978 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3002 3); | 2979 3); |
| 3003 | 2980 |
| 3004 // Set a non-secure cookie from an insecure origin that matches the name of an | 2981 // Set a non-secure cookie from an insecure origin that matches the name of an |
| 3005 // already existing cookie and additionally is equivalent to the existing | 2982 // already existing cookie and additionally is equivalent to the existing |
| 3006 // cookie. | 2983 // cookie. This should fail since it's trying to overwrite a secure cookie. |
| 3007 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "A=B;")); | 2984 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), "A=B;")); |
| 3008 histograms.ExpectTotalCount(cookie_source_histogram, 5); | 2985 histograms.ExpectTotalCount(cookie_source_histogram, 6); |
| 3009 histograms.ExpectBucketCount(cookie_source_histogram, | 2986 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3010 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 2987 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3011 4); | 2988 4); |
| 3012 histograms.ExpectBucketCount(cookie_source_histogram, | 2989 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3013 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | 2990 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, |
| 3014 1); | 2991 0); |
| 2992 histograms.ExpectBucketCount( |
| 2993 cookie_source_histogram, |
| 2994 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 1); |
| 2995 histograms.ExpectBucketCount( |
| 2996 cookie_source_histogram, |
| 2997 CookieMonster::COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED, 1); |
| 3015 | 2998 |
| 3016 // Set a non-secure cookie from an insecure origin that matches the name of an | 2999 // Set a non-secure cookie from an insecure origin that matches the name of an |
| 3017 // already existing cookie but is not equivalent. | 3000 // already existing cookie but is not equivalent. This should fail since it's |
| 3018 EXPECT_TRUE( | 3001 // trying to shadow a secure cookie. |
| 3002 EXPECT_FALSE( |
| 3019 SetCookie(cm.get(), http_www_google_.url(), "A=C; path=/some/path")); | 3003 SetCookie(cm.get(), http_www_google_.url(), "A=C; path=/some/path")); |
| 3020 histograms.ExpectTotalCount(cookie_source_histogram, 6); | 3004 histograms.ExpectTotalCount(cookie_source_histogram, 8); |
| 3021 histograms.ExpectBucketCount(cookie_source_histogram, | 3005 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3022 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3006 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3023 5); | 3007 5); |
| 3008 histograms.ExpectBucketCount( |
| 3009 cookie_source_histogram, |
| 3010 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 2); |
| 3024 | 3011 |
| 3025 // Set a secure cookie from a secure origin that matches the name of an | 3012 // Set a secure cookie from a secure origin that matches the name of an |
| 3026 // already existing cookies and is equivalent. | 3013 // already existing cookies and is equivalent. |
| 3027 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=D; secure")); | 3014 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=D; secure")); |
| 3028 histograms.ExpectTotalCount(cookie_source_histogram, 8); | 3015 histograms.ExpectTotalCount(cookie_source_histogram, 10); |
| 3029 histograms.ExpectBucketCount(cookie_source_histogram, | 3016 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3030 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3017 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3031 6); | 3018 6); |
| 3032 histograms.ExpectBucketCount(cookie_source_histogram, | 3019 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3033 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | 3020 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, |
| 3034 2); | 3021 1); |
| 3035 | 3022 |
| 3036 // Set a secure cookie from a secure origin that matches the name of an | 3023 // Set a secure cookie from a secure origin that matches the name of an |
| 3037 // already existing cookie and is not equivalent. | 3024 // already existing cookie and is not equivalent. |
| 3038 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | 3025 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), |
| 3039 "A=E; secure; path=/some/other/path")); | 3026 "A=E; secure; path=/some/other/path")); |
| 3040 histograms.ExpectTotalCount(cookie_source_histogram, 9); | 3027 histograms.ExpectTotalCount(cookie_source_histogram, 11); |
| 3041 histograms.ExpectBucketCount(cookie_source_histogram, | 3028 histograms.ExpectBucketCount(cookie_source_histogram, |
| 3042 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3029 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
| 3043 7); | 3030 7); |
| 3044 } | 3031 } |
| 3045 | 3032 |
| 3046 TEST_F(CookieMonsterStrictSecureTest, SetSecureCookies) { | 3033 TEST_F(CookieMonsterTest, SetSecureCookies) { |
| 3047 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3034 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 3048 GURL http_url("http://www.google.com"); | 3035 GURL http_url("http://www.google.com"); |
| 3049 GURL http_superdomain_url("http://google.com"); | 3036 GURL http_superdomain_url("http://google.com"); |
| 3050 GURL https_url("https://www.google.com"); | 3037 GURL https_url("https://www.google.com"); |
| 3051 | 3038 |
| 3052 // A non-secure cookie can be created from either a URL with a secure or | 3039 // A non-secure cookie can be created from either a URL with a secure or |
| 3053 // insecure scheme. | 3040 // insecure scheme. |
| 3054 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); | 3041 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); |
| 3055 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); | 3042 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); |
| 3056 | 3043 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3102 // so the insecure examples aren't trying to overwrite the one above. | 3089 // so the insecure examples aren't trying to overwrite the one above. |
| 3103 EXPECT_TRUE(SetCookie(cm.get(), https_url, "B=C; Secure; domain=google.com")); | 3090 EXPECT_TRUE(SetCookie(cm.get(), https_url, "B=C; Secure; domain=google.com")); |
| 3104 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=google.com")); | 3091 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=google.com")); |
| 3105 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); | 3092 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); |
| 3106 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); | 3093 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); |
| 3107 | 3094 |
| 3108 // Verify that if an httponly version of the cookie exists, adding a Secure | 3095 // Verify that if an httponly version of the cookie exists, adding a Secure |
| 3109 // version of the cookie still does not overwrite it. | 3096 // version of the cookie still does not overwrite it. |
| 3110 CookieOptions include_httponly; | 3097 CookieOptions include_httponly; |
| 3111 include_httponly.set_include_httponly(); | 3098 include_httponly.set_include_httponly(); |
| 3112 include_httponly.set_enforce_strict_secure(); | |
| 3113 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", | 3099 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", |
| 3114 include_httponly)); | 3100 include_httponly)); |
| 3115 // Note that the lack of an explicit options object below uses the default, | 3101 // Note that the lack of an explicit options object below uses the default, |
| 3116 // which in this case includes "exclude_httponly = true". | 3102 // which in this case includes "exclude_httponly = true". |
| 3117 EXPECT_FALSE(SetCookie(cm.get(), https_url, "C=E; Secure")); | 3103 EXPECT_FALSE(SetCookie(cm.get(), https_url, "C=E; Secure")); |
| 3118 } | 3104 } |
| 3119 | 3105 |
| 3120 // Tests for behavior if strict secure cookies is enabled. | 3106 // Tests for behavior for strict secure cookies. |
| 3121 TEST_F(CookieMonsterStrictSecureTest, EvictSecureCookies) { | 3107 TEST_F(CookieMonsterTest, EvictSecureCookies) { |
| 3122 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 3108 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
| 3123 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 3109 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
| 3124 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 3110 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
| 3125 CookieMonster::kDomainPurgeCookies); | 3111 CookieMonster::kDomainPurgeCookies); |
| 3126 DCHECK_EQ(3300U, CookieMonster::kMaxCookies); | 3112 DCHECK_EQ(3300U, CookieMonster::kMaxCookies); |
| 3127 DCHECK_EQ(30, CookieMonster::kSafeFromGlobalPurgeDays); | 3113 DCHECK_EQ(30, CookieMonster::kSafeFromGlobalPurgeDays); |
| 3128 | 3114 |
| 3129 // If secure cookies for one domain hit the per domain limit (180), a | 3115 // If secure cookies for one domain hit the per domain limit (180), a |
| 3130 // non-secure cookie will not evict them (and, in fact, the non-secure cookie | 3116 // non-secure cookie will not evict them (and, in fact, the non-secure cookie |
| 3131 // will be removed right after creation). | 3117 // will be removed right after creation). |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3240 // cookies are removed so that the global total number of cookies is at the | 3226 // cookies are removed so that the global total number of cookies is at the |
| 3241 // global purge goal (3000), but the secure cookies are not evicted. | 3227 // global purge goal (3000), but the secure cookies are not evicted. |
| 3242 const CookiesEntry test14[] = {{1U, true}}; | 3228 const CookiesEntry test14[] = {{1U, true}}; |
| 3243 const AltHosts test14_alt_hosts(1500, 1800); | 3229 const AltHosts test14_alt_hosts(1500, 1800); |
| 3244 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, | 3230 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, |
| 3245 &test14_alt_hosts); | 3231 &test14_alt_hosts); |
| 3246 } | 3232 } |
| 3247 | 3233 |
| 3248 // Tests that strict secure cookies doesn't trip equivalent cookie checks | 3234 // Tests that strict secure cookies doesn't trip equivalent cookie checks |
| 3249 // accidentally. Regression test for https://crbug.com/569943. | 3235 // accidentally. Regression test for https://crbug.com/569943. |
| 3250 TEST_F(CookieMonsterStrictSecureTest, EquivalentCookies) { | 3236 TEST_F(CookieMonsterTest, EquivalentCookies) { |
| 3251 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3237 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
| 3252 GURL http_url("http://www.google.com"); | 3238 GURL http_url("http://www.google.com"); |
| 3253 GURL http_superdomain_url("http://google.com"); | 3239 GURL http_superdomain_url("http://google.com"); |
| 3254 GURL https_url("https://www.google.com"); | 3240 GURL https_url("https://www.google.com"); |
| 3255 | 3241 |
| 3256 // Tests that non-equivalent cookies because of the path attribute can be set | 3242 // Tests that non-equivalent cookies because of the path attribute can be set |
| 3257 // successfully. | 3243 // successfully. |
| 3258 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3244 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 3259 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); | 3245 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); |
| 3260 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); | 3246 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); |
| 3261 | 3247 |
| 3262 // Tests that non-equivalent cookies because of the domain attribute can be | 3248 // Tests that non-equivalent cookies because of the domain attribute can be |
| 3263 // set successfully. | 3249 // set successfully. |
| 3264 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3250 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
| 3265 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); | 3251 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); |
| 3266 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); | 3252 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); |
| 3267 } | 3253 } |
| 3268 | 3254 |
| 3269 // Test that cookie delete equivalent histograms are recorded correctly for | |
| 3270 // strict secure cookies. | |
| 3271 TEST_F(CookieMonsterStrictSecureTest, CookieDeleteEquivalentHistogramTest) { | |
| 3272 base::HistogramTester histograms; | |
| 3273 const std::string cookie_source_histogram = "Cookie.CookieDeleteEquivalent"; | |
| 3274 | |
| 3275 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | |
| 3276 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | |
| 3277 | |
| 3278 // Set a secure cookie from a secure origin | |
| 3279 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; Secure")); | |
| 3280 histograms.ExpectTotalCount(cookie_source_histogram, 1); | |
| 3281 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3282 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
| 3283 1); | |
| 3284 | |
| 3285 // Set a new cookie with a different name from a variety of origins (including | |
| 3286 // the same one). | |
| 3287 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "B=A;")); | |
| 3288 histograms.ExpectTotalCount(cookie_source_histogram, 2); | |
| 3289 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3290 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
| 3291 2); | |
| 3292 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "C=A;")); | |
| 3293 histograms.ExpectTotalCount(cookie_source_histogram, 3); | |
| 3294 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3295 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
| 3296 3); | |
| 3297 | |
| 3298 // Set a non-secure cookie from an insecure origin that matches the name of an | |
| 3299 // already existing cookie and additionally is equivalent to the existing | |
| 3300 // cookie. | |
| 3301 EXPECT_FALSE(SetCookie(cm.get(), http_www_google_.url(), "A=B;")); | |
| 3302 histograms.ExpectTotalCount(cookie_source_histogram, 6); | |
| 3303 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3304 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
| 3305 4); | |
| 3306 histograms.ExpectBucketCount( | |
| 3307 cookie_source_histogram, | |
| 3308 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 1); | |
| 3309 histograms.ExpectBucketCount( | |
| 3310 cookie_source_histogram, | |
| 3311 CookieMonster::COOKIE_DELETE_EQUIVALENT_WOULD_HAVE_DELETED, 1); | |
| 3312 | |
| 3313 // Set a non-secure cookie from an insecure origin that matches the name of an | |
| 3314 // already existing cookie but is not equivalent. | |
| 3315 EXPECT_FALSE( | |
| 3316 SetCookie(cm.get(), http_www_google_.url(), "A=B; path=/some/path")); | |
| 3317 histograms.ExpectTotalCount(cookie_source_histogram, 8); | |
| 3318 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3319 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
| 3320 5); | |
| 3321 histograms.ExpectBucketCount( | |
| 3322 cookie_source_histogram, | |
| 3323 CookieMonster::COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE, 2); | |
| 3324 | |
| 3325 // Set a secure cookie from a secure origin that matches the name of an | |
| 3326 // already existing cookies and is equivalent. | |
| 3327 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), "A=B; secure")); | |
| 3328 histograms.ExpectTotalCount(cookie_source_histogram, 10); | |
| 3329 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3330 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
| 3331 6); | |
| 3332 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3333 CookieMonster::COOKIE_DELETE_EQUIVALENT_FOUND, | |
| 3334 1); | |
| 3335 | |
| 3336 // Set a secure cookie from a secure origin that matches the name of an | |
| 3337 // already existing cookie and is not equivalent. | |
| 3338 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | |
| 3339 "A=C; secure; path=/some/path")); | |
| 3340 histograms.ExpectTotalCount(cookie_source_histogram, 11); | |
| 3341 histograms.ExpectBucketCount(cookie_source_histogram, | |
| 3342 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | |
| 3343 7); | |
| 3344 } | |
| 3345 | |
| 3346 class CookieMonsterNotificationTest : public CookieMonsterTest { | 3255 class CookieMonsterNotificationTest : public CookieMonsterTest { |
| 3347 public: | 3256 public: |
| 3348 CookieMonsterNotificationTest() | 3257 CookieMonsterNotificationTest() |
| 3349 : test_url_("http://www.google.com/foo"), | 3258 : test_url_("http://www.google.com/foo"), |
| 3350 store_(new MockPersistentCookieStore), | 3259 store_(new MockPersistentCookieStore), |
| 3351 monster_(new CookieMonster(store_.get(), nullptr)) {} | 3260 monster_(new CookieMonster(store_.get(), nullptr)) {} |
| 3352 | 3261 |
| 3353 ~CookieMonsterNotificationTest() override {} | 3262 ~CookieMonsterNotificationTest() override {} |
| 3354 | 3263 |
| 3355 CookieMonster* monster() { return monster_.get(); } | 3264 CookieMonster* monster() { return monster_.get(); } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3493 monster()->AddCallbackForCookie( | 3402 monster()->AddCallbackForCookie( |
| 3494 test_url_, "abc", | 3403 test_url_, "abc", |
| 3495 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3404 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 3496 SetCookie(monster(), test_url_, "abc=def"); | 3405 SetCookie(monster(), test_url_, "abc=def"); |
| 3497 base::RunLoop().RunUntilIdle(); | 3406 base::RunLoop().RunUntilIdle(); |
| 3498 EXPECT_EQ(1U, cookies0.size()); | 3407 EXPECT_EQ(1U, cookies0.size()); |
| 3499 EXPECT_EQ(1U, cookies0.size()); | 3408 EXPECT_EQ(1U, cookies0.size()); |
| 3500 } | 3409 } |
| 3501 | 3410 |
| 3502 } // namespace net | 3411 } // namespace net |
| OLD | NEW |