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

Side by Side Diff: net/cookies/canonical_cookie_unittest.cc

Issue 1868493002: Ignore cookies with invalid 'SameSite' attribute values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename Created 4 years, 8 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 | « no previous file | net/cookies/parsed_cookie.h » ('j') | 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/cookies/canonical_cookie.h" 5 #include "net/cookies/canonical_cookie.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "net/cookies/cookie_constants.h" 9 #include "net/cookies/cookie_constants.h"
10 #include "net/cookies/cookie_options.h" 10 #include "net/cookies/cookie_options.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // Test creating SameSite cookies. 86 // Test creating SameSite cookies.
87 CookieOptions same_site_options; 87 CookieOptions same_site_options;
88 same_site_options.set_same_site_cookie_mode( 88 same_site_options.set_same_site_cookie_mode(
89 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); 89 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
90 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, 90 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time,
91 same_site_options); 91 same_site_options);
92 EXPECT_TRUE(cookie.get()); 92 EXPECT_TRUE(cookie.get());
93 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); 93 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite());
94 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time, 94 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time,
95 same_site_options); 95 same_site_options);
96 EXPECT_TRUE(cookie.get());
97 EXPECT_EQ(CookieSameSite::LAX_MODE, cookie->SameSite());
98 cookie = CanonicalCookie::Create(url, "A=2; SameSite", creation_time,
99 same_site_options);
100 EXPECT_TRUE(cookie.get());
101 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
102 96
103 // Test the creating cookies using specific parameter instead of a cookie 97 // Test the creating cookies using specific parameter instead of a cookie
104 // string. 98 // string.
105 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test", 99 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test",
106 creation_time, base::Time(), false, false, 100 creation_time, base::Time(), false, false,
107 CookieSameSite::DEFAULT_MODE, false, 101 CookieSameSite::DEFAULT_MODE, false,
108 COOKIE_PRIORITY_DEFAULT); 102 COOKIE_PRIORITY_DEFAULT);
109 EXPECT_EQ(url.GetOrigin(), cookie->Source()); 103 EXPECT_EQ(url.GetOrigin(), cookie->Source());
110 EXPECT_EQ("A", cookie->Name()); 104 EXPECT_EQ("A", cookie->Name());
111 EXPECT_EQ("2", cookie->Value()); 105 EXPECT_EQ("2", cookie->Value());
(...skipping 10 matching lines...) Expand all
122 EXPECT_EQ(url.GetOrigin(), cookie->Source()); 116 EXPECT_EQ(url.GetOrigin(), cookie->Source());
123 EXPECT_EQ("A", cookie->Name()); 117 EXPECT_EQ("A", cookie->Name());
124 EXPECT_EQ("2", cookie->Value()); 118 EXPECT_EQ("2", cookie->Value());
125 EXPECT_EQ(".www.example.com", cookie->Domain()); 119 EXPECT_EQ(".www.example.com", cookie->Domain());
126 EXPECT_EQ("/test", cookie->Path()); 120 EXPECT_EQ("/test", cookie->Path());
127 EXPECT_FALSE(cookie->IsSecure()); 121 EXPECT_FALSE(cookie->IsSecure());
128 EXPECT_FALSE(cookie->IsHttpOnly()); 122 EXPECT_FALSE(cookie->IsHttpOnly());
129 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); 123 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite());
130 } 124 }
131 125
126 TEST(CanonicalCookieTest, CreateInvalidSameSite) {
127 GURL url("http://www.example.com/test/foo.html");
128 base::Time now = base::Time::Now();
129 scoped_ptr<CanonicalCookie> cookie;
130 CookieOptions options;
131
132 // Invalid 'SameSite' attribute values.
133 options.set_same_site_cookie_mode(
134 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
135
136 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Invalid", now, options);
137 EXPECT_EQ(nullptr, cookie.get());
138
139 cookie = CanonicalCookie::Create(url, "A=2; SameSite", now, options);
140 EXPECT_EQ(nullptr, cookie.get());
141 }
142
132 TEST(CanonicalCookieTest, EmptyExpiry) { 143 TEST(CanonicalCookieTest, EmptyExpiry) {
133 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108"); 144 GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108");
134 base::Time creation_time = base::Time::Now(); 145 base::Time creation_time = base::Time::Now();
135 CookieOptions options; 146 CookieOptions options;
136 147
137 std::string cookie_line = 148 std::string cookie_line =
138 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires="; 149 "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires=";
139 scoped_ptr<CanonicalCookie> cookie( 150 scoped_ptr<CanonicalCookie> cookie(
140 CanonicalCookie::Create(url, cookie_line, creation_time, options)); 151 CanonicalCookie::Create(url, cookie_line, creation_time, options));
141 EXPECT_TRUE(cookie.get()); 152 EXPECT_TRUE(cookie.get());
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 719 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
709 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", 720 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure",
710 creation_time, options)); 721 creation_time, options));
711 histograms.ExpectBucketCount(kCookiePrefixHistogram, 722 histograms.ExpectBucketCount(kCookiePrefixHistogram,
712 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); 723 CanonicalCookie::COOKIE_PREFIX_SECURE, 2);
713 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, 724 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram,
714 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); 725 CanonicalCookie::COOKIE_PREFIX_SECURE, 1);
715 } 726 }
716 727
717 } // namespace net 728 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cookies/parsed_cookie.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698