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_F(HttpNetworkTransactionSpdy2Test, DoNotUseSpdySessionIfCertDoesNotMatch) { | |
Ryan Sleevi
2012/07/11 22:50:43
Can you add a comment describing exactly what this
Ryan Hamilton
2012/07/11 23:37:25
Done. Good point.
| |
10080 FilePath certs_dir = GetTestCertsDirectory(); | |
10081 scoped_refptr<X509Certificate> server_cert( | |
10082 ImportCertFromFile(certs_dir, "ok_cert.pem")); | |
10083 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); | |
10084 | |
10085 const std::string url1 = "http://www.google.com/"; | |
10086 const std::string url2 = "https://mail.google.com/"; | |
10087 const std::string ip_addr = "1.2.3.4"; | |
10088 | |
10089 // SPDY GET for HTTP URL (through SPDY proxy) | |
10090 const char* const headers[] = { | |
10091 "method", "GET", | |
10092 "url", url1.c_str(), | |
10093 "host", "www.google.com", | |
10094 "scheme", "http", | |
10095 "version", "HTTP/1.1" | |
10096 }; | |
10097 scoped_ptr<SpdyFrame> req1(ConstructSpdyControlFrame(NULL, 0, false, 1, | |
10098 LOWEST, SYN_STREAM, | |
10099 CONTROL_FLAG_FIN, | |
10100 headers, | |
10101 arraysize(headers))); | |
10102 | |
10103 MockWrite writes1[] = { | |
10104 CreateMockWrite(*req1, 0), | |
10105 }; | |
10106 | |
10107 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10108 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); | |
10109 MockRead reads1[] = { | |
10110 CreateMockRead(*resp1, 1), | |
10111 CreateMockRead(*body1, 2), | |
10112 MockRead(ASYNC, ERR_IO_PENDING, 3) | |
Ryan Sleevi
2012/07/11 22:50:43
Could you add a comment about this? Normally I'd e
Ryan Hamilton
2012/07/11 23:37:25
This is common in SPDY tests for the reason you st
| |
10113 }; | |
10114 | |
10115 scoped_ptr<DeterministicSocketData> data1( | |
10116 new DeterministicSocketData(reads1, arraysize(reads1), | |
10117 writes1, arraysize(writes1))); | |
10118 IPAddressNumber ip; | |
10119 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); | |
10120 IPEndPoint peer_addr = IPEndPoint(ip, 443); | |
10121 MockConnect connect_data1(ASYNC, OK, peer_addr); | |
10122 data1->set_connect_data(connect_data1); | |
10123 | |
10124 // SPDY GET for HTTPS URL (direct) | |
10125 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(url2.c_str(), | |
10126 false, 1, MEDIUM)); | |
10127 | |
10128 MockWrite writes2[] = { | |
10129 CreateMockWrite(*req2, 0), | |
10130 }; | |
10131 | |
10132 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
10133 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); | |
10134 MockRead reads2[] = { | |
10135 CreateMockRead(*resp2, 1), | |
10136 CreateMockRead(*body2, 2), | |
10137 MockRead(ASYNC, ERR_IO_PENDING, 3) | |
10138 }; | |
10139 | |
10140 scoped_ptr<DeterministicSocketData> data2( | |
10141 new DeterministicSocketData(reads2, arraysize(reads2), | |
10142 writes2, arraysize(writes2))); | |
10143 MockConnect connect_data2(ASYNC, OK); | |
10144 data2->set_connect_data(connect_data2); | |
10145 | |
10146 // Set up a proxy config that sends HTTP requests to a proxy, and | |
10147 // all others direct. | |
10148 ProxyConfig proxy_config; | |
10149 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); | |
10150 CapturingProxyResolver* capturing_proxy_resolver = | |
10151 new CapturingProxyResolver(); | |
10152 SpdySessionDependencies session_deps(new ProxyService( | |
10153 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, | |
10154 NULL)); | |
10155 | |
10156 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy | |
10157 ssl1.SetNextProto(kProtoSPDY2); | |
10158 ssl1.cert = server_cert; | |
10159 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); | |
10160 session_deps.deterministic_socket_factory->AddSocketDataProvider(data1.get()); | |
10161 | |
10162 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server | |
10163 ssl2.SetNextProto(kProtoSPDY2); | |
10164 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); | |
10165 session_deps.deterministic_socket_factory->AddSocketDataProvider(data2.get()); | |
10166 | |
10167 session_deps.host_resolver.reset(new MockCachingHostResolver()); | |
10168 session_deps.host_resolver->rules()->AddRule("mail.google.com", ip_addr); | |
10169 session_deps.host_resolver->rules()->AddRule("proxy", ip_addr); | |
10170 | |
10171 scoped_refptr<HttpNetworkSession> session( | |
10172 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps)); | |
10173 | |
10174 // Start the first transaction to set up the SpdySession | |
10175 HttpRequestInfo request1; | |
10176 request1.method = "GET"; | |
10177 request1.url = GURL(url1); | |
10178 request1.priority = LOWEST; | |
10179 request1.load_flags = 0; | |
10180 HttpNetworkTransaction trans1(session); | |
10181 TestCompletionCallback callback1; | |
10182 EXPECT_EQ(ERR_IO_PENDING, | |
Ryan Sleevi
2012/07/11 22:50:43
ASSERT_EQ
Ryan Hamilton
2012/07/11 23:37:25
Done.
| |
10183 trans1.Start(&request1, callback1.callback(), BoundNetLog())); | |
10184 data1->RunFor(3); | |
10185 | |
10186 EXPECT_EQ(OK, callback1.WaitForResult()); | |
Ryan Sleevi
2012/07/11 22:50:43
ASSERT_TRUE(callback1.have_result());
EXPECT_EQ(OK
Ryan Hamilton
2012/07/11 23:37:25
Done.
| |
10187 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); | |
10188 | |
10189 // Now, start the HTTP request | |
10190 HttpRequestInfo request2; | |
10191 request2.method = "GET"; | |
10192 request2.url = GURL(url2); | |
10193 request2.priority = MEDIUM; | |
10194 request2.load_flags = 0; | |
10195 HttpNetworkTransaction trans2(session); | |
10196 TestCompletionCallback callback2; | |
10197 EXPECT_EQ(ERR_IO_PENDING, | |
10198 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | |
10199 MessageLoop::current()->RunAllPending(); | |
10200 data2->RunFor(3); | |
10201 | |
10202 EXPECT_EQ(OK, callback2.WaitForResult()); | |
10203 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | |
10204 } | |
10205 | |
10078 } // namespace net | 10206 } // namespace net |
OLD | NEW |