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

Unified Diff: components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc

Issue 387353003: Modify data_reduction_proxy_header to support tamper detection logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@work
Patch Set: Created 6 years, 5 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: components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc
diff --git a/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc b/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc
index 871d66589e0d4834e51ab59ab0bc56de6e3e1934..1e1d8a2a7013bab6693336b708f189587a6dbae7 100644
--- a/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc
+++ b/components/data_reduction_proxy/common/data_reduction_proxy_headers_unittest.cc
@@ -24,6 +24,94 @@ namespace data_reduction_proxy {
class DataReductionProxyHeadersTest : public testing::Test {};
+TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) {
+ const struct {
+ const char* headers;
+ std::string action_key;
+ bool expected_result;
+ std::string expected_action_value;
+ } tests[] = {
+ { "HTTP/1.1 200 OK\n"
+ "Content-Length: 999\n",
+ "a=",
+ false,
+ "",
+ },
+ { "HTTP/1.1 200 OK\n"
+ "connection: keep-alive\n"
+ "Content-Length: 999\n",
+ "a=",
+ false,
+ "",
+ },
+ { "HTTP/1.1 200 OK\n"
+ "connection: keep-alive\n"
+ "Chrome-Proxy: bypass=86400\n"
+ "Content-Length: 999\n",
+ "bypass=",
+ true,
+ "86400",
+ },
+ { "HTTP/1.1 200 OK\n"
+ "connection: keep-alive\n"
+ "Chrome-Proxy: bypass=0\n"
+ "Content-Length: 999\n",
+ "bypass=",
+ true,
+ "0",
+ },
+ { "HTTP/1.1 200 OK\n"
+ "connection: keep-alive\n"
+ "Chrome-Proxy: bypass=1500\n"
+ "Chrome-Proxy: bypass=86400\n"
+ "Content-Length: 999\n",
+ "bypass=",
+ true,
+ "1500",
+ },
+ { "HTTP/1.1 200 OK\n"
+ "connection: keep-alive\n"
+ "Chrome-Proxy: block=1500, block=3600\n"
+ "Content-Length: 999\n",
+ "block=",
+ true,
+ "1500",
+ },
+ { "HTTP/1.1 200 OK\n"
+ "connection: proxy-bypass\n"
+ "Chrome-Proxy: key=123 \n"
+ "Content-Length: 999\n",
+ "key=",
+ true,
+ "123",
+ },
+ { "HTTP/1.1 200 OK\n"
+ "connection: proxy-bypass\n"
+ "Chrome-Proxy: =123 \n"
+ "Content-Length: 999\n",
+ "=",
bengr 2014/07/14 18:27:14 This shouldn't be allowed by any of the header pro
xingx 2014/07/14 21:37:17 Done.
+ true,
+ "123",
+ },
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ std::string headers(tests[i].headers);
+ HeadersToRaw(&headers);
+ scoped_refptr<net::HttpResponseHeaders> parsed(
+ new net::HttpResponseHeaders(headers));
+
+ std::string action_value;
+ bool has_action_key = GetDataReductionProxyActionValue(parsed,
+ tests[i].action_key,
+ &action_value);
+ EXPECT_EQ(tests[i].expected_result, has_action_key);
+ if (has_action_key) {
+ EXPECT_EQ(tests[i].expected_action_value,
+ action_value);
+ }
+ }
+}
+
TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) {
const struct {
const char* headers;

Powered by Google App Engine
This is Rietveld 408576698