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

Unified Diff: net/http/http_response_headers_unittest.cc

Issue 1827243002: Fix number parsing problems with HttpResponseHeaders::GetAgeValue() to not accept invalid numbers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@parse_refactor
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_response_headers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers_unittest.cc
diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc
index 70a5d09562a4a13d31f0c7bfebb92e64513ec74b..64422384818dc86b47fd77f33e63eb4a7831f3ad 100644
--- a/net/http/http_response_headers_unittest.cc
+++ b/net/http/http_response_headers_unittest.cc
@@ -533,6 +533,71 @@ TEST(HttpResponseHeadersTest, DefaultDateToGMT) {
EXPECT_EQ(expected_value, value);
}
+TEST(HttpResponseHeadersTest, GetAgeValue10) {
+ std::string headers =
+ "HTTP/1.1 200 OK\n"
+ "Age: 10\n";
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
+ base::TimeDelta age;
+ ASSERT_TRUE(parsed->GetAgeValue(&age));
+ EXPECT_EQ(10, age.InSeconds());
+}
+
+TEST(HttpResponseHeadersTest, GetAgeValue0) {
+ std::string headers =
+ "HTTP/1.1 200 OK\n"
+ "Age: 0\n";
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
+ base::TimeDelta age;
+ ASSERT_TRUE(parsed->GetAgeValue(&age));
+ EXPECT_EQ(0, age.InSeconds());
+}
+
+TEST(HttpResponseHeadersTest, GetAgeValueBogus) {
+ std::string headers =
+ "HTTP/1.1 200 OK\n"
+ "Age: donkey\n";
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
+ base::TimeDelta age;
+ ASSERT_FALSE(parsed->GetAgeValue(&age));
+}
+
+TEST(HttpResponseHeadersTest, GetAgeValueNegative) {
+ std::string headers =
+ "HTTP/1.1 200 OK\n"
+ "Age: -10\n";
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
+ base::TimeDelta age;
+ ASSERT_FALSE(parsed->GetAgeValue(&age));
+}
+
+TEST(HttpResponseHeadersTest, GetAgeValueLeadingPlus) {
+ std::string headers =
+ "HTTP/1.1 200 OK\n"
+ "Age: +10\n";
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
+ base::TimeDelta age;
+ ASSERT_FALSE(parsed->GetAgeValue(&age));
+}
+
+TEST(HttpResponseHeadersTest, GetAgeValueOverflow) {
+ std::string headers =
+ "HTTP/1.1 200 OK\n"
+ "Age: 999999999999999999999999999999999999999999\n";
+ HeadersToRaw(&headers);
+ scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers));
+ base::TimeDelta age;
+ ASSERT_TRUE(parsed->GetAgeValue(&age));
+
+ // Should have saturated to 2^32 - 1.
+ EXPECT_EQ(static_cast<int64_t>(0xFFFFFFFFL), age.InSeconds());
+}
+
struct ContentTypeTestData {
const std::string raw_headers;
const std::string mime_type;
« no previous file with comments | « net/http/http_response_headers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698