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/canonical_cookie.h" | 5 #include "net/cookies/canonical_cookie.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
10 #include "net/cookies/cookie_constants.h" | 10 #include "net/cookies/cookie_constants.h" |
11 #include "net/cookies/cookie_options.h" | 11 #include "net/cookies/cookie_options.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 TEST(CanonicalCookieTest, Constructor) { | 17 TEST(CanonicalCookieTest, Constructor) { |
18 GURL url("http://www.example.com/test"); | 18 GURL url("http://www.example.com/test"); |
19 base::Time current_time = base::Time::Now(); | 19 base::Time current_time = base::Time::Now(); |
20 | 20 |
21 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 21 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
22 url, "A", "2", std::string(), "/test", current_time, base::Time(), false, | 22 url, "A", "2", std::string(), "/test", current_time, base::Time(), false, |
23 false, CookieSameSite::DEFAULT_MODE, false, COOKIE_PRIORITY_DEFAULT)); | 23 false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
24 EXPECT_EQ("A", cookie->Name()); | 24 EXPECT_EQ("A", cookie->Name()); |
25 EXPECT_EQ("2", cookie->Value()); | 25 EXPECT_EQ("2", cookie->Value()); |
26 EXPECT_EQ("www.example.com", cookie->Domain()); | 26 EXPECT_EQ("www.example.com", cookie->Domain()); |
27 EXPECT_EQ("/test", cookie->Path()); | 27 EXPECT_EQ("/test", cookie->Path()); |
28 EXPECT_FALSE(cookie->IsSecure()); | 28 EXPECT_FALSE(cookie->IsSecure()); |
29 EXPECT_FALSE(cookie->IsHttpOnly()); | 29 EXPECT_FALSE(cookie->IsHttpOnly()); |
30 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); | 30 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
31 | 31 |
32 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( | 32 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( |
33 url, "A", "2", ".www.example.com", std::string(), current_time, | 33 url, "A", "2", ".www.example.com", std::string(), current_time, |
34 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, false, | 34 base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
35 COOKIE_PRIORITY_DEFAULT)); | 35 COOKIE_PRIORITY_DEFAULT)); |
36 EXPECT_EQ("A", cookie2->Name()); | 36 EXPECT_EQ("A", cookie2->Name()); |
37 EXPECT_EQ("2", cookie2->Value()); | 37 EXPECT_EQ("2", cookie2->Value()); |
38 EXPECT_EQ(".www.example.com", cookie2->Domain()); | 38 EXPECT_EQ(".www.example.com", cookie2->Domain()); |
39 EXPECT_EQ("/", cookie2->Path()); | 39 EXPECT_EQ("/", cookie2->Path()); |
40 EXPECT_FALSE(cookie2->IsSecure()); | 40 EXPECT_FALSE(cookie2->IsSecure()); |
41 EXPECT_FALSE(cookie2->IsHttpOnly()); | 41 EXPECT_FALSE(cookie2->IsHttpOnly()); |
42 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite()); | 42 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie2->SameSite()); |
43 } | 43 } |
44 | 44 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | 86 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); |
87 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, | 87 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Strict", creation_time, |
88 same_site_options); | 88 same_site_options); |
89 EXPECT_TRUE(cookie.get()); | 89 EXPECT_TRUE(cookie.get()); |
90 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); | 90 EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie->SameSite()); |
91 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time, | 91 cookie = CanonicalCookie::Create(url, "A=2; SameSite=Lax", creation_time, |
92 same_site_options); | 92 same_site_options); |
93 | 93 |
94 // Test the creating cookies using specific parameter instead of a cookie | 94 // Test the creating cookies using specific parameter instead of a cookie |
95 // string. | 95 // string. |
96 cookie = CanonicalCookie::Create(url, "A", "2", "www.example.com", "/test", | 96 cookie = CanonicalCookie::Create( |
97 creation_time, base::Time(), false, false, | 97 url, "A", "2", "www.example.com", "/test", creation_time, base::Time(), |
98 CookieSameSite::DEFAULT_MODE, false, | 98 false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); |
99 COOKIE_PRIORITY_DEFAULT); | |
100 EXPECT_EQ("A", cookie->Name()); | 99 EXPECT_EQ("A", cookie->Name()); |
101 EXPECT_EQ("2", cookie->Value()); | 100 EXPECT_EQ("2", cookie->Value()); |
102 EXPECT_EQ(".www.example.com", cookie->Domain()); | 101 EXPECT_EQ(".www.example.com", cookie->Domain()); |
103 EXPECT_EQ("/test", cookie->Path()); | 102 EXPECT_EQ("/test", cookie->Path()); |
104 EXPECT_FALSE(cookie->IsSecure()); | 103 EXPECT_FALSE(cookie->IsSecure()); |
105 EXPECT_FALSE(cookie->IsHttpOnly()); | 104 EXPECT_FALSE(cookie->IsHttpOnly()); |
106 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); | 105 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
107 | 106 |
108 cookie = CanonicalCookie::Create(url, "A", "2", ".www.example.com", "/test", | 107 cookie = CanonicalCookie::Create( |
109 creation_time, base::Time(), false, false, | 108 url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(), |
110 CookieSameSite::DEFAULT_MODE, false, | 109 false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); |
111 COOKIE_PRIORITY_DEFAULT); | |
112 EXPECT_EQ("A", cookie->Name()); | 110 EXPECT_EQ("A", cookie->Name()); |
113 EXPECT_EQ("2", cookie->Value()); | 111 EXPECT_EQ("2", cookie->Value()); |
114 EXPECT_EQ(".www.example.com", cookie->Domain()); | 112 EXPECT_EQ(".www.example.com", cookie->Domain()); |
115 EXPECT_EQ("/test", cookie->Path()); | 113 EXPECT_EQ("/test", cookie->Path()); |
116 EXPECT_FALSE(cookie->IsSecure()); | 114 EXPECT_FALSE(cookie->IsSecure()); |
117 EXPECT_FALSE(cookie->IsHttpOnly()); | 115 EXPECT_FALSE(cookie->IsHttpOnly()); |
118 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); | 116 EXPECT_EQ(CookieSameSite::NO_RESTRICTION, cookie->SameSite()); |
119 } | 117 } |
120 | 118 |
121 TEST(CanonicalCookieTest, CreateInvalidSameSite) { | 119 TEST(CanonicalCookieTest, CreateInvalidSameSite) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 std::string cookie_path = "/path"; | 172 std::string cookie_path = "/path"; |
175 base::Time creation_time = base::Time::Now(); | 173 base::Time creation_time = base::Time::Now(); |
176 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); | 174 base::Time expiration_time = creation_time + base::TimeDelta::FromDays(2); |
177 bool secure(false); | 175 bool secure(false); |
178 bool httponly(false); | 176 bool httponly(false); |
179 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); | 177 CookieSameSite same_site(CookieSameSite::NO_RESTRICTION); |
180 | 178 |
181 // Test that a cookie is equivalent to itself. | 179 // Test that a cookie is equivalent to itself. |
182 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( | 180 std::unique_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
183 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 181 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
184 expiration_time, secure, httponly, same_site, false, | 182 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); |
185 COOKIE_PRIORITY_MEDIUM)); | |
186 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); | 183 EXPECT_TRUE(cookie->IsEquivalent(*cookie)); |
187 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 184 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
188 | 185 |
189 // Test that two identical cookies are equivalent. | 186 // Test that two identical cookies are equivalent. |
190 std::unique_ptr<CanonicalCookie> other_cookie(CanonicalCookie::Create( | 187 std::unique_ptr<CanonicalCookie> other_cookie(CanonicalCookie::Create( |
191 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, | 188 url, cookie_name, cookie_value, cookie_domain, cookie_path, creation_time, |
192 expiration_time, secure, httponly, same_site, false, | 189 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM)); |
193 COOKIE_PRIORITY_MEDIUM)); | |
194 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 190 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
195 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 191 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
196 | 192 |
197 // Tests that use different variations of attribute values that | 193 // Tests that use different variations of attribute values that |
198 // DON'T affect cookie equivalence. | 194 // DON'T affect cookie equivalence. |
199 other_cookie = | 195 other_cookie = CanonicalCookie::Create( |
200 CanonicalCookie::Create(url, cookie_name, "2", cookie_domain, cookie_path, | 196 url, cookie_name, "2", cookie_domain, cookie_path, creation_time, |
201 creation_time, expiration_time, secure, httponly, | 197 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_HIGH); |
202 same_site, false, COOKIE_PRIORITY_HIGH); | |
203 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 198 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
204 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 199 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
205 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 200 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
206 | 201 |
207 base::Time other_creation_time = | 202 base::Time other_creation_time = |
208 creation_time + base::TimeDelta::FromMinutes(2); | 203 creation_time + base::TimeDelta::FromMinutes(2); |
209 other_cookie = CanonicalCookie::Create( | 204 other_cookie = CanonicalCookie::Create( |
210 url, cookie_name, "2", cookie_domain, cookie_path, other_creation_time, | 205 url, cookie_name, "2", cookie_domain, cookie_path, other_creation_time, |
211 expiration_time, secure, httponly, same_site, false, | 206 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); |
212 COOKIE_PRIORITY_MEDIUM); | |
213 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 207 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
214 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 208 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
215 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 209 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
216 | 210 |
217 other_cookie = CanonicalCookie::Create( | 211 other_cookie = CanonicalCookie::Create( |
218 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 212 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
219 expiration_time, true, httponly, same_site, false, COOKIE_PRIORITY_LOW); | 213 expiration_time, true, httponly, same_site, COOKIE_PRIORITY_LOW); |
220 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 214 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
221 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 215 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
222 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 216 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
223 | 217 |
224 other_cookie = CanonicalCookie::Create( | 218 other_cookie = CanonicalCookie::Create( |
225 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 219 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
226 expiration_time, secure, true, same_site, false, COOKIE_PRIORITY_LOW); | 220 expiration_time, secure, true, same_site, COOKIE_PRIORITY_LOW); |
227 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 221 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
228 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 222 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
229 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 223 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
230 | 224 |
231 other_cookie = CanonicalCookie::Create( | 225 other_cookie = CanonicalCookie::Create( |
232 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, | 226 url, cookie_name, cookie_name, cookie_domain, cookie_path, creation_time, |
233 expiration_time, secure, httponly, CookieSameSite::STRICT_MODE, false, | 227 expiration_time, secure, httponly, CookieSameSite::STRICT_MODE, |
234 COOKIE_PRIORITY_LOW); | 228 COOKIE_PRIORITY_LOW); |
235 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); | 229 EXPECT_TRUE(cookie->IsEquivalent(*other_cookie)); |
236 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 230 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
237 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 231 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
238 | 232 |
239 // Cookies whose names mismatch are not equivalent. | 233 // Cookies whose names mismatch are not equivalent. |
240 other_cookie = CanonicalCookie::Create( | 234 other_cookie = CanonicalCookie::Create( |
241 url, "B", cookie_value, cookie_domain, cookie_path, creation_time, | 235 url, "B", cookie_value, cookie_domain, cookie_path, creation_time, |
242 expiration_time, secure, httponly, same_site, false, | 236 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); |
243 COOKIE_PRIORITY_MEDIUM); | |
244 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 237 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
245 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 238 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
246 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 239 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
247 | 240 |
248 // A domain cookie at 'www.example.com' is not equivalent to a host cookie | 241 // A domain cookie at 'www.example.com' is not equivalent to a host cookie |
249 // at the same domain. These are, however, equivalent according to the laxer | 242 // at the same domain. These are, however, equivalent according to the laxer |
250 // rules of 'IsEquivalentForSecureCookieMatching'. | 243 // rules of 'IsEquivalentForSecureCookieMatching'. |
251 other_cookie = CanonicalCookie::Create( | 244 other_cookie = CanonicalCookie::Create( |
252 url, cookie_name, cookie_value, std::string(), cookie_path, creation_time, | 245 url, cookie_name, cookie_value, std::string(), cookie_path, creation_time, |
253 expiration_time, secure, httponly, same_site, false, | 246 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); |
254 COOKIE_PRIORITY_MEDIUM); | |
255 EXPECT_TRUE(cookie->IsDomainCookie()); | 247 EXPECT_TRUE(cookie->IsDomainCookie()); |
256 EXPECT_FALSE(other_cookie->IsDomainCookie()); | 248 EXPECT_FALSE(other_cookie->IsDomainCookie()); |
257 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 249 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
258 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 250 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
259 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 251 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
260 | 252 |
261 // Likewise, a cookie on 'example.com' is not equivalent to a cookie on | 253 // Likewise, a cookie on 'example.com' is not equivalent to a cookie on |
262 // 'www.example.com', but they are equivalent for secure cookie matching. | 254 // 'www.example.com', but they are equivalent for secure cookie matching. |
263 other_cookie = CanonicalCookie::Create( | 255 other_cookie = CanonicalCookie::Create( |
264 url, cookie_name, cookie_value, ".example.com", cookie_path, | 256 url, cookie_name, cookie_value, ".example.com", cookie_path, |
265 creation_time, expiration_time, secure, httponly, same_site, false, | 257 creation_time, expiration_time, secure, httponly, same_site, |
266 COOKIE_PRIORITY_MEDIUM); | 258 COOKIE_PRIORITY_MEDIUM); |
267 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 259 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
268 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 260 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
269 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 261 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
270 | 262 |
271 // Paths are a bit more complicated. 'IsEquivalent' requires an exact path | 263 // Paths are a bit more complicated. 'IsEquivalent' requires an exact path |
272 // match, while secure cookie matching uses a more relaxed 'IsOnPath' check. | 264 // match, while secure cookie matching uses a more relaxed 'IsOnPath' check. |
273 // That is, |cookie| set on '/path' is not equivalent in either way to | 265 // That is, |cookie| set on '/path' is not equivalent in either way to |
274 // |other_cookie| set on '/test' or '/path/subpath'. It is, however, | 266 // |other_cookie| set on '/test' or '/path/subpath'. It is, however, |
275 // equivalent for secure cookie matching to |other_cookie| set on '/'. | 267 // equivalent for secure cookie matching to |other_cookie| set on '/'. |
276 other_cookie = CanonicalCookie::Create( | 268 other_cookie = CanonicalCookie::Create( |
277 url, cookie_name, cookie_value, cookie_domain, "/test", creation_time, | 269 url, cookie_name, cookie_value, cookie_domain, "/test", creation_time, |
278 expiration_time, secure, httponly, same_site, false, | 270 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); |
279 COOKIE_PRIORITY_MEDIUM); | |
280 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 271 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
281 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 272 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
282 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 273 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
283 | 274 |
284 other_cookie = CanonicalCookie::Create( | 275 other_cookie = CanonicalCookie::Create( |
285 url, cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath", | 276 url, cookie_name, cookie_value, cookie_domain, cookie_path + "/subpath", |
286 creation_time, expiration_time, secure, httponly, same_site, false, | 277 creation_time, expiration_time, secure, httponly, same_site, |
287 COOKIE_PRIORITY_MEDIUM); | 278 COOKIE_PRIORITY_MEDIUM); |
288 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 279 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
289 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 280 EXPECT_FALSE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
290 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 281 EXPECT_TRUE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
291 | 282 |
292 other_cookie = CanonicalCookie::Create( | 283 other_cookie = CanonicalCookie::Create( |
293 url, cookie_name, cookie_value, cookie_domain, "/", creation_time, | 284 url, cookie_name, cookie_value, cookie_domain, "/", creation_time, |
294 expiration_time, secure, httponly, same_site, false, | 285 expiration_time, secure, httponly, same_site, COOKIE_PRIORITY_MEDIUM); |
295 COOKIE_PRIORITY_MEDIUM); | |
296 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); | 286 EXPECT_FALSE(cookie->IsEquivalent(*other_cookie)); |
297 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); | 287 EXPECT_TRUE(cookie->IsEquivalentForSecureCookieMatching(*other_cookie)); |
298 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); | 288 EXPECT_FALSE(other_cookie->IsEquivalentForSecureCookieMatching(*cookie)); |
299 } | 289 } |
300 | 290 |
301 TEST(CanonicalCookieTest, IsDomainMatch) { | 291 TEST(CanonicalCookieTest, IsDomainMatch) { |
302 GURL url("http://www.example.com/test/foo.html"); | 292 GURL url("http://www.example.com/test/foo.html"); |
303 base::Time creation_time = base::Time::Now(); | 293 base::Time creation_time = base::Time::Now(); |
304 CookieOptions options; | 294 CookieOptions options; |
305 | 295 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 EXPECT_TRUE(CanonicalCookie::Create( | 558 EXPECT_TRUE(CanonicalCookie::Create( |
569 https_url, "__HostA=B; Domain=" + domain + "; Secure;", creation_time, | 559 https_url, "__HostA=B; Domain=" + domain + "; Secure;", creation_time, |
570 options)); | 560 options)); |
571 } | 561 } |
572 | 562 |
573 TEST(CanonicalCookieTest, EnforceSecureCookiesRequireSecureScheme) { | 563 TEST(CanonicalCookieTest, EnforceSecureCookiesRequireSecureScheme) { |
574 GURL http_url("http://www.example.com"); | 564 GURL http_url("http://www.example.com"); |
575 GURL https_url("https://www.example.com"); | 565 GURL https_url("https://www.example.com"); |
576 base::Time creation_time = base::Time::Now(); | 566 base::Time creation_time = base::Time::Now(); |
577 CookieOptions options; | 567 CookieOptions options; |
578 options.set_enforce_strict_secure(); | |
579 | 568 |
580 std::unique_ptr<CanonicalCookie> http_cookie_no_secure( | 569 std::unique_ptr<CanonicalCookie> http_cookie_no_secure( |
581 CanonicalCookie::Create(http_url, "a=b", creation_time, options)); | 570 CanonicalCookie::Create(http_url, "a=b", creation_time, options)); |
582 std::unique_ptr<CanonicalCookie> http_cookie_secure( | 571 std::unique_ptr<CanonicalCookie> http_cookie_secure( |
583 CanonicalCookie::Create(http_url, "a=b; Secure", creation_time, options)); | 572 CanonicalCookie::Create(http_url, "a=b; Secure", creation_time, options)); |
584 std::unique_ptr<CanonicalCookie> https_cookie_no_secure( | 573 std::unique_ptr<CanonicalCookie> https_cookie_no_secure( |
585 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); | 574 CanonicalCookie::Create(https_url, "a=b", creation_time, options)); |
586 std::unique_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( | 575 std::unique_ptr<CanonicalCookie> https_cookie_secure(CanonicalCookie::Create( |
587 https_url, "a=b; Secure", creation_time, options)); | 576 https_url, "a=b; Secure", creation_time, options)); |
588 | 577 |
589 EXPECT_TRUE(http_cookie_no_secure.get()); | 578 EXPECT_TRUE(http_cookie_no_secure.get()); |
590 EXPECT_FALSE(http_cookie_secure.get()); | 579 EXPECT_FALSE(http_cookie_secure.get()); |
591 EXPECT_TRUE(https_cookie_no_secure.get()); | 580 EXPECT_TRUE(https_cookie_no_secure.get()); |
592 EXPECT_TRUE(https_cookie_secure.get()); | 581 EXPECT_TRUE(https_cookie_secure.get()); |
593 | 582 |
594 std::unique_ptr<CanonicalCookie> http_cookie_no_secure_extended( | 583 std::unique_ptr<CanonicalCookie> http_cookie_no_secure_extended( |
595 CanonicalCookie::Create( | 584 CanonicalCookie::Create( |
596 http_url, "a", "b", "", "", creation_time, creation_time, false, | 585 http_url, "a", "b", "", "", creation_time, creation_time, false, |
597 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 586 false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); |
598 std::unique_ptr<CanonicalCookie> http_cookie_secure_extended( | 587 std::unique_ptr<CanonicalCookie> http_cookie_secure_extended( |
599 CanonicalCookie::Create( | 588 CanonicalCookie::Create( |
600 http_url, "a", "b", "", "", creation_time, creation_time, true, false, | 589 http_url, "a", "b", "", "", creation_time, creation_time, true, false, |
601 CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 590 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); |
602 std::unique_ptr<CanonicalCookie> https_cookie_no_secure_extended( | 591 std::unique_ptr<CanonicalCookie> https_cookie_no_secure_extended( |
603 CanonicalCookie::Create( | 592 CanonicalCookie::Create( |
604 https_url, "a", "b", "", "", creation_time, creation_time, false, | 593 https_url, "a", "b", "", "", creation_time, creation_time, false, |
605 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 594 false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); |
606 std::unique_ptr<CanonicalCookie> https_cookie_secure_extended( | 595 std::unique_ptr<CanonicalCookie> https_cookie_secure_extended( |
607 CanonicalCookie::Create( | 596 CanonicalCookie::Create( |
608 https_url, "a", "b", "", "", creation_time, creation_time, true, | 597 https_url, "a", "b", "", "", creation_time, creation_time, true, |
609 false, CookieSameSite::STRICT_MODE, true, COOKIE_PRIORITY_DEFAULT)); | 598 false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT)); |
610 | 599 |
611 EXPECT_TRUE(http_cookie_no_secure_extended.get()); | 600 EXPECT_TRUE(http_cookie_no_secure_extended.get()); |
612 EXPECT_FALSE(http_cookie_secure_extended.get()); | 601 EXPECT_FALSE(http_cookie_secure_extended.get()); |
613 EXPECT_TRUE(https_cookie_no_secure_extended.get()); | 602 EXPECT_TRUE(https_cookie_no_secure_extended.get()); |
614 EXPECT_TRUE(https_cookie_secure_extended.get()); | 603 EXPECT_TRUE(https_cookie_secure_extended.get()); |
615 } | 604 } |
616 | 605 |
617 TEST(CanonicalCookieTest, TestPrefixHistograms) { | 606 TEST(CanonicalCookieTest, TestPrefixHistograms) { |
618 base::HistogramTester histograms; | 607 base::HistogramTester histograms; |
619 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; | 608 const char kCookiePrefixHistogram[] = "Cookie.CookiePrefix"; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 647 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
659 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", | 648 EXPECT_TRUE(CanonicalCookie::Create(https_url, "__SecureA=B; Path=/; Secure", |
660 creation_time, options)); | 649 creation_time, options)); |
661 histograms.ExpectBucketCount(kCookiePrefixHistogram, | 650 histograms.ExpectBucketCount(kCookiePrefixHistogram, |
662 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); | 651 CanonicalCookie::COOKIE_PREFIX_SECURE, 2); |
663 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, | 652 histograms.ExpectBucketCount(kCookiePrefixBlockedHistogram, |
664 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); | 653 CanonicalCookie::COOKIE_PREFIX_SECURE, 1); |
665 } | 654 } |
666 | 655 |
667 } // namespace net | 656 } // namespace net |
OLD | NEW |