Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/http/http_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.h" |
| 10 #include "net/cert/mock_cert_verifier.h" | 10 #include "net/cert/mock_cert_verifier.h" |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 "PROXY " + bad_proxy)); | 469 "PROXY " + bad_proxy)); |
| 470 TestProxyFallbackFail(1u, bad_proxy, ""); | 470 TestProxyFallbackFail(1u, bad_proxy, ""); |
| 471 } | 471 } |
| 472 | 472 |
| 473 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassFixed) { | 473 TEST_F(HttpNetworkLayerTest, ServerOneProxyNoDirectBypassFixed) { |
| 474 std::string bad_proxy = GetDataReductionProxy(); | 474 std::string bad_proxy = GetDataReductionProxy(); |
| 475 ConfigureTestDependencies(ProxyService::CreateFixed(bad_proxy)); | 475 ConfigureTestDependencies(ProxyService::CreateFixed(bad_proxy)); |
| 476 TestProxyFallbackFail(1u, bad_proxy, ""); | 476 TestProxyFallbackFail(1u, bad_proxy, ""); |
| 477 } | 477 } |
| 478 | 478 |
| 479 TEST_F(HttpNetworkLayerTest, ServerFallbackOn5xxError) { | 479 TEST_F(HttpNetworkLayerTest, ServerFallbackOn4xxAnd5xxErrors) { |
| 480 // Verify that "500 Internal Server Error", "502 Bad Gateway", and | 480 // Verify that "500 Internal Server Error", "502 Bad Gateway", and |
| 481 // "503 Service Unavailable" via the data reduction proxy induce proxy | 481 // "503 Service Unavailable" via the data reduction proxy induce proxy |
| 482 // fallback to a second proxy, if configured. | 482 // fallback to a second proxy, if configured. |
| 483 | 483 |
| 484 // Verify that 4xx responses bypass both data reduction proxies, when | |
| 485 // the proxy originates them. | |
| 486 | |
| 484 // To configure this test, we need to wire up a custom proxy service to use | 487 // To configure this test, we need to wire up a custom proxy service to use |
| 485 // a pair of proxies. We'll induce fallback via the first and return | 488 // a pair or triplet of proxies. We'll induce fallback via the first and |
| 486 // the expected data via the second. | 489 // return the expected data via the second, or third if the first two are |
| 490 // both bypassed. | |
| 487 std::string data_reduction_proxy( | 491 std::string data_reduction_proxy( |
| 488 HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString()); | 492 HostPortPair::FromURL(GURL(SPDY_PROXY_AUTH_ORIGIN)).ToString()); |
| 489 std::string pac_string = base::StringPrintf( | 493 std::string data_reduction_proxy_fallback; |
| 490 "PROXY %s; PROXY good:8080", data_reduction_proxy.data()); | 494 size_t data_reduction_proxy_count = 1u; |
| 495 #if defined(DATA_REDUCTION_FALLBACK_HOST) | |
| 496 data_reduction_proxy_fallback = | |
| 497 HostPortPair::FromURL(GURL(DATA_REDUCTION_FALLBACK_HOST)).ToString(); | |
| 498 data_reduction_proxy_count = 2u; | |
| 499 #endif | |
| 491 | 500 |
| 492 std::string headers[] = { | 501 |
| 493 "HTTP/1.1 500 Internal Server Error\r\n\r\n", | 502 const struct { |
| 494 "HTTP/1.1 502 Bad Gateway\r\n\r\n", | 503 const char* headers; |
| 495 "HTTP/1.1 503 Service Unavailable\r\n\r\n" | 504 size_t expected_proxies_on_retry_list; |
| 505 } tests[] = { | |
| 506 { "HTTP/1.1 500 Internal Server Error\r\n\r\n", 1u }, | |
| 507 { "HTTP/1.1 502 Bad Gateway\r\n\r\n", 1u }, | |
| 508 { "HTTP/1.1 503 Service Unavailable\r\n\r\n", 1u }, | |
| 509 { "HTTP/1.1 414 Request-URI Too Long\r\nServer: GFE/2.0\r\n\r\n", | |
| 510 data_reduction_proxy_count } | |
| 496 }; | 511 }; |
| 497 | 512 |
| 498 for (size_t i = 0; i < arraysize(headers); ++i) { | 513 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 514 //std::string pac_string = base::StringPrintf( | |
|
Matt Welsh
2014/05/23 23:56:30
remove comments?
bengr
2014/05/24 01:22:02
Done.
| |
| 515 // "PROXY %s; PROXY good:8080", data_reduction_proxy.data()); | |
| 516 std::string pac_string; | |
| 517 if (tests[i].expected_proxies_on_retry_list == 1u) { | |
| 518 pac_string = base::StringPrintf( | |
| 519 "PROXY %s; PROXY good:8080", data_reduction_proxy.data()); | |
| 520 } else { | |
| 521 pac_string = base::StringPrintf( | |
| 522 "PROXY %s; PROXY %s; PROXY good:8080", data_reduction_proxy.data(), | |
| 523 data_reduction_proxy_fallback.data()); | |
| 524 } | |
| 499 ConfigureTestDependencies( | 525 ConfigureTestDependencies( |
| 500 ProxyService::CreateFixedFromPacResult(pac_string)); | 526 ProxyService::CreateFixedFromPacResult(pac_string)); |
| 501 | 527 |
| 502 MockRead data_reads[] = { | 528 MockRead data_reads[] = { |
| 503 MockRead(headers[i].c_str()), | 529 MockRead(tests[i].headers), |
| 504 MockRead("Bypass message"), | 530 MockRead("Bypass message"), |
| 505 MockRead(SYNCHRONOUS, OK), | 531 MockRead(SYNCHRONOUS, OK), |
| 506 }; | 532 }; |
| 507 | 533 |
| 508 MockWrite data_writes[] = { | 534 MockWrite data_writes[] = { |
| 509 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 535 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 510 "Host: www.google.com\r\n" | 536 "Host: www.google.com\r\n" |
| 511 "Proxy-Connection: keep-alive\r\n\r\n"), | 537 "Proxy-Connection: keep-alive\r\n\r\n"), |
| 512 }; | 538 }; |
| 513 | 539 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 rv = ReadTransaction(trans.get(), &contents); | 578 rv = ReadTransaction(trans.get(), &contents); |
| 553 EXPECT_EQ(OK, rv); | 579 EXPECT_EQ(OK, rv); |
| 554 | 580 |
| 555 // We should obtain content from the second socket provider write | 581 // We should obtain content from the second socket provider write |
| 556 // corresponding to the fallback proxy. | 582 // corresponding to the fallback proxy. |
| 557 EXPECT_EQ("content", contents); | 583 EXPECT_EQ("content", contents); |
| 558 // We also have a server header here that isn't set by the proxy. | 584 // We also have a server header here that isn't set by the proxy. |
| 559 EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue( | 585 EXPECT_TRUE(trans->GetResponseInfo()->headers->HasHeaderValue( |
| 560 "server", "not-proxy")); | 586 "server", "not-proxy")); |
| 561 // We should also observe the data reduction proxy in the retry list. | 587 // We should also observe the data reduction proxy in the retry list. |
| 562 ASSERT_EQ(1u, proxy_service_->proxy_retry_info().size()); | 588 ASSERT_EQ(tests[i].expected_proxies_on_retry_list, |
| 589 proxy_service_->proxy_retry_info().size()); | |
| 563 EXPECT_EQ(data_reduction_proxy, | 590 EXPECT_EQ(data_reduction_proxy, |
| 564 (*proxy_service_->proxy_retry_info().begin()).first); | 591 (*proxy_service_->proxy_retry_info().begin()).first); |
| 565 } | 592 } |
| 566 } | 593 } |
| 567 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 594 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
| 568 | 595 |
| 569 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) { | 596 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) { |
| 570 // Verify that a Chrome-Proxy header is ignored when returned from a directly | 597 // Verify that a Chrome-Proxy header is ignored when returned from a directly |
| 571 // connected origin server. | 598 // connected origin server. |
| 572 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); | 599 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 MockRead("HTTP/1.1 200 OK\r\n" | 691 MockRead("HTTP/1.1 200 OK\r\n" |
| 665 "Connection: keep-alive\r\n\r\n"), | 692 "Connection: keep-alive\r\n\r\n"), |
| 666 MockRead("Bypass message"), | 693 MockRead("Bypass message"), |
| 667 MockRead(SYNCHRONOUS, OK), | 694 MockRead(SYNCHRONOUS, OK), |
| 668 }; | 695 }; |
| 669 | 696 |
| 670 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, | 697 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, |
| 671 arraysize(data_reads), 1u); | 698 arraysize(data_reads), 1u); |
| 672 } | 699 } |
| 673 | 700 |
| 701 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith4xxFromOrigin) { | |
| 702 // Verify that Chrome will not be induced to bypass the data reduction proxy | |
| 703 // when the data reduction proxy via header is absent on a 4xx. | |
| 704 std::string chrome_proxy = GetDataReductionProxy(); | |
| 705 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | |
| 706 "PROXY " + chrome_proxy + "; PROXY good:8080")); | |
| 707 | |
| 708 MockRead data_reads[] = { | |
| 709 MockRead("HTTP/1.1 414 Request-URI Too Long\r\n" | |
| 710 "Connection: keep-alive\r\n\r\n"), | |
| 711 MockRead(SYNCHRONOUS, OK), | |
| 712 }; | |
| 713 | |
| 714 TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(), | |
| 715 data_reads, arraysize(data_reads), | |
| 716 "GET", std::string(), false, 0); | |
| 717 } | |
| 718 | |
| 674 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) { | 719 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) { |
| 675 // Verify that Chrome will not be induced to bypass the data reduction proxy | 720 // Verify that Chrome will not be induced to bypass the data reduction proxy |
| 676 // when the data reduction proxy via header is absent on a 304. | 721 // when the data reduction proxy via header is absent on a 304. |
| 677 std::string chrome_proxy = GetDataReductionProxy(); | 722 std::string chrome_proxy = GetDataReductionProxy(); |
| 678 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( | 723 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( |
| 679 "PROXY " + chrome_proxy + "; PROXY good:8080")); | 724 "PROXY " + chrome_proxy + "; PROXY good:8080")); |
| 680 | 725 |
| 681 MockRead data_reads[] = { | 726 MockRead data_reads[] = { |
| 682 MockRead("HTTP/1.1 304 Not Modified\r\n" | 727 MockRead("HTTP/1.1 304 Not Modified\r\n" |
| 683 "Connection: keep-alive\r\n\r\n"), | 728 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv)); | 870 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv)); |
| 826 | 871 |
| 827 // If the response info is null, that means that any consumer won't | 872 // If the response info is null, that means that any consumer won't |
| 828 // see the network accessed bit set. | 873 // see the network accessed bit set. |
| 829 EXPECT_EQ(NULL, trans->GetResponseInfo()); | 874 EXPECT_EQ(NULL, trans->GetResponseInfo()); |
| 830 } | 875 } |
| 831 | 876 |
| 832 } // namespace | 877 } // namespace |
| 833 | 878 |
| 834 } // namespace net | 879 } // namespace net |
| OLD | NEW |