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

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, 4 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 | « components/data_reduction_proxy/common/data_reduction_proxy_headers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ef3de65d94cf518a41e13090fc3702329d14ca59..6a98dd1c85de9d58f8b464d8b6517af4c8994e3e 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,92 @@ 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",
+ },
+ };
+ 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;
@@ -202,66 +288,117 @@ TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) {
TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) {
const struct {
- const char* headers;
- bool expected_result;
+ const char* headers;
+ bool expected_result;
+ bool expected_has_intermediary;
+ bool ignore_intermediary;
} tests[] = {
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Proxy\n",
false,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1\n",
false,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
true,
+ true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.0 Chrome-Compression-Proxy\n",
true,
+ true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar, 1.1 Chrome-Compression-Proxy\n",
true,
+ true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Compression-Proxy, 1.1 Bar-Foo\n",
true,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 chrome-compression-proxy\n",
false,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar\n"
"Via: 1.1 Chrome-Compression-Proxy\n",
true,
+ true,
+ false,
+ },
+ { "HTTP/1.1 200 OK\n"
+ "Via: 1.1 Chrome-Compression-Proxy\n"
+ "Via: 1.1 Foo-Bar\n",
+ true,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome-Proxy\n",
false,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome Compression Proxy\n",
true,
+ true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar, 1.1 Chrome Compression Proxy\n",
true,
+ true,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Chrome Compression Proxy, 1.1 Bar-Foo\n",
true,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 chrome compression proxy\n",
false,
+ false,
+ false,
},
{ "HTTP/1.1 200 OK\n"
"Via: 1.1 Foo-Bar\n"
"Via: 1.1 Chrome Compression Proxy\n",
true,
+ true,
+ false,
+ },
+ { "HTTP/1.1 200 OK\n"
+ "Via: 1.1 Chrome Compression Proxy\n"
+ "Via: 1.1 Foo-Bar\n",
+ true,
+ false,
+ false,
+ },
+ { "HTTP/1.1 200 OK\n"
+ "Via: 1.1 Chrome Compression Proxy\n"
+ "Via: 1.1 Foo-Bar\n",
+ true,
+ false,
+ true,
},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
@@ -270,8 +407,19 @@ TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) {
scoped_refptr<net::HttpResponseHeaders> parsed(
new net::HttpResponseHeaders(headers));
- EXPECT_EQ(tests[i].expected_result,
- HasDataReductionProxyViaHeader(parsed));
+ bool has_chrome_proxy_via_header, has_intermediary;
+ if (tests[i].ignore_intermediary) {
+ has_chrome_proxy_via_header =
+ HasDataReductionProxyViaHeader(parsed, NULL);
+ }
+ else {
+ has_chrome_proxy_via_header =
+ HasDataReductionProxyViaHeader(parsed, &has_intermediary);
+ }
+ EXPECT_EQ(tests[i].expected_result, has_chrome_proxy_via_header);
+ if (has_chrome_proxy_via_header && !tests[i].ignore_intermediary) {
+ EXPECT_EQ(tests[i].expected_has_intermediary, has_intermediary);
+ }
}
}
@@ -381,4 +529,236 @@ TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) {
GetDataReductionProxyBypassType(parsed, &chrome_proxy_info));
}
}
+
+TEST_F(DataReductionProxyHeadersTest,
+ GetDataReductionProxyActionFingerprintChromeProxy) {
+ const struct {
+ std::string label;
+ const char* headers;
+ bool expected_fingerprint_exist;
+ std::string expected_fingerprint;
+ } tests[] = {
+ { "fingerprint doesn't exist",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=0\n",
+ false,
+ "",
+ },
+ { "fingerprint occurs once",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=1, fcp=fp\n",
+ true,
+ "fp",
+ },
+ { "fingerprint occurs twice",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=2, fcp=fp1, fcp=fp2\n",
+ true,
+ "fp1",
+ },
+ };
+ 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 fingerprint;
+ bool fingerprint_exist = GetDataReductionProxyActionFingerprintChromeProxy(
+ parsed, &fingerprint);
+ EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
+ << tests[i].label;
+
+ if (fingerprint_exist)
+ EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
+ }
+}
+
+TEST_F(DataReductionProxyHeadersTest,
+ GetDataReductionProxyActionFingerprintVia) {
+ const struct {
+ std::string label;
+ const char* headers;
+ bool expected_fingerprint_exist;
+ std::string expected_fingerprint;
+ } tests[] = {
+ { "fingerprint doesn't exist",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=0\n",
+ false,
+ "",
+ },
+ { "fingerprint occurs once",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=1, fvia=fvia\n",
+ true,
+ "fvia",
+ },
+ { "fingerprint occurs twice",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=2, fvia=fvia1, fvia=fvia2\n",
+ true,
+ "fvia1",
+ },
+ };
+ 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 fingerprint;
+ bool fingerprint_exist =
+ GetDataReductionProxyActionFingerprintVia(parsed, &fingerprint);
+ EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
+ << tests[i].label;
+
+ if (fingerprint_exist)
+ EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
+ }
+}
+
+TEST_F(DataReductionProxyHeadersTest,
+ GetDataReductionProxyActionFingerprintOtherHeaders) {
+ const struct {
+ std::string label;
+ const char* headers;
+ bool expected_fingerprint_exist;
+ std::string expected_fingerprint;
+ } tests[] = {
+ { "fingerprint doesn't exist",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=0\n",
+ false,
+ "",
+ },
+ { "fingerprint occurs once",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=1, foh=foh\n",
+ true,
+ "foh",
+ },
+ { "fingerprint occurs twice",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=2, foh=foh1, foh=foh2\n",
+ true,
+ "foh1",
+ },
+ };
+ 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 fingerprint;
+ bool fingerprint_exist =
+ GetDataReductionProxyActionFingerprintOtherHeaders(
+ parsed, &fingerprint);
+ EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
+ << tests[i].label;
+
+ if (fingerprint_exist)
+ EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
+ }
+}
+
+TEST_F(DataReductionProxyHeadersTest,
+ GetDataReductionProxyActionFingerprintContentLength) {
+ const struct {
+ std::string label;
+ const char* headers;
+ bool expected_fingerprint_exist;
+ std::string expected_fingerprint;
+ } tests[] = {
+ { "fingerprint doesn't exist",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=0\n",
+ false,
+ "",
+ },
+ { "fingerprint occurs once",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=1, fcl=fcl\n",
+ true,
+ "fcl",
+ },
+ { "fingerprint occurs twice",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: bypass=2, fcl=fcl1, fcl=fcl2\n",
+ true,
+ "fcl1",
+ },
+ };
+ 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 fingerprint;
+ bool fingerprint_exist =
+ GetDataReductionProxyActionFingerprintContentLength(
+ parsed, &fingerprint);
+ EXPECT_EQ(tests[i].expected_fingerprint_exist, fingerprint_exist)
+ << tests[i].label;
+
+ if (fingerprint_exist)
+ EXPECT_EQ(tests[i].expected_fingerprint, fingerprint) << tests[i].label;
+ }
+}
+
+TEST_F(DataReductionProxyHeadersTest,
+ GetDataReductionProxyHeaderWithFingerprintRemoved) {
+ struct {
bengr 2014/08/06 17:26:19 Make this const.
xingx1 2014/08/06 17:35:21 Done.
+ std::string label;
+ const char* headers;
+ std::string expected_output_values_string;
+ } test[] = {
+ {
+ "Checks the case that there is no Chrome-Proxy header's fingerprint.",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: 1,2,3,5\n",
+ "1,2,3,5,",
+ },
+ {
+ "Checks the case that there is Chrome-Proxy header's fingerprint.",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: 1,2,3,fcp=4,5\n",
+ "1,2,3,5,",
+ },
+ {
+ "Checks the case that there is Chrome-Proxy header's fingerprint, and it"
+ "occurs at the end.",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: 1,2,3,fcp=4,",
+ "1,2,3,",
+ },
+ {
+ "Checks the case that there is Chrome-Proxy header's fingerprint, and it"
+ "occurs at the beginning.",
+ "HTTP/1.1 200 OK\n"
+ "Chrome-Proxy: fcp=1,2,3,",
+ "2,3,",
+ },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test); ++i) {
+ std::string headers(test[i].headers);
+ HeadersToRaw(&headers);
+ scoped_refptr<net::HttpResponseHeaders> parsed(
+ new net::HttpResponseHeaders(headers));
+
+ std::vector<std::string> output_values;
+ GetDataReductionProxyHeaderWithFingerprintRemoved(parsed, &output_values);
+
+ std::string output_values_string;
+ for (size_t j = 0; j < output_values.size(); ++j)
+ output_values_string += output_values[j] + ",";
+
+ EXPECT_EQ(test[i].expected_output_values_string, output_values_string)
+ << test[i].label;
+ }
+}
+
} // namespace data_reduction_proxy
« no previous file with comments | « components/data_reduction_proxy/common/data_reduction_proxy_headers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698