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_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/test/test_file_util.h" | 20 #include "base/test/test_file_util.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "net/base/auth.h" | 22 #include "net/base/auth.h" |
23 #include "net/base/capturing_net_log.h" | 23 #include "net/base/capturing_net_log.h" |
| 24 #include "net/base/cert_test_util.h" |
24 #include "net/base/completion_callback.h" | 25 #include "net/base/completion_callback.h" |
25 #include "net/base/host_cache.h" | 26 #include "net/base/host_cache.h" |
26 #include "net/base/mock_cert_verifier.h" | 27 #include "net/base/mock_cert_verifier.h" |
27 #include "net/base/mock_host_resolver.h" | 28 #include "net/base/mock_host_resolver.h" |
28 #include "net/base/net_log.h" | 29 #include "net/base/net_log.h" |
29 #include "net/base/net_log_unittest.h" | 30 #include "net/base/net_log_unittest.h" |
30 #include "net/base/request_priority.h" | 31 #include "net/base/request_priority.h" |
31 #include "net/base/ssl_cert_request_info.h" | 32 #include "net/base/ssl_cert_request_info.h" |
32 #include "net/base/ssl_config_service_defaults.h" | 33 #include "net/base/ssl_config_service_defaults.h" |
33 #include "net/base/ssl_info.h" | 34 #include "net/base/ssl_info.h" |
(...skipping 10034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10068 HttpNetworkTransaction trans2(session); | 10069 HttpNetworkTransaction trans2(session); |
10069 TestCompletionCallback callback2; | 10070 TestCompletionCallback callback2; |
10070 EXPECT_EQ(ERR_IO_PENDING, | 10071 EXPECT_EQ(ERR_IO_PENDING, |
10071 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | 10072 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
10072 MessageLoop::current()->RunAllPending(); | 10073 MessageLoop::current()->RunAllPending(); |
10073 | 10074 |
10074 EXPECT_EQ(OK, callback2.WaitForResult()); | 10075 EXPECT_EQ(OK, callback2.WaitForResult()); |
10075 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | 10076 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
10076 } | 10077 } |
10077 | 10078 |
| 10079 // Test that in the case where we have a SPDY session to a SPDY proxy |
| 10080 // that we do not pool other origins that resolve to the same IP when |
| 10081 // the certificate does not match the new origin. |
| 10082 // http://crbug.com/134690 |
| 10083 TEST_F(HttpNetworkTransactionSpdy2Test, DoNotUseSpdySessionIfCertDoesNotMatch) { |
| 10084 const std::string url1 = "http://www.google.com/"; |
| 10085 const std::string url2 = "https://mail.google.com/"; |
| 10086 const std::string ip_addr = "1.2.3.4"; |
| 10087 |
| 10088 // SPDY GET for HTTP URL (through SPDY proxy) |
| 10089 const char* const headers[] = { |
| 10090 "method", "GET", |
| 10091 "url", url1.c_str(), |
| 10092 "host", "www.google.com", |
| 10093 "scheme", "http", |
| 10094 "version", "HTTP/1.1" |
| 10095 }; |
| 10096 scoped_ptr<SpdyFrame> req1(ConstructSpdyControlFrame(NULL, 0, false, 1, |
| 10097 LOWEST, SYN_STREAM, |
| 10098 CONTROL_FLAG_FIN, |
| 10099 headers, |
| 10100 arraysize(headers))); |
| 10101 |
| 10102 MockWrite writes1[] = { |
| 10103 CreateMockWrite(*req1, 0), |
| 10104 }; |
| 10105 |
| 10106 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10107 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); |
| 10108 MockRead reads1[] = { |
| 10109 CreateMockRead(*resp1, 1), |
| 10110 CreateMockRead(*body1, 2), |
| 10111 MockRead(ASYNC, OK, 3) // EOF |
| 10112 }; |
| 10113 |
| 10114 scoped_ptr<DeterministicSocketData> data1( |
| 10115 new DeterministicSocketData(reads1, arraysize(reads1), |
| 10116 writes1, arraysize(writes1))); |
| 10117 IPAddressNumber ip; |
| 10118 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 10119 IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 10120 MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 10121 data1->set_connect_data(connect_data1); |
| 10122 |
| 10123 // SPDY GET for HTTPS URL (direct) |
| 10124 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(url2.c_str(), |
| 10125 false, 1, MEDIUM)); |
| 10126 |
| 10127 MockWrite writes2[] = { |
| 10128 CreateMockWrite(*req2, 0), |
| 10129 }; |
| 10130 |
| 10131 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10132 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); |
| 10133 MockRead reads2[] = { |
| 10134 CreateMockRead(*resp2, 1), |
| 10135 CreateMockRead(*body2, 2), |
| 10136 MockRead(ASYNC, OK, 3) // EOF |
| 10137 }; |
| 10138 |
| 10139 scoped_ptr<DeterministicSocketData> data2( |
| 10140 new DeterministicSocketData(reads2, arraysize(reads2), |
| 10141 writes2, arraysize(writes2))); |
| 10142 MockConnect connect_data2(ASYNC, OK); |
| 10143 data2->set_connect_data(connect_data2); |
| 10144 |
| 10145 // Set up a proxy config that sends HTTP requests to a proxy, and |
| 10146 // all others direct. |
| 10147 ProxyConfig proxy_config; |
| 10148 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
| 10149 CapturingProxyResolver* capturing_proxy_resolver = |
| 10150 new CapturingProxyResolver(); |
| 10151 SpdySessionDependencies session_deps(new ProxyService( |
| 10152 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, |
| 10153 NULL)); |
| 10154 |
| 10155 // Load a valid cert. Note, that this does not need to |
| 10156 // be valid for proxy because the MockSSLClientSocket does |
| 10157 // not actually verify it. But SpdySession will use this |
| 10158 // to see if it is valid for the new origin |
| 10159 FilePath certs_dir = GetTestCertsDirectory(); |
| 10160 scoped_refptr<X509Certificate> server_cert( |
| 10161 ImportCertFromFile(certs_dir, "ok_cert.pem")); |
| 10162 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); |
| 10163 |
| 10164 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
| 10165 ssl1.SetNextProto(kProtoSPDY2); |
| 10166 ssl1.cert = server_cert; |
| 10167 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 10168 session_deps.deterministic_socket_factory->AddSocketDataProvider(data1.get()); |
| 10169 |
| 10170 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
| 10171 ssl2.SetNextProto(kProtoSPDY2); |
| 10172 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 10173 session_deps.deterministic_socket_factory->AddSocketDataProvider(data2.get()); |
| 10174 |
| 10175 session_deps.host_resolver.reset(new MockCachingHostResolver()); |
| 10176 session_deps.host_resolver->rules()->AddRule("mail.google.com", ip_addr); |
| 10177 session_deps.host_resolver->rules()->AddRule("proxy", ip_addr); |
| 10178 |
| 10179 scoped_refptr<HttpNetworkSession> session( |
| 10180 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); |
| 10181 |
| 10182 // Start the first transaction to set up the SpdySession |
| 10183 HttpRequestInfo request1; |
| 10184 request1.method = "GET"; |
| 10185 request1.url = GURL(url1); |
| 10186 request1.priority = LOWEST; |
| 10187 request1.load_flags = 0; |
| 10188 HttpNetworkTransaction trans1(session); |
| 10189 TestCompletionCallback callback1; |
| 10190 ASSERT_EQ(ERR_IO_PENDING, |
| 10191 trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 10192 data1->RunFor(3); |
| 10193 |
| 10194 ASSERT_TRUE(callback1.have_result()); |
| 10195 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10196 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 10197 |
| 10198 // Now, start the HTTP request |
| 10199 HttpRequestInfo request2; |
| 10200 request2.method = "GET"; |
| 10201 request2.url = GURL(url2); |
| 10202 request2.priority = MEDIUM; |
| 10203 request2.load_flags = 0; |
| 10204 HttpNetworkTransaction trans2(session); |
| 10205 TestCompletionCallback callback2; |
| 10206 EXPECT_EQ(ERR_IO_PENDING, |
| 10207 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
| 10208 MessageLoop::current()->RunAllPending(); |
| 10209 data2->RunFor(3); |
| 10210 |
| 10211 ASSERT_TRUE(callback2.have_result()); |
| 10212 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10213 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 10214 } |
| 10215 |
10078 } // namespace net | 10216 } // namespace net |
OLD | NEW |