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

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: FIx curvercp 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 const std::string url1 = "http://www.google.com/";
10059 const std::string url2 = "https://mail.google.com/";
10060 const std::string ip_addr = "1.2.3.4";
10061
10062 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(url1.c_str(),
10063 false, 1, LOWEST));
10064
10065 MockWrite writes1[] = {
10066 CreateMockWrite(*req1, 0),
10067 };
10068
10069 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1));
10070 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true));
10071 MockRead reads1[] = {
10072 CreateMockRead(*resp1, 1),
10073 CreateMockRead(*body1, 2),
10074 MockRead(ASYNC, OK, 3) // EOF
10075 };
10076
10077 scoped_ptr<DeterministicSocketData> data1(
10078 new DeterministicSocketData(reads1, arraysize(reads1),
10079 writes1, arraysize(writes1)));
10080 IPAddressNumber ip;
10081 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip));
10082 IPEndPoint peer_addr = IPEndPoint(ip, 443);
10083 MockConnect connect_data1(ASYNC, OK, peer_addr);
10084 data1->set_connect_data(connect_data1);
10085
10086 // SPDY GET for HTTPS URL (direct)
10087 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(url2.c_str(),
10088 false, 1, MEDIUM));
10089
10090 MockWrite writes2[] = {
10091 CreateMockWrite(*req2, 0),
10092 };
10093
10094 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1));
10095 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true));
10096 MockRead reads2[] = {
10097 CreateMockRead(*resp2, 1),
10098 CreateMockRead(*body2, 2),
10099 MockRead(ASYNC, OK, 3) // EOF
10100 };
10101
10102 scoped_ptr<DeterministicSocketData> data2(
10103 new DeterministicSocketData(reads2, arraysize(reads2),
10104 writes2, arraysize(writes2)));
10105 MockConnect connect_data2(ASYNC, OK);
10106 data2->set_connect_data(connect_data2);
10107
10108 // Set up a proxy config that sends HTTP requests to a proxy, and
10109 // all others direct.
10110 ProxyConfig proxy_config;
10111 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443");
10112 CapturingProxyResolver* capturing_proxy_resolver =
10113 new CapturingProxyResolver();
10114 SpdySessionDependencies session_deps(new ProxyService(
10115 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
10116 NULL));
10117
10118 // Load a valid cert. Note, that this does not need to
10119 // be valid for proxy because the MockSSLClientSocket does
10120 // not actually verify it. But SpdySession will use this
10121 // to see if it is valid for the new origin
10122 FilePath certs_dir = GetTestCertsDirectory();
10123 scoped_refptr<X509Certificate> server_cert(
10124 ImportCertFromFile(certs_dir, "ok_cert.pem"));
10125 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
10126
10127 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
10128 ssl1.SetNextProto(kProtoSPDY3);
10129 ssl1.cert = server_cert;
10130 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
10131 session_deps.deterministic_socket_factory->AddSocketDataProvider(data1.get());
10132
10133 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
10134 ssl2.SetNextProto(kProtoSPDY3);
10135 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
10136 session_deps.deterministic_socket_factory->AddSocketDataProvider(data2.get());
10137
10138 session_deps.host_resolver.reset(new MockCachingHostResolver());
10139 session_deps.host_resolver->rules()->AddRule("mail.google.com", ip_addr);
10140 session_deps.host_resolver->rules()->AddRule("proxy", ip_addr);
10141
10142 scoped_refptr<HttpNetworkSession> session(
10143 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
10144
10145 // Start the first transaction to set up the SpdySession
10146 HttpRequestInfo request1;
10147 request1.method = "GET";
10148 request1.url = GURL(url1);
10149 request1.priority = LOWEST;
10150 request1.load_flags = 0;
10151 HttpNetworkTransaction trans1(session);
10152 TestCompletionCallback callback1;
10153 ASSERT_EQ(ERR_IO_PENDING,
10154 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
10155 data1->RunFor(3);
10156
10157 ASSERT_TRUE(callback1.have_result());
10158 EXPECT_EQ(OK, callback1.WaitForResult());
10159 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
10160
10161 // Now, start the HTTP request
10162 HttpRequestInfo request2;
10163 request2.method = "GET";
10164 request2.url = GURL(url2);
10165 request2.priority = MEDIUM;
10166 request2.load_flags = 0;
10167 HttpNetworkTransaction trans2(session);
10168 TestCompletionCallback callback2;
10169 EXPECT_EQ(ERR_IO_PENDING,
10170 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
10171 MessageLoop::current()->RunAllPending();
10172 data2->RunFor(3);
10173
10174 ASSERT_TRUE(callback2.have_result());
10175 EXPECT_EQ(OK, callback2.WaitForResult());
10176 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
10177 }
10178
10052 } // namespace net 10179 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_spdy2_unittest.cc ('k') | net/http/http_proxy_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698