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

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

Powered by Google App Engine
This is Rietveld 408576698