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

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

Issue 10690122: Change SpdySession::GetSSLInfo to get the SSLInfo from the underlying socket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Expand comment on unit test. Created 8 years, 5 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 | Annotate | Revision Log
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_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 10008 matching lines...) Expand 10 before | Expand all | Expand 10 after
10042 HttpNetworkTransaction trans2(session); 10043 HttpNetworkTransaction trans2(session);
10043 TestCompletionCallback callback2; 10044 TestCompletionCallback callback2;
10044 EXPECT_EQ(ERR_IO_PENDING, 10045 EXPECT_EQ(ERR_IO_PENDING,
10045 trans2.Start(&request2, callback2.callback(), BoundNetLog())); 10046 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
10046 MessageLoop::current()->RunAllPending(); 10047 MessageLoop::current()->RunAllPending();
10047 10048
10048 EXPECT_EQ(OK, callback2.WaitForResult()); 10049 EXPECT_EQ(OK, callback2.WaitForResult());
10049 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); 10050 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
10050 } 10051 }
10051 10052
10053 // Test that in the case where we have a SPDY session to a SPDY proxy
10054 // that we do not pool other origins that resolve to the same IP when
10055 // the certificate does not match the new origin.
10056 // http://crbug.com/134690
10057 TEST_F(HttpNetworkTransactionSpdy3Test, DoNotUseSpdySessionIfCertDoesNotMatch) {
10058 FilePath certs_dir = GetTestCertsDirectory();
10059 scoped_refptr<X509Certificate> server_cert(
10060 ImportCertFromFile(certs_dir, "ok_cert.pem"));
10061 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
10062
10063 const std::string url1 = "http://www.google.com/";
10064 const std::string url2 = "https://mail.google.com/";
10065 const std::string ip_addr = "1.2.3.4";
10066
10067 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(url1.c_str(),
10068 false, 1, LOWEST));
10069
10070 MockWrite writes1[] = {
10071 CreateMockWrite(*req1, 0),
10072 };
10073
10074 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1));
10075 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true));
10076 MockRead reads1[] = {
10077 CreateMockRead(*resp1, 1),
10078 CreateMockRead(*body1, 2),
10079 MockRead(ASYNC, OK, 3) // EOF
10080 };
10081
10082 scoped_ptr<DeterministicSocketData> data1(
10083 new DeterministicSocketData(reads1, arraysize(reads1),
10084 writes1, arraysize(writes1)));
10085 IPAddressNumber ip;
10086 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip));
10087 IPEndPoint peer_addr = IPEndPoint(ip, 443);
10088 MockConnect connect_data1(ASYNC, OK, peer_addr);
10089 data1->set_connect_data(connect_data1);
10090
10091 // SPDY GET for HTTPS URL (direct)
10092 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(url2.c_str(),
10093 false, 1, MEDIUM));
10094
10095 MockWrite writes2[] = {
10096 CreateMockWrite(*req2, 0),
10097 };
10098
10099 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1));
10100 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true));
10101 MockRead reads2[] = {
10102 CreateMockRead(*resp2, 1),
10103 CreateMockRead(*body2, 2),
10104 MockRead(ASYNC, OK, 3) // EOF
10105 };
10106
10107 scoped_ptr<DeterministicSocketData> data2(
10108 new DeterministicSocketData(reads2, arraysize(reads2),
10109 writes2, arraysize(writes2)));
10110 MockConnect connect_data2(ASYNC, OK);
10111 data2->set_connect_data(connect_data2);
10112
10113 // Set up a proxy config that sends HTTP requests to a proxy, and
10114 // all others direct.
10115 ProxyConfig proxy_config;
10116 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443");
10117 CapturingProxyResolver* capturing_proxy_resolver =
10118 new CapturingProxyResolver();
10119 SpdySessionDependencies session_deps(new ProxyService(
10120 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
10121 NULL));
10122
10123 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
10124 ssl1.SetNextProto(kProtoSPDY3);
10125 ssl1.cert = server_cert;
10126 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
10127 session_deps.deterministic_socket_factory->AddSocketDataProvider(data1.get());
10128
10129 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
10130 ssl2.SetNextProto(kProtoSPDY3);
10131 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
10132 session_deps.deterministic_socket_factory->AddSocketDataProvider(data2.get());
10133
10134 session_deps.host_resolver.reset(new MockCachingHostResolver());
10135 session_deps.host_resolver->rules()->AddRule("mail.google.com", ip_addr);
10136 session_deps.host_resolver->rules()->AddRule("proxy", ip_addr);
10137
10138 scoped_refptr<HttpNetworkSession> session(
10139 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
10140
10141 // Start the first transaction to set up the SpdySession
10142 HttpRequestInfo request1;
10143 request1.method = "GET";
10144 request1.url = GURL(url1);
10145 request1.priority = LOWEST;
10146 request1.load_flags = 0;
10147 HttpNetworkTransaction trans1(session);
10148 TestCompletionCallback callback1;
10149 ASSERT_EQ(ERR_IO_PENDING,
10150 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
10151 data1->RunFor(3);
10152
10153 ASSERT_TRUE(callback1.have_result());
10154 EXPECT_EQ(OK, callback1.WaitForResult());
10155 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
10156
10157 // Now, start the HTTP request
10158 HttpRequestInfo request2;
10159 request2.method = "GET";
10160 request2.url = GURL(url2);
10161 request2.priority = MEDIUM;
10162 request2.load_flags = 0;
10163 HttpNetworkTransaction trans2(session);
10164 TestCompletionCallback callback2;
10165 EXPECT_EQ(ERR_IO_PENDING,
10166 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
10167 MessageLoop::current()->RunAllPending();
10168 data2->RunFor(3);
10169
10170 ASSERT_TRUE(callback2.have_result());
10171 EXPECT_EQ(OK, callback2.WaitForResult());
10172 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
10173 }
10174
10052 } // namespace net 10175 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698