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

Side by Side Diff: net/http/http_network_layer_unittest.cc

Issue 298883011: Record errors that trigger a data reduction proxy bypass (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments from mef Created 6 years, 6 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 (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
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 },
511 { "HTTP/1.1 414 Request-URI Too Long\r\n\r\n", 1u}
496 }; 512 };
497 513
498 for (size_t i = 0; i < arraysize(headers); ++i) { 514 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
515 std::string pac_string;
516 if (data_reduction_proxy_count == 1u) {
517 pac_string = base::StringPrintf(
518 "PROXY %s; PROXY good:8080", data_reduction_proxy.data());
519 } else {
520 pac_string = base::StringPrintf(
521 "PROXY %s; PROXY %s; PROXY good:8080", data_reduction_proxy.data(),
522 data_reduction_proxy_fallback.data());
523 }
499 ConfigureTestDependencies( 524 ConfigureTestDependencies(
500 ProxyService::CreateFixedFromPacResult(pac_string)); 525 ProxyService::CreateFixedFromPacResult(pac_string));
501 526
502 MockRead data_reads[] = { 527 MockRead data_reads[] = {
503 MockRead(headers[i].c_str()), 528 MockRead(tests[i].headers),
504 MockRead("Bypass message"), 529 MockRead("Bypass message"),
505 MockRead(SYNCHRONOUS, OK), 530 MockRead(SYNCHRONOUS, OK),
506 }; 531 };
507 532
508 MockWrite data_writes[] = { 533 MockWrite data_writes[] = {
509 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 534 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
510 "Host: www.google.com\r\n" 535 "Host: www.google.com\r\n"
511 "Proxy-Connection: keep-alive\r\n\r\n"), 536 "Proxy-Connection: keep-alive\r\n\r\n"),
512 }; 537 };
513 538
514 StaticSocketDataProvider data1(data_reads, arraysize(data_reads), 539 StaticSocketDataProvider data1(data_reads, arraysize(data_reads),
515 data_writes, arraysize(data_writes)); 540 data_writes, arraysize(data_writes));
516 mock_socket_factory_.AddSocketDataProvider(&data1); 541 mock_socket_factory_.AddSocketDataProvider(&data1);
517 542
518 // Second data provider returns the expected content. 543 // Second data provider returns the expected content.
519 MockRead data_reads2[] = { 544 MockRead data_reads2[] = {
520 MockRead("HTTP/1.0 200 OK\r\n" 545 MockRead("HTTP/1.0 200 OK\r\n"
521 "Server: not-proxy\r\n\r\n"), 546 "Server: good-proxy\r\n"
mef 2014/05/29 16:41:38 Is this the data that is expected from server? Why
bengr 2014/05/29 18:46:19 "Not proxy" was incorrect. The test falls from a b
547 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"),
522 MockRead("content"), 548 MockRead("content"),
523 MockRead(SYNCHRONOUS, OK), 549 MockRead(SYNCHRONOUS, OK),
524 }; 550 };
525 MockWrite data_writes2[] = { 551 MockWrite data_writes2[] = {
526 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 552 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
527 "Host: www.google.com\r\n" 553 "Host: www.google.com\r\n"
528 "Proxy-Connection: keep-alive\r\n\r\n"), 554 "Proxy-Connection: keep-alive\r\n\r\n"),
529 }; 555 };
530 556
531 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), 557 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
(...skipping 18 matching lines...) Expand all
550 576
551 std::string contents; 577 std::string contents;
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", "good-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,
563 EXPECT_EQ(data_reduction_proxy, 589 proxy_service_->proxy_retry_info().size());
564 (*proxy_service_->proxy_retry_info().begin()).first); 590 if (tests[i].expected_proxies_on_retry_list == 1u) {
591 EXPECT_EQ(data_reduction_proxy,
592 (*proxy_service_->proxy_retry_info().begin()).first);
593 } else {
594 ProxyRetryInfoMap::const_iterator i =
mef 2014/05/29 16:41:38 Given that this is a map I think it is too brittle
bengr 2014/05/29 18:46:19 Good suggestion. Thanks. Done.
595 (proxy_service_->proxy_retry_info()).begin();
596 EXPECT_EQ(data_reduction_proxy_fallback, (*i++).first);
597 EXPECT_EQ(data_reduction_proxy, (*i).first);
598 }
565 } 599 }
566 } 600 }
567 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) 601 #endif // defined(SPDY_PROXY_AUTH_ORIGIN)
568 602
569 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) { 603 TEST_F(HttpNetworkLayerTest, ProxyBypassIgnoredOnDirectConnectionPac) {
570 // Verify that a Chrome-Proxy header is ignored when returned from a directly 604 // Verify that a Chrome-Proxy header is ignored when returned from a directly
571 // connected origin server. 605 // connected origin server.
572 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT")); 606 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult("DIRECT"));
573 607
574 MockRead data_reads[] = { 608 MockRead data_reads[] = {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 MockRead("HTTP/1.1 200 OK\r\n" 698 MockRead("HTTP/1.1 200 OK\r\n"
665 "Connection: keep-alive\r\n\r\n"), 699 "Connection: keep-alive\r\n\r\n"),
666 MockRead("Bypass message"), 700 MockRead("Bypass message"),
667 MockRead(SYNCHRONOUS, OK), 701 MockRead(SYNCHRONOUS, OK),
668 }; 702 };
669 703
670 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads, 704 TestProxyFallbackWithMockReads(chrome_proxy, std::string(), data_reads,
671 arraysize(data_reads), 1u); 705 arraysize(data_reads), 1u);
672 } 706 }
673 707
708 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith4xxFromOrigin) {
709 // Verify that Chrome will not be induced to bypass the data reduction proxy
710 // when the data reduction proxy via header is absent on a 4xx.
mef 2014/05/29 16:41:38 Is this a valid comment? I see 'Via' header in moc
bengr 2014/05/29 18:46:19 Done.
711 std::string chrome_proxy = GetDataReductionProxy();
712 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult(
713 "PROXY " + chrome_proxy + "; PROXY good:8080"));
714
715 MockRead data_reads[] = {
716 MockRead("HTTP/1.1 414 Request-URI Too Long\r\n"
717 "Connection: keep-alive\r\n"
718 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n"),
719 MockRead(SYNCHRONOUS, OK),
720 };
721
722 TestProxyFallbackByMethodWithMockReads(chrome_proxy, std::string(),
723 data_reads, arraysize(data_reads),
724 "GET", std::string(), false, 0);
725 }
726
674 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) { 727 TEST_F(HttpNetworkLayerTest, NoServerFallbackWith304Response) {
675 // Verify that Chrome will not be induced to bypass the data reduction proxy 728 // 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. 729 // when the data reduction proxy via header is absent on a 304.
677 std::string chrome_proxy = GetDataReductionProxy(); 730 std::string chrome_proxy = GetDataReductionProxy();
678 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult( 731 ConfigureTestDependencies(ProxyService::CreateFixedFromPacResult(
679 "PROXY " + chrome_proxy + "; PROXY good:8080")); 732 "PROXY " + chrome_proxy + "; PROXY good:8080"));
680 733
681 MockRead data_reads[] = { 734 MockRead data_reads[] = {
682 MockRead("HTTP/1.1 304 Not Modified\r\n" 735 MockRead("HTTP/1.1 304 Not Modified\r\n"
683 "Connection: keep-alive\r\n\r\n"), 736 "Connection: keep-alive\r\n\r\n"),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv)); 878 ASSERT_EQ(ERR_CONNECTION_RESET, callback.GetResult(rv));
826 879
827 // If the response info is null, that means that any consumer won't 880 // If the response info is null, that means that any consumer won't
828 // see the network accessed bit set. 881 // see the network accessed bit set.
829 EXPECT_EQ(NULL, trans->GetResponseInfo()); 882 EXPECT_EQ(NULL, trans->GetResponseInfo());
830 } 883 }
831 884
832 } // namespace 885 } // namespace
833 886
834 } // namespace net 887 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698