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

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: bypass=0\n"
58 "Content-Length: 999\n",
59 "bypass=",
60 true,
61 "0",
62 },
63 { "HTTP/1.1 200 OK\n"
64 "connection: keep-alive\n"
65 "Chrome-Proxy: bypass=1500\n"
66 "Chrome-Proxy: bypass=86400\n"
67 "Content-Length: 999\n",
68 "bypass=",
69 true,
70 "1500",
71 },
72 { "HTTP/1.1 200 OK\n"
73 "connection: keep-alive\n"
74 "Chrome-Proxy: block=1500, block=3600\n"
75 "Content-Length: 999\n",
76 "block=",
77 true,
78 "1500",
79 },
80 { "HTTP/1.1 200 OK\n"
81 "connection: proxy-bypass\n"
82 "Chrome-Proxy: key=123 \n"
83 "Content-Length: 999\n",
84 "key=",
85 true,
86 "123",
87 },
88 { "HTTP/1.1 200 OK\n"
89 "connection: proxy-bypass\n"
90 "Chrome-Proxy: =123 \n"
91 "Content-Length: 999\n",
92 "=",
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.
93 true,
94 "123",
95 },
96 };
97 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
98 std::string headers(tests[i].headers);
99 HeadersToRaw(&headers);
100 scoped_refptr<net::HttpResponseHeaders> parsed(
101 new net::HttpResponseHeaders(headers));
102
103 std::string action_value;
104 bool has_action_key = GetDataReductionProxyActionValue(parsed,
105 tests[i].action_key,
106 &action_value);
107 EXPECT_EQ(tests[i].expected_result, has_action_key);
108 if (has_action_key) {
109 EXPECT_EQ(tests[i].expected_action_value,
110 action_value);
111 }
112 }
113 }
114
27 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { 115 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) {
28 const struct { 116 const struct {
29 const char* headers; 117 const char* headers;
30 bool expected_result; 118 bool expected_result;
31 int64 expected_retry_delay; 119 int64 expected_retry_delay;
32 bool expected_bypass_all; 120 bool expected_bypass_all;
33 } tests[] = { 121 } tests[] = {
34 { "HTTP/1.1 200 OK\n" 122 { "HTTP/1.1 200 OK\n"
35 "Content-Length: 999\n", 123 "Content-Length: 999\n",
36 false, 124 false,
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 std::string headers(tests[i].headers); 431 std::string headers(tests[i].headers);
344 HeadersToRaw(&headers); 432 HeadersToRaw(&headers);
345 scoped_refptr<net::HttpResponseHeaders> parsed( 433 scoped_refptr<net::HttpResponseHeaders> parsed(
346 new net::HttpResponseHeaders(headers)); 434 new net::HttpResponseHeaders(headers));
347 DataReductionProxyInfo chrome_proxy_info; 435 DataReductionProxyInfo chrome_proxy_info;
348 EXPECT_EQ(tests[i].expected_result, 436 EXPECT_EQ(tests[i].expected_result,
349 GetDataReductionProxyBypassEventType(parsed, &chrome_proxy_info)); 437 GetDataReductionProxyBypassEventType(parsed, &chrome_proxy_info));
350 } 438 }
351 } 439 }
352 } // namespace data_reduction_proxy 440 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698