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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 EXPECT_EQ(request_.url.SchemeIs("https"), | 256 EXPECT_EQ(request_.url.SchemeIs("https"), |
257 response->was_npn_negotiated); | 257 response->was_npn_negotiated); |
258 } | 258 } |
259 EXPECT_EQ("127.0.0.1", response->socket_address.host()); | 259 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
260 EXPECT_EQ(port_, response->socket_address.port()); | 260 EXPECT_EQ(port_, response->socket_address.port()); |
261 output_.status_line = response->headers->GetStatusLine(); | 261 output_.status_line = response->headers->GetStatusLine(); |
262 output_.response_info = *response; // Make a copy so we can verify. | 262 output_.response_info = *response; // Make a copy so we can verify. |
263 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); | 263 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
264 } | 264 } |
265 | 265 |
| 266 void FinishDefaultTestWithoutVerification() { |
| 267 output_.rv = callback_.WaitForResult(); |
| 268 if (output_.rv != OK) |
| 269 session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED); |
| 270 } |
| 271 |
266 // Most tests will want to call this function. In particular, the MockReads | 272 // Most tests will want to call this function. In particular, the MockReads |
267 // should end with an empty read, and that read needs to be processed to | 273 // should end with an empty read, and that read needs to be processed to |
268 // ensure proper deletion of the spdy_session_pool. | 274 // ensure proper deletion of the spdy_session_pool. |
269 void VerifyDataConsumed() { | 275 void VerifyDataConsumed() { |
270 for (DataVector::iterator it = data_vector_.begin(); | 276 for (DataVector::iterator it = data_vector_.begin(); |
271 it != data_vector_.end(); ++it) { | 277 it != data_vector_.end(); ++it) { |
272 EXPECT_TRUE((*it)->at_read_eof()) << "Read count: " | 278 EXPECT_TRUE((*it)->at_read_eof()) << "Read count: " |
273 << (*it)->read_count() | 279 << (*it)->read_count() |
274 << " Read index: " | 280 << " Read index: " |
275 << (*it)->read_index(); | 281 << (*it)->read_index(); |
(...skipping 4267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4543 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4549 const HttpResponseInfo* response = trans->GetResponseInfo(); |
4544 EXPECT_TRUE(response->headers.get() != NULL); | 4550 EXPECT_TRUE(response->headers.get() != NULL); |
4545 EXPECT_TRUE(response->was_fetched_via_spdy); | 4551 EXPECT_TRUE(response->was_fetched_via_spdy); |
4546 out.rv = ReadTransaction(trans, &out.response_data); | 4552 out.rv = ReadTransaction(trans, &out.response_data); |
4547 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); | 4553 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
4548 | 4554 |
4549 // Verify that we consumed all test data. | 4555 // Verify that we consumed all test data. |
4550 helper.VerifyDataConsumed(); | 4556 helper.VerifyDataConsumed(); |
4551 } | 4557 } |
4552 | 4558 |
| 4559 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 4560 // protocol negotiation happens, instead this test forces protocols for both |
| 4561 // sockets. |
| 4562 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
| 4563 // HTTP_1_1_REQUIRED is only supported by SPDY4. |
| 4564 if (spdy_util_.spdy_version() < SPDY4) |
| 4565 return; |
| 4566 // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4567 // only spoken over SSL. |
| 4568 if (GetParam().ssl_type != SPDYSSL) |
| 4569 return; |
| 4570 |
| 4571 HttpRequestInfo request; |
| 4572 request.method = "GET"; |
| 4573 request.url = GURL("https://www.google.com/"); |
| 4574 scoped_ptr<SpdySessionDependencies> session_deps( |
| 4575 CreateSpdySessionDependencies(GetParam())); |
| 4576 // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
| 4577 session_deps->force_spdy_over_ssl = false; |
| 4578 session_deps->force_spdy_always = false; |
| 4579 session_deps->next_protos = SpdyNextProtos(); |
| 4580 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4581 GetParam(), session_deps.release()); |
| 4582 |
| 4583 // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. |
| 4584 const char* url = "https://www.google.com/"; |
| 4585 scoped_ptr<SpdyHeaderBlock> headers(spdy_util_.ConstructGetHeaderBlock(url)); |
| 4586 scoped_ptr<SpdyFrame> req( |
| 4587 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 4588 MockWrite writes0[] = {CreateMockWrite(*req)}; |
| 4589 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4590 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4591 MockRead reads0[] = {CreateMockRead(*go_away)}; |
| 4592 DelayedSocketData data0(1, reads0, arraysize(reads0), writes0, |
| 4593 arraysize(writes0)); |
| 4594 |
| 4595 scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4596 new SSLSocketDataProvider(ASYNC, OK)); |
| 4597 // Expect HTTP/2 protocols too in SSLConfig. |
| 4598 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4599 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
| 4600 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14); |
| 4601 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_15); |
| 4602 // Force SPDY. |
| 4603 ssl_provider0->SetNextProto(GetParam().protocol); |
| 4604 helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); |
| 4605 |
| 4606 // Second socket: falling back to HTTP/1.1. |
| 4607 MockWrite writes1[] = {MockWrite( |
| 4608 "GET / HTTP/1.1\r\n" |
| 4609 "Host: www.google.com\r\n" |
| 4610 "Connection: keep-alive\r\n\r\n")}; |
| 4611 MockRead reads1[] = {MockRead( |
| 4612 "HTTP/1.1 200 OK\r\n" |
| 4613 "Content-Length: 5\r\n\r\n" |
| 4614 "hello")}; |
| 4615 DelayedSocketData data1(1, reads1, arraysize(reads1), writes1, |
| 4616 arraysize(writes1)); |
| 4617 |
| 4618 scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4619 new SSLSocketDataProvider(ASYNC, OK)); |
| 4620 // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4621 ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4622 // Force HTTP/1.1. |
| 4623 ssl_provider1->SetNextProto(kProtoHTTP11); |
| 4624 helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); |
| 4625 |
| 4626 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4627 helper.session()->spdy_session_pool()->http_server_properties(); |
| 4628 const HostPortPair host_port_pair = HostPortPair::FromURL(GURL(url)); |
| 4629 EXPECT_FALSE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4630 |
| 4631 helper.RunPreTestSetup(); |
| 4632 helper.StartDefaultTest(); |
| 4633 helper.FinishDefaultTestWithoutVerification(); |
| 4634 helper.VerifyDataConsumed(); |
| 4635 EXPECT_TRUE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4636 |
| 4637 const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4638 ASSERT_TRUE(response != nullptr); |
| 4639 ASSERT_TRUE(response->headers.get() != nullptr); |
| 4640 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4641 EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4642 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4643 EXPECT_TRUE(response->was_npn_negotiated); |
| 4644 EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4645 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4646 EXPECT_EQ(443, response->socket_address.port()); |
| 4647 std::string response_data; |
| 4648 ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4649 EXPECT_EQ("hello", response_data); |
| 4650 } |
| 4651 |
| 4652 // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the |
| 4653 // proxy. Note that no actual protocol negotiation happens, instead this test |
| 4654 // forces protocols for both sockets. |
| 4655 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { |
| 4656 // HTTP_1_1_REQUIRED is only supported by SPDY4. |
| 4657 if (spdy_util_.spdy_version() < SPDY4) |
| 4658 return; |
| 4659 // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4660 // only spoken over SSL. |
| 4661 if (GetParam().ssl_type != SPDYSSL) |
| 4662 return; |
| 4663 |
| 4664 HttpRequestInfo request; |
| 4665 request.method = "GET"; |
| 4666 request.url = GURL("https://www.google.com/"); |
| 4667 scoped_ptr<SpdySessionDependencies> session_deps( |
| 4668 CreateSpdySessionDependencies( |
| 4669 GetParam(), |
| 4670 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"))); |
| 4671 // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
| 4672 session_deps->force_spdy_over_ssl = false; |
| 4673 session_deps->force_spdy_always = false; |
| 4674 session_deps->next_protos = SpdyNextProtos(); |
| 4675 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4676 GetParam(), session_deps.release()); |
| 4677 |
| 4678 // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. |
| 4679 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
| 4680 nullptr, 0, 1, LOWEST, HostPortPair("www.google.com", 443))); |
| 4681 MockWrite writes0[] = {CreateMockWrite(*req)}; |
| 4682 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4683 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4684 MockRead reads0[] = {CreateMockRead(*go_away)}; |
| 4685 DelayedSocketData data0(1, reads0, arraysize(reads0), writes0, |
| 4686 arraysize(writes0)); |
| 4687 |
| 4688 scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4689 new SSLSocketDataProvider(ASYNC, OK)); |
| 4690 // Expect HTTP/2 protocols too in SSLConfig. |
| 4691 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4692 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
| 4693 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14); |
| 4694 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_15); |
| 4695 // Force SPDY. |
| 4696 ssl_provider0->SetNextProto(GetParam().protocol); |
| 4697 helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); |
| 4698 |
| 4699 // Second socket: retry using HTTP/1.1. |
| 4700 MockWrite writes1[] = { |
| 4701 MockWrite(ASYNC, 1, |
| 4702 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 4703 "Host: www.google.com\r\n" |
| 4704 "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4705 MockWrite(ASYNC, 3, |
| 4706 "GET / HTTP/1.1\r\n" |
| 4707 "Host: www.google.com\r\n" |
| 4708 "Connection: keep-alive\r\n\r\n"), |
| 4709 }; |
| 4710 |
| 4711 MockRead reads1[] = { |
| 4712 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4713 MockRead(ASYNC, 4, |
| 4714 "HTTP/1.1 200 OK\r\n" |
| 4715 "Content-Length: 5\r\n\r\n" |
| 4716 "hello"), |
| 4717 }; |
| 4718 DelayedSocketData data1(1, reads1, arraysize(reads1), writes1, |
| 4719 arraysize(writes1)); |
| 4720 |
| 4721 scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4722 new SSLSocketDataProvider(ASYNC, OK)); |
| 4723 // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4724 ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4725 // Force HTTP/1.1. |
| 4726 ssl_provider1->SetNextProto(kProtoHTTP11); |
| 4727 helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); |
| 4728 |
| 4729 // A third socket is needed for the tunnelled connection. |
| 4730 scoped_ptr<SSLSocketDataProvider> ssl_provider2( |
| 4731 new SSLSocketDataProvider(ASYNC, OK)); |
| 4732 helper.session_deps()->socket_factory->AddSSLSocketDataProvider( |
| 4733 ssl_provider2.get()); |
| 4734 |
| 4735 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4736 helper.session()->spdy_session_pool()->http_server_properties(); |
| 4737 const HostPortPair proxy_host_port_pair = HostPortPair("myproxy", 70); |
| 4738 EXPECT_FALSE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4739 |
| 4740 helper.RunPreTestSetup(); |
| 4741 helper.StartDefaultTest(); |
| 4742 helper.FinishDefaultTestWithoutVerification(); |
| 4743 helper.VerifyDataConsumed(); |
| 4744 EXPECT_TRUE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4745 |
| 4746 const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4747 ASSERT_TRUE(response != nullptr); |
| 4748 ASSERT_TRUE(response->headers.get() != nullptr); |
| 4749 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4750 EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4751 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4752 EXPECT_FALSE(response->was_npn_negotiated); |
| 4753 EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4754 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4755 EXPECT_EQ(70, response->socket_address.port()); |
| 4756 std::string response_data; |
| 4757 ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4758 EXPECT_EQ("hello", response_data); |
| 4759 } |
| 4760 |
4553 // Test to make sure we can correctly connect through a proxy. | 4761 // Test to make sure we can correctly connect through a proxy. |
4554 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { | 4762 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
4555 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4763 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
4556 BoundNetLog(), GetParam(), NULL); | 4764 BoundNetLog(), GetParam(), NULL); |
4557 helper.session_deps().reset(CreateSpdySessionDependencies( | 4765 helper.session_deps().reset(CreateSpdySessionDependencies( |
4558 GetParam(), | 4766 GetParam(), |
4559 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); | 4767 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); |
4560 helper.SetSession(make_scoped_refptr( | 4768 helper.SetSession(make_scoped_refptr( |
4561 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); | 4769 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); |
4562 helper.RunPreTestSetup(); | 4770 helper.RunPreTestSetup(); |
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6591 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6799 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
6592 scoped_ptr<SSLSocketDataProvider> ssl_provider( | 6800 scoped_ptr<SSLSocketDataProvider> ssl_provider( |
6593 new SSLSocketDataProvider(ASYNC, OK)); | 6801 new SSLSocketDataProvider(ASYNC, OK)); |
6594 // Set to TLS_RSA_WITH_NULL_MD5 | 6802 // Set to TLS_RSA_WITH_NULL_MD5 |
6595 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6803 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
6596 | 6804 |
6597 RunTLSUsageCheckTest(ssl_provider.Pass()); | 6805 RunTLSUsageCheckTest(ssl_provider.Pass()); |
6598 } | 6806 } |
6599 | 6807 |
6600 } // namespace net | 6808 } // namespace net |
OLD | NEW |