Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "net/http/http_response_headers.h" | 9 #include "net/http/http_response_headers.h" |
| 10 #include "net/proxy/proxy_service.h" | 10 #include "net/proxy/proxy_service.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 "1500", | 88 "1500", |
| 89 }, | 89 }, |
| 90 { "HTTP/1.1 200 OK\n" | 90 { "HTTP/1.1 200 OK\n" |
| 91 "connection: proxy-bypass\n" | 91 "connection: proxy-bypass\n" |
| 92 "Chrome-Proxy: key=123 \n" | 92 "Chrome-Proxy: key=123 \n" |
| 93 "Content-Length: 999\n", | 93 "Content-Length: 999\n", |
| 94 "key", | 94 "key", |
| 95 true, | 95 true, |
| 96 "123", | 96 "123", |
| 97 }, | 97 }, |
| 98 { "HTTP/1.1 200 OK\n" | |
| 99 "connection: proxy-bypass\n" | |
| 100 "Chrome-Proxy: block-once\n" | |
| 101 "Content-Length: 999\n", | |
| 102 "block-once", | |
| 103 false, | |
| 104 "", | |
| 105 }, | |
| 98 }; | 106 }; |
| 99 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 107 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 100 std::string headers(tests[i].headers); | 108 std::string headers(tests[i].headers); |
| 101 HeadersToRaw(&headers); | 109 HeadersToRaw(&headers); |
| 102 scoped_refptr<net::HttpResponseHeaders> parsed( | 110 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 103 new net::HttpResponseHeaders(headers)); | 111 new net::HttpResponseHeaders(headers)); |
| 104 | 112 |
| 105 std::string action_value; | 113 std::string action_value; |
| 106 bool has_action_key = GetDataReductionProxyActionValue( | 114 bool has_action_key = GetDataReductionProxyActionValue( |
| 107 parsed, tests[i].action_key, &action_value); | 115 parsed, tests[i].action_key, &action_value); |
| 108 EXPECT_EQ(tests[i].expected_result, has_action_key); | 116 EXPECT_EQ(tests[i].expected_result, has_action_key); |
| 109 if (has_action_key) { | 117 if (has_action_key) { |
| 110 EXPECT_EQ(tests[i].expected_action_value, action_value); | 118 EXPECT_EQ(tests[i].expected_action_value, action_value); |
| 111 } | 119 } |
| 112 } | 120 } |
| 113 } | 121 } |
| 114 | 122 |
| 115 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { | 123 TEST_F(DataReductionProxyHeadersTest, GetProxyBypassInfo) { |
| 116 const struct { | 124 const struct { |
| 117 const char* headers; | 125 const char* headers; |
| 118 bool expected_result; | 126 bool expected_result; |
| 119 int64 expected_retry_delay; | 127 int64 expected_retry_delay; |
| 120 bool expected_bypass_all; | 128 bool expected_bypass_all; |
| 129 bool expected_mark_proxies_as_bad; | |
| 121 } tests[] = { | 130 } tests[] = { |
| 122 { "HTTP/1.1 200 OK\n" | 131 { "HTTP/1.1 200 OK\n" |
| 123 "Content-Length: 999\n", | 132 "Content-Length: 999\n", |
| 124 false, | 133 false, |
| 125 0, | 134 0, |
| 126 false, | 135 false, |
| 136 false, | |
| 127 }, | 137 }, |
| 128 { "HTTP/1.1 200 OK\n" | 138 { "HTTP/1.1 200 OK\n" |
| 129 "connection: keep-alive\n" | 139 "connection: keep-alive\n" |
| 130 "Content-Length: 999\n", | 140 "Content-Length: 999\n", |
| 131 false, | 141 false, |
| 132 0, | 142 0, |
| 133 false, | 143 false, |
| 144 false, | |
| 134 }, | 145 }, |
| 135 { "HTTP/1.1 200 OK\n" | 146 { "HTTP/1.1 200 OK\n" |
| 136 "connection: keep-alive\n" | 147 "connection: keep-alive\n" |
| 137 "Chrome-Proxy: bypass=86400\n" | 148 "Chrome-Proxy: bypass=86400\n" |
| 138 "Content-Length: 999\n", | 149 "Content-Length: 999\n", |
| 139 true, | 150 true, |
| 140 86400, | 151 86400, |
| 141 false, | 152 false, |
| 153 true, | |
| 142 }, | 154 }, |
| 143 { "HTTP/1.1 200 OK\n" | 155 { "HTTP/1.1 200 OK\n" |
| 144 "connection: keep-alive\n" | 156 "connection: keep-alive\n" |
| 145 "Chrome-Proxy: bypass=-1\n" | 157 "Chrome-Proxy: bypass=-1\n" |
| 146 "Content-Length: 999\n", | 158 "Content-Length: 999\n", |
| 147 false, | 159 false, |
| 148 0, | 160 0, |
| 149 false, | 161 false, |
| 162 false, | |
| 150 }, | 163 }, |
| 151 { "HTTP/1.1 200 OK\n" | 164 { "HTTP/1.1 200 OK\n" |
| 152 "connection: keep-alive\n" | 165 "connection: keep-alive\n" |
| 153 "Chrome-Proxy: bypass=xyz\n" | 166 "Chrome-Proxy: bypass=xyz\n" |
| 154 "Content-Length: 999\n", | 167 "Content-Length: 999\n", |
| 155 false, | 168 false, |
| 156 0, | 169 0, |
| 157 false, | 170 false, |
| 171 false, | |
| 158 }, | 172 }, |
| 159 { "HTTP/1.1 200 OK\n" | 173 { "HTTP/1.1 200 OK\n" |
| 160 "connection: keep-alive\n" | 174 "connection: keep-alive\n" |
| 161 "Chrome-Proxy: bypass\n" | 175 "Chrome-Proxy: bypass\n" |
| 162 "Content-Length: 999\n", | 176 "Content-Length: 999\n", |
| 163 false, | 177 false, |
| 164 0, | 178 0, |
| 165 false, | 179 false, |
| 180 false, | |
| 166 }, | 181 }, |
| 167 { "HTTP/1.1 200 OK\n" | 182 { "HTTP/1.1 200 OK\n" |
| 168 "connection: keep-alive\n" | 183 "connection: keep-alive\n" |
| 169 "Chrome-Proxy: foo=abc, bypass=86400\n" | 184 "Chrome-Proxy: foo=abc, bypass=86400\n" |
| 170 "Content-Length: 999\n", | 185 "Content-Length: 999\n", |
| 171 true, | 186 true, |
| 172 86400, | 187 86400, |
| 173 false, | 188 false, |
| 189 true, | |
| 174 }, | 190 }, |
| 175 { "HTTP/1.1 200 OK\n" | 191 { "HTTP/1.1 200 OK\n" |
| 176 "connection: keep-alive\n" | 192 "connection: keep-alive\n" |
| 177 "Chrome-Proxy: bypass=86400, bar=abc\n" | 193 "Chrome-Proxy: bypass=86400, bar=abc\n" |
| 178 "Content-Length: 999\n", | 194 "Content-Length: 999\n", |
| 179 true, | 195 true, |
| 180 86400, | 196 86400, |
| 181 false, | 197 false, |
| 198 true, | |
| 182 }, | 199 }, |
| 183 { "HTTP/1.1 200 OK\n" | 200 { "HTTP/1.1 200 OK\n" |
| 184 "connection: keep-alive\n" | 201 "connection: keep-alive\n" |
| 185 "Chrome-Proxy: bypass=3600\n" | 202 "Chrome-Proxy: bypass=3600\n" |
| 186 "Chrome-Proxy: bypass=86400\n" | 203 "Chrome-Proxy: bypass=86400\n" |
| 187 "Content-Length: 999\n", | 204 "Content-Length: 999\n", |
| 188 true, | 205 true, |
| 189 3600, | 206 3600, |
| 190 false, | 207 false, |
| 208 true, | |
| 191 }, | 209 }, |
| 192 { "HTTP/1.1 200 OK\n" | 210 { "HTTP/1.1 200 OK\n" |
| 193 "connection: keep-alive\n" | 211 "connection: keep-alive\n" |
| 194 "Chrome-Proxy: bypass=3600, bypass=86400\n" | 212 "Chrome-Proxy: bypass=3600, bypass=86400\n" |
| 195 "Content-Length: 999\n", | 213 "Content-Length: 999\n", |
| 196 true, | 214 true, |
| 197 3600, | 215 3600, |
| 198 false, | 216 false, |
| 217 true, | |
| 199 }, | 218 }, |
| 200 { "HTTP/1.1 200 OK\n" | 219 { "HTTP/1.1 200 OK\n" |
| 201 "connection: keep-alive\n" | 220 "connection: keep-alive\n" |
| 202 "Chrome-Proxy: bypass=, bypass=86400\n" | 221 "Chrome-Proxy: bypass=, bypass=86400\n" |
| 203 "Content-Length: 999\n", | 222 "Content-Length: 999\n", |
| 204 true, | 223 true, |
| 205 86400, | 224 86400, |
| 206 false, | 225 false, |
| 226 true, | |
| 207 }, | 227 }, |
| 208 { "HTTP/1.1 200 OK\n" | 228 { "HTTP/1.1 200 OK\n" |
| 209 "connection: keep-alive\n" | 229 "connection: keep-alive\n" |
| 210 "Chrome-Proxy: bypass\n" | 230 "Chrome-Proxy: bypass\n" |
| 211 "Chrome-Proxy: bypass=86400\n" | 231 "Chrome-Proxy: bypass=86400\n" |
| 212 "Content-Length: 999\n", | 232 "Content-Length: 999\n", |
| 213 true, | 233 true, |
| 214 86400, | 234 86400, |
| 215 false, | 235 false, |
| 236 true, | |
| 216 }, | 237 }, |
| 217 { "HTTP/1.1 200 OK\n" | 238 { "HTTP/1.1 200 OK\n" |
| 218 "connection: keep-alive\n" | 239 "connection: keep-alive\n" |
| 219 "Chrome-Proxy: block=, block=3600\n" | 240 "Chrome-Proxy: block=, block=3600\n" |
| 220 "Content-Length: 999\n", | 241 "Content-Length: 999\n", |
| 221 true, | 242 true, |
| 222 3600, | 243 3600, |
| 223 true, | 244 true, |
| 245 true, | |
| 224 }, | 246 }, |
| 225 { "HTTP/1.1 200 OK\n" | 247 { "HTTP/1.1 200 OK\n" |
| 226 "connection: keep-alive\n" | 248 "connection: keep-alive\n" |
| 227 "Chrome-Proxy: bypass=86400, block=3600\n" | 249 "Chrome-Proxy: bypass=86400, block=3600\n" |
| 228 "Content-Length: 999\n", | 250 "Content-Length: 999\n", |
| 229 true, | 251 true, |
| 230 3600, | 252 3600, |
| 231 true, | 253 true, |
| 254 true, | |
| 232 }, | 255 }, |
| 233 { "HTTP/1.1 200 OK\n" | 256 { "HTTP/1.1 200 OK\n" |
| 234 "connection: proxy-bypass\n" | 257 "connection: proxy-bypass\n" |
| 235 "Chrome-Proxy: block=, bypass=86400\n" | 258 "Chrome-Proxy: block=, bypass=86400\n" |
| 236 "Content-Length: 999\n", | 259 "Content-Length: 999\n", |
| 237 true, | 260 true, |
| 238 86400, | 261 86400, |
| 239 false, | 262 false, |
| 263 true, | |
| 240 }, | 264 }, |
| 241 { "HTTP/1.1 200 OK\n" | 265 { "HTTP/1.1 200 OK\n" |
| 242 "connection: proxy-bypass\n" | 266 "connection: proxy-bypass\n" |
| 243 "Chrome-Proxy: block=-1\n" | 267 "Chrome-Proxy: block=-1\n" |
| 244 "Content-Length: 999\n", | 268 "Content-Length: 999\n", |
| 245 false, | 269 false, |
| 246 0, | 270 0, |
| 247 false, | 271 false, |
| 272 false, | |
| 248 }, | 273 }, |
| 249 { "HTTP/1.1 200 OK\n" | 274 { "HTTP/1.1 200 OK\n" |
| 250 "connection: proxy-bypass\n" | 275 "connection: proxy-bypass\n" |
| 251 "Chrome-Proxy: block=99999999999999999999\n" | 276 "Chrome-Proxy: block=99999999999999999999\n" |
| 252 "Content-Length: 999\n", | 277 "Content-Length: 999\n", |
| 253 false, | 278 false, |
| 254 0, | 279 0, |
| 255 false, | 280 false, |
| 281 false, | |
| 282 }, | |
| 283 { "HTTP/1.1 200 OK\n" | |
| 284 "connection: keep-alive\n" | |
| 285 "Chrome-Proxy: block-once\n" | |
| 286 "Content-Length: 999\n", | |
| 287 true, | |
| 288 0, | |
| 289 true, | |
| 290 false, | |
| 291 }, | |
| 292 { "HTTP/1.1 200 OK\n" | |
| 293 "connection: keep-alive\n" | |
| 294 "Chrome-Proxy: block-once=\n" | |
|
bengr
2014/08/12 20:57:11
So block-once= and block-once=foo are both ignored
sclittle
2014/08/12 21:24:43
Acknowledged.
| |
| 295 "Content-Length: 999\n", | |
| 296 false, | |
| 297 0, | |
| 298 false, | |
| 299 false, | |
| 300 }, | |
| 301 { "HTTP/1.1 200 OK\n" | |
| 302 "connection: keep-alive\n" | |
| 303 "Chrome-Proxy: block-once=10\n" | |
| 304 "Content-Length: 999\n", | |
| 305 false, | |
| 306 0, | |
| 307 false, | |
| 308 false, | |
| 309 }, | |
| 310 { "HTTP/1.1 200 OK\n" | |
| 311 "connection: keep-alive\n" | |
| 312 "Chrome-Proxy: block-once, bypass=86400, block=3600\n" | |
| 313 "Content-Length: 999\n", | |
| 314 true, | |
| 315 3600, | |
| 316 true, | |
| 317 true, | |
| 318 }, | |
| 319 { "HTTP/1.1 200 OK\n" | |
| 320 "connection: keep-alive\n" | |
| 321 "Chrome-Proxy: block-once\n" | |
| 322 "Chrome-Proxy: bypass=86400, block=3600\n" | |
| 323 "Content-Length: 999\n", | |
| 324 true, | |
| 325 3600, | |
| 326 true, | |
| 327 true, | |
| 328 }, | |
| 329 { "HTTP/1.1 200 OK\n" | |
| 330 "connection: keep-alive\n" | |
| 331 "Chrome-Proxy: block-once, bypass=86400\n" | |
| 332 "Content-Length: 999\n", | |
| 333 true, | |
| 334 86400, | |
| 335 false, | |
| 336 true, | |
| 337 }, | |
| 338 { "HTTP/1.1 200 OK\n" | |
| 339 "connection: keep-alive\n" | |
| 340 "Chrome-Proxy: block-once, block=3600\n" | |
| 341 "Content-Length: 999\n", | |
| 342 true, | |
| 343 3600, | |
| 344 true, | |
| 345 true, | |
| 346 }, | |
| 347 { "HTTP/1.1 200 OK\n" | |
| 348 "connection: keep-alive\n" | |
| 349 "Chrome-Proxy: bypass=, block=, block-once\n" | |
| 350 "Content-Length: 999\n", | |
| 351 true, | |
| 352 0, | |
| 353 true, | |
| 354 false, | |
| 256 }, | 355 }, |
| 257 }; | 356 }; |
| 258 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 357 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 259 std::string headers(tests[i].headers); | 358 std::string headers(tests[i].headers); |
| 260 HeadersToRaw(&headers); | 359 HeadersToRaw(&headers); |
| 261 scoped_refptr<net::HttpResponseHeaders> parsed( | 360 scoped_refptr<net::HttpResponseHeaders> parsed( |
| 262 new net::HttpResponseHeaders(headers)); | 361 new net::HttpResponseHeaders(headers)); |
| 263 | 362 |
| 264 DataReductionProxyInfo data_reduction_proxy_info; | 363 DataReductionProxyInfo data_reduction_proxy_info; |
| 265 EXPECT_EQ(tests[i].expected_result, | 364 EXPECT_EQ(tests[i].expected_result, |
| 266 ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); | 365 ParseHeadersAndSetProxyInfo(parsed, &data_reduction_proxy_info)); |
| 267 EXPECT_EQ(tests[i].expected_retry_delay, | 366 EXPECT_EQ(tests[i].expected_retry_delay, |
| 268 data_reduction_proxy_info.bypass_duration.InSeconds()); | 367 data_reduction_proxy_info.bypass_duration.InSeconds()); |
| 269 EXPECT_EQ(tests[i].expected_bypass_all, | 368 EXPECT_EQ(tests[i].expected_bypass_all, |
| 270 data_reduction_proxy_info.bypass_all); | 369 data_reduction_proxy_info.bypass_all); |
| 370 EXPECT_EQ(tests[i].expected_mark_proxies_as_bad, | |
| 371 data_reduction_proxy_info.mark_proxies_as_bad); | |
| 271 } | 372 } |
| 272 } | 373 } |
| 273 | 374 |
| 274 TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { | 375 TEST_F(DataReductionProxyHeadersTest, ParseHeadersAndSetProxyInfo) { |
| 275 std::string headers = | 376 std::string headers = |
| 276 "HTTP/1.1 200 OK\n" | 377 "HTTP/1.1 200 OK\n" |
| 277 "connection: keep-alive\n" | 378 "connection: keep-alive\n" |
| 278 "Chrome-Proxy: bypass=0\n" | 379 "Chrome-Proxy: bypass=0\n" |
| 279 "Content-Length: 999\n"; | 380 "Content-Length: 999\n"; |
| 280 HeadersToRaw(&headers); | 381 HeadersToRaw(&headers); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 { "HTTP/1.1 200 OK\n" | 554 { "HTTP/1.1 200 OK\n" |
| 454 "Chrome-Proxy: bypass=300\n" | 555 "Chrome-Proxy: bypass=300\n" |
| 455 "Via: 1.1 Chrome-Compression-Proxy\n", | 556 "Via: 1.1 Chrome-Compression-Proxy\n", |
| 456 BYPASS_EVENT_TYPE_MEDIUM, | 557 BYPASS_EVENT_TYPE_MEDIUM, |
| 457 }, | 558 }, |
| 458 { "HTTP/1.1 200 OK\n" | 559 { "HTTP/1.1 200 OK\n" |
| 459 "Chrome-Proxy: bypass=301\n" | 560 "Chrome-Proxy: bypass=301\n" |
| 460 "Via: 1.1 Chrome-Compression-Proxy\n", | 561 "Via: 1.1 Chrome-Compression-Proxy\n", |
| 461 BYPASS_EVENT_TYPE_LONG, | 562 BYPASS_EVENT_TYPE_LONG, |
| 462 }, | 563 }, |
| 564 { "HTTP/1.1 200 OK\n" | |
| 565 "Chrome-Proxy: block-once\n" | |
| 566 "Via: 1.1 Chrome-Compression-Proxy\n", | |
| 567 BYPASS_EVENT_TYPE_CURRENT, | |
| 568 }, | |
| 463 { "HTTP/1.1 500 Internal Server Error\n" | 569 { "HTTP/1.1 500 Internal Server Error\n" |
| 464 "Via: 1.1 Chrome-Compression-Proxy\n", | 570 "Via: 1.1 Chrome-Compression-Proxy\n", |
| 465 BYPASS_EVENT_TYPE_STATUS_500_HTTP_INTERNAL_SERVER_ERROR, | 571 BYPASS_EVENT_TYPE_STATUS_500_HTTP_INTERNAL_SERVER_ERROR, |
| 466 }, | 572 }, |
| 467 { "HTTP/1.1 501 Not Implemented\n" | 573 { "HTTP/1.1 501 Not Implemented\n" |
| 468 "Via: 1.1 Chrome-Compression-Proxy\n", | 574 "Via: 1.1 Chrome-Compression-Proxy\n", |
| 469 BYPASS_EVENT_TYPE_MAX, | 575 BYPASS_EVENT_TYPE_MAX, |
| 470 }, | 576 }, |
| 471 { "HTTP/1.1 502 Bad Gateway\n" | 577 { "HTTP/1.1 502 Bad Gateway\n" |
| 472 "Via: 1.1 Chrome-Compression-Proxy\n", | 578 "Via: 1.1 Chrome-Compression-Proxy\n", |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 std::string output_values_string; | 875 std::string output_values_string; |
| 770 for (size_t j = 0; j < output_values.size(); ++j) | 876 for (size_t j = 0; j < output_values.size(); ++j) |
| 771 output_values_string += output_values[j] + ","; | 877 output_values_string += output_values[j] + ","; |
| 772 | 878 |
| 773 EXPECT_EQ(test[i].expected_output_values_string, output_values_string) | 879 EXPECT_EQ(test[i].expected_output_values_string, output_values_string) |
| 774 << test[i].label; | 880 << test[i].label; |
| 775 } | 881 } |
| 776 } | 882 } |
| 777 | 883 |
| 778 } // namespace data_reduction_proxy | 884 } // namespace data_reduction_proxy |
| OLD | NEW |