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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" 5 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h"
6 6
7 #include "net/http/http_response_headers.h" 7 #include "net/http/http_response_headers.h"
8 #include "net/proxy/proxy_service.h" 8 #include "net/proxy/proxy_service.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace { 11 namespace {
12 12
13 // Transform "normal"-looking headers (\n-separated) to the appropriate 13 // Transform "normal"-looking headers (\n-separated) to the appropriate
14 // input format for ParseRawHeaders (\0-separated). 14 // input format for ParseRawHeaders (\0-separated).
15 void HeadersToRaw(std::string* headers) { 15 void HeadersToRaw(std::string* headers) {
16 std::replace(headers->begin(), headers->end(), '\n', '\0'); 16 std::replace(headers->begin(), headers->end(), '\n', '\0');
17 if (!headers->empty()) 17 if (!headers->empty())
18 *headers += '\0'; 18 *headers += '\0';
19 } 19 }
20 20
21 } // namespace 21 } // namespace
22 22
23 namespace data_reduction_proxy { 23 namespace data_reduction_proxy {
24 24
25 class DataReductionProxyHeadersTest : public testing::Test {}; 25 class DataReductionProxyHeadersTest : public testing::Test {};
26 26
27 TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyActionValue) {
28 const struct {
29 const char* headers;
30 std::string action_key;
31 bool expected_result;
32 std::string expected_action_value;
33 } tests[] = {
34 { "HTTP/1.1 200 OK\n"
35 "Content-Length: 999\n",
36 "a",
37 false,
38 "",
39 },
40 { "HTTP/1.1 200 OK\n"
41 "connection: keep-alive\n"
42 "Content-Length: 999\n",
43 "a",
44 false,
45 "",
46 },
47 { "HTTP/1.1 200 OK\n"
48 "connection: keep-alive\n"
49 "Chrome-Proxy: bypass=86400\n"
50 "Content-Length: 999\n",
51 "bypass",
52 true,
53 "86400",
54 },
55 { "HTTP/1.1 200 OK\n"
56 "connection: keep-alive\n"
57 "Chrome-Proxy: bypass86400\n"
58 "Content-Length: 999\n",
59 "bypass",
60 false,
61 "",
62 },
63 { "HTTP/1.1 200 OK\n"
64 "connection: keep-alive\n"
65 "Chrome-Proxy: bypass=0\n"
66 "Content-Length: 999\n",
67 "bypass",
68 true,
69 "0",
70 },
71 { "HTTP/1.1 200 OK\n"
72 "connection: keep-alive\n"
73 "Chrome-Proxy: bypass=1500\n"
74 "Chrome-Proxy: bypass=86400\n"
75 "Content-Length: 999\n",
76 "bypass",
77 true,
78 "1500",
79 },
80 { "HTTP/1.1 200 OK\n"
81 "connection: keep-alive\n"
82 "Chrome-Proxy: block=1500, block=3600\n"
83 "Content-Length: 999\n",
84 "block",
85 true,
86 "1500",
87 },
88 { "HTTP/1.1 200 OK\n"
89 "connection: proxy-bypass\n"
90 "Chrome-Proxy: key=123 \n"
91 "Content-Length: 999\n",
92 "key",
93 true,
94 "123",
95 },
96 { "HTTP/1.1 200 OK\n"
97 "connection: proxy-bypass\n"
98 "Chrome-Proxy: key= \n"
99 "Content-Length: 999\n",
100 "key",
101 true,
102 "",
103 },
104 };
105 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
106 std::string headers(tests[i].headers);
107 HeadersToRaw(&headers);
108 scoped_refptr<net::HttpResponseHeaders> parsed(
109 new net::HttpResponseHeaders(headers));
110
111 std::string action_value;
112 bool has_action_key = GetDataReductionProxyActionValue(parsed,
113 tests[i].action_key,
114 &action_value);
115 EXPECT_EQ(tests[i].expected_result, has_action_key);
116 if (has_action_key) {
117 EXPECT_EQ(tests[i].expected_action_value,
118 action_value);
119 }
120 }
121 }
122
27 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { 123 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) {
28 const struct { 124 const struct {
29 const char* headers; 125 const char* headers;
30 bool expected_result; 126 bool expected_result;
31 int64 expected_retry_delay; 127 int64 expected_retry_delay;
32 bool expected_bypass_all; 128 bool expected_bypass_all;
33 } tests[] = { 129 } tests[] = {
34 { "HTTP/1.1 200 OK\n" 130 { "HTTP/1.1 200 OK\n"
35 "Content-Length: 999\n", 131 "Content-Length: 999\n",
36 false, 132 false,
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 std::string headers(tests[i].headers); 439 std::string headers(tests[i].headers);
344 HeadersToRaw(&headers); 440 HeadersToRaw(&headers);
345 scoped_refptr<net::HttpResponseHeaders> parsed( 441 scoped_refptr<net::HttpResponseHeaders> parsed(
346 new net::HttpResponseHeaders(headers)); 442 new net::HttpResponseHeaders(headers));
347 DataReductionProxyInfo chrome_proxy_info; 443 DataReductionProxyInfo chrome_proxy_info;
348 EXPECT_EQ(tests[i].expected_result, 444 EXPECT_EQ(tests[i].expected_result,
349 GetDataReductionProxyBypassEventType(parsed, &chrome_proxy_info)); 445 GetDataReductionProxyBypassEventType(parsed, &chrome_proxy_info));
350 } 446 }
351 } 447 }
352 } // namespace data_reduction_proxy 448 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698