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

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

Issue 2861063003: Remove dangerous CanonicalCookie::Create method. (Closed)
Patch Set: Fixed bugs from DCHECKing name & path. Created 3 years, 7 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
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/cookie_monster_store_test.h" 5 #include "net/cookies/cookie_monster_store_test.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // This helper is simplistic in interpreting a parsed cookie, in order to 123 // This helper is simplistic in interpreting a parsed cookie, in order to
124 // avoid duplicated CookieMonster's CanonPath() and CanonExpiration() 124 // avoid duplicated CookieMonster's CanonPath() and CanonExpiration()
125 // functions. Would be nice to export them, and re-use here. 125 // functions. Would be nice to export them, and re-use here.
126 EXPECT_FALSE(pc.HasMaxAge()); 126 EXPECT_FALSE(pc.HasMaxAge());
127 EXPECT_TRUE(pc.HasPath()); 127 EXPECT_TRUE(pc.HasPath());
128 base::Time cookie_expires = 128 base::Time cookie_expires =
129 pc.HasExpires() ? cookie_util::ParseCookieExpirationTime(pc.Expires()) 129 pc.HasExpires() ? cookie_util::ParseCookieExpirationTime(pc.Expires())
130 : base::Time(); 130 : base::Time();
131 std::string cookie_path = pc.Path(); 131 std::string cookie_path = pc.Path();
132 132
133 return CanonicalCookie::Create(url, pc.Name(), pc.Value(), url.host(), 133 return CanonicalCookie::Create(pc.Name(), pc.Value(), url.host(), cookie_path,
mmenke 2017/05/09 16:51:09 This is a behavior change. Should be "." + cookie
Randy Smith (Not in Mondays) 2017/05/09 23:52:35 Presuming you meant "." + url.host(). Done.
134 cookie_path, creation_time, cookie_expires, 134 creation_time, cookie_expires, base::Time(),
135 pc.IsSecure(), pc.IsHttpOnly(), pc.SameSite(), 135 pc.IsSecure(), pc.IsHttpOnly(), pc.SameSite(),
136 pc.Priority()); 136 pc.Priority());
137 } 137 }
138 138
139 void AddCookieToList(const GURL& url, 139 void AddCookieToList(const GURL& url,
140 const std::string& cookie_line, 140 const std::string& cookie_line,
141 const base::Time& creation_time, 141 const base::Time& creation_time,
142 std::vector<std::unique_ptr<CanonicalCookie>>* out_list) { 142 std::vector<std::unique_ptr<CanonicalCookie>>* out_list) {
143 std::unique_ptr<CanonicalCookie> cookie( 143 std::unique_ptr<CanonicalCookie> cookie(
144 BuildCanonicalCookie(url, cookie_line, creation_time)); 144 BuildCanonicalCookie(url, cookie_line, creation_time));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 base::Time expiration_time = current + base::TimeDelta::FromDays(30); 232 base::Time expiration_time = current + base::TimeDelta::FromDays(30);
233 base::Time last_access_time = 233 base::Time last_access_time =
234 ((i - base) < num_old_cookies) 234 ((i - base) < num_old_cookies)
235 ? current - base::TimeDelta::FromDays(days_old) 235 ? current - base::TimeDelta::FromDays(days_old)
236 : current; 236 : current;
237 237
238 // The URL must be HTTPS since |secure| can be true or false, and because 238 // The URL must be HTTPS since |secure| can be true or false, and because
239 // strict secure cookies are enforced, the cookie will fail to be created if 239 // strict secure cookies are enforced, the cookie will fail to be created if
240 // |secure| is true but the URL is an insecure scheme. 240 // |secure| is true but the URL is an insecure scheme.
241 std::unique_ptr<CanonicalCookie> cc(CanonicalCookie::Create( 241 std::unique_ptr<CanonicalCookie> cc(CanonicalCookie::Create(
242 GURL(base::StringPrintf("https://h%05d.izzle/", i)), "a", "1", 242 "a", "1", base::StringPrintf("h%05d.izzle", i), "/path", creation_time,
243 std::string(), "/path", creation_time, expiration_time, secure, false, 243 expiration_time, base::Time(), secure, false,
244 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); 244 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT));
245 cc->SetLastAccessDate(last_access_time); 245 cc->SetLastAccessDate(last_access_time);
246 store->AddCookie(*cc); 246 store->AddCookie(*cc);
247 } 247 }
248 248
249 return base::MakeUnique<CookieMonster>(store.get(), nullptr); 249 return base::MakeUnique<CookieMonster>(store.get(), nullptr);
250 } 250 }
251 251
252 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() { 252 MockSimplePersistentCookieStore::~MockSimplePersistentCookieStore() {
253 } 253 }
254 254
255 } // namespace net 255 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698