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

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: Modify HasDataReductionProxyViaHeader to tell whether data reduction proxy occurs at last or not. 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..e0412fa0b4f37e0ce14408100c93b0be052c02d6 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,102 @@ 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: bypass86400\n"
+ "Content-Length: 999\n",
+ "bypass",
+ false,
+ "",
+ },
+ { "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: key= \n"
+ "Content-Length: 999\n",
+ "key",
+ true,
+ "",
+ },
+ };
+ 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,
bengr 2014/07/16 19:23:56 indentation is strange. Parameters should all be o
xingx 2014/07/16 21:22:33 Done.
+ 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);
bengr 2014/07/16 19:23:56 Move up a line.
xingx 2014/07/16 21:22:33 Done.
+ }
+ }
+}
+
TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) {
const struct {
const char* headers;
@@ -195,75 +291,110 @@ TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) {
const struct {
const char* headers;
bool expected_result;
+ bool expected_is_the_last;
} tests[] = {
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Proxy\n",
false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1\n",
false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
true,
+ true,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.0 Chrome-Compression-Proxy\n",
true,
+ true,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar, 1.1 Chrome-Compression-Proxy\n",
true,
+ true,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy, 1.1 Bar-Foo\n",
true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 chrome-compression-proxy\n",
false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
true,
+ true,
+ },
+ { "HTTP/1.1 200 OK\n"
+ "Via: 1.1 Chrome-Compression-Proxy\n"
+ "Via: 1.1 Foo-Bar\n",
+ true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Proxy\n",
false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome Compression Proxy\n",
true,
+ true,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar, 1.1 Chrome Compression Proxy\n",
true,
+ true,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome Compression Proxy, 1.1 Bar-Foo\n",
true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 chrome compression proxy\n",
false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar\n"
"Via: 1.1 Chrome Compression Proxy\n",
true,
+ true,
+ },
+ { "HTTP/1.1 200 OK\n"
+ "Via: 1.1 Chrome Compression Proxy\n"
+ "Via: 1.1 Foo-Bar\n",
+ true,
+ false,
},
};
+ bool has, is_the_last;
+ std::string headers;
+ scoped_refptr<net::HttpResponseHeaders> parsed;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- std::string headers(tests[i].headers);
+ headers = tests[i].headers;
HeadersToRaw(&headers);
- scoped_refptr<net::HttpResponseHeaders> parsed(
- new net::HttpResponseHeaders(headers));
+ parsed = new net::HttpResponseHeaders(headers);
- EXPECT_EQ(tests[i].expected_result,
- HasDataReductionProxyViaHeader(parsed));
+ has = HasDataReductionProxyViaHeader(parsed, &is_the_last);
+ EXPECT_EQ(tests[i].expected_result, has);
+ if (has) {
+ EXPECT_EQ(tests[i].expected_is_the_last, is_the_last);
+ }
}
+
+ has = HasDataReductionProxyViaHeader(parsed, NULL);
+ EXPECT_EQ(tests[ARRAYSIZE_UNSAFE(tests) - 1].expected_result, has);
}
TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) {

Powered by Google App Engine
This is Rietveld 408576698