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

Unified Diff: net/cookies/cookie_util_unittest.cc

Issue 2358343004: When parsing cookie expiration times, clip out of range dates rather
Patch Set: Created 4 years, 3 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
« no previous file with comments | « net/cookies/cookie_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/cookie_util_unittest.cc
diff --git a/net/cookies/cookie_util_unittest.cc b/net/cookies/cookie_util_unittest.cc
index 5414be1e4ddf0dec07fc4b5e146e0b7d8cb5f7e0..6ed2957567f27dec60350d3c2cc1047a4b5ce95f 100644
--- a/net/cookies/cookie_util_unittest.cc
+++ b/net/cookies/cookie_util_unittest.cc
@@ -126,16 +126,18 @@ TEST(CookieUtilTest, TestCookieDateParsing) {
// Some invalid dates
{ "98 April 17 21:01:22", false, 0 },
{ "Thu, 012-Aug-2008 20:49:07 GMT", false, 0 },
- { "Thu, 12-Aug-31841 20:49:07 GMT", false, 0 },
{ "Thu, 12-Aug-9999999999 20:49:07 GMT", false, 0 },
{ "Thu, 999999999999-Aug-2007 20:49:07 GMT", false, 0 },
{ "Thu, 12-Aug-2007 20:61:99999999999 GMT", false, 0 },
{ "IAintNoDateFool", false, 0 },
+ { "1600 April 33 21:01:22", false, 0},
+ { "1970 April 33 21:01:22", false, 0},
+ { "Thu, 33-Aug-31841 20:49:07 GMT", false, 0},
};
base::Time parsed_time;
for (size_t i = 0; i < arraysize(tests); ++i) {
- parsed_time = cookie_util::ParseCookieTime(tests[i].str);
+ parsed_time = cookie_util::ParseCookieExpirationTime(tests[i].str);
if (!tests[i].valid) {
EXPECT_TRUE(parsed_time.is_null()) << tests[i].str;
continue;
@@ -145,6 +147,53 @@ TEST(CookieUtilTest, TestCookieDateParsing) {
}
}
+// Tests parsing dates that are beyond 2038. 32-bit POSIX systems are incapable
+// of doing this, however the expectation is for cookie parsing to succeed
+// anyway (and return base::Time::Max()).
+TEST(CookieUtilTest, ParseCookieExpirationTimeBeyond2038) {
+ const char* kTests[] = {
+ "Thu, 12-Aug-31841 20:49:07 GMT",
+ "2039 April 15 21:01:22",
+ "2039 April 15 21:01:22",
+ "2038 April 15 21:01:22",
+ };
+
+ for (const auto& test : kTests) {
+ base::Time parsed_time = cookie_util::ParseCookieExpirationTime(test);
+ EXPECT_FALSE(parsed_time.is_null());
+
+ // It should either have an exact value, or should be base::Time::Max().
+ // For simplicity just check that it is greater than an arbitray date.
+ base::Time jan_2038 =
+ base::Time::UnixEpoch() + base::TimeDelta::FromDays(365 * 68);
+ EXPECT_GT(parsed_time, jan_2038);
+ }
+}
+
+// Tests parsing dates that are prior to (or around) 1970. POSIX systems are
+// incapable of doing this, however the expectation is for cookie parsing to
+// succeed
+// anyway (and return a minimal base::Time).
+TEST(CookieUtilTest, ParseCookieExpirationTimeBefore1970) {
+ const char* kTests[] = {
+ // The unix epoch.
+ "1970 Jan 1 00:00:00",
+ // The windows epoch.
+ "1601 Jan 1 00:00:00",
+ // Other dates.
+ "1969 March 3 21:01:22", "1600 April 15 21:01:22",
+ };
+
+ for (const auto& test : kTests) {
+ base::Time parsed_time = cookie_util::ParseCookieExpirationTime(test);
+ EXPECT_FALSE(parsed_time.is_null());
+
+ // It should either have an exact value, or should be base::Time(1)
+ // For simplicity just check that it is less than the unix epoch.
+ EXPECT_LT(parsed_time, base::Time::UnixEpoch());
+ }
+}
+
TEST(CookieUtilTest, TestRequestCookieParsing) {
std::vector<RequestCookieParsingTest> tests;
« no previous file with comments | « net/cookies/cookie_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698