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

Unified Diff: net/cookies/canonical_cookie.cc

Issue 2898953008: Implement and test CanonicalCookie::IsCanonical() (Closed)
Patch Set: Add test param to Android Webview cookie test. 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 side-by-side diff with in-line comments
Download patch
Index: net/cookies/canonical_cookie.cc
diff --git a/net/cookies/canonical_cookie.cc b/net/cookies/canonical_cookie.cc
index 6c81a55dc7df1d768618d9d76b338a0b0fd79974..95b1355b659012ee3238afe284a80d04f28666ca 100644
--- a/net/cookies/canonical_cookie.cc
+++ b/net/cookies/canonical_cookie.cc
@@ -50,10 +50,12 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "net/base/url_util.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
#include "url/gurl.h"
#include "url/url_canon.h"
+#include "url/url_util.h"
using base::Time;
using base::TimeDelta;
@@ -238,11 +240,13 @@ std::unique_ptr<CanonicalCookie> CanonicalCookie::Create(
return nullptr;
}
- return base::WrapUnique(new CanonicalCookie(
+ std::unique_ptr<CanonicalCookie> cc(base::WrapUnique(new CanonicalCookie(
mmenke 2017/06/09 18:25:49 base::MakeUnique (pre-existing issue)
Randy Smith (Not in Mondays) 2017/06/09 19:38:32 Done.
parsed_cookie.Name(), parsed_cookie.Value(), cookie_domain, cookie_path,
creation_time, cookie_expires, creation_time, parsed_cookie.IsSecure(),
parsed_cookie.IsHttpOnly(), parsed_cookie.SameSite(),
- parsed_cookie.Priority()));
+ parsed_cookie.Priority())));
+ DCHECK(cc->IsCanonical());
mmenke 2017/06/09 18:25:49 Random comment: Come to think of it, we do have s
Randy Smith (Not in Mondays) 2017/06/09 19:38:33 Acknowledged.
+ return cc;
}
bool CanonicalCookie::IsEquivalentForSecureCookieMatching(
@@ -399,6 +403,32 @@ bool CanonicalCookie::FullCompare(const CanonicalCookie& other) const {
return Priority() < other.Priority();
}
+bool CanonicalCookie::IsCanonical() const {
+ if (ParsedCookie::ParseTokenString(name_) != name_ ||
+ ParsedCookie::ParseValueString(value_) != value_ ||
+ ParsedCookie::ParseValueString(domain_) != domain_ ||
+ ParsedCookie::ParseValueString(path_) != path_) {
mmenke 2017/06/09 18:25:49 I don't think this is enough. In particular, disa
mmenke 2017/06/09 19:00:47 Also, may be worth testing if there are any paths
Randy Smith (Not in Mondays) 2017/06/09 19:38:32 See comments elsewhere about currently web platfor
Randy Smith (Not in Mondays) 2017/06/09 19:38:32 Sorry, could you say a bit more? I may be confuse
mmenke 2017/06/09 19:53:59 If they go through SetCookieWithOptions, that's en
mmenke 2017/06/09 19:53:59 Oops, I missed the FindFirstTerminator call, and w
+ return false;
+ }
+
+ url::CanonHostInfo ignored;
+ std::string canonical_domain(CanonicalizeHost(domain_, &ignored));
+ // TODO(rdsmith): This specifically allows for empty domains. This is
+ // arguable from the spec (the domain attribute may not be empty, but
+ // no specification is made as to the value of the cookie domain in
+ // the absence of a domain attribute), but are needed for chrome
mmenke 2017/06/09 18:25:49 are -> is. Also, should Chrome be capitalized, or
Randy Smith (Not in Mondays) 2017/06/09 19:38:33 Done.
+ // extension cookies. See http://crbug.com/730633 for more information.
+ if (!url::HostIsIPAddress(domain_) && !domain_.empty() &&
mmenke 2017/06/09 18:25:49 instead of url::HostIsIPAddress, can't we just gra
Randy Smith (Not in Mondays) 2017/06/09 19:38:33 Done.
+ canonical_domain != domain_) {
mmenke 2017/06/09 18:25:49 If the URL is an IP address, shouldn't canonical_d
Randy Smith (Not in Mondays) 2017/06/09 19:38:32 Is the issue what "canonical" means, i.e. that you
mmenke 2017/06/09 19:53:59 I'm not sure if canonicalizing domain names canoni
mmenke 2017/06/09 20:05:04 So...this is really weird: CanonicalCookie::Creat
Randy Smith (Not in Mondays) 2017/06/11 15:35:24 That's an excellent clarifying question. I think
Randy Smith (Not in Mondays) 2017/06/11 15:35:24 Yeah, that fits with my understanding, and it soun
mmenke 2017/06/12 15:27:00 I think that's reasonable, and should be documente
mmenke 2017/06/12 15:27:00 I agree this CL shouldn't try to change behavior,
Randy Smith (Not in Mondays) 2017/06/13 15:06:02 Ignore the above about modification times; they do
Randy Smith (Not in Mondays) 2017/06/13 20:37:35 Huh. Good point. I think the only code modificat
+ return false;
+ }
+
+ if (path_.empty() || path_[0] != '/')
mmenke 2017/06/09 18:25:49 Hrm...I guess we do nothing about invalid characte
Randy Smith (Not in Mondays) 2017/06/09 19:38:32 That sounds right to me, though if there's anythin
+ return false;
+
+ return true;
mmenke 2017/06/09 18:25:49 What if there's no creation time, or the creation
Randy Smith (Not in Mondays) 2017/06/09 19:38:32 As noted above, I'd like to put in the Mojo-requir
mmenke 2017/06/12 15:27:00 I think that's fine. Part of the trouble I'm havi
mmenke 2017/06/12 15:28:48 Another option would be to land this largely as-is
Randy Smith (Not in Mondays) 2017/06/13 15:06:02 I see that as part of the basic philosophical tens
Randy Smith (Not in Mondays) 2017/06/13 15:06:02 Not really any point; let's keep the CL conceptual
+}
+
// static
CanonicalCookie::CookiePrefix CanonicalCookie::GetCookiePrefix(
const std::string& name) {

Powered by Google App Engine
This is Rietveld 408576698