blob: 6e1ad43b13812b1f304ae82825c28efcc4559bb4 [file] [log] [blame]
[email protected]23e482282013-06-14 16:08:021// Copyright 2013 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
[email protected]2d731a32010-04-29 01:04:065#include "net/http/http_network_transaction.h"
6
[email protected]77848d12008-11-14 00:00:227#include <math.h> // ceil
[email protected]5285d972011-10-18 18:56:348#include <stdarg.h>
9#include <string>
[email protected]95d88ffe2010-02-04 21:25:3310#include <vector>
[email protected]77848d12008-11-14 00:00:2211
[email protected]2d731a32010-04-29 01:04:0612#include "base/basictypes.h"
[email protected]68bf9152008-09-25 19:47:3013#include "base/compiler_specific.h"
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
thestigd8df0332014-09-04 06:33:2915#include "base/files/file_util.h"
[email protected]f3da152d2012-06-02 01:00:5716#include "base/json/json_writer.h"
Adam Rice425cf122015-01-19 06:18:2417#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1518#include "base/memory/scoped_ptr.h"
[email protected]bf828982013-08-14 18:01:4719#include "base/memory/weak_ptr.h"
[email protected]a34f61ee2014-03-18 20:59:4920#include "base/run_loop.h"
[email protected]125ef482013-06-11 18:32:4721#include "base/strings/string_util.h"
[email protected]750b2f3c2013-06-07 18:41:0522#include "base/strings/utf_string_conversions.h"
[email protected]f36a8132011-09-02 18:36:3323#include "base/test/test_file_util.h"
[email protected]277d5942010-08-11 21:02:3524#include "net/base/auth.h"
[email protected]169d0012010-05-10 23:20:1225#include "net/base/capturing_net_log.h"
mmenkecbc2b712014-10-09 20:29:0726#include "net/base/chunked_upload_data_stream.h"
[email protected]bacff652009-03-31 17:50:3327#include "net/base/completion_callback.h"
mmenkecbc2b712014-10-09 20:29:0728#include "net/base/elements_upload_data_stream.h"
[email protected]58e32bb2013-01-21 18:23:2529#include "net/base/load_timing_info.h"
30#include "net/base/load_timing_info_test_util.h"
Adam Rice425cf122015-01-19 06:18:2431#include "net/base/net_errors.h"
[email protected]169d0012010-05-10 23:20:1232#include "net/base/net_log.h"
33#include "net/base/net_log_unittest.h"
[email protected]ac790b42009-12-02 04:31:3134#include "net/base/request_priority.h"
initial.commit586acc5fe2008-07-26 22:42:5235#include "net/base/test_completion_callback.h"
[email protected]42fdb452012-11-01 12:44:4036#include "net/base/test_data_directory.h"
[email protected]b2d26cfd2012-12-11 10:36:0637#include "net/base/upload_bytes_element_reader.h"
[email protected]d98961652012-09-11 20:27:2138#include "net/base/upload_file_element_reader.h"
[email protected]6e7845ae2013-03-29 21:48:1139#include "net/cert/mock_cert_verifier.h"
[email protected]bc71b8772013-04-10 20:55:1640#include "net/dns/host_cache.h"
[email protected]f2cb3cf2013-03-21 01:40:5341#include "net/dns/mock_host_resolver.h"
[email protected]df41d0d82014-03-13 00:43:2442#include "net/http/http_auth_challenge_tokenizer.h"
[email protected]3c32c5f2010-05-18 15:18:1243#include "net/http/http_auth_handler_digest.h"
[email protected]3fd9dae2010-06-21 11:39:0044#include "net/http/http_auth_handler_mock.h"
[email protected]385a4672009-03-11 22:21:2945#include "net/http/http_auth_handler_ntlm.h"
Adam Rice425cf122015-01-19 06:18:2446#include "net/http/http_basic_state.h"
[email protected]0877e3d2009-10-17 22:29:5747#include "net/http/http_basic_stream.h"
initial.commit586acc5fe2008-07-26 22:42:5248#include "net/http/http_network_session.h"
[email protected]87bfa3f2010-09-30 14:54:5649#include "net/http/http_network_session_peer.h"
Adam Rice425cf122015-01-19 06:18:2450#include "net/http/http_request_headers.h"
[email protected]17291a022011-10-10 07:32:5351#include "net/http/http_server_properties_impl.h"
[email protected]0877e3d2009-10-17 22:29:5752#include "net/http/http_stream.h"
[email protected]8e6441ca2010-08-19 05:56:3853#include "net/http/http_stream_factory.h"
Adam Rice425cf122015-01-19 06:18:2454#include "net/http/http_stream_parser.h"
[email protected]c41737d2014-05-14 07:47:1955#include "net/http/http_transaction_test_util.h"
[email protected]51fff29d2008-12-19 22:17:5356#include "net/proxy/proxy_config_service_fixed.h"
[email protected]e86839fd2013-08-14 18:29:0357#include "net/proxy/proxy_info.h"
[email protected]631f1322010-04-30 17:59:1158#include "net/proxy/proxy_resolver.h"
59#include "net/proxy/proxy_service.h"
[email protected]f7984fc62009-06-22 23:26:4460#include "net/socket/client_socket_factory.h"
[email protected]483fa202013-05-14 01:07:0361#include "net/socket/client_socket_pool_manager.h"
[email protected]a42dbd142011-11-17 16:42:0262#include "net/socket/mock_client_socket_pool_manager.h"
[email protected]bb88e1d32013-05-03 23:11:0763#include "net/socket/next_proto.h"
[email protected]f7984fc62009-06-22 23:26:4464#include "net/socket/socket_test_util.h"
65#include "net/socket/ssl_client_socket.h"
[email protected]2ff8b312010-04-26 22:20:5466#include "net/spdy/spdy_framer.h"
67#include "net/spdy/spdy_session.h"
68#include "net/spdy/spdy_session_pool.h"
[email protected]23e482282013-06-14 16:08:0269#include "net/spdy/spdy_test_util_common.h"
[email protected]536fd0b2013-03-14 17:41:5770#include "net/ssl/ssl_cert_request_info.h"
[email protected]e86839fd2013-08-14 18:29:0371#include "net/ssl/ssl_config_service.h"
[email protected]536fd0b2013-03-14 17:41:5772#include "net/ssl/ssl_config_service_defaults.h"
73#include "net/ssl/ssl_info.h"
[email protected]6e7845ae2013-03-29 21:48:1174#include "net/test/cert_test_util.h"
[email protected]831e4a32013-11-14 02:14:4475#include "net/websockets/websocket_handshake_stream_base.h"
initial.commit586acc5fe2008-07-26 22:42:5276#include "testing/gtest/include/gtest/gtest.h"
[email protected]23887f04f2008-12-02 19:20:1577#include "testing/platform_test.h"
[email protected]795cbf82013-07-22 09:37:2778#include "url/gurl.h"
initial.commit586acc5fe2008-07-26 22:42:5279
[email protected]ad65a3e2013-12-25 18:18:0180using base::ASCIIToUTF16;
81
initial.commit586acc5fe2008-07-26 22:42:5282//-----------------------------------------------------------------------------
83
[email protected]13c8a092010-07-29 06:15:4484namespace {
85
[email protected]42cba2fb2013-03-29 19:58:5786const base::string16 kBar(ASCIIToUTF16("bar"));
87const base::string16 kBar2(ASCIIToUTF16("bar2"));
88const base::string16 kBar3(ASCIIToUTF16("bar3"));
89const base::string16 kBaz(ASCIIToUTF16("baz"));
90const base::string16 kFirst(ASCIIToUTF16("first"));
91const base::string16 kFoo(ASCIIToUTF16("foo"));
92const base::string16 kFoo2(ASCIIToUTF16("foo2"));
93const base::string16 kFoo3(ASCIIToUTF16("foo3"));
94const base::string16 kFou(ASCIIToUTF16("fou"));
95const base::string16 kSecond(ASCIIToUTF16("second"));
96const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm"));
97const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword"));
[email protected]13c8a092010-07-29 06:15:4498
[email protected]e5c026642012-03-17 00:14:0299int GetIdleSocketCountInTransportSocketPool(net::HttpNetworkSession* session) {
100 return session->GetTransportSocketPool(
101 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount();
102}
103
104int GetIdleSocketCountInSSLSocketPool(net::HttpNetworkSession* session) {
105 return session->GetSSLSocketPool(
106 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IdleSocketCount();
107}
108
[email protected]043b68c82013-08-22 23:41:52109bool IsTransportSocketPoolStalled(net::HttpNetworkSession* session) {
110 return session->GetTransportSocketPool(
111 net::HttpNetworkSession::NORMAL_SOCKET_POOL)->IsStalled();
112}
113
[email protected]f3da152d2012-06-02 01:00:57114// Takes in a Value created from a NetLogHttpResponseParameter, and returns
115// a JSONified list of headers as a single string. Uses single quotes instead
116// of double quotes for easier comparison. Returns false on failure.
[email protected]ea5ef4c2013-06-13 22:50:27117bool GetHeaders(base::DictionaryValue* params, std::string* headers) {
[email protected]f3da152d2012-06-02 01:00:57118 if (!params)
119 return false;
[email protected]ea5ef4c2013-06-13 22:50:27120 base::ListValue* header_list;
[email protected]f3da152d2012-06-02 01:00:57121 if (!params->GetList("headers", &header_list))
122 return false;
123 std::string double_quote_headers;
124 base::JSONWriter::Write(header_list, &double_quote_headers);
[email protected]466c9862013-12-03 22:05:28125 base::ReplaceChars(double_quote_headers, "\"", "'", headers);
[email protected]f3da152d2012-06-02 01:00:57126 return true;
127}
128
[email protected]029c83b62013-01-24 05:28:20129// Tests LoadTimingInfo in the case a socket is reused and no PAC script is
130// used.
131void TestLoadTimingReused(const net::LoadTimingInfo& load_timing_info) {
132 EXPECT_TRUE(load_timing_info.socket_reused);
[email protected]58e32bb2013-01-21 18:23:25133 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
134
[email protected]029c83b62013-01-24 05:28:20135 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
136 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
137
138 net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
139 EXPECT_FALSE(load_timing_info.send_start.is_null());
[email protected]58e32bb2013-01-21 18:23:25140
141 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]58e32bb2013-01-21 18:23:25142
[email protected]3b23a222013-05-15 21:33:25143 // Set at a higher level.
[email protected]58e32bb2013-01-21 18:23:25144 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
145 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25146 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]58e32bb2013-01-21 18:23:25147}
148
[email protected]029c83b62013-01-24 05:28:20149// Tests LoadTimingInfo in the case a new socket is used and no PAC script is
150// used.
[email protected]58e32bb2013-01-21 18:23:25151void TestLoadTimingNotReused(const net::LoadTimingInfo& load_timing_info,
152 int connect_timing_flags) {
[email protected]029c83b62013-01-24 05:28:20153 EXPECT_FALSE(load_timing_info.socket_reused);
154 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
155
156 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
157 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
158
159 net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing,
[email protected]3b23a222013-05-15 21:33:25160 connect_timing_flags);
[email protected]029c83b62013-01-24 05:28:20161 EXPECT_LE(load_timing_info.connect_timing.connect_end,
162 load_timing_info.send_start);
163
164 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]029c83b62013-01-24 05:28:20165
[email protected]3b23a222013-05-15 21:33:25166 // Set at a higher level.
[email protected]029c83b62013-01-24 05:28:20167 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
168 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25169 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]029c83b62013-01-24 05:28:20170}
171
172// Tests LoadTimingInfo in the case a socket is reused and a PAC script is
173// used.
174void TestLoadTimingReusedWithPac(const net::LoadTimingInfo& load_timing_info) {
175 EXPECT_TRUE(load_timing_info.socket_reused);
176 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
177
178 net::ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
179
180 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null());
181 EXPECT_LE(load_timing_info.proxy_resolve_start,
182 load_timing_info.proxy_resolve_end);
183 EXPECT_LE(load_timing_info.proxy_resolve_end,
184 load_timing_info.send_start);
185 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]029c83b62013-01-24 05:28:20186
[email protected]3b23a222013-05-15 21:33:25187 // Set at a higher level.
[email protected]029c83b62013-01-24 05:28:20188 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
189 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25190 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]029c83b62013-01-24 05:28:20191}
192
193// Tests LoadTimingInfo in the case a new socket is used and a PAC script is
194// used.
195void TestLoadTimingNotReusedWithPac(const net::LoadTimingInfo& load_timing_info,
196 int connect_timing_flags) {
197 EXPECT_FALSE(load_timing_info.socket_reused);
198 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
199
200 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null());
201 EXPECT_LE(load_timing_info.proxy_resolve_start,
202 load_timing_info.proxy_resolve_end);
203 EXPECT_LE(load_timing_info.proxy_resolve_end,
204 load_timing_info.connect_timing.connect_start);
205 net::ExpectConnectTimingHasTimes(load_timing_info.connect_timing,
206 connect_timing_flags);
207 EXPECT_LE(load_timing_info.connect_timing.connect_end,
208 load_timing_info.send_start);
209
210 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end);
[email protected]029c83b62013-01-24 05:28:20211
[email protected]3b23a222013-05-15 21:33:25212 // Set at a higher level.
[email protected]029c83b62013-01-24 05:28:20213 EXPECT_TRUE(load_timing_info.request_start_time.is_null());
214 EXPECT_TRUE(load_timing_info.request_start.is_null());
[email protected]3b23a222013-05-15 21:33:25215 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]58e32bb2013-01-21 18:23:25216}
217
Adam Rice425cf122015-01-19 06:18:24218void AddWebSocketHeaders(net::HttpRequestHeaders* headers) {
219 headers->SetHeader("Connection", "Upgrade");
220 headers->SetHeader("Upgrade", "websocket");
221 headers->SetHeader("Origin", "http://www.google.com");
222 headers->SetHeader("Sec-WebSocket-Version", "13");
223 headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
224}
225
[email protected]13c8a092010-07-29 06:15:44226} // namespace
227
[email protected]89ceba9a2009-03-21 03:46:06228namespace net {
229
[email protected]448d4ca52012-03-04 04:12:23230namespace {
231
[email protected]c6bf8152012-12-02 07:43:34232HttpNetworkSession* CreateSession(SpdySessionDependencies* session_deps) {
233 return SpdySessionDependencies::SpdyCreateSession(session_deps);
[email protected]e8d536192008-10-17 22:21:14234}
235
[email protected]448d4ca52012-03-04 04:12:23236} // namespace
237
[email protected]23e482282013-06-14 16:08:02238class HttpNetworkTransactionTest
239 : public PlatformTest,
240 public ::testing::WithParamInterface<NextProto> {
[email protected]483fa202013-05-14 01:07:03241 public:
[email protected]23e482282013-06-14 16:08:02242 virtual ~HttpNetworkTransactionTest() {
[email protected]483fa202013-05-14 01:07:03243 // Important to restore the per-pool limit first, since the pool limit must
244 // always be greater than group limit, and the tests reduce both limits.
245 ClientSocketPoolManager::set_max_sockets_per_pool(
246 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_);
247 ClientSocketPoolManager::set_max_sockets_per_group(
248 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_);
249 }
250
[email protected]e3ceb682011-06-28 23:55:46251 protected:
[email protected]23e482282013-06-14 16:08:02252 HttpNetworkTransactionTest()
253 : spdy_util_(GetParam()),
254 session_deps_(GetParam()),
[email protected]483fa202013-05-14 01:07:03255 old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group(
256 HttpNetworkSession::NORMAL_SOCKET_POOL)),
257 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool(
258 HttpNetworkSession::NORMAL_SOCKET_POOL)) {
259 }
[email protected]bb88e1d32013-05-03 23:11:07260
[email protected]e3ceb682011-06-28 23:55:46261 struct SimpleGetHelperResult {
262 int rv;
263 std::string status_line;
264 std::string response_data;
[email protected]b8015c42013-12-24 15:18:19265 int64 totalReceivedBytes;
[email protected]58e32bb2013-01-21 18:23:25266 LoadTimingInfo load_timing_info;
[email protected]e3ceb682011-06-28 23:55:46267 };
268
dcheng67be2b1f2014-10-27 21:47:29269 void SetUp() override {
[email protected]0b0bf032010-09-21 18:08:50270 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
[email protected]2da659e2013-05-23 20:51:34271 base::MessageLoop::current()->RunUntilIdle();
[email protected]2ff8b312010-04-26 22:20:54272 }
273
dcheng67be2b1f2014-10-27 21:47:29274 void TearDown() override {
[email protected]0b0bf032010-09-21 18:08:50275 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
[email protected]2da659e2013-05-23 20:51:34276 base::MessageLoop::current()->RunUntilIdle();
[email protected]0e75a732008-10-16 20:36:09277 // Empty the current queue.
[email protected]2da659e2013-05-23 20:51:34278 base::MessageLoop::current()->RunUntilIdle();
[email protected]0e75a732008-10-16 20:36:09279 PlatformTest::TearDown();
[email protected]0b0bf032010-09-21 18:08:50280 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
[email protected]2da659e2013-05-23 20:51:34281 base::MessageLoop::current()->RunUntilIdle();
[email protected]0e75a732008-10-16 20:36:09282 }
283
bnc33b8cef42014-11-19 17:30:38284 const char* GetAlternateProtocolFromParam() {
285 return
286 AlternateProtocolToString(AlternateProtocolFromNextProto(GetParam()));
287 }
288
[email protected]8a0fc822013-06-27 20:52:43289 // This is the expected return from a current server advertising SPDY.
290 std::string GetAlternateProtocolHttpHeader() {
bnc33b8cef42014-11-19 17:30:38291 return std::string("Alternate-Protocol: 443:") +
292 GetAlternateProtocolFromParam() + "\r\n\r\n";
[email protected]8a0fc822013-06-27 20:52:43293 }
294
[email protected]202965992011-12-07 23:04:51295 // Either |write_failure| specifies a write failure or |read_failure|
296 // specifies a read failure when using a reused socket. In either case, the
297 // failure should cause the network transaction to resend the request, and the
298 // other argument should be NULL.
299 void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure,
300 const MockRead* read_failure);
initial.commit586acc5fe2008-07-26 22:42:52301
[email protected]a34f61ee2014-03-18 20:59:49302 // Either |write_failure| specifies a write failure or |read_failure|
303 // specifies a read failure when using a reused socket. In either case, the
304 // failure should cause the network transaction to resend the request, and the
305 // other argument should be NULL.
306 void PreconnectErrorResendRequestTest(const MockWrite* write_failure,
[email protected]09356c652014-03-25 15:36:10307 const MockRead* read_failure,
308 bool use_spdy);
[email protected]a34f61ee2014-03-18 20:59:49309
[email protected]5a60c8b2011-10-19 20:14:29310 SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[],
311 size_t data_count) {
[email protected]ff007e162009-05-23 09:13:15312 SimpleGetHelperResult out;
initial.commit586acc5fe2008-07-26 22:42:52313
[email protected]ff007e162009-05-23 09:13:15314 HttpRequestInfo request;
315 request.method = "GET";
316 request.url = GURL("http://www.google.com/");
317 request.load_flags = 0;
initial.commit586acc5fe2008-07-26 22:42:52318
[email protected]58e32bb2013-01-21 18:23:25319 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:07320 session_deps_.net_log = log.bound().net_log();
[email protected]3fe8d2f82013-10-17 08:56:07321 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:27322 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:41323 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:27324
[email protected]5a60c8b2011-10-19 20:14:29325 for (size_t i = 0; i < data_count; ++i) {
[email protected]bb88e1d32013-05-03 23:11:07326 session_deps_.socket_factory->AddSocketDataProvider(data[i]);
[email protected]5a60c8b2011-10-19 20:14:29327 }
initial.commit586acc5fe2008-07-26 22:42:52328
[email protected]49639fa2011-12-20 23:22:41329 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:52330
[email protected]c47c0372014-03-12 23:07:02331 EXPECT_TRUE(log.bound().IsLogging());
[email protected]49639fa2011-12-20 23:22:41332 int rv = trans->Start(&request, callback.callback(), log.bound());
[email protected]ff007e162009-05-23 09:13:15333 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:52334
[email protected]ff007e162009-05-23 09:13:15335 out.rv = callback.WaitForResult();
[email protected]58e32bb2013-01-21 18:23:25336
337 // Even in the failure cases that use this function, connections are always
338 // successfully established before the error.
339 EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info));
340 TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
341
[email protected]ff007e162009-05-23 09:13:15342 if (out.rv != OK)
343 return out;
344
345 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:50346 // Can't use ASSERT_* inside helper functions like this, so
347 // return an error.
[email protected]90499482013-06-01 00:39:50348 if (response == NULL || response->headers.get() == NULL) {
[email protected]fe2255a2011-09-20 19:37:50349 out.rv = ERR_UNEXPECTED;
350 return out;
351 }
[email protected]ff007e162009-05-23 09:13:15352 out.status_line = response->headers->GetStatusLine();
353
[email protected]80a09a82012-11-16 17:40:06354 EXPECT_EQ("127.0.0.1", response->socket_address.host());
355 EXPECT_EQ(80, response->socket_address.port());
[email protected]6d81b482011-02-22 19:47:19356
[email protected]ff007e162009-05-23 09:13:15357 rv = ReadTransaction(trans.get(), &out.response_data);
358 EXPECT_EQ(OK, rv);
[email protected]b2fcd0e2010-12-01 15:19:40359
[email protected]f3da152d2012-06-02 01:00:57360 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:40361 log.GetEntries(&entries);
[email protected]dbb83db2010-05-11 18:13:39362 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:40363 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
[email protected]169d0012010-05-10 23:20:12364 NetLog::PHASE_NONE);
[email protected]dbb83db2010-05-11 18:13:39365 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:40366 entries, pos,
[email protected]dbb83db2010-05-11 18:13:39367 NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
368 NetLog::PHASE_NONE);
[email protected]ff007e162009-05-23 09:13:15369
[email protected]f3da152d2012-06-02 01:00:57370 std::string line;
371 EXPECT_TRUE(entries[pos].GetStringValue("line", &line));
372 EXPECT_EQ("GET / HTTP/1.1\r\n", line);
373
[email protected]79e1fd62013-06-20 06:50:04374 HttpRequestHeaders request_headers;
375 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
376 std::string value;
377 EXPECT_TRUE(request_headers.GetHeader("Host", &value));
378 EXPECT_EQ("www.google.com", value);
379 EXPECT_TRUE(request_headers.GetHeader("Connection", &value));
380 EXPECT_EQ("keep-alive", value);
381
382 std::string response_headers;
383 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers));
384 EXPECT_EQ("['Host: www.google.com','Connection: keep-alive']",
385 response_headers);
[email protected]3deb9a52010-11-11 00:24:40386
[email protected]b8015c42013-12-24 15:18:19387 out.totalReceivedBytes = trans->GetTotalReceivedBytes();
[email protected]aecfbf22008-10-16 02:02:47388 return out;
[email protected]ff007e162009-05-23 09:13:15389 }
initial.commit586acc5fe2008-07-26 22:42:52390
[email protected]5a60c8b2011-10-19 20:14:29391 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[],
392 size_t reads_count) {
393 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0);
394 StaticSocketDataProvider* data[] = { &reads };
395 return SimpleGetHelperForData(data, 1);
396 }
397
[email protected]b8015c42013-12-24 15:18:19398 int64 ReadsSize(MockRead data_reads[], size_t reads_count) {
399 int64 size = 0;
400 for (size_t i = 0; i < reads_count; ++i)
401 size += data_reads[i].data_len;
402 return size;
403 }
404
[email protected]ff007e162009-05-23 09:13:15405 void ConnectStatusHelperWithExpectedStatus(const MockRead& status,
406 int expected_status);
initial.commit586acc5fe2008-07-26 22:42:52407
[email protected]ff007e162009-05-23 09:13:15408 void ConnectStatusHelper(const MockRead& status);
[email protected]bb88e1d32013-05-03 23:11:07409
410 void BypassHostCacheOnRefreshHelper(int load_flags);
411
412 void CheckErrorIsPassedBack(int error, IoMode mode);
413
[email protected]4bd46222013-05-14 19:32:23414 SpdyTestUtil spdy_util_;
[email protected]bb88e1d32013-05-03 23:11:07415 SpdySessionDependencies session_deps_;
[email protected]483fa202013-05-14 01:07:03416
417 // Original socket limits. Some tests set these. Safest to always restore
418 // them once each test has been run.
419 int old_max_group_sockets_;
420 int old_max_pool_sockets_;
[email protected]ff007e162009-05-23 09:13:15421};
[email protected]231d5a32008-09-13 00:45:27422
[email protected]23e482282013-06-14 16:08:02423INSTANTIATE_TEST_CASE_P(
424 NextProto,
425 HttpNetworkTransactionTest,
bnc33b8cef42014-11-19 17:30:38426 testing::Values(kProtoSPDY31, kProtoSPDY4_14, kProtoSPDY4_15));
[email protected]23e482282013-06-14 16:08:02427
[email protected]448d4ca52012-03-04 04:12:23428namespace {
429
[email protected]1826a402014-01-08 15:40:48430class BeforeNetworkStartHandler {
431 public:
432 explicit BeforeNetworkStartHandler(bool defer)
433 : defer_on_before_network_start_(defer),
434 observed_before_network_start_(false) {}
435
436 void OnBeforeNetworkStart(bool* defer) {
437 *defer = defer_on_before_network_start_;
438 observed_before_network_start_ = true;
439 }
440
441 bool observed_before_network_start() const {
442 return observed_before_network_start_;
443 }
444
445 private:
446 const bool defer_on_before_network_start_;
447 bool observed_before_network_start_;
448
449 DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler);
450};
451
[email protected]597a1ab2014-06-26 08:12:27452class BeforeProxyHeadersSentHandler {
453 public:
454 BeforeProxyHeadersSentHandler()
455 : observed_before_proxy_headers_sent_(false) {}
456
[email protected]1252d42f2014-07-01 21:20:20457 void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info,
458 HttpRequestHeaders* request_headers) {
[email protected]597a1ab2014-06-26 08:12:27459 observed_before_proxy_headers_sent_ = true;
460 observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI();
461 }
462
463 bool observed_before_proxy_headers_sent() const {
464 return observed_before_proxy_headers_sent_;
465 }
466
467 std::string observed_proxy_server_uri() const {
468 return observed_proxy_server_uri_;
469 }
470
471 private:
472 bool observed_before_proxy_headers_sent_;
473 std::string observed_proxy_server_uri_;
474
475 DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler);
476};
477
[email protected]15a5ccf82008-10-23 19:57:43478// Fill |str| with a long header list that consumes >= |size| bytes.
479void FillLargeHeadersString(std::string* str, int size) {
thestig9d3bb0c2015-01-24 00:49:51480 const char row[] =
[email protected]4ddaf2502008-10-23 18:26:19481 "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n";
482 const int sizeof_row = strlen(row);
483 const int num_rows = static_cast<int>(
484 ceil(static_cast<float>(size) / sizeof_row));
485 const int sizeof_data = num_rows * sizeof_row;
486 DCHECK(sizeof_data >= size);
[email protected]15a5ccf82008-10-23 19:57:43487 str->reserve(sizeof_data);
[email protected]372d34a2008-11-05 21:30:51488
[email protected]4ddaf2502008-10-23 18:26:19489 for (int i = 0; i < num_rows; ++i)
[email protected]15a5ccf82008-10-23 19:57:43490 str->append(row, sizeof_row);
[email protected]4ddaf2502008-10-23 18:26:19491}
492
[email protected]385a4672009-03-11 22:21:29493// Alternative functions that eliminate randomness and dependency on the local
494// host name so that the generated NTLM messages are reproducible.
[email protected]fe2bc6a2009-03-23 16:52:20495void MockGenerateRandom1(uint8* output, size_t n) {
[email protected]385a4672009-03-11 22:21:29496 static const uint8 bytes[] = {
497 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54
498 };
499 static size_t current_byte = 0;
500 for (size_t i = 0; i < n; ++i) {
501 output[i] = bytes[current_byte++];
502 current_byte %= arraysize(bytes);
503 }
504}
505
[email protected]fe2bc6a2009-03-23 16:52:20506void MockGenerateRandom2(uint8* output, size_t n) {
[email protected]385a4672009-03-11 22:21:29507 static const uint8 bytes[] = {
508 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1,
509 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f
510 };
511 static size_t current_byte = 0;
512 for (size_t i = 0; i < n; ++i) {
513 output[i] = bytes[current_byte++];
514 current_byte %= arraysize(bytes);
515 }
516}
517
[email protected]fe2bc6a2009-03-23 16:52:20518std::string MockGetHostName() {
519 return "WTC-WIN7";
[email protected]385a4672009-03-11 22:21:29520}
521
[email protected]e60e47a2010-07-14 03:37:18522template<typename ParentPool>
523class CaptureGroupNameSocketPool : public ParentPool {
[email protected]04e5be32009-06-26 20:00:31524 public:
[email protected]9e1bdd32011-02-03 21:48:34525 CaptureGroupNameSocketPool(HostResolver* host_resolver,
526 CertVerifier* cert_verifier);
[email protected]e60e47a2010-07-14 03:37:18527
[email protected]d80a4322009-08-14 07:07:49528 const std::string last_group_name_received() const {
529 return last_group_name_;
530 }
531
dmichaeld6e570d2014-12-18 22:30:57532 int RequestSocket(const std::string& group_name,
533 const void* socket_params,
534 RequestPriority priority,
535 ClientSocketHandle* handle,
536 const CompletionCallback& callback,
537 const BoundNetLog& net_log) override {
[email protected]04e5be32009-06-26 20:00:31538 last_group_name_ = group_name;
539 return ERR_IO_PENDING;
540 }
dmichaeld6e570d2014-12-18 22:30:57541 void CancelRequest(const std::string& group_name,
542 ClientSocketHandle* handle) override {}
543 void ReleaseSocket(const std::string& group_name,
544 scoped_ptr<StreamSocket> socket,
545 int id) override {}
546 void CloseIdleSockets() override {}
547 int IdleSocketCount() const override { return 0; }
548 int IdleSocketCountInGroup(const std::string& group_name) const override {
[email protected]04e5be32009-06-26 20:00:31549 return 0;
550 }
dmichaeld6e570d2014-12-18 22:30:57551 LoadState GetLoadState(const std::string& group_name,
552 const ClientSocketHandle* handle) const override {
[email protected]04e5be32009-06-26 20:00:31553 return LOAD_STATE_IDLE;
554 }
dmichaeld6e570d2014-12-18 22:30:57555 base::TimeDelta ConnectionTimeout() const override {
[email protected]a796bcec2010-03-22 17:17:26556 return base::TimeDelta();
557 }
[email protected]d80a4322009-08-14 07:07:49558
559 private:
[email protected]04e5be32009-06-26 20:00:31560 std::string last_group_name_;
561};
562
[email protected]ab739042011-04-07 15:22:28563typedef CaptureGroupNameSocketPool<TransportClientSocketPool>
564CaptureGroupNameTransportSocketPool;
[email protected]e772db3f2010-07-12 18:11:13565typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool>
566CaptureGroupNameHttpProxySocketPool;
[email protected]2d731a32010-04-29 01:04:06567typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool>
[email protected]2227c692010-05-04 15:36:11568CaptureGroupNameSOCKSSocketPool;
[email protected]e60e47a2010-07-14 03:37:18569typedef CaptureGroupNameSocketPool<SSLClientSocketPool>
570CaptureGroupNameSSLSocketPool;
571
572template<typename ParentPool>
573CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool(
[email protected]9e1bdd32011-02-03 21:48:34574 HostResolver* host_resolver,
575 CertVerifier* /* cert_verifier */)
576 : ParentPool(0, 0, NULL, host_resolver, NULL, NULL) {}
[email protected]e60e47a2010-07-14 03:37:18577
hashimoto0d3e4fb2015-01-09 05:02:50578template <>
[email protected]2df19bb2010-08-25 20:13:46579CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool(
hashimotodae13b02015-01-15 04:28:21580 HostResolver* /* host_resolver */,
[email protected]9e1bdd32011-02-03 21:48:34581 CertVerifier* /* cert_verifier */)
hashimotodae13b02015-01-15 04:28:21582 : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {
hashimoto0d3e4fb2015-01-09 05:02:50583}
[email protected]2df19bb2010-08-25 20:13:46584
[email protected]007b3f82013-04-09 08:46:45585template <>
[email protected]e60e47a2010-07-14 03:37:18586CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool(
hashimotodae13b02015-01-15 04:28:21587 HostResolver* /* host_resolver */,
[email protected]9e1bdd32011-02-03 21:48:34588 CertVerifier* cert_verifier)
[email protected]007b3f82013-04-09 08:46:45589 : SSLClientSocketPool(0,
590 0,
591 NULL,
[email protected]007b3f82013-04-09 08:46:45592 cert_verifier,
593 NULL,
594 NULL,
[email protected]284303b62013-11-28 15:11:54595 NULL,
eranm6571b2b2014-12-03 15:53:23596 NULL,
[email protected]007b3f82013-04-09 08:46:45597 std::string(),
598 NULL,
599 NULL,
600 NULL,
601 NULL,
602 NULL,
[email protected]8e458552014-08-05 00:02:15603 false,
604 NULL) {
605}
[email protected]2227c692010-05-04 15:36:11606
[email protected]231d5a32008-09-13 00:45:27607//-----------------------------------------------------------------------------
608
[email protected]79cb5c12011-09-12 13:12:04609// Helper functions for validating that AuthChallengeInfo's are correctly
610// configured for common cases.
611bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) {
612 if (!auth_challenge)
613 return false;
614 EXPECT_FALSE(auth_challenge->is_proxy);
615 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString());
616 EXPECT_EQ("MyRealm1", auth_challenge->realm);
617 EXPECT_EQ("basic", auth_challenge->scheme);
618 return true;
619}
620
621bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) {
622 if (!auth_challenge)
623 return false;
624 EXPECT_TRUE(auth_challenge->is_proxy);
625 EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString());
626 EXPECT_EQ("MyRealm1", auth_challenge->realm);
627 EXPECT_EQ("basic", auth_challenge->scheme);
628 return true;
629}
630
631bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) {
632 if (!auth_challenge)
633 return false;
634 EXPECT_FALSE(auth_challenge->is_proxy);
635 EXPECT_EQ("www.google.com:80", auth_challenge->challenger.ToString());
636 EXPECT_EQ("digestive", auth_challenge->realm);
637 EXPECT_EQ("digest", auth_challenge->scheme);
638 return true;
639}
640
641bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) {
642 if (!auth_challenge)
643 return false;
644 EXPECT_FALSE(auth_challenge->is_proxy);
645 EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString());
646 EXPECT_EQ(std::string(), auth_challenge->realm);
647 EXPECT_EQ("ntlm", auth_challenge->scheme);
648 return true;
649}
650
[email protected]448d4ca52012-03-04 04:12:23651} // namespace
652
[email protected]23e482282013-06-14 16:08:02653TEST_P(HttpNetworkTransactionTest, Basic) {
[email protected]3fe8d2f82013-10-17 08:56:07654 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d207a5f2009-06-04 05:28:40655 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:41656 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]231d5a32008-09-13 00:45:27657}
658
[email protected]23e482282013-06-14 16:08:02659TEST_P(HttpNetworkTransactionTest, SimpleGET) {
[email protected]231d5a32008-09-13 00:45:27660 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35661 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
662 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:06663 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27664 };
[email protected]31a2bfe2010-02-09 08:03:39665 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
666 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42667 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27668 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
669 EXPECT_EQ("hello world", out.response_data);
[email protected]b8015c42013-12-24 15:18:19670 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
671 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27672}
673
674// Response with no status line.
[email protected]23e482282013-06-14 16:08:02675TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) {
[email protected]231d5a32008-09-13 00:45:27676 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35677 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:06678 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27679 };
[email protected]31a2bfe2010-02-09 08:03:39680 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
681 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42682 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27683 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
684 EXPECT_EQ("hello world", out.response_data);
[email protected]b8015c42013-12-24 15:18:19685 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
686 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27687}
688
689// Allow up to 4 bytes of junk to precede status line.
[email protected]23e482282013-06-14 16:08:02690TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) {
[email protected]231d5a32008-09-13 00:45:27691 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35692 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
[email protected]8ddf8322012-02-23 18:08:06693 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27694 };
[email protected]31a2bfe2010-02-09 08:03:39695 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
696 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42697 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27698 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
699 EXPECT_EQ("DATA", out.response_data);
[email protected]b8015c42013-12-24 15:18:19700 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
701 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27702}
703
704// Allow up to 4 bytes of junk to precede status line.
[email protected]23e482282013-06-14 16:08:02705TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) {
[email protected]231d5a32008-09-13 00:45:27706 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35707 MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
[email protected]8ddf8322012-02-23 18:08:06708 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27709 };
[email protected]31a2bfe2010-02-09 08:03:39710 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
711 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42712 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27713 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
714 EXPECT_EQ("DATA", out.response_data);
[email protected]b8015c42013-12-24 15:18:19715 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
716 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27717}
718
719// Beyond 4 bytes of slop and it should fail to find a status line.
[email protected]23e482282013-06-14 16:08:02720TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) {
[email protected]231d5a32008-09-13 00:45:27721 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35722 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"),
[email protected]8ddf8322012-02-23 18:08:06723 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27724 };
[email protected]31a2bfe2010-02-09 08:03:39725 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
726 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42727 EXPECT_EQ(OK, out.rv);
[email protected]3d2a59b2008-09-26 19:44:25728 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
729 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data);
[email protected]b8015c42013-12-24 15:18:19730 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
731 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27732}
733
734// Same as StatusLineJunk4Bytes, except the read chunks are smaller.
[email protected]23e482282013-06-14 16:08:02735TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) {
[email protected]231d5a32008-09-13 00:45:27736 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35737 MockRead("\n"),
738 MockRead("\n"),
739 MockRead("Q"),
740 MockRead("J"),
741 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
[email protected]8ddf8322012-02-23 18:08:06742 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27743 };
[email protected]31a2bfe2010-02-09 08:03:39744 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
745 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42746 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27747 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
748 EXPECT_EQ("DATA", out.response_data);
[email protected]b8015c42013-12-24 15:18:19749 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
750 EXPECT_EQ(reads_size, out.totalReceivedBytes);
[email protected]231d5a32008-09-13 00:45:27751}
752
753// Close the connection before enough bytes to have a status line.
[email protected]23e482282013-06-14 16:08:02754TEST_P(HttpNetworkTransactionTest, StatusLinePartial) {
[email protected]231d5a32008-09-13 00:45:27755 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35756 MockRead("HTT"),
[email protected]8ddf8322012-02-23 18:08:06757 MockRead(SYNCHRONOUS, OK),
[email protected]231d5a32008-09-13 00:45:27758 };
[email protected]31a2bfe2010-02-09 08:03:39759 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
760 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42761 EXPECT_EQ(OK, out.rv);
[email protected]231d5a32008-09-13 00:45:27762 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
763 EXPECT_EQ("HTT", out.response_data);
[email protected]b8015c42013-12-24 15:18:19764 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
765 EXPECT_EQ(reads_size, out.totalReceivedBytes);
initial.commit586acc5fe2008-07-26 22:42:52766}
767
[email protected]f9d44aa2008-09-23 23:57:17768// Simulate a 204 response, lacking a Content-Length header, sent over a
769// persistent connection. The response should still terminate since a 204
770// cannot have a response body.
[email protected]23e482282013-06-14 16:08:02771TEST_P(HttpNetworkTransactionTest, StopsReading204) {
[email protected]b8015c42013-12-24 15:18:19772 char junk[] = "junk";
[email protected]f9d44aa2008-09-23 23:57:17773 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:35774 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
[email protected]b8015c42013-12-24 15:18:19775 MockRead(junk), // Should not be read!!
[email protected]8ddf8322012-02-23 18:08:06776 MockRead(SYNCHRONOUS, OK),
[email protected]f9d44aa2008-09-23 23:57:17777 };
[email protected]31a2bfe2010-02-09 08:03:39778 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
779 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:42780 EXPECT_EQ(OK, out.rv);
[email protected]f9d44aa2008-09-23 23:57:17781 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line);
782 EXPECT_EQ("", out.response_data);
[email protected]b8015c42013-12-24 15:18:19783 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
784 int64 response_size = reads_size - strlen(junk);
785 EXPECT_EQ(response_size, out.totalReceivedBytes);
[email protected]f9d44aa2008-09-23 23:57:17786}
787
[email protected]0877e3d2009-10-17 22:29:57788// A simple request using chunked encoding with some extra data after.
[email protected]23e482282013-06-14 16:08:02789TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) {
[email protected]b8015c42013-12-24 15:18:19790 std::string final_chunk = "0\r\n\r\n";
791 std::string extra_data = "HTTP/1.1 200 OK\r\n";
792 std::string last_read = final_chunk + extra_data;
[email protected]0877e3d2009-10-17 22:29:57793 MockRead data_reads[] = {
794 MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"),
795 MockRead("5\r\nHello\r\n"),
796 MockRead("1\r\n"),
797 MockRead(" \r\n"),
798 MockRead("5\r\nworld\r\n"),
[email protected]b8015c42013-12-24 15:18:19799 MockRead(last_read.data()),
[email protected]8ddf8322012-02-23 18:08:06800 MockRead(SYNCHRONOUS, OK),
[email protected]0877e3d2009-10-17 22:29:57801 };
[email protected]31a2bfe2010-02-09 08:03:39802 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
803 arraysize(data_reads));
[email protected]0877e3d2009-10-17 22:29:57804 EXPECT_EQ(OK, out.rv);
805 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
806 EXPECT_EQ("Hello world", out.response_data);
[email protected]b8015c42013-12-24 15:18:19807 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
808 int64 response_size = reads_size - extra_data.size();
809 EXPECT_EQ(response_size, out.totalReceivedBytes);
[email protected]0877e3d2009-10-17 22:29:57810}
811
[email protected]9fe44f52010-09-23 18:36:00812// Next tests deal with http://crbug.com/56344.
813
[email protected]23e482282013-06-14 16:08:02814TEST_P(HttpNetworkTransactionTest,
[email protected]9fe44f52010-09-23 18:36:00815 MultipleContentLengthHeadersNoTransferEncoding) {
816 MockRead data_reads[] = {
817 MockRead("HTTP/1.1 200 OK\r\n"),
818 MockRead("Content-Length: 10\r\n"),
819 MockRead("Content-Length: 5\r\n\r\n"),
820 };
821 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
822 arraysize(data_reads));
823 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv);
824}
825
[email protected]23e482282013-06-14 16:08:02826TEST_P(HttpNetworkTransactionTest,
[email protected]44b52042010-10-29 22:48:04827 DuplicateContentLengthHeadersNoTransferEncoding) {
828 MockRead data_reads[] = {
829 MockRead("HTTP/1.1 200 OK\r\n"),
830 MockRead("Content-Length: 5\r\n"),
831 MockRead("Content-Length: 5\r\n\r\n"),
832 MockRead("Hello"),
833 };
834 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
835 arraysize(data_reads));
836 EXPECT_EQ(OK, out.rv);
837 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
838 EXPECT_EQ("Hello", out.response_data);
839}
840
[email protected]23e482282013-06-14 16:08:02841TEST_P(HttpNetworkTransactionTest,
[email protected]44b52042010-10-29 22:48:04842 ComplexContentLengthHeadersNoTransferEncoding) {
843 // More than 2 dupes.
844 {
845 MockRead data_reads[] = {
846 MockRead("HTTP/1.1 200 OK\r\n"),
847 MockRead("Content-Length: 5\r\n"),
848 MockRead("Content-Length: 5\r\n"),
849 MockRead("Content-Length: 5\r\n\r\n"),
850 MockRead("Hello"),
851 };
852 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
853 arraysize(data_reads));
854 EXPECT_EQ(OK, out.rv);
855 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
856 EXPECT_EQ("Hello", out.response_data);
857 }
858 // HTTP/1.0
859 {
860 MockRead data_reads[] = {
861 MockRead("HTTP/1.0 200 OK\r\n"),
862 MockRead("Content-Length: 5\r\n"),
863 MockRead("Content-Length: 5\r\n"),
864 MockRead("Content-Length: 5\r\n\r\n"),
865 MockRead("Hello"),
866 };
867 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
868 arraysize(data_reads));
869 EXPECT_EQ(OK, out.rv);
870 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
871 EXPECT_EQ("Hello", out.response_data);
872 }
873 // 2 dupes and one mismatched.
874 {
875 MockRead data_reads[] = {
876 MockRead("HTTP/1.1 200 OK\r\n"),
877 MockRead("Content-Length: 10\r\n"),
878 MockRead("Content-Length: 10\r\n"),
879 MockRead("Content-Length: 5\r\n\r\n"),
880 };
881 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
882 arraysize(data_reads));
883 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv);
884 }
885}
886
[email protected]23e482282013-06-14 16:08:02887TEST_P(HttpNetworkTransactionTest,
[email protected]9fe44f52010-09-23 18:36:00888 MultipleContentLengthHeadersTransferEncoding) {
889 MockRead data_reads[] = {
890 MockRead("HTTP/1.1 200 OK\r\n"),
891 MockRead("Content-Length: 666\r\n"),
892 MockRead("Content-Length: 1337\r\n"),
893 MockRead("Transfer-Encoding: chunked\r\n\r\n"),
894 MockRead("5\r\nHello\r\n"),
895 MockRead("1\r\n"),
896 MockRead(" \r\n"),
897 MockRead("5\r\nworld\r\n"),
898 MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"),
[email protected]8ddf8322012-02-23 18:08:06899 MockRead(SYNCHRONOUS, OK),
[email protected]9fe44f52010-09-23 18:36:00900 };
901 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
902 arraysize(data_reads));
903 EXPECT_EQ(OK, out.rv);
904 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
905 EXPECT_EQ("Hello world", out.response_data);
906}
907
[email protected]1628fe92011-10-04 23:04:55908// Next tests deal with http://crbug.com/98895.
909
910// Checks that a single Content-Disposition header results in no error.
[email protected]23e482282013-06-14 16:08:02911TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) {
[email protected]1628fe92011-10-04 23:04:55912 MockRead data_reads[] = {
913 MockRead("HTTP/1.1 200 OK\r\n"),
914 MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"),
915 MockRead("Content-Length: 5\r\n\r\n"),
916 MockRead("Hello"),
917 };
918 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
919 arraysize(data_reads));
920 EXPECT_EQ(OK, out.rv);
921 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
922 EXPECT_EQ("Hello", out.response_data);
923}
924
[email protected]54a9c6e52012-03-21 20:10:59925// Checks that two identical Content-Disposition headers result in no error.
[email protected]23e482282013-06-14 16:08:02926TEST_P(HttpNetworkTransactionTest,
[email protected]54a9c6e52012-03-21 20:10:59927 TwoIdenticalContentDispositionHeaders) {
[email protected]1628fe92011-10-04 23:04:55928 MockRead data_reads[] = {
929 MockRead("HTTP/1.1 200 OK\r\n"),
930 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"),
931 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"),
932 MockRead("Content-Length: 5\r\n\r\n"),
933 MockRead("Hello"),
934 };
935 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
936 arraysize(data_reads));
[email protected]54a9c6e52012-03-21 20:10:59937 EXPECT_EQ(OK, out.rv);
938 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
939 EXPECT_EQ("Hello", out.response_data);
[email protected]1628fe92011-10-04 23:04:55940}
941
942// Checks that two distinct Content-Disposition headers result in an error.
[email protected]23e482282013-06-14 16:08:02943TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) {
[email protected]1628fe92011-10-04 23:04:55944 MockRead data_reads[] = {
945 MockRead("HTTP/1.1 200 OK\r\n"),
946 MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"),
947 MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"),
948 MockRead("Content-Length: 5\r\n\r\n"),
949 MockRead("Hello"),
950 };
951 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
952 arraysize(data_reads));
953 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv);
954}
955
[email protected]54a9c6e52012-03-21 20:10:59956// Checks that two identical Location headers result in no error.
957// Also tests Location header behavior.
[email protected]23e482282013-06-14 16:08:02958TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) {
[email protected]1628fe92011-10-04 23:04:55959 MockRead data_reads[] = {
960 MockRead("HTTP/1.1 302 Redirect\r\n"),
961 MockRead("Location: http://good.com/\r\n"),
[email protected]54a9c6e52012-03-21 20:10:59962 MockRead("Location: http://good.com/\r\n"),
[email protected]1628fe92011-10-04 23:04:55963 MockRead("Content-Length: 0\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:06964 MockRead(SYNCHRONOUS, OK),
[email protected]1628fe92011-10-04 23:04:55965 };
966
967 HttpRequestInfo request;
968 request.method = "GET";
969 request.url = GURL("http://redirect.com/");
970 request.load_flags = 0;
971
[email protected]3fe8d2f82013-10-17 08:56:07972 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]1628fe92011-10-04 23:04:55973 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:41974 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]1628fe92011-10-04 23:04:55975
976 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:07977 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1628fe92011-10-04 23:04:55978
[email protected]49639fa2011-12-20 23:22:41979 TestCompletionCallback callback;
[email protected]1628fe92011-10-04 23:04:55980
[email protected]49639fa2011-12-20 23:22:41981 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1628fe92011-10-04 23:04:55982 EXPECT_EQ(ERR_IO_PENDING, rv);
983
984 EXPECT_EQ(OK, callback.WaitForResult());
985
986 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]90499482013-06-01 00:39:50987 ASSERT_TRUE(response != NULL && response->headers.get() != NULL);
[email protected]1628fe92011-10-04 23:04:55988 EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine());
989 std::string url;
990 EXPECT_TRUE(response->headers->IsRedirect(&url));
991 EXPECT_EQ("http://good.com/", url);
[email protected]d8fc4722014-06-13 13:17:15992 EXPECT_TRUE(response->proxy_server.IsEmpty());
[email protected]1628fe92011-10-04 23:04:55993}
994
[email protected]1628fe92011-10-04 23:04:55995// Checks that two distinct Location headers result in an error.
[email protected]23e482282013-06-14 16:08:02996TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) {
[email protected]1628fe92011-10-04 23:04:55997 MockRead data_reads[] = {
998 MockRead("HTTP/1.1 302 Redirect\r\n"),
999 MockRead("Location: http://good.com/\r\n"),
1000 MockRead("Location: http://evil.com/\r\n"),
1001 MockRead("Content-Length: 0\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:061002 MockRead(SYNCHRONOUS, OK),
[email protected]1628fe92011-10-04 23:04:551003 };
1004 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
1005 arraysize(data_reads));
1006 EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv);
1007}
1008
[email protected]ef0faf2e72009-03-05 23:27:231009// Do a request using the HEAD method. Verify that we don't try to read the
1010// message body (since HEAD has none).
[email protected]23e482282013-06-14 16:08:021011TEST_P(HttpNetworkTransactionTest, Head) {
[email protected]1c773ea12009-04-28 19:58:421012 HttpRequestInfo request;
[email protected]ef0faf2e72009-03-05 23:27:231013 request.method = "HEAD";
1014 request.url = GURL("http://www.google.com/");
1015 request.load_flags = 0;
1016
[email protected]3fe8d2f82013-10-17 08:56:071017 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271018 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411019 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]597a1ab2014-06-26 08:12:271020 BeforeProxyHeadersSentHandler proxy_headers_handler;
1021 trans->SetBeforeProxyHeadersSentCallback(
1022 base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent,
1023 base::Unretained(&proxy_headers_handler)));
[email protected]cb9bf6ca2011-01-28 13:15:271024
[email protected]ef0faf2e72009-03-05 23:27:231025 MockWrite data_writes1[] = {
1026 MockWrite("HEAD / HTTP/1.1\r\n"
1027 "Host: www.google.com\r\n"
1028 "Connection: keep-alive\r\n"
1029 "Content-Length: 0\r\n\r\n"),
1030 };
1031 MockRead data_reads1[] = {
1032 MockRead("HTTP/1.1 404 Not Found\r\n"),
1033 MockRead("Server: Blah\r\n"),
1034 MockRead("Content-Length: 1234\r\n\r\n"),
1035
1036 // No response body because the test stops reading here.
[email protected]8ddf8322012-02-23 18:08:061037 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]ef0faf2e72009-03-05 23:27:231038 };
1039
[email protected]31a2bfe2010-02-09 08:03:391040 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1041 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:071042 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]ef0faf2e72009-03-05 23:27:231043
[email protected]49639fa2011-12-20 23:22:411044 TestCompletionCallback callback1;
[email protected]ef0faf2e72009-03-05 23:27:231045
[email protected]49639fa2011-12-20 23:22:411046 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421047 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]ef0faf2e72009-03-05 23:27:231048
1049 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421050 EXPECT_EQ(OK, rv);
[email protected]ef0faf2e72009-03-05 23:27:231051
[email protected]1c773ea12009-04-28 19:58:421052 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501053 ASSERT_TRUE(response != NULL);
[email protected]ef0faf2e72009-03-05 23:27:231054
1055 // Check that the headers got parsed.
[email protected]90499482013-06-01 00:39:501056 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]ef0faf2e72009-03-05 23:27:231057 EXPECT_EQ(1234, response->headers->GetContentLength());
1058 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine());
[email protected]d8fc4722014-06-13 13:17:151059 EXPECT_TRUE(response->proxy_server.IsEmpty());
[email protected]597a1ab2014-06-26 08:12:271060 EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent());
[email protected]ef0faf2e72009-03-05 23:27:231061
1062 std::string server_header;
1063 void* iter = NULL;
1064 bool has_server_header = response->headers->EnumerateHeader(
1065 &iter, "Server", &server_header);
1066 EXPECT_TRUE(has_server_header);
1067 EXPECT_EQ("Blah", server_header);
1068
1069 // Reading should give EOF right away, since there is no message body
1070 // (despite non-zero content-length).
1071 std::string response_data;
1072 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421073 EXPECT_EQ(OK, rv);
[email protected]ef0faf2e72009-03-05 23:27:231074 EXPECT_EQ("", response_data);
1075}
1076
[email protected]23e482282013-06-14 16:08:021077TEST_P(HttpNetworkTransactionTest, ReuseConnection) {
[email protected]bb88e1d32013-05-03 23:11:071078 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
initial.commit586acc5fe2008-07-26 22:42:521079
1080 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:351081 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1082 MockRead("hello"),
1083 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1084 MockRead("world"),
[email protected]8ddf8322012-02-23 18:08:061085 MockRead(SYNCHRONOUS, OK),
initial.commit586acc5fe2008-07-26 22:42:521086 };
[email protected]31a2bfe2010-02-09 08:03:391087 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071088 session_deps_.socket_factory->AddSocketDataProvider(&data);
initial.commit586acc5fe2008-07-26 22:42:521089
[email protected]0b0bf032010-09-21 18:08:501090 const char* const kExpectedResponseData[] = {
initial.commit586acc5fe2008-07-26 22:42:521091 "hello", "world"
1092 };
1093
1094 for (int i = 0; i < 2; ++i) {
[email protected]1c773ea12009-04-28 19:58:421095 HttpRequestInfo request;
initial.commit586acc5fe2008-07-26 22:42:521096 request.method = "GET";
1097 request.url = GURL("http://www.google.com/");
1098 request.load_flags = 0;
1099
[email protected]262eec82013-03-19 21:01:361100 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501101 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271102
[email protected]49639fa2011-12-20 23:22:411103 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:521104
[email protected]49639fa2011-12-20 23:22:411105 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421106 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:521107
1108 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421109 EXPECT_EQ(OK, rv);
initial.commit586acc5fe2008-07-26 22:42:521110
[email protected]1c773ea12009-04-28 19:58:421111 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501112 ASSERT_TRUE(response != NULL);
initial.commit586acc5fe2008-07-26 22:42:521113
[email protected]90499482013-06-01 00:39:501114 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3d2a59b2008-09-26 19:44:251115 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]d8fc4722014-06-13 13:17:151116 EXPECT_TRUE(response->proxy_server.IsEmpty());
initial.commit586acc5fe2008-07-26 22:42:521117
1118 std::string response_data;
[email protected]af4876d2008-10-21 23:10:571119 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421120 EXPECT_EQ(OK, rv);
[email protected]3d2a59b2008-09-26 19:44:251121 EXPECT_EQ(kExpectedResponseData[i], response_data);
initial.commit586acc5fe2008-07-26 22:42:521122 }
1123}
1124
[email protected]23e482282013-06-14 16:08:021125TEST_P(HttpNetworkTransactionTest, Ignores100) {
[email protected]b2d26cfd2012-12-11 10:36:061126 ScopedVector<UploadElementReader> element_readers;
1127 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:071128 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:271129
[email protected]1c773ea12009-04-28 19:58:421130 HttpRequestInfo request;
initial.commit586acc5fe2008-07-26 22:42:521131 request.method = "POST";
1132 request.url = GURL("http://www.foo.com/");
[email protected]329b68b2012-11-14 17:54:271133 request.upload_data_stream = &upload_data_stream;
initial.commit586acc5fe2008-07-26 22:42:521134 request.load_flags = 0;
1135
[email protected]3fe8d2f82013-10-17 08:56:071136 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271137 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411138 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271139
initial.commit586acc5fe2008-07-26 22:42:521140 MockRead data_reads[] = {
[email protected]217e6022008-09-29 18:18:351141 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
1142 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
1143 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061144 MockRead(SYNCHRONOUS, OK),
initial.commit586acc5fe2008-07-26 22:42:521145 };
[email protected]31a2bfe2010-02-09 08:03:391146 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071147 session_deps_.socket_factory->AddSocketDataProvider(&data);
initial.commit586acc5fe2008-07-26 22:42:521148
[email protected]49639fa2011-12-20 23:22:411149 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:521150
[email protected]49639fa2011-12-20 23:22:411151 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421152 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:521153
1154 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421155 EXPECT_EQ(OK, rv);
initial.commit586acc5fe2008-07-26 22:42:521156
[email protected]1c773ea12009-04-28 19:58:421157 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501158 ASSERT_TRUE(response != NULL);
initial.commit586acc5fe2008-07-26 22:42:521159
[email protected]90499482013-06-01 00:39:501160 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3d2a59b2008-09-26 19:44:251161 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
initial.commit586acc5fe2008-07-26 22:42:521162
1163 std::string response_data;
[email protected]af4876d2008-10-21 23:10:571164 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421165 EXPECT_EQ(OK, rv);
[email protected]3d2a59b2008-09-26 19:44:251166 EXPECT_EQ("hello world", response_data);
initial.commit586acc5fe2008-07-26 22:42:521167}
1168
[email protected]3a2d3662009-03-27 03:49:141169// This test is almost the same as Ignores100 above, but the response contains
1170// a 102 instead of a 100. Also, instead of HTTP/1.0 the response is
[email protected]0877e3d2009-10-17 22:29:571171// HTTP/1.1 and the two status headers are read in one read.
[email protected]23e482282013-06-14 16:08:021172TEST_P(HttpNetworkTransactionTest, Ignores1xx) {
[email protected]1c773ea12009-04-28 19:58:421173 HttpRequestInfo request;
[email protected]3a2d3662009-03-27 03:49:141174 request.method = "GET";
1175 request.url = GURL("http://www.foo.com/");
1176 request.load_flags = 0;
1177
[email protected]3fe8d2f82013-10-17 08:56:071178 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271179 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411180 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271181
[email protected]3a2d3662009-03-27 03:49:141182 MockRead data_reads[] = {
[email protected]0877e3d2009-10-17 22:29:571183 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"
1184 "HTTP/1.1 200 OK\r\n\r\n"),
[email protected]3a2d3662009-03-27 03:49:141185 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061186 MockRead(SYNCHRONOUS, OK),
[email protected]3a2d3662009-03-27 03:49:141187 };
[email protected]31a2bfe2010-02-09 08:03:391188 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071189 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3a2d3662009-03-27 03:49:141190
[email protected]49639fa2011-12-20 23:22:411191 TestCompletionCallback callback;
[email protected]3a2d3662009-03-27 03:49:141192
[email protected]49639fa2011-12-20 23:22:411193 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421194 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3a2d3662009-03-27 03:49:141195
1196 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421197 EXPECT_EQ(OK, rv);
[email protected]3a2d3662009-03-27 03:49:141198
[email protected]1c773ea12009-04-28 19:58:421199 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501200 ASSERT_TRUE(response != NULL);
[email protected]3a2d3662009-03-27 03:49:141201
[email protected]90499482013-06-01 00:39:501202 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3a2d3662009-03-27 03:49:141203 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1204
1205 std::string response_data;
1206 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421207 EXPECT_EQ(OK, rv);
[email protected]3a2d3662009-03-27 03:49:141208 EXPECT_EQ("hello world", response_data);
1209}
1210
[email protected]23e482282013-06-14 16:08:021211TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) {
[email protected]ee9410e72010-01-07 01:42:381212 HttpRequestInfo request;
1213 request.method = "POST";
1214 request.url = GURL("http://www.foo.com/");
1215 request.load_flags = 0;
1216
[email protected]3fe8d2f82013-10-17 08:56:071217 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271218 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411219 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271220
[email protected]ee9410e72010-01-07 01:42:381221 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061222 MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"),
1223 MockRead(ASYNC, 0),
[email protected]ee9410e72010-01-07 01:42:381224 };
[email protected]31a2bfe2010-02-09 08:03:391225 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071226 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]ee9410e72010-01-07 01:42:381227
[email protected]49639fa2011-12-20 23:22:411228 TestCompletionCallback callback;
[email protected]ee9410e72010-01-07 01:42:381229
[email protected]49639fa2011-12-20 23:22:411230 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]ee9410e72010-01-07 01:42:381231 EXPECT_EQ(ERR_IO_PENDING, rv);
1232
1233 rv = callback.WaitForResult();
1234 EXPECT_EQ(OK, rv);
1235
1236 std::string response_data;
1237 rv = ReadTransaction(trans.get(), &response_data);
1238 EXPECT_EQ(OK, rv);
1239 EXPECT_EQ("", response_data);
1240}
1241
[email protected]23e482282013-06-14 16:08:021242TEST_P(HttpNetworkTransactionTest, EmptyResponse) {
[email protected]ee9410e72010-01-07 01:42:381243 HttpRequestInfo request;
1244 request.method = "POST";
1245 request.url = GURL("http://www.foo.com/");
1246 request.load_flags = 0;
1247
[email protected]3fe8d2f82013-10-17 08:56:071248 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271249 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411250 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271251
[email protected]ee9410e72010-01-07 01:42:381252 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061253 MockRead(ASYNC, 0),
[email protected]ee9410e72010-01-07 01:42:381254 };
[email protected]31a2bfe2010-02-09 08:03:391255 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071256 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]ee9410e72010-01-07 01:42:381257
[email protected]49639fa2011-12-20 23:22:411258 TestCompletionCallback callback;
[email protected]ee9410e72010-01-07 01:42:381259
[email protected]49639fa2011-12-20 23:22:411260 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]ee9410e72010-01-07 01:42:381261 EXPECT_EQ(ERR_IO_PENDING, rv);
1262
1263 rv = callback.WaitForResult();
1264 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
1265}
1266
[email protected]23e482282013-06-14 16:08:021267void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
[email protected]202965992011-12-07 23:04:511268 const MockWrite* write_failure,
1269 const MockRead* read_failure) {
[email protected]1c773ea12009-04-28 19:58:421270 HttpRequestInfo request;
initial.commit586acc5fe2008-07-26 22:42:521271 request.method = "GET";
1272 request.url = GURL("http://www.foo.com/");
1273 request.load_flags = 0;
1274
[email protected]58e32bb2013-01-21 18:23:251275 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:071276 session_deps_.net_log = &net_log;
1277 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271278
[email protected]202965992011-12-07 23:04:511279 // Written data for successfully sending both requests.
1280 MockWrite data1_writes[] = {
1281 MockWrite("GET / HTTP/1.1\r\n"
1282 "Host: www.foo.com\r\n"
1283 "Connection: keep-alive\r\n\r\n"),
1284 MockWrite("GET / HTTP/1.1\r\n"
1285 "Host: www.foo.com\r\n"
1286 "Connection: keep-alive\r\n\r\n")
1287 };
1288
1289 // Read results for the first request.
initial.commit586acc5fe2008-07-26 22:42:521290 MockRead data1_reads[] = {
[email protected]217e6022008-09-29 18:18:351291 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1292 MockRead("hello"),
[email protected]8ddf8322012-02-23 18:08:061293 MockRead(ASYNC, OK),
initial.commit586acc5fe2008-07-26 22:42:521294 };
[email protected]202965992011-12-07 23:04:511295
1296 if (write_failure) {
[email protected]a34f61ee2014-03-18 20:59:491297 ASSERT_FALSE(read_failure);
[email protected]202965992011-12-07 23:04:511298 data1_writes[1] = *write_failure;
1299 } else {
1300 ASSERT_TRUE(read_failure);
1301 data1_reads[2] = *read_failure;
1302 }
1303
1304 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads),
1305 data1_writes, arraysize(data1_writes));
[email protected]bb88e1d32013-05-03 23:11:071306 session_deps_.socket_factory->AddSocketDataProvider(&data1);
initial.commit586acc5fe2008-07-26 22:42:521307
1308 MockRead data2_reads[] = {
[email protected]217e6022008-09-29 18:18:351309 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1310 MockRead("world"),
[email protected]8ddf8322012-02-23 18:08:061311 MockRead(ASYNC, OK),
initial.commit586acc5fe2008-07-26 22:42:521312 };
[email protected]31a2bfe2010-02-09 08:03:391313 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071314 session_deps_.socket_factory->AddSocketDataProvider(&data2);
initial.commit586acc5fe2008-07-26 22:42:521315
thestig9d3bb0c2015-01-24 00:49:511316 const char* const kExpectedResponseData[] = {
initial.commit586acc5fe2008-07-26 22:42:521317 "hello", "world"
1318 };
1319
[email protected]58e32bb2013-01-21 18:23:251320 uint32 first_socket_log_id = NetLog::Source::kInvalidId;
initial.commit586acc5fe2008-07-26 22:42:521321 for (int i = 0; i < 2; ++i) {
[email protected]49639fa2011-12-20 23:22:411322 TestCompletionCallback callback;
initial.commit586acc5fe2008-07-26 22:42:521323
[email protected]262eec82013-03-19 21:01:361324 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501325 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
initial.commit586acc5fe2008-07-26 22:42:521326
[email protected]49639fa2011-12-20 23:22:411327 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421328 EXPECT_EQ(ERR_IO_PENDING, rv);
initial.commit586acc5fe2008-07-26 22:42:521329
1330 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421331 EXPECT_EQ(OK, rv);
initial.commit586acc5fe2008-07-26 22:42:521332
[email protected]58e32bb2013-01-21 18:23:251333 LoadTimingInfo load_timing_info;
1334 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
1335 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
1336 if (i == 0) {
1337 first_socket_log_id = load_timing_info.socket_log_id;
1338 } else {
1339 // The second request should be using a new socket.
1340 EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id);
1341 }
1342
[email protected]1c773ea12009-04-28 19:58:421343 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501344 ASSERT_TRUE(response != NULL);
initial.commit586acc5fe2008-07-26 22:42:521345
[email protected]90499482013-06-01 00:39:501346 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]3d2a59b2008-09-26 19:44:251347 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
initial.commit586acc5fe2008-07-26 22:42:521348
1349 std::string response_data;
[email protected]af4876d2008-10-21 23:10:571350 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:421351 EXPECT_EQ(OK, rv);
[email protected]3d2a59b2008-09-26 19:44:251352 EXPECT_EQ(kExpectedResponseData[i], response_data);
initial.commit586acc5fe2008-07-26 22:42:521353 }
1354}
[email protected]3d2a59b2008-09-26 19:44:251355
[email protected]a34f61ee2014-03-18 20:59:491356void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest(
1357 const MockWrite* write_failure,
[email protected]09356c652014-03-25 15:36:101358 const MockRead* read_failure,
1359 bool use_spdy) {
[email protected]a34f61ee2014-03-18 20:59:491360 HttpRequestInfo request;
1361 request.method = "GET";
[email protected]09356c652014-03-25 15:36:101362 request.url = GURL("https://www.foo.com/");
[email protected]a34f61ee2014-03-18 20:59:491363 request.load_flags = 0;
1364
1365 CapturingNetLog net_log;
1366 session_deps_.net_log = &net_log;
1367 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1368
[email protected]09356c652014-03-25 15:36:101369 SSLSocketDataProvider ssl1(ASYNC, OK);
1370 SSLSocketDataProvider ssl2(ASYNC, OK);
1371 if (use_spdy) {
1372 ssl1.SetNextProto(GetParam());
1373 ssl2.SetNextProto(GetParam());
1374 }
1375 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1);
1376 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]a34f61ee2014-03-18 20:59:491377
[email protected]09356c652014-03-25 15:36:101378 // SPDY versions of the request and response.
1379 scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet(
1380 request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY));
1381 scoped_ptr<SpdyFrame> spdy_response(
1382 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
1383 scoped_ptr<SpdyFrame> spdy_data(
1384 spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true));
[email protected]a34f61ee2014-03-18 20:59:491385
[email protected]09356c652014-03-25 15:36:101386 // HTTP/1.1 versions of the request and response.
1387 const char kHttpRequest[] = "GET / HTTP/1.1\r\n"
1388 "Host: www.foo.com\r\n"
1389 "Connection: keep-alive\r\n\r\n";
1390 const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n";
1391 const char kHttpData[] = "hello";
1392
1393 std::vector<MockRead> data1_reads;
1394 std::vector<MockWrite> data1_writes;
[email protected]a34f61ee2014-03-18 20:59:491395 if (write_failure) {
1396 ASSERT_FALSE(read_failure);
[email protected]09356c652014-03-25 15:36:101397 data1_writes.push_back(*write_failure);
1398 data1_reads.push_back(MockRead(ASYNC, OK));
[email protected]a34f61ee2014-03-18 20:59:491399 } else {
1400 ASSERT_TRUE(read_failure);
[email protected]09356c652014-03-25 15:36:101401 if (use_spdy) {
1402 data1_writes.push_back(CreateMockWrite(*spdy_request));
1403 } else {
1404 data1_writes.push_back(MockWrite(kHttpRequest));
1405 }
1406 data1_reads.push_back(*read_failure);
[email protected]a34f61ee2014-03-18 20:59:491407 }
1408
[email protected]09356c652014-03-25 15:36:101409 StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(),
1410 &data1_writes[0], data1_writes.size());
[email protected]a34f61ee2014-03-18 20:59:491411 session_deps_.socket_factory->AddSocketDataProvider(&data1);
1412
[email protected]09356c652014-03-25 15:36:101413 std::vector<MockRead> data2_reads;
1414 std::vector<MockWrite> data2_writes;
1415
1416 if (use_spdy) {
1417 data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC));
1418
1419 data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC));
1420 data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC));
1421 data2_reads.push_back(MockRead(ASYNC, OK, 3));
1422 } else {
1423 data2_writes.push_back(
1424 MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0));
1425
1426 data2_reads.push_back(
1427 MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1));
1428 data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2));
1429 data2_reads.push_back(MockRead(ASYNC, OK, 3));
1430 }
1431 OrderedSocketData data2(&data2_reads[0], data2_reads.size(),
1432 &data2_writes[0], data2_writes.size());
[email protected]a34f61ee2014-03-18 20:59:491433 session_deps_.socket_factory->AddSocketDataProvider(&data2);
1434
1435 // Preconnect a socket.
1436 net::SSLConfig ssl_config;
1437 session->ssl_config_service()->GetSSLConfig(&ssl_config);
[email protected]d7599122014-05-24 03:37:231438 session->GetNextProtos(&ssl_config.next_protos);
[email protected]a34f61ee2014-03-18 20:59:491439 session->http_stream_factory()->PreconnectStreams(
1440 1, request, DEFAULT_PRIORITY, ssl_config, ssl_config);
1441 // Wait for the preconnect to complete.
1442 // TODO(davidben): Some way to wait for an idle socket count might be handy.
1443 base::RunLoop().RunUntilIdle();
[email protected]09356c652014-03-25 15:36:101444 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]a34f61ee2014-03-18 20:59:491445
1446 // Make the request.
1447 TestCompletionCallback callback;
1448
1449 scoped_ptr<HttpTransaction> trans(
1450 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1451
1452 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1453 EXPECT_EQ(ERR_IO_PENDING, rv);
1454
1455 rv = callback.WaitForResult();
1456 EXPECT_EQ(OK, rv);
1457
1458 LoadTimingInfo load_timing_info;
1459 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
[email protected]09356c652014-03-25 15:36:101460 TestLoadTimingNotReused(
1461 load_timing_info,
1462 CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]a34f61ee2014-03-18 20:59:491463
1464 const HttpResponseInfo* response = trans->GetResponseInfo();
1465 ASSERT_TRUE(response != NULL);
1466
1467 EXPECT_TRUE(response->headers.get() != NULL);
1468 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1469
1470 std::string response_data;
1471 rv = ReadTransaction(trans.get(), &response_data);
1472 EXPECT_EQ(OK, rv);
[email protected]09356c652014-03-25 15:36:101473 EXPECT_EQ(kHttpData, response_data);
[email protected]a34f61ee2014-03-18 20:59:491474}
1475
[email protected]23e482282013-06-14 16:08:021476TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:231477 KeepAliveConnectionNotConnectedOnWrite) {
[email protected]8ddf8322012-02-23 18:08:061478 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
[email protected]202965992011-12-07 23:04:511479 KeepAliveConnectionResendRequestTest(&write_failure, NULL);
1480}
1481
[email protected]23e482282013-06-14 16:08:021482TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
[email protected]8ddf8322012-02-23 18:08:061483 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
[email protected]202965992011-12-07 23:04:511484 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
[email protected]3d2a59b2008-09-26 19:44:251485}
1486
[email protected]23e482282013-06-14 16:08:021487TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
[email protected]8ddf8322012-02-23 18:08:061488 MockRead read_failure(SYNCHRONOUS, OK); // EOF
[email protected]202965992011-12-07 23:04:511489 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
[email protected]3d2a59b2008-09-26 19:44:251490}
1491
[email protected]d58ceea82014-06-04 10:55:541492// Make sure that on a 408 response (Request Timeout), the request is retried,
1493// if the socket was a reused keep alive socket.
1494TEST_P(HttpNetworkTransactionTest, KeepAlive408) {
1495 MockRead read_failure(SYNCHRONOUS,
1496 "HTTP/1.1 408 Request Timeout\r\n"
1497 "Connection: Keep-Alive\r\n"
1498 "Content-Length: 6\r\n\r\n"
1499 "Pickle");
1500 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
1501}
1502
[email protected]a34f61ee2014-03-18 20:59:491503TEST_P(HttpNetworkTransactionTest,
1504 PreconnectErrorNotConnectedOnWrite) {
1505 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
[email protected]09356c652014-03-25 15:36:101506 PreconnectErrorResendRequestTest(&write_failure, NULL, false);
[email protected]a34f61ee2014-03-18 20:59:491507}
1508
1509TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) {
1510 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
[email protected]09356c652014-03-25 15:36:101511 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
[email protected]a34f61ee2014-03-18 20:59:491512}
1513
1514TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) {
1515 MockRead read_failure(SYNCHRONOUS, OK); // EOF
[email protected]09356c652014-03-25 15:36:101516 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
1517}
1518
1519TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) {
1520 MockRead read_failure(ASYNC, OK); // EOF
1521 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
1522}
1523
[email protected]d58ceea82014-06-04 10:55:541524// Make sure that on a 408 response (Request Timeout), the request is retried,
1525// if the socket was a preconnected (UNUSED_IDLE) socket.
1526TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) {
1527 MockRead read_failure(SYNCHRONOUS,
1528 "HTTP/1.1 408 Request Timeout\r\n"
1529 "Connection: Keep-Alive\r\n"
1530 "Content-Length: 6\r\n\r\n"
1531 "Pickle");
1532 KeepAliveConnectionResendRequestTest(NULL, &read_failure);
1533 PreconnectErrorResendRequestTest(NULL, &read_failure, false);
1534}
1535
[email protected]09356c652014-03-25 15:36:101536TEST_P(HttpNetworkTransactionTest,
1537 SpdyPreconnectErrorNotConnectedOnWrite) {
1538 MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED);
1539 PreconnectErrorResendRequestTest(&write_failure, NULL, true);
1540}
1541
1542TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) {
1543 MockRead read_failure(ASYNC, ERR_CONNECTION_RESET);
1544 PreconnectErrorResendRequestTest(NULL, &read_failure, true);
1545}
1546
1547TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) {
1548 MockRead read_failure(SYNCHRONOUS, OK); // EOF
1549 PreconnectErrorResendRequestTest(NULL, &read_failure, true);
1550}
1551
1552TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) {
1553 MockRead read_failure(ASYNC, OK); // EOF
1554 PreconnectErrorResendRequestTest(NULL, &read_failure, true);
[email protected]a34f61ee2014-03-18 20:59:491555}
1556
[email protected]23e482282013-06-14 16:08:021557TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
[email protected]1c773ea12009-04-28 19:58:421558 HttpRequestInfo request;
[email protected]3d2a59b2008-09-26 19:44:251559 request.method = "GET";
1560 request.url = GURL("http://www.google.com/");
1561 request.load_flags = 0;
1562
[email protected]3fe8d2f82013-10-17 08:56:071563 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271564 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411565 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271566
[email protected]3d2a59b2008-09-26 19:44:251567 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061568 MockRead(ASYNC, ERR_CONNECTION_RESET),
[email protected]217e6022008-09-29 18:18:351569 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
1570 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061571 MockRead(SYNCHRONOUS, OK),
[email protected]3d2a59b2008-09-26 19:44:251572 };
[email protected]31a2bfe2010-02-09 08:03:391573 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071574 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3d2a59b2008-09-26 19:44:251575
[email protected]49639fa2011-12-20 23:22:411576 TestCompletionCallback callback;
[email protected]3d2a59b2008-09-26 19:44:251577
[email protected]49639fa2011-12-20 23:22:411578 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421579 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3d2a59b2008-09-26 19:44:251580
1581 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421582 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
[email protected]3d2a59b2008-09-26 19:44:251583
[email protected]1c773ea12009-04-28 19:58:421584 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]3d2a59b2008-09-26 19:44:251585 EXPECT_TRUE(response == NULL);
[email protected]3d2a59b2008-09-26 19:44:251586}
1587
1588// What do various browsers do when the server closes a non-keepalive
1589// connection without sending any response header or body?
1590//
1591// IE7: error page
1592// Safari 3.1.2 (Windows): error page
1593// Firefox 3.0.1: blank page
1594// Opera 9.52: after five attempts, blank page
[email protected]1c773ea12009-04-28 19:58:421595// Us with WinHTTP: error page (ERR_INVALID_RESPONSE)
1596// Us: error page (EMPTY_RESPONSE)
[email protected]23e482282013-06-14 16:08:021597TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) {
[email protected]3d2a59b2008-09-26 19:44:251598 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061599 MockRead(SYNCHRONOUS, OK), // EOF
[email protected]217e6022008-09-29 18:18:351600 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
1601 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:061602 MockRead(SYNCHRONOUS, OK),
[email protected]3d2a59b2008-09-26 19:44:251603 };
[email protected]31a2bfe2010-02-09 08:03:391604 SimpleGetHelperResult out = SimpleGetHelper(data_reads,
1605 arraysize(data_reads));
[email protected]1c773ea12009-04-28 19:58:421606 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv);
[email protected]3d2a59b2008-09-26 19:44:251607}
[email protected]038e9a32008-10-08 22:40:161608
[email protected]1826a402014-01-08 15:40:481609// Test that network access can be deferred and resumed.
1610TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) {
1611 HttpRequestInfo request;
1612 request.method = "GET";
1613 request.url = GURL("http://www.google.com/");
1614 request.load_flags = 0;
1615
1616 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1617 scoped_ptr<HttpTransaction> trans(
1618 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1619
1620 // Defer on OnBeforeNetworkStart.
1621 BeforeNetworkStartHandler net_start_handler(true); // defer
1622 trans->SetBeforeNetworkStartCallback(
1623 base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart,
1624 base::Unretained(&net_start_handler)));
1625
1626 MockRead data_reads[] = {
1627 MockRead("HTTP/1.0 200 OK\r\n"),
1628 MockRead("Content-Length: 5\r\n\r\n"),
1629 MockRead("hello"),
1630 MockRead(SYNCHRONOUS, 0),
1631 };
1632 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
1633 session_deps_.socket_factory->AddSocketDataProvider(&data);
1634
1635 TestCompletionCallback callback;
1636
1637 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1638 EXPECT_EQ(ERR_IO_PENDING, rv);
1639 base::MessageLoop::current()->RunUntilIdle();
1640
1641 // Should have deferred for network start.
1642 EXPECT_TRUE(net_start_handler.observed_before_network_start());
1643 EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState());
1644 EXPECT_TRUE(trans->GetResponseInfo() == NULL);
1645
1646 trans->ResumeNetworkStart();
1647 rv = callback.WaitForResult();
1648 EXPECT_EQ(OK, rv);
1649 EXPECT_TRUE(trans->GetResponseInfo() != NULL);
1650
1651 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100));
1652 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
1653 if (rv == ERR_IO_PENDING)
1654 rv = callback.WaitForResult();
1655 EXPECT_EQ(5, rv);
1656 trans.reset();
1657}
1658
1659// Test that network use can be deferred and canceled.
1660TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) {
1661 HttpRequestInfo request;
1662 request.method = "GET";
1663 request.url = GURL("http://www.google.com/");
1664 request.load_flags = 0;
1665
1666 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
1667 scoped_ptr<HttpTransaction> trans(
1668 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
1669
1670 // Defer on OnBeforeNetworkStart.
1671 BeforeNetworkStartHandler net_start_handler(true); // defer
1672 trans->SetBeforeNetworkStartCallback(
1673 base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart,
1674 base::Unretained(&net_start_handler)));
1675
1676 TestCompletionCallback callback;
1677
1678 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1679 EXPECT_EQ(ERR_IO_PENDING, rv);
1680 base::MessageLoop::current()->RunUntilIdle();
1681
1682 // Should have deferred for network start.
1683 EXPECT_TRUE(net_start_handler.observed_before_network_start());
1684 EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState());
1685 EXPECT_TRUE(trans->GetResponseInfo() == NULL);
1686}
1687
[email protected]7a5378b2012-11-04 03:25:171688// Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression
1689// tests. There was a bug causing HttpNetworkTransaction to hang in the
1690// destructor in such situations.
1691// See http://crbug.com/154712 and http://crbug.com/156609.
[email protected]23e482282013-06-14 16:08:021692TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) {
[email protected]7a5378b2012-11-04 03:25:171693 HttpRequestInfo request;
1694 request.method = "GET";
1695 request.url = GURL("http://www.google.com/");
1696 request.load_flags = 0;
1697
[email protected]bb88e1d32013-05-03 23:11:071698 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:361699 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501700 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7a5378b2012-11-04 03:25:171701
1702 MockRead data_reads[] = {
1703 MockRead("HTTP/1.0 200 OK\r\n"),
1704 MockRead("Connection: keep-alive\r\n"),
1705 MockRead("Content-Length: 100\r\n\r\n"),
1706 MockRead("hello"),
1707 MockRead(SYNCHRONOUS, 0),
1708 };
1709 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071710 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]7a5378b2012-11-04 03:25:171711
1712 TestCompletionCallback callback;
1713
1714 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1715 EXPECT_EQ(ERR_IO_PENDING, rv);
1716
1717 rv = callback.WaitForResult();
1718 EXPECT_EQ(OK, rv);
1719
1720 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100));
[email protected]90499482013-06-01 00:39:501721 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7a5378b2012-11-04 03:25:171722 if (rv == ERR_IO_PENDING)
1723 rv = callback.WaitForResult();
1724 EXPECT_EQ(5, rv);
[email protected]90499482013-06-01 00:39:501725 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7a5378b2012-11-04 03:25:171726 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv);
1727
1728 trans.reset();
[email protected]2da659e2013-05-23 20:51:341729 base::MessageLoop::current()->RunUntilIdle();
[email protected]7a5378b2012-11-04 03:25:171730 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
1731}
1732
[email protected]23e482282013-06-14 16:08:021733TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) {
[email protected]7a5378b2012-11-04 03:25:171734 HttpRequestInfo request;
1735 request.method = "GET";
1736 request.url = GURL("http://www.google.com/");
1737 request.load_flags = 0;
1738
[email protected]bb88e1d32013-05-03 23:11:071739 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:361740 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501741 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7a5378b2012-11-04 03:25:171742
1743 MockRead data_reads[] = {
1744 MockRead("HTTP/1.0 200 OK\r\n"),
1745 MockRead("Connection: keep-alive\r\n"),
1746 MockRead("Content-Length: 100\r\n\r\n"),
1747 MockRead(SYNCHRONOUS, 0),
1748 };
1749 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071750 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]7a5378b2012-11-04 03:25:171751
1752 TestCompletionCallback callback;
1753
1754 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
1755 EXPECT_EQ(ERR_IO_PENDING, rv);
1756
1757 rv = callback.WaitForResult();
1758 EXPECT_EQ(OK, rv);
1759
1760 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100));
[email protected]90499482013-06-01 00:39:501761 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7a5378b2012-11-04 03:25:171762 if (rv == ERR_IO_PENDING)
1763 rv = callback.WaitForResult();
1764 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv);
1765
1766 trans.reset();
[email protected]2da659e2013-05-23 20:51:341767 base::MessageLoop::current()->RunUntilIdle();
[email protected]7a5378b2012-11-04 03:25:171768 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
1769}
1770
[email protected]0b0bf032010-09-21 18:08:501771// Test that we correctly reuse a keep-alive connection after not explicitly
1772// reading the body.
[email protected]23e482282013-06-14 16:08:021773TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) {
[email protected]fc31d6a42010-06-24 18:05:131774 HttpRequestInfo request;
1775 request.method = "GET";
1776 request.url = GURL("http://www.foo.com/");
1777 request.load_flags = 0;
1778
[email protected]58e32bb2013-01-21 18:23:251779 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:071780 session_deps_.net_log = &net_log;
1781 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271782
[email protected]0b0bf032010-09-21 18:08:501783 // Note that because all these reads happen in the same
1784 // StaticSocketDataProvider, it shows that the same socket is being reused for
1785 // all transactions.
[email protected]fc31d6a42010-06-24 18:05:131786 MockRead data1_reads[] = {
[email protected]0b0bf032010-09-21 18:08:501787 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
1788 MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"),
[email protected]fc31d6a42010-06-24 18:05:131789 MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"),
[email protected]0b0bf032010-09-21 18:08:501790 MockRead("HTTP/1.1 302 Found\r\n"
1791 "Content-Length: 0\r\n\r\n"),
1792 MockRead("HTTP/1.1 302 Found\r\n"
1793 "Content-Length: 5\r\n\r\n"
1794 "hello"),
1795 MockRead("HTTP/1.1 301 Moved Permanently\r\n"
1796 "Content-Length: 0\r\n\r\n"),
1797 MockRead("HTTP/1.1 301 Moved Permanently\r\n"
1798 "Content-Length: 5\r\n\r\n"
1799 "hello"),
[email protected]fc31d6a42010-06-24 18:05:131800 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
1801 MockRead("hello"),
1802 };
1803 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071804 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]fc31d6a42010-06-24 18:05:131805
1806 MockRead data2_reads[] = {
[email protected]8ddf8322012-02-23 18:08:061807 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]fc31d6a42010-06-24 18:05:131808 };
1809 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:071810 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]fc31d6a42010-06-24 18:05:131811
[email protected]0b0bf032010-09-21 18:08:501812 const int kNumUnreadBodies = arraysize(data1_reads) - 2;
1813 std::string response_lines[kNumUnreadBodies];
1814
[email protected]58e32bb2013-01-21 18:23:251815 uint32 first_socket_log_id = NetLog::Source::kInvalidId;
[email protected]0b0bf032010-09-21 18:08:501816 for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) {
[email protected]49639fa2011-12-20 23:22:411817 TestCompletionCallback callback;
[email protected]fc31d6a42010-06-24 18:05:131818
[email protected]262eec82013-03-19 21:01:361819 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501820 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]fc31d6a42010-06-24 18:05:131821
[email protected]49639fa2011-12-20 23:22:411822 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]fc31d6a42010-06-24 18:05:131823 EXPECT_EQ(ERR_IO_PENDING, rv);
1824
1825 rv = callback.WaitForResult();
1826 EXPECT_EQ(OK, rv);
1827
[email protected]58e32bb2013-01-21 18:23:251828 LoadTimingInfo load_timing_info;
1829 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
1830 if (i == 0) {
1831 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
1832 first_socket_log_id = load_timing_info.socket_log_id;
1833 } else {
1834 TestLoadTimingReused(load_timing_info);
1835 EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id);
1836 }
1837
[email protected]fc31d6a42010-06-24 18:05:131838 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]0b0bf032010-09-21 18:08:501839 ASSERT_TRUE(response != NULL);
[email protected]fc31d6a42010-06-24 18:05:131840
[email protected]90499482013-06-01 00:39:501841 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]0b0bf032010-09-21 18:08:501842 response_lines[i] = response->headers->GetStatusLine();
1843
1844 // We intentionally don't read the response bodies.
[email protected]fc31d6a42010-06-24 18:05:131845 }
[email protected]0b0bf032010-09-21 18:08:501846
1847 const char* const kStatusLines[] = {
1848 "HTTP/1.1 204 No Content",
1849 "HTTP/1.1 205 Reset Content",
1850 "HTTP/1.1 304 Not Modified",
1851 "HTTP/1.1 302 Found",
1852 "HTTP/1.1 302 Found",
1853 "HTTP/1.1 301 Moved Permanently",
1854 "HTTP/1.1 301 Moved Permanently",
1855 };
1856
mostynb91e0da982015-01-20 19:17:271857 static_assert(kNumUnreadBodies == arraysize(kStatusLines),
1858 "forgot to update kStatusLines");
[email protected]0b0bf032010-09-21 18:08:501859
1860 for (int i = 0; i < kNumUnreadBodies; ++i)
1861 EXPECT_EQ(kStatusLines[i], response_lines[i]);
1862
[email protected]49639fa2011-12-20 23:22:411863 TestCompletionCallback callback;
[email protected]262eec82013-03-19 21:01:361864 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:501865 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:411866 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0b0bf032010-09-21 18:08:501867 EXPECT_EQ(ERR_IO_PENDING, rv);
1868 rv = callback.WaitForResult();
1869 EXPECT_EQ(OK, rv);
1870 const HttpResponseInfo* response = trans->GetResponseInfo();
1871 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:501872 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]0b0bf032010-09-21 18:08:501873 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1874 std::string response_data;
1875 rv = ReadTransaction(trans.get(), &response_data);
1876 EXPECT_EQ(OK, rv);
1877 EXPECT_EQ("hello", response_data);
[email protected]fc31d6a42010-06-24 18:05:131878}
1879
[email protected]038e9a32008-10-08 22:40:161880// Test the request-challenge-retry sequence for basic auth.
1881// (basic auth is the easiest to mock, because it has no randomness).
[email protected]23e482282013-06-14 16:08:021882TEST_P(HttpNetworkTransactionTest, BasicAuth) {
[email protected]1c773ea12009-04-28 19:58:421883 HttpRequestInfo request;
[email protected]038e9a32008-10-08 22:40:161884 request.method = "GET";
1885 request.url = GURL("http://www.google.com/");
1886 request.load_flags = 0;
1887
[email protected]58e32bb2013-01-21 18:23:251888 CapturingNetLog log;
[email protected]bb88e1d32013-05-03 23:11:071889 session_deps_.net_log = &log;
[email protected]3fe8d2f82013-10-17 08:56:071890 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271891 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411892 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271893
[email protected]f9ee6b52008-11-08 06:46:231894 MockWrite data_writes1[] = {
1895 MockWrite("GET / HTTP/1.1\r\n"
1896 "Host: www.google.com\r\n"
1897 "Connection: keep-alive\r\n\r\n"),
1898 };
1899
[email protected]038e9a32008-10-08 22:40:161900 MockRead data_reads1[] = {
1901 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
1902 // Give a couple authenticate options (only the middle one is actually
1903 // supported).
[email protected]22927ad2009-09-21 19:56:191904 MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed.
[email protected]038e9a32008-10-08 22:40:161905 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1906 MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"),
1907 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1908 // Large content-length -- won't matter, as connection will be reset.
1909 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:061910 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]038e9a32008-10-08 22:40:161911 };
1912
1913 // After calling trans->RestartWithAuth(), this is the request we should
1914 // be issuing -- the final header line contains the credentials.
1915 MockWrite data_writes2[] = {
1916 MockWrite("GET / HTTP/1.1\r\n"
1917 "Host: www.google.com\r\n"
1918 "Connection: keep-alive\r\n"
1919 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
1920 };
1921
1922 // Lastly, the server responds with the actual content.
1923 MockRead data_reads2[] = {
1924 MockRead("HTTP/1.0 200 OK\r\n"),
1925 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1926 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:061927 MockRead(SYNCHRONOUS, OK),
[email protected]038e9a32008-10-08 22:40:161928 };
1929
[email protected]31a2bfe2010-02-09 08:03:391930 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1931 data_writes1, arraysize(data_writes1));
1932 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
1933 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:071934 session_deps_.socket_factory->AddSocketDataProvider(&data1);
1935 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]038e9a32008-10-08 22:40:161936
[email protected]49639fa2011-12-20 23:22:411937 TestCompletionCallback callback1;
[email protected]038e9a32008-10-08 22:40:161938
[email protected]49639fa2011-12-20 23:22:411939 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:421940 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:161941
1942 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421943 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:161944
[email protected]58e32bb2013-01-21 18:23:251945 LoadTimingInfo load_timing_info1;
1946 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1));
1947 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES);
1948
[email protected]b8015c42013-12-24 15:18:191949 int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1));
1950 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes());
1951
[email protected]1c773ea12009-04-28 19:58:421952 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501953 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:041954 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]038e9a32008-10-08 22:40:161955
[email protected]49639fa2011-12-20 23:22:411956 TestCompletionCallback callback2;
[email protected]038e9a32008-10-08 22:40:161957
[email protected]49639fa2011-12-20 23:22:411958 rv = trans->RestartWithAuth(
1959 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:421960 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:161961
1962 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:421963 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:161964
[email protected]58e32bb2013-01-21 18:23:251965 LoadTimingInfo load_timing_info2;
1966 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2));
1967 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES);
1968 // The load timing after restart should have a new socket ID, and times after
1969 // those of the first load timing.
1970 EXPECT_LE(load_timing_info1.receive_headers_end,
1971 load_timing_info2.connect_timing.connect_start);
1972 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
1973
[email protected]b8015c42013-12-24 15:18:191974 int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2));
1975 EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes());
1976
[email protected]038e9a32008-10-08 22:40:161977 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:501978 ASSERT_TRUE(response != NULL);
[email protected]038e9a32008-10-08 22:40:161979 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1980 EXPECT_EQ(100, response->headers->GetContentLength());
[email protected]038e9a32008-10-08 22:40:161981}
1982
[email protected]23e482282013-06-14 16:08:021983TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) {
[email protected]861fcd52009-08-26 02:33:461984 HttpRequestInfo request;
1985 request.method = "GET";
1986 request.url = GURL("http://www.google.com/");
1987 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1988
[email protected]3fe8d2f82013-10-17 08:56:071989 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:271990 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:411991 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:271992
[email protected]861fcd52009-08-26 02:33:461993 MockWrite data_writes[] = {
1994 MockWrite("GET / HTTP/1.1\r\n"
1995 "Host: www.google.com\r\n"
1996 "Connection: keep-alive\r\n\r\n"),
1997 };
1998
1999 MockRead data_reads[] = {
2000 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
2001 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2002 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2003 // Large content-length -- won't matter, as connection will be reset.
2004 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062005 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]861fcd52009-08-26 02:33:462006 };
2007
[email protected]31a2bfe2010-02-09 08:03:392008 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
2009 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:072010 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]49639fa2011-12-20 23:22:412011 TestCompletionCallback callback;
[email protected]861fcd52009-08-26 02:33:462012
[email protected]49639fa2011-12-20 23:22:412013 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]861fcd52009-08-26 02:33:462014 EXPECT_EQ(ERR_IO_PENDING, rv);
2015
2016 rv = callback.WaitForResult();
2017 EXPECT_EQ(0, rv);
2018
[email protected]b8015c42013-12-24 15:18:192019 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads));
2020 EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes());
2021
[email protected]861fcd52009-08-26 02:33:462022 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502023 ASSERT_TRUE(response != NULL);
[email protected]861fcd52009-08-26 02:33:462024 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2025}
2026
[email protected]2d2697f92009-02-18 21:00:322027// Test the request-challenge-retry sequence for basic auth, over a keep-alive
2028// connection.
[email protected]23e482282013-06-14 16:08:022029TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) {
[email protected]1c773ea12009-04-28 19:58:422030 HttpRequestInfo request;
[email protected]2d2697f92009-02-18 21:00:322031 request.method = "GET";
2032 request.url = GURL("http://www.google.com/");
2033 request.load_flags = 0;
2034
[email protected]58e32bb2013-01-21 18:23:252035 CapturingNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072036 session_deps_.net_log = &log;
2037 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272038
[email protected]2d2697f92009-02-18 21:00:322039 MockWrite data_writes1[] = {
2040 MockWrite("GET / HTTP/1.1\r\n"
2041 "Host: www.google.com\r\n"
2042 "Connection: keep-alive\r\n\r\n"),
2043
2044 // After calling trans->RestartWithAuth(), this is the request we should
2045 // be issuing -- the final header line contains the credentials.
2046 MockWrite("GET / HTTP/1.1\r\n"
2047 "Host: www.google.com\r\n"
2048 "Connection: keep-alive\r\n"
2049 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2050 };
2051
2052 MockRead data_reads1[] = {
2053 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2054 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2055 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2056 MockRead("Content-Length: 14\r\n\r\n"),
2057 MockRead("Unauthorized\r\n"),
2058
2059 // Lastly, the server responds with the actual content.
2060 MockRead("HTTP/1.1 200 OK\r\n"),
2061 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502062 MockRead("Content-Length: 5\r\n\r\n"),
2063 MockRead("Hello"),
[email protected]2d2697f92009-02-18 21:00:322064 };
2065
[email protected]2d0a4f92011-05-05 16:38:462066 // If there is a regression where we disconnect a Keep-Alive
2067 // connection during an auth roundtrip, we'll end up reading this.
2068 MockRead data_reads2[] = {
[email protected]8ddf8322012-02-23 18:08:062069 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]2d0a4f92011-05-05 16:38:462070 };
2071
[email protected]31a2bfe2010-02-09 08:03:392072 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2073 data_writes1, arraysize(data_writes1));
[email protected]2d0a4f92011-05-05 16:38:462074 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2075 NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:072076 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2077 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]2d2697f92009-02-18 21:00:322078
[email protected]49639fa2011-12-20 23:22:412079 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322080
[email protected]262eec82013-03-19 21:01:362081 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502082 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412083 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422084 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322085
2086 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422087 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322088
[email protected]58e32bb2013-01-21 18:23:252089 LoadTimingInfo load_timing_info1;
2090 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1));
2091 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES);
2092
[email protected]1c773ea12009-04-28 19:58:422093 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502094 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042095 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322096
[email protected]49639fa2011-12-20 23:22:412097 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322098
[email protected]49639fa2011-12-20 23:22:412099 rv = trans->RestartWithAuth(
2100 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422101 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322102
2103 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422104 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322105
[email protected]58e32bb2013-01-21 18:23:252106 LoadTimingInfo load_timing_info2;
2107 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2));
2108 TestLoadTimingReused(load_timing_info2);
2109 // The load timing after restart should have the same socket ID, and times
2110 // those of the first load timing.
2111 EXPECT_LE(load_timing_info1.receive_headers_end,
2112 load_timing_info2.send_start);
2113 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
2114
[email protected]2d2697f92009-02-18 21:00:322115 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502116 ASSERT_TRUE(response != NULL);
[email protected]2d2697f92009-02-18 21:00:322117 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502118 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]b8015c42013-12-24 15:18:192119
2120 std::string response_data;
2121 rv = ReadTransaction(trans.get(), &response_data);
2122 EXPECT_EQ(OK, rv);
2123 int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1));
2124 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes());
[email protected]2d2697f92009-02-18 21:00:322125}
2126
2127// Test the request-challenge-retry sequence for basic auth, over a keep-alive
2128// connection and with no response body to drain.
[email protected]23e482282013-06-14 16:08:022129TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) {
[email protected]1c773ea12009-04-28 19:58:422130 HttpRequestInfo request;
[email protected]2d2697f92009-02-18 21:00:322131 request.method = "GET";
2132 request.url = GURL("http://www.google.com/");
2133 request.load_flags = 0;
2134
[email protected]bb88e1d32013-05-03 23:11:072135 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272136
[email protected]2d2697f92009-02-18 21:00:322137 MockWrite data_writes1[] = {
2138 MockWrite("GET / HTTP/1.1\r\n"
2139 "Host: www.google.com\r\n"
2140 "Connection: keep-alive\r\n\r\n"),
2141
2142 // After calling trans->RestartWithAuth(), this is the request we should
2143 // be issuing -- the final header line contains the credentials.
2144 MockWrite("GET / HTTP/1.1\r\n"
2145 "Host: www.google.com\r\n"
2146 "Connection: keep-alive\r\n"
2147 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2148 };
2149
[email protected]2d2697f92009-02-18 21:00:322150 MockRead data_reads1[] = {
2151 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2152 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
[email protected]11203f012009-11-12 23:02:312153 MockRead("Content-Length: 0\r\n\r\n"), // No response body.
[email protected]2d2697f92009-02-18 21:00:322154
2155 // Lastly, the server responds with the actual content.
2156 MockRead("HTTP/1.1 200 OK\r\n"),
2157 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502158 MockRead("Content-Length: 5\r\n\r\n"),
2159 MockRead("hello"),
[email protected]2d2697f92009-02-18 21:00:322160 };
2161
[email protected]2d0a4f92011-05-05 16:38:462162 // An incorrect reconnect would cause this to be read.
2163 MockRead data_reads2[] = {
[email protected]8ddf8322012-02-23 18:08:062164 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]2d0a4f92011-05-05 16:38:462165 };
2166
[email protected]31a2bfe2010-02-09 08:03:392167 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2168 data_writes1, arraysize(data_writes1));
[email protected]2d0a4f92011-05-05 16:38:462169 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2170 NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:072171 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2172 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]2d2697f92009-02-18 21:00:322173
[email protected]49639fa2011-12-20 23:22:412174 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322175
[email protected]262eec82013-03-19 21:01:362176 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502177 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412178 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422179 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322180
2181 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422182 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322183
[email protected]1c773ea12009-04-28 19:58:422184 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502185 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042186 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322187
[email protected]49639fa2011-12-20 23:22:412188 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322189
[email protected]49639fa2011-12-20 23:22:412190 rv = trans->RestartWithAuth(
2191 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422192 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322193
2194 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422195 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322196
2197 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502198 ASSERT_TRUE(response != NULL);
[email protected]2d2697f92009-02-18 21:00:322199 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502200 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]2d2697f92009-02-18 21:00:322201}
2202
2203// Test the request-challenge-retry sequence for basic auth, over a keep-alive
2204// connection and with a large response body to drain.
[email protected]23e482282013-06-14 16:08:022205TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) {
[email protected]1c773ea12009-04-28 19:58:422206 HttpRequestInfo request;
[email protected]2d2697f92009-02-18 21:00:322207 request.method = "GET";
2208 request.url = GURL("http://www.google.com/");
2209 request.load_flags = 0;
2210
[email protected]bb88e1d32013-05-03 23:11:072211 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272212
[email protected]2d2697f92009-02-18 21:00:322213 MockWrite data_writes1[] = {
2214 MockWrite("GET / HTTP/1.1\r\n"
2215 "Host: www.google.com\r\n"
2216 "Connection: keep-alive\r\n\r\n"),
2217
2218 // After calling trans->RestartWithAuth(), this is the request we should
2219 // be issuing -- the final header line contains the credentials.
2220 MockWrite("GET / HTTP/1.1\r\n"
2221 "Host: www.google.com\r\n"
2222 "Connection: keep-alive\r\n"
2223 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2224 };
2225
2226 // Respond with 5 kb of response body.
2227 std::string large_body_string("Unauthorized");
2228 large_body_string.append(5 * 1024, ' ');
2229 large_body_string.append("\r\n");
2230
2231 MockRead data_reads1[] = {
2232 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2233 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2234 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2235 // 5134 = 12 + 5 * 1024 + 2
2236 MockRead("Content-Length: 5134\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062237 MockRead(ASYNC, large_body_string.data(), large_body_string.size()),
[email protected]2d2697f92009-02-18 21:00:322238
2239 // Lastly, the server responds with the actual content.
2240 MockRead("HTTP/1.1 200 OK\r\n"),
2241 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502242 MockRead("Content-Length: 5\r\n\r\n"),
2243 MockRead("hello"),
[email protected]2d2697f92009-02-18 21:00:322244 };
2245
[email protected]2d0a4f92011-05-05 16:38:462246 // An incorrect reconnect would cause this to be read.
2247 MockRead data_reads2[] = {
[email protected]8ddf8322012-02-23 18:08:062248 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]2d0a4f92011-05-05 16:38:462249 };
2250
[email protected]31a2bfe2010-02-09 08:03:392251 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2252 data_writes1, arraysize(data_writes1));
[email protected]2d0a4f92011-05-05 16:38:462253 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2254 NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:072255 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2256 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]2d2697f92009-02-18 21:00:322257
[email protected]49639fa2011-12-20 23:22:412258 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322259
[email protected]262eec82013-03-19 21:01:362260 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502261 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412262 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422263 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322264
2265 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422266 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322267
[email protected]1c773ea12009-04-28 19:58:422268 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502269 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042270 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322271
[email protected]49639fa2011-12-20 23:22:412272 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322273
[email protected]49639fa2011-12-20 23:22:412274 rv = trans->RestartWithAuth(
2275 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422276 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322277
2278 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422279 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322280
2281 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502282 ASSERT_TRUE(response != NULL);
[email protected]2d2697f92009-02-18 21:00:322283 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502284 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]2d2697f92009-02-18 21:00:322285}
2286
2287// Test the request-challenge-retry sequence for basic auth, over a keep-alive
[email protected]11203f012009-11-12 23:02:312288// connection, but the server gets impatient and closes the connection.
[email protected]23e482282013-06-14 16:08:022289TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) {
[email protected]11203f012009-11-12 23:02:312290 HttpRequestInfo request;
2291 request.method = "GET";
2292 request.url = GURL("http://www.google.com/");
2293 request.load_flags = 0;
2294
[email protected]bb88e1d32013-05-03 23:11:072295 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272296
[email protected]11203f012009-11-12 23:02:312297 MockWrite data_writes1[] = {
2298 MockWrite("GET / HTTP/1.1\r\n"
2299 "Host: www.google.com\r\n"
2300 "Connection: keep-alive\r\n\r\n"),
2301 // This simulates the seemingly successful write to a closed connection
2302 // if the bug is not fixed.
2303 MockWrite("GET / HTTP/1.1\r\n"
2304 "Host: www.google.com\r\n"
2305 "Connection: keep-alive\r\n"
2306 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2307 };
2308
2309 MockRead data_reads1[] = {
2310 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
2311 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2312 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
2313 MockRead("Content-Length: 14\r\n\r\n"),
2314 // Tell MockTCPClientSocket to simulate the server closing the connection.
[email protected]8ddf8322012-02-23 18:08:062315 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]11203f012009-11-12 23:02:312316 MockRead("Unauthorized\r\n"),
[email protected]8ddf8322012-02-23 18:08:062317 MockRead(SYNCHRONOUS, OK), // The server closes the connection.
[email protected]11203f012009-11-12 23:02:312318 };
2319
2320 // After calling trans->RestartWithAuth(), this is the request we should
2321 // be issuing -- the final header line contains the credentials.
2322 MockWrite data_writes2[] = {
2323 MockWrite("GET / HTTP/1.1\r\n"
2324 "Host: www.google.com\r\n"
2325 "Connection: keep-alive\r\n"
2326 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2327 };
2328
2329 // Lastly, the server responds with the actual content.
2330 MockRead data_reads2[] = {
2331 MockRead("HTTP/1.1 200 OK\r\n"),
2332 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502333 MockRead("Content-Length: 5\r\n\r\n"),
2334 MockRead("hello"),
[email protected]11203f012009-11-12 23:02:312335 };
2336
[email protected]31a2bfe2010-02-09 08:03:392337 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2338 data_writes1, arraysize(data_writes1));
2339 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
2340 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:072341 session_deps_.socket_factory->AddSocketDataProvider(&data1);
2342 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]11203f012009-11-12 23:02:312343
[email protected]49639fa2011-12-20 23:22:412344 TestCompletionCallback callback1;
[email protected]11203f012009-11-12 23:02:312345
[email protected]262eec82013-03-19 21:01:362346 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502347 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:412348 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]11203f012009-11-12 23:02:312349 EXPECT_EQ(ERR_IO_PENDING, rv);
2350
2351 rv = callback1.WaitForResult();
2352 EXPECT_EQ(OK, rv);
2353
2354 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502355 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:042356 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]11203f012009-11-12 23:02:312357
[email protected]49639fa2011-12-20 23:22:412358 TestCompletionCallback callback2;
[email protected]11203f012009-11-12 23:02:312359
[email protected]49639fa2011-12-20 23:22:412360 rv = trans->RestartWithAuth(
2361 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]11203f012009-11-12 23:02:312362 EXPECT_EQ(ERR_IO_PENDING, rv);
2363
2364 rv = callback2.WaitForResult();
2365 EXPECT_EQ(OK, rv);
2366
2367 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502368 ASSERT_TRUE(response != NULL);
[email protected]11203f012009-11-12 23:02:312369 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502370 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]11203f012009-11-12 23:02:312371}
2372
[email protected]394816e92010-08-03 07:38:592373// Test the request-challenge-retry sequence for basic auth, over a connection
2374// that requires a restart when setting up an SSL tunnel.
[email protected]23e482282013-06-14 16:08:022375TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) {
[email protected]394816e92010-08-03 07:38:592376 HttpRequestInfo request;
2377 request.method = "GET";
2378 request.url = GURL("https://www.google.com/");
2379 // when the no authentication data flag is set.
2380 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2381
[email protected]cb9bf6ca2011-01-28 13:15:272382 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072383 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:202384 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:292385 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072386 session_deps_.net_log = log.bound().net_log();
2387 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272388
[email protected]394816e92010-08-03 07:38:592389 // Since we have proxy, should try to establish tunnel.
2390 MockWrite data_writes1[] = {
2391 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2392 "Host: www.google.com\r\n"
2393 "Proxy-Connection: keep-alive\r\n\r\n"),
2394
2395 // After calling trans->RestartWithAuth(), this is the request we should
2396 // be issuing -- the final header line contains the credentials.
2397 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2398 "Host: www.google.com\r\n"
2399 "Proxy-Connection: keep-alive\r\n"
2400 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
2401
2402 MockWrite("GET / HTTP/1.1\r\n"
2403 "Host: www.google.com\r\n"
2404 "Connection: keep-alive\r\n\r\n"),
2405 };
2406
2407 // The proxy responds to the connect with a 407, using a persistent
2408 // connection.
2409 MockRead data_reads1[] = {
2410 // No credentials.
2411 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2412 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2413 MockRead("Proxy-Connection: close\r\n\r\n"),
2414
2415 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2416
2417 MockRead("HTTP/1.1 200 OK\r\n"),
2418 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
[email protected]0b0bf032010-09-21 18:08:502419 MockRead("Content-Length: 5\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062420 MockRead(SYNCHRONOUS, "hello"),
[email protected]394816e92010-08-03 07:38:592421 };
2422
2423 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2424 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072425 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:062426 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072427 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]394816e92010-08-03 07:38:592428
[email protected]49639fa2011-12-20 23:22:412429 TestCompletionCallback callback1;
[email protected]394816e92010-08-03 07:38:592430
[email protected]262eec82013-03-19 21:01:362431 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502432 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:502433
[email protected]49639fa2011-12-20 23:22:412434 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]394816e92010-08-03 07:38:592435 EXPECT_EQ(ERR_IO_PENDING, rv);
2436
2437 rv = callback1.WaitForResult();
2438 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:572439 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:402440 log.GetEntries(&entries);
[email protected]394816e92010-08-03 07:38:592441 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402442 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]394816e92010-08-03 07:38:592443 NetLog::PHASE_NONE);
2444 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402445 entries, pos,
[email protected]394816e92010-08-03 07:38:592446 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2447 NetLog::PHASE_NONE);
2448
2449 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502450 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:502451 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]394816e92010-08-03 07:38:592452 EXPECT_EQ(407, response->headers->response_code());
2453 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:042454 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]394816e92010-08-03 07:38:592455
[email protected]029c83b62013-01-24 05:28:202456 LoadTimingInfo load_timing_info;
2457 // CONNECT requests and responses are handled at the connect job level, so
2458 // the transaction does not yet have a connection.
2459 EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info));
2460
[email protected]49639fa2011-12-20 23:22:412461 TestCompletionCallback callback2;
[email protected]394816e92010-08-03 07:38:592462
[email protected]49639fa2011-12-20 23:22:412463 rv = trans->RestartWithAuth(
2464 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]394816e92010-08-03 07:38:592465 EXPECT_EQ(ERR_IO_PENDING, rv);
2466
2467 rv = callback2.WaitForResult();
2468 EXPECT_EQ(OK, rv);
2469
2470 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:502471 ASSERT_TRUE(response != NULL);
[email protected]394816e92010-08-03 07:38:592472
2473 EXPECT_TRUE(response->headers->IsKeepAlive());
2474 EXPECT_EQ(200, response->headers->response_code());
[email protected]0b0bf032010-09-21 18:08:502475 EXPECT_EQ(5, response->headers->GetContentLength());
[email protected]394816e92010-08-03 07:38:592476 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2477
2478 // The password prompt info should not be set.
2479 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]0b0bf032010-09-21 18:08:502480
[email protected]029c83b62013-01-24 05:28:202481 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
2482 TestLoadTimingNotReusedWithPac(load_timing_info,
2483 CONNECT_TIMING_HAS_SSL_TIMES);
2484
[email protected]0b0bf032010-09-21 18:08:502485 trans.reset();
[email protected]102e27c2011-02-23 01:01:312486 session->CloseAllConnections();
[email protected]394816e92010-08-03 07:38:592487}
2488
[email protected]11203f012009-11-12 23:02:312489// Test the request-challenge-retry sequence for basic auth, over a keep-alive
[email protected]2d2697f92009-02-18 21:00:322490// proxy connection, when setting up an SSL tunnel.
[email protected]23e482282013-06-14 16:08:022491TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) {
[email protected]cb9bf6ca2011-01-28 13:15:272492 HttpRequestInfo request;
2493 request.method = "GET";
2494 request.url = GURL("https://www.google.com/");
2495 // Ensure that proxy authentication is attempted even
2496 // when the no authentication data flag is set.
2497 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
2498
[email protected]2d2697f92009-02-18 21:00:322499 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072500 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]333bdf62012-06-08 22:57:292501 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072502 session_deps_.net_log = log.bound().net_log();
2503 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2d2697f92009-02-18 21:00:322504
[email protected]262eec82013-03-19 21:01:362505 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502506 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d2697f92009-02-18 21:00:322507
[email protected]2d2697f92009-02-18 21:00:322508 // Since we have proxy, should try to establish tunnel.
2509 MockWrite data_writes1[] = {
2510 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:452511 "Host: www.google.com\r\n"
2512 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]2d2697f92009-02-18 21:00:322513
2514 // After calling trans->RestartWithAuth(), this is the request we should
2515 // be issuing -- the final header line contains the credentials.
2516 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2517 "Host: www.google.com\r\n"
[email protected]e44de5d2009-06-05 20:12:452518 "Proxy-Connection: keep-alive\r\n"
[email protected]2d2697f92009-02-18 21:00:322519 "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
2520 };
2521
2522 // The proxy responds to the connect with a 407, using a persistent
2523 // connection.
2524 MockRead data_reads1[] = {
2525 // No credentials.
2526 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2527 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2528 MockRead("Content-Length: 10\r\n\r\n"),
2529 MockRead("0123456789"),
2530
2531 // Wrong credentials (wrong password).
2532 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2533 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2534 MockRead("Content-Length: 10\r\n\r\n"),
2535 // No response body because the test stops reading here.
[email protected]8ddf8322012-02-23 18:08:062536 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]2d2697f92009-02-18 21:00:322537 };
2538
[email protected]31a2bfe2010-02-09 08:03:392539 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2540 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072541 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]2d2697f92009-02-18 21:00:322542
[email protected]49639fa2011-12-20 23:22:412543 TestCompletionCallback callback1;
[email protected]2d2697f92009-02-18 21:00:322544
[email protected]49639fa2011-12-20 23:22:412545 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]1c773ea12009-04-28 19:58:422546 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322547
2548 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422549 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:572550 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:402551 log.GetEntries(&entries);
[email protected]dbb83db2010-05-11 18:13:392552 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402553 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]dbb83db2010-05-11 18:13:392554 NetLog::PHASE_NONE);
2555 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402556 entries, pos,
[email protected]dbb83db2010-05-11 18:13:392557 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2558 NetLog::PHASE_NONE);
[email protected]2d2697f92009-02-18 21:00:322559
[email protected]1c773ea12009-04-28 19:58:422560 const HttpResponseInfo* response = trans->GetResponseInfo();
ttuttle7933c112015-01-06 00:55:242561 ASSERT_TRUE(response);
2562 ASSERT_TRUE(response->headers);
[email protected]2d2697f92009-02-18 21:00:322563 EXPECT_TRUE(response->headers->IsKeepAlive());
2564 EXPECT_EQ(407, response->headers->response_code());
ttuttle7933c112015-01-06 00:55:242565 EXPECT_EQ(-1, response->headers->GetContentLength());
[email protected]1c773ea12009-04-28 19:58:422566 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:042567 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]2d2697f92009-02-18 21:00:322568
[email protected]49639fa2011-12-20 23:22:412569 TestCompletionCallback callback2;
[email protected]2d2697f92009-02-18 21:00:322570
2571 // Wrong password (should be "bar").
[email protected]49639fa2011-12-20 23:22:412572 rv = trans->RestartWithAuth(
2573 AuthCredentials(kFoo, kBaz), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:422574 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]2d2697f92009-02-18 21:00:322575
2576 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422577 EXPECT_EQ(OK, rv);
[email protected]2d2697f92009-02-18 21:00:322578
2579 response = trans->GetResponseInfo();
ttuttle7933c112015-01-06 00:55:242580 ASSERT_TRUE(response);
2581 ASSERT_TRUE(response->headers);
[email protected]2d2697f92009-02-18 21:00:322582 EXPECT_TRUE(response->headers->IsKeepAlive());
2583 EXPECT_EQ(407, response->headers->response_code());
ttuttle7933c112015-01-06 00:55:242584 EXPECT_EQ(-1, response->headers->GetContentLength());
[email protected]1c773ea12009-04-28 19:58:422585 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:042586 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]e772db3f2010-07-12 18:11:132587
[email protected]e60e47a2010-07-14 03:37:182588 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
2589 // out of scope.
[email protected]102e27c2011-02-23 01:01:312590 session->CloseAllConnections();
[email protected]2d2697f92009-02-18 21:00:322591}
2592
[email protected]a8e9b162009-03-12 00:06:442593// Test that we don't read the response body when we fail to establish a tunnel,
2594// even if the user cancels the proxy's auth attempt.
[email protected]23e482282013-06-14 16:08:022595TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
[email protected]cb9bf6ca2011-01-28 13:15:272596 HttpRequestInfo request;
2597 request.method = "GET";
2598 request.url = GURL("https://www.google.com/");
2599 request.load_flags = 0;
2600
[email protected]a8e9b162009-03-12 00:06:442601 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072602 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]a8e9b162009-03-12 00:06:442603
[email protected]bb88e1d32013-05-03 23:11:072604 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]a8e9b162009-03-12 00:06:442605
[email protected]262eec82013-03-19 21:01:362606 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502607 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]a8e9b162009-03-12 00:06:442608
[email protected]a8e9b162009-03-12 00:06:442609 // Since we have proxy, should try to establish tunnel.
2610 MockWrite data_writes[] = {
2611 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:452612 "Host: www.google.com\r\n"
2613 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]a8e9b162009-03-12 00:06:442614 };
2615
2616 // The proxy responds to the connect with a 407.
2617 MockRead data_reads[] = {
ttuttle7933c112015-01-06 00:55:242618 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2619 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2620 MockRead("Content-Length: 10\r\n\r\n"),
2621 MockRead("0123456789"), // Should not be reached.
2622 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
[email protected]a8e9b162009-03-12 00:06:442623 };
2624
[email protected]31a2bfe2010-02-09 08:03:392625 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
2626 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:072627 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]a8e9b162009-03-12 00:06:442628
[email protected]49639fa2011-12-20 23:22:412629 TestCompletionCallback callback;
[email protected]a8e9b162009-03-12 00:06:442630
[email protected]49639fa2011-12-20 23:22:412631 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:422632 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]a8e9b162009-03-12 00:06:442633
2634 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:422635 EXPECT_EQ(OK, rv);
[email protected]a8e9b162009-03-12 00:06:442636
[email protected]1c773ea12009-04-28 19:58:422637 const HttpResponseInfo* response = trans->GetResponseInfo();
ttuttle7933c112015-01-06 00:55:242638 ASSERT_TRUE(response);
2639 ASSERT_TRUE(response->headers);
[email protected]a8e9b162009-03-12 00:06:442640 EXPECT_TRUE(response->headers->IsKeepAlive());
2641 EXPECT_EQ(407, response->headers->response_code());
[email protected]1c773ea12009-04-28 19:58:422642 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]a8e9b162009-03-12 00:06:442643
2644 std::string response_data;
2645 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:422646 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]e60e47a2010-07-14 03:37:182647
2648 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
[email protected]102e27c2011-02-23 01:01:312649 session->CloseAllConnections();
[email protected]a8e9b162009-03-12 00:06:442650}
2651
ttuttle7933c112015-01-06 00:55:242652// Test that we don't pass extraneous headers from the proxy's response to the
2653// caller when the proxy responds to CONNECT with 407.
2654TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) {
2655 HttpRequestInfo request;
2656 request.method = "GET";
2657 request.url = GURL("https://www.google.com/");
2658 request.load_flags = 0;
2659
2660 // Configure against proxy server "myproxy:70".
2661 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
2662
2663 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
2664
2665 scoped_ptr<HttpTransaction> trans(
2666 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
2667
2668 // Since we have proxy, should try to establish tunnel.
2669 MockWrite data_writes[] = {
2670 MockWrite(
2671 "CONNECT www.google.com:443 HTTP/1.1\r\n"
2672 "Host: www.google.com\r\n"
2673 "Proxy-Connection: keep-alive\r\n\r\n"),
2674 };
2675
2676 // The proxy responds to the connect with a 407.
2677 MockRead data_reads[] = {
2678 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
2679 MockRead("X-Foo: bar\r\n"),
2680 MockRead("Set-Cookie: foo=bar\r\n"),
2681 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2682 MockRead("Content-Length: 10\r\n\r\n"),
2683 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
2684 };
2685
2686 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
2687 arraysize(data_writes));
2688 session_deps_.socket_factory->AddSocketDataProvider(&data);
2689
2690 TestCompletionCallback callback;
2691
2692 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
2693 EXPECT_EQ(ERR_IO_PENDING, rv);
2694
2695 rv = callback.WaitForResult();
2696 EXPECT_EQ(OK, rv);
2697
2698 const HttpResponseInfo* response = trans->GetResponseInfo();
2699 ASSERT_TRUE(response);
2700 ASSERT_TRUE(response->headers);
2701 EXPECT_TRUE(response->headers->IsKeepAlive());
2702 EXPECT_EQ(407, response->headers->response_code());
2703 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
2704 EXPECT_FALSE(response->headers->HasHeader("X-Foo"));
2705 EXPECT_FALSE(response->headers->HasHeader("Set-Cookie"));
2706
2707 std::string response_data;
2708 rv = ReadTransaction(trans.get(), &response_data);
2709 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
2710
2711 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
2712 session->CloseAllConnections();
2713}
2714
[email protected]8fdbcd22010-05-05 02:54:522715// Test when a server (non-proxy) returns a 407 (proxy-authenticate).
2716// The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
[email protected]23e482282013-06-14 16:08:022717TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
[email protected]8fdbcd22010-05-05 02:54:522718 HttpRequestInfo request;
2719 request.method = "GET";
2720 request.url = GURL("http://www.google.com/");
2721 request.load_flags = 0;
2722
[email protected]cb9bf6ca2011-01-28 13:15:272723 // We are using a DIRECT connection (i.e. no proxy) for this session.
[email protected]3fe8d2f82013-10-17 08:56:072724 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:272725 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:412726 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:272727
[email protected]8fdbcd22010-05-05 02:54:522728 MockWrite data_writes1[] = {
2729 MockWrite("GET / HTTP/1.1\r\n"
2730 "Host: www.google.com\r\n"
2731 "Connection: keep-alive\r\n\r\n"),
2732 };
2733
2734 MockRead data_reads1[] = {
2735 MockRead("HTTP/1.0 407 Proxy Auth required\r\n"),
2736 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2737 // Large content-length -- won't matter, as connection will be reset.
2738 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:062739 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]8fdbcd22010-05-05 02:54:522740 };
2741
2742 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2743 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072744 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8fdbcd22010-05-05 02:54:522745
[email protected]49639fa2011-12-20 23:22:412746 TestCompletionCallback callback;
[email protected]8fdbcd22010-05-05 02:54:522747
[email protected]49639fa2011-12-20 23:22:412748 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]8fdbcd22010-05-05 02:54:522749 EXPECT_EQ(ERR_IO_PENDING, rv);
2750
2751 rv = callback.WaitForResult();
2752 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv);
2753}
2754
[email protected]7a67a8152010-11-05 18:31:102755// Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication)
2756// through a non-authenticating proxy. The request should fail with
2757// ERR_UNEXPECTED_PROXY_AUTH.
2758// Note that it is impossible to detect if an HTTP server returns a 407 through
2759// a non-authenticating proxy - there is nothing to indicate whether the
2760// response came from the proxy or the server, so it is treated as if the proxy
2761// issued the challenge.
[email protected]23e482282013-06-14 16:08:022762TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:232763 HttpsServerRequestsProxyAuthThroughProxy) {
[email protected]cb9bf6ca2011-01-28 13:15:272764 HttpRequestInfo request;
2765 request.method = "GET";
2766 request.url = GURL("https://www.google.com/");
2767
[email protected]bb88e1d32013-05-03 23:11:072768 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]333bdf62012-06-08 22:57:292769 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072770 session_deps_.net_log = log.bound().net_log();
2771 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7a67a8152010-11-05 18:31:102772
[email protected]7a67a8152010-11-05 18:31:102773 // Since we have proxy, should try to establish tunnel.
2774 MockWrite data_writes1[] = {
2775 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2776 "Host: www.google.com\r\n"
2777 "Proxy-Connection: keep-alive\r\n\r\n"),
2778
2779 MockWrite("GET / HTTP/1.1\r\n"
2780 "Host: www.google.com\r\n"
2781 "Connection: keep-alive\r\n\r\n"),
2782 };
2783
2784 MockRead data_reads1[] = {
2785 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2786
2787 MockRead("HTTP/1.1 407 Unauthorized\r\n"),
2788 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
2789 MockRead("\r\n"),
[email protected]8ddf8322012-02-23 18:08:062790 MockRead(SYNCHRONOUS, OK),
[email protected]7a67a8152010-11-05 18:31:102791 };
2792
2793 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2794 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072795 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:062796 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072797 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]7a67a8152010-11-05 18:31:102798
[email protected]49639fa2011-12-20 23:22:412799 TestCompletionCallback callback1;
[email protected]7a67a8152010-11-05 18:31:102800
[email protected]262eec82013-03-19 21:01:362801 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:502802 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7a67a8152010-11-05 18:31:102803
[email protected]49639fa2011-12-20 23:22:412804 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]7a67a8152010-11-05 18:31:102805 EXPECT_EQ(ERR_IO_PENDING, rv);
2806
2807 rv = callback1.WaitForResult();
2808 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv);
[email protected]f3da152d2012-06-02 01:00:572809 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:402810 log.GetEntries(&entries);
[email protected]7a67a8152010-11-05 18:31:102811 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402812 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]7a67a8152010-11-05 18:31:102813 NetLog::PHASE_NONE);
2814 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:402815 entries, pos,
[email protected]7a67a8152010-11-05 18:31:102816 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
2817 NetLog::PHASE_NONE);
2818}
[email protected]2df19bb2010-08-25 20:13:462819
[email protected]029c83b62013-01-24 05:28:202820// Test the load timing for HTTPS requests with an HTTP proxy.
[email protected]23e482282013-06-14 16:08:022821TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) {
[email protected]029c83b62013-01-24 05:28:202822 HttpRequestInfo request1;
2823 request1.method = "GET";
2824 request1.url = GURL("https://www.google.com/1");
2825
2826 HttpRequestInfo request2;
2827 request2.method = "GET";
2828 request2.url = GURL("https://www.google.com/2");
2829
2830 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072831 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:202832 ProxyService::CreateFixed("PROXY myproxy:70"));
2833 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072834 session_deps_.net_log = log.bound().net_log();
2835 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]029c83b62013-01-24 05:28:202836
2837 // Since we have proxy, should try to establish tunnel.
2838 MockWrite data_writes1[] = {
2839 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2840 "Host: www.google.com\r\n"
2841 "Proxy-Connection: keep-alive\r\n\r\n"),
2842
2843 MockWrite("GET /1 HTTP/1.1\r\n"
2844 "Host: www.google.com\r\n"
2845 "Connection: keep-alive\r\n\r\n"),
2846
2847 MockWrite("GET /2 HTTP/1.1\r\n"
2848 "Host: www.google.com\r\n"
2849 "Connection: keep-alive\r\n\r\n"),
2850 };
2851
2852 // The proxy responds to the connect with a 407, using a persistent
2853 // connection.
2854 MockRead data_reads1[] = {
2855 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2856
2857 MockRead("HTTP/1.1 200 OK\r\n"),
2858 MockRead("Content-Length: 1\r\n\r\n"),
2859 MockRead(SYNCHRONOUS, "1"),
2860
2861 MockRead("HTTP/1.1 200 OK\r\n"),
2862 MockRead("Content-Length: 2\r\n\r\n"),
2863 MockRead(SYNCHRONOUS, "22"),
2864 };
2865
2866 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2867 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072868 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]029c83b62013-01-24 05:28:202869 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072870 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]029c83b62013-01-24 05:28:202871
2872 TestCompletionCallback callback1;
[email protected]262eec82013-03-19 21:01:362873 scoped_ptr<HttpTransaction> trans1(
[email protected]90499482013-06-01 00:39:502874 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202875
2876 int rv = trans1->Start(&request1, callback1.callback(), log.bound());
2877 EXPECT_EQ(ERR_IO_PENDING, rv);
2878
2879 rv = callback1.WaitForResult();
2880 EXPECT_EQ(OK, rv);
2881
2882 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
2883 ASSERT_TRUE(response1 != NULL);
[email protected]90499482013-06-01 00:39:502884 ASSERT_TRUE(response1->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:202885 EXPECT_EQ(1, response1->headers->GetContentLength());
2886
2887 LoadTimingInfo load_timing_info1;
2888 EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1));
2889 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES);
2890
2891 trans1.reset();
2892
2893 TestCompletionCallback callback2;
[email protected]262eec82013-03-19 21:01:362894 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:502895 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202896
2897 rv = trans2->Start(&request2, callback2.callback(), log.bound());
2898 EXPECT_EQ(ERR_IO_PENDING, rv);
2899
2900 rv = callback2.WaitForResult();
2901 EXPECT_EQ(OK, rv);
2902
2903 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
2904 ASSERT_TRUE(response2 != NULL);
[email protected]90499482013-06-01 00:39:502905 ASSERT_TRUE(response2->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:202906 EXPECT_EQ(2, response2->headers->GetContentLength());
2907
2908 LoadTimingInfo load_timing_info2;
2909 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
2910 TestLoadTimingReused(load_timing_info2);
2911
2912 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
2913
2914 trans2.reset();
2915 session->CloseAllConnections();
2916}
2917
2918// Test the load timing for HTTPS requests with an HTTP proxy and a PAC script.
[email protected]23e482282013-06-14 16:08:022919TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) {
[email protected]029c83b62013-01-24 05:28:202920 HttpRequestInfo request1;
2921 request1.method = "GET";
2922 request1.url = GURL("https://www.google.com/1");
2923
2924 HttpRequestInfo request2;
2925 request2.method = "GET";
2926 request2.url = GURL("https://www.google.com/2");
2927
2928 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:072929 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:202930 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
2931 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:072932 session_deps_.net_log = log.bound().net_log();
2933 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]029c83b62013-01-24 05:28:202934
2935 // Since we have proxy, should try to establish tunnel.
2936 MockWrite data_writes1[] = {
2937 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
2938 "Host: www.google.com\r\n"
2939 "Proxy-Connection: keep-alive\r\n\r\n"),
2940
2941 MockWrite("GET /1 HTTP/1.1\r\n"
2942 "Host: www.google.com\r\n"
2943 "Connection: keep-alive\r\n\r\n"),
2944
2945 MockWrite("GET /2 HTTP/1.1\r\n"
2946 "Host: www.google.com\r\n"
2947 "Connection: keep-alive\r\n\r\n"),
2948 };
2949
2950 // The proxy responds to the connect with a 407, using a persistent
2951 // connection.
2952 MockRead data_reads1[] = {
2953 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
2954
2955 MockRead("HTTP/1.1 200 OK\r\n"),
2956 MockRead("Content-Length: 1\r\n\r\n"),
2957 MockRead(SYNCHRONOUS, "1"),
2958
2959 MockRead("HTTP/1.1 200 OK\r\n"),
2960 MockRead("Content-Length: 2\r\n\r\n"),
2961 MockRead(SYNCHRONOUS, "22"),
2962 };
2963
2964 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
2965 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:072966 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]029c83b62013-01-24 05:28:202967 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:072968 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]029c83b62013-01-24 05:28:202969
2970 TestCompletionCallback callback1;
[email protected]262eec82013-03-19 21:01:362971 scoped_ptr<HttpTransaction> trans1(
[email protected]90499482013-06-01 00:39:502972 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202973
2974 int rv = trans1->Start(&request1, callback1.callback(), log.bound());
2975 EXPECT_EQ(ERR_IO_PENDING, rv);
2976
2977 rv = callback1.WaitForResult();
2978 EXPECT_EQ(OK, rv);
2979
2980 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
2981 ASSERT_TRUE(response1 != NULL);
[email protected]90499482013-06-01 00:39:502982 ASSERT_TRUE(response1->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:202983 EXPECT_EQ(1, response1->headers->GetContentLength());
2984
2985 LoadTimingInfo load_timing_info1;
2986 EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1));
2987 TestLoadTimingNotReusedWithPac(load_timing_info1,
2988 CONNECT_TIMING_HAS_SSL_TIMES);
2989
2990 trans1.reset();
2991
2992 TestCompletionCallback callback2;
[email protected]262eec82013-03-19 21:01:362993 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:502994 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:202995
2996 rv = trans2->Start(&request2, callback2.callback(), log.bound());
2997 EXPECT_EQ(ERR_IO_PENDING, rv);
2998
2999 rv = callback2.WaitForResult();
3000 EXPECT_EQ(OK, rv);
3001
3002 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
3003 ASSERT_TRUE(response2 != NULL);
[email protected]90499482013-06-01 00:39:503004 ASSERT_TRUE(response2->headers.get() != NULL);
[email protected]029c83b62013-01-24 05:28:203005 EXPECT_EQ(2, response2->headers->GetContentLength());
3006
3007 LoadTimingInfo load_timing_info2;
3008 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
3009 TestLoadTimingReusedWithPac(load_timing_info2);
3010
3011 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
3012
3013 trans2.reset();
3014 session->CloseAllConnections();
3015}
3016
[email protected]2df19bb2010-08-25 20:13:463017// Test a simple get through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:023018TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) {
[email protected]cb9bf6ca2011-01-28 13:15:273019 HttpRequestInfo request;
3020 request.method = "GET";
3021 request.url = GURL("http://www.google.com/");
3022
[email protected]2df19bb2010-08-25 20:13:463023 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073024 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113025 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293026 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073027 session_deps_.net_log = log.bound().net_log();
3028 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2df19bb2010-08-25 20:13:463029
[email protected]2df19bb2010-08-25 20:13:463030 // Since we have proxy, should use full url
3031 MockWrite data_writes1[] = {
3032 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
3033 "Host: www.google.com\r\n"
3034 "Proxy-Connection: keep-alive\r\n\r\n"),
3035 };
3036
3037 MockRead data_reads1[] = {
3038 MockRead("HTTP/1.1 200 OK\r\n"),
3039 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
3040 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:063041 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:463042 };
3043
3044 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
3045 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:073046 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:063047 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:073048 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2df19bb2010-08-25 20:13:463049
[email protected]49639fa2011-12-20 23:22:413050 TestCompletionCallback callback1;
[email protected]2df19bb2010-08-25 20:13:463051
[email protected]262eec82013-03-19 21:01:363052 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503053 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:503054
[email protected]49639fa2011-12-20 23:22:413055 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]2df19bb2010-08-25 20:13:463056 EXPECT_EQ(ERR_IO_PENDING, rv);
3057
3058 rv = callback1.WaitForResult();
3059 EXPECT_EQ(OK, rv);
3060
[email protected]58e32bb2013-01-21 18:23:253061 LoadTimingInfo load_timing_info;
3062 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3063 TestLoadTimingNotReused(load_timing_info,
3064 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
3065
[email protected]2df19bb2010-08-25 20:13:463066 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:503067 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:463068
3069 EXPECT_TRUE(response->headers->IsKeepAlive());
3070 EXPECT_EQ(200, response->headers->response_code());
3071 EXPECT_EQ(100, response->headers->GetContentLength());
3072 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
3073
3074 // The password prompt info should not be set.
3075 EXPECT_TRUE(response->auth_challenge.get() == NULL);
3076}
3077
[email protected]7642b5ae2010-09-01 20:55:173078// Test a SPDY get through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:023079TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) {
[email protected]cb9bf6ca2011-01-28 13:15:273080 HttpRequestInfo request;
3081 request.method = "GET";
3082 request.url = GURL("http://www.google.com/");
3083 request.load_flags = 0;
3084
[email protected]7642b5ae2010-09-01 20:55:173085 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073086 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113087 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293088 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073089 session_deps_.net_log = log.bound().net_log();
3090 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7642b5ae2010-09-01 20:55:173091
[email protected]7642b5ae2010-09-01 20:55:173092 // fetch http://www.google.com/ via SPDY
[email protected]cdf8f7e72013-05-23 10:56:463093 scoped_ptr<SpdyFrame> req(
3094 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]7642b5ae2010-09-01 20:55:173095 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
3096
[email protected]23e482282013-06-14 16:08:023097 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3098 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]7642b5ae2010-09-01 20:55:173099 MockRead spdy_reads[] = {
3100 CreateMockRead(*resp),
3101 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:063102 MockRead(ASYNC, 0, 0),
[email protected]7642b5ae2010-09-01 20:55:173103 };
3104
[email protected]dd54bd82012-07-19 23:44:573105 DelayedSocketData spdy_data(
3106 1, // wait for one write to finish before reading.
3107 spdy_reads, arraysize(spdy_reads),
3108 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073109 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]7642b5ae2010-09-01 20:55:173110
[email protected]8ddf8322012-02-23 18:08:063111 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023112 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073113 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]7642b5ae2010-09-01 20:55:173114
[email protected]49639fa2011-12-20 23:22:413115 TestCompletionCallback callback1;
[email protected]7642b5ae2010-09-01 20:55:173116
[email protected]262eec82013-03-19 21:01:363117 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503118 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:503119
[email protected]49639fa2011-12-20 23:22:413120 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]7642b5ae2010-09-01 20:55:173121 EXPECT_EQ(ERR_IO_PENDING, rv);
3122
3123 rv = callback1.WaitForResult();
3124 EXPECT_EQ(OK, rv);
3125
[email protected]58e32bb2013-01-21 18:23:253126 LoadTimingInfo load_timing_info;
3127 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3128 TestLoadTimingNotReused(load_timing_info,
3129 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
3130
[email protected]7642b5ae2010-09-01 20:55:173131 const HttpResponseInfo* response = trans->GetResponseInfo();
3132 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503133 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]7642b5ae2010-09-01 20:55:173134 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3135
3136 std::string response_data;
3137 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
[email protected]448d4ca52012-03-04 04:12:233138 EXPECT_EQ(kUploadData, response_data);
[email protected]7642b5ae2010-09-01 20:55:173139}
3140
[email protected]1c173852014-06-19 12:51:503141// Verifies that a session which races and wins against the owning transaction
3142// (completing prior to host resolution), doesn't fail the transaction.
3143// Regression test for crbug.com/334413.
3144TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) {
3145 HttpRequestInfo request;
3146 request.method = "GET";
3147 request.url = GURL("http://www.google.com/");
3148 request.load_flags = 0;
3149
3150 // Configure SPDY proxy server "proxy:70".
3151 session_deps_.proxy_service.reset(
3152 ProxyService::CreateFixed("https://proxy:70"));
3153 CapturingBoundNetLog log;
3154 session_deps_.net_log = log.bound().net_log();
3155 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
3156
3157 // Fetch http://www.google.com/ through the SPDY proxy.
3158 scoped_ptr<SpdyFrame> req(
3159 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
3160 MockWrite spdy_writes[] = {CreateMockWrite(*req)};
3161
3162 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3163 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
3164 MockRead spdy_reads[] = {
3165 CreateMockRead(*resp), CreateMockRead(*data), MockRead(ASYNC, 0, 0),
3166 };
3167
3168 DelayedSocketData spdy_data(
3169 1, // wait for one write to finish before reading.
3170 spdy_reads,
3171 arraysize(spdy_reads),
3172 spdy_writes,
3173 arraysize(spdy_writes));
3174 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
3175
3176 SSLSocketDataProvider ssl(ASYNC, OK);
3177 ssl.SetNextProto(GetParam());
3178 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
3179
3180 TestCompletionCallback callback1;
3181
3182 scoped_ptr<HttpTransaction> trans(
3183 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
3184
3185 // Stall the hostname resolution begun by the transaction.
3186 session_deps_.host_resolver->set_synchronous_mode(false);
3187 session_deps_.host_resolver->set_ondemand_mode(true);
3188
3189 int rv = trans->Start(&request, callback1.callback(), log.bound());
3190 EXPECT_EQ(ERR_IO_PENDING, rv);
3191
3192 // Race a session to the proxy, which completes first.
3193 session_deps_.host_resolver->set_ondemand_mode(false);
3194 SpdySessionKey key(
3195 HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
3196 base::WeakPtr<SpdySession> spdy_session =
3197 CreateSecureSpdySession(session, key, log.bound());
3198
3199 // Unstall the resolution begun by the transaction.
3200 session_deps_.host_resolver->set_ondemand_mode(true);
3201 session_deps_.host_resolver->ResolveAllPending();
3202
3203 EXPECT_FALSE(callback1.have_result());
3204 rv = callback1.WaitForResult();
3205 EXPECT_EQ(OK, rv);
3206
3207 const HttpResponseInfo* response = trans->GetResponseInfo();
3208 ASSERT_TRUE(response != NULL);
3209 ASSERT_TRUE(response->headers.get() != NULL);
3210 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3211
3212 std::string response_data;
3213 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
3214 EXPECT_EQ(kUploadData, response_data);
3215}
3216
[email protected]dc7bd1c52010-11-12 00:01:133217// Test a SPDY get through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:023218TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) {
[email protected]cb9bf6ca2011-01-28 13:15:273219 HttpRequestInfo request;
3220 request.method = "GET";
3221 request.url = GURL("http://www.google.com/");
3222 request.load_flags = 0;
3223
[email protected]79cb5c12011-09-12 13:12:043224 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:073225 session_deps_.proxy_service.reset(
[email protected]79cb5c12011-09-12 13:12:043226 ProxyService::CreateFixed("https://myproxy:70"));
[email protected]333bdf62012-06-08 22:57:293227 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073228 session_deps_.net_log = log.bound().net_log();
3229 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]dc7bd1c52010-11-12 00:01:133230
[email protected]dc7bd1c52010-11-12 00:01:133231 // The first request will be a bare GET, the second request will be a
3232 // GET with a Proxy-Authorization header.
[email protected]ff98d7f02012-03-22 21:44:193233 scoped_ptr<SpdyFrame> req_get(
[email protected]cdf8f7e72013-05-23 10:56:463234 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]dc7bd1c52010-11-12 00:01:133235 const char* const kExtraAuthorizationHeaders[] = {
[email protected]cdf8f7e72013-05-23 10:56:463236 "proxy-authorization", "Basic Zm9vOmJhcg=="
[email protected]dc7bd1c52010-11-12 00:01:133237 };
[email protected]ff98d7f02012-03-22 21:44:193238 scoped_ptr<SpdyFrame> req_get_authorization(
[email protected]cdf8f7e72013-05-23 10:56:463239 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders,
3240 arraysize(kExtraAuthorizationHeaders) / 2,
3241 false,
3242 3,
3243 LOWEST,
3244 false));
[email protected]dc7bd1c52010-11-12 00:01:133245 MockWrite spdy_writes[] = {
3246 CreateMockWrite(*req_get, 1),
3247 CreateMockWrite(*req_get_authorization, 4),
3248 };
3249
3250 // The first response is a 407 proxy authentication challenge, and the second
3251 // response will be a 200 response since the second request includes a valid
3252 // Authorization header.
3253 const char* const kExtraAuthenticationHeaders[] = {
[email protected]cdf8f7e72013-05-23 10:56:463254 "proxy-authenticate", "Basic realm=\"MyRealm1\""
[email protected]dc7bd1c52010-11-12 00:01:133255 };
[email protected]ff98d7f02012-03-22 21:44:193256 scoped_ptr<SpdyFrame> resp_authentication(
[email protected]23e482282013-06-14 16:08:023257 spdy_util_.ConstructSpdySynReplyError(
[email protected]dc7bd1c52010-11-12 00:01:133258 "407 Proxy Authentication Required",
3259 kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2,
3260 1));
[email protected]ff98d7f02012-03-22 21:44:193261 scoped_ptr<SpdyFrame> body_authentication(
[email protected]23e482282013-06-14 16:08:023262 spdy_util_.ConstructSpdyBodyFrame(1, true));
3263 scoped_ptr<SpdyFrame> resp_data(
3264 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
3265 scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]dc7bd1c52010-11-12 00:01:133266 MockRead spdy_reads[] = {
3267 CreateMockRead(*resp_authentication, 2),
3268 CreateMockRead(*body_authentication, 3),
3269 CreateMockRead(*resp_data, 5),
3270 CreateMockRead(*body_data, 6),
[email protected]8ddf8322012-02-23 18:08:063271 MockRead(ASYNC, 0, 7),
[email protected]dc7bd1c52010-11-12 00:01:133272 };
3273
[email protected]dd54bd82012-07-19 23:44:573274 OrderedSocketData data(
3275 spdy_reads, arraysize(spdy_reads),
3276 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073277 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]dc7bd1c52010-11-12 00:01:133278
[email protected]8ddf8322012-02-23 18:08:063279 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023280 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073281 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]dc7bd1c52010-11-12 00:01:133282
[email protected]49639fa2011-12-20 23:22:413283 TestCompletionCallback callback1;
[email protected]dc7bd1c52010-11-12 00:01:133284
[email protected]262eec82013-03-19 21:01:363285 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503286 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]dc7bd1c52010-11-12 00:01:133287
[email protected]49639fa2011-12-20 23:22:413288 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]dc7bd1c52010-11-12 00:01:133289 EXPECT_EQ(ERR_IO_PENDING, rv);
3290
3291 rv = callback1.WaitForResult();
3292 EXPECT_EQ(OK, rv);
3293
3294 const HttpResponseInfo* const response = trans->GetResponseInfo();
3295
3296 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503297 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]dc7bd1c52010-11-12 00:01:133298 EXPECT_EQ(407, response->headers->response_code());
3299 EXPECT_TRUE(response->was_fetched_via_spdy);
[email protected]79cb5c12011-09-12 13:12:043300 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]dc7bd1c52010-11-12 00:01:133301
[email protected]49639fa2011-12-20 23:22:413302 TestCompletionCallback callback2;
[email protected]dc7bd1c52010-11-12 00:01:133303
[email protected]49639fa2011-12-20 23:22:413304 rv = trans->RestartWithAuth(
3305 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]dc7bd1c52010-11-12 00:01:133306 EXPECT_EQ(ERR_IO_PENDING, rv);
3307
3308 rv = callback2.WaitForResult();
3309 EXPECT_EQ(OK, rv);
3310
3311 const HttpResponseInfo* const response_restart = trans->GetResponseInfo();
3312
3313 ASSERT_TRUE(response_restart != NULL);
[email protected]90499482013-06-01 00:39:503314 ASSERT_TRUE(response_restart->headers.get() != NULL);
[email protected]dc7bd1c52010-11-12 00:01:133315 EXPECT_EQ(200, response_restart->headers->response_code());
3316 // The password prompt info should not be set.
3317 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL);
3318}
3319
[email protected]d9da5fe2010-10-13 22:37:163320// Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server.
[email protected]23e482282013-06-14 16:08:023321TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) {
[email protected]cb9bf6ca2011-01-28 13:15:273322 HttpRequestInfo request;
3323 request.method = "GET";
3324 request.url = GURL("https://www.google.com/");
3325 request.load_flags = 0;
3326
[email protected]d9da5fe2010-10-13 22:37:163327 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073328 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113329 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293330 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073331 session_deps_.net_log = log.bound().net_log();
3332 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d9da5fe2010-10-13 22:37:163333
[email protected]262eec82013-03-19 21:01:363334 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503335 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]d9da5fe2010-10-13 22:37:163336
[email protected]d9da5fe2010-10-13 22:37:163337 // CONNECT to www.google.com:443 via SPDY
lgarrona91df87f2014-12-05 00:51:343338 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(
3339 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]d9da5fe2010-10-13 22:37:163340 // fetch https://www.google.com/ via HTTP
3341
3342 const char get[] = "GET / HTTP/1.1\r\n"
3343 "Host: www.google.com\r\n"
3344 "Connection: keep-alive\r\n\r\n";
[email protected]ff98d7f02012-03-22 21:44:193345 scoped_ptr<SpdyFrame> wrapped_get(
[email protected]23e482282013-06-14 16:08:023346 spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false));
3347 scoped_ptr<SpdyFrame> conn_resp(
3348 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]d9da5fe2010-10-13 22:37:163349 const char resp[] = "HTTP/1.1 200 OK\r\n"
3350 "Content-Length: 10\r\n\r\n";
[email protected]ff98d7f02012-03-22 21:44:193351 scoped_ptr<SpdyFrame> wrapped_get_resp(
[email protected]23e482282013-06-14 16:08:023352 spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false));
[email protected]ff98d7f02012-03-22 21:44:193353 scoped_ptr<SpdyFrame> wrapped_body(
[email protected]23e482282013-06-14 16:08:023354 spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false));
[email protected]ff98d7f02012-03-22 21:44:193355 scoped_ptr<SpdyFrame> window_update(
[email protected]c10b20852013-05-15 21:29:203356 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size()));
[email protected]8d2f7012012-02-16 00:08:043357
3358 MockWrite spdy_writes[] = {
3359 CreateMockWrite(*connect, 1),
3360 CreateMockWrite(*wrapped_get, 3),
[email protected]cdf8f7e72013-05-23 10:56:463361 CreateMockWrite(*window_update, 5),
[email protected]8d2f7012012-02-16 00:08:043362 };
3363
[email protected]d9da5fe2010-10-13 22:37:163364 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:063365 CreateMockRead(*conn_resp, 2, ASYNC),
3366 CreateMockRead(*wrapped_get_resp, 4, ASYNC),
3367 CreateMockRead(*wrapped_body, 6, ASYNC),
3368 CreateMockRead(*wrapped_body, 7, ASYNC),
3369 MockRead(ASYNC, 0, 8),
[email protected]d9da5fe2010-10-13 22:37:163370 };
3371
[email protected]dd54bd82012-07-19 23:44:573372 OrderedSocketData spdy_data(
3373 spdy_reads, arraysize(spdy_reads),
3374 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073375 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d9da5fe2010-10-13 22:37:163376
[email protected]8ddf8322012-02-23 18:08:063377 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023378 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073379 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]8ddf8322012-02-23 18:08:063380 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]d9da5fe2010-10-13 22:37:163381 ssl2.was_npn_negotiated = false;
[email protected]8e3c78cb2012-03-31 03:58:463382 ssl2.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073383 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]d9da5fe2010-10-13 22:37:163384
[email protected]49639fa2011-12-20 23:22:413385 TestCompletionCallback callback1;
[email protected]d9da5fe2010-10-13 22:37:163386
[email protected]49639fa2011-12-20 23:22:413387 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]d9da5fe2010-10-13 22:37:163388 EXPECT_EQ(ERR_IO_PENDING, rv);
3389
3390 rv = callback1.WaitForResult();
3391 EXPECT_EQ(OK, rv);
3392
[email protected]58e32bb2013-01-21 18:23:253393 LoadTimingInfo load_timing_info;
3394 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3395 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3396
[email protected]d9da5fe2010-10-13 22:37:163397 const HttpResponseInfo* response = trans->GetResponseInfo();
3398 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503399 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d9da5fe2010-10-13 22:37:163400 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3401
3402 std::string response_data;
3403 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
3404 EXPECT_EQ("1234567890", response_data);
3405}
3406
3407// Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server.
[email protected]23e482282013-06-14 16:08:023408TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) {
[email protected]cb9bf6ca2011-01-28 13:15:273409 HttpRequestInfo request;
3410 request.method = "GET";
3411 request.url = GURL("https://www.google.com/");
3412 request.load_flags = 0;
3413
[email protected]d9da5fe2010-10-13 22:37:163414 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073415 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113416 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293417 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073418 session_deps_.net_log = log.bound().net_log();
3419 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d9da5fe2010-10-13 22:37:163420
[email protected]262eec82013-03-19 21:01:363421 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503422 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]d9da5fe2010-10-13 22:37:163423
[email protected]d9da5fe2010-10-13 22:37:163424 // CONNECT to www.google.com:443 via SPDY
lgarrona91df87f2014-12-05 00:51:343425 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(
3426 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]d9da5fe2010-10-13 22:37:163427 // fetch https://www.google.com/ via SPDY
thestig9d3bb0c2015-01-24 00:49:513428 const char kMyUrl[] = "https://www.google.com/";
[email protected]cdf8f7e72013-05-23 10:56:463429 scoped_ptr<SpdyFrame> get(
3430 spdy_util_.ConstructSpdyGet(kMyUrl, false, 1, LOWEST));
[email protected]23e482282013-06-14 16:08:023431 scoped_ptr<SpdyFrame> wrapped_get(
3432 spdy_util_.ConstructWrappedSpdyFrame(get, 1));
3433 scoped_ptr<SpdyFrame> conn_resp(
3434 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3435 scoped_ptr<SpdyFrame> get_resp(
3436 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]ff98d7f02012-03-22 21:44:193437 scoped_ptr<SpdyFrame> wrapped_get_resp(
[email protected]23e482282013-06-14 16:08:023438 spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1));
3439 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true));
3440 scoped_ptr<SpdyFrame> wrapped_body(
3441 spdy_util_.ConstructWrappedSpdyFrame(body, 1));
[email protected]ff98d7f02012-03-22 21:44:193442 scoped_ptr<SpdyFrame> window_update_get_resp(
[email protected]c10b20852013-05-15 21:29:203443 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size()));
[email protected]ff98d7f02012-03-22 21:44:193444 scoped_ptr<SpdyFrame> window_update_body(
[email protected]c10b20852013-05-15 21:29:203445 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size()));
[email protected]8d2f7012012-02-16 00:08:043446
3447 MockWrite spdy_writes[] = {
3448 CreateMockWrite(*connect, 1),
3449 CreateMockWrite(*wrapped_get, 3),
3450 CreateMockWrite(*window_update_get_resp, 5),
3451 CreateMockWrite(*window_update_body, 7),
3452 };
3453
[email protected]d9da5fe2010-10-13 22:37:163454 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:063455 CreateMockRead(*conn_resp, 2, ASYNC),
3456 CreateMockRead(*wrapped_get_resp, 4, ASYNC),
3457 CreateMockRead(*wrapped_body, 6, ASYNC),
3458 MockRead(ASYNC, 0, 8),
[email protected]d9da5fe2010-10-13 22:37:163459 };
3460
[email protected]dd54bd82012-07-19 23:44:573461 OrderedSocketData spdy_data(
3462 spdy_reads, arraysize(spdy_reads),
3463 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073464 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d9da5fe2010-10-13 22:37:163465
[email protected]8ddf8322012-02-23 18:08:063466 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023467 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073468 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]8ddf8322012-02-23 18:08:063469 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023470 ssl2.SetNextProto(GetParam());
3471 ssl2.protocol_negotiated = GetParam();
[email protected]bb88e1d32013-05-03 23:11:073472 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]d9da5fe2010-10-13 22:37:163473
[email protected]49639fa2011-12-20 23:22:413474 TestCompletionCallback callback1;
[email protected]d9da5fe2010-10-13 22:37:163475
[email protected]49639fa2011-12-20 23:22:413476 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]d9da5fe2010-10-13 22:37:163477 EXPECT_EQ(ERR_IO_PENDING, rv);
3478
3479 rv = callback1.WaitForResult();
3480 EXPECT_EQ(OK, rv);
3481
[email protected]58e32bb2013-01-21 18:23:253482 LoadTimingInfo load_timing_info;
3483 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3484 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3485
[email protected]d9da5fe2010-10-13 22:37:163486 const HttpResponseInfo* response = trans->GetResponseInfo();
3487 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503488 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d9da5fe2010-10-13 22:37:163489 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3490
3491 std::string response_data;
3492 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
[email protected]448d4ca52012-03-04 04:12:233493 EXPECT_EQ(kUploadData, response_data);
[email protected]d9da5fe2010-10-13 22:37:163494}
3495
3496// Test a SPDY CONNECT failure through an HTTPS Proxy.
[email protected]23e482282013-06-14 16:08:023497TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) {
[email protected]cb9bf6ca2011-01-28 13:15:273498 HttpRequestInfo request;
3499 request.method = "GET";
3500 request.url = GURL("https://www.google.com/");
3501 request.load_flags = 0;
3502
[email protected]d9da5fe2010-10-13 22:37:163503 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073504 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:113505 "https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:293506 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073507 session_deps_.net_log = log.bound().net_log();
3508 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d9da5fe2010-10-13 22:37:163509
[email protected]262eec82013-03-19 21:01:363510 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503511 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]d9da5fe2010-10-13 22:37:163512
[email protected]d9da5fe2010-10-13 22:37:163513 // CONNECT to www.google.com:443 via SPDY
lgarrona91df87f2014-12-05 00:51:343514 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(
3515 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]c10b20852013-05-15 21:29:203516 scoped_ptr<SpdyFrame> get(
3517 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]d9da5fe2010-10-13 22:37:163518
3519 MockWrite spdy_writes[] = {
3520 CreateMockWrite(*connect, 1),
3521 CreateMockWrite(*get, 3),
3522 };
3523
[email protected]23e482282013-06-14 16:08:023524 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1));
3525 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]d9da5fe2010-10-13 22:37:163526 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:063527 CreateMockRead(*resp, 2, ASYNC),
3528 MockRead(ASYNC, 0, 4),
[email protected]d9da5fe2010-10-13 22:37:163529 };
3530
[email protected]dd54bd82012-07-19 23:44:573531 OrderedSocketData spdy_data(
3532 spdy_reads, arraysize(spdy_reads),
3533 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073534 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d9da5fe2010-10-13 22:37:163535
[email protected]8ddf8322012-02-23 18:08:063536 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023537 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073538 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]8ddf8322012-02-23 18:08:063539 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023540 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073541 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]d9da5fe2010-10-13 22:37:163542
[email protected]49639fa2011-12-20 23:22:413543 TestCompletionCallback callback1;
[email protected]d9da5fe2010-10-13 22:37:163544
[email protected]49639fa2011-12-20 23:22:413545 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]d9da5fe2010-10-13 22:37:163546 EXPECT_EQ(ERR_IO_PENDING, rv);
3547
3548 rv = callback1.WaitForResult();
[email protected]4eddbc732012-08-09 05:40:173549 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]d9da5fe2010-10-13 22:37:163550
[email protected]4eddbc732012-08-09 05:40:173551 // TODO(ttuttle): Anything else to check here?
[email protected]d9da5fe2010-10-13 22:37:163552}
3553
[email protected]f6c63db52013-02-02 00:35:223554// Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY
3555// HTTPS Proxy to different servers.
[email protected]23e482282013-06-14 16:08:023556TEST_P(HttpNetworkTransactionTest,
[email protected]f6c63db52013-02-02 00:35:223557 HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) {
3558 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073559 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]f6c63db52013-02-02 00:35:223560 "https://proxy:70"));
3561 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073562 session_deps_.net_log = log.bound().net_log();
[email protected]f6c63db52013-02-02 00:35:223563 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:073564 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]f6c63db52013-02-02 00:35:223565
3566 HttpRequestInfo request1;
3567 request1.method = "GET";
3568 request1.url = GURL("https://www.google.com/");
3569 request1.load_flags = 0;
3570
3571 HttpRequestInfo request2;
3572 request2.method = "GET";
3573 request2.url = GURL("https://news.google.com/");
3574 request2.load_flags = 0;
3575
3576 // CONNECT to www.google.com:443 via SPDY.
lgarrona91df87f2014-12-05 00:51:343577 scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(
3578 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]23e482282013-06-14 16:08:023579 scoped_ptr<SpdyFrame> conn_resp1(
3580 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]f6c63db52013-02-02 00:35:223581
3582 // Fetch https://www.google.com/ via HTTP.
3583 const char get1[] = "GET / HTTP/1.1\r\n"
3584 "Host: www.google.com\r\n"
3585 "Connection: keep-alive\r\n\r\n";
3586 scoped_ptr<SpdyFrame> wrapped_get1(
[email protected]23e482282013-06-14 16:08:023587 spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false));
[email protected]f6c63db52013-02-02 00:35:223588 const char resp1[] = "HTTP/1.1 200 OK\r\n"
3589 "Content-Length: 1\r\n\r\n";
3590 scoped_ptr<SpdyFrame> wrapped_get_resp1(
[email protected]23e482282013-06-14 16:08:023591 spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false));
3592 scoped_ptr<SpdyFrame> wrapped_body1(
3593 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false));
[email protected]f6c63db52013-02-02 00:35:223594 scoped_ptr<SpdyFrame> window_update(
[email protected]c10b20852013-05-15 21:29:203595 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size()));
[email protected]f6c63db52013-02-02 00:35:223596
3597 // CONNECT to news.google.com:443 via SPDY.
[email protected]745aa9c2014-06-27 02:21:293598 SpdyHeaderBlock connect2_block;
3599 connect2_block[spdy_util_.GetMethodKey()] = "CONNECT";
3600 connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443";
3601 connect2_block[spdy_util_.GetHostKey()] = "news.google.com";
3602 spdy_util_.MaybeAddVersionHeader(&connect2_block);
[email protected]f6c63db52013-02-02 00:35:223603 scoped_ptr<SpdyFrame> connect2(
[email protected]745aa9c2014-06-27 02:21:293604 spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false));
[email protected]601e03f12014-04-06 16:26:393605
[email protected]23e482282013-06-14 16:08:023606 scoped_ptr<SpdyFrame> conn_resp2(
3607 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
[email protected]f6c63db52013-02-02 00:35:223608
3609 // Fetch https://news.google.com/ via HTTP.
3610 const char get2[] = "GET / HTTP/1.1\r\n"
3611 "Host: news.google.com\r\n"
3612 "Connection: keep-alive\r\n\r\n";
3613 scoped_ptr<SpdyFrame> wrapped_get2(
[email protected]23e482282013-06-14 16:08:023614 spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false));
[email protected]f6c63db52013-02-02 00:35:223615 const char resp2[] = "HTTP/1.1 200 OK\r\n"
3616 "Content-Length: 2\r\n\r\n";
3617 scoped_ptr<SpdyFrame> wrapped_get_resp2(
[email protected]23e482282013-06-14 16:08:023618 spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false));
[email protected]f6c63db52013-02-02 00:35:223619 scoped_ptr<SpdyFrame> wrapped_body2(
[email protected]23e482282013-06-14 16:08:023620 spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false));
[email protected]f6c63db52013-02-02 00:35:223621
3622 MockWrite spdy_writes[] = {
3623 CreateMockWrite(*connect1, 0),
3624 CreateMockWrite(*wrapped_get1, 2),
3625 CreateMockWrite(*connect2, 5),
3626 CreateMockWrite(*wrapped_get2, 7),
3627 };
3628
3629 MockRead spdy_reads[] = {
3630 CreateMockRead(*conn_resp1, 1, ASYNC),
3631 CreateMockRead(*wrapped_get_resp1, 3, ASYNC),
3632 CreateMockRead(*wrapped_body1, 4, ASYNC),
3633 CreateMockRead(*conn_resp2, 6, ASYNC),
3634 CreateMockRead(*wrapped_get_resp2, 8, ASYNC),
3635 CreateMockRead(*wrapped_body2, 9, ASYNC),
3636 MockRead(ASYNC, 0, 10),
3637 };
3638
3639 DeterministicSocketData spdy_data(
3640 spdy_reads, arraysize(spdy_reads),
3641 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073642 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]f6c63db52013-02-02 00:35:223643
3644 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023645 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073646 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]f6c63db52013-02-02 00:35:223647 SSLSocketDataProvider ssl2(ASYNC, OK);
3648 ssl2.was_npn_negotiated = false;
3649 ssl2.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073650 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]f6c63db52013-02-02 00:35:223651 SSLSocketDataProvider ssl3(ASYNC, OK);
3652 ssl3.was_npn_negotiated = false;
3653 ssl3.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073654 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl3);
[email protected]f6c63db52013-02-02 00:35:223655
3656 TestCompletionCallback callback;
3657
[email protected]262eec82013-03-19 21:01:363658 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503659 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223660 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
3661 EXPECT_EQ(ERR_IO_PENDING, rv);
3662 // The first connect and request, each of their responses, and the body.
3663 spdy_data.RunFor(5);
3664
3665 rv = callback.WaitForResult();
3666 EXPECT_EQ(OK, rv);
3667
3668 LoadTimingInfo load_timing_info;
3669 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3670 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3671
3672 const HttpResponseInfo* response = trans->GetResponseInfo();
3673 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503674 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]f6c63db52013-02-02 00:35:223675 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3676
3677 std::string response_data;
3678 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
[email protected]90499482013-06-01 00:39:503679 EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223680
[email protected]262eec82013-03-19 21:01:363681 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:503682 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223683 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
3684 EXPECT_EQ(ERR_IO_PENDING, rv);
3685
3686 // The second connect and request, each of their responses, and the body.
3687 spdy_data.RunFor(5);
3688 rv = callback.WaitForResult();
3689 EXPECT_EQ(OK, rv);
3690
3691 LoadTimingInfo load_timing_info2;
3692 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
3693 // Even though the SPDY connection is reused, a new tunnelled connection has
3694 // to be created, so the socket's load timing looks like a fresh connection.
3695 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES);
3696
3697 // The requests should have different IDs, since they each are using their own
3698 // separate stream.
3699 EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id);
3700
[email protected]90499482013-06-01 00:39:503701 EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223702}
3703
3704// Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY
3705// HTTPS Proxy to the same server.
[email protected]23e482282013-06-14 16:08:023706TEST_P(HttpNetworkTransactionTest,
[email protected]f6c63db52013-02-02 00:35:223707 HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) {
3708 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073709 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]f6c63db52013-02-02 00:35:223710 "https://proxy:70"));
3711 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073712 session_deps_.net_log = log.bound().net_log();
[email protected]f6c63db52013-02-02 00:35:223713 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:073714 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]f6c63db52013-02-02 00:35:223715
3716 HttpRequestInfo request1;
3717 request1.method = "GET";
3718 request1.url = GURL("https://www.google.com/");
3719 request1.load_flags = 0;
3720
3721 HttpRequestInfo request2;
3722 request2.method = "GET";
3723 request2.url = GURL("https://www.google.com/2");
3724 request2.load_flags = 0;
3725
3726 // CONNECT to www.google.com:443 via SPDY.
lgarrona91df87f2014-12-05 00:51:343727 scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect(
3728 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]23e482282013-06-14 16:08:023729 scoped_ptr<SpdyFrame> conn_resp1(
3730 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]f6c63db52013-02-02 00:35:223731
3732 // Fetch https://www.google.com/ via HTTP.
3733 const char get1[] = "GET / HTTP/1.1\r\n"
3734 "Host: www.google.com\r\n"
3735 "Connection: keep-alive\r\n\r\n";
3736 scoped_ptr<SpdyFrame> wrapped_get1(
[email protected]23e482282013-06-14 16:08:023737 spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false));
[email protected]f6c63db52013-02-02 00:35:223738 const char resp1[] = "HTTP/1.1 200 OK\r\n"
3739 "Content-Length: 1\r\n\r\n";
3740 scoped_ptr<SpdyFrame> wrapped_get_resp1(
[email protected]23e482282013-06-14 16:08:023741 spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false));
3742 scoped_ptr<SpdyFrame> wrapped_body1(
3743 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false));
[email protected]f6c63db52013-02-02 00:35:223744 scoped_ptr<SpdyFrame> window_update(
[email protected]c10b20852013-05-15 21:29:203745 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size()));
[email protected]f6c63db52013-02-02 00:35:223746
3747 // Fetch https://www.google.com/2 via HTTP.
3748 const char get2[] = "GET /2 HTTP/1.1\r\n"
3749 "Host: www.google.com\r\n"
3750 "Connection: keep-alive\r\n\r\n";
3751 scoped_ptr<SpdyFrame> wrapped_get2(
[email protected]23e482282013-06-14 16:08:023752 spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false));
[email protected]f6c63db52013-02-02 00:35:223753 const char resp2[] = "HTTP/1.1 200 OK\r\n"
3754 "Content-Length: 2\r\n\r\n";
3755 scoped_ptr<SpdyFrame> wrapped_get_resp2(
[email protected]23e482282013-06-14 16:08:023756 spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false));
[email protected]f6c63db52013-02-02 00:35:223757 scoped_ptr<SpdyFrame> wrapped_body2(
[email protected]23e482282013-06-14 16:08:023758 spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false));
[email protected]f6c63db52013-02-02 00:35:223759
3760 MockWrite spdy_writes[] = {
3761 CreateMockWrite(*connect1, 0),
3762 CreateMockWrite(*wrapped_get1, 2),
3763 CreateMockWrite(*wrapped_get2, 5),
3764 };
3765
3766 MockRead spdy_reads[] = {
3767 CreateMockRead(*conn_resp1, 1, ASYNC),
3768 CreateMockRead(*wrapped_get_resp1, 3, ASYNC),
3769 CreateMockRead(*wrapped_body1, 4, ASYNC),
3770 CreateMockRead(*wrapped_get_resp2, 6, ASYNC),
3771 CreateMockRead(*wrapped_body2, 7, ASYNC),
3772 MockRead(ASYNC, 0, 8),
3773 };
3774
3775 DeterministicSocketData spdy_data(
3776 spdy_reads, arraysize(spdy_reads),
3777 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073778 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]f6c63db52013-02-02 00:35:223779
3780 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023781 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073782 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]f6c63db52013-02-02 00:35:223783 SSLSocketDataProvider ssl2(ASYNC, OK);
3784 ssl2.was_npn_negotiated = false;
3785 ssl2.protocol_negotiated = kProtoUnknown;
[email protected]bb88e1d32013-05-03 23:11:073786 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]f6c63db52013-02-02 00:35:223787
3788 TestCompletionCallback callback;
3789
[email protected]262eec82013-03-19 21:01:363790 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503791 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223792 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
3793 EXPECT_EQ(ERR_IO_PENDING, rv);
3794 // The first connect and request, each of their responses, and the body.
3795 spdy_data.RunFor(5);
3796
3797 rv = callback.WaitForResult();
3798 EXPECT_EQ(OK, rv);
3799
3800 LoadTimingInfo load_timing_info;
3801 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3802 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES);
3803
3804 const HttpResponseInfo* response = trans->GetResponseInfo();
3805 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503806 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]f6c63db52013-02-02 00:35:223807 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3808
3809 std::string response_data;
3810 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
[email protected]90499482013-06-01 00:39:503811 EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223812 trans.reset();
3813
[email protected]262eec82013-03-19 21:01:363814 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:503815 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223816 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
3817 EXPECT_EQ(ERR_IO_PENDING, rv);
3818
3819 // The second request, response, and body. There should not be a second
3820 // connect.
3821 spdy_data.RunFor(3);
3822 rv = callback.WaitForResult();
3823 EXPECT_EQ(OK, rv);
3824
3825 LoadTimingInfo load_timing_info2;
3826 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
3827 TestLoadTimingReused(load_timing_info2);
3828
3829 // The requests should have the same ID.
3830 EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id);
3831
[email protected]90499482013-06-01 00:39:503832 EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223833}
3834
3835// Test load timing in the case of of two HTTP requests through a SPDY HTTPS
3836// Proxy to different servers.
[email protected]23e482282013-06-14 16:08:023837TEST_P(HttpNetworkTransactionTest,
[email protected]f6c63db52013-02-02 00:35:223838 HttpsProxySpdyLoadTimingTwoHttpRequests) {
3839 // Configure against https proxy server "proxy:70".
[email protected]bb88e1d32013-05-03 23:11:073840 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]f6c63db52013-02-02 00:35:223841 "https://proxy:70"));
3842 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073843 session_deps_.net_log = log.bound().net_log();
[email protected]f6c63db52013-02-02 00:35:223844 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:073845 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]f6c63db52013-02-02 00:35:223846
3847 HttpRequestInfo request1;
3848 request1.method = "GET";
3849 request1.url = GURL("http://www.google.com/");
3850 request1.load_flags = 0;
3851
3852 HttpRequestInfo request2;
3853 request2.method = "GET";
3854 request2.url = GURL("http://news.google.com/");
3855 request2.load_flags = 0;
3856
3857 // http://www.google.com/
[email protected]23e482282013-06-14 16:08:023858 scoped_ptr<SpdyHeaderBlock> headers(
3859 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/"));
[email protected]745aa9c2014-06-27 02:21:293860 scoped_ptr<SpdyFrame> get1(
3861 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true));
[email protected]23e482282013-06-14 16:08:023862 scoped_ptr<SpdyFrame> get_resp1(
3863 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
3864 scoped_ptr<SpdyFrame> body1(
3865 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true));
[email protected]f6c63db52013-02-02 00:35:223866
3867 // http://news.google.com/
[email protected]23e482282013-06-14 16:08:023868 scoped_ptr<SpdyHeaderBlock> headers2(
3869 spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/"));
[email protected]745aa9c2014-06-27 02:21:293870 scoped_ptr<SpdyFrame> get2(
3871 spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true));
[email protected]23e482282013-06-14 16:08:023872 scoped_ptr<SpdyFrame> get_resp2(
3873 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
3874 scoped_ptr<SpdyFrame> body2(
3875 spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true));
[email protected]f6c63db52013-02-02 00:35:223876
3877 MockWrite spdy_writes[] = {
3878 CreateMockWrite(*get1, 0),
3879 CreateMockWrite(*get2, 3),
3880 };
3881
3882 MockRead spdy_reads[] = {
3883 CreateMockRead(*get_resp1, 1, ASYNC),
3884 CreateMockRead(*body1, 2, ASYNC),
3885 CreateMockRead(*get_resp2, 4, ASYNC),
3886 CreateMockRead(*body2, 5, ASYNC),
3887 MockRead(ASYNC, 0, 6),
3888 };
3889
3890 DeterministicSocketData spdy_data(
3891 spdy_reads, arraysize(spdy_reads),
3892 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:073893 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]f6c63db52013-02-02 00:35:223894
3895 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:023896 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:073897 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]f6c63db52013-02-02 00:35:223898
3899 TestCompletionCallback callback;
3900
[email protected]262eec82013-03-19 21:01:363901 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:503902 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223903 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
3904 EXPECT_EQ(ERR_IO_PENDING, rv);
3905 spdy_data.RunFor(2);
3906
3907 rv = callback.WaitForResult();
3908 EXPECT_EQ(OK, rv);
3909
3910 LoadTimingInfo load_timing_info;
3911 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
3912 TestLoadTimingNotReused(load_timing_info,
3913 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
3914
3915 const HttpResponseInfo* response = trans->GetResponseInfo();
3916 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:503917 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]f6c63db52013-02-02 00:35:223918 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
3919
3920 std::string response_data;
3921 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
[email protected]90499482013-06-01 00:39:503922 EXPECT_EQ(ERR_IO_PENDING, trans->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223923 spdy_data.RunFor(1);
3924 EXPECT_EQ(1, callback.WaitForResult());
3925 // Delete the first request, so the second one can reuse the socket.
3926 trans.reset();
3927
[email protected]262eec82013-03-19 21:01:363928 scoped_ptr<HttpTransaction> trans2(
[email protected]90499482013-06-01 00:39:503929 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f6c63db52013-02-02 00:35:223930 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
3931 EXPECT_EQ(ERR_IO_PENDING, rv);
3932
3933 spdy_data.RunFor(2);
3934 rv = callback.WaitForResult();
3935 EXPECT_EQ(OK, rv);
3936
3937 LoadTimingInfo load_timing_info2;
3938 EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2));
3939 TestLoadTimingReused(load_timing_info2);
3940
3941 // The requests should have the same ID.
3942 EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id);
3943
[email protected]90499482013-06-01 00:39:503944 EXPECT_EQ(ERR_IO_PENDING, trans2->Read(buf.get(), 256, callback.callback()));
[email protected]f6c63db52013-02-02 00:35:223945 spdy_data.RunFor(1);
3946 EXPECT_EQ(2, callback.WaitForResult());
3947}
3948
[email protected]2df19bb2010-08-25 20:13:463949// Test the challenge-response-retry sequence through an HTTPS Proxy
[email protected]23e482282013-06-14 16:08:023950TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) {
[email protected]2df19bb2010-08-25 20:13:463951 HttpRequestInfo request;
3952 request.method = "GET";
3953 request.url = GURL("http://www.google.com/");
3954 // when the no authentication data flag is set.
3955 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
3956
[email protected]79cb5c12011-09-12 13:12:043957 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:073958 session_deps_.proxy_service.reset(
[email protected]79cb5c12011-09-12 13:12:043959 ProxyService::CreateFixed("https://myproxy:70"));
[email protected]333bdf62012-06-08 22:57:293960 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:073961 session_deps_.net_log = log.bound().net_log();
3962 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:273963
[email protected]2df19bb2010-08-25 20:13:463964 // Since we have proxy, should use full url
3965 MockWrite data_writes1[] = {
3966 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
3967 "Host: www.google.com\r\n"
3968 "Proxy-Connection: keep-alive\r\n\r\n"),
3969
3970 // After calling trans->RestartWithAuth(), this is the request we should
3971 // be issuing -- the final header line contains the credentials.
3972 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
3973 "Host: www.google.com\r\n"
3974 "Proxy-Connection: keep-alive\r\n"
3975 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
3976 };
3977
3978 // The proxy responds to the GET with a 407, using a persistent
3979 // connection.
3980 MockRead data_reads1[] = {
3981 // No credentials.
3982 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
3983 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
3984 MockRead("Proxy-Connection: keep-alive\r\n"),
3985 MockRead("Content-Length: 0\r\n\r\n"),
3986
3987 MockRead("HTTP/1.1 200 OK\r\n"),
3988 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
3989 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:063990 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:463991 };
3992
3993 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
3994 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:073995 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:063996 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:073997 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2df19bb2010-08-25 20:13:463998
[email protected]49639fa2011-12-20 23:22:413999 TestCompletionCallback callback1;
[email protected]2df19bb2010-08-25 20:13:464000
[email protected]262eec82013-03-19 21:01:364001 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504002 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:504003
[email protected]49639fa2011-12-20 23:22:414004 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]2df19bb2010-08-25 20:13:464005 EXPECT_EQ(ERR_IO_PENDING, rv);
4006
4007 rv = callback1.WaitForResult();
4008 EXPECT_EQ(OK, rv);
4009
[email protected]58e32bb2013-01-21 18:23:254010 LoadTimingInfo load_timing_info;
4011 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
4012 TestLoadTimingNotReused(load_timing_info,
4013 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
4014
[email protected]2df19bb2010-08-25 20:13:464015 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504016 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:504017 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]2df19bb2010-08-25 20:13:464018 EXPECT_EQ(407, response->headers->response_code());
4019 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]79cb5c12011-09-12 13:12:044020 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]2df19bb2010-08-25 20:13:464021
[email protected]49639fa2011-12-20 23:22:414022 TestCompletionCallback callback2;
[email protected]2df19bb2010-08-25 20:13:464023
[email protected]49639fa2011-12-20 23:22:414024 rv = trans->RestartWithAuth(
4025 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]2df19bb2010-08-25 20:13:464026 EXPECT_EQ(ERR_IO_PENDING, rv);
4027
4028 rv = callback2.WaitForResult();
4029 EXPECT_EQ(OK, rv);
4030
[email protected]58e32bb2013-01-21 18:23:254031 load_timing_info = LoadTimingInfo();
4032 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
4033 // Retrying with HTTP AUTH is considered to be reusing a socket.
4034 TestLoadTimingReused(load_timing_info);
4035
[email protected]2df19bb2010-08-25 20:13:464036 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504037 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:464038
4039 EXPECT_TRUE(response->headers->IsKeepAlive());
4040 EXPECT_EQ(200, response->headers->response_code());
4041 EXPECT_EQ(100, response->headers->GetContentLength());
4042 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
4043
4044 // The password prompt info should not be set.
4045 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4046}
4047
[email protected]23e482282013-06-14 16:08:024048void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus(
[email protected]c744cf22009-02-27 07:28:084049 const MockRead& status, int expected_status) {
[email protected]1c773ea12009-04-28 19:58:424050 HttpRequestInfo request;
[email protected]c744cf22009-02-27 07:28:084051 request.method = "GET";
4052 request.url = GURL("https://www.google.com/");
4053 request.load_flags = 0;
4054
[email protected]cb9bf6ca2011-01-28 13:15:274055 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:074056 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]bb88e1d32013-05-03 23:11:074057 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274058
[email protected]c744cf22009-02-27 07:28:084059 // Since we have proxy, should try to establish tunnel.
4060 MockWrite data_writes[] = {
4061 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:454062 "Host: www.google.com\r\n"
4063 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]c744cf22009-02-27 07:28:084064 };
4065
4066 MockRead data_reads[] = {
4067 status,
4068 MockRead("Content-Length: 10\r\n\r\n"),
4069 // No response body because the test stops reading here.
[email protected]8ddf8322012-02-23 18:08:064070 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]c744cf22009-02-27 07:28:084071 };
4072
[email protected]31a2bfe2010-02-09 08:03:394073 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4074 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:074075 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]c744cf22009-02-27 07:28:084076
[email protected]49639fa2011-12-20 23:22:414077 TestCompletionCallback callback;
[email protected]c744cf22009-02-27 07:28:084078
[email protected]262eec82013-03-19 21:01:364079 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504080 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:504081
[email protected]49639fa2011-12-20 23:22:414082 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424083 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]c744cf22009-02-27 07:28:084084
4085 rv = callback.WaitForResult();
4086 EXPECT_EQ(expected_status, rv);
4087}
4088
[email protected]23e482282013-06-14 16:08:024089void HttpNetworkTransactionTest::ConnectStatusHelper(
[email protected]448d4ca52012-03-04 04:12:234090 const MockRead& status) {
[email protected]c744cf22009-02-27 07:28:084091 ConnectStatusHelperWithExpectedStatus(
[email protected]1c773ea12009-04-28 19:58:424092 status, ERR_TUNNEL_CONNECTION_FAILED);
[email protected]c744cf22009-02-27 07:28:084093}
4094
[email protected]23e482282013-06-14 16:08:024095TEST_P(HttpNetworkTransactionTest, ConnectStatus100) {
[email protected]c744cf22009-02-27 07:28:084096 ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n"));
4097}
4098
[email protected]23e482282013-06-14 16:08:024099TEST_P(HttpNetworkTransactionTest, ConnectStatus101) {
[email protected]c744cf22009-02-27 07:28:084100 ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n"));
4101}
4102
[email protected]23e482282013-06-14 16:08:024103TEST_P(HttpNetworkTransactionTest, ConnectStatus201) {
[email protected]c744cf22009-02-27 07:28:084104 ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n"));
4105}
4106
[email protected]23e482282013-06-14 16:08:024107TEST_P(HttpNetworkTransactionTest, ConnectStatus202) {
[email protected]c744cf22009-02-27 07:28:084108 ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n"));
4109}
4110
[email protected]23e482282013-06-14 16:08:024111TEST_P(HttpNetworkTransactionTest, ConnectStatus203) {
[email protected]c744cf22009-02-27 07:28:084112 ConnectStatusHelper(
4113 MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n"));
4114}
4115
[email protected]23e482282013-06-14 16:08:024116TEST_P(HttpNetworkTransactionTest, ConnectStatus204) {
[email protected]c744cf22009-02-27 07:28:084117 ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n"));
4118}
4119
[email protected]23e482282013-06-14 16:08:024120TEST_P(HttpNetworkTransactionTest, ConnectStatus205) {
[email protected]c744cf22009-02-27 07:28:084121 ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n"));
4122}
4123
[email protected]23e482282013-06-14 16:08:024124TEST_P(HttpNetworkTransactionTest, ConnectStatus206) {
[email protected]c744cf22009-02-27 07:28:084125 ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n"));
4126}
4127
[email protected]23e482282013-06-14 16:08:024128TEST_P(HttpNetworkTransactionTest, ConnectStatus300) {
[email protected]c744cf22009-02-27 07:28:084129 ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n"));
4130}
4131
[email protected]23e482282013-06-14 16:08:024132TEST_P(HttpNetworkTransactionTest, ConnectStatus301) {
[email protected]c744cf22009-02-27 07:28:084133 ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n"));
4134}
4135
[email protected]23e482282013-06-14 16:08:024136TEST_P(HttpNetworkTransactionTest, ConnectStatus302) {
[email protected]c744cf22009-02-27 07:28:084137 ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n"));
4138}
4139
[email protected]23e482282013-06-14 16:08:024140TEST_P(HttpNetworkTransactionTest, ConnectStatus303) {
[email protected]c744cf22009-02-27 07:28:084141 ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n"));
4142}
4143
[email protected]23e482282013-06-14 16:08:024144TEST_P(HttpNetworkTransactionTest, ConnectStatus304) {
[email protected]c744cf22009-02-27 07:28:084145 ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n"));
4146}
4147
[email protected]23e482282013-06-14 16:08:024148TEST_P(HttpNetworkTransactionTest, ConnectStatus305) {
[email protected]c744cf22009-02-27 07:28:084149 ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n"));
4150}
4151
[email protected]23e482282013-06-14 16:08:024152TEST_P(HttpNetworkTransactionTest, ConnectStatus306) {
[email protected]c744cf22009-02-27 07:28:084153 ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n"));
4154}
4155
[email protected]23e482282013-06-14 16:08:024156TEST_P(HttpNetworkTransactionTest, ConnectStatus307) {
[email protected]c744cf22009-02-27 07:28:084157 ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n"));
4158}
4159
[email protected]0a17aab32014-04-24 03:32:374160TEST_P(HttpNetworkTransactionTest, ConnectStatus308) {
4161 ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n"));
4162}
4163
[email protected]23e482282013-06-14 16:08:024164TEST_P(HttpNetworkTransactionTest, ConnectStatus400) {
[email protected]c744cf22009-02-27 07:28:084165 ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n"));
4166}
4167
[email protected]23e482282013-06-14 16:08:024168TEST_P(HttpNetworkTransactionTest, ConnectStatus401) {
[email protected]c744cf22009-02-27 07:28:084169 ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n"));
4170}
4171
[email protected]23e482282013-06-14 16:08:024172TEST_P(HttpNetworkTransactionTest, ConnectStatus402) {
[email protected]c744cf22009-02-27 07:28:084173 ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n"));
4174}
4175
[email protected]23e482282013-06-14 16:08:024176TEST_P(HttpNetworkTransactionTest, ConnectStatus403) {
[email protected]c744cf22009-02-27 07:28:084177 ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n"));
4178}
4179
[email protected]23e482282013-06-14 16:08:024180TEST_P(HttpNetworkTransactionTest, ConnectStatus404) {
[email protected]c744cf22009-02-27 07:28:084181 ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n"));
4182}
4183
[email protected]23e482282013-06-14 16:08:024184TEST_P(HttpNetworkTransactionTest, ConnectStatus405) {
[email protected]c744cf22009-02-27 07:28:084185 ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n"));
4186}
4187
[email protected]23e482282013-06-14 16:08:024188TEST_P(HttpNetworkTransactionTest, ConnectStatus406) {
[email protected]c744cf22009-02-27 07:28:084189 ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n"));
4190}
4191
[email protected]23e482282013-06-14 16:08:024192TEST_P(HttpNetworkTransactionTest, ConnectStatus407) {
[email protected]c744cf22009-02-27 07:28:084193 ConnectStatusHelperWithExpectedStatus(
4194 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
[email protected]a7ea8832010-07-12 17:54:544195 ERR_PROXY_AUTH_UNSUPPORTED);
[email protected]c744cf22009-02-27 07:28:084196}
4197
[email protected]23e482282013-06-14 16:08:024198TEST_P(HttpNetworkTransactionTest, ConnectStatus408) {
[email protected]c744cf22009-02-27 07:28:084199 ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n"));
4200}
4201
[email protected]23e482282013-06-14 16:08:024202TEST_P(HttpNetworkTransactionTest, ConnectStatus409) {
[email protected]c744cf22009-02-27 07:28:084203 ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n"));
4204}
4205
[email protected]23e482282013-06-14 16:08:024206TEST_P(HttpNetworkTransactionTest, ConnectStatus410) {
[email protected]c744cf22009-02-27 07:28:084207 ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n"));
4208}
4209
[email protected]23e482282013-06-14 16:08:024210TEST_P(HttpNetworkTransactionTest, ConnectStatus411) {
[email protected]c744cf22009-02-27 07:28:084211 ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n"));
4212}
4213
[email protected]23e482282013-06-14 16:08:024214TEST_P(HttpNetworkTransactionTest, ConnectStatus412) {
[email protected]c744cf22009-02-27 07:28:084215 ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n"));
4216}
4217
[email protected]23e482282013-06-14 16:08:024218TEST_P(HttpNetworkTransactionTest, ConnectStatus413) {
[email protected]c744cf22009-02-27 07:28:084219 ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n"));
4220}
4221
[email protected]23e482282013-06-14 16:08:024222TEST_P(HttpNetworkTransactionTest, ConnectStatus414) {
[email protected]c744cf22009-02-27 07:28:084223 ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n"));
4224}
4225
[email protected]23e482282013-06-14 16:08:024226TEST_P(HttpNetworkTransactionTest, ConnectStatus415) {
[email protected]c744cf22009-02-27 07:28:084227 ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n"));
4228}
4229
[email protected]23e482282013-06-14 16:08:024230TEST_P(HttpNetworkTransactionTest, ConnectStatus416) {
[email protected]c744cf22009-02-27 07:28:084231 ConnectStatusHelper(
4232 MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n"));
4233}
4234
[email protected]23e482282013-06-14 16:08:024235TEST_P(HttpNetworkTransactionTest, ConnectStatus417) {
[email protected]c744cf22009-02-27 07:28:084236 ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n"));
4237}
4238
[email protected]23e482282013-06-14 16:08:024239TEST_P(HttpNetworkTransactionTest, ConnectStatus500) {
[email protected]c744cf22009-02-27 07:28:084240 ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n"));
4241}
4242
[email protected]23e482282013-06-14 16:08:024243TEST_P(HttpNetworkTransactionTest, ConnectStatus501) {
[email protected]c744cf22009-02-27 07:28:084244 ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n"));
4245}
4246
[email protected]23e482282013-06-14 16:08:024247TEST_P(HttpNetworkTransactionTest, ConnectStatus502) {
[email protected]c744cf22009-02-27 07:28:084248 ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n"));
4249}
4250
[email protected]23e482282013-06-14 16:08:024251TEST_P(HttpNetworkTransactionTest, ConnectStatus503) {
[email protected]c744cf22009-02-27 07:28:084252 ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n"));
4253}
4254
[email protected]23e482282013-06-14 16:08:024255TEST_P(HttpNetworkTransactionTest, ConnectStatus504) {
[email protected]c744cf22009-02-27 07:28:084256 ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n"));
4257}
4258
[email protected]23e482282013-06-14 16:08:024259TEST_P(HttpNetworkTransactionTest, ConnectStatus505) {
[email protected]c744cf22009-02-27 07:28:084260 ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n"));
4261}
4262
[email protected]038e9a32008-10-08 22:40:164263// Test the flow when both the proxy server AND origin server require
4264// authentication. Again, this uses basic auth for both since that is
4265// the simplest to mock.
[email protected]23e482282013-06-14 16:08:024266TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
[email protected]cb9bf6ca2011-01-28 13:15:274267 HttpRequestInfo request;
4268 request.method = "GET";
4269 request.url = GURL("http://www.google.com/");
4270 request.load_flags = 0;
4271
[email protected]038e9a32008-10-08 22:40:164272 // Configure against proxy server "myproxy:70".
[email protected]3fe8d2f82013-10-17 08:56:074273 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
4274 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
4275
4276 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:414277 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]038e9a32008-10-08 22:40:164278
[email protected]f9ee6b52008-11-08 06:46:234279 MockWrite data_writes1[] = {
4280 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
4281 "Host: www.google.com\r\n"
4282 "Proxy-Connection: keep-alive\r\n\r\n"),
4283 };
4284
[email protected]038e9a32008-10-08 22:40:164285 MockRead data_reads1[] = {
4286 MockRead("HTTP/1.0 407 Unauthorized\r\n"),
4287 // Give a couple authenticate options (only the middle one is actually
4288 // supported).
[email protected]22927ad2009-09-21 19:56:194289 MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed.
[email protected]038e9a32008-10-08 22:40:164290 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
4291 MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"),
4292 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4293 // Large content-length -- won't matter, as connection will be reset.
4294 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064295 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]038e9a32008-10-08 22:40:164296 };
4297
4298 // After calling trans->RestartWithAuth() the first time, this is the
4299 // request we should be issuing -- the final header line contains the
4300 // proxy's credentials.
4301 MockWrite data_writes2[] = {
4302 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
4303 "Host: www.google.com\r\n"
4304 "Proxy-Connection: keep-alive\r\n"
4305 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
4306 };
4307
4308 // Now the proxy server lets the request pass through to origin server.
4309 // The origin server responds with a 401.
4310 MockRead data_reads2[] = {
4311 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
4312 // Note: We are using the same realm-name as the proxy server. This is
4313 // completely valid, as realms are unique across hosts.
4314 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
4315 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4316 MockRead("Content-Length: 2000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064317 MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached.
[email protected]038e9a32008-10-08 22:40:164318 };
4319
4320 // After calling trans->RestartWithAuth() the second time, we should send
4321 // the credentials for both the proxy and origin server.
4322 MockWrite data_writes3[] = {
4323 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
4324 "Host: www.google.com\r\n"
4325 "Proxy-Connection: keep-alive\r\n"
4326 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n"
4327 "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"),
4328 };
4329
4330 // Lastly we get the desired content.
4331 MockRead data_reads3[] = {
4332 MockRead("HTTP/1.0 200 OK\r\n"),
4333 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
4334 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064335 MockRead(SYNCHRONOUS, OK),
[email protected]038e9a32008-10-08 22:40:164336 };
4337
[email protected]31a2bfe2010-02-09 08:03:394338 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4339 data_writes1, arraysize(data_writes1));
4340 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
4341 data_writes2, arraysize(data_writes2));
4342 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
4343 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:074344 session_deps_.socket_factory->AddSocketDataProvider(&data1);
4345 session_deps_.socket_factory->AddSocketDataProvider(&data2);
4346 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]038e9a32008-10-08 22:40:164347
[email protected]49639fa2011-12-20 23:22:414348 TestCompletionCallback callback1;
[email protected]038e9a32008-10-08 22:40:164349
[email protected]49639fa2011-12-20 23:22:414350 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424351 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:164352
4353 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424354 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:164355
[email protected]1c773ea12009-04-28 19:58:424356 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504357 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:044358 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
[email protected]038e9a32008-10-08 22:40:164359
[email protected]49639fa2011-12-20 23:22:414360 TestCompletionCallback callback2;
[email protected]038e9a32008-10-08 22:40:164361
[email protected]49639fa2011-12-20 23:22:414362 rv = trans->RestartWithAuth(
4363 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:424364 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:164365
4366 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424367 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:164368
4369 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504370 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:044371 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]038e9a32008-10-08 22:40:164372
[email protected]49639fa2011-12-20 23:22:414373 TestCompletionCallback callback3;
[email protected]038e9a32008-10-08 22:40:164374
[email protected]49639fa2011-12-20 23:22:414375 rv = trans->RestartWithAuth(
4376 AuthCredentials(kFoo2, kBar2), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:424377 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]038e9a32008-10-08 22:40:164378
4379 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424380 EXPECT_EQ(OK, rv);
[email protected]038e9a32008-10-08 22:40:164381
4382 response = trans->GetResponseInfo();
4383 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4384 EXPECT_EQ(100, response->headers->GetContentLength());
[email protected]038e9a32008-10-08 22:40:164385}
[email protected]4ddaf2502008-10-23 18:26:194386
[email protected]ea9dc9a2009-09-05 00:43:324387// For the NTLM implementation using SSPI, we skip the NTLM tests since we
4388// can't hook into its internals to cause it to generate predictable NTLM
4389// authorization headers.
4390#if defined(NTLM_PORTABLE)
[email protected]385a4672009-03-11 22:21:294391// The NTLM authentication unit tests were generated by capturing the HTTP
4392// requests and responses using Fiddler 2 and inspecting the generated random
4393// bytes in the debugger.
4394
4395// Enter the correct password and authenticate successfully.
[email protected]23e482282013-06-14 16:08:024396TEST_P(HttpNetworkTransactionTest, NTLMAuth1) {
[email protected]1c773ea12009-04-28 19:58:424397 HttpRequestInfo request;
[email protected]3f918782009-02-28 01:29:244398 request.method = "GET";
4399 request.url = GURL("http://172.22.68.17/kids/login.aspx");
[email protected]2217aa22013-10-11 03:03:544400
4401 // Ensure load is not disrupted by flags which suppress behaviour specific
4402 // to other auth schemes.
4403 request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY;
[email protected]3f918782009-02-28 01:29:244404
[email protected]cb9bf6ca2011-01-28 13:15:274405 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1,
4406 MockGetHostName);
[email protected]bb88e1d32013-05-03 23:11:074407 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274408
[email protected]3f918782009-02-28 01:29:244409 MockWrite data_writes1[] = {
4410 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4411 "Host: 172.22.68.17\r\n"
4412 "Connection: keep-alive\r\n\r\n"),
4413 };
4414
4415 MockRead data_reads1[] = {
4416 MockRead("HTTP/1.1 401 Access Denied\r\n"),
[email protected]aef04272010-06-28 18:03:044417 // Negotiate and NTLM are often requested together. However, we only want
4418 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip
4419 // the header that requests Negotiate for this test.
[email protected]3f918782009-02-28 01:29:244420 MockRead("WWW-Authenticate: NTLM\r\n"),
4421 MockRead("Connection: close\r\n"),
4422 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364423 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]3f918782009-02-28 01:29:244424 // Missing content -- won't matter, as connection will be reset.
[email protected]8ddf8322012-02-23 18:08:064425 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
[email protected]3f918782009-02-28 01:29:244426 };
4427
4428 MockWrite data_writes2[] = {
[email protected]0757e7702009-03-27 04:00:224429 // After restarting with a null identity, this is the
[email protected]3f918782009-02-28 01:29:244430 // request we should be issuing -- the final header line contains a Type
4431 // 1 message.
4432 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4433 "Host: 172.22.68.17\r\n"
4434 "Connection: keep-alive\r\n"
4435 "Authorization: NTLM "
4436 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
4437
4438 // After calling trans->RestartWithAuth(), we should send a Type 3 message
4439 // (the credentials for the origin server). The second request continues
4440 // on the same connection.
4441 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4442 "Host: 172.22.68.17\r\n"
4443 "Connection: keep-alive\r\n"
[email protected]385a4672009-03-11 22:21:294444 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA"
4445 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA"
4446 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW"
4447 "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX"
4448 "ahlhx5I=\r\n\r\n"),
[email protected]3f918782009-02-28 01:29:244449 };
4450
4451 MockRead data_reads2[] = {
4452 // The origin server responds with a Type 2 message.
4453 MockRead("HTTP/1.1 401 Access Denied\r\n"),
4454 MockRead("WWW-Authenticate: NTLM "
[email protected]385a4672009-03-11 22:21:294455 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo"
[email protected]3f918782009-02-28 01:29:244456 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
4457 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
4458 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
4459 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
4460 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
4461 "BtAAAAAAA=\r\n"),
4462 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364463 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]3f918782009-02-28 01:29:244464 MockRead("You are not authorized to view this page\r\n"),
4465
4466 // Lastly we get the desired content.
4467 MockRead("HTTP/1.1 200 OK\r\n"),
4468 MockRead("Content-Type: text/html; charset=utf-8\r\n"),
4469 MockRead("Content-Length: 13\r\n\r\n"),
4470 MockRead("Please Login\r\n"),
[email protected]8ddf8322012-02-23 18:08:064471 MockRead(SYNCHRONOUS, OK),
[email protected]3f918782009-02-28 01:29:244472 };
4473
[email protected]31a2bfe2010-02-09 08:03:394474 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4475 data_writes1, arraysize(data_writes1));
4476 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
4477 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:074478 session_deps_.socket_factory->AddSocketDataProvider(&data1);
4479 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]3f918782009-02-28 01:29:244480
[email protected]49639fa2011-12-20 23:22:414481 TestCompletionCallback callback1;
[email protected]3f918782009-02-28 01:29:244482
[email protected]262eec82013-03-19 21:01:364483 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504484 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:504485
[email protected]49639fa2011-12-20 23:22:414486 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424487 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3f918782009-02-28 01:29:244488
4489 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424490 EXPECT_EQ(OK, rv);
[email protected]3f918782009-02-28 01:29:244491
[email protected]0757e7702009-03-27 04:00:224492 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
4493
[email protected]1c773ea12009-04-28 19:58:424494 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]79cb5c12011-09-12 13:12:044495 ASSERT_FALSE(response == NULL);
4496 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
[email protected]3f918782009-02-28 01:29:244497
[email protected]49639fa2011-12-20 23:22:414498 TestCompletionCallback callback2;
[email protected]10af5fe72011-01-31 16:17:254499
[email protected]f3cf9802011-10-28 18:44:584500 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM),
[email protected]49639fa2011-12-20 23:22:414501 callback2.callback());
[email protected]10af5fe72011-01-31 16:17:254502 EXPECT_EQ(ERR_IO_PENDING, rv);
4503
4504 rv = callback2.WaitForResult();
4505 EXPECT_EQ(OK, rv);
4506
4507 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
4508
4509 response = trans->GetResponseInfo();
4510 ASSERT_TRUE(response != NULL);
[email protected]10af5fe72011-01-31 16:17:254511 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4512
[email protected]49639fa2011-12-20 23:22:414513 TestCompletionCallback callback3;
[email protected]3f918782009-02-28 01:29:244514
[email protected]49639fa2011-12-20 23:22:414515 rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:424516 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]3f918782009-02-28 01:29:244517
[email protected]0757e7702009-03-27 04:00:224518 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424519 EXPECT_EQ(OK, rv);
[email protected]3f918782009-02-28 01:29:244520
4521 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504522 ASSERT_TRUE(response != NULL);
[email protected]3f918782009-02-28 01:29:244523 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4524 EXPECT_EQ(13, response->headers->GetContentLength());
4525}
4526
[email protected]385a4672009-03-11 22:21:294527// Enter a wrong password, and then the correct one.
[email protected]23e482282013-06-14 16:08:024528TEST_P(HttpNetworkTransactionTest, NTLMAuth2) {
[email protected]1c773ea12009-04-28 19:58:424529 HttpRequestInfo request;
[email protected]385a4672009-03-11 22:21:294530 request.method = "GET";
4531 request.url = GURL("http://172.22.68.17/kids/login.aspx");
4532 request.load_flags = 0;
4533
[email protected]cb9bf6ca2011-01-28 13:15:274534 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2,
4535 MockGetHostName);
[email protected]bb88e1d32013-05-03 23:11:074536 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274537
[email protected]385a4672009-03-11 22:21:294538 MockWrite data_writes1[] = {
4539 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4540 "Host: 172.22.68.17\r\n"
4541 "Connection: keep-alive\r\n\r\n"),
4542 };
4543
4544 MockRead data_reads1[] = {
4545 MockRead("HTTP/1.1 401 Access Denied\r\n"),
[email protected]aef04272010-06-28 18:03:044546 // Negotiate and NTLM are often requested together. However, we only want
4547 // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip
4548 // the header that requests Negotiate for this test.
[email protected]385a4672009-03-11 22:21:294549 MockRead("WWW-Authenticate: NTLM\r\n"),
4550 MockRead("Connection: close\r\n"),
4551 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364552 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294553 // Missing content -- won't matter, as connection will be reset.
[email protected]8ddf8322012-02-23 18:08:064554 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
[email protected]385a4672009-03-11 22:21:294555 };
4556
4557 MockWrite data_writes2[] = {
[email protected]0757e7702009-03-27 04:00:224558 // After restarting with a null identity, this is the
[email protected]385a4672009-03-11 22:21:294559 // request we should be issuing -- the final header line contains a Type
4560 // 1 message.
4561 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4562 "Host: 172.22.68.17\r\n"
4563 "Connection: keep-alive\r\n"
4564 "Authorization: NTLM "
4565 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
4566
4567 // After calling trans->RestartWithAuth(), we should send a Type 3 message
4568 // (the credentials for the origin server). The second request continues
4569 // on the same connection.
4570 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4571 "Host: 172.22.68.17\r\n"
4572 "Connection: keep-alive\r\n"
4573 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA"
4574 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA"
4575 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY"
4576 "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj"
4577 "4Ww7b7E=\r\n\r\n"),
4578 };
4579
4580 MockRead data_reads2[] = {
4581 // The origin server responds with a Type 2 message.
4582 MockRead("HTTP/1.1 401 Access Denied\r\n"),
4583 MockRead("WWW-Authenticate: NTLM "
4584 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo"
4585 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
4586 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
4587 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
4588 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
4589 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
4590 "BtAAAAAAA=\r\n"),
4591 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364592 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294593 MockRead("You are not authorized to view this page\r\n"),
4594
4595 // Wrong password.
4596 MockRead("HTTP/1.1 401 Access Denied\r\n"),
[email protected]385a4672009-03-11 22:21:294597 MockRead("WWW-Authenticate: NTLM\r\n"),
4598 MockRead("Connection: close\r\n"),
4599 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364600 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294601 // Missing content -- won't matter, as connection will be reset.
[email protected]8ddf8322012-02-23 18:08:064602 MockRead(SYNCHRONOUS, ERR_UNEXPECTED),
[email protected]385a4672009-03-11 22:21:294603 };
4604
4605 MockWrite data_writes3[] = {
[email protected]0757e7702009-03-27 04:00:224606 // After restarting with a null identity, this is the
[email protected]385a4672009-03-11 22:21:294607 // request we should be issuing -- the final header line contains a Type
4608 // 1 message.
4609 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4610 "Host: 172.22.68.17\r\n"
4611 "Connection: keep-alive\r\n"
4612 "Authorization: NTLM "
4613 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
4614
4615 // After calling trans->RestartWithAuth(), we should send a Type 3 message
4616 // (the credentials for the origin server). The second request continues
4617 // on the same connection.
4618 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
4619 "Host: 172.22.68.17\r\n"
4620 "Connection: keep-alive\r\n"
4621 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA"
4622 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA"
4623 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54"
4624 "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI"
4625 "+4MUm7c=\r\n\r\n"),
4626 };
4627
4628 MockRead data_reads3[] = {
4629 // The origin server responds with a Type 2 message.
4630 MockRead("HTTP/1.1 401 Access Denied\r\n"),
4631 MockRead("WWW-Authenticate: NTLM "
4632 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo"
4633 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
4634 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
4635 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
4636 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
4637 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
4638 "BtAAAAAAA=\r\n"),
4639 MockRead("Content-Length: 42\r\n"),
[email protected]076c85082009-04-10 23:21:364640 MockRead("Content-Type: text/html\r\n\r\n"),
[email protected]385a4672009-03-11 22:21:294641 MockRead("You are not authorized to view this page\r\n"),
4642
4643 // Lastly we get the desired content.
4644 MockRead("HTTP/1.1 200 OK\r\n"),
4645 MockRead("Content-Type: text/html; charset=utf-8\r\n"),
4646 MockRead("Content-Length: 13\r\n\r\n"),
4647 MockRead("Please Login\r\n"),
[email protected]8ddf8322012-02-23 18:08:064648 MockRead(SYNCHRONOUS, OK),
[email protected]385a4672009-03-11 22:21:294649 };
4650
[email protected]31a2bfe2010-02-09 08:03:394651 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4652 data_writes1, arraysize(data_writes1));
4653 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
4654 data_writes2, arraysize(data_writes2));
4655 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
4656 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:074657 session_deps_.socket_factory->AddSocketDataProvider(&data1);
4658 session_deps_.socket_factory->AddSocketDataProvider(&data2);
4659 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]385a4672009-03-11 22:21:294660
[email protected]49639fa2011-12-20 23:22:414661 TestCompletionCallback callback1;
[email protected]385a4672009-03-11 22:21:294662
[email protected]262eec82013-03-19 21:01:364663 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504664 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:504665
[email protected]49639fa2011-12-20 23:22:414666 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424667 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]385a4672009-03-11 22:21:294668
4669 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424670 EXPECT_EQ(OK, rv);
[email protected]385a4672009-03-11 22:21:294671
[email protected]0757e7702009-03-27 04:00:224672 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
[email protected]385a4672009-03-11 22:21:294673
[email protected]1c773ea12009-04-28 19:58:424674 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504675 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:044676 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
[email protected]385a4672009-03-11 22:21:294677
[email protected]49639fa2011-12-20 23:22:414678 TestCompletionCallback callback2;
[email protected]385a4672009-03-11 22:21:294679
[email protected]0757e7702009-03-27 04:00:224680 // Enter the wrong password.
[email protected]f3cf9802011-10-28 18:44:584681 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword),
[email protected]49639fa2011-12-20 23:22:414682 callback2.callback());
[email protected]1c773ea12009-04-28 19:58:424683 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]385a4672009-03-11 22:21:294684
[email protected]10af5fe72011-01-31 16:17:254685 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424686 EXPECT_EQ(OK, rv);
[email protected]385a4672009-03-11 22:21:294687
[email protected]0757e7702009-03-27 04:00:224688 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
[email protected]49639fa2011-12-20 23:22:414689 TestCompletionCallback callback3;
4690 rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:424691 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]10af5fe72011-01-31 16:17:254692 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424693 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:224694 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
4695
4696 response = trans->GetResponseInfo();
[email protected]79cb5c12011-09-12 13:12:044697 ASSERT_FALSE(response == NULL);
4698 EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get()));
[email protected]0757e7702009-03-27 04:00:224699
[email protected]49639fa2011-12-20 23:22:414700 TestCompletionCallback callback4;
[email protected]0757e7702009-03-27 04:00:224701
4702 // Now enter the right password.
[email protected]f3cf9802011-10-28 18:44:584703 rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM),
[email protected]49639fa2011-12-20 23:22:414704 callback4.callback());
[email protected]10af5fe72011-01-31 16:17:254705 EXPECT_EQ(ERR_IO_PENDING, rv);
4706
4707 rv = callback4.WaitForResult();
4708 EXPECT_EQ(OK, rv);
4709
4710 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
4711
[email protected]49639fa2011-12-20 23:22:414712 TestCompletionCallback callback5;
[email protected]10af5fe72011-01-31 16:17:254713
4714 // One more roundtrip
[email protected]49639fa2011-12-20 23:22:414715 rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback());
[email protected]1c773ea12009-04-28 19:58:424716 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]0757e7702009-03-27 04:00:224717
4718 rv = callback5.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424719 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:224720
[email protected]385a4672009-03-11 22:21:294721 response = trans->GetResponseInfo();
4722 EXPECT_TRUE(response->auth_challenge.get() == NULL);
4723 EXPECT_EQ(13, response->headers->GetContentLength());
4724}
[email protected]ea9dc9a2009-09-05 00:43:324725#endif // NTLM_PORTABLE
[email protected]385a4672009-03-11 22:21:294726
[email protected]4ddaf2502008-10-23 18:26:194727// Test reading a server response which has only headers, and no body.
4728// After some maximum number of bytes is consumed, the transaction should
4729// fail with ERR_RESPONSE_HEADERS_TOO_BIG.
[email protected]23e482282013-06-14 16:08:024730TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) {
[email protected]1c773ea12009-04-28 19:58:424731 HttpRequestInfo request;
[email protected]4ddaf2502008-10-23 18:26:194732 request.method = "GET";
4733 request.url = GURL("http://www.google.com/");
4734 request.load_flags = 0;
4735
[email protected]3fe8d2f82013-10-17 08:56:074736 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274737 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:414738 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:274739
[email protected]b75b7b2f2009-10-06 00:54:534740 // Respond with 300 kb of headers (we should fail after 256 kb).
[email protected]15a5ccf82008-10-23 19:57:434741 std::string large_headers_string;
[email protected]b75b7b2f2009-10-06 00:54:534742 FillLargeHeadersString(&large_headers_string, 300 * 1024);
[email protected]4ddaf2502008-10-23 18:26:194743
4744 MockRead data_reads[] = {
4745 MockRead("HTTP/1.0 200 OK\r\n"),
[email protected]8ddf8322012-02-23 18:08:064746 MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()),
[email protected]4ddaf2502008-10-23 18:26:194747 MockRead("\r\nBODY"),
[email protected]8ddf8322012-02-23 18:08:064748 MockRead(SYNCHRONOUS, OK),
[email protected]4ddaf2502008-10-23 18:26:194749 };
[email protected]31a2bfe2010-02-09 08:03:394750 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:074751 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]4ddaf2502008-10-23 18:26:194752
[email protected]49639fa2011-12-20 23:22:414753 TestCompletionCallback callback;
[email protected]4ddaf2502008-10-23 18:26:194754
[email protected]49639fa2011-12-20 23:22:414755 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424756 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]4ddaf2502008-10-23 18:26:194757
4758 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424759 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv);
[email protected]4ddaf2502008-10-23 18:26:194760
[email protected]1c773ea12009-04-28 19:58:424761 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]4ddaf2502008-10-23 18:26:194762 EXPECT_TRUE(response == NULL);
4763}
[email protected]f4e426b2008-11-05 00:24:494764
4765// Make sure that we don't try to reuse a TCPClientSocket when failing to
4766// establish tunnel.
4767// http://code.google.com/p/chromium/issues/detail?id=3772
[email protected]23e482282013-06-14 16:08:024768TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:234769 DontRecycleTransportSocketForSSLTunnel) {
[email protected]cb9bf6ca2011-01-28 13:15:274770 HttpRequestInfo request;
4771 request.method = "GET";
4772 request.url = GURL("https://www.google.com/");
4773 request.load_flags = 0;
4774
[email protected]f4e426b2008-11-05 00:24:494775 // Configure against proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:074776 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]db8f44c2008-12-13 04:52:014777
[email protected]bb88e1d32013-05-03 23:11:074778 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]f4e426b2008-11-05 00:24:494779
[email protected]262eec82013-03-19 21:01:364780 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504781 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]f4e426b2008-11-05 00:24:494782
[email protected]f4e426b2008-11-05 00:24:494783 // Since we have proxy, should try to establish tunnel.
4784 MockWrite data_writes1[] = {
4785 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:454786 "Host: www.google.com\r\n"
4787 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]f4e426b2008-11-05 00:24:494788 };
4789
[email protected]77848d12008-11-14 00:00:224790 // The proxy responds to the connect with a 404, using a persistent
[email protected]f4e426b2008-11-05 00:24:494791 // connection. Usually a proxy would return 501 (not implemented),
4792 // or 200 (tunnel established).
4793 MockRead data_reads1[] = {
4794 MockRead("HTTP/1.1 404 Not Found\r\n"),
4795 MockRead("Content-Length: 10\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064796 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
[email protected]f4e426b2008-11-05 00:24:494797 };
4798
[email protected]31a2bfe2010-02-09 08:03:394799 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
4800 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:074801 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]f4e426b2008-11-05 00:24:494802
[email protected]49639fa2011-12-20 23:22:414803 TestCompletionCallback callback1;
[email protected]f4e426b2008-11-05 00:24:494804
[email protected]49639fa2011-12-20 23:22:414805 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424806 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f4e426b2008-11-05 00:24:494807
4808 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424809 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]f4e426b2008-11-05 00:24:494810
[email protected]1c773ea12009-04-28 19:58:424811 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]c744cf22009-02-27 07:28:084812 EXPECT_TRUE(response == NULL);
[email protected]f4e426b2008-11-05 00:24:494813
[email protected]b4404c02009-04-10 16:38:524814 // Empty the current queue. This is necessary because idle sockets are
4815 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344816 base::MessageLoop::current()->RunUntilIdle();
[email protected]b4404c02009-04-10 16:38:524817
[email protected]f4e426b2008-11-05 00:24:494818 // We now check to make sure the TCPClientSocket was not added back to
4819 // the pool.
[email protected]90499482013-06-01 00:39:504820 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]f4e426b2008-11-05 00:24:494821 trans.reset();
[email protected]2da659e2013-05-23 20:51:344822 base::MessageLoop::current()->RunUntilIdle();
[email protected]f4e426b2008-11-05 00:24:494823 // Make sure that the socket didn't get recycled after calling the destructor.
[email protected]90499482013-06-01 00:39:504824 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]f4e426b2008-11-05 00:24:494825}
[email protected]372d34a2008-11-05 21:30:514826
[email protected]1b157c02009-04-21 01:55:404827// Make sure that we recycle a socket after reading all of the response body.
[email protected]23e482282013-06-14 16:08:024828TEST_P(HttpNetworkTransactionTest, RecycleSocket) {
[email protected]1c773ea12009-04-28 19:58:424829 HttpRequestInfo request;
[email protected]1b157c02009-04-21 01:55:404830 request.method = "GET";
4831 request.url = GURL("http://www.google.com/");
4832 request.load_flags = 0;
4833
[email protected]bb88e1d32013-05-03 23:11:074834 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:274835
[email protected]262eec82013-03-19 21:01:364836 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504837 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:274838
[email protected]1b157c02009-04-21 01:55:404839 MockRead data_reads[] = {
4840 // A part of the response body is received with the response headers.
4841 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"),
4842 // The rest of the response body is received in two parts.
4843 MockRead("lo"),
4844 MockRead(" world"),
4845 MockRead("junk"), // Should not be read!!
[email protected]8ddf8322012-02-23 18:08:064846 MockRead(SYNCHRONOUS, OK),
[email protected]1b157c02009-04-21 01:55:404847 };
4848
[email protected]31a2bfe2010-02-09 08:03:394849 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:074850 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1b157c02009-04-21 01:55:404851
[email protected]49639fa2011-12-20 23:22:414852 TestCompletionCallback callback;
[email protected]1b157c02009-04-21 01:55:404853
[email protected]49639fa2011-12-20 23:22:414854 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:424855 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]1b157c02009-04-21 01:55:404856
4857 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:424858 EXPECT_EQ(OK, rv);
[email protected]1b157c02009-04-21 01:55:404859
[email protected]1c773ea12009-04-28 19:58:424860 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:504861 ASSERT_TRUE(response != NULL);
[email protected]1b157c02009-04-21 01:55:404862
[email protected]90499482013-06-01 00:39:504863 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]1b157c02009-04-21 01:55:404864 std::string status_line = response->headers->GetStatusLine();
4865 EXPECT_EQ("HTTP/1.1 200 OK", status_line);
4866
[email protected]90499482013-06-01 00:39:504867 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]1b157c02009-04-21 01:55:404868
4869 std::string response_data;
4870 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:424871 EXPECT_EQ(OK, rv);
[email protected]1b157c02009-04-21 01:55:404872 EXPECT_EQ("hello world", response_data);
4873
4874 // Empty the current queue. This is necessary because idle sockets are
4875 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344876 base::MessageLoop::current()->RunUntilIdle();
[email protected]1b157c02009-04-21 01:55:404877
4878 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:504879 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]1b157c02009-04-21 01:55:404880}
4881
[email protected]76a505b2010-08-25 06:23:004882// Make sure that we recycle a SSL socket after reading all of the response
4883// body.
[email protected]23e482282013-06-14 16:08:024884TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) {
[email protected]76a505b2010-08-25 06:23:004885 HttpRequestInfo request;
4886 request.method = "GET";
4887 request.url = GURL("https://www.google.com/");
4888 request.load_flags = 0;
4889
4890 MockWrite data_writes[] = {
4891 MockWrite("GET / HTTP/1.1\r\n"
4892 "Host: www.google.com\r\n"
4893 "Connection: keep-alive\r\n\r\n"),
4894 };
4895
4896 MockRead data_reads[] = {
4897 MockRead("HTTP/1.1 200 OK\r\n"),
4898 MockRead("Content-Length: 11\r\n\r\n"),
4899 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:064900 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:004901 };
4902
[email protected]8ddf8322012-02-23 18:08:064903 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:074904 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:004905
4906 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4907 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:074908 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]76a505b2010-08-25 06:23:004909
[email protected]49639fa2011-12-20 23:22:414910 TestCompletionCallback callback;
[email protected]76a505b2010-08-25 06:23:004911
[email protected]bb88e1d32013-05-03 23:11:074912 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:364913 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504914 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]76a505b2010-08-25 06:23:004915
[email protected]49639fa2011-12-20 23:22:414916 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]76a505b2010-08-25 06:23:004917
4918 EXPECT_EQ(ERR_IO_PENDING, rv);
4919 EXPECT_EQ(OK, callback.WaitForResult());
4920
4921 const HttpResponseInfo* response = trans->GetResponseInfo();
4922 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:504923 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]76a505b2010-08-25 06:23:004924 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4925
[email protected]90499482013-06-01 00:39:504926 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004927
4928 std::string response_data;
4929 rv = ReadTransaction(trans.get(), &response_data);
4930 EXPECT_EQ(OK, rv);
4931 EXPECT_EQ("hello world", response_data);
4932
4933 // Empty the current queue. This is necessary because idle sockets are
4934 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:344935 base::MessageLoop::current()->RunUntilIdle();
[email protected]76a505b2010-08-25 06:23:004936
4937 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:504938 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004939}
4940
4941// Grab a SSL socket, use it, and put it back into the pool. Then, reuse it
4942// from the pool and make sure that we recover okay.
[email protected]23e482282013-06-14 16:08:024943TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) {
[email protected]76a505b2010-08-25 06:23:004944 HttpRequestInfo request;
4945 request.method = "GET";
4946 request.url = GURL("https://www.google.com/");
4947 request.load_flags = 0;
4948
4949 MockWrite data_writes[] = {
4950 MockWrite("GET / HTTP/1.1\r\n"
4951 "Host: www.google.com\r\n"
4952 "Connection: keep-alive\r\n\r\n"),
4953 MockWrite("GET / HTTP/1.1\r\n"
4954 "Host: www.google.com\r\n"
4955 "Connection: keep-alive\r\n\r\n"),
4956 };
4957
4958 MockRead data_reads[] = {
4959 MockRead("HTTP/1.1 200 OK\r\n"),
4960 MockRead("Content-Length: 11\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:064961 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]76a505b2010-08-25 06:23:004962 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:064963 MockRead(ASYNC, 0, 0) // EOF
[email protected]76a505b2010-08-25 06:23:004964 };
4965
[email protected]8ddf8322012-02-23 18:08:064966 SSLSocketDataProvider ssl(ASYNC, OK);
4967 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:074968 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
4969 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
[email protected]76a505b2010-08-25 06:23:004970
4971 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
4972 data_writes, arraysize(data_writes));
4973 StaticSocketDataProvider data2(data_reads, arraysize(data_reads),
4974 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:074975 session_deps_.socket_factory->AddSocketDataProvider(&data);
4976 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]76a505b2010-08-25 06:23:004977
[email protected]49639fa2011-12-20 23:22:414978 TestCompletionCallback callback;
[email protected]76a505b2010-08-25 06:23:004979
[email protected]bb88e1d32013-05-03 23:11:074980 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:364981 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:504982 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]76a505b2010-08-25 06:23:004983
[email protected]49639fa2011-12-20 23:22:414984 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]76a505b2010-08-25 06:23:004985
4986 EXPECT_EQ(ERR_IO_PENDING, rv);
4987 EXPECT_EQ(OK, callback.WaitForResult());
4988
4989 const HttpResponseInfo* response = trans->GetResponseInfo();
4990 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:504991 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]76a505b2010-08-25 06:23:004992 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
4993
[email protected]90499482013-06-01 00:39:504994 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:004995
4996 std::string response_data;
4997 rv = ReadTransaction(trans.get(), &response_data);
4998 EXPECT_EQ(OK, rv);
4999 EXPECT_EQ("hello world", response_data);
5000
5001 // Empty the current queue. This is necessary because idle sockets are
5002 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:345003 base::MessageLoop::current()->RunUntilIdle();
[email protected]76a505b2010-08-25 06:23:005004
5005 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:505006 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:005007
5008 // Now start the second transaction, which should reuse the previous socket.
5009
[email protected]90499482013-06-01 00:39:505010 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]76a505b2010-08-25 06:23:005011
[email protected]49639fa2011-12-20 23:22:415012 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]76a505b2010-08-25 06:23:005013
5014 EXPECT_EQ(ERR_IO_PENDING, rv);
5015 EXPECT_EQ(OK, callback.WaitForResult());
5016
5017 response = trans->GetResponseInfo();
5018 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:505019 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]76a505b2010-08-25 06:23:005020 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
5021
[email protected]90499482013-06-01 00:39:505022 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:005023
5024 rv = ReadTransaction(trans.get(), &response_data);
5025 EXPECT_EQ(OK, rv);
5026 EXPECT_EQ("hello world", response_data);
5027
5028 // Empty the current queue. This is necessary because idle sockets are
5029 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:345030 base::MessageLoop::current()->RunUntilIdle();
[email protected]76a505b2010-08-25 06:23:005031
5032 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:505033 EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]76a505b2010-08-25 06:23:005034}
5035
[email protected]b4404c02009-04-10 16:38:525036// Make sure that we recycle a socket after a zero-length response.
5037// http://crbug.com/9880
[email protected]23e482282013-06-14 16:08:025038TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) {
[email protected]1c773ea12009-04-28 19:58:425039 HttpRequestInfo request;
[email protected]b4404c02009-04-10 16:38:525040 request.method = "GET";
5041 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&"
5042 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&"
5043 "e=17259,18167,19592,19773,19981,20133,20173,20233&"
5044 "rt=prt.2642,ol.2649,xjs.2951");
5045 request.load_flags = 0;
5046
[email protected]bb88e1d32013-05-03 23:11:075047 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:275048
[email protected]262eec82013-03-19 21:01:365049 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505050 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275051
[email protected]b4404c02009-04-10 16:38:525052 MockRead data_reads[] = {
5053 MockRead("HTTP/1.1 204 No Content\r\n"
5054 "Content-Length: 0\r\n"
5055 "Content-Type: text/html\r\n\r\n"),
5056 MockRead("junk"), // Should not be read!!
[email protected]8ddf8322012-02-23 18:08:065057 MockRead(SYNCHRONOUS, OK),
[email protected]b4404c02009-04-10 16:38:525058 };
5059
[email protected]31a2bfe2010-02-09 08:03:395060 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:075061 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]b4404c02009-04-10 16:38:525062
[email protected]49639fa2011-12-20 23:22:415063 TestCompletionCallback callback;
[email protected]b4404c02009-04-10 16:38:525064
[email protected]49639fa2011-12-20 23:22:415065 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425066 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]b4404c02009-04-10 16:38:525067
5068 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425069 EXPECT_EQ(OK, rv);
[email protected]b4404c02009-04-10 16:38:525070
[email protected]1c773ea12009-04-28 19:58:425071 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505072 ASSERT_TRUE(response != NULL);
[email protected]b4404c02009-04-10 16:38:525073
[email protected]90499482013-06-01 00:39:505074 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]b4404c02009-04-10 16:38:525075 std::string status_line = response->headers->GetStatusLine();
5076 EXPECT_EQ("HTTP/1.1 204 No Content", status_line);
5077
[email protected]90499482013-06-01 00:39:505078 EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]b4404c02009-04-10 16:38:525079
5080 std::string response_data;
5081 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:425082 EXPECT_EQ(OK, rv);
[email protected]b4404c02009-04-10 16:38:525083 EXPECT_EQ("", response_data);
5084
5085 // Empty the current queue. This is necessary because idle sockets are
5086 // added to the connection pool asynchronously with a PostTask.
[email protected]2da659e2013-05-23 20:51:345087 base::MessageLoop::current()->RunUntilIdle();
[email protected]b4404c02009-04-10 16:38:525088
5089 // We now check to make sure the socket was added back to the pool.
[email protected]90499482013-06-01 00:39:505090 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]b4404c02009-04-10 16:38:525091}
5092
[email protected]23e482282013-06-14 16:08:025093TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) {
[email protected]b2d26cfd2012-12-11 10:36:065094 ScopedVector<UploadElementReader> element_readers;
5095 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:075096 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:275097
[email protected]1c773ea12009-04-28 19:58:425098 HttpRequestInfo request[2];
[email protected]372d34a2008-11-05 21:30:515099 // Transaction 1: a GET request that succeeds. The socket is recycled
5100 // after use.
5101 request[0].method = "GET";
5102 request[0].url = GURL("http://www.google.com/");
5103 request[0].load_flags = 0;
5104 // Transaction 2: a POST request. Reuses the socket kept alive from
5105 // transaction 1. The first attempts fails when writing the POST data.
5106 // This causes the transaction to retry with a new socket. The second
5107 // attempt succeeds.
5108 request[1].method = "POST";
5109 request[1].url = GURL("http://www.google.com/login.cgi");
[email protected]329b68b2012-11-14 17:54:275110 request[1].upload_data_stream = &upload_data_stream;
[email protected]372d34a2008-11-05 21:30:515111 request[1].load_flags = 0;
5112
[email protected]bb88e1d32013-05-03 23:11:075113 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]372d34a2008-11-05 21:30:515114
5115 // The first socket is used for transaction 1 and the first attempt of
5116 // transaction 2.
5117
5118 // The response of transaction 1.
5119 MockRead data_reads1[] = {
5120 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"),
5121 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:065122 MockRead(SYNCHRONOUS, OK),
[email protected]372d34a2008-11-05 21:30:515123 };
5124 // The mock write results of transaction 1 and the first attempt of
5125 // transaction 2.
5126 MockWrite data_writes1[] = {
[email protected]8ddf8322012-02-23 18:08:065127 MockWrite(SYNCHRONOUS, 64), // GET
5128 MockWrite(SYNCHRONOUS, 93), // POST
5129 MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data
[email protected]372d34a2008-11-05 21:30:515130 };
[email protected]31a2bfe2010-02-09 08:03:395131 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5132 data_writes1, arraysize(data_writes1));
[email protected]372d34a2008-11-05 21:30:515133
5134 // The second socket is used for the second attempt of transaction 2.
5135
5136 // The response of transaction 2.
5137 MockRead data_reads2[] = {
5138 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"),
5139 MockRead("welcome"),
[email protected]8ddf8322012-02-23 18:08:065140 MockRead(SYNCHRONOUS, OK),
[email protected]372d34a2008-11-05 21:30:515141 };
5142 // The mock write results of the second attempt of transaction 2.
5143 MockWrite data_writes2[] = {
[email protected]8ddf8322012-02-23 18:08:065144 MockWrite(SYNCHRONOUS, 93), // POST
5145 MockWrite(SYNCHRONOUS, 3), // POST data
[email protected]372d34a2008-11-05 21:30:515146 };
[email protected]31a2bfe2010-02-09 08:03:395147 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5148 data_writes2, arraysize(data_writes2));
[email protected]372d34a2008-11-05 21:30:515149
[email protected]bb88e1d32013-05-03 23:11:075150 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5151 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]372d34a2008-11-05 21:30:515152
thestig9d3bb0c2015-01-24 00:49:515153 const char* const kExpectedResponseData[] = {
[email protected]372d34a2008-11-05 21:30:515154 "hello world", "welcome"
5155 };
5156
5157 for (int i = 0; i < 2; ++i) {
[email protected]1c773ea12009-04-28 19:58:425158 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505159 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]372d34a2008-11-05 21:30:515160
[email protected]49639fa2011-12-20 23:22:415161 TestCompletionCallback callback;
[email protected]372d34a2008-11-05 21:30:515162
[email protected]49639fa2011-12-20 23:22:415163 int rv = trans->Start(&request[i], callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425164 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]372d34a2008-11-05 21:30:515165
5166 rv = callback.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425167 EXPECT_EQ(OK, rv);
[email protected]372d34a2008-11-05 21:30:515168
[email protected]1c773ea12009-04-28 19:58:425169 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505170 ASSERT_TRUE(response != NULL);
[email protected]372d34a2008-11-05 21:30:515171
[email protected]90499482013-06-01 00:39:505172 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]372d34a2008-11-05 21:30:515173 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
5174
5175 std::string response_data;
5176 rv = ReadTransaction(trans.get(), &response_data);
[email protected]1c773ea12009-04-28 19:58:425177 EXPECT_EQ(OK, rv);
[email protected]372d34a2008-11-05 21:30:515178 EXPECT_EQ(kExpectedResponseData[i], response_data);
5179 }
5180}
[email protected]f9ee6b52008-11-08 06:46:235181
5182// Test the request-challenge-retry sequence for basic auth when there is
5183// an identity in the URL. The request should be sent as normal, but when
[email protected]2262e3a2012-05-22 16:08:165184// it fails the identity from the URL is used to answer the challenge.
[email protected]23e482282013-06-14 16:08:025185TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) {
[email protected]1c773ea12009-04-28 19:58:425186 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235187 request.method = "GET";
[email protected]a97cca42009-08-14 01:00:295188 request.url = GURL("http://foo:b@[email protected]/");
[email protected]7b08ba62012-02-10 20:19:415189 request.load_flags = LOAD_NORMAL;
[email protected]a97cca42009-08-14 01:00:295190
[email protected]3fe8d2f82013-10-17 08:56:075191 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:275192 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:415193 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275194
[email protected]a97cca42009-08-14 01:00:295195 // The password contains an escaped character -- for this test to pass it
5196 // will need to be unescaped by HttpNetworkTransaction.
5197 EXPECT_EQ("b%40r", request.url.password());
5198
[email protected]f9ee6b52008-11-08 06:46:235199 MockWrite data_writes1[] = {
5200 MockWrite("GET / HTTP/1.1\r\n"
5201 "Host: www.google.com\r\n"
5202 "Connection: keep-alive\r\n\r\n"),
5203 };
5204
5205 MockRead data_reads1[] = {
5206 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5207 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5208 MockRead("Content-Length: 10\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065209 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235210 };
5211
[email protected]2262e3a2012-05-22 16:08:165212 // After the challenge above, the transaction will be restarted using the
5213 // identity from the url (foo, b@r) to answer the challenge.
5214 MockWrite data_writes2[] = {
5215 MockWrite("GET / HTTP/1.1\r\n"
5216 "Host: www.google.com\r\n"
5217 "Connection: keep-alive\r\n"
5218 "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"),
5219 };
5220
5221 MockRead data_reads2[] = {
5222 MockRead("HTTP/1.0 200 OK\r\n"),
5223 MockRead("Content-Length: 100\r\n\r\n"),
5224 MockRead(SYNCHRONOUS, OK),
5225 };
5226
[email protected]31a2bfe2010-02-09 08:03:395227 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5228 data_writes1, arraysize(data_writes1));
[email protected]2262e3a2012-05-22 16:08:165229 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5230 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075231 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5232 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235233
[email protected]49639fa2011-12-20 23:22:415234 TestCompletionCallback callback1;
[email protected]49639fa2011-12-20 23:22:415235 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425236 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235237 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425238 EXPECT_EQ(OK, rv);
[email protected]2262e3a2012-05-22 16:08:165239 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
5240
5241 TestCompletionCallback callback2;
5242 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
5243 EXPECT_EQ(ERR_IO_PENDING, rv);
5244 rv = callback2.WaitForResult();
5245 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:225246 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5247
[email protected]2262e3a2012-05-22 16:08:165248 const HttpResponseInfo* response = trans->GetResponseInfo();
5249 ASSERT_TRUE(response != NULL);
5250
5251 // There is no challenge info, since the identity in URL worked.
5252 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5253
5254 EXPECT_EQ(100, response->headers->GetContentLength());
5255
5256 // Empty the current queue.
[email protected]2da659e2013-05-23 20:51:345257 base::MessageLoop::current()->RunUntilIdle();
[email protected]2262e3a2012-05-22 16:08:165258}
5259
5260// Test the request-challenge-retry sequence for basic auth when there is an
5261// incorrect identity in the URL. The identity from the URL should be used only
5262// once.
[email protected]23e482282013-06-14 16:08:025263TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) {
[email protected]2262e3a2012-05-22 16:08:165264 HttpRequestInfo request;
5265 request.method = "GET";
5266 // Note: the URL has a username:password in it. The password "baz" is
5267 // wrong (should be "bar").
5268 request.url = GURL("http://foo:[email protected]/");
5269
5270 request.load_flags = LOAD_NORMAL;
5271
[email protected]3fe8d2f82013-10-17 08:56:075272 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2262e3a2012-05-22 16:08:165273 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:415274 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2262e3a2012-05-22 16:08:165275
5276 MockWrite data_writes1[] = {
5277 MockWrite("GET / HTTP/1.1\r\n"
5278 "Host: www.google.com\r\n"
5279 "Connection: keep-alive\r\n\r\n"),
5280 };
5281
5282 MockRead data_reads1[] = {
5283 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5284 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5285 MockRead("Content-Length: 10\r\n\r\n"),
5286 MockRead(SYNCHRONOUS, ERR_FAILED),
5287 };
5288
5289 // After the challenge above, the transaction will be restarted using the
5290 // identity from the url (foo, baz) to answer the challenge.
5291 MockWrite data_writes2[] = {
5292 MockWrite("GET / HTTP/1.1\r\n"
5293 "Host: www.google.com\r\n"
5294 "Connection: keep-alive\r\n"
5295 "Authorization: Basic Zm9vOmJheg==\r\n\r\n"),
5296 };
5297
5298 MockRead data_reads2[] = {
5299 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5300 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5301 MockRead("Content-Length: 10\r\n\r\n"),
5302 MockRead(SYNCHRONOUS, ERR_FAILED),
5303 };
5304
5305 // After the challenge above, the transaction will be restarted using the
5306 // identity supplied by the user (foo, bar) to answer the challenge.
5307 MockWrite data_writes3[] = {
5308 MockWrite("GET / HTTP/1.1\r\n"
5309 "Host: www.google.com\r\n"
5310 "Connection: keep-alive\r\n"
5311 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5312 };
5313
5314 MockRead data_reads3[] = {
5315 MockRead("HTTP/1.0 200 OK\r\n"),
5316 MockRead("Content-Length: 100\r\n\r\n"),
5317 MockRead(SYNCHRONOUS, OK),
5318 };
5319
5320 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5321 data_writes1, arraysize(data_writes1));
5322 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5323 data_writes2, arraysize(data_writes2));
5324 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
5325 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:075326 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5327 session_deps_.socket_factory->AddSocketDataProvider(&data2);
5328 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]2262e3a2012-05-22 16:08:165329
5330 TestCompletionCallback callback1;
5331
5332 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
5333 EXPECT_EQ(ERR_IO_PENDING, rv);
5334
5335 rv = callback1.WaitForResult();
5336 EXPECT_EQ(OK, rv);
5337
5338 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
5339 TestCompletionCallback callback2;
5340 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
5341 EXPECT_EQ(ERR_IO_PENDING, rv);
5342 rv = callback2.WaitForResult();
5343 EXPECT_EQ(OK, rv);
5344 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5345
5346 const HttpResponseInfo* response = trans->GetResponseInfo();
5347 ASSERT_TRUE(response != NULL);
5348 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
5349
5350 TestCompletionCallback callback3;
5351 rv = trans->RestartWithAuth(
5352 AuthCredentials(kFoo, kBar), callback3.callback());
5353 EXPECT_EQ(ERR_IO_PENDING, rv);
5354 rv = callback3.WaitForResult();
5355 EXPECT_EQ(OK, rv);
5356 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5357
5358 response = trans->GetResponseInfo();
5359 ASSERT_TRUE(response != NULL);
5360
5361 // There is no challenge info, since the identity worked.
5362 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5363
5364 EXPECT_EQ(100, response->headers->GetContentLength());
5365
[email protected]ea9dc9a2009-09-05 00:43:325366 // Empty the current queue.
[email protected]2da659e2013-05-23 20:51:345367 base::MessageLoop::current()->RunUntilIdle();
[email protected]ea9dc9a2009-09-05 00:43:325368}
5369
[email protected]2217aa22013-10-11 03:03:545370
5371// Test the request-challenge-retry sequence for basic auth when there is a
5372// correct identity in the URL, but its use is being suppressed. The identity
5373// from the URL should never be used.
5374TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) {
5375 HttpRequestInfo request;
5376 request.method = "GET";
5377 request.url = GURL("http://foo:[email protected]/");
5378 request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY;
5379
[email protected]3fe8d2f82013-10-17 08:56:075380 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2217aa22013-10-11 03:03:545381 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:415382 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2217aa22013-10-11 03:03:545383
5384 MockWrite data_writes1[] = {
5385 MockWrite("GET / HTTP/1.1\r\n"
5386 "Host: www.google.com\r\n"
5387 "Connection: keep-alive\r\n\r\n"),
5388 };
5389
5390 MockRead data_reads1[] = {
5391 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5392 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5393 MockRead("Content-Length: 10\r\n\r\n"),
5394 MockRead(SYNCHRONOUS, ERR_FAILED),
5395 };
5396
5397 // After the challenge above, the transaction will be restarted using the
5398 // identity supplied by the user, not the one in the URL, to answer the
5399 // challenge.
5400 MockWrite data_writes3[] = {
5401 MockWrite("GET / HTTP/1.1\r\n"
5402 "Host: www.google.com\r\n"
5403 "Connection: keep-alive\r\n"
5404 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5405 };
5406
5407 MockRead data_reads3[] = {
5408 MockRead("HTTP/1.0 200 OK\r\n"),
5409 MockRead("Content-Length: 100\r\n\r\n"),
5410 MockRead(SYNCHRONOUS, OK),
5411 };
5412
5413 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5414 data_writes1, arraysize(data_writes1));
5415 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
5416 data_writes3, arraysize(data_writes3));
5417 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5418 session_deps_.socket_factory->AddSocketDataProvider(&data3);
5419
5420 TestCompletionCallback callback1;
5421 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
5422 EXPECT_EQ(ERR_IO_PENDING, rv);
5423 rv = callback1.WaitForResult();
5424 EXPECT_EQ(OK, rv);
5425 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5426
5427 const HttpResponseInfo* response = trans->GetResponseInfo();
5428 ASSERT_TRUE(response != NULL);
5429 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
5430
5431 TestCompletionCallback callback3;
5432 rv = trans->RestartWithAuth(
5433 AuthCredentials(kFoo, kBar), callback3.callback());
5434 EXPECT_EQ(ERR_IO_PENDING, rv);
5435 rv = callback3.WaitForResult();
5436 EXPECT_EQ(OK, rv);
5437 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5438
5439 response = trans->GetResponseInfo();
5440 ASSERT_TRUE(response != NULL);
5441
5442 // There is no challenge info, since the identity worked.
5443 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5444 EXPECT_EQ(100, response->headers->GetContentLength());
5445
5446 // Empty the current queue.
5447 base::MessageLoop::current()->RunUntilIdle();
5448}
5449
[email protected]f9ee6b52008-11-08 06:46:235450// Test that previously tried username/passwords for a realm get re-used.
[email protected]23e482282013-06-14 16:08:025451TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) {
[email protected]bb88e1d32013-05-03 23:11:075452 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]f9ee6b52008-11-08 06:46:235453
5454 // Transaction 1: authenticate (foo, bar) on MyRealm1
5455 {
[email protected]1c773ea12009-04-28 19:58:425456 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235457 request.method = "GET";
5458 request.url = GURL("http://www.google.com/x/y/z");
5459 request.load_flags = 0;
5460
[email protected]262eec82013-03-19 21:01:365461 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505462 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275463
[email protected]f9ee6b52008-11-08 06:46:235464 MockWrite data_writes1[] = {
5465 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5466 "Host: www.google.com\r\n"
5467 "Connection: keep-alive\r\n\r\n"),
5468 };
5469
5470 MockRead data_reads1[] = {
5471 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5472 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5473 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065474 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235475 };
5476
5477 // Resend with authorization (username=foo, password=bar)
5478 MockWrite data_writes2[] = {
5479 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5480 "Host: www.google.com\r\n"
5481 "Connection: keep-alive\r\n"
5482 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5483 };
5484
5485 // Sever accepts the authorization.
5486 MockRead data_reads2[] = {
5487 MockRead("HTTP/1.0 200 OK\r\n"),
5488 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065489 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235490 };
5491
[email protected]31a2bfe2010-02-09 08:03:395492 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5493 data_writes1, arraysize(data_writes1));
5494 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5495 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075496 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5497 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235498
[email protected]49639fa2011-12-20 23:22:415499 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235500
[email protected]49639fa2011-12-20 23:22:415501 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425502 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235503
5504 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425505 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235506
[email protected]1c773ea12009-04-28 19:58:425507 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505508 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045509 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]f9ee6b52008-11-08 06:46:235510
[email protected]49639fa2011-12-20 23:22:415511 TestCompletionCallback callback2;
[email protected]f9ee6b52008-11-08 06:46:235512
[email protected]49639fa2011-12-20 23:22:415513 rv = trans->RestartWithAuth(
5514 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425515 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235516
5517 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425518 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235519
5520 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505521 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235522 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5523 EXPECT_EQ(100, response->headers->GetContentLength());
5524 }
5525
5526 // ------------------------------------------------------------------------
5527
5528 // Transaction 2: authenticate (foo2, bar2) on MyRealm2
5529 {
[email protected]1c773ea12009-04-28 19:58:425530 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235531 request.method = "GET";
5532 // Note that Transaction 1 was at /x/y/z, so this is in the same
5533 // protection space as MyRealm1.
5534 request.url = GURL("http://www.google.com/x/y/a/b");
5535 request.load_flags = 0;
5536
[email protected]262eec82013-03-19 21:01:365537 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505538 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275539
[email protected]f9ee6b52008-11-08 06:46:235540 MockWrite data_writes1[] = {
5541 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
5542 "Host: www.google.com\r\n"
5543 "Connection: keep-alive\r\n"
5544 // Send preemptive authorization for MyRealm1
5545 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5546 };
5547
5548 // The server didn't like the preemptive authorization, and
5549 // challenges us for a different realm (MyRealm2).
5550 MockRead data_reads1[] = {
5551 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5552 MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"),
5553 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065554 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235555 };
5556
5557 // Resend with authorization for MyRealm2 (username=foo2, password=bar2)
5558 MockWrite data_writes2[] = {
5559 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
5560 "Host: www.google.com\r\n"
5561 "Connection: keep-alive\r\n"
5562 "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"),
5563 };
5564
5565 // Sever accepts the authorization.
5566 MockRead data_reads2[] = {
5567 MockRead("HTTP/1.0 200 OK\r\n"),
5568 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065569 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235570 };
5571
[email protected]31a2bfe2010-02-09 08:03:395572 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5573 data_writes1, arraysize(data_writes1));
5574 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5575 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075576 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5577 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235578
[email protected]49639fa2011-12-20 23:22:415579 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235580
[email protected]49639fa2011-12-20 23:22:415581 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425582 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235583
5584 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425585 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235586
[email protected]1c773ea12009-04-28 19:58:425587 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505588 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045589 ASSERT_TRUE(response->auth_challenge.get());
5590 EXPECT_FALSE(response->auth_challenge->is_proxy);
5591 EXPECT_EQ("www.google.com:80",
5592 response->auth_challenge->challenger.ToString());
5593 EXPECT_EQ("MyRealm2", response->auth_challenge->realm);
5594 EXPECT_EQ("basic", response->auth_challenge->scheme);
[email protected]f9ee6b52008-11-08 06:46:235595
[email protected]49639fa2011-12-20 23:22:415596 TestCompletionCallback callback2;
[email protected]f9ee6b52008-11-08 06:46:235597
[email protected]49639fa2011-12-20 23:22:415598 rv = trans->RestartWithAuth(
5599 AuthCredentials(kFoo2, kBar2), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425600 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235601
5602 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425603 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235604
5605 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505606 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235607 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5608 EXPECT_EQ(100, response->headers->GetContentLength());
5609 }
5610
5611 // ------------------------------------------------------------------------
5612
5613 // Transaction 3: Resend a request in MyRealm's protection space --
5614 // succeed with preemptive authorization.
5615 {
[email protected]1c773ea12009-04-28 19:58:425616 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235617 request.method = "GET";
5618 request.url = GURL("http://www.google.com/x/y/z2");
5619 request.load_flags = 0;
5620
[email protected]262eec82013-03-19 21:01:365621 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505622 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275623
[email protected]f9ee6b52008-11-08 06:46:235624 MockWrite data_writes1[] = {
5625 MockWrite("GET /x/y/z2 HTTP/1.1\r\n"
5626 "Host: www.google.com\r\n"
5627 "Connection: keep-alive\r\n"
5628 // The authorization for MyRealm1 gets sent preemptively
5629 // (since the url is in the same protection space)
5630 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5631 };
5632
5633 // Sever accepts the preemptive authorization
5634 MockRead data_reads1[] = {
5635 MockRead("HTTP/1.0 200 OK\r\n"),
5636 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065637 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235638 };
5639
[email protected]31a2bfe2010-02-09 08:03:395640 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5641 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:075642 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]f9ee6b52008-11-08 06:46:235643
[email protected]49639fa2011-12-20 23:22:415644 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235645
[email protected]49639fa2011-12-20 23:22:415646 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425647 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235648
5649 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425650 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235651
[email protected]1c773ea12009-04-28 19:58:425652 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505653 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235654
5655 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5656 EXPECT_EQ(100, response->headers->GetContentLength());
5657 }
5658
5659 // ------------------------------------------------------------------------
5660
5661 // Transaction 4: request another URL in MyRealm (however the
5662 // url is not known to belong to the protection space, so no pre-auth).
5663 {
[email protected]1c773ea12009-04-28 19:58:425664 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235665 request.method = "GET";
5666 request.url = GURL("http://www.google.com/x/1");
5667 request.load_flags = 0;
5668
[email protected]262eec82013-03-19 21:01:365669 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505670 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275671
[email protected]f9ee6b52008-11-08 06:46:235672 MockWrite data_writes1[] = {
5673 MockWrite("GET /x/1 HTTP/1.1\r\n"
5674 "Host: www.google.com\r\n"
5675 "Connection: keep-alive\r\n\r\n"),
5676 };
5677
5678 MockRead data_reads1[] = {
5679 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5680 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5681 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065682 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235683 };
5684
5685 // Resend with authorization from MyRealm's cache.
5686 MockWrite data_writes2[] = {
5687 MockWrite("GET /x/1 HTTP/1.1\r\n"
5688 "Host: www.google.com\r\n"
5689 "Connection: keep-alive\r\n"
5690 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5691 };
5692
5693 // Sever accepts the authorization.
5694 MockRead data_reads2[] = {
5695 MockRead("HTTP/1.0 200 OK\r\n"),
5696 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065697 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235698 };
5699
[email protected]31a2bfe2010-02-09 08:03:395700 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5701 data_writes1, arraysize(data_writes1));
5702 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5703 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075704 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5705 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]f9ee6b52008-11-08 06:46:235706
[email protected]49639fa2011-12-20 23:22:415707 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235708
[email protected]49639fa2011-12-20 23:22:415709 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425710 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235711
5712 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425713 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235714
[email protected]0757e7702009-03-27 04:00:225715 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
[email protected]49639fa2011-12-20 23:22:415716 TestCompletionCallback callback2;
5717 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425718 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]0757e7702009-03-27 04:00:225719 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425720 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:225721 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5722
[email protected]1c773ea12009-04-28 19:58:425723 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505724 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235725 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5726 EXPECT_EQ(100, response->headers->GetContentLength());
5727 }
5728
5729 // ------------------------------------------------------------------------
5730
5731 // Transaction 5: request a URL in MyRealm, but the server rejects the
5732 // cached identity. Should invalidate and re-prompt.
5733 {
[email protected]1c773ea12009-04-28 19:58:425734 HttpRequestInfo request;
[email protected]f9ee6b52008-11-08 06:46:235735 request.method = "GET";
5736 request.url = GURL("http://www.google.com/p/q/t");
5737 request.load_flags = 0;
5738
[email protected]262eec82013-03-19 21:01:365739 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505740 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275741
[email protected]f9ee6b52008-11-08 06:46:235742 MockWrite data_writes1[] = {
5743 MockWrite("GET /p/q/t HTTP/1.1\r\n"
5744 "Host: www.google.com\r\n"
5745 "Connection: keep-alive\r\n\r\n"),
5746 };
5747
5748 MockRead data_reads1[] = {
5749 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5750 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5751 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065752 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235753 };
5754
5755 // Resend with authorization from cache for MyRealm.
5756 MockWrite data_writes2[] = {
5757 MockWrite("GET /p/q/t HTTP/1.1\r\n"
5758 "Host: www.google.com\r\n"
5759 "Connection: keep-alive\r\n"
5760 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
5761 };
5762
5763 // Sever rejects the authorization.
5764 MockRead data_reads2[] = {
5765 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5766 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
5767 MockRead("Content-Length: 10000\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065768 MockRead(SYNCHRONOUS, ERR_FAILED),
[email protected]f9ee6b52008-11-08 06:46:235769 };
5770
5771 // At this point we should prompt for new credentials for MyRealm.
5772 // Restart with username=foo3, password=foo4.
5773 MockWrite data_writes3[] = {
5774 MockWrite("GET /p/q/t HTTP/1.1\r\n"
5775 "Host: www.google.com\r\n"
5776 "Connection: keep-alive\r\n"
5777 "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"),
5778 };
5779
5780 // Sever accepts the authorization.
5781 MockRead data_reads3[] = {
5782 MockRead("HTTP/1.0 200 OK\r\n"),
5783 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065784 MockRead(SYNCHRONOUS, OK),
[email protected]f9ee6b52008-11-08 06:46:235785 };
5786
[email protected]31a2bfe2010-02-09 08:03:395787 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5788 data_writes1, arraysize(data_writes1));
5789 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5790 data_writes2, arraysize(data_writes2));
5791 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
5792 data_writes3, arraysize(data_writes3));
[email protected]bb88e1d32013-05-03 23:11:075793 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5794 session_deps_.socket_factory->AddSocketDataProvider(&data2);
5795 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]f9ee6b52008-11-08 06:46:235796
[email protected]49639fa2011-12-20 23:22:415797 TestCompletionCallback callback1;
[email protected]f9ee6b52008-11-08 06:46:235798
[email protected]49639fa2011-12-20 23:22:415799 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:425800 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235801
5802 rv = callback1.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425803 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235804
[email protected]0757e7702009-03-27 04:00:225805 EXPECT_TRUE(trans->IsReadyToRestartForAuth());
[email protected]49639fa2011-12-20 23:22:415806 TestCompletionCallback callback2;
5807 rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback());
[email protected]1c773ea12009-04-28 19:58:425808 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]0757e7702009-03-27 04:00:225809 rv = callback2.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425810 EXPECT_EQ(OK, rv);
[email protected]0757e7702009-03-27 04:00:225811 EXPECT_FALSE(trans->IsReadyToRestartForAuth());
5812
[email protected]1c773ea12009-04-28 19:58:425813 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505814 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045815 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]f9ee6b52008-11-08 06:46:235816
[email protected]49639fa2011-12-20 23:22:415817 TestCompletionCallback callback3;
[email protected]f9ee6b52008-11-08 06:46:235818
[email protected]49639fa2011-12-20 23:22:415819 rv = trans->RestartWithAuth(
5820 AuthCredentials(kFoo3, kBar3), callback3.callback());
[email protected]1c773ea12009-04-28 19:58:425821 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]f9ee6b52008-11-08 06:46:235822
[email protected]0757e7702009-03-27 04:00:225823 rv = callback3.WaitForResult();
[email protected]1c773ea12009-04-28 19:58:425824 EXPECT_EQ(OK, rv);
[email protected]f9ee6b52008-11-08 06:46:235825
5826 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505827 ASSERT_TRUE(response != NULL);
[email protected]f9ee6b52008-11-08 06:46:235828 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5829 EXPECT_EQ(100, response->headers->GetContentLength());
5830 }
5831}
[email protected]89ceba9a2009-03-21 03:46:065832
[email protected]3c32c5f2010-05-18 15:18:125833// Tests that nonce count increments when multiple auth attempts
5834// are started with the same nonce.
[email protected]23e482282013-06-14 16:08:025835TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) {
[email protected]54fea2562010-11-17 14:40:445836 HttpAuthHandlerDigest::Factory* digest_factory =
5837 new HttpAuthHandlerDigest::Factory();
5838 HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator =
5839 new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef");
5840 digest_factory->set_nonce_generator(nonce_generator);
[email protected]bb88e1d32013-05-03 23:11:075841 session_deps_.http_auth_handler_factory.reset(digest_factory);
5842 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3c32c5f2010-05-18 15:18:125843
5844 // Transaction 1: authenticate (foo, bar) on MyRealm1
5845 {
[email protected]3c32c5f2010-05-18 15:18:125846 HttpRequestInfo request;
5847 request.method = "GET";
5848 request.url = GURL("http://www.google.com/x/y/z");
5849 request.load_flags = 0;
5850
[email protected]262eec82013-03-19 21:01:365851 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505852 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275853
[email protected]3c32c5f2010-05-18 15:18:125854 MockWrite data_writes1[] = {
5855 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5856 "Host: www.google.com\r\n"
5857 "Connection: keep-alive\r\n\r\n"),
5858 };
5859
5860 MockRead data_reads1[] = {
5861 MockRead("HTTP/1.0 401 Unauthorized\r\n"),
5862 MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", "
5863 "algorithm=MD5, qop=\"auth\"\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065864 MockRead(SYNCHRONOUS, OK),
[email protected]3c32c5f2010-05-18 15:18:125865 };
5866
5867 // Resend with authorization (username=foo, password=bar)
5868 MockWrite data_writes2[] = {
5869 MockWrite("GET /x/y/z HTTP/1.1\r\n"
5870 "Host: www.google.com\r\n"
5871 "Connection: keep-alive\r\n"
5872 "Authorization: Digest username=\"foo\", realm=\"digestive\", "
5873 "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, "
5874 "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, "
5875 "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"),
5876 };
5877
5878 // Sever accepts the authorization.
5879 MockRead data_reads2[] = {
5880 MockRead("HTTP/1.0 200 OK\r\n"),
[email protected]8ddf8322012-02-23 18:08:065881 MockRead(SYNCHRONOUS, OK),
[email protected]3c32c5f2010-05-18 15:18:125882 };
5883
5884 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5885 data_writes1, arraysize(data_writes1));
5886 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
5887 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:075888 session_deps_.socket_factory->AddSocketDataProvider(&data1);
5889 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]3c32c5f2010-05-18 15:18:125890
[email protected]49639fa2011-12-20 23:22:415891 TestCompletionCallback callback1;
[email protected]3c32c5f2010-05-18 15:18:125892
[email protected]49639fa2011-12-20 23:22:415893 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]3c32c5f2010-05-18 15:18:125894 EXPECT_EQ(ERR_IO_PENDING, rv);
5895
5896 rv = callback1.WaitForResult();
5897 EXPECT_EQ(OK, rv);
5898
5899 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505900 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:045901 EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get()));
[email protected]3c32c5f2010-05-18 15:18:125902
[email protected]49639fa2011-12-20 23:22:415903 TestCompletionCallback callback2;
[email protected]3c32c5f2010-05-18 15:18:125904
[email protected]49639fa2011-12-20 23:22:415905 rv = trans->RestartWithAuth(
5906 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]3c32c5f2010-05-18 15:18:125907 EXPECT_EQ(ERR_IO_PENDING, rv);
5908
5909 rv = callback2.WaitForResult();
5910 EXPECT_EQ(OK, rv);
5911
5912 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505913 ASSERT_TRUE(response != NULL);
[email protected]3c32c5f2010-05-18 15:18:125914 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5915 }
5916
5917 // ------------------------------------------------------------------------
5918
5919 // Transaction 2: Request another resource in digestive's protection space.
5920 // This will preemptively add an Authorization header which should have an
5921 // "nc" value of 2 (as compared to 1 in the first use.
5922 {
[email protected]3c32c5f2010-05-18 15:18:125923 HttpRequestInfo request;
5924 request.method = "GET";
5925 // Note that Transaction 1 was at /x/y/z, so this is in the same
5926 // protection space as digest.
5927 request.url = GURL("http://www.google.com/x/y/a/b");
5928 request.load_flags = 0;
5929
[email protected]262eec82013-03-19 21:01:365930 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:505931 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:275932
[email protected]3c32c5f2010-05-18 15:18:125933 MockWrite data_writes1[] = {
5934 MockWrite("GET /x/y/a/b HTTP/1.1\r\n"
5935 "Host: www.google.com\r\n"
5936 "Connection: keep-alive\r\n"
5937 "Authorization: Digest username=\"foo\", realm=\"digestive\", "
5938 "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, "
5939 "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, "
5940 "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"),
5941 };
5942
5943 // Sever accepts the authorization.
5944 MockRead data_reads1[] = {
5945 MockRead("HTTP/1.0 200 OK\r\n"),
5946 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:065947 MockRead(SYNCHRONOUS, OK),
[email protected]3c32c5f2010-05-18 15:18:125948 };
5949
5950 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
5951 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:075952 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]3c32c5f2010-05-18 15:18:125953
[email protected]49639fa2011-12-20 23:22:415954 TestCompletionCallback callback1;
[email protected]3c32c5f2010-05-18 15:18:125955
[email protected]49639fa2011-12-20 23:22:415956 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]3c32c5f2010-05-18 15:18:125957 EXPECT_EQ(ERR_IO_PENDING, rv);
5958
5959 rv = callback1.WaitForResult();
5960 EXPECT_EQ(OK, rv);
5961
5962 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:505963 ASSERT_TRUE(response != NULL);
[email protected]3c32c5f2010-05-18 15:18:125964 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5965 }
5966}
5967
[email protected]89ceba9a2009-03-21 03:46:065968// Test the ResetStateForRestart() private method.
[email protected]23e482282013-06-14 16:08:025969TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) {
[email protected]89ceba9a2009-03-21 03:46:065970 // Create a transaction (the dependencies aren't important).
[email protected]3fe8d2f82013-10-17 08:56:075971 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d207a5f2009-06-04 05:28:405972 scoped_ptr<HttpNetworkTransaction> trans(
dcheng48459ac22014-08-26 00:46:415973 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]89ceba9a2009-03-21 03:46:065974
5975 // Setup some state (which we expect ResetStateForRestart() will clear).
[email protected]89ceba9a2009-03-21 03:46:065976 trans->read_buf_ = new IOBuffer(15);
5977 trans->read_buf_len_ = 15;
[email protected]b94f92d2010-10-27 16:45:205978 trans->request_headers_.SetHeader("Authorization", "NTLM");
[email protected]89ceba9a2009-03-21 03:46:065979
5980 // Setup state in response_
[email protected]a7e41312009-12-16 23:18:145981 HttpResponseInfo* response = &trans->response_;
[email protected]0877e3d2009-10-17 22:29:575982 response->auth_challenge = new AuthChallengeInfo();
[email protected]70d66502011-09-23 00:55:085983 response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical.
[email protected]0877e3d2009-10-17 22:29:575984 response->response_time = base::Time::Now();
5985 response->was_cached = true; // (Wouldn't ever actually be true...)
[email protected]89ceba9a2009-03-21 03:46:065986
5987 { // Setup state for response_.vary_data
5988 HttpRequestInfo request;
5989 std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n");
5990 std::replace(temp.begin(), temp.end(), '\n', '\0');
[email protected]ad8e04a2010-11-01 04:16:275991 scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp));
[email protected]8c76ae22010-04-20 22:15:435992 request.extra_headers.SetHeader("Foo", "1");
5993 request.extra_headers.SetHeader("bar", "23");
[email protected]90499482013-06-01 00:39:505994 EXPECT_TRUE(response->vary_data.Init(request, *headers.get()));
[email protected]89ceba9a2009-03-21 03:46:065995 }
5996
5997 // Cause the above state to be reset.
5998 trans->ResetStateForRestart();
5999
6000 // Verify that the state that needed to be reset, has been reset.
[email protected]9b6fee12009-09-29 18:13:076001 EXPECT_TRUE(trans->read_buf_.get() == NULL);
[email protected]89ceba9a2009-03-21 03:46:066002 EXPECT_EQ(0, trans->read_buf_len_);
[email protected]b94f92d2010-10-27 16:45:206003 EXPECT_TRUE(trans->request_headers_.IsEmpty());
[email protected]0877e3d2009-10-17 22:29:576004 EXPECT_TRUE(response->auth_challenge.get() == NULL);
6005 EXPECT_TRUE(response->headers.get() == NULL);
[email protected]34f40942010-10-04 00:34:046006 EXPECT_FALSE(response->was_cached);
[email protected]70d66502011-09-23 00:55:086007 EXPECT_EQ(0U, response->ssl_info.cert_status);
[email protected]0877e3d2009-10-17 22:29:576008 EXPECT_FALSE(response->vary_data.is_valid());
[email protected]89ceba9a2009-03-21 03:46:066009}
6010
[email protected]bacff652009-03-31 17:50:336011// Test HTTPS connections to a site with a bad certificate
[email protected]23e482282013-06-14 16:08:026012TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) {
[email protected]bacff652009-03-31 17:50:336013 HttpRequestInfo request;
6014 request.method = "GET";
6015 request.url = GURL("https://www.google.com/");
6016 request.load_flags = 0;
6017
[email protected]3fe8d2f82013-10-17 08:56:076018 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276019 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416020 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276021
[email protected]bacff652009-03-31 17:50:336022 MockWrite data_writes[] = {
6023 MockWrite("GET / HTTP/1.1\r\n"
6024 "Host: www.google.com\r\n"
6025 "Connection: keep-alive\r\n\r\n"),
6026 };
6027
6028 MockRead data_reads[] = {
6029 MockRead("HTTP/1.0 200 OK\r\n"),
6030 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6031 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066032 MockRead(SYNCHRONOUS, OK),
[email protected]bacff652009-03-31 17:50:336033 };
6034
[email protected]5ecc992a42009-11-11 01:41:596035 StaticSocketDataProvider ssl_bad_certificate;
[email protected]31a2bfe2010-02-09 08:03:396036 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6037 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066038 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID);
6039 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bacff652009-03-31 17:50:336040
[email protected]bb88e1d32013-05-03 23:11:076041 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
6042 session_deps_.socket_factory->AddSocketDataProvider(&data);
6043 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
6044 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]bacff652009-03-31 17:50:336045
[email protected]49639fa2011-12-20 23:22:416046 TestCompletionCallback callback;
[email protected]bacff652009-03-31 17:50:336047
[email protected]49639fa2011-12-20 23:22:416048 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]bacff652009-03-31 17:50:336049 EXPECT_EQ(ERR_IO_PENDING, rv);
6050
6051 rv = callback.WaitForResult();
6052 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
6053
[email protected]49639fa2011-12-20 23:22:416054 rv = trans->RestartIgnoringLastError(callback.callback());
[email protected]bacff652009-03-31 17:50:336055 EXPECT_EQ(ERR_IO_PENDING, rv);
6056
6057 rv = callback.WaitForResult();
6058 EXPECT_EQ(OK, rv);
6059
6060 const HttpResponseInfo* response = trans->GetResponseInfo();
6061
[email protected]fe2255a2011-09-20 19:37:506062 ASSERT_TRUE(response != NULL);
[email protected]bacff652009-03-31 17:50:336063 EXPECT_EQ(100, response->headers->GetContentLength());
6064}
6065
6066// Test HTTPS connections to a site with a bad certificate, going through a
6067// proxy
[email protected]23e482282013-06-14 16:08:026068TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) {
[email protected]bb88e1d32013-05-03 23:11:076069 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]bacff652009-03-31 17:50:336070
6071 HttpRequestInfo request;
6072 request.method = "GET";
6073 request.url = GURL("https://www.google.com/");
6074 request.load_flags = 0;
6075
6076 MockWrite proxy_writes[] = {
6077 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:456078 "Host: www.google.com\r\n"
6079 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]bacff652009-03-31 17:50:336080 };
6081
6082 MockRead proxy_reads[] = {
6083 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066084 MockRead(SYNCHRONOUS, OK)
[email protected]bacff652009-03-31 17:50:336085 };
6086
6087 MockWrite data_writes[] = {
6088 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
[email protected]e44de5d2009-06-05 20:12:456089 "Host: www.google.com\r\n"
6090 "Proxy-Connection: keep-alive\r\n\r\n"),
[email protected]bacff652009-03-31 17:50:336091 MockWrite("GET / HTTP/1.1\r\n"
6092 "Host: www.google.com\r\n"
6093 "Connection: keep-alive\r\n\r\n"),
6094 };
6095
6096 MockRead data_reads[] = {
6097 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
6098 MockRead("HTTP/1.0 200 OK\r\n"),
6099 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6100 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066101 MockRead(SYNCHRONOUS, OK),
[email protected]bacff652009-03-31 17:50:336102 };
6103
[email protected]31a2bfe2010-02-09 08:03:396104 StaticSocketDataProvider ssl_bad_certificate(
6105 proxy_reads, arraysize(proxy_reads),
6106 proxy_writes, arraysize(proxy_writes));
6107 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6108 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066109 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID);
6110 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bacff652009-03-31 17:50:336111
[email protected]bb88e1d32013-05-03 23:11:076112 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
6113 session_deps_.socket_factory->AddSocketDataProvider(&data);
6114 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
6115 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]bacff652009-03-31 17:50:336116
[email protected]49639fa2011-12-20 23:22:416117 TestCompletionCallback callback;
[email protected]bacff652009-03-31 17:50:336118
6119 for (int i = 0; i < 2; i++) {
[email protected]bb88e1d32013-05-03 23:11:076120 session_deps_.socket_factory->ResetNextMockIndexes();
[email protected]bacff652009-03-31 17:50:336121
[email protected]3fe8d2f82013-10-17 08:56:076122 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d207a5f2009-06-04 05:28:406123 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416124 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bacff652009-03-31 17:50:336125
[email protected]49639fa2011-12-20 23:22:416126 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]bacff652009-03-31 17:50:336127 EXPECT_EQ(ERR_IO_PENDING, rv);
6128
6129 rv = callback.WaitForResult();
6130 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
6131
[email protected]49639fa2011-12-20 23:22:416132 rv = trans->RestartIgnoringLastError(callback.callback());
[email protected]bacff652009-03-31 17:50:336133 EXPECT_EQ(ERR_IO_PENDING, rv);
6134
6135 rv = callback.WaitForResult();
6136 EXPECT_EQ(OK, rv);
6137
6138 const HttpResponseInfo* response = trans->GetResponseInfo();
6139
[email protected]fe2255a2011-09-20 19:37:506140 ASSERT_TRUE(response != NULL);
[email protected]bacff652009-03-31 17:50:336141 EXPECT_EQ(100, response->headers->GetContentLength());
6142 }
6143}
6144
[email protected]2df19bb2010-08-25 20:13:466145
6146// Test HTTPS connections to a site, going through an HTTPS proxy
[email protected]23e482282013-06-14 16:08:026147TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076148 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206149 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"));
6150 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:076151 session_deps_.net_log = &net_log;
[email protected]2df19bb2010-08-25 20:13:466152
6153 HttpRequestInfo request;
6154 request.method = "GET";
6155 request.url = GURL("https://www.google.com/");
6156 request.load_flags = 0;
6157
6158 MockWrite data_writes[] = {
6159 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6160 "Host: www.google.com\r\n"
6161 "Proxy-Connection: keep-alive\r\n\r\n"),
6162 MockWrite("GET / HTTP/1.1\r\n"
6163 "Host: www.google.com\r\n"
6164 "Connection: keep-alive\r\n\r\n"),
6165 };
6166
6167 MockRead data_reads[] = {
6168 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
6169 MockRead("HTTP/1.1 200 OK\r\n"),
6170 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6171 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066172 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:466173 };
6174
6175 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6176 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066177 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
6178 SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel
[email protected]2df19bb2010-08-25 20:13:466179
[email protected]bb88e1d32013-05-03 23:11:076180 session_deps_.socket_factory->AddSocketDataProvider(&data);
6181 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
6182 session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl);
[email protected]2df19bb2010-08-25 20:13:466183
[email protected]49639fa2011-12-20 23:22:416184 TestCompletionCallback callback;
[email protected]2df19bb2010-08-25 20:13:466185
[email protected]3fe8d2f82013-10-17 08:56:076186 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2df19bb2010-08-25 20:13:466187 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416188 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2df19bb2010-08-25 20:13:466189
[email protected]49639fa2011-12-20 23:22:416190 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2df19bb2010-08-25 20:13:466191 EXPECT_EQ(ERR_IO_PENDING, rv);
6192
6193 rv = callback.WaitForResult();
6194 EXPECT_EQ(OK, rv);
6195 const HttpResponseInfo* response = trans->GetResponseInfo();
6196
[email protected]fe2255a2011-09-20 19:37:506197 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:466198
6199 EXPECT_TRUE(response->headers->IsKeepAlive());
6200 EXPECT_EQ(200, response->headers->response_code());
6201 EXPECT_EQ(100, response->headers->GetContentLength());
6202 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]029c83b62013-01-24 05:28:206203
6204 LoadTimingInfo load_timing_info;
6205 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6206 TestLoadTimingNotReusedWithPac(load_timing_info,
6207 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]2df19bb2010-08-25 20:13:466208}
6209
[email protected]511f6f52010-12-17 03:58:296210// Test an HTTPS Proxy's ability to redirect a CONNECT request
[email protected]23e482282013-06-14 16:08:026211TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076212 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206213 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"));
6214 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:076215 session_deps_.net_log = &net_log;
[email protected]511f6f52010-12-17 03:58:296216
6217 HttpRequestInfo request;
6218 request.method = "GET";
6219 request.url = GURL("https://www.google.com/");
6220 request.load_flags = 0;
6221
6222 MockWrite data_writes[] = {
6223 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6224 "Host: www.google.com\r\n"
6225 "Proxy-Connection: keep-alive\r\n\r\n"),
6226 };
6227
6228 MockRead data_reads[] = {
6229 MockRead("HTTP/1.1 302 Redirect\r\n"),
6230 MockRead("Location: http://login.example.com/\r\n"),
6231 MockRead("Content-Length: 0\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066232 MockRead(SYNCHRONOUS, OK),
[email protected]511f6f52010-12-17 03:58:296233 };
6234
6235 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6236 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066237 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]511f6f52010-12-17 03:58:296238
[email protected]bb88e1d32013-05-03 23:11:076239 session_deps_.socket_factory->AddSocketDataProvider(&data);
6240 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296241
[email protected]49639fa2011-12-20 23:22:416242 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296243
[email protected]3fe8d2f82013-10-17 08:56:076244 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296245 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416246 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296247
[email protected]49639fa2011-12-20 23:22:416248 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296249 EXPECT_EQ(ERR_IO_PENDING, rv);
6250
6251 rv = callback.WaitForResult();
6252 EXPECT_EQ(OK, rv);
6253 const HttpResponseInfo* response = trans->GetResponseInfo();
6254
[email protected]fe2255a2011-09-20 19:37:506255 ASSERT_TRUE(response != NULL);
[email protected]511f6f52010-12-17 03:58:296256
6257 EXPECT_EQ(302, response->headers->response_code());
6258 std::string url;
6259 EXPECT_TRUE(response->headers->IsRedirect(&url));
6260 EXPECT_EQ("http://login.example.com/", url);
[email protected]029c83b62013-01-24 05:28:206261
6262 // In the case of redirects from proxies, HttpNetworkTransaction returns
6263 // timing for the proxy connection instead of the connection to the host,
6264 // and no send / receive times.
6265 // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse.
6266 LoadTimingInfo load_timing_info;
6267 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6268
6269 EXPECT_FALSE(load_timing_info.socket_reused);
6270 EXPECT_NE(net::NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
6271
6272 EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null());
6273 EXPECT_LE(load_timing_info.proxy_resolve_start,
6274 load_timing_info.proxy_resolve_end);
6275 EXPECT_LE(load_timing_info.proxy_resolve_end,
6276 load_timing_info.connect_timing.connect_start);
6277 ExpectConnectTimingHasTimes(
6278 load_timing_info.connect_timing,
6279 CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES);
6280
6281 EXPECT_TRUE(load_timing_info.send_start.is_null());
6282 EXPECT_TRUE(load_timing_info.send_end.is_null());
6283 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
[email protected]511f6f52010-12-17 03:58:296284}
6285
6286// Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request
[email protected]23e482282013-06-14 16:08:026287TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) {
[email protected]bb88e1d32013-05-03 23:11:076288 session_deps_.proxy_service.reset(
[email protected]511f6f52010-12-17 03:58:296289 ProxyService::CreateFixed("https://proxy:70"));
6290
6291 HttpRequestInfo request;
6292 request.method = "GET";
6293 request.url = GURL("https://www.google.com/");
6294 request.load_flags = 0;
6295
lgarrona91df87f2014-12-05 00:51:346296 scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(
6297 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]c10b20852013-05-15 21:29:206298 scoped_ptr<SpdyFrame> goaway(
6299 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]511f6f52010-12-17 03:58:296300 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:066301 CreateMockWrite(*conn.get(), 0, SYNCHRONOUS),
[email protected]57d2dfa2013-06-24 06:04:126302 CreateMockWrite(*goaway.get(), 3, SYNCHRONOUS),
[email protected]511f6f52010-12-17 03:58:296303 };
6304
6305 static const char* const kExtraHeaders[] = {
6306 "location",
6307 "http://login.example.com/",
6308 };
[email protected]ff98d7f02012-03-22 21:44:196309 scoped_ptr<SpdyFrame> resp(
[email protected]23e482282013-06-14 16:08:026310 spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders,
[email protected]511f6f52010-12-17 03:58:296311 arraysize(kExtraHeaders)/2, 1));
6312 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:066313 CreateMockRead(*resp.get(), 1, SYNCHRONOUS),
6314 MockRead(ASYNC, 0, 2), // EOF
[email protected]511f6f52010-12-17 03:58:296315 };
6316
[email protected]dd54bd82012-07-19 23:44:576317 DelayedSocketData data(
6318 1, // wait for one write to finish before reading.
6319 data_reads, arraysize(data_reads),
6320 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066321 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]23e482282013-06-14 16:08:026322 proxy_ssl.SetNextProto(GetParam());
[email protected]511f6f52010-12-17 03:58:296323
[email protected]bb88e1d32013-05-03 23:11:076324 session_deps_.socket_factory->AddSocketDataProvider(&data);
6325 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296326
[email protected]49639fa2011-12-20 23:22:416327 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296328
[email protected]3fe8d2f82013-10-17 08:56:076329 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296330 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416331 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296332
[email protected]49639fa2011-12-20 23:22:416333 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296334 EXPECT_EQ(ERR_IO_PENDING, rv);
6335
6336 rv = callback.WaitForResult();
6337 EXPECT_EQ(OK, rv);
6338 const HttpResponseInfo* response = trans->GetResponseInfo();
6339
[email protected]fe2255a2011-09-20 19:37:506340 ASSERT_TRUE(response != NULL);
[email protected]511f6f52010-12-17 03:58:296341
6342 EXPECT_EQ(302, response->headers->response_code());
6343 std::string url;
6344 EXPECT_TRUE(response->headers->IsRedirect(&url));
6345 EXPECT_EQ("http://login.example.com/", url);
6346}
6347
[email protected]4eddbc732012-08-09 05:40:176348// Test that an HTTPS proxy's response to a CONNECT request is filtered.
[email protected]23e482282013-06-14 16:08:026349TEST_P(HttpNetworkTransactionTest,
[email protected]4eddbc732012-08-09 05:40:176350 ErrorResponseToHttpsConnectViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076351 session_deps_.proxy_service.reset(
[email protected]511f6f52010-12-17 03:58:296352 ProxyService::CreateFixed("https://proxy:70"));
6353
6354 HttpRequestInfo request;
6355 request.method = "GET";
6356 request.url = GURL("https://www.google.com/");
6357 request.load_flags = 0;
6358
6359 MockWrite data_writes[] = {
6360 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6361 "Host: www.google.com\r\n"
6362 "Proxy-Connection: keep-alive\r\n\r\n"),
6363 };
6364
6365 MockRead data_reads[] = {
6366 MockRead("HTTP/1.1 404 Not Found\r\n"),
6367 MockRead("Content-Length: 23\r\n\r\n"),
6368 MockRead("The host does not exist"),
[email protected]8ddf8322012-02-23 18:08:066369 MockRead(SYNCHRONOUS, OK),
[email protected]511f6f52010-12-17 03:58:296370 };
6371
6372 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6373 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066374 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]511f6f52010-12-17 03:58:296375
[email protected]bb88e1d32013-05-03 23:11:076376 session_deps_.socket_factory->AddSocketDataProvider(&data);
6377 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296378
[email protected]49639fa2011-12-20 23:22:416379 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296380
[email protected]3fe8d2f82013-10-17 08:56:076381 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296382 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416383 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296384
[email protected]49639fa2011-12-20 23:22:416385 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296386 EXPECT_EQ(ERR_IO_PENDING, rv);
6387
6388 rv = callback.WaitForResult();
[email protected]4eddbc732012-08-09 05:40:176389 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]511f6f52010-12-17 03:58:296390
[email protected]4eddbc732012-08-09 05:40:176391 // TODO(ttuttle): Anything else to check here?
[email protected]511f6f52010-12-17 03:58:296392}
6393
[email protected]4eddbc732012-08-09 05:40:176394// Test that a SPDY proxy's response to a CONNECT request is filtered.
[email protected]23e482282013-06-14 16:08:026395TEST_P(HttpNetworkTransactionTest,
[email protected]4eddbc732012-08-09 05:40:176396 ErrorResponseToHttpsConnectViaSpdyProxy) {
[email protected]bb88e1d32013-05-03 23:11:076397 session_deps_.proxy_service.reset(
6398 ProxyService::CreateFixed("https://proxy:70"));
[email protected]511f6f52010-12-17 03:58:296399
6400 HttpRequestInfo request;
6401 request.method = "GET";
6402 request.url = GURL("https://www.google.com/");
6403 request.load_flags = 0;
6404
lgarrona91df87f2014-12-05 00:51:346405 scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect(
6406 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]c10b20852013-05-15 21:29:206407 scoped_ptr<SpdyFrame> rst(
6408 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]511f6f52010-12-17 03:58:296409 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:066410 CreateMockWrite(*conn.get(), 0, SYNCHRONOUS),
[email protected]4eddbc732012-08-09 05:40:176411 CreateMockWrite(*rst.get(), 3, SYNCHRONOUS),
[email protected]511f6f52010-12-17 03:58:296412 };
6413
6414 static const char* const kExtraHeaders[] = {
6415 "location",
6416 "http://login.example.com/",
6417 };
[email protected]ff98d7f02012-03-22 21:44:196418 scoped_ptr<SpdyFrame> resp(
[email protected]23e482282013-06-14 16:08:026419 spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders,
[email protected]511f6f52010-12-17 03:58:296420 arraysize(kExtraHeaders)/2, 1));
[email protected]ff98d7f02012-03-22 21:44:196421 scoped_ptr<SpdyFrame> body(
[email protected]23e482282013-06-14 16:08:026422 spdy_util_.ConstructSpdyBodyFrame(
6423 1, "The host does not exist", 23, true));
[email protected]511f6f52010-12-17 03:58:296424 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:066425 CreateMockRead(*resp.get(), 1, SYNCHRONOUS),
6426 CreateMockRead(*body.get(), 2, SYNCHRONOUS),
[email protected]4eddbc732012-08-09 05:40:176427 MockRead(ASYNC, 0, 4), // EOF
[email protected]511f6f52010-12-17 03:58:296428 };
6429
[email protected]dd54bd82012-07-19 23:44:576430 DelayedSocketData data(
6431 1, // wait for one write to finish before reading.
6432 data_reads, arraysize(data_reads),
6433 data_writes, arraysize(data_writes));
[email protected]8ddf8322012-02-23 18:08:066434 SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy
[email protected]23e482282013-06-14 16:08:026435 proxy_ssl.SetNextProto(GetParam());
[email protected]511f6f52010-12-17 03:58:296436
[email protected]bb88e1d32013-05-03 23:11:076437 session_deps_.socket_factory->AddSocketDataProvider(&data);
6438 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl);
[email protected]511f6f52010-12-17 03:58:296439
[email protected]49639fa2011-12-20 23:22:416440 TestCompletionCallback callback;
[email protected]511f6f52010-12-17 03:58:296441
[email protected]3fe8d2f82013-10-17 08:56:076442 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]511f6f52010-12-17 03:58:296443 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416444 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]511f6f52010-12-17 03:58:296445
[email protected]49639fa2011-12-20 23:22:416446 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]511f6f52010-12-17 03:58:296447 EXPECT_EQ(ERR_IO_PENDING, rv);
6448
6449 rv = callback.WaitForResult();
[email protected]4eddbc732012-08-09 05:40:176450 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
[email protected]511f6f52010-12-17 03:58:296451
[email protected]4eddbc732012-08-09 05:40:176452 // TODO(ttuttle): Anything else to check here?
[email protected]511f6f52010-12-17 03:58:296453}
6454
[email protected]0c5fb722012-02-28 11:50:356455// Test the request-challenge-retry sequence for basic auth, through
6456// a SPDY proxy over a single SPDY session.
[email protected]23e482282013-06-14 16:08:026457TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) {
[email protected]0c5fb722012-02-28 11:50:356458 HttpRequestInfo request;
6459 request.method = "GET";
6460 request.url = GURL("https://www.google.com/");
6461 // when the no authentication data flag is set.
6462 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
6463
6464 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:076465 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206466 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"));
[email protected]333bdf62012-06-08 22:57:296467 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:076468 session_deps_.net_log = log.bound().net_log();
6469 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0c5fb722012-02-28 11:50:356470
6471 // Since we have proxy, should try to establish tunnel.
lgarrona91df87f2014-12-05 00:51:346472 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect(
6473 NULL, 0, 1, LOWEST, HostPortPair("www.google.com", 443)));
[email protected]c10b20852013-05-15 21:29:206474 scoped_ptr<SpdyFrame> rst(
6475 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL));
[email protected]0c5fb722012-02-28 11:50:356476
6477 // After calling trans->RestartWithAuth(), this is the request we should
6478 // be issuing -- the final header line contains the credentials.
6479 const char* const kAuthCredentials[] = {
6480 "proxy-authorization", "Basic Zm9vOmJhcg==",
6481 };
[email protected]fba2dbde2013-05-24 16:09:016482 scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect(
lgarrona91df87f2014-12-05 00:51:346483 kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST,
6484 HostPortPair("www.google.com", 443)));
[email protected]0c5fb722012-02-28 11:50:356485 // fetch https://www.google.com/ via HTTP
6486 const char get[] = "GET / HTTP/1.1\r\n"
6487 "Host: www.google.com\r\n"
6488 "Connection: keep-alive\r\n\r\n";
[email protected]ff98d7f02012-03-22 21:44:196489 scoped_ptr<SpdyFrame> wrapped_get(
[email protected]23e482282013-06-14 16:08:026490 spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false));
[email protected]0c5fb722012-02-28 11:50:356491
6492 MockWrite spdy_writes[] = {
[email protected]3d7c43f2012-07-10 21:26:206493 CreateMockWrite(*req, 1, ASYNC),
[email protected]c92f4b4542012-07-26 23:53:216494 CreateMockWrite(*rst, 4, ASYNC),
6495 CreateMockWrite(*connect2, 5),
[email protected]3d7c43f2012-07-10 21:26:206496 CreateMockWrite(*wrapped_get, 8),
[email protected]0c5fb722012-02-28 11:50:356497 };
6498
6499 // The proxy responds to the connect with a 407, using a persistent
6500 // connection.
thestig9d3bb0c2015-01-24 00:49:516501 const char kAuthStatus[] = "407";
[email protected]0c5fb722012-02-28 11:50:356502 const char* const kAuthChallenge[] = {
[email protected]0c5fb722012-02-28 11:50:356503 "proxy-authenticate", "Basic realm=\"MyRealm1\"",
6504 };
[email protected]745aa9c2014-06-27 02:21:296505 scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError(
6506 kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1));
[email protected]0c5fb722012-02-28 11:50:356507
[email protected]23e482282013-06-14 16:08:026508 scoped_ptr<SpdyFrame> conn_resp(
6509 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
[email protected]0c5fb722012-02-28 11:50:356510 const char resp[] = "HTTP/1.1 200 OK\r\n"
6511 "Content-Length: 5\r\n\r\n";
6512
[email protected]ff98d7f02012-03-22 21:44:196513 scoped_ptr<SpdyFrame> wrapped_get_resp(
[email protected]23e482282013-06-14 16:08:026514 spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false));
[email protected]ff98d7f02012-03-22 21:44:196515 scoped_ptr<SpdyFrame> wrapped_body(
[email protected]23e482282013-06-14 16:08:026516 spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false));
[email protected]0c5fb722012-02-28 11:50:356517 MockRead spdy_reads[] = {
[email protected]3d7c43f2012-07-10 21:26:206518 CreateMockRead(*conn_auth_resp, 2, ASYNC),
6519 CreateMockRead(*conn_resp, 6, ASYNC),
6520 CreateMockRead(*wrapped_get_resp, 9, ASYNC),
6521 CreateMockRead(*wrapped_body, 10, ASYNC),
6522 MockRead(ASYNC, OK, 11), // EOF. May or may not be read.
[email protected]0c5fb722012-02-28 11:50:356523 };
6524
[email protected]dd54bd82012-07-19 23:44:576525 OrderedSocketData spdy_data(
6526 spdy_reads, arraysize(spdy_reads),
6527 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:076528 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]0c5fb722012-02-28 11:50:356529 // Negotiate SPDY to the proxy
6530 SSLSocketDataProvider proxy(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:026531 proxy.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:076532 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy);
[email protected]0c5fb722012-02-28 11:50:356533 // Vanilla SSL to the server
6534 SSLSocketDataProvider server(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:076535 session_deps_.socket_factory->AddSSLSocketDataProvider(&server);
[email protected]0c5fb722012-02-28 11:50:356536
6537 TestCompletionCallback callback1;
6538
[email protected]262eec82013-03-19 21:01:366539 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:506540 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0c5fb722012-02-28 11:50:356541
6542 int rv = trans->Start(&request, callback1.callback(), log.bound());
6543 EXPECT_EQ(ERR_IO_PENDING, rv);
6544
6545 rv = callback1.WaitForResult();
6546 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:576547 net::CapturingNetLog::CapturedEntryList entries;
[email protected]0c5fb722012-02-28 11:50:356548 log.GetEntries(&entries);
6549 size_t pos = ExpectLogContainsSomewhere(
6550 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
6551 NetLog::PHASE_NONE);
6552 ExpectLogContainsSomewhere(
6553 entries, pos,
6554 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
6555 NetLog::PHASE_NONE);
6556
6557 const HttpResponseInfo* response = trans->GetResponseInfo();
6558 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:506559 ASSERT_FALSE(response->headers.get() == NULL);
[email protected]0c5fb722012-02-28 11:50:356560 EXPECT_EQ(407, response->headers->response_code());
6561 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6562 EXPECT_TRUE(response->auth_challenge.get() != NULL);
6563 EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get()));
6564
6565 TestCompletionCallback callback2;
6566
6567 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar),
6568 callback2.callback());
6569 EXPECT_EQ(ERR_IO_PENDING, rv);
6570
6571 rv = callback2.WaitForResult();
6572 EXPECT_EQ(OK, rv);
6573
6574 response = trans->GetResponseInfo();
6575 ASSERT_TRUE(response != NULL);
6576
6577 EXPECT_TRUE(response->headers->IsKeepAlive());
6578 EXPECT_EQ(200, response->headers->response_code());
6579 EXPECT_EQ(5, response->headers->GetContentLength());
6580 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6581
6582 // The password prompt info should not be set.
6583 EXPECT_TRUE(response->auth_challenge.get() == NULL);
6584
[email protected]029c83b62013-01-24 05:28:206585 LoadTimingInfo load_timing_info;
6586 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6587 TestLoadTimingNotReusedWithPac(load_timing_info,
6588 CONNECT_TIMING_HAS_SSL_TIMES);
6589
[email protected]0c5fb722012-02-28 11:50:356590 trans.reset();
6591 session->CloseAllConnections();
6592}
6593
[email protected]7c6f7ba2012-04-03 04:09:296594// Test that an explicitly trusted SPDY proxy can push a resource from an
6595// origin that is different from that of its associated resource.
[email protected]23e482282013-06-14 16:08:026596TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) {
[email protected]7c6f7ba2012-04-03 04:09:296597 HttpRequestInfo request;
6598 HttpRequestInfo push_request;
6599
[email protected]7c6f7ba2012-04-03 04:09:296600 request.method = "GET";
6601 request.url = GURL("http://www.google.com/");
6602 push_request.method = "GET";
6603 push_request.url = GURL("http://www.another-origin.com/foo.dat");
6604
[email protected]7c6f7ba2012-04-03 04:09:296605 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:076606 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:206607 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"));
[email protected]333bdf62012-06-08 22:57:296608 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:076609 session_deps_.net_log = log.bound().net_log();
[email protected]61b4efc2012-04-27 18:12:506610
6611 // Enable cross-origin push.
[email protected]bb88e1d32013-05-03 23:11:076612 session_deps_.trusted_spdy_proxy = "myproxy:70";
[email protected]61b4efc2012-04-27 18:12:506613
[email protected]bb88e1d32013-05-03 23:11:076614 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7c6f7ba2012-04-03 04:09:296615
[email protected]cdf8f7e72013-05-23 10:56:466616 scoped_ptr<SpdyFrame> stream1_syn(
6617 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]7c6f7ba2012-04-03 04:09:296618
6619 MockWrite spdy_writes[] = {
[email protected]cdf8f7e72013-05-23 10:56:466620 CreateMockWrite(*stream1_syn, 1, ASYNC),
[email protected]7c6f7ba2012-04-03 04:09:296621 };
6622
6623 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026624 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]7c6f7ba2012-04-03 04:09:296625
6626 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026627 stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]7c6f7ba2012-04-03 04:09:296628
6629 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026630 stream2_syn(spdy_util_.ConstructSpdyPush(NULL,
[email protected]7c6f7ba2012-04-03 04:09:296631 0,
6632 2,
6633 1,
6634 "http://www.another-origin.com/foo.dat"));
[email protected]8a0fc822013-06-27 20:52:436635 const char kPushedData[] = "pushed";
6636 scoped_ptr<SpdyFrame> stream2_body(
6637 spdy_util_.ConstructSpdyBodyFrame(
6638 2, kPushedData, strlen(kPushedData), true));
[email protected]7c6f7ba2012-04-03 04:09:296639
6640 MockRead spdy_reads[] = {
6641 CreateMockRead(*stream1_reply, 2, ASYNC),
6642 CreateMockRead(*stream2_syn, 3, ASYNC),
6643 CreateMockRead(*stream1_body, 4, ASYNC),
[email protected]8a0fc822013-06-27 20:52:436644 CreateMockRead(*stream2_body, 5, ASYNC),
[email protected]7c6f7ba2012-04-03 04:09:296645 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
6646 };
6647
[email protected]dd54bd82012-07-19 23:44:576648 OrderedSocketData spdy_data(
6649 spdy_reads, arraysize(spdy_reads),
6650 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:076651 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]7c6f7ba2012-04-03 04:09:296652 // Negotiate SPDY to the proxy
6653 SSLSocketDataProvider proxy(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:026654 proxy.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:076655 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy);
[email protected]7c6f7ba2012-04-03 04:09:296656
[email protected]262eec82013-03-19 21:01:366657 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:506658 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]7c6f7ba2012-04-03 04:09:296659 TestCompletionCallback callback;
6660 int rv = trans->Start(&request, callback.callback(), log.bound());
6661 EXPECT_EQ(ERR_IO_PENDING, rv);
6662
6663 rv = callback.WaitForResult();
6664 EXPECT_EQ(OK, rv);
6665 const HttpResponseInfo* response = trans->GetResponseInfo();
6666
[email protected]262eec82013-03-19 21:01:366667 scoped_ptr<HttpTransaction> push_trans(
[email protected]90499482013-06-01 00:39:506668 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
6669 rv = push_trans->Start(&push_request, callback.callback(), log.bound());
[email protected]7c6f7ba2012-04-03 04:09:296670 EXPECT_EQ(ERR_IO_PENDING, rv);
6671
6672 rv = callback.WaitForResult();
6673 EXPECT_EQ(OK, rv);
6674 const HttpResponseInfo* push_response = push_trans->GetResponseInfo();
6675
6676 ASSERT_TRUE(response != NULL);
6677 EXPECT_TRUE(response->headers->IsKeepAlive());
6678
6679 EXPECT_EQ(200, response->headers->response_code());
6680 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6681
6682 std::string response_data;
6683 rv = ReadTransaction(trans.get(), &response_data);
6684 EXPECT_EQ(OK, rv);
6685 EXPECT_EQ("hello!", response_data);
6686
[email protected]029c83b62013-01-24 05:28:206687 LoadTimingInfo load_timing_info;
6688 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
6689 TestLoadTimingNotReusedWithPac(load_timing_info,
6690 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
6691
[email protected]7c6f7ba2012-04-03 04:09:296692 // Verify the pushed stream.
[email protected]90499482013-06-01 00:39:506693 EXPECT_TRUE(push_response->headers.get() != NULL);
[email protected]7c6f7ba2012-04-03 04:09:296694 EXPECT_EQ(200, push_response->headers->response_code());
6695
6696 rv = ReadTransaction(push_trans.get(), &response_data);
6697 EXPECT_EQ(OK, rv);
6698 EXPECT_EQ("pushed", response_data);
6699
[email protected]029c83b62013-01-24 05:28:206700 LoadTimingInfo push_load_timing_info;
6701 EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info));
6702 TestLoadTimingReusedWithPac(push_load_timing_info);
6703 // The transactions should share a socket ID, despite being for different
6704 // origins.
6705 EXPECT_EQ(load_timing_info.socket_log_id,
6706 push_load_timing_info.socket_log_id);
6707
[email protected]7c6f7ba2012-04-03 04:09:296708 trans.reset();
6709 push_trans.reset();
6710 session->CloseAllConnections();
6711}
6712
[email protected]8c843192012-04-05 07:15:006713// Test that an explicitly trusted SPDY proxy cannot push HTTPS content.
[email protected]23e482282013-06-14 16:08:026714TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) {
[email protected]8c843192012-04-05 07:15:006715 HttpRequestInfo request;
6716
6717 request.method = "GET";
6718 request.url = GURL("http://www.google.com/");
6719
[email protected]8c843192012-04-05 07:15:006720 // Configure against https proxy server "myproxy:70".
[email protected]bb88e1d32013-05-03 23:11:076721 session_deps_.proxy_service.reset(
[email protected]8c843192012-04-05 07:15:006722 ProxyService::CreateFixed("https://myproxy:70"));
[email protected]333bdf62012-06-08 22:57:296723 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:076724 session_deps_.net_log = log.bound().net_log();
[email protected]61b4efc2012-04-27 18:12:506725
6726 // Enable cross-origin push.
[email protected]bb88e1d32013-05-03 23:11:076727 session_deps_.trusted_spdy_proxy = "myproxy:70";
[email protected]61b4efc2012-04-27 18:12:506728
[email protected]bb88e1d32013-05-03 23:11:076729 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8c843192012-04-05 07:15:006730
[email protected]cdf8f7e72013-05-23 10:56:466731 scoped_ptr<SpdyFrame> stream1_syn(
6732 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false));
[email protected]8c843192012-04-05 07:15:006733
6734 scoped_ptr<SpdyFrame> push_rst(
[email protected]c10b20852013-05-15 21:29:206735 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
[email protected]8c843192012-04-05 07:15:006736
6737 MockWrite spdy_writes[] = {
6738 CreateMockWrite(*stream1_syn, 1, ASYNC),
6739 CreateMockWrite(*push_rst, 4),
6740 };
6741
6742 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026743 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
[email protected]8c843192012-04-05 07:15:006744
6745 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026746 stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]8c843192012-04-05 07:15:006747
6748 scoped_ptr<SpdyFrame>
[email protected]23e482282013-06-14 16:08:026749 stream2_syn(spdy_util_.ConstructSpdyPush(NULL,
[email protected]8c843192012-04-05 07:15:006750 0,
6751 2,
6752 1,
6753 "https://www.another-origin.com/foo.dat"));
6754
6755 MockRead spdy_reads[] = {
6756 CreateMockRead(*stream1_reply, 2, ASYNC),
6757 CreateMockRead(*stream2_syn, 3, ASYNC),
6758 CreateMockRead(*stream1_body, 5, ASYNC),
6759 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause
6760 };
6761
[email protected]dd54bd82012-07-19 23:44:576762 OrderedSocketData spdy_data(
6763 spdy_reads, arraysize(spdy_reads),
6764 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:076765 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]8c843192012-04-05 07:15:006766 // Negotiate SPDY to the proxy
6767 SSLSocketDataProvider proxy(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:026768 proxy.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:076769 session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy);
[email protected]8c843192012-04-05 07:15:006770
[email protected]262eec82013-03-19 21:01:366771 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:506772 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]8c843192012-04-05 07:15:006773 TestCompletionCallback callback;
6774 int rv = trans->Start(&request, callback.callback(), log.bound());
6775 EXPECT_EQ(ERR_IO_PENDING, rv);
6776
6777 rv = callback.WaitForResult();
6778 EXPECT_EQ(OK, rv);
6779 const HttpResponseInfo* response = trans->GetResponseInfo();
6780
6781 ASSERT_TRUE(response != NULL);
6782 EXPECT_TRUE(response->headers->IsKeepAlive());
6783
6784 EXPECT_EQ(200, response->headers->response_code());
6785 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
6786
6787 std::string response_data;
6788 rv = ReadTransaction(trans.get(), &response_data);
6789 EXPECT_EQ(OK, rv);
6790 EXPECT_EQ("hello!", response_data);
6791
6792 trans.reset();
6793 session->CloseAllConnections();
6794}
6795
[email protected]2df19bb2010-08-25 20:13:466796// Test HTTPS connections to a site with a bad certificate, going through an
6797// HTTPS proxy
[email protected]23e482282013-06-14 16:08:026798TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) {
[email protected]bb88e1d32013-05-03 23:11:076799 session_deps_.proxy_service.reset(ProxyService::CreateFixed(
[email protected]3912662a32011-10-04 00:51:116800 "https://proxy:70"));
[email protected]2df19bb2010-08-25 20:13:466801
6802 HttpRequestInfo request;
6803 request.method = "GET";
6804 request.url = GURL("https://www.google.com/");
6805 request.load_flags = 0;
6806
6807 // Attempt to fetch the URL from a server with a bad cert
6808 MockWrite bad_cert_writes[] = {
6809 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6810 "Host: www.google.com\r\n"
6811 "Proxy-Connection: keep-alive\r\n\r\n"),
6812 };
6813
6814 MockRead bad_cert_reads[] = {
6815 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066816 MockRead(SYNCHRONOUS, OK)
[email protected]2df19bb2010-08-25 20:13:466817 };
6818
6819 // Attempt to fetch the URL with a good cert
6820 MockWrite good_data_writes[] = {
6821 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6822 "Host: www.google.com\r\n"
6823 "Proxy-Connection: keep-alive\r\n\r\n"),
6824 MockWrite("GET / HTTP/1.1\r\n"
6825 "Host: www.google.com\r\n"
6826 "Connection: keep-alive\r\n\r\n"),
6827 };
6828
6829 MockRead good_cert_reads[] = {
6830 MockRead("HTTP/1.0 200 Connected\r\n\r\n"),
6831 MockRead("HTTP/1.0 200 OK\r\n"),
6832 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6833 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066834 MockRead(SYNCHRONOUS, OK),
[email protected]2df19bb2010-08-25 20:13:466835 };
6836
6837 StaticSocketDataProvider ssl_bad_certificate(
6838 bad_cert_reads, arraysize(bad_cert_reads),
6839 bad_cert_writes, arraysize(bad_cert_writes));
6840 StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads),
6841 good_data_writes, arraysize(good_data_writes));
[email protected]8ddf8322012-02-23 18:08:066842 SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID);
6843 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]2df19bb2010-08-25 20:13:466844
6845 // SSL to the proxy, then CONNECT request, then SSL with bad certificate
[email protected]bb88e1d32013-05-03 23:11:076846 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
6847 session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate);
6848 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad);
[email protected]2df19bb2010-08-25 20:13:466849
6850 // SSL to the proxy, then CONNECT request, then valid SSL certificate
[email protected]bb88e1d32013-05-03 23:11:076851 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
6852 session_deps_.socket_factory->AddSocketDataProvider(&data);
6853 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2df19bb2010-08-25 20:13:466854
[email protected]49639fa2011-12-20 23:22:416855 TestCompletionCallback callback;
[email protected]2df19bb2010-08-25 20:13:466856
[email protected]3fe8d2f82013-10-17 08:56:076857 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2df19bb2010-08-25 20:13:466858 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416859 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2df19bb2010-08-25 20:13:466860
[email protected]49639fa2011-12-20 23:22:416861 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2df19bb2010-08-25 20:13:466862 EXPECT_EQ(ERR_IO_PENDING, rv);
6863
6864 rv = callback.WaitForResult();
6865 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv);
6866
[email protected]49639fa2011-12-20 23:22:416867 rv = trans->RestartIgnoringLastError(callback.callback());
[email protected]2df19bb2010-08-25 20:13:466868 EXPECT_EQ(ERR_IO_PENDING, rv);
6869
6870 rv = callback.WaitForResult();
6871 EXPECT_EQ(OK, rv);
6872
6873 const HttpResponseInfo* response = trans->GetResponseInfo();
6874
[email protected]fe2255a2011-09-20 19:37:506875 ASSERT_TRUE(response != NULL);
[email protected]2df19bb2010-08-25 20:13:466876 EXPECT_EQ(100, response->headers->GetContentLength());
6877}
6878
[email protected]23e482282013-06-14 16:08:026879TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) {
[email protected]1c773ea12009-04-28 19:58:426880 HttpRequestInfo request;
6881 request.method = "GET";
6882 request.url = GURL("http://www.google.com/");
[email protected]8c76ae22010-04-20 22:15:436883 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
6884 "Chromium Ultra Awesome X Edition");
[email protected]1c773ea12009-04-28 19:58:426885
[email protected]3fe8d2f82013-10-17 08:56:076886 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276887 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416888 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276889
[email protected]1c773ea12009-04-28 19:58:426890 MockWrite data_writes[] = {
6891 MockWrite("GET / HTTP/1.1\r\n"
6892 "Host: www.google.com\r\n"
6893 "Connection: keep-alive\r\n"
6894 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
6895 };
6896
6897 // Lastly, the server responds with the actual content.
6898 MockRead data_reads[] = {
6899 MockRead("HTTP/1.0 200 OK\r\n"),
6900 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6901 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066902 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:426903 };
6904
[email protected]31a2bfe2010-02-09 08:03:396905 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6906 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076907 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:426908
[email protected]49639fa2011-12-20 23:22:416909 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:426910
[email protected]49639fa2011-12-20 23:22:416911 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:426912 EXPECT_EQ(ERR_IO_PENDING, rv);
6913
6914 rv = callback.WaitForResult();
6915 EXPECT_EQ(OK, rv);
6916}
6917
[email protected]23e482282013-06-14 16:08:026918TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) {
[email protected]da81f132010-08-18 23:39:296919 HttpRequestInfo request;
6920 request.method = "GET";
6921 request.url = GURL("https://www.google.com/");
6922 request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
6923 "Chromium Ultra Awesome X Edition");
6924
[email protected]bb88e1d32013-05-03 23:11:076925 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]3fe8d2f82013-10-17 08:56:076926 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276927 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416928 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276929
[email protected]da81f132010-08-18 23:39:296930 MockWrite data_writes[] = {
6931 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
6932 "Host: www.google.com\r\n"
6933 "Proxy-Connection: keep-alive\r\n"
6934 "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
6935 };
6936 MockRead data_reads[] = {
6937 // Return an error, so the transaction stops here (this test isn't
6938 // interested in the rest).
6939 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
6940 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
6941 MockRead("Proxy-Connection: close\r\n\r\n"),
6942 };
6943
6944 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6945 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076946 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]da81f132010-08-18 23:39:296947
[email protected]49639fa2011-12-20 23:22:416948 TestCompletionCallback callback;
[email protected]da81f132010-08-18 23:39:296949
[email protected]49639fa2011-12-20 23:22:416950 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]da81f132010-08-18 23:39:296951 EXPECT_EQ(ERR_IO_PENDING, rv);
6952
6953 rv = callback.WaitForResult();
6954 EXPECT_EQ(OK, rv);
6955}
6956
[email protected]23e482282013-06-14 16:08:026957TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) {
[email protected]1c773ea12009-04-28 19:58:426958 HttpRequestInfo request;
6959 request.method = "GET";
6960 request.url = GURL("http://www.google.com/");
6961 request.load_flags = 0;
[email protected]c10450102011-06-27 09:06:166962 request.extra_headers.SetHeader(HttpRequestHeaders::kReferer,
6963 "http://the.previous.site.com/");
[email protected]1c773ea12009-04-28 19:58:426964
[email protected]3fe8d2f82013-10-17 08:56:076965 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:276966 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:416967 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:276968
[email protected]1c773ea12009-04-28 19:58:426969 MockWrite data_writes[] = {
6970 MockWrite("GET / HTTP/1.1\r\n"
6971 "Host: www.google.com\r\n"
6972 "Connection: keep-alive\r\n"
6973 "Referer: http://the.previous.site.com/\r\n\r\n"),
6974 };
6975
6976 // Lastly, the server responds with the actual content.
6977 MockRead data_reads[] = {
6978 MockRead("HTTP/1.0 200 OK\r\n"),
6979 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
6980 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:066981 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:426982 };
6983
[email protected]31a2bfe2010-02-09 08:03:396984 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
6985 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:076986 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:426987
[email protected]49639fa2011-12-20 23:22:416988 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:426989
[email protected]49639fa2011-12-20 23:22:416990 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:426991 EXPECT_EQ(ERR_IO_PENDING, rv);
6992
6993 rv = callback.WaitForResult();
6994 EXPECT_EQ(OK, rv);
6995}
6996
[email protected]23e482282013-06-14 16:08:026997TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) {
[email protected]1c773ea12009-04-28 19:58:426998 HttpRequestInfo request;
6999 request.method = "POST";
7000 request.url = GURL("http://www.google.com/");
7001
[email protected]3fe8d2f82013-10-17 08:56:077002 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277003 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417004 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277005
[email protected]1c773ea12009-04-28 19:58:427006 MockWrite data_writes[] = {
7007 MockWrite("POST / HTTP/1.1\r\n"
7008 "Host: www.google.com\r\n"
7009 "Connection: keep-alive\r\n"
7010 "Content-Length: 0\r\n\r\n"),
7011 };
7012
7013 // Lastly, the server responds with the actual content.
7014 MockRead data_reads[] = {
7015 MockRead("HTTP/1.0 200 OK\r\n"),
7016 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7017 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067018 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427019 };
7020
[email protected]31a2bfe2010-02-09 08:03:397021 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7022 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077023 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427024
[email protected]49639fa2011-12-20 23:22:417025 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427026
[email protected]49639fa2011-12-20 23:22:417027 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427028 EXPECT_EQ(ERR_IO_PENDING, rv);
7029
7030 rv = callback.WaitForResult();
7031 EXPECT_EQ(OK, rv);
7032}
7033
[email protected]23e482282013-06-14 16:08:027034TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) {
[email protected]1c773ea12009-04-28 19:58:427035 HttpRequestInfo request;
7036 request.method = "PUT";
7037 request.url = GURL("http://www.google.com/");
7038
[email protected]3fe8d2f82013-10-17 08:56:077039 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277040 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417041 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277042
[email protected]1c773ea12009-04-28 19:58:427043 MockWrite data_writes[] = {
7044 MockWrite("PUT / HTTP/1.1\r\n"
7045 "Host: www.google.com\r\n"
7046 "Connection: keep-alive\r\n"
7047 "Content-Length: 0\r\n\r\n"),
7048 };
7049
7050 // Lastly, the server responds with the actual content.
7051 MockRead data_reads[] = {
7052 MockRead("HTTP/1.0 200 OK\r\n"),
7053 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7054 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067055 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427056 };
7057
[email protected]31a2bfe2010-02-09 08:03:397058 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7059 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077060 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427061
[email protected]49639fa2011-12-20 23:22:417062 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427063
[email protected]49639fa2011-12-20 23:22:417064 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427065 EXPECT_EQ(ERR_IO_PENDING, rv);
7066
7067 rv = callback.WaitForResult();
7068 EXPECT_EQ(OK, rv);
7069}
7070
[email protected]23e482282013-06-14 16:08:027071TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) {
[email protected]1c773ea12009-04-28 19:58:427072 HttpRequestInfo request;
7073 request.method = "HEAD";
7074 request.url = GURL("http://www.google.com/");
7075
[email protected]3fe8d2f82013-10-17 08:56:077076 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277077 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417078 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277079
[email protected]1c773ea12009-04-28 19:58:427080 MockWrite data_writes[] = {
7081 MockWrite("HEAD / HTTP/1.1\r\n"
7082 "Host: www.google.com\r\n"
7083 "Connection: keep-alive\r\n"
7084 "Content-Length: 0\r\n\r\n"),
7085 };
7086
7087 // Lastly, the server responds with the actual content.
7088 MockRead data_reads[] = {
7089 MockRead("HTTP/1.0 200 OK\r\n"),
7090 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7091 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067092 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427093 };
7094
[email protected]31a2bfe2010-02-09 08:03:397095 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7096 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077097 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427098
[email protected]49639fa2011-12-20 23:22:417099 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427100
[email protected]49639fa2011-12-20 23:22:417101 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427102 EXPECT_EQ(ERR_IO_PENDING, rv);
7103
7104 rv = callback.WaitForResult();
7105 EXPECT_EQ(OK, rv);
7106}
7107
[email protected]23e482282013-06-14 16:08:027108TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) {
[email protected]1c773ea12009-04-28 19:58:427109 HttpRequestInfo request;
7110 request.method = "GET";
7111 request.url = GURL("http://www.google.com/");
7112 request.load_flags = LOAD_BYPASS_CACHE;
7113
[email protected]3fe8d2f82013-10-17 08:56:077114 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277115 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417116 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277117
[email protected]1c773ea12009-04-28 19:58:427118 MockWrite data_writes[] = {
7119 MockWrite("GET / HTTP/1.1\r\n"
7120 "Host: www.google.com\r\n"
7121 "Connection: keep-alive\r\n"
7122 "Pragma: no-cache\r\n"
7123 "Cache-Control: no-cache\r\n\r\n"),
7124 };
7125
7126 // Lastly, the server responds with the actual content.
7127 MockRead data_reads[] = {
7128 MockRead("HTTP/1.0 200 OK\r\n"),
7129 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7130 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067131 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427132 };
7133
[email protected]31a2bfe2010-02-09 08:03:397134 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7135 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077136 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427137
[email protected]49639fa2011-12-20 23:22:417138 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427139
[email protected]49639fa2011-12-20 23:22:417140 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427141 EXPECT_EQ(ERR_IO_PENDING, rv);
7142
7143 rv = callback.WaitForResult();
7144 EXPECT_EQ(OK, rv);
7145}
7146
[email protected]23e482282013-06-14 16:08:027147TEST_P(HttpNetworkTransactionTest,
[email protected]1c773ea12009-04-28 19:58:427148 BuildRequest_CacheControlValidateCache) {
[email protected]1c773ea12009-04-28 19:58:427149 HttpRequestInfo request;
7150 request.method = "GET";
7151 request.url = GURL("http://www.google.com/");
7152 request.load_flags = LOAD_VALIDATE_CACHE;
7153
[email protected]3fe8d2f82013-10-17 08:56:077154 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277155 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417156 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277157
[email protected]1c773ea12009-04-28 19:58:427158 MockWrite data_writes[] = {
7159 MockWrite("GET / HTTP/1.1\r\n"
7160 "Host: www.google.com\r\n"
7161 "Connection: keep-alive\r\n"
7162 "Cache-Control: max-age=0\r\n\r\n"),
7163 };
7164
7165 // Lastly, the server responds with the actual content.
7166 MockRead data_reads[] = {
7167 MockRead("HTTP/1.0 200 OK\r\n"),
7168 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7169 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067170 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427171 };
7172
[email protected]31a2bfe2010-02-09 08:03:397173 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7174 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077175 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427176
[email protected]49639fa2011-12-20 23:22:417177 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427178
[email protected]49639fa2011-12-20 23:22:417179 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427180 EXPECT_EQ(ERR_IO_PENDING, rv);
7181
7182 rv = callback.WaitForResult();
7183 EXPECT_EQ(OK, rv);
7184}
7185
[email protected]23e482282013-06-14 16:08:027186TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) {
[email protected]1c773ea12009-04-28 19:58:427187 HttpRequestInfo request;
7188 request.method = "GET";
7189 request.url = GURL("http://www.google.com/");
[email protected]8c76ae22010-04-20 22:15:437190 request.extra_headers.SetHeader("FooHeader", "Bar");
[email protected]1c773ea12009-04-28 19:58:427191
[email protected]3fe8d2f82013-10-17 08:56:077192 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277193 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417194 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277195
[email protected]1c773ea12009-04-28 19:58:427196 MockWrite data_writes[] = {
7197 MockWrite("GET / HTTP/1.1\r\n"
7198 "Host: www.google.com\r\n"
7199 "Connection: keep-alive\r\n"
7200 "FooHeader: Bar\r\n\r\n"),
7201 };
7202
7203 // Lastly, the server responds with the actual content.
7204 MockRead data_reads[] = {
7205 MockRead("HTTP/1.0 200 OK\r\n"),
7206 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7207 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067208 MockRead(SYNCHRONOUS, OK),
[email protected]1c773ea12009-04-28 19:58:427209 };
7210
[email protected]31a2bfe2010-02-09 08:03:397211 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7212 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077213 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]1c773ea12009-04-28 19:58:427214
[email protected]49639fa2011-12-20 23:22:417215 TestCompletionCallback callback;
[email protected]1c773ea12009-04-28 19:58:427216
[email protected]49639fa2011-12-20 23:22:417217 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]1c773ea12009-04-28 19:58:427218 EXPECT_EQ(ERR_IO_PENDING, rv);
7219
7220 rv = callback.WaitForResult();
7221 EXPECT_EQ(OK, rv);
7222}
7223
[email protected]23e482282013-06-14 16:08:027224TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) {
[email protected]270c6412010-03-29 22:02:477225 HttpRequestInfo request;
7226 request.method = "GET";
7227 request.url = GURL("http://www.google.com/");
[email protected]8c76ae22010-04-20 22:15:437228 request.extra_headers.SetHeader("referer", "www.foo.com");
7229 request.extra_headers.SetHeader("hEllo", "Kitty");
7230 request.extra_headers.SetHeader("FoO", "bar");
[email protected]270c6412010-03-29 22:02:477231
[email protected]3fe8d2f82013-10-17 08:56:077232 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:277233 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417234 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277235
[email protected]270c6412010-03-29 22:02:477236 MockWrite data_writes[] = {
7237 MockWrite("GET / HTTP/1.1\r\n"
7238 "Host: www.google.com\r\n"
7239 "Connection: keep-alive\r\n"
[email protected]c10450102011-06-27 09:06:167240 "referer: www.foo.com\r\n"
[email protected]270c6412010-03-29 22:02:477241 "hEllo: Kitty\r\n"
7242 "FoO: bar\r\n\r\n"),
7243 };
7244
7245 // Lastly, the server responds with the actual content.
7246 MockRead data_reads[] = {
7247 MockRead("HTTP/1.0 200 OK\r\n"),
7248 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
7249 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:067250 MockRead(SYNCHRONOUS, OK),
[email protected]270c6412010-03-29 22:02:477251 };
7252
7253 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7254 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077255 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]270c6412010-03-29 22:02:477256
[email protected]49639fa2011-12-20 23:22:417257 TestCompletionCallback callback;
[email protected]270c6412010-03-29 22:02:477258
[email protected]49639fa2011-12-20 23:22:417259 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]270c6412010-03-29 22:02:477260 EXPECT_EQ(ERR_IO_PENDING, rv);
7261
7262 rv = callback.WaitForResult();
7263 EXPECT_EQ(OK, rv);
7264}
7265
[email protected]23e482282013-06-14 16:08:027266TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277267 HttpRequestInfo request;
7268 request.method = "GET";
7269 request.url = GURL("http://www.google.com/");
7270 request.load_flags = 0;
7271
[email protected]bb88e1d32013-05-03 23:11:077272 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207273 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"));
7274 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077275 session_deps_.net_log = &net_log;
[email protected]3cd17242009-06-23 02:59:027276
[email protected]3fe8d2f82013-10-17 08:56:077277 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3cd17242009-06-23 02:59:027278 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417279 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]3cd17242009-06-23 02:59:027280
[email protected]3cd17242009-06-23 02:59:027281 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
7282 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
7283
7284 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067285 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)),
[email protected]3cd17242009-06-23 02:59:027286 MockWrite("GET / HTTP/1.1\r\n"
7287 "Host: www.google.com\r\n"
7288 "Connection: keep-alive\r\n\r\n")
7289 };
7290
7291 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:067292 MockRead(ASYNC, read_buffer, arraysize(read_buffer)),
[email protected]3cd17242009-06-23 02:59:027293 MockRead("HTTP/1.0 200 OK\r\n"),
7294 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7295 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067296 MockRead(SYNCHRONOUS, OK)
[email protected]3cd17242009-06-23 02:59:027297 };
7298
[email protected]31a2bfe2010-02-09 08:03:397299 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7300 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077301 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3cd17242009-06-23 02:59:027302
[email protected]49639fa2011-12-20 23:22:417303 TestCompletionCallback callback;
[email protected]3cd17242009-06-23 02:59:027304
[email protected]49639fa2011-12-20 23:22:417305 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]3cd17242009-06-23 02:59:027306 EXPECT_EQ(ERR_IO_PENDING, rv);
7307
7308 rv = callback.WaitForResult();
7309 EXPECT_EQ(OK, rv);
7310
7311 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507312 ASSERT_TRUE(response != NULL);
[email protected]3cd17242009-06-23 02:59:027313
[email protected]029c83b62013-01-24 05:28:207314 LoadTimingInfo load_timing_info;
7315 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7316 TestLoadTimingNotReusedWithPac(load_timing_info,
7317 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
7318
[email protected]3cd17242009-06-23 02:59:027319 std::string response_text;
7320 rv = ReadTransaction(trans.get(), &response_text);
7321 EXPECT_EQ(OK, rv);
7322 EXPECT_EQ("Payload", response_text);
7323}
7324
[email protected]23e482282013-06-14 16:08:027325TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277326 HttpRequestInfo request;
7327 request.method = "GET";
7328 request.url = GURL("https://www.google.com/");
7329 request.load_flags = 0;
7330
[email protected]bb88e1d32013-05-03 23:11:077331 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207332 ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"));
7333 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077334 session_deps_.net_log = &net_log;
[email protected]3cd17242009-06-23 02:59:027335
[email protected]3fe8d2f82013-10-17 08:56:077336 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3cd17242009-06-23 02:59:027337 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417338 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]3cd17242009-06-23 02:59:027339
[email protected]3cd17242009-06-23 02:59:027340 unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 };
7341 unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
7342
7343 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067344 MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer),
[email protected]e0c27be2009-07-15 13:09:357345 arraysize(write_buffer)),
[email protected]3cd17242009-06-23 02:59:027346 MockWrite("GET / HTTP/1.1\r\n"
7347 "Host: www.google.com\r\n"
7348 "Connection: keep-alive\r\n\r\n")
7349 };
7350
7351 MockRead data_reads[] = {
[email protected]f871ee152012-07-27 19:02:017352 MockRead(ASYNC, reinterpret_cast<char*>(read_buffer),
7353 arraysize(read_buffer)),
[email protected]e0c27be2009-07-15 13:09:357354 MockRead("HTTP/1.0 200 OK\r\n"),
7355 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7356 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067357 MockRead(SYNCHRONOUS, OK)
[email protected]e0c27be2009-07-15 13:09:357358 };
7359
[email protected]31a2bfe2010-02-09 08:03:397360 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7361 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077362 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]e0c27be2009-07-15 13:09:357363
[email protected]8ddf8322012-02-23 18:08:067364 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:077365 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e0c27be2009-07-15 13:09:357366
[email protected]49639fa2011-12-20 23:22:417367 TestCompletionCallback callback;
[email protected]e0c27be2009-07-15 13:09:357368
[email protected]49639fa2011-12-20 23:22:417369 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]e0c27be2009-07-15 13:09:357370 EXPECT_EQ(ERR_IO_PENDING, rv);
7371
7372 rv = callback.WaitForResult();
7373 EXPECT_EQ(OK, rv);
7374
[email protected]029c83b62013-01-24 05:28:207375 LoadTimingInfo load_timing_info;
7376 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7377 TestLoadTimingNotReusedWithPac(load_timing_info,
7378 CONNECT_TIMING_HAS_SSL_TIMES);
7379
[email protected]e0c27be2009-07-15 13:09:357380 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507381 ASSERT_TRUE(response != NULL);
[email protected]e0c27be2009-07-15 13:09:357382
7383 std::string response_text;
7384 rv = ReadTransaction(trans.get(), &response_text);
7385 EXPECT_EQ(OK, rv);
7386 EXPECT_EQ("Payload", response_text);
7387}
7388
[email protected]23e482282013-06-14 16:08:027389TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) {
[email protected]029c83b62013-01-24 05:28:207390 HttpRequestInfo request;
7391 request.method = "GET";
7392 request.url = GURL("http://www.google.com/");
7393 request.load_flags = 0;
7394
[email protected]bb88e1d32013-05-03 23:11:077395 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207396 ProxyService::CreateFixed("socks4://myproxy:1080"));
7397 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077398 session_deps_.net_log = &net_log;
[email protected]029c83b62013-01-24 05:28:207399
[email protected]3fe8d2f82013-10-17 08:56:077400 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]029c83b62013-01-24 05:28:207401 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417402 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]029c83b62013-01-24 05:28:207403
7404 char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 };
7405 char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
7406
7407 MockWrite data_writes[] = {
7408 MockWrite(ASYNC, write_buffer, arraysize(write_buffer)),
7409 MockWrite("GET / HTTP/1.1\r\n"
7410 "Host: www.google.com\r\n"
7411 "Connection: keep-alive\r\n\r\n")
7412 };
7413
7414 MockRead data_reads[] = {
7415 MockRead(ASYNC, read_buffer, arraysize(read_buffer)),
7416 MockRead("HTTP/1.0 200 OK\r\n"),
7417 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7418 MockRead("Payload"),
7419 MockRead(SYNCHRONOUS, OK)
7420 };
7421
7422 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7423 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077424 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]029c83b62013-01-24 05:28:207425
7426 TestCompletionCallback callback;
7427
7428 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
7429 EXPECT_EQ(ERR_IO_PENDING, rv);
7430
7431 rv = callback.WaitForResult();
7432 EXPECT_EQ(OK, rv);
7433
7434 const HttpResponseInfo* response = trans->GetResponseInfo();
7435 ASSERT_TRUE(response != NULL);
7436
7437 LoadTimingInfo load_timing_info;
7438 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7439 TestLoadTimingNotReused(load_timing_info,
7440 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
7441
7442 std::string response_text;
7443 rv = ReadTransaction(trans.get(), &response_text);
7444 EXPECT_EQ(OK, rv);
7445 EXPECT_EQ("Payload", response_text);
7446}
7447
[email protected]23e482282013-06-14 16:08:027448TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277449 HttpRequestInfo request;
7450 request.method = "GET";
7451 request.url = GURL("http://www.google.com/");
7452 request.load_flags = 0;
7453
[email protected]bb88e1d32013-05-03 23:11:077454 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207455 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"));
7456 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077457 session_deps_.net_log = &net_log;
[email protected]e0c27be2009-07-15 13:09:357458
[email protected]3fe8d2f82013-10-17 08:56:077459 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]e0c27be2009-07-15 13:09:357460 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417461 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]e0c27be2009-07-15 13:09:357462
[email protected]e0c27be2009-07-15 13:09:357463 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
7464 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
[email protected]f209dba2009-12-18 00:24:377465 const char kSOCKS5OkRequest[] = {
7466 0x05, // Version
7467 0x01, // Command (CONNECT)
7468 0x00, // Reserved.
7469 0x03, // Address type (DOMAINNAME).
7470 0x0E, // Length of domain (14)
7471 // Domain string:
7472 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm',
7473 0x00, 0x50, // 16-bit port (80)
7474 };
[email protected]e0c27be2009-07-15 13:09:357475 const char kSOCKS5OkResponse[] =
7476 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
7477
7478 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067479 MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
7480 MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)),
[email protected]e0c27be2009-07-15 13:09:357481 MockWrite("GET / HTTP/1.1\r\n"
7482 "Host: www.google.com\r\n"
7483 "Connection: keep-alive\r\n\r\n")
7484 };
7485
7486 MockRead data_reads[] = {
[email protected]f871ee152012-07-27 19:02:017487 MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
7488 MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)),
[email protected]e0c27be2009-07-15 13:09:357489 MockRead("HTTP/1.0 200 OK\r\n"),
7490 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7491 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067492 MockRead(SYNCHRONOUS, OK)
[email protected]e0c27be2009-07-15 13:09:357493 };
7494
[email protected]31a2bfe2010-02-09 08:03:397495 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7496 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077497 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]e0c27be2009-07-15 13:09:357498
[email protected]49639fa2011-12-20 23:22:417499 TestCompletionCallback callback;
[email protected]e0c27be2009-07-15 13:09:357500
[email protected]49639fa2011-12-20 23:22:417501 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]e0c27be2009-07-15 13:09:357502 EXPECT_EQ(ERR_IO_PENDING, rv);
7503
7504 rv = callback.WaitForResult();
7505 EXPECT_EQ(OK, rv);
7506
7507 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507508 ASSERT_TRUE(response != NULL);
[email protected]e0c27be2009-07-15 13:09:357509
[email protected]029c83b62013-01-24 05:28:207510 LoadTimingInfo load_timing_info;
7511 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7512 TestLoadTimingNotReusedWithPac(load_timing_info,
7513 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
7514
[email protected]e0c27be2009-07-15 13:09:357515 std::string response_text;
7516 rv = ReadTransaction(trans.get(), &response_text);
7517 EXPECT_EQ(OK, rv);
7518 EXPECT_EQ("Payload", response_text);
7519}
7520
[email protected]23e482282013-06-14 16:08:027521TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) {
[email protected]cb9bf6ca2011-01-28 13:15:277522 HttpRequestInfo request;
7523 request.method = "GET";
7524 request.url = GURL("https://www.google.com/");
7525 request.load_flags = 0;
7526
[email protected]bb88e1d32013-05-03 23:11:077527 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:207528 ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"));
7529 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:077530 session_deps_.net_log = &net_log;
[email protected]e0c27be2009-07-15 13:09:357531
[email protected]3fe8d2f82013-10-17 08:56:077532 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]e0c27be2009-07-15 13:09:357533 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417534 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]e0c27be2009-07-15 13:09:357535
[email protected]e0c27be2009-07-15 13:09:357536 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
7537 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
[email protected]f209dba2009-12-18 00:24:377538 const unsigned char kSOCKS5OkRequest[] = {
7539 0x05, // Version
7540 0x01, // Command (CONNECT)
7541 0x00, // Reserved.
7542 0x03, // Address type (DOMAINNAME).
7543 0x0E, // Length of domain (14)
7544 // Domain string:
7545 'w', 'w', 'w', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'c', 'o', 'm',
7546 0x01, 0xBB, // 16-bit port (443)
7547 };
7548
[email protected]e0c27be2009-07-15 13:09:357549 const char kSOCKS5OkResponse[] =
7550 { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 };
7551
7552 MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:067553 MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
7554 MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest),
[email protected]e0c27be2009-07-15 13:09:357555 arraysize(kSOCKS5OkRequest)),
7556 MockWrite("GET / HTTP/1.1\r\n"
7557 "Host: www.google.com\r\n"
7558 "Connection: keep-alive\r\n\r\n")
7559 };
7560
7561 MockRead data_reads[] = {
[email protected]f871ee152012-07-27 19:02:017562 MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
7563 MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)),
[email protected]3cd17242009-06-23 02:59:027564 MockRead("HTTP/1.0 200 OK\r\n"),
7565 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
7566 MockRead("Payload"),
[email protected]8ddf8322012-02-23 18:08:067567 MockRead(SYNCHRONOUS, OK)
[email protected]3cd17242009-06-23 02:59:027568 };
7569
[email protected]31a2bfe2010-02-09 08:03:397570 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
7571 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:077572 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3cd17242009-06-23 02:59:027573
[email protected]8ddf8322012-02-23 18:08:067574 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:077575 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]3cd17242009-06-23 02:59:027576
[email protected]49639fa2011-12-20 23:22:417577 TestCompletionCallback callback;
[email protected]3cd17242009-06-23 02:59:027578
[email protected]49639fa2011-12-20 23:22:417579 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]3cd17242009-06-23 02:59:027580 EXPECT_EQ(ERR_IO_PENDING, rv);
7581
7582 rv = callback.WaitForResult();
7583 EXPECT_EQ(OK, rv);
7584
7585 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:507586 ASSERT_TRUE(response != NULL);
[email protected]3cd17242009-06-23 02:59:027587
[email protected]029c83b62013-01-24 05:28:207588 LoadTimingInfo load_timing_info;
7589 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
7590 TestLoadTimingNotReusedWithPac(load_timing_info,
7591 CONNECT_TIMING_HAS_SSL_TIMES);
7592
[email protected]3cd17242009-06-23 02:59:027593 std::string response_text;
7594 rv = ReadTransaction(trans.get(), &response_text);
7595 EXPECT_EQ(OK, rv);
7596 EXPECT_EQ("Payload", response_text);
7597}
7598
[email protected]448d4ca52012-03-04 04:12:237599namespace {
7600
[email protected]04e5be32009-06-26 20:00:317601// Tests that for connection endpoints the group names are correctly set.
[email protected]2d731a32010-04-29 01:04:067602
7603struct GroupNameTest {
7604 std::string proxy_server;
7605 std::string url;
7606 std::string expected_group_name;
[email protected]e60e47a2010-07-14 03:37:187607 bool ssl;
[email protected]2d731a32010-04-29 01:04:067608};
7609
7610scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests(
[email protected]8a0fc822013-06-27 20:52:437611 NextProto next_proto,
[email protected]bb88e1d32013-05-03 23:11:077612 SpdySessionDependencies* session_deps_) {
7613 scoped_refptr<HttpNetworkSession> session(CreateSession(session_deps_));
[email protected]2d731a32010-04-29 01:04:067614
[email protected]30d4c022013-07-18 22:58:167615 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:537616 session->http_server_properties();
7617 http_server_properties->SetAlternateProtocol(
[email protected]2d731a32010-04-29 01:04:067618 HostPortPair("host.with.alternate", 80), 443,
bnc1102b552015-01-30 20:11:017619 AlternateProtocolFromNextProto(next_proto), 1.0);
[email protected]2d731a32010-04-29 01:04:067620
7621 return session;
7622}
7623
7624int GroupNameTransactionHelper(
7625 const std::string& url,
7626 const scoped_refptr<HttpNetworkSession>& session) {
[email protected]2d731a32010-04-29 01:04:067627 HttpRequestInfo request;
7628 request.method = "GET";
7629 request.url = GURL(url);
7630 request.load_flags = 0;
7631
[email protected]262eec82013-03-19 21:01:367632 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:507633 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:277634
[email protected]49639fa2011-12-20 23:22:417635 TestCompletionCallback callback;
[email protected]2d731a32010-04-29 01:04:067636
7637 // We do not complete this request, the dtor will clean the transaction up.
[email protected]49639fa2011-12-20 23:22:417638 return trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d731a32010-04-29 01:04:067639}
7640
[email protected]448d4ca52012-03-04 04:12:237641} // namespace
7642
[email protected]23e482282013-06-14 16:08:027643TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) {
[email protected]2d731a32010-04-29 01:04:067644 const GroupNameTest tests[] = {
[email protected]04e5be32009-06-26 20:00:317645 {
[email protected]2d731a32010-04-29 01:04:067646 "", // unused
[email protected]04e5be32009-06-26 20:00:317647 "http://www.google.com/direct",
[email protected]2ff8b312010-04-26 22:20:547648 "www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187649 false,
[email protected]2ff8b312010-04-26 22:20:547650 },
7651 {
[email protected]2d731a32010-04-29 01:04:067652 "", // unused
[email protected]2ff8b312010-04-26 22:20:547653 "http://[2001:1418:13:1::25]/direct",
7654 "[2001:1418:13:1::25]:80",
[email protected]e60e47a2010-07-14 03:37:187655 false,
[email protected]04e5be32009-06-26 20:00:317656 },
[email protected]04e5be32009-06-26 20:00:317657
7658 // SSL Tests
7659 {
[email protected]2d731a32010-04-29 01:04:067660 "", // unused
[email protected]04e5be32009-06-26 20:00:317661 "https://www.google.com/direct_ssl",
[email protected]0e88ad602010-05-04 23:47:027662 "ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187663 true,
[email protected]04e5be32009-06-26 20:00:317664 },
7665 {
[email protected]2d731a32010-04-29 01:04:067666 "", // unused
7667 "https://[2001:1418:13:1::25]/direct",
[email protected]0e88ad602010-05-04 23:47:027668 "ssl/[2001:1418:13:1::25]:443",
[email protected]e60e47a2010-07-14 03:37:187669 true,
[email protected]04e5be32009-06-26 20:00:317670 },
7671 {
[email protected]2d731a32010-04-29 01:04:067672 "", // unused
[email protected]2ff8b312010-04-26 22:20:547673 "http://host.with.alternate/direct",
[email protected]0e88ad602010-05-04 23:47:027674 "ssl/host.with.alternate:443",
[email protected]e60e47a2010-07-14 03:37:187675 true,
[email protected]2ff8b312010-04-26 22:20:547676 },
[email protected]2d731a32010-04-29 01:04:067677 };
[email protected]2ff8b312010-04-26 22:20:547678
[email protected]d7599122014-05-24 03:37:237679 session_deps_.use_alternate_protocols = true;
[email protected]2d731a32010-04-29 01:04:067680
viettrungluue4a8b882014-10-16 06:17:387681 for (size_t i = 0; i < arraysize(tests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:077682 session_deps_.proxy_service.reset(
[email protected]8b114dd72011-03-25 05:33:027683 ProxyService::CreateFixed(tests[i].proxy_server));
[email protected]2d731a32010-04-29 01:04:067684 scoped_refptr<HttpNetworkSession> session(
[email protected]8a0fc822013-06-27 20:52:437685 SetupSessionForGroupNameTests(GetParam(), &session_deps_));
[email protected]2d731a32010-04-29 01:04:067686
7687 HttpNetworkSessionPeer peer(session);
[email protected]ab739042011-04-07 15:22:287688 CaptureGroupNameTransportSocketPool* transport_conn_pool =
7689 new CaptureGroupNameTransportSocketPool(NULL, NULL);
[email protected]2431756e2010-09-29 20:26:137690 CaptureGroupNameSSLSocketPool* ssl_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347691 new CaptureGroupNameSSLSocketPool(NULL, NULL);
[email protected]831e4a32013-11-14 02:14:447692 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
7693 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:027694 mock_pool_manager->SetTransportSocketPool(transport_conn_pool);
7695 mock_pool_manager->SetSSLSocketPool(ssl_conn_pool);
dchenge3d1ddc2014-10-15 19:30:517696 peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]2d731a32010-04-29 01:04:067697
7698 EXPECT_EQ(ERR_IO_PENDING,
7699 GroupNameTransactionHelper(tests[i].url, session));
[email protected]e60e47a2010-07-14 03:37:187700 if (tests[i].ssl)
7701 EXPECT_EQ(tests[i].expected_group_name,
7702 ssl_conn_pool->last_group_name_received());
7703 else
7704 EXPECT_EQ(tests[i].expected_group_name,
[email protected]ab739042011-04-07 15:22:287705 transport_conn_pool->last_group_name_received());
[email protected]2d731a32010-04-29 01:04:067706 }
7707
[email protected]2d731a32010-04-29 01:04:067708}
7709
[email protected]23e482282013-06-14 16:08:027710TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) {
[email protected]2d731a32010-04-29 01:04:067711 const GroupNameTest tests[] = {
7712 {
7713 "http_proxy",
7714 "http://www.google.com/http_proxy_normal",
7715 "www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187716 false,
[email protected]2d731a32010-04-29 01:04:067717 },
7718
7719 // SSL Tests
7720 {
7721 "http_proxy",
7722 "https://www.google.com/http_connect_ssl",
[email protected]0e88ad602010-05-04 23:47:027723 "ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187724 true,
[email protected]2d731a32010-04-29 01:04:067725 },
[email protected]af3490e2010-10-16 21:02:297726
[email protected]9faeded92010-04-29 20:03:057727 {
7728 "http_proxy",
7729 "http://host.with.alternate/direct",
[email protected]0e88ad602010-05-04 23:47:027730 "ssl/host.with.alternate:443",
[email protected]e60e47a2010-07-14 03:37:187731 true,
[email protected]9faeded92010-04-29 20:03:057732 },
[email protected]45499252013-01-23 17:12:567733
7734 {
7735 "http_proxy",
7736 "ftp://ftp.google.com/http_proxy_normal",
7737 "ftp/ftp.google.com:21",
7738 false,
7739 },
[email protected]2d731a32010-04-29 01:04:067740 };
7741
[email protected]d7599122014-05-24 03:37:237742 session_deps_.use_alternate_protocols = true;
[email protected]2d731a32010-04-29 01:04:067743
viettrungluue4a8b882014-10-16 06:17:387744 for (size_t i = 0; i < arraysize(tests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:077745 session_deps_.proxy_service.reset(
[email protected]8b114dd72011-03-25 05:33:027746 ProxyService::CreateFixed(tests[i].proxy_server));
[email protected]2d731a32010-04-29 01:04:067747 scoped_refptr<HttpNetworkSession> session(
[email protected]8a0fc822013-06-27 20:52:437748 SetupSessionForGroupNameTests(GetParam(), &session_deps_));
[email protected]2d731a32010-04-29 01:04:067749
7750 HttpNetworkSessionPeer peer(session);
7751
[email protected]e60e47a2010-07-14 03:37:187752 HostPortPair proxy_host("http_proxy", 80);
[email protected]2431756e2010-09-29 20:26:137753 CaptureGroupNameHttpProxySocketPool* http_proxy_pool =
[email protected]9e1bdd32011-02-03 21:48:347754 new CaptureGroupNameHttpProxySocketPool(NULL, NULL);
[email protected]2431756e2010-09-29 20:26:137755 CaptureGroupNameSSLSocketPool* ssl_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347756 new CaptureGroupNameSSLSocketPool(NULL, NULL);
[email protected]a42dbd142011-11-17 16:42:027757
[email protected]831e4a32013-11-14 02:14:447758 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
7759 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:027760 mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool);
7761 mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
dchenge3d1ddc2014-10-15 19:30:517762 peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]2d731a32010-04-29 01:04:067763
7764 EXPECT_EQ(ERR_IO_PENDING,
7765 GroupNameTransactionHelper(tests[i].url, session));
[email protected]e60e47a2010-07-14 03:37:187766 if (tests[i].ssl)
7767 EXPECT_EQ(tests[i].expected_group_name,
7768 ssl_conn_pool->last_group_name_received());
7769 else
7770 EXPECT_EQ(tests[i].expected_group_name,
7771 http_proxy_pool->last_group_name_received());
[email protected]2d731a32010-04-29 01:04:067772 }
[email protected]2d731a32010-04-29 01:04:067773}
7774
[email protected]23e482282013-06-14 16:08:027775TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) {
[email protected]2d731a32010-04-29 01:04:067776 const GroupNameTest tests[] = {
7777 {
7778 "socks4://socks_proxy:1080",
7779 "http://www.google.com/socks4_direct",
7780 "socks4/www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187781 false,
[email protected]2d731a32010-04-29 01:04:067782 },
7783 {
7784 "socks5://socks_proxy:1080",
7785 "http://www.google.com/socks5_direct",
7786 "socks5/www.google.com:80",
[email protected]e60e47a2010-07-14 03:37:187787 false,
[email protected]2d731a32010-04-29 01:04:067788 },
7789
7790 // SSL Tests
7791 {
7792 "socks4://socks_proxy:1080",
7793 "https://www.google.com/socks4_ssl",
[email protected]0e88ad602010-05-04 23:47:027794 "socks4/ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187795 true,
[email protected]2d731a32010-04-29 01:04:067796 },
7797 {
7798 "socks5://socks_proxy:1080",
7799 "https://www.google.com/socks5_ssl",
[email protected]0e88ad602010-05-04 23:47:027800 "socks5/ssl/www.google.com:443",
[email protected]e60e47a2010-07-14 03:37:187801 true,
[email protected]2d731a32010-04-29 01:04:067802 },
[email protected]af3490e2010-10-16 21:02:297803
[email protected]9faeded92010-04-29 20:03:057804 {
7805 "socks4://socks_proxy:1080",
7806 "http://host.with.alternate/direct",
[email protected]0e88ad602010-05-04 23:47:027807 "socks4/ssl/host.with.alternate:443",
[email protected]e60e47a2010-07-14 03:37:187808 true,
[email protected]9faeded92010-04-29 20:03:057809 },
[email protected]04e5be32009-06-26 20:00:317810 };
7811
[email protected]d7599122014-05-24 03:37:237812 session_deps_.use_alternate_protocols = true;
[email protected]2ff8b312010-04-26 22:20:547813
viettrungluue4a8b882014-10-16 06:17:387814 for (size_t i = 0; i < arraysize(tests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:077815 session_deps_.proxy_service.reset(
[email protected]8b114dd72011-03-25 05:33:027816 ProxyService::CreateFixed(tests[i].proxy_server));
[email protected]2d731a32010-04-29 01:04:067817 scoped_refptr<HttpNetworkSession> session(
[email protected]8a0fc822013-06-27 20:52:437818 SetupSessionForGroupNameTests(GetParam(), &session_deps_));
[email protected]8b114dd72011-03-25 05:33:027819
[email protected]2d731a32010-04-29 01:04:067820 HttpNetworkSessionPeer peer(session);
[email protected]04e5be32009-06-26 20:00:317821
[email protected]e60e47a2010-07-14 03:37:187822 HostPortPair proxy_host("socks_proxy", 1080);
[email protected]2431756e2010-09-29 20:26:137823 CaptureGroupNameSOCKSSocketPool* socks_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347824 new CaptureGroupNameSOCKSSocketPool(NULL, NULL);
[email protected]2431756e2010-09-29 20:26:137825 CaptureGroupNameSSLSocketPool* ssl_conn_pool =
[email protected]9e1bdd32011-02-03 21:48:347826 new CaptureGroupNameSSLSocketPool(NULL, NULL);
[email protected]a42dbd142011-11-17 16:42:027827
[email protected]831e4a32013-11-14 02:14:447828 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
7829 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:027830 mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool);
7831 mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
dchenge3d1ddc2014-10-15 19:30:517832 peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]04e5be32009-06-26 20:00:317833
[email protected]262eec82013-03-19 21:01:367834 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:507835 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]04e5be32009-06-26 20:00:317836
[email protected]2d731a32010-04-29 01:04:067837 EXPECT_EQ(ERR_IO_PENDING,
7838 GroupNameTransactionHelper(tests[i].url, session));
[email protected]e60e47a2010-07-14 03:37:187839 if (tests[i].ssl)
7840 EXPECT_EQ(tests[i].expected_group_name,
7841 ssl_conn_pool->last_group_name_received());
7842 else
7843 EXPECT_EQ(tests[i].expected_group_name,
7844 socks_conn_pool->last_group_name_received());
[email protected]04e5be32009-06-26 20:00:317845 }
7846}
7847
[email protected]23e482282013-06-14 16:08:027848TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) {
[email protected]cb9bf6ca2011-01-28 13:15:277849 HttpRequestInfo request;
7850 request.method = "GET";
7851 request.url = GURL("http://www.google.com/");
7852
[email protected]bb88e1d32013-05-03 23:11:077853 session_deps_.proxy_service.reset(
[email protected]81cdfcd2010-10-16 00:49:007854 ProxyService::CreateFixed("myproxy:70;foobar:80"));
[email protected]b59ff372009-07-15 22:04:327855
[email protected]69719062010-01-05 20:09:217856 // This simulates failure resolving all hostnames; that means we will fail
7857 // connecting to both proxies (myproxy:70 and foobar:80).
[email protected]bb88e1d32013-05-03 23:11:077858 session_deps_.host_resolver->rules()->AddSimulatedFailure("*");
[email protected]b59ff372009-07-15 22:04:327859
[email protected]3fe8d2f82013-10-17 08:56:077860 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]9172a982009-06-06 00:30:257861 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417862 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]9172a982009-06-06 00:30:257863
[email protected]49639fa2011-12-20 23:22:417864 TestCompletionCallback callback;
[email protected]9172a982009-06-06 00:30:257865
[email protected]49639fa2011-12-20 23:22:417866 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]9172a982009-06-06 00:30:257867 EXPECT_EQ(ERR_IO_PENDING, rv);
7868
[email protected]9172a982009-06-06 00:30:257869 rv = callback.WaitForResult();
[email protected]f7fccee2010-09-16 20:53:017870 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv);
[email protected]9172a982009-06-06 00:30:257871}
7872
[email protected]685af592010-05-11 19:31:247873// Base test to make sure that when the load flags for a request specify to
7874// bypass the cache, the DNS cache is not used.
[email protected]23e482282013-06-14 16:08:027875void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper(
[email protected]bb88e1d32013-05-03 23:11:077876 int load_flags) {
[email protected]cb9bf6ca2011-01-28 13:15:277877 // Issue a request, asking to bypass the cache(s).
7878 HttpRequestInfo request;
7879 request.method = "GET";
7880 request.load_flags = load_flags;
7881 request.url = GURL("http://www.google.com/");
7882
[email protected]a2c2fb92009-07-18 07:31:047883 // Select a host resolver that does caching.
[email protected]bb88e1d32013-05-03 23:11:077884 session_deps_.host_resolver.reset(new MockCachingHostResolver);
[email protected]b59ff372009-07-15 22:04:327885
[email protected]3fe8d2f82013-10-17 08:56:077886 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
7887 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417888 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]3b9cca42009-06-16 01:08:287889
[email protected]6e78dfb2011-07-28 21:34:477890 // Warm up the host cache so it has an entry for "www.google.com".
[email protected]3b9cca42009-06-16 01:08:287891 AddressList addrlist;
[email protected]aa22b242011-11-16 18:58:297892 TestCompletionCallback callback;
[email protected]bb88e1d32013-05-03 23:11:077893 int rv = session_deps_.host_resolver->Resolve(
[email protected]5109c1952013-08-20 18:44:107894 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)),
7895 DEFAULT_PRIORITY,
[email protected]b9823c02013-08-16 21:24:417896 &addrlist,
7897 callback.callback(),
7898 NULL,
7899 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:477900 EXPECT_EQ(ERR_IO_PENDING, rv);
7901 rv = callback.WaitForResult();
[email protected]3b9cca42009-06-16 01:08:287902 EXPECT_EQ(OK, rv);
7903
7904 // Verify that it was added to host cache, by doing a subsequent async lookup
7905 // and confirming it completes synchronously.
[email protected]bb88e1d32013-05-03 23:11:077906 rv = session_deps_.host_resolver->Resolve(
[email protected]5109c1952013-08-20 18:44:107907 HostResolver::RequestInfo(HostPortPair("www.google.com", 80)),
7908 DEFAULT_PRIORITY,
[email protected]b9823c02013-08-16 21:24:417909 &addrlist,
7910 callback.callback(),
7911 NULL,
7912 BoundNetLog());
[email protected]b59ff372009-07-15 22:04:327913 ASSERT_EQ(OK, rv);
[email protected]3b9cca42009-06-16 01:08:287914
7915 // Inject a failure the next time that "www.google.com" is resolved. This way
7916 // we can tell if the next lookup hit the cache, or the "network".
7917 // (cache --> success, "network" --> failure).
[email protected]bb88e1d32013-05-03 23:11:077918 session_deps_.host_resolver->rules()->AddSimulatedFailure("www.google.com");
[email protected]3b9cca42009-06-16 01:08:287919
7920 // Connect up a mock socket which will fail with ERR_UNEXPECTED during the
7921 // first read -- this won't be reached as the host resolution will fail first.
[email protected]8ddf8322012-02-23 18:08:067922 MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) };
[email protected]31a2bfe2010-02-09 08:03:397923 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:077924 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3b9cca42009-06-16 01:08:287925
[email protected]3b9cca42009-06-16 01:08:287926 // Run the request.
[email protected]49639fa2011-12-20 23:22:417927 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]3b9cca42009-06-16 01:08:287928 ASSERT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:417929 rv = callback.WaitForResult();
[email protected]3b9cca42009-06-16 01:08:287930
7931 // If we bypassed the cache, we would have gotten a failure while resolving
7932 // "www.google.com".
7933 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv);
7934}
7935
[email protected]685af592010-05-11 19:31:247936// There are multiple load flags that should trigger the host cache bypass.
7937// Test each in isolation:
[email protected]23e482282013-06-14 16:08:027938TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) {
[email protected]685af592010-05-11 19:31:247939 BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE);
7940}
7941
[email protected]23e482282013-06-14 16:08:027942TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) {
[email protected]685af592010-05-11 19:31:247943 BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE);
7944}
7945
[email protected]23e482282013-06-14 16:08:027946TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) {
[email protected]685af592010-05-11 19:31:247947 BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE);
7948}
7949
[email protected]0877e3d2009-10-17 22:29:577950// Make sure we can handle an error when writing the request.
[email protected]23e482282013-06-14 16:08:027951TEST_P(HttpNetworkTransactionTest, RequestWriteError) {
[email protected]0877e3d2009-10-17 22:29:577952 HttpRequestInfo request;
7953 request.method = "GET";
7954 request.url = GURL("http://www.foo.com/");
7955 request.load_flags = 0;
7956
7957 MockWrite write_failure[] = {
[email protected]8ddf8322012-02-23 18:08:067958 MockWrite(ASYNC, ERR_CONNECTION_RESET),
[email protected]0877e3d2009-10-17 22:29:577959 };
[email protected]31a2bfe2010-02-09 08:03:397960 StaticSocketDataProvider data(NULL, 0,
7961 write_failure, arraysize(write_failure));
[email protected]bb88e1d32013-05-03 23:11:077962 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3fe8d2f82013-10-17 08:56:077963 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:577964
[email protected]49639fa2011-12-20 23:22:417965 TestCompletionCallback callback;
[email protected]0877e3d2009-10-17 22:29:577966
7967 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417968 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0877e3d2009-10-17 22:29:577969
[email protected]49639fa2011-12-20 23:22:417970 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:577971 EXPECT_EQ(ERR_IO_PENDING, rv);
7972
7973 rv = callback.WaitForResult();
7974 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
7975}
7976
7977// Check that a connection closed after the start of the headers finishes ok.
[email protected]23e482282013-06-14 16:08:027978TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) {
[email protected]0877e3d2009-10-17 22:29:577979 HttpRequestInfo request;
7980 request.method = "GET";
7981 request.url = GURL("http://www.foo.com/");
7982 request.load_flags = 0;
7983
7984 MockRead data_reads[] = {
7985 MockRead("HTTP/1."),
[email protected]8ddf8322012-02-23 18:08:067986 MockRead(SYNCHRONOUS, OK),
[email protected]0877e3d2009-10-17 22:29:577987 };
7988
[email protected]31a2bfe2010-02-09 08:03:397989 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:077990 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]3fe8d2f82013-10-17 08:56:077991 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:577992
[email protected]49639fa2011-12-20 23:22:417993 TestCompletionCallback callback;
[email protected]0877e3d2009-10-17 22:29:577994
7995 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:417996 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0877e3d2009-10-17 22:29:577997
[email protected]49639fa2011-12-20 23:22:417998 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:577999 EXPECT_EQ(ERR_IO_PENDING, rv);
8000
8001 rv = callback.WaitForResult();
8002 EXPECT_EQ(OK, rv);
8003
8004 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508005 ASSERT_TRUE(response != NULL);
[email protected]0877e3d2009-10-17 22:29:578006
[email protected]90499482013-06-01 00:39:508007 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]0877e3d2009-10-17 22:29:578008 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
8009
8010 std::string response_data;
8011 rv = ReadTransaction(trans.get(), &response_data);
8012 EXPECT_EQ(OK, rv);
8013 EXPECT_EQ("", response_data);
8014}
8015
8016// Make sure that a dropped connection while draining the body for auth
8017// restart does the right thing.
[email protected]23e482282013-06-14 16:08:028018TEST_P(HttpNetworkTransactionTest, DrainResetOK) {
[email protected]0877e3d2009-10-17 22:29:578019 HttpRequestInfo request;
8020 request.method = "GET";
8021 request.url = GURL("http://www.google.com/");
8022 request.load_flags = 0;
8023
8024 MockWrite data_writes1[] = {
8025 MockWrite("GET / HTTP/1.1\r\n"
8026 "Host: www.google.com\r\n"
8027 "Connection: keep-alive\r\n\r\n"),
8028 };
8029
8030 MockRead data_reads1[] = {
8031 MockRead("HTTP/1.1 401 Unauthorized\r\n"),
8032 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
8033 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
8034 MockRead("Content-Length: 14\r\n\r\n"),
8035 MockRead("Unauth"),
[email protected]8ddf8322012-02-23 18:08:068036 MockRead(ASYNC, ERR_CONNECTION_RESET),
[email protected]0877e3d2009-10-17 22:29:578037 };
8038
[email protected]31a2bfe2010-02-09 08:03:398039 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
8040 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:078041 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]0877e3d2009-10-17 22:29:578042
8043 // After calling trans->RestartWithAuth(), this is the request we should
8044 // be issuing -- the final header line contains the credentials.
8045 MockWrite data_writes2[] = {
8046 MockWrite("GET / HTTP/1.1\r\n"
8047 "Host: www.google.com\r\n"
8048 "Connection: keep-alive\r\n"
8049 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
8050 };
8051
8052 // Lastly, the server responds with the actual content.
8053 MockRead data_reads2[] = {
8054 MockRead("HTTP/1.1 200 OK\r\n"),
8055 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
8056 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:068057 MockRead(SYNCHRONOUS, OK),
[email protected]0877e3d2009-10-17 22:29:578058 };
8059
[email protected]31a2bfe2010-02-09 08:03:398060 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
8061 data_writes2, arraysize(data_writes2));
[email protected]bb88e1d32013-05-03 23:11:078062 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]3fe8d2f82013-10-17 08:56:078063 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:578064
[email protected]49639fa2011-12-20 23:22:418065 TestCompletionCallback callback1;
[email protected]0877e3d2009-10-17 22:29:578066
[email protected]262eec82013-03-19 21:01:368067 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508068 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:508069
[email protected]49639fa2011-12-20 23:22:418070 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:578071 EXPECT_EQ(ERR_IO_PENDING, rv);
8072
8073 rv = callback1.WaitForResult();
8074 EXPECT_EQ(OK, rv);
8075
8076 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508077 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048078 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get()));
[email protected]0877e3d2009-10-17 22:29:578079
[email protected]49639fa2011-12-20 23:22:418080 TestCompletionCallback callback2;
[email protected]0877e3d2009-10-17 22:29:578081
[email protected]49639fa2011-12-20 23:22:418082 rv = trans->RestartWithAuth(
8083 AuthCredentials(kFoo, kBar), callback2.callback());
[email protected]0877e3d2009-10-17 22:29:578084 EXPECT_EQ(ERR_IO_PENDING, rv);
8085
8086 rv = callback2.WaitForResult();
8087 EXPECT_EQ(OK, rv);
8088
8089 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508090 ASSERT_TRUE(response != NULL);
[email protected]0877e3d2009-10-17 22:29:578091 EXPECT_TRUE(response->auth_challenge.get() == NULL);
8092 EXPECT_EQ(100, response->headers->GetContentLength());
8093}
8094
8095// Test HTTPS connections going through a proxy that sends extra data.
[email protected]23e482282013-06-14 16:08:028096TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) {
[email protected]bb88e1d32013-05-03 23:11:078097 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]0877e3d2009-10-17 22:29:578098
8099 HttpRequestInfo request;
8100 request.method = "GET";
8101 request.url = GURL("https://www.google.com/");
8102 request.load_flags = 0;
8103
8104 MockRead proxy_reads[] = {
8105 MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"),
[email protected]8ddf8322012-02-23 18:08:068106 MockRead(SYNCHRONOUS, OK)
[email protected]0877e3d2009-10-17 22:29:578107 };
8108
[email protected]31a2bfe2010-02-09 08:03:398109 StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0);
[email protected]8ddf8322012-02-23 18:08:068110 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]0877e3d2009-10-17 22:29:578111
[email protected]bb88e1d32013-05-03 23:11:078112 session_deps_.socket_factory->AddSocketDataProvider(&data);
8113 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]0877e3d2009-10-17 22:29:578114
[email protected]49639fa2011-12-20 23:22:418115 TestCompletionCallback callback;
[email protected]0877e3d2009-10-17 22:29:578116
[email protected]bb88e1d32013-05-03 23:11:078117 session_deps_.socket_factory->ResetNextMockIndexes();
[email protected]0877e3d2009-10-17 22:29:578118
[email protected]3fe8d2f82013-10-17 08:56:078119 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0877e3d2009-10-17 22:29:578120 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418121 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0877e3d2009-10-17 22:29:578122
[email protected]49639fa2011-12-20 23:22:418123 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]0877e3d2009-10-17 22:29:578124 EXPECT_EQ(ERR_IO_PENDING, rv);
8125
8126 rv = callback.WaitForResult();
8127 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
8128}
8129
[email protected]23e482282013-06-14 16:08:028130TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) {
[email protected]9492e4a2010-02-24 00:58:468131 HttpRequestInfo request;
8132 request.method = "GET";
8133 request.url = GURL("http://www.google.com/");
8134 request.load_flags = 0;
8135
[email protected]3fe8d2f82013-10-17 08:56:078136 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:278137 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418138 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:278139
[email protected]e22e1362009-11-23 21:31:128140 MockRead data_reads[] = {
8141 MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:068142 MockRead(SYNCHRONOUS, OK),
[email protected]e22e1362009-11-23 21:31:128143 };
[email protected]9492e4a2010-02-24 00:58:468144
8145 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078146 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]9492e4a2010-02-24 00:58:468147
[email protected]49639fa2011-12-20 23:22:418148 TestCompletionCallback callback;
[email protected]9492e4a2010-02-24 00:58:468149
[email protected]49639fa2011-12-20 23:22:418150 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]9492e4a2010-02-24 00:58:468151 EXPECT_EQ(ERR_IO_PENDING, rv);
8152
8153 EXPECT_EQ(OK, callback.WaitForResult());
8154
8155 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508156 ASSERT_TRUE(response != NULL);
[email protected]9492e4a2010-02-24 00:58:468157
[email protected]90499482013-06-01 00:39:508158 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]9492e4a2010-02-24 00:58:468159 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
8160
8161 std::string response_data;
8162 rv = ReadTransaction(trans.get(), &response_data);
[email protected]5543cbb2012-04-20 16:35:238163 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv);
[email protected]e22e1362009-11-23 21:31:128164}
8165
[email protected]23e482282013-06-14 16:08:028166TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) {
[email protected]6cdfd7f2013-02-08 20:40:158167 base::FilePath temp_file_path;
[email protected]03d9afc02013-12-03 17:55:528168 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path));
[email protected]95d88ffe2010-02-04 21:25:338169 const uint64 kFakeSize = 100000; // file is actually blank
[email protected]d98961652012-09-11 20:27:218170 UploadFileElementReader::ScopedOverridingContentLengthForTests
8171 overriding_content_length(kFakeSize);
[email protected]95d88ffe2010-02-04 21:25:338172
[email protected]b2d26cfd2012-12-11 10:36:068173 ScopedVector<UploadElementReader> element_readers;
8174 element_readers.push_back(
[email protected]cadac622013-06-11 16:46:368175 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
8176 temp_file_path,
8177 0,
8178 kuint64max,
8179 base::Time()));
mmenkecbc2b712014-10-09 20:29:078180 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:278181
8182 HttpRequestInfo request;
8183 request.method = "POST";
8184 request.url = GURL("http://www.google.com/upload");
8185 request.upload_data_stream = &upload_data_stream;
8186 request.load_flags = 0;
8187
[email protected]3fe8d2f82013-10-17 08:56:078188 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]329b68b2012-11-14 17:54:278189 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418190 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]95d88ffe2010-02-04 21:25:338191
8192 MockRead data_reads[] = {
8193 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
8194 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068195 MockRead(SYNCHRONOUS, OK),
[email protected]95d88ffe2010-02-04 21:25:338196 };
[email protected]31a2bfe2010-02-09 08:03:398197 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078198 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]95d88ffe2010-02-04 21:25:338199
[email protected]49639fa2011-12-20 23:22:418200 TestCompletionCallback callback;
[email protected]95d88ffe2010-02-04 21:25:338201
[email protected]49639fa2011-12-20 23:22:418202 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]95d88ffe2010-02-04 21:25:338203 EXPECT_EQ(ERR_IO_PENDING, rv);
8204
8205 rv = callback.WaitForResult();
8206 EXPECT_EQ(OK, rv);
8207
8208 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508209 ASSERT_TRUE(response != NULL);
[email protected]95d88ffe2010-02-04 21:25:338210
[email protected]90499482013-06-01 00:39:508211 EXPECT_TRUE(response->headers.get() != NULL);
[email protected]95d88ffe2010-02-04 21:25:338212 EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine());
8213
8214 std::string response_data;
8215 rv = ReadTransaction(trans.get(), &response_data);
8216 EXPECT_EQ(OK, rv);
8217 EXPECT_EQ("hello world", response_data);
8218
[email protected]dd3aa792013-07-16 19:10:238219 base::DeleteFile(temp_file_path, false);
[email protected]95d88ffe2010-02-04 21:25:338220}
8221
[email protected]23e482282013-06-14 16:08:028222TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) {
[email protected]6cdfd7f2013-02-08 20:40:158223 base::FilePath temp_file;
[email protected]03d9afc02013-12-03 17:55:528224 ASSERT_TRUE(base::CreateTemporaryFile(&temp_file));
[email protected]6624b4622010-03-29 19:58:368225 std::string temp_file_content("Unreadable file.");
[email protected]e5c2a22e2014-03-06 20:42:308226 ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(),
[email protected]6624b4622010-03-29 19:58:368227 temp_file_content.length()));
[email protected]92be8eb2014-08-07 22:57:118228 ASSERT_TRUE(base::MakeFileUnreadable(temp_file));
[email protected]6624b4622010-03-29 19:58:368229
[email protected]b2d26cfd2012-12-11 10:36:068230 ScopedVector<UploadElementReader> element_readers;
8231 element_readers.push_back(
[email protected]cadac622013-06-11 16:46:368232 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
8233 temp_file,
8234 0,
8235 kuint64max,
8236 base::Time()));
mmenkecbc2b712014-10-09 20:29:078237 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]329b68b2012-11-14 17:54:278238
8239 HttpRequestInfo request;
8240 request.method = "POST";
8241 request.url = GURL("http://www.google.com/upload");
8242 request.upload_data_stream = &upload_data_stream;
8243 request.load_flags = 0;
8244
[email protected]999dd8c2013-11-12 06:45:548245 // If we try to upload an unreadable file, the transaction should fail.
[email protected]3fe8d2f82013-10-17 08:56:078246 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]329b68b2012-11-14 17:54:278247 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418248 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]6624b4622010-03-29 19:58:368249
[email protected]999dd8c2013-11-12 06:45:548250 StaticSocketDataProvider data(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078251 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]6624b4622010-03-29 19:58:368252
[email protected]49639fa2011-12-20 23:22:418253 TestCompletionCallback callback;
[email protected]6624b4622010-03-29 19:58:368254
[email protected]49639fa2011-12-20 23:22:418255 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]6624b4622010-03-29 19:58:368256 EXPECT_EQ(ERR_IO_PENDING, rv);
8257
8258 rv = callback.WaitForResult();
[email protected]999dd8c2013-11-12 06:45:548259 EXPECT_EQ(ERR_ACCESS_DENIED, rv);
[email protected]6624b4622010-03-29 19:58:368260
8261 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]999dd8c2013-11-12 06:45:548262 EXPECT_FALSE(response);
[email protected]6624b4622010-03-29 19:58:368263
[email protected]dd3aa792013-07-16 19:10:238264 base::DeleteFile(temp_file, false);
[email protected]6624b4622010-03-29 19:58:368265}
8266
[email protected]02cad5d2013-10-02 08:14:038267TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) {
8268 class FakeUploadElementReader : public UploadElementReader {
8269 public:
8270 FakeUploadElementReader() {}
dchengb03027d2014-10-21 12:00:208271 ~FakeUploadElementReader() override {}
[email protected]02cad5d2013-10-02 08:14:038272
8273 const CompletionCallback& callback() const { return callback_; }
8274
8275 // UploadElementReader overrides:
dchengb03027d2014-10-21 12:00:208276 int Init(const CompletionCallback& callback) override {
[email protected]02cad5d2013-10-02 08:14:038277 callback_ = callback;
8278 return ERR_IO_PENDING;
8279 }
dchengb03027d2014-10-21 12:00:208280 uint64 GetContentLength() const override { return 0; }
8281 uint64 BytesRemaining() const override { return 0; }
8282 int Read(IOBuffer* buf,
8283 int buf_length,
8284 const CompletionCallback& callback) override {
[email protected]02cad5d2013-10-02 08:14:038285 return ERR_FAILED;
8286 }
8287
8288 private:
8289 CompletionCallback callback_;
8290 };
8291
8292 FakeUploadElementReader* fake_reader = new FakeUploadElementReader;
8293 ScopedVector<UploadElementReader> element_readers;
8294 element_readers.push_back(fake_reader);
mmenkecbc2b712014-10-09 20:29:078295 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02cad5d2013-10-02 08:14:038296
8297 HttpRequestInfo request;
8298 request.method = "POST";
8299 request.url = GURL("http://www.google.com/upload");
8300 request.upload_data_stream = &upload_data_stream;
8301 request.load_flags = 0;
8302
[email protected]3fe8d2f82013-10-17 08:56:078303 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]02cad5d2013-10-02 08:14:038304 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418305 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02cad5d2013-10-02 08:14:038306
8307 StaticSocketDataProvider data;
8308 session_deps_.socket_factory->AddSocketDataProvider(&data);
8309
8310 TestCompletionCallback callback;
8311 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8312 EXPECT_EQ(ERR_IO_PENDING, rv);
8313 base::MessageLoop::current()->RunUntilIdle();
8314
8315 // Transaction is pending on request body initialization.
8316 ASSERT_FALSE(fake_reader->callback().is_null());
8317
8318 // Return Init()'s result after the transaction gets destroyed.
8319 trans.reset();
8320 fake_reader->callback().Run(OK); // Should not crash.
8321}
8322
[email protected]aeefc9e82010-02-19 16:18:278323// Tests that changes to Auth realms are treated like auth rejections.
[email protected]23e482282013-06-14 16:08:028324TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) {
[email protected]aeefc9e82010-02-19 16:18:278325
8326 HttpRequestInfo request;
8327 request.method = "GET";
8328 request.url = GURL("http://www.google.com/");
8329 request.load_flags = 0;
8330
8331 // First transaction will request a resource and receive a Basic challenge
8332 // with realm="first_realm".
8333 MockWrite data_writes1[] = {
8334 MockWrite("GET / HTTP/1.1\r\n"
8335 "Host: www.google.com\r\n"
8336 "Connection: keep-alive\r\n"
8337 "\r\n"),
8338 };
8339 MockRead data_reads1[] = {
8340 MockRead("HTTP/1.1 401 Unauthorized\r\n"
8341 "WWW-Authenticate: Basic realm=\"first_realm\"\r\n"
8342 "\r\n"),
8343 };
8344
8345 // After calling trans->RestartWithAuth(), provide an Authentication header
8346 // for first_realm. The server will reject and provide a challenge with
8347 // second_realm.
8348 MockWrite data_writes2[] = {
8349 MockWrite("GET / HTTP/1.1\r\n"
8350 "Host: www.google.com\r\n"
8351 "Connection: keep-alive\r\n"
8352 "Authorization: Basic Zmlyc3Q6YmF6\r\n"
8353 "\r\n"),
8354 };
8355 MockRead data_reads2[] = {
8356 MockRead("HTTP/1.1 401 Unauthorized\r\n"
8357 "WWW-Authenticate: Basic realm=\"second_realm\"\r\n"
8358 "\r\n"),
8359 };
8360
8361 // This again fails, and goes back to first_realm. Make sure that the
8362 // entry is removed from cache.
8363 MockWrite data_writes3[] = {
8364 MockWrite("GET / HTTP/1.1\r\n"
8365 "Host: www.google.com\r\n"
8366 "Connection: keep-alive\r\n"
8367 "Authorization: Basic c2Vjb25kOmZvdQ==\r\n"
8368 "\r\n"),
8369 };
8370 MockRead data_reads3[] = {
8371 MockRead("HTTP/1.1 401 Unauthorized\r\n"
8372 "WWW-Authenticate: Basic realm=\"first_realm\"\r\n"
8373 "\r\n"),
8374 };
8375
8376 // Try one last time (with the correct password) and get the resource.
8377 MockWrite data_writes4[] = {
8378 MockWrite("GET / HTTP/1.1\r\n"
8379 "Host: www.google.com\r\n"
8380 "Connection: keep-alive\r\n"
8381 "Authorization: Basic Zmlyc3Q6YmFy\r\n"
8382 "\r\n"),
8383 };
8384 MockRead data_reads4[] = {
8385 MockRead("HTTP/1.1 200 OK\r\n"
8386 "Content-Type: text/html; charset=iso-8859-1\r\n"
[email protected]0b0bf032010-09-21 18:08:508387 "Content-Length: 5\r\n"
8388 "\r\n"
8389 "hello"),
[email protected]aeefc9e82010-02-19 16:18:278390 };
8391
8392 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
8393 data_writes1, arraysize(data_writes1));
8394 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2),
8395 data_writes2, arraysize(data_writes2));
8396 StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3),
8397 data_writes3, arraysize(data_writes3));
8398 StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4),
8399 data_writes4, arraysize(data_writes4));
[email protected]bb88e1d32013-05-03 23:11:078400 session_deps_.socket_factory->AddSocketDataProvider(&data1);
8401 session_deps_.socket_factory->AddSocketDataProvider(&data2);
8402 session_deps_.socket_factory->AddSocketDataProvider(&data3);
8403 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]aeefc9e82010-02-19 16:18:278404
[email protected]49639fa2011-12-20 23:22:418405 TestCompletionCallback callback1;
[email protected]aeefc9e82010-02-19 16:18:278406
[email protected]3fe8d2f82013-10-17 08:56:078407 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]0b0bf032010-09-21 18:08:508408 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:418409 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:508410
[email protected]aeefc9e82010-02-19 16:18:278411 // Issue the first request with Authorize headers. There should be a
8412 // password prompt for first_realm waiting to be filled in after the
8413 // transaction completes.
[email protected]49639fa2011-12-20 23:22:418414 int rv = trans->Start(&request, callback1.callback(), BoundNetLog());
[email protected]aeefc9e82010-02-19 16:18:278415 EXPECT_EQ(ERR_IO_PENDING, rv);
8416 rv = callback1.WaitForResult();
8417 EXPECT_EQ(OK, rv);
8418 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508419 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048420 const AuthChallengeInfo* challenge = response->auth_challenge.get();
8421 ASSERT_FALSE(challenge == NULL);
8422 EXPECT_FALSE(challenge->is_proxy);
8423 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString());
8424 EXPECT_EQ("first_realm", challenge->realm);
8425 EXPECT_EQ("basic", challenge->scheme);
[email protected]aeefc9e82010-02-19 16:18:278426
8427 // Issue the second request with an incorrect password. There should be a
8428 // password prompt for second_realm waiting to be filled in after the
8429 // transaction completes.
[email protected]49639fa2011-12-20 23:22:418430 TestCompletionCallback callback2;
8431 rv = trans->RestartWithAuth(
8432 AuthCredentials(kFirst, kBaz), callback2.callback());
[email protected]aeefc9e82010-02-19 16:18:278433 EXPECT_EQ(ERR_IO_PENDING, rv);
8434 rv = callback2.WaitForResult();
8435 EXPECT_EQ(OK, rv);
8436 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508437 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048438 challenge = response->auth_challenge.get();
8439 ASSERT_FALSE(challenge == NULL);
8440 EXPECT_FALSE(challenge->is_proxy);
8441 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString());
8442 EXPECT_EQ("second_realm", challenge->realm);
8443 EXPECT_EQ("basic", challenge->scheme);
[email protected]aeefc9e82010-02-19 16:18:278444
8445 // Issue the third request with another incorrect password. There should be
8446 // a password prompt for first_realm waiting to be filled in. If the password
8447 // prompt is not present, it indicates that the HttpAuthCacheEntry for
8448 // first_realm was not correctly removed.
[email protected]49639fa2011-12-20 23:22:418449 TestCompletionCallback callback3;
8450 rv = trans->RestartWithAuth(
8451 AuthCredentials(kSecond, kFou), callback3.callback());
[email protected]aeefc9e82010-02-19 16:18:278452 EXPECT_EQ(ERR_IO_PENDING, rv);
8453 rv = callback3.WaitForResult();
8454 EXPECT_EQ(OK, rv);
8455 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508456 ASSERT_TRUE(response != NULL);
[email protected]79cb5c12011-09-12 13:12:048457 challenge = response->auth_challenge.get();
8458 ASSERT_FALSE(challenge == NULL);
8459 EXPECT_FALSE(challenge->is_proxy);
8460 EXPECT_EQ("www.google.com:80", challenge->challenger.ToString());
8461 EXPECT_EQ("first_realm", challenge->realm);
8462 EXPECT_EQ("basic", challenge->scheme);
[email protected]aeefc9e82010-02-19 16:18:278463
8464 // Issue the fourth request with the correct password and username.
[email protected]49639fa2011-12-20 23:22:418465 TestCompletionCallback callback4;
8466 rv = trans->RestartWithAuth(
8467 AuthCredentials(kFirst, kBar), callback4.callback());
[email protected]aeefc9e82010-02-19 16:18:278468 EXPECT_EQ(ERR_IO_PENDING, rv);
8469 rv = callback4.WaitForResult();
8470 EXPECT_EQ(OK, rv);
8471 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:508472 ASSERT_TRUE(response != NULL);
[email protected]aeefc9e82010-02-19 16:18:278473 EXPECT_TRUE(response->auth_challenge.get() == NULL);
8474}
8475
[email protected]23e482282013-06-14 16:08:028476TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) {
[email protected]d7599122014-05-24 03:37:238477 session_deps_.next_protos = SpdyNextProtos();
8478 session_deps_.use_alternate_protocols = true;
[email protected]a2cb8122010-03-10 17:22:428479
[email protected]8a0fc822013-06-27 20:52:438480 std::string alternate_protocol_http_header =
8481 GetAlternateProtocolHttpHeader();
8482
[email protected]564b4912010-03-09 16:30:428483 MockRead data_reads[] = {
8484 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438485 MockRead(alternate_protocol_http_header.c_str()),
[email protected]564b4912010-03-09 16:30:428486 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068487 MockRead(SYNCHRONOUS, OK),
[email protected]564b4912010-03-09 16:30:428488 };
8489
8490 HttpRequestInfo request;
8491 request.method = "GET";
8492 request.url = GURL("http://www.google.com/");
8493 request.load_flags = 0;
8494
8495 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
8496
[email protected]bb88e1d32013-05-03 23:11:078497 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]564b4912010-03-09 16:30:428498
[email protected]49639fa2011-12-20 23:22:418499 TestCompletionCallback callback;
[email protected]564b4912010-03-09 16:30:428500
[email protected]bb88e1d32013-05-03 23:11:078501 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:368502 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508503 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]564b4912010-03-09 16:30:428504
[email protected]49639fa2011-12-20 23:22:418505 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]564b4912010-03-09 16:30:428506 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]9e743cd2010-03-16 07:03:538507
[email protected]2fbaecf22010-07-22 22:20:358508 HostPortPair http_host_port_pair("www.google.com", 80);
[email protected]9801e3702014-03-07 09:33:558509 HttpServerProperties& http_server_properties =
[email protected]17291a022011-10-10 07:32:538510 *session->http_server_properties();
bnc3c2553312015-02-03 23:12:018511 AlternateProtocolInfo alternate =
8512 http_server_properties.GetAlternateProtocol(http_host_port_pair);
8513 EXPECT_EQ(alternate.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL);
[email protected]564b4912010-03-09 16:30:428514
8515 EXPECT_EQ(OK, callback.WaitForResult());
8516
8517 const HttpResponseInfo* response = trans->GetResponseInfo();
8518 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508519 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]564b4912010-03-09 16:30:428520 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:538521 EXPECT_FALSE(response->was_fetched_via_spdy);
8522 EXPECT_FALSE(response->was_npn_negotiated);
[email protected]564b4912010-03-09 16:30:428523
8524 std::string response_data;
8525 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8526 EXPECT_EQ("hello world", response_data);
8527
bnc3c2553312015-02-03 23:12:018528 alternate = http_server_properties.GetAlternateProtocol(http_host_port_pair);
8529 EXPECT_EQ(443, alternate.port);
8530 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), alternate.protocol);
8531 EXPECT_EQ(1.0, alternate.probability);
[email protected]564b4912010-03-09 16:30:428532}
8533
[email protected]23e482282013-06-14 16:08:028534TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238535 MarkBrokenAlternateProtocolAndFallback) {
[email protected]d7599122014-05-24 03:37:238536 session_deps_.use_alternate_protocols = true;
[email protected]564b4912010-03-09 16:30:428537
8538 HttpRequestInfo request;
8539 request.method = "GET";
8540 request.url = GURL("http://www.google.com/");
8541 request.load_flags = 0;
8542
[email protected]d973e99a2012-02-17 21:02:368543 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]564b4912010-03-09 16:30:428544 StaticSocketDataProvider first_data;
8545 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078546 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]564b4912010-03-09 16:30:428547
8548 MockRead data_reads[] = {
8549 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8550 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068551 MockRead(ASYNC, OK),
[email protected]564b4912010-03-09 16:30:428552 };
8553 StaticSocketDataProvider second_data(
8554 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078555 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]564b4912010-03-09 16:30:428556
[email protected]bb88e1d32013-05-03 23:11:078557 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]564b4912010-03-09 16:30:428558
[email protected]30d4c022013-07-18 22:58:168559 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538560 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118561 // Port must be < 1024, or the header will be ignored (since initial port was
8562 // port 80 (another restricted port).
[email protected]17291a022011-10-10 07:32:538563 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118564 HostPortPair::FromURL(request.url),
8565 666 /* port is ignored by MockConnect anyway */,
bnc1102b552015-01-30 20:11:018566 AlternateProtocolFromNextProto(GetParam()), 1.0);
[email protected]564b4912010-03-09 16:30:428567
[email protected]262eec82013-03-19 21:01:368568 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508569 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418570 TestCompletionCallback callback;
[email protected]564b4912010-03-09 16:30:428571
[email protected]49639fa2011-12-20 23:22:418572 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]564b4912010-03-09 16:30:428573 EXPECT_EQ(ERR_IO_PENDING, rv);
8574 EXPECT_EQ(OK, callback.WaitForResult());
8575
8576 const HttpResponseInfo* response = trans->GetResponseInfo();
8577 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508578 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]564b4912010-03-09 16:30:428579 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8580
8581 std::string response_data;
8582 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8583 EXPECT_EQ("hello world", response_data);
8584
[email protected]287d9412014-07-08 23:01:008585 const AlternateProtocolInfo alternate =
[email protected]17291a022011-10-10 07:32:538586 http_server_properties->GetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118587 HostPortPair::FromURL(request.url));
bnc3c2553312015-02-03 23:12:018588 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol);
bnccbd55d5f2014-11-06 19:50:408589 EXPECT_TRUE(alternate.is_broken);
[email protected]564b4912010-03-09 16:30:428590}
8591
[email protected]23e482282013-06-14 16:08:028592TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238593 AlternateProtocolPortRestrictedBlocked) {
[email protected]3912662a32011-10-04 00:51:118594 // Ensure that we're not allowed to redirect traffic via an alternate
8595 // protocol to an unrestricted (port >= 1024) when the original traffic was
8596 // on a restricted port (port < 1024). Ensure that we can redirect in all
8597 // other cases.
[email protected]d7599122014-05-24 03:37:238598 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118599
8600 HttpRequestInfo restricted_port_request;
8601 restricted_port_request.method = "GET";
8602 restricted_port_request.url = GURL("http://www.google.com:1023/");
8603 restricted_port_request.load_flags = 0;
8604
[email protected]d973e99a2012-02-17 21:02:368605 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118606 StaticSocketDataProvider first_data;
8607 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078608 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118609
8610 MockRead data_reads[] = {
8611 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8612 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068613 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118614 };
8615 StaticSocketDataProvider second_data(
8616 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078617 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118618
[email protected]bb88e1d32013-05-03 23:11:078619 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118620
[email protected]30d4c022013-07-18 22:58:168621 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538622 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118623 const int kUnrestrictedAlternatePort = 1024;
[email protected]17291a022011-10-10 07:32:538624 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118625 HostPortPair::FromURL(restricted_port_request.url),
bnc1102b552015-01-30 20:11:018626 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8627 1.0);
[email protected]3912662a32011-10-04 00:51:118628
[email protected]262eec82013-03-19 21:01:368629 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508630 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418631 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118632
[email protected]49639fa2011-12-20 23:22:418633 int rv = trans->Start(
[email protected]262eec82013-03-19 21:01:368634 &restricted_port_request,
8635 callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118636 EXPECT_EQ(ERR_IO_PENDING, rv);
8637 // Invalid change to unrestricted port should fail.
8638 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
[email protected]c54c6962013-02-01 04:53:198639}
[email protected]3912662a32011-10-04 00:51:118640
[email protected]23e482282013-06-14 16:08:028641TEST_P(HttpNetworkTransactionTest,
[email protected]c54c6962013-02-01 04:53:198642 AlternateProtocolPortRestrictedPermitted) {
8643 // Ensure that we're allowed to redirect traffic via an alternate
8644 // protocol to an unrestricted (port >= 1024) when the original traffic was
8645 // on a restricted port (port < 1024) if we set
8646 // enable_user_alternate_protocol_ports.
8647
[email protected]d7599122014-05-24 03:37:238648 session_deps_.use_alternate_protocols = true;
[email protected]bb88e1d32013-05-03 23:11:078649 session_deps_.enable_user_alternate_protocol_ports = true;
[email protected]c54c6962013-02-01 04:53:198650
8651 HttpRequestInfo restricted_port_request;
8652 restricted_port_request.method = "GET";
8653 restricted_port_request.url = GURL("http://www.google.com:1023/");
8654 restricted_port_request.load_flags = 0;
8655
8656 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
8657 StaticSocketDataProvider first_data;
8658 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078659 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]c54c6962013-02-01 04:53:198660
8661 MockRead data_reads[] = {
8662 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8663 MockRead("hello world"),
8664 MockRead(ASYNC, OK),
8665 };
8666 StaticSocketDataProvider second_data(
8667 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078668 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]c54c6962013-02-01 04:53:198669
[email protected]bb88e1d32013-05-03 23:11:078670 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]c54c6962013-02-01 04:53:198671
[email protected]30d4c022013-07-18 22:58:168672 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]c54c6962013-02-01 04:53:198673 session->http_server_properties();
8674 const int kUnrestrictedAlternatePort = 1024;
8675 http_server_properties->SetAlternateProtocol(
8676 HostPortPair::FromURL(restricted_port_request.url),
bnc1102b552015-01-30 20:11:018677 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8678 1.0);
[email protected]c54c6962013-02-01 04:53:198679
[email protected]262eec82013-03-19 21:01:368680 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508681 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]c54c6962013-02-01 04:53:198682 TestCompletionCallback callback;
8683
8684 EXPECT_EQ(ERR_IO_PENDING, trans->Start(
[email protected]262eec82013-03-19 21:01:368685 &restricted_port_request,
8686 callback.callback(), BoundNetLog()));
[email protected]c54c6962013-02-01 04:53:198687 // Change to unrestricted port should succeed.
8688 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118689}
8690
[email protected]23e482282013-06-14 16:08:028691TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238692 AlternateProtocolPortRestrictedAllowed) {
[email protected]3912662a32011-10-04 00:51:118693 // Ensure that we're not allowed to redirect traffic via an alternate
8694 // protocol to an unrestricted (port >= 1024) when the original traffic was
8695 // on a restricted port (port < 1024). Ensure that we can redirect in all
8696 // other cases.
[email protected]d7599122014-05-24 03:37:238697 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118698
8699 HttpRequestInfo restricted_port_request;
8700 restricted_port_request.method = "GET";
8701 restricted_port_request.url = GURL("http://www.google.com:1023/");
8702 restricted_port_request.load_flags = 0;
8703
[email protected]d973e99a2012-02-17 21:02:368704 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118705 StaticSocketDataProvider first_data;
8706 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078707 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118708
8709 MockRead data_reads[] = {
8710 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8711 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068712 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118713 };
8714 StaticSocketDataProvider second_data(
8715 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078716 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118717
[email protected]bb88e1d32013-05-03 23:11:078718 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118719
[email protected]30d4c022013-07-18 22:58:168720 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538721 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118722 const int kRestrictedAlternatePort = 80;
[email protected]17291a022011-10-10 07:32:538723 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118724 HostPortPair::FromURL(restricted_port_request.url),
bnc1102b552015-01-30 20:11:018725 kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8726 1.0);
[email protected]3912662a32011-10-04 00:51:118727
[email protected]262eec82013-03-19 21:01:368728 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508729 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418730 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118731
[email protected]49639fa2011-12-20 23:22:418732 int rv = trans->Start(
[email protected]262eec82013-03-19 21:01:368733 &restricted_port_request,
8734 callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118735 EXPECT_EQ(ERR_IO_PENDING, rv);
8736 // Valid change to restricted port should pass.
8737 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118738}
8739
[email protected]23e482282013-06-14 16:08:028740TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238741 AlternateProtocolPortUnrestrictedAllowed1) {
[email protected]3912662a32011-10-04 00:51:118742 // Ensure that we're not allowed to redirect traffic via an alternate
8743 // protocol to an unrestricted (port >= 1024) when the original traffic was
8744 // on a restricted port (port < 1024). Ensure that we can redirect in all
8745 // other cases.
[email protected]d7599122014-05-24 03:37:238746 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118747
8748 HttpRequestInfo unrestricted_port_request;
8749 unrestricted_port_request.method = "GET";
8750 unrestricted_port_request.url = GURL("http://www.google.com:1024/");
8751 unrestricted_port_request.load_flags = 0;
8752
[email protected]d973e99a2012-02-17 21:02:368753 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118754 StaticSocketDataProvider first_data;
8755 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078756 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118757
8758 MockRead data_reads[] = {
8759 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8760 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068761 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118762 };
8763 StaticSocketDataProvider second_data(
8764 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078765 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118766
[email protected]bb88e1d32013-05-03 23:11:078767 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118768
[email protected]30d4c022013-07-18 22:58:168769 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538770 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118771 const int kRestrictedAlternatePort = 80;
[email protected]17291a022011-10-10 07:32:538772 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118773 HostPortPair::FromURL(unrestricted_port_request.url),
bnc1102b552015-01-30 20:11:018774 kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8775 1.0);
[email protected]3912662a32011-10-04 00:51:118776
[email protected]262eec82013-03-19 21:01:368777 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508778 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418779 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118780
[email protected]49639fa2011-12-20 23:22:418781 int rv = trans->Start(
8782 &unrestricted_port_request, callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118783 EXPECT_EQ(ERR_IO_PENDING, rv);
8784 // Valid change to restricted port should pass.
8785 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118786}
8787
[email protected]23e482282013-06-14 16:08:028788TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238789 AlternateProtocolPortUnrestrictedAllowed2) {
[email protected]3912662a32011-10-04 00:51:118790 // Ensure that we're not allowed to redirect traffic via an alternate
8791 // protocol to an unrestricted (port >= 1024) when the original traffic was
8792 // on a restricted port (port < 1024). Ensure that we can redirect in all
8793 // other cases.
[email protected]d7599122014-05-24 03:37:238794 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118795
8796 HttpRequestInfo unrestricted_port_request;
8797 unrestricted_port_request.method = "GET";
8798 unrestricted_port_request.url = GURL("http://www.google.com:1024/");
8799 unrestricted_port_request.load_flags = 0;
8800
[email protected]d973e99a2012-02-17 21:02:368801 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118802 StaticSocketDataProvider first_data;
8803 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078804 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118805
8806 MockRead data_reads[] = {
8807 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8808 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068809 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118810 };
8811 StaticSocketDataProvider second_data(
8812 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078813 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118814
[email protected]bb88e1d32013-05-03 23:11:078815 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118816
[email protected]30d4c022013-07-18 22:58:168817 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538818 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118819 const int kUnrestrictedAlternatePort = 1024;
[email protected]17291a022011-10-10 07:32:538820 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118821 HostPortPair::FromURL(unrestricted_port_request.url),
bnc1102b552015-01-30 20:11:018822 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8823 1.0);
[email protected]3912662a32011-10-04 00:51:118824
[email protected]262eec82013-03-19 21:01:368825 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508826 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418827 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118828
[email protected]49639fa2011-12-20 23:22:418829 int rv = trans->Start(
8830 &unrestricted_port_request, callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118831 EXPECT_EQ(ERR_IO_PENDING, rv);
8832 // Valid change to an unrestricted port should pass.
8833 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118834}
8835
[email protected]d7599122014-05-24 03:37:238836TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) {
[email protected]eb6234e2012-01-19 01:50:028837 // Ensure that we're not allowed to redirect traffic via an alternate
8838 // protocol to an unsafe port, and that we resume the second
8839 // HttpStreamFactoryImpl::Job once the alternate protocol request fails.
[email protected]d7599122014-05-24 03:37:238840 session_deps_.use_alternate_protocols = true;
[email protected]eb6234e2012-01-19 01:50:028841
8842 HttpRequestInfo request;
8843 request.method = "GET";
8844 request.url = GURL("http://www.google.com/");
8845 request.load_flags = 0;
8846
8847 // The alternate protocol request will error out before we attempt to connect,
8848 // so only the standard HTTP request will try to connect.
8849 MockRead data_reads[] = {
8850 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8851 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068852 MockRead(ASYNC, OK),
[email protected]eb6234e2012-01-19 01:50:028853 };
8854 StaticSocketDataProvider data(
8855 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078856 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]eb6234e2012-01-19 01:50:028857
[email protected]bb88e1d32013-05-03 23:11:078858 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]eb6234e2012-01-19 01:50:028859
[email protected]30d4c022013-07-18 22:58:168860 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]eb6234e2012-01-19 01:50:028861 session->http_server_properties();
8862 const int kUnsafePort = 7;
8863 http_server_properties->SetAlternateProtocol(
bnc1102b552015-01-30 20:11:018864 HostPortPair::FromURL(request.url), kUnsafePort,
8865 AlternateProtocolFromNextProto(GetParam()), 1.0);
[email protected]eb6234e2012-01-19 01:50:028866
[email protected]262eec82013-03-19 21:01:368867 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508868 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]eb6234e2012-01-19 01:50:028869 TestCompletionCallback callback;
8870
8871 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8872 EXPECT_EQ(ERR_IO_PENDING, rv);
8873 // The HTTP request should succeed.
8874 EXPECT_EQ(OK, callback.WaitForResult());
8875
8876 // Disable alternate protocol before the asserts.
[email protected]d7599122014-05-24 03:37:238877 // HttpStreamFactory::set_use_alternate_protocols(false);
[email protected]eb6234e2012-01-19 01:50:028878
8879 const HttpResponseInfo* response = trans->GetResponseInfo();
8880 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508881 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]eb6234e2012-01-19 01:50:028882 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8883
8884 std::string response_data;
8885 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8886 EXPECT_EQ("hello world", response_data);
8887}
8888
[email protected]23e482282013-06-14 16:08:028889TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) {
[email protected]d7599122014-05-24 03:37:238890 session_deps_.use_alternate_protocols = true;
8891 session_deps_.next_protos = SpdyNextProtos();
[email protected]2ff8b312010-04-26 22:20:548892
8893 HttpRequestInfo request;
8894 request.method = "GET";
8895 request.url = GURL("http://www.google.com/");
8896 request.load_flags = 0;
8897
[email protected]8a0fc822013-06-27 20:52:438898 std::string alternate_protocol_http_header =
8899 GetAlternateProtocolHttpHeader();
8900
[email protected]2ff8b312010-04-26 22:20:548901 MockRead data_reads[] = {
8902 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438903 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2ff8b312010-04-26 22:20:548904 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:178905 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
8906 MockRead(ASYNC, OK)
[email protected]2ff8b312010-04-26 22:20:548907 };
8908
8909 StaticSocketDataProvider first_transaction(
8910 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078911 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2ff8b312010-04-26 22:20:548912
[email protected]8ddf8322012-02-23 18:08:068913 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:028914 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:078915 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2ff8b312010-04-26 22:20:548916
[email protected]cdf8f7e72013-05-23 10:56:468917 scoped_ptr<SpdyFrame> req(
8918 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:138919 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]2ff8b312010-04-26 22:20:548920
[email protected]23e482282013-06-14 16:08:028921 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
8922 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2ff8b312010-04-26 22:20:548923 MockRead spdy_reads[] = {
[email protected]e7f75092010-07-01 22:39:138924 CreateMockRead(*resp),
8925 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:068926 MockRead(ASYNC, 0, 0),
[email protected]2ff8b312010-04-26 22:20:548927 };
8928
[email protected]dd54bd82012-07-19 23:44:578929 DelayedSocketData spdy_data(
8930 1, // wait for one write to finish before reading.
8931 spdy_reads, arraysize(spdy_reads),
8932 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:078933 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2ff8b312010-04-26 22:20:548934
[email protected]d973e99a2012-02-17 21:02:368935 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:558936 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
8937 NULL, 0, NULL, 0);
8938 hanging_non_alternate_protocol_socket.set_connect_data(
8939 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:078940 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:558941 &hanging_non_alternate_protocol_socket);
8942
[email protected]49639fa2011-12-20 23:22:418943 TestCompletionCallback callback;
[email protected]2ff8b312010-04-26 22:20:548944
[email protected]bb88e1d32013-05-03 23:11:078945 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:368946 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508947 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:548948
[email protected]49639fa2011-12-20 23:22:418949 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:548950 EXPECT_EQ(ERR_IO_PENDING, rv);
8951 EXPECT_EQ(OK, callback.WaitForResult());
8952
8953 const HttpResponseInfo* response = trans->GetResponseInfo();
8954 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508955 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:548956 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8957
8958 std::string response_data;
8959 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8960 EXPECT_EQ("hello world", response_data);
8961
[email protected]90499482013-06-01 00:39:508962 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:548963
[email protected]49639fa2011-12-20 23:22:418964 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:548965 EXPECT_EQ(ERR_IO_PENDING, rv);
8966 EXPECT_EQ(OK, callback.WaitForResult());
8967
8968 response = trans->GetResponseInfo();
8969 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508970 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:548971 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:538972 EXPECT_TRUE(response->was_fetched_via_spdy);
8973 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]2ff8b312010-04-26 22:20:548974
8975 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8976 EXPECT_EQ("hello!", response_data);
[email protected]2ff8b312010-04-26 22:20:548977}
8978
[email protected]23e482282013-06-14 16:08:028979TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
[email protected]d7599122014-05-24 03:37:238980 session_deps_.use_alternate_protocols = true;
8981 session_deps_.next_protos = SpdyNextProtos();
[email protected]2d6728692011-03-12 01:39:558982
8983 HttpRequestInfo request;
8984 request.method = "GET";
8985 request.url = GURL("http://www.google.com/");
8986 request.load_flags = 0;
8987
[email protected]8a0fc822013-06-27 20:52:438988 std::string alternate_protocol_http_header =
8989 GetAlternateProtocolHttpHeader();
8990
[email protected]2d6728692011-03-12 01:39:558991 MockRead data_reads[] = {
8992 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438993 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2d6728692011-03-12 01:39:558994 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:178995 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:068996 MockRead(ASYNC, OK),
[email protected]2d6728692011-03-12 01:39:558997 };
8998
8999 StaticSocketDataProvider first_transaction(
9000 data_reads, arraysize(data_reads), NULL, 0);
9001 // Socket 1 is the HTTP transaction with the Alternate-Protocol header.
[email protected]bb88e1d32013-05-03 23:11:079002 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559003
[email protected]d973e99a2012-02-17 21:02:369004 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559005 StaticSocketDataProvider hanging_socket(
9006 NULL, 0, NULL, 0);
9007 hanging_socket.set_connect_data(never_finishing_connect);
9008 // Socket 2 and 3 are the hanging Alternate-Protocol and
9009 // non-Alternate-Protocol jobs from the 2nd transaction.
[email protected]bb88e1d32013-05-03 23:11:079010 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
9011 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
[email protected]2d6728692011-03-12 01:39:559012
[email protected]8ddf8322012-02-23 18:08:069013 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029014 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079015 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2d6728692011-03-12 01:39:559016
[email protected]cdf8f7e72013-05-23 10:56:469017 scoped_ptr<SpdyFrame> req1(
9018 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
9019 scoped_ptr<SpdyFrame> req2(
9020 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
[email protected]2d6728692011-03-12 01:39:559021 MockWrite spdy_writes[] = {
9022 CreateMockWrite(*req1),
9023 CreateMockWrite(*req2),
9024 };
[email protected]23e482282013-06-14 16:08:029025 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9026 scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true));
9027 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
9028 scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]2d6728692011-03-12 01:39:559029 MockRead spdy_reads[] = {
9030 CreateMockRead(*resp1),
9031 CreateMockRead(*data1),
9032 CreateMockRead(*resp2),
9033 CreateMockRead(*data2),
[email protected]8ddf8322012-02-23 18:08:069034 MockRead(ASYNC, 0, 0),
[email protected]2d6728692011-03-12 01:39:559035 };
9036
[email protected]dd54bd82012-07-19 23:44:579037 DelayedSocketData spdy_data(
9038 2, // wait for writes to finish before reading.
9039 spdy_reads, arraysize(spdy_reads),
9040 spdy_writes, arraysize(spdy_writes));
[email protected]2d6728692011-03-12 01:39:559041 // Socket 4 is the successful Alternate-Protocol for transaction 3.
[email protected]bb88e1d32013-05-03 23:11:079042 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2d6728692011-03-12 01:39:559043
9044 // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3.
[email protected]bb88e1d32013-05-03 23:11:079045 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
[email protected]2d6728692011-03-12 01:39:559046
[email protected]bb88e1d32013-05-03 23:11:079047 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]49639fa2011-12-20 23:22:419048 TestCompletionCallback callback1;
[email protected]90499482013-06-01 00:39:509049 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]2d6728692011-03-12 01:39:559050
[email protected]49639fa2011-12-20 23:22:419051 int rv = trans1.Start(&request, callback1.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559052 EXPECT_EQ(ERR_IO_PENDING, rv);
9053 EXPECT_EQ(OK, callback1.WaitForResult());
9054
9055 const HttpResponseInfo* response = trans1.GetResponseInfo();
9056 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509057 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559058 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9059
9060 std::string response_data;
9061 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
9062 EXPECT_EQ("hello world", response_data);
9063
[email protected]49639fa2011-12-20 23:22:419064 TestCompletionCallback callback2;
[email protected]90499482013-06-01 00:39:509065 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]49639fa2011-12-20 23:22:419066 rv = trans2.Start(&request, callback2.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559067 EXPECT_EQ(ERR_IO_PENDING, rv);
9068
[email protected]49639fa2011-12-20 23:22:419069 TestCompletionCallback callback3;
[email protected]90499482013-06-01 00:39:509070 HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get());
[email protected]49639fa2011-12-20 23:22:419071 rv = trans3.Start(&request, callback3.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559072 EXPECT_EQ(ERR_IO_PENDING, rv);
9073
9074 EXPECT_EQ(OK, callback2.WaitForResult());
9075 EXPECT_EQ(OK, callback3.WaitForResult());
9076
9077 response = trans2.GetResponseInfo();
9078 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509079 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559080 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9081 EXPECT_TRUE(response->was_fetched_via_spdy);
9082 EXPECT_TRUE(response->was_npn_negotiated);
9083 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
9084 EXPECT_EQ("hello!", response_data);
9085
9086 response = trans3.GetResponseInfo();
9087 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509088 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559089 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9090 EXPECT_TRUE(response->was_fetched_via_spdy);
9091 EXPECT_TRUE(response->was_npn_negotiated);
9092 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data));
9093 EXPECT_EQ("hello!", response_data);
[email protected]2d6728692011-03-12 01:39:559094}
9095
[email protected]23e482282013-06-14 16:08:029096TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) {
[email protected]d7599122014-05-24 03:37:239097 session_deps_.use_alternate_protocols = true;
9098 session_deps_.next_protos = SpdyNextProtos();
[email protected]2d6728692011-03-12 01:39:559099
9100 HttpRequestInfo request;
9101 request.method = "GET";
9102 request.url = GURL("http://www.google.com/");
9103 request.load_flags = 0;
9104
[email protected]8a0fc822013-06-27 20:52:439105 std::string alternate_protocol_http_header =
9106 GetAlternateProtocolHttpHeader();
9107
[email protected]2d6728692011-03-12 01:39:559108 MockRead data_reads[] = {
9109 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439110 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2d6728692011-03-12 01:39:559111 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:179112 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:069113 MockRead(ASYNC, OK),
[email protected]2d6728692011-03-12 01:39:559114 };
9115
9116 StaticSocketDataProvider first_transaction(
9117 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079118 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559119
[email protected]8ddf8322012-02-23 18:08:069120 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029121 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079122 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2d6728692011-03-12 01:39:559123
[email protected]d973e99a2012-02-17 21:02:369124 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559125 StaticSocketDataProvider hanging_alternate_protocol_socket(
9126 NULL, 0, NULL, 0);
9127 hanging_alternate_protocol_socket.set_connect_data(
9128 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:079129 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:559130 &hanging_alternate_protocol_socket);
9131
9132 // 2nd request is just a copy of the first one, over HTTP again.
[email protected]bb88e1d32013-05-03 23:11:079133 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559134
[email protected]49639fa2011-12-20 23:22:419135 TestCompletionCallback callback;
[email protected]2d6728692011-03-12 01:39:559136
[email protected]bb88e1d32013-05-03 23:11:079137 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:369138 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509139 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d6728692011-03-12 01:39:559140
[email protected]49639fa2011-12-20 23:22:419141 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559142 EXPECT_EQ(ERR_IO_PENDING, rv);
9143 EXPECT_EQ(OK, callback.WaitForResult());
9144
9145 const HttpResponseInfo* response = trans->GetResponseInfo();
9146 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509147 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559148 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9149
9150 std::string response_data;
9151 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9152 EXPECT_EQ("hello world", response_data);
9153
[email protected]90499482013-06-01 00:39:509154 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d6728692011-03-12 01:39:559155
[email protected]49639fa2011-12-20 23:22:419156 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559157 EXPECT_EQ(ERR_IO_PENDING, rv);
9158 EXPECT_EQ(OK, callback.WaitForResult());
9159
9160 response = trans->GetResponseInfo();
9161 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509162 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559163 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9164 EXPECT_FALSE(response->was_fetched_via_spdy);
9165 EXPECT_FALSE(response->was_npn_negotiated);
9166
9167 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9168 EXPECT_EQ("hello world", response_data);
[email protected]2d6728692011-03-12 01:39:559169}
9170
[email protected]631f1322010-04-30 17:59:119171class CapturingProxyResolver : public ProxyResolver {
9172 public:
9173 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {}
dchengb03027d2014-10-21 12:00:209174 ~CapturingProxyResolver() override {}
[email protected]631f1322010-04-30 17:59:119175
dchengb03027d2014-10-21 12:00:209176 int GetProxyForURL(const GURL& url,
9177 ProxyInfo* results,
9178 const CompletionCallback& callback,
9179 RequestHandle* request,
9180 const BoundNetLog& net_log) override {
[email protected]fae7669f2010-08-02 21:49:409181 ProxyServer proxy_server(ProxyServer::SCHEME_HTTP,
9182 HostPortPair("myproxy", 80));
[email protected]d911f1b2010-05-05 22:39:429183 results->UseProxyServer(proxy_server);
[email protected]631f1322010-04-30 17:59:119184 resolved_.push_back(url);
[email protected]d911f1b2010-05-05 22:39:429185 return OK;
[email protected]631f1322010-04-30 17:59:119186 }
9187
dchengb03027d2014-10-21 12:00:209188 void CancelRequest(RequestHandle request) override { NOTREACHED(); }
[email protected]631f1322010-04-30 17:59:119189
dchengb03027d2014-10-21 12:00:209190 LoadState GetLoadState(RequestHandle request) const override {
[email protected]f2c971f2011-11-08 00:33:179191 NOTREACHED();
9192 return LOAD_STATE_IDLE;
9193 }
9194
dchengb03027d2014-10-21 12:00:209195 void CancelSetPacScript() override { NOTREACHED(); }
[email protected]1e605472010-12-16 21:41:409196
dchengb03027d2014-10-21 12:00:209197 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&,
9198 const CompletionCallback& /*callback*/) override {
[email protected]d911f1b2010-05-05 22:39:429199 return OK;
[email protected]631f1322010-04-30 17:59:119200 }
9201
[email protected]24476402010-07-20 20:55:179202 const std::vector<GURL>& resolved() const { return resolved_; }
9203
9204 private:
[email protected]631f1322010-04-30 17:59:119205 std::vector<GURL> resolved_;
9206
9207 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver);
9208};
9209
[email protected]23e482282013-06-14 16:08:029210TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:239211 UseAlternateProtocolForTunneledNpnSpdy) {
[email protected]d7599122014-05-24 03:37:239212 session_deps_.use_alternate_protocols = true;
9213 session_deps_.next_protos = SpdyNextProtos();
[email protected]631f1322010-04-30 17:59:119214
9215 ProxyConfig proxy_config;
[email protected]d911f1b2010-05-05 22:39:429216 proxy_config.set_auto_detect(true);
9217 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
[email protected]2227c692010-05-04 15:36:119218
[email protected]631f1322010-04-30 17:59:119219 CapturingProxyResolver* capturing_proxy_resolver =
9220 new CapturingProxyResolver();
[email protected]bb88e1d32013-05-03 23:11:079221 session_deps_.proxy_service.reset(new ProxyService(
[email protected]66761b952010-06-25 21:30:389222 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
9223 NULL));
[email protected]029c83b62013-01-24 05:28:209224 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:079225 session_deps_.net_log = &net_log;
[email protected]631f1322010-04-30 17:59:119226
9227 HttpRequestInfo request;
9228 request.method = "GET";
9229 request.url = GURL("http://www.google.com/");
9230 request.load_flags = 0;
9231
[email protected]8a0fc822013-06-27 20:52:439232 std::string alternate_protocol_http_header =
9233 GetAlternateProtocolHttpHeader();
9234
[email protected]631f1322010-04-30 17:59:119235 MockRead data_reads[] = {
9236 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439237 MockRead(alternate_protocol_http_header.c_str()),
[email protected]631f1322010-04-30 17:59:119238 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:179239 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:069240 MockRead(ASYNC, OK),
[email protected]631f1322010-04-30 17:59:119241 };
9242
9243 StaticSocketDataProvider first_transaction(
9244 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079245 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]631f1322010-04-30 17:59:119246
[email protected]8ddf8322012-02-23 18:08:069247 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029248 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079249 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]631f1322010-04-30 17:59:119250
[email protected]cdf8f7e72013-05-23 10:56:469251 scoped_ptr<SpdyFrame> req(
9252 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]631f1322010-04-30 17:59:119253 MockWrite spdy_writes[] = {
9254 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
9255 "Host: www.google.com\r\n"
[email protected]d911f1b2010-05-05 22:39:429256 "Proxy-Connection: keep-alive\r\n\r\n"), // 0
[email protected]cdf8f7e72013-05-23 10:56:469257 CreateMockWrite(*req), // 3
[email protected]631f1322010-04-30 17:59:119258 };
9259
[email protected]d911f1b2010-05-05 22:39:429260 const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
9261
[email protected]23e482282013-06-14 16:08:029262 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9263 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]631f1322010-04-30 17:59:119264 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:069265 MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1
[email protected]e7f75092010-07-01 22:39:139266 CreateMockRead(*resp.get(), 4), // 2, 4
9267 CreateMockRead(*data.get(), 4), // 5
[email protected]8ddf8322012-02-23 18:08:069268 MockRead(ASYNC, 0, 0, 4), // 6
[email protected]631f1322010-04-30 17:59:119269 };
9270
[email protected]dd54bd82012-07-19 23:44:579271 OrderedSocketData spdy_data(
9272 spdy_reads, arraysize(spdy_reads),
9273 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:079274 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]631f1322010-04-30 17:59:119275
[email protected]d973e99a2012-02-17 21:02:369276 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559277 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
9278 NULL, 0, NULL, 0);
9279 hanging_non_alternate_protocol_socket.set_connect_data(
9280 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:079281 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:559282 &hanging_non_alternate_protocol_socket);
9283
[email protected]49639fa2011-12-20 23:22:419284 TestCompletionCallback callback;
[email protected]631f1322010-04-30 17:59:119285
[email protected]bb88e1d32013-05-03 23:11:079286 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:369287 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509288 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]631f1322010-04-30 17:59:119289
[email protected]49639fa2011-12-20 23:22:419290 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]631f1322010-04-30 17:59:119291 EXPECT_EQ(ERR_IO_PENDING, rv);
9292 EXPECT_EQ(OK, callback.WaitForResult());
9293
9294 const HttpResponseInfo* response = trans->GetResponseInfo();
9295 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509296 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]631f1322010-04-30 17:59:119297 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539298 EXPECT_FALSE(response->was_fetched_via_spdy);
9299 EXPECT_FALSE(response->was_npn_negotiated);
[email protected]631f1322010-04-30 17:59:119300
9301 std::string response_data;
9302 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9303 EXPECT_EQ("hello world", response_data);
9304
[email protected]90499482013-06-01 00:39:509305 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]631f1322010-04-30 17:59:119306
[email protected]49639fa2011-12-20 23:22:419307 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]631f1322010-04-30 17:59:119308 EXPECT_EQ(ERR_IO_PENDING, rv);
9309 EXPECT_EQ(OK, callback.WaitForResult());
9310
9311 response = trans->GetResponseInfo();
9312 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509313 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]631f1322010-04-30 17:59:119314 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539315 EXPECT_TRUE(response->was_fetched_via_spdy);
9316 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]631f1322010-04-30 17:59:119317
9318 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9319 EXPECT_EQ("hello!", response_data);
[email protected]2d6728692011-03-12 01:39:559320 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size());
[email protected]d911f1b2010-05-05 22:39:429321 EXPECT_EQ("http://www.google.com/",
[email protected]631f1322010-04-30 17:59:119322 capturing_proxy_resolver->resolved()[0].spec());
[email protected]d911f1b2010-05-05 22:39:429323 EXPECT_EQ("https://www.google.com/",
9324 capturing_proxy_resolver->resolved()[1].spec());
[email protected]631f1322010-04-30 17:59:119325
[email protected]029c83b62013-01-24 05:28:209326 LoadTimingInfo load_timing_info;
9327 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
9328 TestLoadTimingNotReusedWithPac(load_timing_info,
9329 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]631f1322010-04-30 17:59:119330}
[email protected]631f1322010-04-30 17:59:119331
[email protected]23e482282013-06-14 16:08:029332TEST_P(HttpNetworkTransactionTest,
[email protected]2ff8b312010-04-26 22:20:549333 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) {
[email protected]d7599122014-05-24 03:37:239334 session_deps_.use_alternate_protocols = true;
9335 session_deps_.next_protos = SpdyNextProtos();
[email protected]2ff8b312010-04-26 22:20:549336
9337 HttpRequestInfo request;
9338 request.method = "GET";
9339 request.url = GURL("http://www.google.com/");
9340 request.load_flags = 0;
9341
[email protected]8a0fc822013-06-27 20:52:439342 std::string alternate_protocol_http_header =
9343 GetAlternateProtocolHttpHeader();
9344
[email protected]2ff8b312010-04-26 22:20:549345 MockRead data_reads[] = {
9346 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439347 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2ff8b312010-04-26 22:20:549348 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:069349 MockRead(ASYNC, OK),
[email protected]2ff8b312010-04-26 22:20:549350 };
9351
9352 StaticSocketDataProvider first_transaction(
9353 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079354 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2ff8b312010-04-26 22:20:549355
[email protected]8ddf8322012-02-23 18:08:069356 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029357 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079358 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2ff8b312010-04-26 22:20:549359
[email protected]cdf8f7e72013-05-23 10:56:469360 scoped_ptr<SpdyFrame> req(
9361 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:139362 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]2ff8b312010-04-26 22:20:549363
[email protected]23e482282013-06-14 16:08:029364 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9365 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2ff8b312010-04-26 22:20:549366 MockRead spdy_reads[] = {
[email protected]e7f75092010-07-01 22:39:139367 CreateMockRead(*resp),
9368 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:069369 MockRead(ASYNC, 0, 0),
[email protected]2ff8b312010-04-26 22:20:549370 };
9371
[email protected]dd54bd82012-07-19 23:44:579372 DelayedSocketData spdy_data(
9373 1, // wait for one write to finish before reading.
9374 spdy_reads, arraysize(spdy_reads),
9375 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:079376 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2ff8b312010-04-26 22:20:549377
[email protected]83039bb2011-12-09 18:43:559378 TestCompletionCallback callback;
[email protected]2ff8b312010-04-26 22:20:549379
[email protected]bb88e1d32013-05-03 23:11:079380 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2ff8b312010-04-26 22:20:549381
[email protected]262eec82013-03-19 21:01:369382 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509383 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:549384
[email protected]49639fa2011-12-20 23:22:419385 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:549386 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:419387 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]2ff8b312010-04-26 22:20:549388
9389 const HttpResponseInfo* response = trans->GetResponseInfo();
9390 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509391 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:549392 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9393
9394 std::string response_data;
9395 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9396 EXPECT_EQ("hello world", response_data);
9397
9398 // Set up an initial SpdySession in the pool to reuse.
[email protected]02b0c342010-09-25 21:09:389399 HostPortPair host_port_pair("www.google.com", 443);
[email protected]e6d017652013-05-17 18:01:409400 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
[email protected]314b03992014-04-01 01:28:539401 PRIVACY_MODE_DISABLED);
[email protected]795cbf82013-07-22 09:37:279402 base::WeakPtr<SpdySession> spdy_session =
[email protected]41d64e82013-07-03 22:44:269403 CreateSecureSpdySession(session, key, BoundNetLog());
[email protected]02b0c342010-09-25 21:09:389404
[email protected]90499482013-06-01 00:39:509405 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:549406
[email protected]49639fa2011-12-20 23:22:419407 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:549408 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:419409 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]2ff8b312010-04-26 22:20:549410
9411 response = trans->GetResponseInfo();
9412 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509413 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:549414 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539415 EXPECT_TRUE(response->was_fetched_via_spdy);
9416 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]2ff8b312010-04-26 22:20:549417
9418 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9419 EXPECT_EQ("hello!", response_data);
[email protected]564b4912010-03-09 16:30:429420}
9421
[email protected]044de0642010-06-17 10:42:159422// GenerateAuthToken is a mighty big test.
9423// It tests all permutation of GenerateAuthToken behavior:
9424// - Synchronous and Asynchronous completion.
9425// - OK or error on completion.
9426// - Direct connection, non-authenticating proxy, and authenticating proxy.
9427// - HTTP or HTTPS backend (to include proxy tunneling).
9428// - Non-authenticating and authenticating backend.
9429//
[email protected]fe3b7dc2012-02-03 19:52:099430// In all, there are 44 reasonable permuations (for example, if there are
[email protected]044de0642010-06-17 10:42:159431// problems generating an auth token for an authenticating proxy, we don't
9432// need to test all permutations of the backend server).
9433//
9434// The test proceeds by going over each of the configuration cases, and
9435// potentially running up to three rounds in each of the tests. The TestConfig
9436// specifies both the configuration for the test as well as the expectations
9437// for the results.
[email protected]23e482282013-06-14 16:08:029438TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) {
[email protected]0b0bf032010-09-21 18:08:509439 static const char kServer[] = "http://www.example.com";
9440 static const char kSecureServer[] = "https://www.example.com";
9441 static const char kProxy[] = "myproxy:70";
[email protected]044de0642010-06-17 10:42:159442 const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS;
9443
9444 enum AuthTiming {
9445 AUTH_NONE,
9446 AUTH_SYNC,
9447 AUTH_ASYNC,
9448 };
9449
9450 const MockWrite kGet(
9451 "GET / HTTP/1.1\r\n"
9452 "Host: www.example.com\r\n"
9453 "Connection: keep-alive\r\n\r\n");
9454 const MockWrite kGetProxy(
9455 "GET http://www.example.com/ HTTP/1.1\r\n"
9456 "Host: www.example.com\r\n"
9457 "Proxy-Connection: keep-alive\r\n\r\n");
9458 const MockWrite kGetAuth(
9459 "GET / HTTP/1.1\r\n"
9460 "Host: www.example.com\r\n"
9461 "Connection: keep-alive\r\n"
9462 "Authorization: auth_token\r\n\r\n");
9463 const MockWrite kGetProxyAuth(
9464 "GET http://www.example.com/ HTTP/1.1\r\n"
9465 "Host: www.example.com\r\n"
9466 "Proxy-Connection: keep-alive\r\n"
9467 "Proxy-Authorization: auth_token\r\n\r\n");
9468 const MockWrite kGetAuthThroughProxy(
9469 "GET http://www.example.com/ HTTP/1.1\r\n"
9470 "Host: www.example.com\r\n"
9471 "Proxy-Connection: keep-alive\r\n"
9472 "Authorization: auth_token\r\n\r\n");
9473 const MockWrite kGetAuthWithProxyAuth(
9474 "GET http://www.example.com/ HTTP/1.1\r\n"
9475 "Host: www.example.com\r\n"
9476 "Proxy-Connection: keep-alive\r\n"
9477 "Proxy-Authorization: auth_token\r\n"
9478 "Authorization: auth_token\r\n\r\n");
9479 const MockWrite kConnect(
9480 "CONNECT www.example.com:443 HTTP/1.1\r\n"
9481 "Host: www.example.com\r\n"
9482 "Proxy-Connection: keep-alive\r\n\r\n");
9483 const MockWrite kConnectProxyAuth(
9484 "CONNECT www.example.com:443 HTTP/1.1\r\n"
9485 "Host: www.example.com\r\n"
9486 "Proxy-Connection: keep-alive\r\n"
9487 "Proxy-Authorization: auth_token\r\n\r\n");
9488
9489 const MockRead kSuccess(
9490 "HTTP/1.1 200 OK\r\n"
9491 "Content-Type: text/html; charset=iso-8859-1\r\n"
9492 "Content-Length: 3\r\n\r\n"
9493 "Yes");
9494 const MockRead kFailure(
9495 "Should not be called.");
9496 const MockRead kServerChallenge(
9497 "HTTP/1.1 401 Unauthorized\r\n"
9498 "WWW-Authenticate: Mock realm=server\r\n"
9499 "Content-Type: text/html; charset=iso-8859-1\r\n"
9500 "Content-Length: 14\r\n\r\n"
9501 "Unauthorized\r\n");
9502 const MockRead kProxyChallenge(
9503 "HTTP/1.1 407 Unauthorized\r\n"
9504 "Proxy-Authenticate: Mock realm=proxy\r\n"
9505 "Proxy-Connection: close\r\n"
9506 "Content-Type: text/html; charset=iso-8859-1\r\n"
9507 "Content-Length: 14\r\n\r\n"
9508 "Unauthorized\r\n");
9509 const MockRead kProxyConnected(
9510 "HTTP/1.1 200 Connection Established\r\n\r\n");
9511
9512 // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with
9513 // no constructors, but the C++ compiler on Windows warns about
9514 // unspecified data in compound literals. So, moved to using constructors,
9515 // and TestRound's created with the default constructor should not be used.
9516 struct TestRound {
9517 TestRound()
9518 : expected_rv(ERR_UNEXPECTED),
9519 extra_write(NULL),
9520 extra_read(NULL) {
9521 }
9522 TestRound(const MockWrite& write_arg, const MockRead& read_arg,
9523 int expected_rv_arg)
9524 : write(write_arg),
9525 read(read_arg),
9526 expected_rv(expected_rv_arg),
9527 extra_write(NULL),
9528 extra_read(NULL) {
9529 }
9530 TestRound(const MockWrite& write_arg, const MockRead& read_arg,
9531 int expected_rv_arg, const MockWrite* extra_write_arg,
[email protected]f871ee152012-07-27 19:02:019532 const MockRead* extra_read_arg)
[email protected]044de0642010-06-17 10:42:159533 : write(write_arg),
9534 read(read_arg),
9535 expected_rv(expected_rv_arg),
9536 extra_write(extra_write_arg),
9537 extra_read(extra_read_arg) {
9538 }
9539 MockWrite write;
9540 MockRead read;
9541 int expected_rv;
9542 const MockWrite* extra_write;
9543 const MockRead* extra_read;
9544 };
9545
9546 static const int kNoSSL = 500;
9547
9548 struct TestConfig {
thestig9d3bb0c2015-01-24 00:49:519549 const char* const proxy_url;
[email protected]044de0642010-06-17 10:42:159550 AuthTiming proxy_auth_timing;
9551 int proxy_auth_rv;
thestig9d3bb0c2015-01-24 00:49:519552 const char* const server_url;
[email protected]044de0642010-06-17 10:42:159553 AuthTiming server_auth_timing;
9554 int server_auth_rv;
9555 int num_auth_rounds;
9556 int first_ssl_round;
9557 TestRound rounds[3];
9558 } test_configs[] = {
9559 // Non-authenticating HTTP server with a direct connection.
9560 { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL,
9561 { TestRound(kGet, kSuccess, OK)}},
9562 // Authenticating HTTP server with a direct connection.
9563 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL,
9564 { TestRound(kGet, kServerChallenge, OK),
9565 TestRound(kGetAuth, kSuccess, OK)}},
9566 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL,
9567 { TestRound(kGet, kServerChallenge, OK),
9568 TestRound(kGetAuth, kFailure, kAuthErr)}},
9569 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL,
9570 { TestRound(kGet, kServerChallenge, OK),
9571 TestRound(kGetAuth, kSuccess, OK)}},
9572 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL,
9573 { TestRound(kGet, kServerChallenge, OK),
9574 TestRound(kGetAuth, kFailure, kAuthErr)}},
9575 // Non-authenticating HTTP server through a non-authenticating proxy.
9576 { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL,
9577 { TestRound(kGetProxy, kSuccess, OK)}},
9578 // Authenticating HTTP server through a non-authenticating proxy.
9579 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL,
9580 { TestRound(kGetProxy, kServerChallenge, OK),
9581 TestRound(kGetAuthThroughProxy, kSuccess, OK)}},
9582 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL,
9583 { TestRound(kGetProxy, kServerChallenge, OK),
9584 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}},
9585 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL,
9586 { TestRound(kGetProxy, kServerChallenge, OK),
9587 TestRound(kGetAuthThroughProxy, kSuccess, OK)}},
9588 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL,
9589 { TestRound(kGetProxy, kServerChallenge, OK),
9590 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}},
9591 // Non-authenticating HTTP server through an authenticating proxy.
9592 { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL,
9593 { TestRound(kGetProxy, kProxyChallenge, OK),
9594 TestRound(kGetProxyAuth, kSuccess, OK)}},
9595 { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL,
9596 { TestRound(kGetProxy, kProxyChallenge, OK),
9597 TestRound(kGetProxyAuth, kFailure, kAuthErr)}},
9598 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL,
9599 { TestRound(kGetProxy, kProxyChallenge, OK),
9600 TestRound(kGetProxyAuth, kSuccess, OK)}},
9601 { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL,
9602 { TestRound(kGetProxy, kProxyChallenge, OK),
9603 TestRound(kGetProxyAuth, kFailure, kAuthErr)}},
9604 // Authenticating HTTP server through an authenticating proxy.
9605 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL,
9606 { TestRound(kGetProxy, kProxyChallenge, OK),
9607 TestRound(kGetProxyAuth, kServerChallenge, OK),
9608 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9609 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL,
9610 { TestRound(kGetProxy, kProxyChallenge, OK),
9611 TestRound(kGetProxyAuth, kServerChallenge, OK),
9612 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9613 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL,
9614 { TestRound(kGetProxy, kProxyChallenge, OK),
9615 TestRound(kGetProxyAuth, kServerChallenge, OK),
9616 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9617 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL,
9618 { TestRound(kGetProxy, kProxyChallenge, OK),
9619 TestRound(kGetProxyAuth, kServerChallenge, OK),
9620 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9621 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL,
9622 { TestRound(kGetProxy, kProxyChallenge, OK),
9623 TestRound(kGetProxyAuth, kServerChallenge, OK),
9624 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9625 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL,
9626 { TestRound(kGetProxy, kProxyChallenge, OK),
9627 TestRound(kGetProxyAuth, kServerChallenge, OK),
9628 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9629 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL,
9630 { TestRound(kGetProxy, kProxyChallenge, OK),
9631 TestRound(kGetProxyAuth, kServerChallenge, OK),
9632 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9633 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL,
9634 { TestRound(kGetProxy, kProxyChallenge, OK),
9635 TestRound(kGetProxyAuth, kServerChallenge, OK),
9636 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9637 // Non-authenticating HTTPS server with a direct connection.
9638 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0,
9639 { TestRound(kGet, kSuccess, OK)}},
9640 // Authenticating HTTPS server with a direct connection.
9641 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0,
9642 { TestRound(kGet, kServerChallenge, OK),
9643 TestRound(kGetAuth, kSuccess, OK)}},
9644 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0,
9645 { TestRound(kGet, kServerChallenge, OK),
9646 TestRound(kGetAuth, kFailure, kAuthErr)}},
9647 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0,
9648 { TestRound(kGet, kServerChallenge, OK),
9649 TestRound(kGetAuth, kSuccess, OK)}},
9650 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0,
9651 { TestRound(kGet, kServerChallenge, OK),
9652 TestRound(kGetAuth, kFailure, kAuthErr)}},
9653 // Non-authenticating HTTPS server with a non-authenticating proxy.
9654 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0,
9655 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}},
9656 // Authenticating HTTPS server through a non-authenticating proxy.
9657 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0,
9658 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9659 TestRound(kGetAuth, kSuccess, OK)}},
9660 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0,
9661 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9662 TestRound(kGetAuth, kFailure, kAuthErr)}},
9663 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0,
9664 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9665 TestRound(kGetAuth, kSuccess, OK)}},
9666 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0,
9667 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9668 TestRound(kGetAuth, kFailure, kAuthErr)}},
9669 // Non-Authenticating HTTPS server through an authenticating proxy.
9670 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1,
9671 { TestRound(kConnect, kProxyChallenge, OK),
9672 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}},
9673 { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL,
9674 { TestRound(kConnect, kProxyChallenge, OK),
9675 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}},
9676 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1,
9677 { TestRound(kConnect, kProxyChallenge, OK),
9678 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}},
9679 { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL,
9680 { TestRound(kConnect, kProxyChallenge, OK),
9681 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}},
9682 // Authenticating HTTPS server through an authenticating proxy.
9683 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1,
9684 { TestRound(kConnect, kProxyChallenge, OK),
9685 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9686 &kGet, &kServerChallenge),
9687 TestRound(kGetAuth, kSuccess, OK)}},
9688 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1,
9689 { TestRound(kConnect, kProxyChallenge, OK),
9690 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9691 &kGet, &kServerChallenge),
9692 TestRound(kGetAuth, kFailure, kAuthErr)}},
9693 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1,
9694 { TestRound(kConnect, kProxyChallenge, OK),
9695 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9696 &kGet, &kServerChallenge),
9697 TestRound(kGetAuth, kSuccess, OK)}},
9698 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1,
9699 { TestRound(kConnect, kProxyChallenge, OK),
9700 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9701 &kGet, &kServerChallenge),
9702 TestRound(kGetAuth, kFailure, kAuthErr)}},
9703 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1,
9704 { TestRound(kConnect, kProxyChallenge, OK),
9705 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9706 &kGet, &kServerChallenge),
9707 TestRound(kGetAuth, kSuccess, OK)}},
9708 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1,
9709 { TestRound(kConnect, kProxyChallenge, OK),
9710 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9711 &kGet, &kServerChallenge),
9712 TestRound(kGetAuth, kFailure, kAuthErr)}},
9713 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1,
9714 { TestRound(kConnect, kProxyChallenge, OK),
9715 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9716 &kGet, &kServerChallenge),
9717 TestRound(kGetAuth, kSuccess, OK)}},
9718 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1,
9719 { TestRound(kConnect, kProxyChallenge, OK),
9720 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9721 &kGet, &kServerChallenge),
9722 TestRound(kGetAuth, kFailure, kAuthErr)}},
9723 };
9724
viettrungluue4a8b882014-10-16 06:17:389725 for (size_t i = 0; i < arraysize(test_configs); ++i) {
[email protected]2d01c262011-08-11 23:07:089726 HttpAuthHandlerMock::Factory* auth_factory(
9727 new HttpAuthHandlerMock::Factory());
[email protected]bb88e1d32013-05-03 23:11:079728 session_deps_.http_auth_handler_factory.reset(auth_factory);
[email protected]044de0642010-06-17 10:42:159729 const TestConfig& test_config = test_configs[i];
[email protected]65d34382010-07-01 18:12:269730
9731 // Set up authentication handlers as necessary.
[email protected]044de0642010-06-17 10:42:159732 if (test_config.proxy_auth_timing != AUTH_NONE) {
[email protected]2d01c262011-08-11 23:07:089733 for (int n = 0; n < 2; n++) {
9734 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
9735 std::string auth_challenge = "Mock realm=proxy";
9736 GURL origin(test_config.proxy_url);
[email protected]df41d0d82014-03-13 00:43:249737 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9738 auth_challenge.end());
[email protected]2d01c262011-08-11 23:07:089739 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY,
9740 origin, BoundNetLog());
9741 auth_handler->SetGenerateExpectation(
9742 test_config.proxy_auth_timing == AUTH_ASYNC,
9743 test_config.proxy_auth_rv);
9744 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
9745 }
[email protected]044de0642010-06-17 10:42:159746 }
9747 if (test_config.server_auth_timing != AUTH_NONE) {
[email protected]3fd9dae2010-06-21 11:39:009748 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
[email protected]044de0642010-06-17 10:42:159749 std::string auth_challenge = "Mock realm=server";
9750 GURL origin(test_config.server_url);
[email protected]df41d0d82014-03-13 00:43:249751 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9752 auth_challenge.end());
[email protected]044de0642010-06-17 10:42:159753 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
9754 origin, BoundNetLog());
9755 auth_handler->SetGenerateExpectation(
9756 test_config.server_auth_timing == AUTH_ASYNC,
9757 test_config.server_auth_rv);
[email protected]2d01c262011-08-11 23:07:089758 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
[email protected]044de0642010-06-17 10:42:159759 }
9760 if (test_config.proxy_url) {
[email protected]bb88e1d32013-05-03 23:11:079761 session_deps_.proxy_service.reset(
[email protected]6104ea5d2011-04-27 21:37:129762 ProxyService::CreateFixed(test_config.proxy_url));
[email protected]044de0642010-06-17 10:42:159763 } else {
[email protected]bb88e1d32013-05-03 23:11:079764 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
[email protected]044de0642010-06-17 10:42:159765 }
9766
9767 HttpRequestInfo request;
9768 request.method = "GET";
9769 request.url = GURL(test_config.server_url);
9770 request.load_flags = 0;
9771
[email protected]bb88e1d32013-05-03 23:11:079772 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
dcheng48459ac22014-08-26 00:46:419773 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
[email protected]044de0642010-06-17 10:42:159774
9775 for (int round = 0; round < test_config.num_auth_rounds; ++round) {
9776 const TestRound& read_write_round = test_config.rounds[round];
9777
9778 // Set up expected reads and writes.
9779 MockRead reads[2];
9780 reads[0] = read_write_round.read;
9781 size_t length_reads = 1;
9782 if (read_write_round.extra_read) {
9783 reads[1] = *read_write_round.extra_read;
9784 length_reads = 2;
9785 }
9786
9787 MockWrite writes[2];
9788 writes[0] = read_write_round.write;
9789 size_t length_writes = 1;
9790 if (read_write_round.extra_write) {
9791 writes[1] = *read_write_round.extra_write;
9792 length_writes = 2;
9793 }
9794 StaticSocketDataProvider data_provider(
9795 reads, length_reads, writes, length_writes);
[email protected]bb88e1d32013-05-03 23:11:079796 session_deps_.socket_factory->AddSocketDataProvider(&data_provider);
[email protected]044de0642010-06-17 10:42:159797
9798 // Add an SSL sequence if necessary.
[email protected]8ddf8322012-02-23 18:08:069799 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK);
[email protected]044de0642010-06-17 10:42:159800 if (round >= test_config.first_ssl_round)
[email protected]bb88e1d32013-05-03 23:11:079801 session_deps_.socket_factory->AddSSLSocketDataProvider(
[email protected]044de0642010-06-17 10:42:159802 &ssl_socket_data_provider);
9803
9804 // Start or restart the transaction.
[email protected]49639fa2011-12-20 23:22:419805 TestCompletionCallback callback;
[email protected]044de0642010-06-17 10:42:159806 int rv;
9807 if (round == 0) {
[email protected]49639fa2011-12-20 23:22:419808 rv = trans.Start(&request, callback.callback(), BoundNetLog());
[email protected]044de0642010-06-17 10:42:159809 } else {
[email protected]49639fa2011-12-20 23:22:419810 rv = trans.RestartWithAuth(
9811 AuthCredentials(kFoo, kBar), callback.callback());
[email protected]044de0642010-06-17 10:42:159812 }
9813 if (rv == ERR_IO_PENDING)
9814 rv = callback.WaitForResult();
9815
9816 // Compare results with expected data.
9817 EXPECT_EQ(read_write_round.expected_rv, rv);
[email protected]0b0bf032010-09-21 18:08:509818 const HttpResponseInfo* response = trans.GetResponseInfo();
[email protected]044de0642010-06-17 10:42:159819 if (read_write_round.expected_rv == OK) {
[email protected]fe2255a2011-09-20 19:37:509820 ASSERT_TRUE(response != NULL);
[email protected]044de0642010-06-17 10:42:159821 } else {
9822 EXPECT_TRUE(response == NULL);
9823 EXPECT_EQ(round + 1, test_config.num_auth_rounds);
9824 continue;
9825 }
9826 if (round + 1 < test_config.num_auth_rounds) {
9827 EXPECT_FALSE(response->auth_challenge.get() == NULL);
9828 } else {
9829 EXPECT_TRUE(response->auth_challenge.get() == NULL);
9830 }
9831 }
[email protected]e5ae96a2010-04-14 20:12:459832 }
9833}
9834
[email protected]23e482282013-06-14 16:08:029835TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) {
[email protected]c871bce92010-07-15 21:51:149836 // Do multi-round authentication and make sure it works correctly.
[email protected]c871bce92010-07-15 21:51:149837 HttpAuthHandlerMock::Factory* auth_factory(
9838 new HttpAuthHandlerMock::Factory());
[email protected]bb88e1d32013-05-03 23:11:079839 session_deps_.http_auth_handler_factory.reset(auth_factory);
9840 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
9841 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1");
9842 session_deps_.host_resolver->set_synchronous_mode(true);
[email protected]c871bce92010-07-15 21:51:149843
9844 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
9845 auth_handler->set_connection_based(true);
9846 std::string auth_challenge = "Mock realm=server";
9847 GURL origin("http://www.example.com");
[email protected]df41d0d82014-03-13 00:43:249848 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9849 auth_challenge.end());
[email protected]c871bce92010-07-15 21:51:149850 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
9851 origin, BoundNetLog());
[email protected]2d01c262011-08-11 23:07:089852 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
[email protected]c871bce92010-07-15 21:51:149853
[email protected]c871bce92010-07-15 21:51:149854 int rv = OK;
9855 const HttpResponseInfo* response = NULL;
9856 HttpRequestInfo request;
9857 request.method = "GET";
9858 request.url = origin;
9859 request.load_flags = 0;
[email protected]cb9bf6ca2011-01-28 13:15:279860
[email protected]bb88e1d32013-05-03 23:11:079861 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7ef4cbbb2011-02-06 11:19:109862
9863 // Use a TCP Socket Pool with only one connection per group. This is used
9864 // to validate that the TCP socket is not released to the pool between
9865 // each round of multi-round authentication.
9866 HttpNetworkSessionPeer session_peer(session);
[email protected]ab739042011-04-07 15:22:289867 ClientSocketPoolHistograms transport_pool_histograms("SmallTCP");
9868 TransportClientSocketPool* transport_pool = new TransportClientSocketPool(
[email protected]7ef4cbbb2011-02-06 11:19:109869 50, // Max sockets for pool
9870 1, // Max sockets per group
[email protected]ab739042011-04-07 15:22:289871 &transport_pool_histograms,
[email protected]bb88e1d32013-05-03 23:11:079872 session_deps_.host_resolver.get(),
9873 session_deps_.socket_factory.get(),
9874 session_deps_.net_log);
[email protected]831e4a32013-11-14 02:14:449875 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
9876 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:029877 mock_pool_manager->SetTransportSocketPool(transport_pool);
dchenge3d1ddc2014-10-15 19:30:519878 session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]7ef4cbbb2011-02-06 11:19:109879
[email protected]262eec82013-03-19 21:01:369880 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509881 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:419882 TestCompletionCallback callback;
[email protected]c871bce92010-07-15 21:51:149883
9884 const MockWrite kGet(
9885 "GET / HTTP/1.1\r\n"
9886 "Host: www.example.com\r\n"
9887 "Connection: keep-alive\r\n\r\n");
9888 const MockWrite kGetAuth(
9889 "GET / HTTP/1.1\r\n"
9890 "Host: www.example.com\r\n"
9891 "Connection: keep-alive\r\n"
9892 "Authorization: auth_token\r\n\r\n");
9893
9894 const MockRead kServerChallenge(
9895 "HTTP/1.1 401 Unauthorized\r\n"
9896 "WWW-Authenticate: Mock realm=server\r\n"
9897 "Content-Type: text/html; charset=iso-8859-1\r\n"
9898 "Content-Length: 14\r\n\r\n"
9899 "Unauthorized\r\n");
9900 const MockRead kSuccess(
9901 "HTTP/1.1 200 OK\r\n"
9902 "Content-Type: text/html; charset=iso-8859-1\r\n"
9903 "Content-Length: 3\r\n\r\n"
9904 "Yes");
9905
9906 MockWrite writes[] = {
9907 // First round
9908 kGet,
9909 // Second round
9910 kGetAuth,
9911 // Third round
9912 kGetAuth,
[email protected]eca50e122010-09-11 14:03:309913 // Fourth round
[email protected]7ef4cbbb2011-02-06 11:19:109914 kGetAuth,
9915 // Competing request
9916 kGet,
[email protected]c871bce92010-07-15 21:51:149917 };
9918 MockRead reads[] = {
9919 // First round
9920 kServerChallenge,
9921 // Second round
9922 kServerChallenge,
9923 // Third round
[email protected]eca50e122010-09-11 14:03:309924 kServerChallenge,
9925 // Fourth round
[email protected]c871bce92010-07-15 21:51:149926 kSuccess,
[email protected]7ef4cbbb2011-02-06 11:19:109927 // Competing response
9928 kSuccess,
[email protected]c871bce92010-07-15 21:51:149929 };
9930 StaticSocketDataProvider data_provider(reads, arraysize(reads),
9931 writes, arraysize(writes));
[email protected]bb88e1d32013-05-03 23:11:079932 session_deps_.socket_factory->AddSocketDataProvider(&data_provider);
[email protected]c871bce92010-07-15 21:51:149933
thestig9d3bb0c2015-01-24 00:49:519934 const char kSocketGroup[] = "www.example.com:80";
[email protected]7ef4cbbb2011-02-06 11:19:109935
9936 // First round of authentication.
[email protected]c871bce92010-07-15 21:51:149937 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419938 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]c871bce92010-07-15 21:51:149939 if (rv == ERR_IO_PENDING)
9940 rv = callback.WaitForResult();
9941 EXPECT_EQ(OK, rv);
9942 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509943 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149944 EXPECT_FALSE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289945 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:149946
[email protected]7ef4cbbb2011-02-06 11:19:109947 // In between rounds, another request comes in for the same domain.
9948 // It should not be able to grab the TCP socket that trans has already
9949 // claimed.
9950 scoped_ptr<HttpTransaction> trans_compete(
[email protected]90499482013-06-01 00:39:509951 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:419952 TestCompletionCallback callback_compete;
9953 rv = trans_compete->Start(
9954 &request, callback_compete.callback(), BoundNetLog());
[email protected]7ef4cbbb2011-02-06 11:19:109955 EXPECT_EQ(ERR_IO_PENDING, rv);
9956 // callback_compete.WaitForResult at this point would stall forever,
9957 // since the HttpNetworkTransaction does not release the request back to
9958 // the pool until after authentication completes.
9959
9960 // Second round of authentication.
[email protected]c871bce92010-07-15 21:51:149961 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419962 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback());
[email protected]c871bce92010-07-15 21:51:149963 if (rv == ERR_IO_PENDING)
9964 rv = callback.WaitForResult();
9965 EXPECT_EQ(OK, rv);
9966 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509967 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149968 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289969 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:149970
[email protected]7ef4cbbb2011-02-06 11:19:109971 // Third round of authentication.
[email protected]c871bce92010-07-15 21:51:149972 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419973 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
[email protected]c871bce92010-07-15 21:51:149974 if (rv == ERR_IO_PENDING)
9975 rv = callback.WaitForResult();
9976 EXPECT_EQ(OK, rv);
9977 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509978 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149979 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289980 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]eca50e122010-09-11 14:03:309981
[email protected]7ef4cbbb2011-02-06 11:19:109982 // Fourth round of authentication, which completes successfully.
[email protected]eca50e122010-09-11 14:03:309983 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419984 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
[email protected]eca50e122010-09-11 14:03:309985 if (rv == ERR_IO_PENDING)
9986 rv = callback.WaitForResult();
9987 EXPECT_EQ(OK, rv);
9988 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509989 ASSERT_TRUE(response != NULL);
[email protected]eca50e122010-09-11 14:03:309990 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289991 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]7ef4cbbb2011-02-06 11:19:109992
9993 // Read the body since the fourth round was successful. This will also
9994 // release the socket back to the pool.
9995 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50));
[email protected]90499482013-06-01 00:39:509996 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:109997 if (rv == ERR_IO_PENDING)
9998 rv = callback.WaitForResult();
9999 EXPECT_EQ(3, rv);
[email protected]90499482013-06-01 00:39:5010000 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:1010001 EXPECT_EQ(0, rv);
10002 // There are still 0 idle sockets, since the trans_compete transaction
10003 // will be handed it immediately after trans releases it to the group.
[email protected]ab739042011-04-07 15:22:2810004 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]7ef4cbbb2011-02-06 11:19:1010005
10006 // The competing request can now finish. Wait for the headers and then
10007 // read the body.
10008 rv = callback_compete.WaitForResult();
10009 EXPECT_EQ(OK, rv);
[email protected]90499482013-06-01 00:39:5010010 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:1010011 if (rv == ERR_IO_PENDING)
10012 rv = callback.WaitForResult();
10013 EXPECT_EQ(3, rv);
[email protected]90499482013-06-01 00:39:5010014 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:1010015 EXPECT_EQ(0, rv);
10016
10017 // Finally, the socket is released to the group.
[email protected]ab739042011-04-07 15:22:2810018 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:1410019}
10020
[email protected]65041fa2010-05-21 06:56:5310021// This tests the case that a request is issued via http instead of spdy after
10022// npn is negotiated.
[email protected]23e482282013-06-14 16:08:0210023TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) {
[email protected]d7599122014-05-24 03:37:2310024 session_deps_.use_alternate_protocols = true;
10025 NextProtoVector next_protos;
[email protected]0ce3af82013-07-22 16:17:1610026 next_protos.push_back(kProtoHTTP11);
[email protected]d7599122014-05-24 03:37:2310027 session_deps_.next_protos = next_protos;
10028
[email protected]65041fa2010-05-21 06:56:5310029 HttpRequestInfo request;
10030 request.method = "GET";
10031 request.url = GURL("https://www.google.com/");
10032 request.load_flags = 0;
10033
10034 MockWrite data_writes[] = {
10035 MockWrite("GET / HTTP/1.1\r\n"
10036 "Host: www.google.com\r\n"
10037 "Connection: keep-alive\r\n\r\n"),
10038 };
10039
[email protected]8a0fc822013-06-27 20:52:4310040 std::string alternate_protocol_http_header =
10041 GetAlternateProtocolHttpHeader();
10042
[email protected]65041fa2010-05-21 06:56:5310043 MockRead data_reads[] = {
10044 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:4310045 MockRead(alternate_protocol_http_header.c_str()),
[email protected]65041fa2010-05-21 06:56:5310046 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:0610047 MockRead(SYNCHRONOUS, OK),
[email protected]65041fa2010-05-21 06:56:5310048 };
10049
[email protected]8ddf8322012-02-23 18:08:0610050 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]65041fa2010-05-21 06:56:5310051 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
10052 ssl.next_proto = "http/1.1";
[email protected]8e3c78cb2012-03-31 03:58:4610053 ssl.protocol_negotiated = kProtoHTTP11;
[email protected]65041fa2010-05-21 06:56:5310054
[email protected]bb88e1d32013-05-03 23:11:0710055 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]65041fa2010-05-21 06:56:5310056
10057 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
10058 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:0710059 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]65041fa2010-05-21 06:56:5310060
[email protected]49639fa2011-12-20 23:22:4110061 TestCompletionCallback callback;
[email protected]65041fa2010-05-21 06:56:5310062
[email protected]bb88e1d32013-05-03 23:11:0710063 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610064 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010065 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]65041fa2010-05-21 06:56:5310066
[email protected]49639fa2011-12-20 23:22:4110067 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]65041fa2010-05-21 06:56:5310068
10069 EXPECT_EQ(ERR_IO_PENDING, rv);
10070 EXPECT_EQ(OK, callback.WaitForResult());
10071
10072 const HttpResponseInfo* response = trans->GetResponseInfo();
10073 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5010074 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]65041fa2010-05-21 06:56:5310075 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
10076
10077 std::string response_data;
10078 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
10079 EXPECT_EQ("hello world", response_data);
10080
10081 EXPECT_FALSE(response->was_fetched_via_spdy);
10082 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]65041fa2010-05-21 06:56:5310083}
[email protected]26ef6582010-06-24 02:30:4710084
[email protected]23e482282013-06-14 16:08:0210085TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) {
[email protected]26ef6582010-06-24 02:30:4710086 // Simulate the SSL handshake completing with an NPN negotiation
10087 // followed by an immediate server closing of the socket.
10088 // Fix crash: http://crbug.com/46369
[email protected]d7599122014-05-24 03:37:2310089 session_deps_.use_alternate_protocols = true;
10090 session_deps_.next_protos = SpdyNextProtos();
[email protected]26ef6582010-06-24 02:30:4710091
10092 HttpRequestInfo request;
10093 request.method = "GET";
10094 request.url = GURL("https://www.google.com/");
10095 request.load_flags = 0;
10096
[email protected]8ddf8322012-02-23 18:08:0610097 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210098 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0710099 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]26ef6582010-06-24 02:30:4710100
[email protected]cdf8f7e72013-05-23 10:56:4610101 scoped_ptr<SpdyFrame> req(
10102 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:1310103 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]26ef6582010-06-24 02:30:4710104
10105 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610106 MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately.
[email protected]26ef6582010-06-24 02:30:4710107 };
10108
[email protected]dd54bd82012-07-19 23:44:5710109 DelayedSocketData spdy_data(
10110 0, // don't wait in this case, immediate hangup.
10111 spdy_reads, arraysize(spdy_reads),
10112 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0710113 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]26ef6582010-06-24 02:30:4710114
[email protected]49639fa2011-12-20 23:22:4110115 TestCompletionCallback callback;
[email protected]26ef6582010-06-24 02:30:4710116
[email protected]bb88e1d32013-05-03 23:11:0710117 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610118 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010119 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]26ef6582010-06-24 02:30:4710120
[email protected]49639fa2011-12-20 23:22:4110121 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]26ef6582010-06-24 02:30:4710122 EXPECT_EQ(ERR_IO_PENDING, rv);
10123 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
[email protected]26ef6582010-06-24 02:30:4710124}
[email protected]65d34382010-07-01 18:12:2610125
[email protected]795cbf82013-07-22 09:37:2710126// A subclass of HttpAuthHandlerMock that records the request URL when
10127// it gets it. This is needed since the auth handler may get destroyed
10128// before we get a chance to query it.
10129class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock {
10130 public:
10131 explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {}
10132
dchengb03027d2014-10-21 12:00:2010133 ~UrlRecordingHttpAuthHandlerMock() override {}
[email protected]795cbf82013-07-22 09:37:2710134
10135 protected:
dchengb03027d2014-10-21 12:00:2010136 int GenerateAuthTokenImpl(const AuthCredentials* credentials,
10137 const HttpRequestInfo* request,
10138 const CompletionCallback& callback,
10139 std::string* auth_token) override {
[email protected]795cbf82013-07-22 09:37:2710140 *url_ = request->url;
10141 return HttpAuthHandlerMock::GenerateAuthTokenImpl(
10142 credentials, request, callback, auth_token);
10143 }
10144
10145 private:
10146 GURL* url_;
10147};
10148
[email protected]23e482282013-06-14 16:08:0210149TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) {
[email protected]f45c1ee2010-08-03 00:54:3010150 // This test ensures that the URL passed into the proxy is upgraded
10151 // to https when doing an Alternate Protocol upgrade.
[email protected]d7599122014-05-24 03:37:2310152 session_deps_.use_alternate_protocols = true;
10153 session_deps_.next_protos = SpdyNextProtos();
[email protected]f45c1ee2010-08-03 00:54:3010154
[email protected]bb88e1d32013-05-03 23:11:0710155 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010156 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
10157 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:0710158 session_deps_.net_log = &net_log;
[email protected]795cbf82013-07-22 09:37:2710159 GURL request_url;
10160 {
10161 HttpAuthHandlerMock::Factory* auth_factory =
10162 new HttpAuthHandlerMock::Factory();
10163 UrlRecordingHttpAuthHandlerMock* auth_handler =
10164 new UrlRecordingHttpAuthHandlerMock(&request_url);
10165 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
10166 auth_factory->set_do_init_from_challenge(true);
10167 session_deps_.http_auth_handler_factory.reset(auth_factory);
10168 }
[email protected]f45c1ee2010-08-03 00:54:3010169
10170 HttpRequestInfo request;
10171 request.method = "GET";
10172 request.url = GURL("http://www.google.com");
10173 request.load_flags = 0;
10174
10175 // First round goes unauthenticated through the proxy.
10176 MockWrite data_writes_1[] = {
10177 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
10178 "Host: www.google.com\r\n"
10179 "Proxy-Connection: keep-alive\r\n"
10180 "\r\n"),
10181 };
10182 MockRead data_reads_1[] = {
[email protected]8ddf8322012-02-23 18:08:0610183 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
bnc33b8cef42014-11-19 17:30:3810184 MockRead("HTTP/1.1 200 OK\r\n"),
10185 MockRead("Alternate-Protocol: 443:"),
10186 MockRead(GetAlternateProtocolFromParam()),
10187 MockRead("\r\n"),
10188 MockRead("Proxy-Connection: close\r\n"),
10189 MockRead("\r\n"),
[email protected]f45c1ee2010-08-03 00:54:3010190 };
10191 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1),
10192 data_writes_1, arraysize(data_writes_1));
10193
10194 // Second round tries to tunnel to www.google.com due to the
10195 // Alternate-Protocol announcement in the first round. It fails due
10196 // to a proxy authentication challenge.
[email protected]394816e92010-08-03 07:38:5910197 // After the failure, a tunnel is established to www.google.com using
10198 // Proxy-Authorization headers. There is then a SPDY request round.
10199 //
[email protected]fe3b7dc2012-02-03 19:52:0910200 // NOTE: Despite the "Proxy-Connection: Close", these are done on the
10201 // same MockTCPClientSocket since the underlying HttpNetworkClientSocket
10202 // does a Disconnect and Connect on the same socket, rather than trying
10203 // to obtain a new one.
10204 //
[email protected]394816e92010-08-03 07:38:5910205 // NOTE: Originally, the proxy response to the second CONNECT request
10206 // simply returned another 407 so the unit test could skip the SSL connection
10207 // establishment and SPDY framing issues. Alas, the
10208 // retry-http-when-alternate-protocol fails logic kicks in, which was more
[email protected]f45c1ee2010-08-03 00:54:3010209 // complicated to set up expectations for than the SPDY session.
[email protected]394816e92010-08-03 07:38:5910210
[email protected]cdf8f7e72013-05-23 10:56:4610211 scoped_ptr<SpdyFrame> req(
10212 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]23e482282013-06-14 16:08:0210213 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
10214 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]f45c1ee2010-08-03 00:54:3010215
[email protected]394816e92010-08-03 07:38:5910216 MockWrite data_writes_2[] = {
10217 // First connection attempt without Proxy-Authorization.
10218 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10219 "Host: www.google.com\r\n"
10220 "Proxy-Connection: keep-alive\r\n"
10221 "\r\n"),
10222
10223 // Second connection attempt with Proxy-Authorization.
[email protected]f45c1ee2010-08-03 00:54:3010224 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10225 "Host: www.google.com\r\n"
10226 "Proxy-Connection: keep-alive\r\n"
10227 "Proxy-Authorization: auth_token\r\n"
10228 "\r\n"),
[email protected]f45c1ee2010-08-03 00:54:3010229
[email protected]394816e92010-08-03 07:38:5910230 // SPDY request
10231 CreateMockWrite(*req),
[email protected]f45c1ee2010-08-03 00:54:3010232 };
[email protected]394816e92010-08-03 07:38:5910233 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n"
10234 "Proxy-Authenticate: Mock\r\n"
10235 "Proxy-Connection: close\r\n"
10236 "\r\n");
10237 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
10238 MockRead data_reads_2[] = {
10239 // First connection attempt fails
[email protected]8ddf8322012-02-23 18:08:0610240 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1),
10241 MockRead(ASYNC, kRejectConnectResponse,
[email protected]394816e92010-08-03 07:38:5910242 arraysize(kRejectConnectResponse) - 1, 1),
10243
10244 // Second connection attempt passes
[email protected]8ddf8322012-02-23 18:08:0610245 MockRead(ASYNC, kAcceptConnectResponse,
[email protected]fe3b7dc2012-02-03 19:52:0910246 arraysize(kAcceptConnectResponse) -1, 4),
[email protected]394816e92010-08-03 07:38:5910247
10248 // SPDY response
[email protected]fe3b7dc2012-02-03 19:52:0910249 CreateMockRead(*resp.get(), 6),
10250 CreateMockRead(*data.get(), 6),
[email protected]8ddf8322012-02-23 18:08:0610251 MockRead(ASYNC, 0, 0, 6),
[email protected]394816e92010-08-03 07:38:5910252 };
[email protected]dd54bd82012-07-19 23:44:5710253 OrderedSocketData data_2(
10254 data_reads_2, arraysize(data_reads_2),
10255 data_writes_2, arraysize(data_writes_2));
[email protected]f45c1ee2010-08-03 00:54:3010256
[email protected]8ddf8322012-02-23 18:08:0610257 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210258 ssl.SetNextProto(GetParam());
[email protected]f45c1ee2010-08-03 00:54:3010259
[email protected]d973e99a2012-02-17 21:02:3610260 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:5510261 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
10262 NULL, 0, NULL, 0);
10263 hanging_non_alternate_protocol_socket.set_connect_data(
10264 never_finishing_connect);
10265
[email protected]bb88e1d32013-05-03 23:11:0710266 session_deps_.socket_factory->AddSocketDataProvider(&data_1);
10267 session_deps_.socket_factory->AddSocketDataProvider(&data_2);
10268 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
10269 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:5510270 &hanging_non_alternate_protocol_socket);
[email protected]bb88e1d32013-05-03 23:11:0710271 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]f45c1ee2010-08-03 00:54:3010272
10273 // First round should work and provide the Alternate-Protocol state.
[email protected]49639fa2011-12-20 23:22:4110274 TestCompletionCallback callback_1;
[email protected]262eec82013-03-19 21:01:3610275 scoped_ptr<HttpTransaction> trans_1(
[email protected]90499482013-06-01 00:39:5010276 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:4110277 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog());
[email protected]f45c1ee2010-08-03 00:54:3010278 EXPECT_EQ(ERR_IO_PENDING, rv);
10279 EXPECT_EQ(OK, callback_1.WaitForResult());
10280
10281 // Second round should attempt a tunnel connect and get an auth challenge.
[email protected]49639fa2011-12-20 23:22:4110282 TestCompletionCallback callback_2;
[email protected]262eec82013-03-19 21:01:3610283 scoped_ptr<HttpTransaction> trans_2(
[email protected]90499482013-06-01 00:39:5010284 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:4110285 rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog());
[email protected]f45c1ee2010-08-03 00:54:3010286 EXPECT_EQ(ERR_IO_PENDING, rv);
10287 EXPECT_EQ(OK, callback_2.WaitForResult());
10288 const HttpResponseInfo* response = trans_2->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010289 ASSERT_TRUE(response != NULL);
[email protected]f45c1ee2010-08-03 00:54:3010290 ASSERT_FALSE(response->auth_challenge.get() == NULL);
10291
10292 // Restart with auth. Tunnel should work and response received.
[email protected]49639fa2011-12-20 23:22:4110293 TestCompletionCallback callback_3;
10294 rv = trans_2->RestartWithAuth(
10295 AuthCredentials(kFoo, kBar), callback_3.callback());
[email protected]f45c1ee2010-08-03 00:54:3010296 EXPECT_EQ(ERR_IO_PENDING, rv);
10297 EXPECT_EQ(OK, callback_3.WaitForResult());
10298
10299 // After all that work, these two lines (or actually, just the scheme) are
10300 // what this test is all about. Make sure it happens correctly.
[email protected]f45c1ee2010-08-03 00:54:3010301 EXPECT_EQ("https", request_url.scheme());
10302 EXPECT_EQ("www.google.com", request_url.host());
10303
[email protected]029c83b62013-01-24 05:28:2010304 LoadTimingInfo load_timing_info;
10305 EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info));
10306 TestLoadTimingNotReusedWithPac(load_timing_info,
10307 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]8e6441ca2010-08-19 05:56:3810308}
10309
10310// Test that if we cancel the transaction as the connection is completing, that
10311// everything tears down correctly.
[email protected]23e482282013-06-14 16:08:0210312TEST_P(HttpNetworkTransactionTest, SimpleCancel) {
[email protected]8e6441ca2010-08-19 05:56:3810313 // Setup everything about the connection to complete synchronously, so that
10314 // after calling HttpNetworkTransaction::Start, the only thing we're waiting
10315 // for is the callback from the HttpStreamRequest.
10316 // Then cancel the transaction.
10317 // Verify that we don't crash.
[email protected]d973e99a2012-02-17 21:02:3610318 MockConnect mock_connect(SYNCHRONOUS, OK);
[email protected]8e6441ca2010-08-19 05:56:3810319 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610320 MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"),
10321 MockRead(SYNCHRONOUS, "hello world"),
10322 MockRead(SYNCHRONOUS, OK),
[email protected]8e6441ca2010-08-19 05:56:3810323 };
10324
[email protected]8e6441ca2010-08-19 05:56:3810325 HttpRequestInfo request;
10326 request.method = "GET";
10327 request.url = GURL("http://www.google.com/");
10328 request.load_flags = 0;
10329
[email protected]bb88e1d32013-05-03 23:11:0710330 session_deps_.host_resolver->set_synchronous_mode(true);
[email protected]3fe8d2f82013-10-17 08:56:0710331 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:2710332 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4110333 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:2710334
[email protected]8e6441ca2010-08-19 05:56:3810335 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10336 data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:0710337 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]8e6441ca2010-08-19 05:56:3810338
[email protected]49639fa2011-12-20 23:22:4110339 TestCompletionCallback callback;
[email protected]8e6441ca2010-08-19 05:56:3810340
[email protected]333bdf62012-06-08 22:57:2910341 CapturingBoundNetLog log;
[email protected]49639fa2011-12-20 23:22:4110342 int rv = trans->Start(&request, callback.callback(), log.bound());
[email protected]8e6441ca2010-08-19 05:56:3810343 EXPECT_EQ(ERR_IO_PENDING, rv);
10344 trans.reset(); // Cancel the transaction here.
10345
[email protected]2da659e2013-05-23 20:51:3410346 base::MessageLoop::current()->RunUntilIdle();
[email protected]f45c1ee2010-08-03 00:54:3010347}
10348
[email protected]ecab6e052014-05-16 14:58:1210349// Test that if a transaction is cancelled after receiving the headers, the
10350// stream is drained properly and added back to the socket pool. The main
10351// purpose of this test is to make sure that an HttpStreamParser can be read
10352// from after the HttpNetworkTransaction and the objects it owns have been
10353// deleted.
10354// See http://crbug.com/368418
10355TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) {
10356 MockRead data_reads[] = {
10357 MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"),
10358 MockRead(ASYNC, "Content-Length: 2\r\n"),
10359 MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"),
10360 MockRead(ASYNC, "1"),
10361 // 2 async reads are necessary to trigger a ReadResponseBody call after the
10362 // HttpNetworkTransaction has been deleted.
10363 MockRead(ASYNC, "2"),
10364 MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this.
10365 };
10366 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10367 session_deps_.socket_factory->AddSocketDataProvider(&data);
10368
10369 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
10370
10371 {
10372 HttpRequestInfo request;
10373 request.method = "GET";
10374 request.url = GURL("http://www.google.com/");
10375 request.load_flags = 0;
10376
dcheng48459ac22014-08-26 00:46:4110377 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
[email protected]ecab6e052014-05-16 14:58:1210378 TestCompletionCallback callback;
10379
10380 int rv = trans.Start(&request, callback.callback(), BoundNetLog());
10381 EXPECT_EQ(ERR_IO_PENDING, rv);
10382 callback.WaitForResult();
10383
10384 const HttpResponseInfo* response = trans.GetResponseInfo();
10385 ASSERT_TRUE(response != NULL);
10386 EXPECT_TRUE(response->headers.get() != NULL);
10387 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
10388
10389 // The transaction and HttpRequestInfo are deleted.
10390 }
10391
10392 // Let the HttpResponseBodyDrainer drain the socket.
10393 base::MessageLoop::current()->RunUntilIdle();
10394
10395 // Socket should now be idle, waiting to be reused.
dcheng48459ac22014-08-26 00:46:4110396 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]ecab6e052014-05-16 14:58:1210397}
10398
[email protected]76a505b2010-08-25 06:23:0010399// Test a basic GET request through a proxy.
[email protected]23e482282013-06-14 16:08:0210400TEST_P(HttpNetworkTransactionTest, ProxyGet) {
[email protected]bb88e1d32013-05-03 23:11:0710401 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010402 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910403 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710404 session_deps_.net_log = log.bound().net_log();
10405 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010406
[email protected]76a505b2010-08-25 06:23:0010407 HttpRequestInfo request;
10408 request.method = "GET";
10409 request.url = GURL("http://www.google.com/");
10410
10411 MockWrite data_writes1[] = {
10412 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
10413 "Host: www.google.com\r\n"
10414 "Proxy-Connection: keep-alive\r\n\r\n"),
10415 };
10416
10417 MockRead data_reads1[] = {
10418 MockRead("HTTP/1.1 200 OK\r\n"),
10419 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
10420 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610421 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:0010422 };
10423
10424 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10425 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710426 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]76a505b2010-08-25 06:23:0010427
[email protected]49639fa2011-12-20 23:22:4110428 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010429
[email protected]262eec82013-03-19 21:01:3610430 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010431 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]597a1ab2014-06-26 08:12:2710432 BeforeProxyHeadersSentHandler proxy_headers_handler;
10433 trans->SetBeforeProxyHeadersSentCallback(
10434 base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent,
10435 base::Unretained(&proxy_headers_handler)));
[email protected]0b0bf032010-09-21 18:08:5010436
[email protected]49639fa2011-12-20 23:22:4110437 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010438 EXPECT_EQ(ERR_IO_PENDING, rv);
10439
10440 rv = callback1.WaitForResult();
10441 EXPECT_EQ(OK, rv);
10442
10443 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010444 ASSERT_TRUE(response != NULL);
[email protected]76a505b2010-08-25 06:23:0010445
10446 EXPECT_TRUE(response->headers->IsKeepAlive());
10447 EXPECT_EQ(200, response->headers->response_code());
10448 EXPECT_EQ(100, response->headers->GetContentLength());
10449 EXPECT_TRUE(response->was_fetched_via_proxy);
[email protected]d8fc4722014-06-13 13:17:1510450 EXPECT_TRUE(
10451 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70")));
[email protected]597a1ab2014-06-26 08:12:2710452 EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent());
10453 EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri());
[email protected]76a505b2010-08-25 06:23:0010454 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]029c83b62013-01-24 05:28:2010455
10456 LoadTimingInfo load_timing_info;
10457 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
10458 TestLoadTimingNotReusedWithPac(load_timing_info,
10459 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
[email protected]76a505b2010-08-25 06:23:0010460}
10461
10462// Test a basic HTTPS GET request through a proxy.
[email protected]23e482282013-06-14 16:08:0210463TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) {
[email protected]bb88e1d32013-05-03 23:11:0710464 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010465 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910466 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710467 session_deps_.net_log = log.bound().net_log();
10468 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010469
[email protected]76a505b2010-08-25 06:23:0010470 HttpRequestInfo request;
10471 request.method = "GET";
10472 request.url = GURL("https://www.google.com/");
10473
10474 // Since we have proxy, should try to establish tunnel.
10475 MockWrite data_writes1[] = {
10476 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10477 "Host: www.google.com\r\n"
10478 "Proxy-Connection: keep-alive\r\n\r\n"),
10479
10480 MockWrite("GET / HTTP/1.1\r\n"
10481 "Host: www.google.com\r\n"
10482 "Connection: keep-alive\r\n\r\n"),
10483 };
10484
10485 MockRead data_reads1[] = {
10486 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
10487
10488 MockRead("HTTP/1.1 200 OK\r\n"),
10489 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
10490 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610491 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:0010492 };
10493
10494 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10495 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710496 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:0610497 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:0710498 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:0010499
[email protected]49639fa2011-12-20 23:22:4110500 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010501
[email protected]262eec82013-03-19 21:01:3610502 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010503 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:5010504
[email protected]49639fa2011-12-20 23:22:4110505 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010506 EXPECT_EQ(ERR_IO_PENDING, rv);
10507
10508 rv = callback1.WaitForResult();
10509 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:5710510 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:4010511 log.GetEntries(&entries);
[email protected]76a505b2010-08-25 06:23:0010512 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010513 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]76a505b2010-08-25 06:23:0010514 NetLog::PHASE_NONE);
10515 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010516 entries, pos,
[email protected]76a505b2010-08-25 06:23:0010517 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
10518 NetLog::PHASE_NONE);
10519
10520 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010521 ASSERT_TRUE(response != NULL);
[email protected]76a505b2010-08-25 06:23:0010522
10523 EXPECT_TRUE(response->headers->IsKeepAlive());
10524 EXPECT_EQ(200, response->headers->response_code());
10525 EXPECT_EQ(100, response->headers->GetContentLength());
10526 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
10527 EXPECT_TRUE(response->was_fetched_via_proxy);
[email protected]d8fc4722014-06-13 13:17:1510528 EXPECT_TRUE(
10529 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70")));
[email protected]029c83b62013-01-24 05:28:2010530
10531 LoadTimingInfo load_timing_info;
10532 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
10533 TestLoadTimingNotReusedWithPac(load_timing_info,
10534 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]76a505b2010-08-25 06:23:0010535}
10536
10537// Test a basic HTTPS GET request through a proxy, but the server hangs up
10538// while establishing the tunnel.
[email protected]23e482282013-06-14 16:08:0210539TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) {
[email protected]bb88e1d32013-05-03 23:11:0710540 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910541 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710542 session_deps_.net_log = log.bound().net_log();
10543 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010544
[email protected]76a505b2010-08-25 06:23:0010545 HttpRequestInfo request;
10546 request.method = "GET";
10547 request.url = GURL("https://www.google.com/");
10548
10549 // Since we have proxy, should try to establish tunnel.
10550 MockWrite data_writes1[] = {
10551 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10552 "Host: www.google.com\r\n"
10553 "Proxy-Connection: keep-alive\r\n\r\n"),
10554
10555 MockWrite("GET / HTTP/1.1\r\n"
10556 "Host: www.google.com\r\n"
10557 "Connection: keep-alive\r\n\r\n"),
10558 };
10559
10560 MockRead data_reads1[] = {
[email protected]8ddf8322012-02-23 18:08:0610561 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]76a505b2010-08-25 06:23:0010562 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610563 MockRead(ASYNC, 0, 0), // EOF
[email protected]76a505b2010-08-25 06:23:0010564 };
10565
10566 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10567 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710568 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:0610569 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:0710570 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:0010571
[email protected]49639fa2011-12-20 23:22:4110572 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010573
[email protected]262eec82013-03-19 21:01:3610574 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010575 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:5010576
[email protected]49639fa2011-12-20 23:22:4110577 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010578 EXPECT_EQ(ERR_IO_PENDING, rv);
10579
10580 rv = callback1.WaitForResult();
10581 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
[email protected]f3da152d2012-06-02 01:00:5710582 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:4010583 log.GetEntries(&entries);
[email protected]76a505b2010-08-25 06:23:0010584 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010585 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]76a505b2010-08-25 06:23:0010586 NetLog::PHASE_NONE);
10587 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010588 entries, pos,
[email protected]76a505b2010-08-25 06:23:0010589 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
10590 NetLog::PHASE_NONE);
10591}
10592
[email protected]749eefa82010-09-13 22:14:0310593// Test for crbug.com/55424.
[email protected]23e482282013-06-14 16:08:0210594TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) {
[email protected]cdf8f7e72013-05-23 10:56:4610595 scoped_ptr<SpdyFrame> req(
10596 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
[email protected]749eefa82010-09-13 22:14:0310597 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
10598
[email protected]23e482282013-06-14 16:08:0210599 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
10600 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]749eefa82010-09-13 22:14:0310601 MockRead spdy_reads[] = {
10602 CreateMockRead(*resp),
10603 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:0610604 MockRead(ASYNC, 0, 0),
[email protected]749eefa82010-09-13 22:14:0310605 };
10606
[email protected]dd54bd82012-07-19 23:44:5710607 DelayedSocketData spdy_data(
10608 1, // wait for one write to finish before reading.
10609 spdy_reads, arraysize(spdy_reads),
10610 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0710611 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]749eefa82010-09-13 22:14:0310612
[email protected]8ddf8322012-02-23 18:08:0610613 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210614 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0710615 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]749eefa82010-09-13 22:14:0310616
[email protected]bb88e1d32013-05-03 23:11:0710617 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]749eefa82010-09-13 22:14:0310618
10619 // Set up an initial SpdySession in the pool to reuse.
[email protected]02b0c342010-09-25 21:09:3810620 HostPortPair host_port_pair("www.google.com", 443);
[email protected]e6d017652013-05-17 18:01:4010621 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
[email protected]314b03992014-04-01 01:28:5310622 PRIVACY_MODE_DISABLED);
[email protected]795cbf82013-07-22 09:37:2710623 base::WeakPtr<SpdySession> spdy_session =
[email protected]41d64e82013-07-03 22:44:2610624 CreateInsecureSpdySession(session, key, BoundNetLog());
[email protected]749eefa82010-09-13 22:14:0310625
10626 HttpRequestInfo request;
10627 request.method = "GET";
10628 request.url = GURL("https://www.google.com/");
10629 request.load_flags = 0;
10630
10631 // This is the important line that marks this as a preconnect.
10632 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED;
10633
[email protected]262eec82013-03-19 21:01:3610634 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010635 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]749eefa82010-09-13 22:14:0310636
[email protected]41d64e82013-07-03 22:44:2610637 TestCompletionCallback callback;
[email protected]49639fa2011-12-20 23:22:4110638 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]749eefa82010-09-13 22:14:0310639 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4110640 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]749eefa82010-09-13 22:14:0310641}
10642
[email protected]73b8dd222010-11-11 19:55:2410643// Given a net error, cause that error to be returned from the first Write()
10644// call and verify that the HttpTransaction fails with that error.
[email protected]23e482282013-06-14 16:08:0210645void HttpNetworkTransactionTest::CheckErrorIsPassedBack(
[email protected]bb88e1d32013-05-03 23:11:0710646 int error, IoMode mode) {
[email protected]cb9bf6ca2011-01-28 13:15:2710647 net::HttpRequestInfo request_info;
10648 request_info.url = GURL("https://www.example.com/");
10649 request_info.method = "GET";
10650 request_info.load_flags = net::LOAD_NORMAL;
10651
[email protected]8ddf8322012-02-23 18:08:0610652 SSLSocketDataProvider ssl_data(mode, OK);
[email protected]73b8dd222010-11-11 19:55:2410653 net::MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:0610654 net::MockWrite(mode, error),
[email protected]73b8dd222010-11-11 19:55:2410655 };
10656 net::StaticSocketDataProvider data(NULL, 0,
10657 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:0710658 session_deps_.socket_factory->AddSocketDataProvider(&data);
10659 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data);
[email protected]73b8dd222010-11-11 19:55:2410660
[email protected]bb88e1d32013-05-03 23:11:0710661 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610662 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010663 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]73b8dd222010-11-11 19:55:2410664
[email protected]49639fa2011-12-20 23:22:4110665 TestCompletionCallback callback;
10666 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]73b8dd222010-11-11 19:55:2410667 if (rv == net::ERR_IO_PENDING)
10668 rv = callback.WaitForResult();
10669 ASSERT_EQ(error, rv);
10670}
10671
[email protected]23e482282013-06-14 16:08:0210672TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) {
[email protected]73b8dd222010-11-11 19:55:2410673 // Just check a grab bag of cert errors.
10674 static const int kErrors[] = {
10675 ERR_CERT_COMMON_NAME_INVALID,
10676 ERR_CERT_AUTHORITY_INVALID,
10677 ERR_CERT_DATE_INVALID,
10678 };
10679 for (size_t i = 0; i < arraysize(kErrors); i++) {
[email protected]8ddf8322012-02-23 18:08:0610680 CheckErrorIsPassedBack(kErrors[i], ASYNC);
10681 CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS);
[email protected]73b8dd222010-11-11 19:55:2410682 }
10683}
10684
[email protected]bd0b6772011-01-11 19:59:3010685// Ensure that a client certificate is removed from the SSL client auth
10686// cache when:
10687// 1) No proxy is involved.
10688// 2) TLS False Start is disabled.
10689// 3) The initial TLS handshake requests a client certificate.
10690// 4) The client supplies an invalid/unacceptable certificate.
[email protected]23e482282013-06-14 16:08:0210691TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:2310692 ClientAuthCertCache_Direct_NoFalseStart) {
[email protected]cb9bf6ca2011-01-28 13:15:2710693 net::HttpRequestInfo request_info;
10694 request_info.url = GURL("https://www.example.com/");
10695 request_info.method = "GET";
10696 request_info.load_flags = net::LOAD_NORMAL;
10697
[email protected]bd0b6772011-01-11 19:59:3010698 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110699 cert_request->host_and_port = HostPortPair("www.example.com", 443);
[email protected]bd0b6772011-01-11 19:59:3010700
10701 // [ssl_]data1 contains the data for the first SSL handshake. When a
10702 // CertificateRequest is received for the first time, the handshake will
10703 // be aborted to allow the caller to provide a certificate.
[email protected]8ddf8322012-02-23 18:08:0610704 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]bd0b6772011-01-11 19:59:3010705 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710706 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]bd0b6772011-01-11 19:59:3010707 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710708 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]bd0b6772011-01-11 19:59:3010709
10710 // [ssl_]data2 contains the data for the second SSL handshake. When TLS
10711 // False Start is not being used, the result of the SSL handshake will be
10712 // returned as part of the SSLClientSocket::Connect() call. This test
10713 // matches the result of a server sending a handshake_failure alert,
10714 // rather than a Finished message, because it requires a client
10715 // certificate and none was supplied.
[email protected]8ddf8322012-02-23 18:08:0610716 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]bd0b6772011-01-11 19:59:3010717 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710718 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]bd0b6772011-01-11 19:59:3010719 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710720 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]bd0b6772011-01-11 19:59:3010721
10722 // [ssl_]data3 contains the data for the third SSL handshake. When a
10723 // connection to a server fails during an SSL handshake,
[email protected]80c75f682012-05-26 16:22:1710724 // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous
10725 // connection was attempted with TLSv1.1. This is transparent to the caller
[email protected]bd0b6772011-01-11 19:59:3010726 // of the HttpNetworkTransaction. Because this test failure is due to
10727 // requiring a client certificate, this fallback handshake should also
10728 // fail.
[email protected]8ddf8322012-02-23 18:08:0610729 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]bd0b6772011-01-11 19:59:3010730 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710731 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]bd0b6772011-01-11 19:59:3010732 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710733 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]bd0b6772011-01-11 19:59:3010734
[email protected]80c75f682012-05-26 16:22:1710735 // [ssl_]data4 contains the data for the fourth SSL handshake. When a
10736 // connection to a server fails during an SSL handshake,
10737 // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous
10738 // connection was attempted with TLSv1. This is transparent to the caller
10739 // of the HttpNetworkTransaction. Because this test failure is due to
10740 // requiring a client certificate, this fallback handshake should also
10741 // fail.
10742 SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
10743 ssl_data4.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710744 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4);
[email protected]80c75f682012-05-26 16:22:1710745 net::StaticSocketDataProvider data4(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710746 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]80c75f682012-05-26 16:22:1710747
[email protected]7799de12013-05-30 05:52:5110748 // Need one more if TLSv1.2 is enabled.
10749 SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
10750 ssl_data5.cert_request_info = cert_request.get();
10751 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5);
10752 net::StaticSocketDataProvider data5(NULL, 0, NULL, 0);
10753 session_deps_.socket_factory->AddSocketDataProvider(&data5);
10754
[email protected]bb88e1d32013-05-03 23:11:0710755 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610756 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010757 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bd0b6772011-01-11 19:59:3010758
[email protected]bd0b6772011-01-11 19:59:3010759 // Begin the SSL handshake with the peer. This consumes ssl_data1.
[email protected]49639fa2011-12-20 23:22:4110760 TestCompletionCallback callback;
10761 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]bd0b6772011-01-11 19:59:3010762 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10763
10764 // Complete the SSL handshake, which should abort due to requiring a
10765 // client certificate.
10766 rv = callback.WaitForResult();
10767 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10768
10769 // Indicate that no certificate should be supplied. From the perspective
10770 // of SSLClientCertCache, NULL is just as meaningful as a real
10771 // certificate, so this is the same as supply a
10772 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110773 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]bd0b6772011-01-11 19:59:3010774 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10775
10776 // Ensure the certificate was added to the client auth cache before
10777 // allowing the connection to continue restarting.
10778 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110779 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10780 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010781 ASSERT_EQ(NULL, client_cert.get());
10782
10783 // Restart the handshake. This will consume ssl_data2, which fails, and
[email protected]80c75f682012-05-26 16:22:1710784 // then consume ssl_data3 and ssl_data4, both of which should also fail.
10785 // The result code is checked against what ssl_data4 should return.
[email protected]bd0b6772011-01-11 19:59:3010786 rv = callback.WaitForResult();
10787 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv);
10788
10789 // Ensure that the client certificate is removed from the cache on a
10790 // handshake failure.
[email protected]791879c2013-12-17 07:22:4110791 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10792 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010793}
10794
10795// Ensure that a client certificate is removed from the SSL client auth
10796// cache when:
10797// 1) No proxy is involved.
10798// 2) TLS False Start is enabled.
10799// 3) The initial TLS handshake requests a client certificate.
10800// 4) The client supplies an invalid/unacceptable certificate.
[email protected]23e482282013-06-14 16:08:0210801TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:2310802 ClientAuthCertCache_Direct_FalseStart) {
[email protected]cb9bf6ca2011-01-28 13:15:2710803 net::HttpRequestInfo request_info;
10804 request_info.url = GURL("https://www.example.com/");
10805 request_info.method = "GET";
10806 request_info.load_flags = net::LOAD_NORMAL;
10807
[email protected]bd0b6772011-01-11 19:59:3010808 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110809 cert_request->host_and_port = HostPortPair("www.example.com", 443);
[email protected]bd0b6772011-01-11 19:59:3010810
10811 // When TLS False Start is used, SSLClientSocket::Connect() calls will
10812 // return successfully after reading up to the peer's Certificate message.
10813 // This is to allow the caller to call SSLClientSocket::Write(), which can
10814 // enqueue application data to be sent in the same packet as the
10815 // ChangeCipherSpec and Finished messages.
10816 // The actual handshake will be finished when SSLClientSocket::Read() is
10817 // called, which expects to process the peer's ChangeCipherSpec and
10818 // Finished messages. If there was an error negotiating with the peer,
10819 // such as due to the peer requiring a client certificate when none was
10820 // supplied, the alert sent by the peer won't be processed until Read() is
10821 // called.
10822
10823 // Like the non-False Start case, when a client certificate is requested by
10824 // the peer, the handshake is aborted during the Connect() call.
10825 // [ssl_]data1 represents the initial SSL handshake with the peer.
[email protected]8ddf8322012-02-23 18:08:0610826 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]bd0b6772011-01-11 19:59:3010827 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710828 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]bd0b6772011-01-11 19:59:3010829 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710830 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]bd0b6772011-01-11 19:59:3010831
10832 // When a client certificate is supplied, Connect() will not be aborted
10833 // when the peer requests the certificate. Instead, the handshake will
10834 // artificially succeed, allowing the caller to write the HTTP request to
10835 // the socket. The handshake messages are not processed until Read() is
10836 // called, which then detects that the handshake was aborted, due to the
10837 // peer sending a handshake_failure because it requires a client
10838 // certificate.
[email protected]8ddf8322012-02-23 18:08:0610839 SSLSocketDataProvider ssl_data2(ASYNC, net::OK);
[email protected]bd0b6772011-01-11 19:59:3010840 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710841 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]bd0b6772011-01-11 19:59:3010842 net::MockRead data2_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610843 net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR),
[email protected]bd0b6772011-01-11 19:59:3010844 };
10845 net::StaticSocketDataProvider data2(
10846 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710847 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]bd0b6772011-01-11 19:59:3010848
10849 // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is
[email protected]80c75f682012-05-26 16:22:1710850 // the data for the SSL handshake once the TLSv1.1 connection falls back to
10851 // TLSv1. It has the same behaviour as [ssl_]data2.
[email protected]8ddf8322012-02-23 18:08:0610852 SSLSocketDataProvider ssl_data3(ASYNC, net::OK);
[email protected]bd0b6772011-01-11 19:59:3010853 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710854 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]bd0b6772011-01-11 19:59:3010855 net::StaticSocketDataProvider data3(
10856 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710857 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]bd0b6772011-01-11 19:59:3010858
[email protected]80c75f682012-05-26 16:22:1710859 // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection
10860 // falls back to SSLv3. It has the same behaviour as [ssl_]data2.
10861 SSLSocketDataProvider ssl_data4(ASYNC, net::OK);
10862 ssl_data4.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710863 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4);
[email protected]80c75f682012-05-26 16:22:1710864 net::StaticSocketDataProvider data4(
10865 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710866 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]80c75f682012-05-26 16:22:1710867
[email protected]7799de12013-05-30 05:52:5110868 // Need one more if TLSv1.2 is enabled.
10869 SSLSocketDataProvider ssl_data5(ASYNC, net::OK);
10870 ssl_data5.cert_request_info = cert_request.get();
10871 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5);
10872 net::StaticSocketDataProvider data5(
10873 data2_reads, arraysize(data2_reads), NULL, 0);
10874 session_deps_.socket_factory->AddSocketDataProvider(&data5);
10875
[email protected]bb88e1d32013-05-03 23:11:0710876 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610877 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010878 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bd0b6772011-01-11 19:59:3010879
[email protected]bd0b6772011-01-11 19:59:3010880 // Begin the initial SSL handshake.
[email protected]49639fa2011-12-20 23:22:4110881 TestCompletionCallback callback;
10882 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]bd0b6772011-01-11 19:59:3010883 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10884
10885 // Complete the SSL handshake, which should abort due to requiring a
10886 // client certificate.
10887 rv = callback.WaitForResult();
10888 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10889
10890 // Indicate that no certificate should be supplied. From the perspective
10891 // of SSLClientCertCache, NULL is just as meaningful as a real
10892 // certificate, so this is the same as supply a
10893 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110894 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]bd0b6772011-01-11 19:59:3010895 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10896
10897 // Ensure the certificate was added to the client auth cache before
10898 // allowing the connection to continue restarting.
10899 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110900 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10901 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010902 ASSERT_EQ(NULL, client_cert.get());
10903
[email protected]bd0b6772011-01-11 19:59:3010904 // Restart the handshake. This will consume ssl_data2, which fails, and
[email protected]80c75f682012-05-26 16:22:1710905 // then consume ssl_data3 and ssl_data4, both of which should also fail.
10906 // The result code is checked against what ssl_data4 should return.
[email protected]bd0b6772011-01-11 19:59:3010907 rv = callback.WaitForResult();
10908 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv);
10909
10910 // Ensure that the client certificate is removed from the cache on a
10911 // handshake failure.
[email protected]791879c2013-12-17 07:22:4110912 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10913 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010914}
10915
[email protected]8c405132011-01-11 22:03:1810916// Ensure that a client certificate is removed from the SSL client auth
10917// cache when:
10918// 1) An HTTPS proxy is involved.
10919// 3) The HTTPS proxy requests a client certificate.
10920// 4) The client supplies an invalid/unacceptable certificate for the
10921// proxy.
10922// The test is repeated twice, first for connecting to an HTTPS endpoint,
10923// then for connecting to an HTTP endpoint.
[email protected]23e482282013-06-14 16:08:0210924TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) {
[email protected]bb88e1d32013-05-03 23:11:0710925 session_deps_.proxy_service.reset(
[email protected]8c405132011-01-11 22:03:1810926 ProxyService::CreateFixed("https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:2910927 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710928 session_deps_.net_log = log.bound().net_log();
[email protected]8c405132011-01-11 22:03:1810929
10930 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110931 cert_request->host_and_port = HostPortPair("proxy", 70);
[email protected]8c405132011-01-11 22:03:1810932
10933 // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of
10934 // [ssl_]data[1-3]. Rather than represending the endpoint
10935 // (www.example.com:443), they represent failures with the HTTPS proxy
10936 // (proxy:70).
[email protected]8ddf8322012-02-23 18:08:0610937 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]8c405132011-01-11 22:03:1810938 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710939 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]8c405132011-01-11 22:03:1810940 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710941 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8c405132011-01-11 22:03:1810942
[email protected]8ddf8322012-02-23 18:08:0610943 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]8c405132011-01-11 22:03:1810944 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710945 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]8c405132011-01-11 22:03:1810946 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710947 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]8c405132011-01-11 22:03:1810948
[email protected]80c75f682012-05-26 16:22:1710949 // TODO(wtc): find out why this unit test doesn't need [ssl_]data3.
10950#if 0
[email protected]8ddf8322012-02-23 18:08:0610951 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]8c405132011-01-11 22:03:1810952 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710953 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]8c405132011-01-11 22:03:1810954 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710955 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]80c75f682012-05-26 16:22:1710956#endif
[email protected]8c405132011-01-11 22:03:1810957
10958 net::HttpRequestInfo requests[2];
10959 requests[0].url = GURL("https://www.example.com/");
10960 requests[0].method = "GET";
10961 requests[0].load_flags = net::LOAD_NORMAL;
10962
10963 requests[1].url = GURL("http://www.example.com/");
10964 requests[1].method = "GET";
10965 requests[1].load_flags = net::LOAD_NORMAL;
10966
10967 for (size_t i = 0; i < arraysize(requests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:0710968 session_deps_.socket_factory->ResetNextMockIndexes();
10969 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8c405132011-01-11 22:03:1810970 scoped_ptr<HttpNetworkTransaction> trans(
[email protected]90499482013-06-01 00:39:5010971 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]8c405132011-01-11 22:03:1810972
10973 // Begin the SSL handshake with the proxy.
[email protected]49639fa2011-12-20 23:22:4110974 TestCompletionCallback callback;
10975 int rv = trans->Start(
10976 &requests[i], callback.callback(), net::BoundNetLog());
[email protected]8c405132011-01-11 22:03:1810977 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10978
10979 // Complete the SSL handshake, which should abort due to requiring a
10980 // client certificate.
10981 rv = callback.WaitForResult();
10982 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10983
10984 // Indicate that no certificate should be supplied. From the perspective
10985 // of SSLClientCertCache, NULL is just as meaningful as a real
10986 // certificate, so this is the same as supply a
10987 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110988 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]8c405132011-01-11 22:03:1810989 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10990
10991 // Ensure the certificate was added to the client auth cache before
10992 // allowing the connection to continue restarting.
10993 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110994 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10995 HostPortPair("proxy", 70), &client_cert));
[email protected]8c405132011-01-11 22:03:1810996 ASSERT_EQ(NULL, client_cert.get());
10997 // Ensure the certificate was NOT cached for the endpoint. This only
10998 // applies to HTTPS requests, but is fine to check for HTTP requests.
[email protected]791879c2013-12-17 07:22:4110999 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
11000 HostPortPair("www.example.com", 443), &client_cert));
[email protected]8c405132011-01-11 22:03:1811001
11002 // Restart the handshake. This will consume ssl_data2, which fails, and
11003 // then consume ssl_data3, which should also fail. The result code is
11004 // checked against what ssl_data3 should return.
11005 rv = callback.WaitForResult();
11006 ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv);
11007
11008 // Now that the new handshake has failed, ensure that the client
11009 // certificate was removed from the client auth cache.
[email protected]791879c2013-12-17 07:22:4111010 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
11011 HostPortPair("proxy", 70), &client_cert));
11012 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
11013 HostPortPair("www.example.com", 443), &client_cert));
[email protected]8c405132011-01-11 22:03:1811014 }
11015}
11016
[email protected]23e482282013-06-14 16:08:0211017// Unlike TEST/TEST_F, which are macros that expand to further macros,
11018// TEST_P is a macro that expands directly to code that stringizes the
11019// arguments. As a result, macros passed as parameters (such as prefix
11020// or test_case_name) will not be expanded by the preprocessor. To
11021// work around this, indirect the macro for TEST_P, so that the
11022// pre-processor will expand macros such as MAYBE_test_name before
11023// instantiating the test.
11024#define WRAPPED_TEST_P(test_case_name, test_name) \
11025 TEST_P(test_case_name, test_name)
11026
[email protected]45b170822012-05-04 21:18:1411027// Times out on Win7 dbg(2) bot. http://crbug.com/124776
11028#if defined(OS_WIN)
11029#define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling
11030#else
11031#define MAYBE_UseIPConnectionPooling UseIPConnectionPooling
11032#endif
[email protected]23e482282013-06-14 16:08:0211033WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) {
[email protected]d7599122014-05-24 03:37:2311034 session_deps_.use_alternate_protocols = true;
11035 session_deps_.next_protos = SpdyNextProtos();
[email protected]e3ceb682011-06-28 23:55:4611036
11037 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
[email protected]bb88e1d32013-05-03 23:11:0711038 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11039 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]b9ec6882011-07-01 07:40:2611040 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11041 pool_peer.DisableDomainAuthenticationVerification();
[email protected]e3ceb682011-06-28 23:55:4611042
[email protected]8ddf8322012-02-23 18:08:0611043 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211044 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711045 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e3ceb682011-06-28 23:55:4611046
[email protected]cdf8f7e72013-05-23 10:56:4611047 scoped_ptr<SpdyFrame> host1_req(
11048 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11049 scoped_ptr<SpdyFrame> host2_req(
11050 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]e3ceb682011-06-28 23:55:4611051 MockWrite spdy_writes[] = {
11052 CreateMockWrite(*host1_req, 1),
11053 CreateMockWrite(*host2_req, 4),
11054 };
[email protected]23e482282013-06-14 16:08:0211055 scoped_ptr<SpdyFrame> host1_resp(
11056 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11057 scoped_ptr<SpdyFrame> host1_resp_body(
11058 spdy_util_.ConstructSpdyBodyFrame(1, true));
11059 scoped_ptr<SpdyFrame> host2_resp(
11060 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11061 scoped_ptr<SpdyFrame> host2_resp_body(
11062 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]e3ceb682011-06-28 23:55:4611063 MockRead spdy_reads[] = {
11064 CreateMockRead(*host1_resp, 2),
11065 CreateMockRead(*host1_resp_body, 3),
11066 CreateMockRead(*host2_resp, 5),
11067 CreateMockRead(*host2_resp_body, 6),
[email protected]8ddf8322012-02-23 18:08:0611068 MockRead(ASYNC, 0, 7),
[email protected]e3ceb682011-06-28 23:55:4611069 };
11070
[email protected]d2b5f092012-06-08 23:55:0211071 IPAddressNumber ip;
11072 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11073 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11074 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711075 OrderedSocketData spdy_data(
11076 connect,
11077 spdy_reads, arraysize(spdy_reads),
11078 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711079 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]e3ceb682011-06-28 23:55:4611080
[email protected]aa22b242011-11-16 18:58:2911081 TestCompletionCallback callback;
[email protected]e3ceb682011-06-28 23:55:4611082 HttpRequestInfo request1;
11083 request1.method = "GET";
11084 request1.url = GURL("https://www.google.com/");
11085 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011086 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611087
[email protected]49639fa2011-12-20 23:22:4111088 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611089 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111090 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611091
11092 const HttpResponseInfo* response = trans1.GetResponseInfo();
11093 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011094 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611095 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11096
11097 std::string response_data;
11098 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11099 EXPECT_EQ("hello!", response_data);
11100
11101 // Preload www.gmail.com into HostCache.
11102 HostPortPair host_port("www.gmail.com", 443);
[email protected]5109c1952013-08-20 18:44:1011103 HostResolver::RequestInfo resolve_info(host_port);
[email protected]e3ceb682011-06-28 23:55:4611104 AddressList ignored;
[email protected]5109c1952013-08-20 18:44:1011105 rv = session_deps_.host_resolver->Resolve(resolve_info,
11106 DEFAULT_PRIORITY,
11107 &ignored,
11108 callback.callback(),
11109 NULL,
11110 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:4711111 EXPECT_EQ(ERR_IO_PENDING, rv);
11112 rv = callback.WaitForResult();
11113 EXPECT_EQ(OK, rv);
[email protected]e3ceb682011-06-28 23:55:4611114
11115 HttpRequestInfo request2;
11116 request2.method = "GET";
11117 request2.url = GURL("https://www.gmail.com/");
11118 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011119 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611120
[email protected]49639fa2011-12-20 23:22:4111121 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611122 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111123 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611124
11125 response = trans2.GetResponseInfo();
11126 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011127 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611128 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11129 EXPECT_TRUE(response->was_fetched_via_spdy);
11130 EXPECT_TRUE(response->was_npn_negotiated);
11131 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11132 EXPECT_EQ("hello!", response_data);
[email protected]e3ceb682011-06-28 23:55:4611133}
[email protected]45b170822012-05-04 21:18:1411134#undef MAYBE_UseIPConnectionPooling
[email protected]e3ceb682011-06-28 23:55:4611135
[email protected]23e482282013-06-14 16:08:0211136TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) {
[email protected]d7599122014-05-24 03:37:2311137 session_deps_.use_alternate_protocols = true;
11138 session_deps_.next_protos = SpdyNextProtos();
[email protected]d2b5f092012-06-08 23:55:0211139
11140 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
[email protected]bb88e1d32013-05-03 23:11:0711141 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11142 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d2b5f092012-06-08 23:55:0211143 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11144 pool_peer.DisableDomainAuthenticationVerification();
11145
11146 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211147 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711148 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]d2b5f092012-06-08 23:55:0211149
[email protected]cdf8f7e72013-05-23 10:56:4611150 scoped_ptr<SpdyFrame> host1_req(
11151 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11152 scoped_ptr<SpdyFrame> host2_req(
11153 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]d2b5f092012-06-08 23:55:0211154 MockWrite spdy_writes[] = {
11155 CreateMockWrite(*host1_req, 1),
11156 CreateMockWrite(*host2_req, 4),
11157 };
[email protected]23e482282013-06-14 16:08:0211158 scoped_ptr<SpdyFrame> host1_resp(
11159 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11160 scoped_ptr<SpdyFrame> host1_resp_body(
11161 spdy_util_.ConstructSpdyBodyFrame(1, true));
11162 scoped_ptr<SpdyFrame> host2_resp(
11163 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11164 scoped_ptr<SpdyFrame> host2_resp_body(
11165 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]d2b5f092012-06-08 23:55:0211166 MockRead spdy_reads[] = {
11167 CreateMockRead(*host1_resp, 2),
11168 CreateMockRead(*host1_resp_body, 3),
11169 CreateMockRead(*host2_resp, 5),
11170 CreateMockRead(*host2_resp_body, 6),
11171 MockRead(ASYNC, 0, 7),
11172 };
11173
11174 IPAddressNumber ip;
11175 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11176 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11177 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711178 OrderedSocketData spdy_data(
11179 connect,
11180 spdy_reads, arraysize(spdy_reads),
11181 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711182 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d2b5f092012-06-08 23:55:0211183
11184 TestCompletionCallback callback;
11185 HttpRequestInfo request1;
11186 request1.method = "GET";
11187 request1.url = GURL("https://www.google.com/");
11188 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011189 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]d2b5f092012-06-08 23:55:0211190
11191 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
11192 EXPECT_EQ(ERR_IO_PENDING, rv);
11193 EXPECT_EQ(OK, callback.WaitForResult());
11194
11195 const HttpResponseInfo* response = trans1.GetResponseInfo();
11196 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011197 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d2b5f092012-06-08 23:55:0211198 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11199
11200 std::string response_data;
11201 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11202 EXPECT_EQ("hello!", response_data);
11203
11204 HttpRequestInfo request2;
11205 request2.method = "GET";
11206 request2.url = GURL("https://www.gmail.com/");
11207 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011208 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]d2b5f092012-06-08 23:55:0211209
11210 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
11211 EXPECT_EQ(ERR_IO_PENDING, rv);
11212 EXPECT_EQ(OK, callback.WaitForResult());
11213
11214 response = trans2.GetResponseInfo();
11215 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011216 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d2b5f092012-06-08 23:55:0211217 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11218 EXPECT_TRUE(response->was_fetched_via_spdy);
11219 EXPECT_TRUE(response->was_npn_negotiated);
11220 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11221 EXPECT_EQ("hello!", response_data);
[email protected]d2b5f092012-06-08 23:55:0211222}
11223
[email protected]e3ceb682011-06-28 23:55:4611224class OneTimeCachingHostResolver : public net::HostResolver {
11225 public:
11226 explicit OneTimeCachingHostResolver(const HostPortPair& host_port)
11227 : host_port_(host_port) {}
dchengb03027d2014-10-21 12:00:2011228 ~OneTimeCachingHostResolver() override {}
[email protected]e3ceb682011-06-28 23:55:4611229
11230 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); }
11231
11232 // HostResolver methods:
dchengb03027d2014-10-21 12:00:2011233 int Resolve(const RequestInfo& info,
11234 RequestPriority priority,
11235 AddressList* addresses,
11236 const CompletionCallback& callback,
11237 RequestHandle* out_req,
11238 const BoundNetLog& net_log) override {
[email protected]95a214c2011-08-04 21:50:4011239 return host_resolver_.Resolve(
[email protected]5109c1952013-08-20 18:44:1011240 info, priority, addresses, callback, out_req, net_log);
[email protected]95a214c2011-08-04 21:50:4011241 }
11242
dchengb03027d2014-10-21 12:00:2011243 int ResolveFromCache(const RequestInfo& info,
11244 AddressList* addresses,
11245 const BoundNetLog& net_log) override {
[email protected]95a214c2011-08-04 21:50:4011246 int rv = host_resolver_.ResolveFromCache(info, addresses, net_log);
11247 if (rv == OK && info.host_port_pair().Equals(host_port_))
[email protected]98e1cd012011-11-08 15:33:0911248 host_resolver_.GetHostCache()->clear();
[email protected]e3ceb682011-06-28 23:55:4611249 return rv;
11250 }
11251
dchengb03027d2014-10-21 12:00:2011252 void CancelRequest(RequestHandle req) override {
[email protected]e3ceb682011-06-28 23:55:4611253 host_resolver_.CancelRequest(req);
11254 }
11255
[email protected]46da33be2011-07-19 21:58:0411256 MockCachingHostResolver* GetMockHostResolver() {
11257 return &host_resolver_;
11258 }
11259
[email protected]e3ceb682011-06-28 23:55:4611260 private:
11261 MockCachingHostResolver host_resolver_;
11262 const HostPortPair host_port_;
11263};
11264
[email protected]45b170822012-05-04 21:18:1411265// Times out on Win7 dbg(2) bot. http://crbug.com/124776
11266#if defined(OS_WIN)
[email protected]bb88e1d32013-05-03 23:11:0711267#define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \
11268 DISABLED_UseIPConnectionPoolingWithHostCacheExpiration
[email protected]45b170822012-05-04 21:18:1411269#else
[email protected]bb88e1d32013-05-03 23:11:0711270#define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \
11271 UseIPConnectionPoolingWithHostCacheExpiration
[email protected]45b170822012-05-04 21:18:1411272#endif
[email protected]23e482282013-06-14 16:08:0211273WRAPPED_TEST_P(HttpNetworkTransactionTest,
11274 MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) {
[email protected]23e482282013-06-14 16:08:0211275// Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_
11276// prefix doesn't work with parametrized tests).
11277#if defined(OS_WIN)
11278 return;
[email protected]88c7b4be2014-03-19 23:04:0111279#else
[email protected]d7599122014-05-24 03:37:2311280 session_deps_.use_alternate_protocols = true;
11281 session_deps_.next_protos = SpdyNextProtos();
[email protected]e3ceb682011-06-28 23:55:4611282
11283 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver.
[email protected]e3ceb682011-06-28 23:55:4611284 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443));
[email protected]c6bf8152012-12-02 07:43:3411285 HttpNetworkSession::Params params =
[email protected]bb88e1d32013-05-03 23:11:0711286 SpdySessionDependencies::CreateSessionParams(&session_deps_);
[email protected]e3ceb682011-06-28 23:55:4611287 params.host_resolver = &host_resolver;
[email protected]bb88e1d32013-05-03 23:11:0711288 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]b9ec6882011-07-01 07:40:2611289 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11290 pool_peer.DisableDomainAuthenticationVerification();
[email protected]e3ceb682011-06-28 23:55:4611291
[email protected]8ddf8322012-02-23 18:08:0611292 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211293 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711294 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e3ceb682011-06-28 23:55:4611295
[email protected]cdf8f7e72013-05-23 10:56:4611296 scoped_ptr<SpdyFrame> host1_req(
11297 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11298 scoped_ptr<SpdyFrame> host2_req(
11299 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]e3ceb682011-06-28 23:55:4611300 MockWrite spdy_writes[] = {
11301 CreateMockWrite(*host1_req, 1),
11302 CreateMockWrite(*host2_req, 4),
11303 };
[email protected]23e482282013-06-14 16:08:0211304 scoped_ptr<SpdyFrame> host1_resp(
11305 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11306 scoped_ptr<SpdyFrame> host1_resp_body(
11307 spdy_util_.ConstructSpdyBodyFrame(1, true));
11308 scoped_ptr<SpdyFrame> host2_resp(
11309 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11310 scoped_ptr<SpdyFrame> host2_resp_body(
11311 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]e3ceb682011-06-28 23:55:4611312 MockRead spdy_reads[] = {
11313 CreateMockRead(*host1_resp, 2),
11314 CreateMockRead(*host1_resp_body, 3),
11315 CreateMockRead(*host2_resp, 5),
11316 CreateMockRead(*host2_resp_body, 6),
[email protected]8ddf8322012-02-23 18:08:0611317 MockRead(ASYNC, 0, 7),
[email protected]e3ceb682011-06-28 23:55:4611318 };
11319
[email protected]d2b5f092012-06-08 23:55:0211320 IPAddressNumber ip;
11321 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11322 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11323 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711324 OrderedSocketData spdy_data(
11325 connect,
11326 spdy_reads, arraysize(spdy_reads),
11327 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711328 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]e3ceb682011-06-28 23:55:4611329
[email protected]aa22b242011-11-16 18:58:2911330 TestCompletionCallback callback;
[email protected]e3ceb682011-06-28 23:55:4611331 HttpRequestInfo request1;
11332 request1.method = "GET";
11333 request1.url = GURL("https://www.google.com/");
11334 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011335 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611336
[email protected]49639fa2011-12-20 23:22:4111337 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611338 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111339 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611340
11341 const HttpResponseInfo* response = trans1.GetResponseInfo();
11342 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011343 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611344 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11345
11346 std::string response_data;
11347 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11348 EXPECT_EQ("hello!", response_data);
11349
11350 // Preload cache entries into HostCache.
[email protected]5109c1952013-08-20 18:44:1011351 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443));
[email protected]e3ceb682011-06-28 23:55:4611352 AddressList ignored;
[email protected]5109c1952013-08-20 18:44:1011353 rv = host_resolver.Resolve(resolve_info,
11354 DEFAULT_PRIORITY,
11355 &ignored,
11356 callback.callback(),
11357 NULL,
11358 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:4711359 EXPECT_EQ(ERR_IO_PENDING, rv);
11360 rv = callback.WaitForResult();
11361 EXPECT_EQ(OK, rv);
[email protected]e3ceb682011-06-28 23:55:4611362
11363 HttpRequestInfo request2;
11364 request2.method = "GET";
11365 request2.url = GURL("https://www.gmail.com/");
11366 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011367 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611368
[email protected]49639fa2011-12-20 23:22:4111369 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611370 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111371 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611372
11373 response = trans2.GetResponseInfo();
11374 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011375 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611376 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11377 EXPECT_TRUE(response->was_fetched_via_spdy);
11378 EXPECT_TRUE(response->was_npn_negotiated);
11379 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11380 EXPECT_EQ("hello!", response_data);
[email protected]88c7b4be2014-03-19 23:04:0111381#endif
[email protected]e3ceb682011-06-28 23:55:4611382}
[email protected]45b170822012-05-04 21:18:1411383#undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration
[email protected]e3ceb682011-06-28 23:55:4611384
[email protected]23e482282013-06-14 16:08:0211385TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) {
lgarrona91df87f2014-12-05 00:51:3411386 const std::string https_url = "https://www.google.com:8080/";
11387 const std::string http_url = "http://www.google.com:8080/";
[email protected]8450d722012-07-02 19:14:0411388
11389 // SPDY GET for HTTPS URL
[email protected]cdf8f7e72013-05-23 10:56:4611390 scoped_ptr<SpdyFrame> req1(
11391 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]8450d722012-07-02 19:14:0411392
11393 MockWrite writes1[] = {
11394 CreateMockWrite(*req1, 0),
11395 };
11396
[email protected]23e482282013-06-14 16:08:0211397 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11398 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]8450d722012-07-02 19:14:0411399 MockRead reads1[] = {
11400 CreateMockRead(*resp1, 1),
11401 CreateMockRead(*body1, 2),
11402 MockRead(ASYNC, ERR_IO_PENDING, 3)
11403 };
11404
[email protected]dd54bd82012-07-19 23:44:5711405 DelayedSocketData data1(
11406 1, reads1, arraysize(reads1),
11407 writes1, arraysize(writes1));
[email protected]8450d722012-07-02 19:14:0411408 MockConnect connect_data1(ASYNC, OK);
[email protected]dd54bd82012-07-19 23:44:5711409 data1.set_connect_data(connect_data1);
[email protected]8450d722012-07-02 19:14:0411410
11411 // HTTP GET for the HTTP URL
11412 MockWrite writes2[] = {
lgarrona91df87f2014-12-05 00:51:3411413 MockWrite(ASYNC, 4,
11414 "GET / HTTP/1.1\r\n"
11415 "Host: www.google.com:8080\r\n"
11416 "Connection: keep-alive\r\n\r\n"),
[email protected]8450d722012-07-02 19:14:0411417 };
11418
11419 MockRead reads2[] = {
11420 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
11421 MockRead(ASYNC, 6, "hello"),
11422 MockRead(ASYNC, 7, OK),
11423 };
11424
[email protected]dd54bd82012-07-19 23:44:5711425 DelayedSocketData data2(
11426 1, reads2, arraysize(reads2),
11427 writes2, arraysize(writes2));
[email protected]8450d722012-07-02 19:14:0411428
[email protected]8450d722012-07-02 19:14:0411429 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211430 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711431 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
11432 session_deps_.socket_factory->AddSocketDataProvider(&data1);
11433 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]8450d722012-07-02 19:14:0411434
[email protected]bb88e1d32013-05-03 23:11:0711435 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411436
11437 // Start the first transaction to set up the SpdySession
11438 HttpRequestInfo request1;
11439 request1.method = "GET";
11440 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411441 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011442 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411443 TestCompletionCallback callback1;
11444 EXPECT_EQ(ERR_IO_PENDING,
11445 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411446 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411447
11448 EXPECT_EQ(OK, callback1.WaitForResult());
11449 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11450
11451 // Now, start the HTTP request
11452 HttpRequestInfo request2;
11453 request2.method = "GET";
11454 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411455 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011456 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411457 TestCompletionCallback callback2;
11458 EXPECT_EQ(ERR_IO_PENDING,
11459 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411460 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411461
11462 EXPECT_EQ(OK, callback2.WaitForResult());
11463 EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11464}
11465
[email protected]23e482282013-06-14 16:08:0211466TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) {
lgarrona91df87f2014-12-05 00:51:3411467 const std::string https_url = "https://www.google.com:8080/";
11468 const std::string http_url = "http://www.google.com:8080/";
[email protected]8450d722012-07-02 19:14:0411469
11470 // SPDY GET for HTTPS URL (through CONNECT tunnel)
lgarrona91df87f2014-12-05 00:51:3411471 const HostPortPair host_port_pair("www.google.com", 8080);
11472 scoped_ptr<SpdyFrame> connect(
11473 spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair));
[email protected]cdf8f7e72013-05-23 10:56:4611474 scoped_ptr<SpdyFrame> req1(
11475 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]23e482282013-06-14 16:08:0211476 scoped_ptr<SpdyFrame> wrapped_req1(
11477 spdy_util_.ConstructWrappedSpdyFrame(req1, 1));
[email protected]601e03f12014-04-06 16:26:3911478
11479 // SPDY GET for HTTP URL (through the proxy, but not the tunnel).
[email protected]745aa9c2014-06-27 02:21:2911480 SpdyHeaderBlock req2_block;
11481 req2_block[spdy_util_.GetMethodKey()] = "GET";
bnc33b8cef42014-11-19 17:30:3811482 req2_block[spdy_util_.GetPathKey()] = "/";
lgarrona91df87f2014-12-05 00:51:3411483 req2_block[spdy_util_.GetHostKey()] = "www.google.com:8080";
[email protected]745aa9c2014-06-27 02:21:2911484 req2_block[spdy_util_.GetSchemeKey()] = "http";
11485 spdy_util_.MaybeAddVersionHeader(&req2_block);
[email protected]601e03f12014-04-06 16:26:3911486 scoped_ptr<SpdyFrame> req2(
[email protected]745aa9c2014-06-27 02:21:2911487 spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true));
[email protected]8450d722012-07-02 19:14:0411488
11489 MockWrite writes1[] = {
11490 CreateMockWrite(*connect, 0),
11491 CreateMockWrite(*wrapped_req1, 2),
11492 CreateMockWrite(*req2, 5),
11493 };
11494
[email protected]23e482282013-06-14 16:08:0211495 scoped_ptr<SpdyFrame> conn_resp(
11496 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11497 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11498 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
11499 scoped_ptr<SpdyFrame> wrapped_resp1(
11500 spdy_util_.ConstructWrappedSpdyFrame(resp1, 1));
11501 scoped_ptr<SpdyFrame> wrapped_body1(
11502 spdy_util_.ConstructWrappedSpdyFrame(body1, 1));
11503 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11504 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]8450d722012-07-02 19:14:0411505 MockRead reads1[] = {
11506 CreateMockRead(*conn_resp, 1),
11507 CreateMockRead(*wrapped_resp1, 3),
11508 CreateMockRead(*wrapped_body1, 4),
11509 CreateMockRead(*resp2, 6),
11510 CreateMockRead(*body2, 7),
11511 MockRead(ASYNC, ERR_IO_PENDING, 8)
11512 };
11513
[email protected]dd54bd82012-07-19 23:44:5711514 DeterministicSocketData data1(reads1, arraysize(reads1),
11515 writes1, arraysize(writes1));
[email protected]8450d722012-07-02 19:14:0411516 MockConnect connect_data1(ASYNC, OK);
[email protected]dd54bd82012-07-19 23:44:5711517 data1.set_connect_data(connect_data1);
[email protected]8450d722012-07-02 19:14:0411518
[email protected]bb88e1d32013-05-03 23:11:0711519 session_deps_.proxy_service.reset(
[email protected]f6c63db52013-02-02 00:35:2211520 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"));
11521 CapturingNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0711522 session_deps_.net_log = &log;
[email protected]8450d722012-07-02 19:14:0411523 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
[email protected]23e482282013-06-14 16:08:0211524 ssl1.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711525 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
[email protected]8450d722012-07-02 19:14:0411526 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
[email protected]23e482282013-06-14 16:08:0211527 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711528 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11529 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1);
[email protected]8450d722012-07-02 19:14:0411530
11531 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711532 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411533
11534 // Start the first transaction to set up the SpdySession
11535 HttpRequestInfo request1;
11536 request1.method = "GET";
11537 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411538 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011539 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411540 TestCompletionCallback callback1;
11541 EXPECT_EQ(ERR_IO_PENDING,
11542 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411543 base::MessageLoop::current()->RunUntilIdle();
[email protected]dd54bd82012-07-19 23:44:5711544 data1.RunFor(4);
[email protected]8450d722012-07-02 19:14:0411545
11546 EXPECT_EQ(OK, callback1.WaitForResult());
11547 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11548
[email protected]f6c63db52013-02-02 00:35:2211549 LoadTimingInfo load_timing_info1;
11550 EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1));
11551 TestLoadTimingNotReusedWithPac(load_timing_info1,
11552 CONNECT_TIMING_HAS_SSL_TIMES);
11553
[email protected]8450d722012-07-02 19:14:0411554 // Now, start the HTTP request
11555 HttpRequestInfo request2;
11556 request2.method = "GET";
11557 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411558 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011559 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411560 TestCompletionCallback callback2;
11561 EXPECT_EQ(ERR_IO_PENDING,
11562 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411563 base::MessageLoop::current()->RunUntilIdle();
[email protected]dd54bd82012-07-19 23:44:5711564 data1.RunFor(3);
[email protected]8450d722012-07-02 19:14:0411565
11566 EXPECT_EQ(OK, callback2.WaitForResult());
11567 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
[email protected]f6c63db52013-02-02 00:35:2211568
11569 LoadTimingInfo load_timing_info2;
11570 EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2));
11571 // The established SPDY sessions is considered reused by the HTTP request.
11572 TestLoadTimingReusedWithPac(load_timing_info2);
11573 // HTTP requests over a SPDY session should have a different connection
11574 // socket_log_id than requests over a tunnel.
11575 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
[email protected]8450d722012-07-02 19:14:0411576}
11577
[email protected]23e482282013-06-14 16:08:0211578TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) {
[email protected]d7599122014-05-24 03:37:2311579 session_deps_.force_spdy_always = true;
lgarrona91df87f2014-12-05 00:51:3411580 const std::string https_url = "https://www.google.com:8080/";
11581 const std::string http_url = "http://www.google.com:8080/";
[email protected]8450d722012-07-02 19:14:0411582
11583 // SPDY GET for HTTPS URL
[email protected]cdf8f7e72013-05-23 10:56:4611584 scoped_ptr<SpdyFrame> req1(
11585 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]8450d722012-07-02 19:14:0411586 // SPDY GET for the HTTP URL
[email protected]cdf8f7e72013-05-23 10:56:4611587 scoped_ptr<SpdyFrame> req2(
11588 spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM));
[email protected]8450d722012-07-02 19:14:0411589
11590 MockWrite writes[] = {
11591 CreateMockWrite(*req1, 1),
11592 CreateMockWrite(*req2, 4),
11593 };
11594
[email protected]23e482282013-06-14 16:08:0211595 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11596 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
11597 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11598 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]8450d722012-07-02 19:14:0411599 MockRead reads[] = {
11600 CreateMockRead(*resp1, 2),
11601 CreateMockRead(*body1, 3),
11602 CreateMockRead(*resp2, 5),
11603 CreateMockRead(*body2, 6),
11604 MockRead(ASYNC, ERR_IO_PENDING, 7)
11605 };
11606
[email protected]dd54bd82012-07-19 23:44:5711607 OrderedSocketData data(reads, arraysize(reads),
11608 writes, arraysize(writes));
[email protected]8450d722012-07-02 19:14:0411609
[email protected]8450d722012-07-02 19:14:0411610 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211611 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711612 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
11613 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]8450d722012-07-02 19:14:0411614
[email protected]bb88e1d32013-05-03 23:11:0711615 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411616
11617 // Start the first transaction to set up the SpdySession
11618 HttpRequestInfo request1;
11619 request1.method = "GET";
11620 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411621 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011622 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411623 TestCompletionCallback callback1;
11624 EXPECT_EQ(ERR_IO_PENDING,
11625 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411626 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411627
11628 EXPECT_EQ(OK, callback1.WaitForResult());
11629 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11630
11631 // Now, start the HTTP request
11632 HttpRequestInfo request2;
11633 request2.method = "GET";
11634 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411635 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011636 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411637 TestCompletionCallback callback2;
11638 EXPECT_EQ(ERR_IO_PENDING,
11639 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411640 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411641
11642 EXPECT_EQ(OK, callback2.WaitForResult());
11643 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11644}
11645
[email protected]2d88e7d2012-07-19 17:55:1711646// Test that in the case where we have a SPDY session to a SPDY proxy
11647// that we do not pool other origins that resolve to the same IP when
11648// the certificate does not match the new origin.
11649// http://crbug.com/134690
[email protected]23e482282013-06-14 16:08:0211650TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) {
[email protected]2d88e7d2012-07-19 17:55:1711651 const std::string url1 = "http://www.google.com/";
11652 const std::string url2 = "https://mail.google.com/";
11653 const std::string ip_addr = "1.2.3.4";
11654
11655 // SPDY GET for HTTP URL (through SPDY proxy)
[email protected]23e482282013-06-14 16:08:0211656 scoped_ptr<SpdyHeaderBlock> headers(
11657 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/"));
[email protected]745aa9c2014-06-27 02:21:2911658 scoped_ptr<SpdyFrame> req1(
11659 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true));
[email protected]2d88e7d2012-07-19 17:55:1711660
11661 MockWrite writes1[] = {
11662 CreateMockWrite(*req1, 0),
11663 };
11664
[email protected]23e482282013-06-14 16:08:0211665 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11666 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2d88e7d2012-07-19 17:55:1711667 MockRead reads1[] = {
11668 CreateMockRead(*resp1, 1),
11669 CreateMockRead(*body1, 2),
11670 MockRead(ASYNC, OK, 3) // EOF
11671 };
11672
11673 scoped_ptr<DeterministicSocketData> data1(
11674 new DeterministicSocketData(reads1, arraysize(reads1),
11675 writes1, arraysize(writes1)));
11676 IPAddressNumber ip;
11677 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip));
11678 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11679 MockConnect connect_data1(ASYNC, OK, peer_addr);
11680 data1->set_connect_data(connect_data1);
11681
11682 // SPDY GET for HTTPS URL (direct)
[email protected]cdf8f7e72013-05-23 10:56:4611683 scoped_ptr<SpdyFrame> req2(
11684 spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM));
[email protected]2d88e7d2012-07-19 17:55:1711685
11686 MockWrite writes2[] = {
11687 CreateMockWrite(*req2, 0),
11688 };
11689
[email protected]23e482282013-06-14 16:08:0211690 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11691 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2d88e7d2012-07-19 17:55:1711692 MockRead reads2[] = {
11693 CreateMockRead(*resp2, 1),
11694 CreateMockRead(*body2, 2),
11695 MockRead(ASYNC, OK, 3) // EOF
11696 };
11697
11698 scoped_ptr<DeterministicSocketData> data2(
11699 new DeterministicSocketData(reads2, arraysize(reads2),
11700 writes2, arraysize(writes2)));
11701 MockConnect connect_data2(ASYNC, OK);
11702 data2->set_connect_data(connect_data2);
11703
11704 // Set up a proxy config that sends HTTP requests to a proxy, and
11705 // all others direct.
11706 ProxyConfig proxy_config;
11707 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443");
11708 CapturingProxyResolver* capturing_proxy_resolver =
11709 new CapturingProxyResolver();
[email protected]bb88e1d32013-05-03 23:11:0711710 session_deps_.proxy_service.reset(new ProxyService(
[email protected]2d88e7d2012-07-19 17:55:1711711 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
11712 NULL));
11713
11714 // Load a valid cert. Note, that this does not need to
11715 // be valid for proxy because the MockSSLClientSocket does
11716 // not actually verify it. But SpdySession will use this
11717 // to see if it is valid for the new origin
[email protected]6cdfd7f2013-02-08 20:40:1511718 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]2d88e7d2012-07-19 17:55:1711719 scoped_refptr<X509Certificate> server_cert(
11720 ImportCertFromFile(certs_dir, "ok_cert.pem"));
dcheng48459ac22014-08-26 00:46:4111721 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get());
[email protected]2d88e7d2012-07-19 17:55:1711722
11723 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
[email protected]23e482282013-06-14 16:08:0211724 ssl1.SetNextProto(GetParam());
[email protected]2d88e7d2012-07-19 17:55:1711725 ssl1.cert = server_cert;
[email protected]bb88e1d32013-05-03 23:11:0711726 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
11727 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11728 data1.get());
[email protected]2d88e7d2012-07-19 17:55:1711729
11730 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
[email protected]23e482282013-06-14 16:08:0211731 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711732 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11733 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11734 data2.get());
[email protected]2d88e7d2012-07-19 17:55:1711735
[email protected]bb88e1d32013-05-03 23:11:0711736 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11737 session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr);
11738 session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr);
[email protected]2d88e7d2012-07-19 17:55:1711739
11740 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711741 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]2d88e7d2012-07-19 17:55:1711742
11743 // Start the first transaction to set up the SpdySession
11744 HttpRequestInfo request1;
11745 request1.method = "GET";
11746 request1.url = GURL(url1);
[email protected]2d88e7d2012-07-19 17:55:1711747 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011748 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]2d88e7d2012-07-19 17:55:1711749 TestCompletionCallback callback1;
11750 ASSERT_EQ(ERR_IO_PENDING,
11751 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
11752 data1->RunFor(3);
11753
11754 ASSERT_TRUE(callback1.have_result());
11755 EXPECT_EQ(OK, callback1.WaitForResult());
11756 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11757
11758 // Now, start the HTTP request
11759 HttpRequestInfo request2;
11760 request2.method = "GET";
11761 request2.url = GURL(url2);
[email protected]2d88e7d2012-07-19 17:55:1711762 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011763 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]2d88e7d2012-07-19 17:55:1711764 TestCompletionCallback callback2;
11765 EXPECT_EQ(ERR_IO_PENDING,
11766 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411767 base::MessageLoop::current()->RunUntilIdle();
[email protected]2d88e7d2012-07-19 17:55:1711768 data2->RunFor(3);
11769
11770 ASSERT_TRUE(callback2.have_result());
11771 EXPECT_EQ(OK, callback2.WaitForResult());
11772 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11773}
11774
[email protected]85f97342013-04-17 06:12:2411775// Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED
11776// error) in SPDY session, removes the socket from pool and closes the SPDY
11777// session. Verify that new url's from the same HttpNetworkSession (and a new
11778// SpdySession) do work. http://crbug.com/224701
[email protected]23e482282013-06-14 16:08:0211779TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) {
[email protected]85f97342013-04-17 06:12:2411780 const std::string https_url = "https://www.google.com/";
11781
11782 MockRead reads1[] = {
11783 MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0)
11784 };
11785
11786 scoped_ptr<DeterministicSocketData> data1(
11787 new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0));
11788 data1->SetStop(1);
11789
[email protected]cdf8f7e72013-05-23 10:56:4611790 scoped_ptr<SpdyFrame> req2(
11791 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM));
[email protected]85f97342013-04-17 06:12:2411792 MockWrite writes2[] = {
11793 CreateMockWrite(*req2, 0),
11794 };
11795
[email protected]23e482282013-06-14 16:08:0211796 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11797 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]85f97342013-04-17 06:12:2411798 MockRead reads2[] = {
11799 CreateMockRead(*resp2, 1),
11800 CreateMockRead(*body2, 2),
11801 MockRead(ASYNC, OK, 3) // EOF
11802 };
11803
11804 scoped_ptr<DeterministicSocketData> data2(
11805 new DeterministicSocketData(reads2, arraysize(reads2),
11806 writes2, arraysize(writes2)));
11807
[email protected]85f97342013-04-17 06:12:2411808 SSLSocketDataProvider ssl1(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211809 ssl1.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711810 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
11811 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11812 data1.get());
[email protected]85f97342013-04-17 06:12:2411813
11814 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211815 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711816 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11817 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11818 data2.get());
[email protected]85f97342013-04-17 06:12:2411819
11820 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711821 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]85f97342013-04-17 06:12:2411822
11823 // Start the first transaction to set up the SpdySession and verify that
11824 // connection was closed.
11825 HttpRequestInfo request1;
11826 request1.method = "GET";
11827 request1.url = GURL(https_url);
11828 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011829 HttpNetworkTransaction trans1(MEDIUM, session.get());
[email protected]85f97342013-04-17 06:12:2411830 TestCompletionCallback callback1;
11831 EXPECT_EQ(ERR_IO_PENDING,
11832 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411833 base::MessageLoop::current()->RunUntilIdle();
[email protected]85f97342013-04-17 06:12:2411834 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult());
11835
11836 // Now, start the second request and make sure it succeeds.
11837 HttpRequestInfo request2;
11838 request2.method = "GET";
11839 request2.url = GURL(https_url);
11840 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011841 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]85f97342013-04-17 06:12:2411842 TestCompletionCallback callback2;
11843 EXPECT_EQ(ERR_IO_PENDING,
11844 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411845 base::MessageLoop::current()->RunUntilIdle();
[email protected]85f97342013-04-17 06:12:2411846 data2->RunFor(3);
11847
11848 ASSERT_TRUE(callback2.have_result());
11849 EXPECT_EQ(OK, callback2.WaitForResult());
11850 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11851}
11852
[email protected]23e482282013-06-14 16:08:0211853TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) {
[email protected]d7599122014-05-24 03:37:2311854 session_deps_.next_protos = SpdyNextProtos();
[email protected]483fa202013-05-14 01:07:0311855 ClientSocketPoolManager::set_max_sockets_per_group(
11856 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
11857 ClientSocketPoolManager::set_max_sockets_per_pool(
11858 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
11859
11860 // Use two different hosts with different IPs so they don't get pooled.
11861 session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1");
11862 session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2");
11863 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11864
11865 SSLSocketDataProvider ssl1(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211866 ssl1.SetNextProto(GetParam());
[email protected]483fa202013-05-14 01:07:0311867 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211868 ssl2.SetNextProto(GetParam());
[email protected]483fa202013-05-14 01:07:0311869 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1);
11870 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
11871
[email protected]cdf8f7e72013-05-23 10:56:4611872 scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet(
[email protected]483fa202013-05-14 01:07:0311873 "https://www.a.com", false, 1, DEFAULT_PRIORITY));
11874 MockWrite spdy1_writes[] = {
11875 CreateMockWrite(*host1_req, 1),
11876 };
[email protected]23e482282013-06-14 16:08:0211877 scoped_ptr<SpdyFrame> host1_resp(
11878 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11879 scoped_ptr<SpdyFrame> host1_resp_body(
11880 spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]483fa202013-05-14 01:07:0311881 MockRead spdy1_reads[] = {
11882 CreateMockRead(*host1_resp, 2),
11883 CreateMockRead(*host1_resp_body, 3),
11884 MockRead(ASYNC, ERR_IO_PENDING, 4),
11885 };
11886
11887 scoped_ptr<OrderedSocketData> spdy1_data(
11888 new OrderedSocketData(
11889 spdy1_reads, arraysize(spdy1_reads),
11890 spdy1_writes, arraysize(spdy1_writes)));
11891 session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get());
11892
[email protected]cdf8f7e72013-05-23 10:56:4611893 scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet(
[email protected]483fa202013-05-14 01:07:0311894 "https://www.b.com", false, 1, DEFAULT_PRIORITY));
11895 MockWrite spdy2_writes[] = {
11896 CreateMockWrite(*host2_req, 1),
11897 };
[email protected]23e482282013-06-14 16:08:0211898 scoped_ptr<SpdyFrame> host2_resp(
11899 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11900 scoped_ptr<SpdyFrame> host2_resp_body(
11901 spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]483fa202013-05-14 01:07:0311902 MockRead spdy2_reads[] = {
11903 CreateMockRead(*host2_resp, 2),
11904 CreateMockRead(*host2_resp_body, 3),
11905 MockRead(ASYNC, ERR_IO_PENDING, 4),
11906 };
11907
11908 scoped_ptr<OrderedSocketData> spdy2_data(
11909 new OrderedSocketData(
11910 spdy2_reads, arraysize(spdy2_reads),
11911 spdy2_writes, arraysize(spdy2_writes)));
11912 session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get());
11913
11914 MockWrite http_write[] = {
11915 MockWrite("GET / HTTP/1.1\r\n"
11916 "Host: www.a.com\r\n"
11917 "Connection: keep-alive\r\n\r\n"),
11918 };
11919
11920 MockRead http_read[] = {
11921 MockRead("HTTP/1.1 200 OK\r\n"),
11922 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
11923 MockRead("Content-Length: 6\r\n\r\n"),
11924 MockRead("hello!"),
11925 };
11926 StaticSocketDataProvider http_data(http_read, arraysize(http_read),
11927 http_write, arraysize(http_write));
11928 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
11929
11930 HostPortPair host_port_pair_a("www.a.com", 443);
[email protected]e6d017652013-05-17 18:01:4011931 SpdySessionKey spdy_session_key_a(
[email protected]314b03992014-04-01 01:28:5311932 host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311933 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611934 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311935
11936 TestCompletionCallback callback;
11937 HttpRequestInfo request1;
11938 request1.method = "GET";
11939 request1.url = GURL("https://www.a.com/");
11940 request1.load_flags = 0;
11941 scoped_ptr<HttpNetworkTransaction> trans(
[email protected]90499482013-06-01 00:39:5011942 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0311943
11944 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
11945 EXPECT_EQ(ERR_IO_PENDING, rv);
11946 EXPECT_EQ(OK, callback.WaitForResult());
11947
11948 const HttpResponseInfo* response = trans->GetResponseInfo();
11949 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011950 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0311951 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11952 EXPECT_TRUE(response->was_fetched_via_spdy);
11953 EXPECT_TRUE(response->was_npn_negotiated);
11954
11955 std::string response_data;
11956 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
11957 EXPECT_EQ("hello!", response_data);
11958 trans.reset();
11959 EXPECT_TRUE(
[email protected]41d64e82013-07-03 22:44:2611960 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311961
11962 HostPortPair host_port_pair_b("www.b.com", 443);
[email protected]e6d017652013-05-17 18:01:4011963 SpdySessionKey spdy_session_key_b(
[email protected]314b03992014-04-01 01:28:5311964 host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311965 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611966 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0311967 HttpRequestInfo request2;
11968 request2.method = "GET";
11969 request2.url = GURL("https://www.b.com/");
11970 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011971 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0311972
11973 rv = trans->Start(&request2, callback.callback(), BoundNetLog());
11974 EXPECT_EQ(ERR_IO_PENDING, rv);
11975 EXPECT_EQ(OK, callback.WaitForResult());
11976
11977 response = trans->GetResponseInfo();
11978 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011979 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0311980 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11981 EXPECT_TRUE(response->was_fetched_via_spdy);
11982 EXPECT_TRUE(response->was_npn_negotiated);
11983 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
11984 EXPECT_EQ("hello!", response_data);
11985 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611986 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311987 EXPECT_TRUE(
[email protected]41d64e82013-07-03 22:44:2611988 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0311989
11990 HostPortPair host_port_pair_a1("www.a.com", 80);
[email protected]e6d017652013-05-17 18:01:4011991 SpdySessionKey spdy_session_key_a1(
[email protected]314b03992014-04-01 01:28:5311992 host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311993 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611994 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1));
[email protected]483fa202013-05-14 01:07:0311995 HttpRequestInfo request3;
11996 request3.method = "GET";
11997 request3.url = GURL("http://www.a.com/");
11998 request3.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011999 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0312000
12001 rv = trans->Start(&request3, callback.callback(), BoundNetLog());
12002 EXPECT_EQ(ERR_IO_PENDING, rv);
12003 EXPECT_EQ(OK, callback.WaitForResult());
12004
12005 response = trans->GetResponseInfo();
12006 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5012007 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0312008 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
12009 EXPECT_FALSE(response->was_fetched_via_spdy);
12010 EXPECT_FALSE(response->was_npn_negotiated);
12011 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
12012 EXPECT_EQ("hello!", response_data);
12013 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2612014 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0312015 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2612016 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0312017}
12018
[email protected]79e1fd62013-06-20 06:50:0412019TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) {
12020 HttpRequestInfo request;
12021 request.method = "GET";
12022 request.url = GURL("http://www.google.com/");
12023 request.load_flags = 0;
12024
[email protected]3fe8d2f82013-10-17 08:56:0712025 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412026 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112027 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412028
12029 MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED);
12030 StaticSocketDataProvider data;
12031 data.set_connect_data(mock_connect);
12032 session_deps_.socket_factory->AddSocketDataProvider(&data);
12033
12034 TestCompletionCallback callback;
12035
12036 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12037 EXPECT_EQ(ERR_IO_PENDING, rv);
12038
12039 rv = callback.WaitForResult();
12040 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
12041
12042 EXPECT_EQ(NULL, trans->GetResponseInfo());
12043
12044 // We don't care whether this succeeds or fails, but it shouldn't crash.
12045 HttpRequestHeaders request_headers;
12046 trans->GetFullRequestHeaders(&request_headers);
12047}
12048
12049TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) {
12050 HttpRequestInfo request;
12051 request.method = "GET";
12052 request.url = GURL("http://www.google.com/");
12053 request.load_flags = 0;
12054
[email protected]3fe8d2f82013-10-17 08:56:0712055 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412056 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112057 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412058
12059 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
12060 StaticSocketDataProvider data;
12061 data.set_connect_data(mock_connect);
12062 session_deps_.socket_factory->AddSocketDataProvider(&data);
12063
12064 TestCompletionCallback callback;
12065
12066 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12067 EXPECT_EQ(ERR_IO_PENDING, rv);
12068
12069 rv = callback.WaitForResult();
12070 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
12071
12072 EXPECT_EQ(NULL, trans->GetResponseInfo());
12073
12074 // We don't care whether this succeeds or fails, but it shouldn't crash.
12075 HttpRequestHeaders request_headers;
12076 trans->GetFullRequestHeaders(&request_headers);
12077}
12078
12079TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) {
12080 HttpRequestInfo request;
12081 request.method = "GET";
12082 request.url = GURL("http://www.google.com/");
12083 request.load_flags = 0;
12084
[email protected]3fe8d2f82013-10-17 08:56:0712085 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412086 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112087 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412088
12089 MockWrite data_writes[] = {
12090 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12091 };
12092 MockRead data_reads[] = {
12093 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
12094 };
12095
12096 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12097 data_writes, arraysize(data_writes));
12098 session_deps_.socket_factory->AddSocketDataProvider(&data);
12099
12100 TestCompletionCallback callback;
12101
12102 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12103 EXPECT_EQ(ERR_IO_PENDING, rv);
12104
12105 rv = callback.WaitForResult();
12106 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12107
12108 EXPECT_EQ(NULL, trans->GetResponseInfo());
12109
12110 HttpRequestHeaders request_headers;
12111 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12112 EXPECT_TRUE(request_headers.HasHeader("Host"));
12113}
12114
12115TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) {
12116 HttpRequestInfo request;
12117 request.method = "GET";
12118 request.url = GURL("http://www.google.com/");
12119 request.load_flags = 0;
12120
[email protected]3fe8d2f82013-10-17 08:56:0712121 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412122 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112123 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412124
12125 MockWrite data_writes[] = {
12126 MockWrite(ASYNC, ERR_CONNECTION_RESET),
12127 };
12128 MockRead data_reads[] = {
12129 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
12130 };
12131
12132 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12133 data_writes, arraysize(data_writes));
12134 session_deps_.socket_factory->AddSocketDataProvider(&data);
12135
12136 TestCompletionCallback callback;
12137
12138 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12139 EXPECT_EQ(ERR_IO_PENDING, rv);
12140
12141 rv = callback.WaitForResult();
12142 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12143
12144 EXPECT_EQ(NULL, trans->GetResponseInfo());
12145
12146 HttpRequestHeaders request_headers;
12147 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12148 EXPECT_TRUE(request_headers.HasHeader("Host"));
12149}
12150
12151TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) {
12152 HttpRequestInfo request;
12153 request.method = "GET";
12154 request.url = GURL("http://www.google.com/");
12155 request.load_flags = 0;
12156
[email protected]3fe8d2f82013-10-17 08:56:0712157 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412158 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112159 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412160
12161 MockWrite data_writes[] = {
12162 MockWrite("GET / HTTP/1.1\r\n"
12163 "Host: www.google.com\r\n"
12164 "Connection: keep-alive\r\n\r\n"),
12165 };
12166 MockRead data_reads[] = {
12167 MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET),
12168 };
12169
12170 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12171 data_writes, arraysize(data_writes));
12172 session_deps_.socket_factory->AddSocketDataProvider(&data);
12173
12174 TestCompletionCallback callback;
12175
12176 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12177 EXPECT_EQ(ERR_IO_PENDING, rv);
12178
12179 rv = callback.WaitForResult();
12180 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12181
12182 EXPECT_EQ(NULL, trans->GetResponseInfo());
12183
12184 HttpRequestHeaders request_headers;
12185 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12186 EXPECT_TRUE(request_headers.HasHeader("Host"));
12187}
12188
12189TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) {
12190 HttpRequestInfo request;
12191 request.method = "GET";
12192 request.url = GURL("http://www.google.com/");
12193 request.load_flags = 0;
12194
[email protected]3fe8d2f82013-10-17 08:56:0712195 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412196 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112197 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412198
12199 MockWrite data_writes[] = {
12200 MockWrite("GET / HTTP/1.1\r\n"
12201 "Host: www.google.com\r\n"
12202 "Connection: keep-alive\r\n\r\n"),
12203 };
12204 MockRead data_reads[] = {
12205 MockRead(ASYNC, ERR_CONNECTION_RESET),
12206 };
12207
12208 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12209 data_writes, arraysize(data_writes));
12210 session_deps_.socket_factory->AddSocketDataProvider(&data);
12211
12212 TestCompletionCallback callback;
12213
12214 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12215 EXPECT_EQ(ERR_IO_PENDING, rv);
12216
12217 rv = callback.WaitForResult();
12218 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12219
12220 EXPECT_EQ(NULL, trans->GetResponseInfo());
12221
12222 HttpRequestHeaders request_headers;
12223 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12224 EXPECT_TRUE(request_headers.HasHeader("Host"));
12225}
12226
12227TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) {
12228 HttpRequestInfo request;
12229 request.method = "GET";
12230 request.url = GURL("http://www.google.com/");
12231 request.load_flags = 0;
12232 request.extra_headers.SetHeader("X-Foo", "bar");
12233
[email protected]3fe8d2f82013-10-17 08:56:0712234 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412235 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112236 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412237
12238 MockWrite data_writes[] = {
12239 MockWrite("GET / HTTP/1.1\r\n"
12240 "Host: www.google.com\r\n"
12241 "Connection: keep-alive\r\n"
12242 "X-Foo: bar\r\n\r\n"),
12243 };
12244 MockRead data_reads[] = {
12245 MockRead("HTTP/1.1 200 OK\r\n"
12246 "Content-Length: 5\r\n\r\n"
12247 "hello"),
12248 MockRead(ASYNC, ERR_UNEXPECTED),
12249 };
12250
12251 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12252 data_writes, arraysize(data_writes));
12253 session_deps_.socket_factory->AddSocketDataProvider(&data);
12254
12255 TestCompletionCallback callback;
12256
12257 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12258 EXPECT_EQ(ERR_IO_PENDING, rv);
12259
12260 rv = callback.WaitForResult();
12261 EXPECT_EQ(OK, rv);
12262
12263 HttpRequestHeaders request_headers;
12264 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12265 std::string foo;
12266 EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo));
12267 EXPECT_EQ("bar", foo);
12268}
12269
[email protected]bf828982013-08-14 18:01:4712270namespace {
12271
yhiranoa7e05bb2014-11-06 05:40:3912272// Fake HttpStream that simply records calls to SetPriority().
12273class FakeStream : public HttpStream,
[email protected]e86839fd2013-08-14 18:29:0312274 public base::SupportsWeakPtr<FakeStream> {
12275 public:
12276 explicit FakeStream(RequestPriority priority) : priority_(priority) {}
dchengb03027d2014-10-21 12:00:2012277 ~FakeStream() override {}
[email protected]e86839fd2013-08-14 18:29:0312278
12279 RequestPriority priority() const { return priority_; }
12280
dchengb03027d2014-10-21 12:00:2012281 int InitializeStream(const HttpRequestInfo* request_info,
12282 RequestPriority priority,
12283 const BoundNetLog& net_log,
12284 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312285 return ERR_IO_PENDING;
12286 }
12287
dchengb03027d2014-10-21 12:00:2012288 int SendRequest(const HttpRequestHeaders& request_headers,
12289 HttpResponseInfo* response,
12290 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312291 ADD_FAILURE();
12292 return ERR_UNEXPECTED;
12293 }
12294
dchengb03027d2014-10-21 12:00:2012295 int ReadResponseHeaders(const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312296 ADD_FAILURE();
12297 return ERR_UNEXPECTED;
12298 }
12299
dchengb03027d2014-10-21 12:00:2012300 int ReadResponseBody(IOBuffer* buf,
12301 int buf_len,
12302 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312303 ADD_FAILURE();
12304 return ERR_UNEXPECTED;
12305 }
12306
dchengb03027d2014-10-21 12:00:2012307 void Close(bool not_reusable) override {}
[email protected]e86839fd2013-08-14 18:29:0312308
dchengb03027d2014-10-21 12:00:2012309 bool IsResponseBodyComplete() const override {
[email protected]e86839fd2013-08-14 18:29:0312310 ADD_FAILURE();
12311 return false;
12312 }
12313
dchengb03027d2014-10-21 12:00:2012314 bool CanFindEndOfResponse() const override { return false; }
[email protected]e86839fd2013-08-14 18:29:0312315
dchengb03027d2014-10-21 12:00:2012316 bool IsConnectionReused() const override {
[email protected]e86839fd2013-08-14 18:29:0312317 ADD_FAILURE();
12318 return false;
12319 }
12320
dchengb03027d2014-10-21 12:00:2012321 void SetConnectionReused() override { ADD_FAILURE(); }
[email protected]e86839fd2013-08-14 18:29:0312322
dchengb03027d2014-10-21 12:00:2012323 bool IsConnectionReusable() const override {
[email protected]e86839fd2013-08-14 18:29:0312324 ADD_FAILURE();
12325 return false;
12326 }
12327
dchengb03027d2014-10-21 12:00:2012328 int64 GetTotalReceivedBytes() const override {
[email protected]bc92bc972013-12-13 08:32:5912329 ADD_FAILURE();
12330 return 0;
12331 }
12332
dchengb03027d2014-10-21 12:00:2012333 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override {
[email protected]e86839fd2013-08-14 18:29:0312334 ADD_FAILURE();
12335 return false;
12336 }
12337
dchengb03027d2014-10-21 12:00:2012338 void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); }
12339
12340 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {
[email protected]e86839fd2013-08-14 18:29:0312341 ADD_FAILURE();
12342 }
12343
dchengb03027d2014-10-21 12:00:2012344 bool IsSpdyHttpStream() const override {
[email protected]e86839fd2013-08-14 18:29:0312345 ADD_FAILURE();
12346 return false;
12347 }
12348
dchengb03027d2014-10-21 12:00:2012349 void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); }
[email protected]e86839fd2013-08-14 18:29:0312350
dchengb03027d2014-10-21 12:00:2012351 void SetPriority(RequestPriority priority) override { priority_ = priority; }
[email protected]e86839fd2013-08-14 18:29:0312352
yhiranoa7e05bb2014-11-06 05:40:3912353 UploadProgress GetUploadProgress() const override { return UploadProgress(); }
12354
12355 HttpStream* RenewStreamForAuth() override { return NULL; }
12356
[email protected]e86839fd2013-08-14 18:29:0312357 private:
12358 RequestPriority priority_;
12359
12360 DISALLOW_COPY_AND_ASSIGN(FakeStream);
12361};
12362
12363// Fake HttpStreamRequest that simply records calls to SetPriority()
12364// and vends FakeStreams with its current priority.
[email protected]bf828982013-08-14 18:01:4712365class FakeStreamRequest : public HttpStreamRequest,
12366 public base::SupportsWeakPtr<FakeStreamRequest> {
12367 public:
[email protected]e86839fd2013-08-14 18:29:0312368 FakeStreamRequest(RequestPriority priority,
12369 HttpStreamRequest::Delegate* delegate)
12370 : priority_(priority),
[email protected]831e4a32013-11-14 02:14:4412371 delegate_(delegate),
12372 websocket_stream_create_helper_(NULL) {}
12373
12374 FakeStreamRequest(RequestPriority priority,
12375 HttpStreamRequest::Delegate* delegate,
12376 WebSocketHandshakeStreamBase::CreateHelper* create_helper)
12377 : priority_(priority),
12378 delegate_(delegate),
12379 websocket_stream_create_helper_(create_helper) {}
[email protected]e86839fd2013-08-14 18:29:0312380
dchengb03027d2014-10-21 12:00:2012381 ~FakeStreamRequest() override {}
[email protected]bf828982013-08-14 18:01:4712382
12383 RequestPriority priority() const { return priority_; }
12384
[email protected]831e4a32013-11-14 02:14:4412385 const WebSocketHandshakeStreamBase::CreateHelper*
12386 websocket_stream_create_helper() const {
12387 return websocket_stream_create_helper_;
12388 }
12389
[email protected]e86839fd2013-08-14 18:29:0312390 // Create a new FakeStream and pass it to the request's
12391 // delegate. Returns a weak pointer to the FakeStream.
12392 base::WeakPtr<FakeStream> FinishStreamRequest() {
12393 FakeStream* fake_stream = new FakeStream(priority_);
12394 // Do this before calling OnStreamReady() as OnStreamReady() may
12395 // immediately delete |fake_stream|.
12396 base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr();
12397 delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream);
12398 return weak_stream;
12399 }
12400
dchengb03027d2014-10-21 12:00:2012401 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override {
[email protected]bf828982013-08-14 18:01:4712402 ADD_FAILURE();
12403 return ERR_UNEXPECTED;
12404 }
12405
dchengb03027d2014-10-21 12:00:2012406 LoadState GetLoadState() const override {
[email protected]bf828982013-08-14 18:01:4712407 ADD_FAILURE();
12408 return LoadState();
12409 }
12410
dchengb03027d2014-10-21 12:00:2012411 void SetPriority(RequestPriority priority) override { priority_ = priority; }
[email protected]bf828982013-08-14 18:01:4712412
dchengb03027d2014-10-21 12:00:2012413 bool was_npn_negotiated() const override { return false; }
[email protected]bf828982013-08-14 18:01:4712414
dchengb03027d2014-10-21 12:00:2012415 NextProto protocol_negotiated() const override { return kProtoUnknown; }
[email protected]bf828982013-08-14 18:01:4712416
dchengb03027d2014-10-21 12:00:2012417 bool using_spdy() const override { return false; }
[email protected]bf828982013-08-14 18:01:4712418
12419 private:
12420 RequestPriority priority_;
[email protected]e86839fd2013-08-14 18:29:0312421 HttpStreamRequest::Delegate* const delegate_;
[email protected]831e4a32013-11-14 02:14:4412422 WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_;
[email protected]bf828982013-08-14 18:01:4712423
12424 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest);
12425};
12426
12427// Fake HttpStreamFactory that vends FakeStreamRequests.
12428class FakeStreamFactory : public HttpStreamFactory {
12429 public:
12430 FakeStreamFactory() {}
dchengb03027d2014-10-21 12:00:2012431 ~FakeStreamFactory() override {}
[email protected]bf828982013-08-14 18:01:4712432
12433 // Returns a WeakPtr<> to the last HttpStreamRequest returned by
12434 // RequestStream() (which may be NULL if it was destroyed already).
12435 base::WeakPtr<FakeStreamRequest> last_stream_request() {
12436 return last_stream_request_;
12437 }
12438
dchengb03027d2014-10-21 12:00:2012439 HttpStreamRequest* RequestStream(const HttpRequestInfo& info,
12440 RequestPriority priority,
12441 const SSLConfig& server_ssl_config,
12442 const SSLConfig& proxy_ssl_config,
12443 HttpStreamRequest::Delegate* delegate,
12444 const BoundNetLog& net_log) override {
[email protected]e86839fd2013-08-14 18:29:0312445 FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate);
[email protected]bf828982013-08-14 18:01:4712446 last_stream_request_ = fake_request->AsWeakPtr();
12447 return fake_request;
12448 }
12449
dchengb03027d2014-10-21 12:00:2012450 HttpStreamRequest* RequestWebSocketHandshakeStream(
[email protected]bf828982013-08-14 18:01:4712451 const HttpRequestInfo& info,
12452 RequestPriority priority,
12453 const SSLConfig& server_ssl_config,
12454 const SSLConfig& proxy_ssl_config,
12455 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4612456 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
mostynbba063d6032014-10-09 11:01:1312457 const BoundNetLog& net_log) override {
[email protected]831e4a32013-11-14 02:14:4412458 FakeStreamRequest* fake_request =
12459 new FakeStreamRequest(priority, delegate, create_helper);
12460 last_stream_request_ = fake_request->AsWeakPtr();
12461 return fake_request;
[email protected]bf828982013-08-14 18:01:4712462 }
12463
dchengb03027d2014-10-21 12:00:2012464 void PreconnectStreams(int num_streams,
12465 const HttpRequestInfo& info,
12466 RequestPriority priority,
12467 const SSLConfig& server_ssl_config,
12468 const SSLConfig& proxy_ssl_config) override {
[email protected]bf828982013-08-14 18:01:4712469 ADD_FAILURE();
12470 }
12471
dchengb03027d2014-10-21 12:00:2012472 const HostMappingRules* GetHostMappingRules() const override {
[email protected]bf828982013-08-14 18:01:4712473 ADD_FAILURE();
12474 return NULL;
12475 }
12476
12477 private:
12478 base::WeakPtr<FakeStreamRequest> last_stream_request_;
12479
12480 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory);
12481};
12482
Adam Rice425cf122015-01-19 06:18:2412483// TODO(ricea): Maybe unify this with the one in
12484// url_request_http_job_unittest.cc ?
12485class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase {
12486 public:
12487 FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection,
12488 bool using_proxy)
12489 : state_(connection.release(), using_proxy) {}
12490
12491 // Fake implementation of HttpStreamBase methods.
12492 // This ends up being quite "real" because this object has to really send data
12493 // on the mock socket. It might be easier to use the real implementation, but
12494 // the fact that the WebSocket code is not compiled on iOS makes that
12495 // difficult.
12496 int InitializeStream(const HttpRequestInfo* request_info,
12497 RequestPriority priority,
12498 const BoundNetLog& net_log,
12499 const CompletionCallback& callback) override {
12500 state_.Initialize(request_info, priority, net_log, callback);
12501 return OK;
12502 }
12503
12504 int SendRequest(const HttpRequestHeaders& request_headers,
12505 HttpResponseInfo* response,
12506 const CompletionCallback& callback) override {
12507 return parser()->SendRequest(state_.GenerateRequestLine(), request_headers,
12508 response, callback);
12509 }
12510
12511 int ReadResponseHeaders(const CompletionCallback& callback) override {
12512 return parser()->ReadResponseHeaders(callback);
12513 }
12514
12515 int ReadResponseBody(IOBuffer* buf,
12516 int buf_len,
12517 const CompletionCallback& callback) override {
12518 NOTREACHED();
12519 return ERR_IO_PENDING;
12520 }
12521
12522 void Close(bool not_reusable) override {
12523 if (parser())
12524 parser()->Close(true);
12525 }
12526
12527 bool IsResponseBodyComplete() const override {
12528 NOTREACHED();
12529 return false;
12530 }
12531
12532 bool CanFindEndOfResponse() const override {
12533 return parser()->CanFindEndOfResponse();
12534 }
12535
12536 bool IsConnectionReused() const override {
12537 NOTREACHED();
12538 return false;
12539 }
12540 void SetConnectionReused() override { NOTREACHED(); }
12541
12542 bool IsConnectionReusable() const override {
12543 NOTREACHED();
12544 return false;
12545 }
12546
12547 int64 GetTotalReceivedBytes() const override {
12548 NOTREACHED();
12549 return 0;
12550 }
12551
12552 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override {
12553 NOTREACHED();
12554 return false;
12555 }
12556
Adam Ricecb76ac62015-02-20 05:33:2512557 void GetSSLInfo(SSLInfo* ssl_info) override {}
Adam Rice425cf122015-01-19 06:18:2412558
12559 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {
12560 NOTREACHED();
12561 }
12562
12563 bool IsSpdyHttpStream() const override {
12564 NOTREACHED();
12565 return false;
12566 }
12567
12568 void Drain(HttpNetworkSession* session) override { NOTREACHED(); }
12569
12570 void SetPriority(RequestPriority priority) override { NOTREACHED(); }
12571
12572 UploadProgress GetUploadProgress() const override {
12573 NOTREACHED();
12574 return UploadProgress();
12575 }
12576
12577 HttpStream* RenewStreamForAuth() override {
12578 NOTREACHED();
12579 return nullptr;
12580 }
12581
12582 // Fake implementation of WebSocketHandshakeStreamBase method(s)
12583 scoped_ptr<WebSocketStream> Upgrade() override {
12584 NOTREACHED();
12585 return scoped_ptr<WebSocketStream>();
12586 }
12587
12588 private:
12589 HttpStreamParser* parser() const { return state_.parser(); }
12590 HttpBasicState state_;
12591
12592 DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream);
12593};
12594
[email protected]831e4a32013-11-14 02:14:4412595// TODO(yhirano): Split this class out into a net/websockets file, if it is
12596// worth doing.
12597class FakeWebSocketStreamCreateHelper :
12598 public WebSocketHandshakeStreamBase::CreateHelper {
12599 public:
dchengb03027d2014-10-21 12:00:2012600 WebSocketHandshakeStreamBase* CreateBasicStream(
[email protected]7e841a52013-11-22 09:04:2112601 scoped_ptr<ClientSocketHandle> connection,
mostynbba063d6032014-10-09 11:01:1312602 bool using_proxy) override {
Adam Rice425cf122015-01-19 06:18:2412603 return new FakeWebSocketBasicHandshakeStream(connection.Pass(),
12604 using_proxy);
[email protected]831e4a32013-11-14 02:14:4412605 }
12606
dchengb03027d2014-10-21 12:00:2012607 WebSocketHandshakeStreamBase* CreateSpdyStream(
[email protected]831e4a32013-11-14 02:14:4412608 const base::WeakPtr<SpdySession>& session,
mostynbba063d6032014-10-09 11:01:1312609 bool use_relative_url) override {
[email protected]831e4a32013-11-14 02:14:4412610 NOTREACHED();
12611 return NULL;
12612 };
12613
dchengb03027d2014-10-21 12:00:2012614 ~FakeWebSocketStreamCreateHelper() override {}
[email protected]831e4a32013-11-14 02:14:4412615
12616 virtual scoped_ptr<WebSocketStream> Upgrade() {
12617 NOTREACHED();
12618 return scoped_ptr<WebSocketStream>();
12619 }
12620};
12621
[email protected]bf828982013-08-14 18:01:4712622} // namespace
12623
12624// Make sure that HttpNetworkTransaction passes on its priority to its
12625// stream request on start.
12626TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) {
12627 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12628 HttpNetworkSessionPeer peer(session);
12629 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412630 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]bf828982013-08-14 18:01:4712631
dcheng48459ac22014-08-26 00:46:4112632 HttpNetworkTransaction trans(LOW, session.get());
[email protected]bf828982013-08-14 18:01:4712633
12634 ASSERT_TRUE(fake_factory->last_stream_request() == NULL);
12635
12636 HttpRequestInfo request;
12637 TestCompletionCallback callback;
12638 EXPECT_EQ(ERR_IO_PENDING,
12639 trans.Start(&request, callback.callback(), BoundNetLog()));
12640
12641 base::WeakPtr<FakeStreamRequest> fake_request =
12642 fake_factory->last_stream_request();
12643 ASSERT_TRUE(fake_request != NULL);
12644 EXPECT_EQ(LOW, fake_request->priority());
12645}
12646
12647// Make sure that HttpNetworkTransaction passes on its priority
12648// updates to its stream request.
12649TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) {
12650 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12651 HttpNetworkSessionPeer peer(session);
12652 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412653 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]bf828982013-08-14 18:01:4712654
dcheng48459ac22014-08-26 00:46:4112655 HttpNetworkTransaction trans(LOW, session.get());
[email protected]bf828982013-08-14 18:01:4712656
12657 HttpRequestInfo request;
12658 TestCompletionCallback callback;
12659 EXPECT_EQ(ERR_IO_PENDING,
12660 trans.Start(&request, callback.callback(), BoundNetLog()));
12661
12662 base::WeakPtr<FakeStreamRequest> fake_request =
12663 fake_factory->last_stream_request();
12664 ASSERT_TRUE(fake_request != NULL);
12665 EXPECT_EQ(LOW, fake_request->priority());
12666
12667 trans.SetPriority(LOWEST);
12668 ASSERT_TRUE(fake_request != NULL);
12669 EXPECT_EQ(LOWEST, fake_request->priority());
12670}
12671
[email protected]e86839fd2013-08-14 18:29:0312672// Make sure that HttpNetworkTransaction passes on its priority
12673// updates to its stream.
12674TEST_P(HttpNetworkTransactionTest, SetStreamPriority) {
12675 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12676 HttpNetworkSessionPeer peer(session);
12677 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412678 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]e86839fd2013-08-14 18:29:0312679
dcheng48459ac22014-08-26 00:46:4112680 HttpNetworkTransaction trans(LOW, session.get());
[email protected]e86839fd2013-08-14 18:29:0312681
12682 HttpRequestInfo request;
12683 TestCompletionCallback callback;
12684 EXPECT_EQ(ERR_IO_PENDING,
12685 trans.Start(&request, callback.callback(), BoundNetLog()));
12686
12687 base::WeakPtr<FakeStreamRequest> fake_request =
12688 fake_factory->last_stream_request();
12689 ASSERT_TRUE(fake_request != NULL);
12690 base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest();
12691 ASSERT_TRUE(fake_stream != NULL);
12692 EXPECT_EQ(LOW, fake_stream->priority());
12693
12694 trans.SetPriority(LOWEST);
12695 EXPECT_EQ(LOWEST, fake_stream->priority());
12696}
12697
[email protected]831e4a32013-11-14 02:14:4412698TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) {
12699 // The same logic needs to be tested for both ws: and wss: schemes, but this
12700 // test is already parameterised on NextProto, so it uses a loop to verify
12701 // that the different schemes work.
12702 std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"};
12703 for (size_t i = 0; i < arraysize(test_cases); ++i) {
12704 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12705 HttpNetworkSessionPeer peer(session);
12706 FakeStreamFactory* fake_factory = new FakeStreamFactory();
12707 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
[email protected]0191b51c2013-11-18 10:55:2312708 peer.SetHttpStreamFactoryForWebSocket(
[email protected]831e4a32013-11-14 02:14:4412709 scoped_ptr<HttpStreamFactory>(fake_factory));
12710
dcheng48459ac22014-08-26 00:46:4112711 HttpNetworkTransaction trans(LOW, session.get());
[email protected]831e4a32013-11-14 02:14:4412712 trans.SetWebSocketHandshakeStreamCreateHelper(
12713 &websocket_stream_create_helper);
12714
12715 HttpRequestInfo request;
12716 TestCompletionCallback callback;
12717 request.method = "GET";
12718 request.url = GURL(test_cases[i]);
12719
12720 EXPECT_EQ(ERR_IO_PENDING,
12721 trans.Start(&request, callback.callback(), BoundNetLog()));
12722
12723 base::WeakPtr<FakeStreamRequest> fake_request =
12724 fake_factory->last_stream_request();
12725 ASSERT_TRUE(fake_request != NULL);
12726 EXPECT_EQ(&websocket_stream_create_helper,
12727 fake_request->websocket_stream_create_helper());
12728 }
12729}
12730
[email protected]043b68c82013-08-22 23:41:5212731// Tests that when a used socket is returned to the SSL socket pool, it's closed
12732// if the transport socket pool is stalled on the global socket limit.
12733TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) {
12734 ClientSocketPoolManager::set_max_sockets_per_group(
12735 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12736 ClientSocketPoolManager::set_max_sockets_per_pool(
12737 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12738
12739 // Set up SSL request.
12740
12741 HttpRequestInfo ssl_request;
12742 ssl_request.method = "GET";
12743 ssl_request.url = GURL("https://www.google.com/");
12744
12745 MockWrite ssl_writes[] = {
12746 MockWrite("GET / HTTP/1.1\r\n"
12747 "Host: www.google.com\r\n"
12748 "Connection: keep-alive\r\n\r\n"),
12749 };
12750 MockRead ssl_reads[] = {
12751 MockRead("HTTP/1.1 200 OK\r\n"),
12752 MockRead("Content-Length: 11\r\n\r\n"),
12753 MockRead("hello world"),
12754 MockRead(SYNCHRONOUS, OK),
12755 };
12756 StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads),
12757 ssl_writes, arraysize(ssl_writes));
12758 session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
12759
12760 SSLSocketDataProvider ssl(ASYNC, OK);
12761 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
12762
12763 // Set up HTTP request.
12764
12765 HttpRequestInfo http_request;
12766 http_request.method = "GET";
12767 http_request.url = GURL("http://www.google.com/");
12768
12769 MockWrite http_writes[] = {
12770 MockWrite("GET / HTTP/1.1\r\n"
12771 "Host: www.google.com\r\n"
12772 "Connection: keep-alive\r\n\r\n"),
12773 };
12774 MockRead http_reads[] = {
12775 MockRead("HTTP/1.1 200 OK\r\n"),
12776 MockRead("Content-Length: 7\r\n\r\n"),
12777 MockRead("falafel"),
12778 MockRead(SYNCHRONOUS, OK),
12779 };
12780 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
12781 http_writes, arraysize(http_writes));
12782 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
12783
12784 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12785
12786 // Start the SSL request.
12787 TestCompletionCallback ssl_callback;
12788 scoped_ptr<HttpTransaction> ssl_trans(
12789 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12790 ASSERT_EQ(ERR_IO_PENDING,
12791 ssl_trans->Start(&ssl_request, ssl_callback.callback(),
12792 BoundNetLog()));
12793
12794 // Start the HTTP request. Pool should stall.
12795 TestCompletionCallback http_callback;
12796 scoped_ptr<HttpTransaction> http_trans(
12797 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12798 ASSERT_EQ(ERR_IO_PENDING,
12799 http_trans->Start(&http_request, http_callback.callback(),
12800 BoundNetLog()));
dcheng48459ac22014-08-26 00:46:4112801 EXPECT_TRUE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212802
12803 // Wait for response from SSL request.
12804 ASSERT_EQ(OK, ssl_callback.WaitForResult());
12805 std::string response_data;
12806 ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data));
12807 EXPECT_EQ("hello world", response_data);
12808
12809 // The SSL socket should automatically be closed, so the HTTP request can
12810 // start.
dcheng48459ac22014-08-26 00:46:4112811 EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get()));
12812 ASSERT_FALSE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212813
12814 // The HTTP request can now complete.
12815 ASSERT_EQ(OK, http_callback.WaitForResult());
12816 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
12817 EXPECT_EQ("falafel", response_data);
12818
dcheng48459ac22014-08-26 00:46:4112819 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212820}
12821
12822// Tests that when a SSL connection is established but there's no corresponding
12823// request that needs it, the new socket is closed if the transport socket pool
12824// is stalled on the global socket limit.
12825TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) {
12826 ClientSocketPoolManager::set_max_sockets_per_group(
12827 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12828 ClientSocketPoolManager::set_max_sockets_per_pool(
12829 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12830
12831 // Set up an ssl request.
12832
12833 HttpRequestInfo ssl_request;
12834 ssl_request.method = "GET";
12835 ssl_request.url = GURL("https://www.foopy.com/");
12836
12837 // No data will be sent on the SSL socket.
12838 StaticSocketDataProvider ssl_data;
12839 session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
12840
12841 SSLSocketDataProvider ssl(ASYNC, OK);
12842 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
12843
12844 // Set up HTTP request.
12845
12846 HttpRequestInfo http_request;
12847 http_request.method = "GET";
12848 http_request.url = GURL("http://www.google.com/");
12849
12850 MockWrite http_writes[] = {
12851 MockWrite("GET / HTTP/1.1\r\n"
12852 "Host: www.google.com\r\n"
12853 "Connection: keep-alive\r\n\r\n"),
12854 };
12855 MockRead http_reads[] = {
12856 MockRead("HTTP/1.1 200 OK\r\n"),
12857 MockRead("Content-Length: 7\r\n\r\n"),
12858 MockRead("falafel"),
12859 MockRead(SYNCHRONOUS, OK),
12860 };
12861 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
12862 http_writes, arraysize(http_writes));
12863 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
12864
12865 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12866
12867 // Preconnect an SSL socket. A preconnect is needed because connect jobs are
12868 // cancelled when a normal transaction is cancelled.
12869 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
12870 net::SSLConfig ssl_config;
12871 session->ssl_config_service()->GetSSLConfig(&ssl_config);
12872 http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY,
12873 ssl_config, ssl_config);
dcheng48459ac22014-08-26 00:46:4112874 EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212875
12876 // Start the HTTP request. Pool should stall.
12877 TestCompletionCallback http_callback;
12878 scoped_ptr<HttpTransaction> http_trans(
12879 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12880 ASSERT_EQ(ERR_IO_PENDING,
12881 http_trans->Start(&http_request, http_callback.callback(),
12882 BoundNetLog()));
dcheng48459ac22014-08-26 00:46:4112883 EXPECT_TRUE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212884
12885 // The SSL connection will automatically be closed once the connection is
12886 // established, to let the HTTP request start.
12887 ASSERT_EQ(OK, http_callback.WaitForResult());
12888 std::string response_data;
12889 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
12890 EXPECT_EQ("falafel", response_data);
12891
dcheng48459ac22014-08-26 00:46:4112892 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212893}
12894
[email protected]02d74a02014-04-23 18:10:5412895TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) {
12896 ScopedVector<UploadElementReader> element_readers;
12897 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0712898 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5412899
12900 HttpRequestInfo request;
12901 request.method = "POST";
12902 request.url = GURL("http://www.foo.com/");
12903 request.upload_data_stream = &upload_data_stream;
12904 request.load_flags = 0;
12905
12906 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12907 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112908 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412909 // Send headers successfully, but get an error while sending the body.
12910 MockWrite data_writes[] = {
12911 MockWrite("POST / HTTP/1.1\r\n"
12912 "Host: www.foo.com\r\n"
12913 "Connection: keep-alive\r\n"
12914 "Content-Length: 3\r\n\r\n"),
12915 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12916 };
12917
12918 MockRead data_reads[] = {
12919 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
12920 MockRead("hello world"),
12921 MockRead(SYNCHRONOUS, OK),
12922 };
12923 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12924 arraysize(data_writes));
12925 session_deps_.socket_factory->AddSocketDataProvider(&data);
12926
12927 TestCompletionCallback callback;
12928
12929 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12930 EXPECT_EQ(ERR_IO_PENDING, rv);
12931
12932 rv = callback.WaitForResult();
12933 EXPECT_EQ(OK, rv);
12934
12935 const HttpResponseInfo* response = trans->GetResponseInfo();
12936 ASSERT_TRUE(response != NULL);
12937
12938 EXPECT_TRUE(response->headers.get() != NULL);
12939 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
12940
12941 std::string response_data;
12942 rv = ReadTransaction(trans.get(), &response_data);
12943 EXPECT_EQ(OK, rv);
12944 EXPECT_EQ("hello world", response_data);
12945}
12946
12947// This test makes sure the retry logic doesn't trigger when reading an error
12948// response from a server that rejected a POST with a CONNECTION_RESET.
12949TEST_P(HttpNetworkTransactionTest,
12950 PostReadsErrorResponseAfterResetOnReusedSocket) {
12951 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12952 MockWrite data_writes[] = {
12953 MockWrite("GET / HTTP/1.1\r\n"
12954 "Host: www.foo.com\r\n"
12955 "Connection: keep-alive\r\n\r\n"),
12956 MockWrite("POST / HTTP/1.1\r\n"
12957 "Host: www.foo.com\r\n"
12958 "Connection: keep-alive\r\n"
12959 "Content-Length: 3\r\n\r\n"),
12960 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12961 };
12962
12963 MockRead data_reads[] = {
12964 MockRead("HTTP/1.1 200 Peachy\r\n"
12965 "Content-Length: 14\r\n\r\n"),
12966 MockRead("first response"),
12967 MockRead("HTTP/1.1 400 Not OK\r\n"
12968 "Content-Length: 15\r\n\r\n"),
12969 MockRead("second response"),
12970 MockRead(SYNCHRONOUS, OK),
12971 };
12972 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12973 arraysize(data_writes));
12974 session_deps_.socket_factory->AddSocketDataProvider(&data);
12975
12976 TestCompletionCallback callback;
12977 HttpRequestInfo request1;
12978 request1.method = "GET";
12979 request1.url = GURL("http://www.foo.com/");
12980 request1.load_flags = 0;
12981
12982 scoped_ptr<HttpTransaction> trans1(
dcheng48459ac22014-08-26 00:46:4112983 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412984 int rv = trans1->Start(&request1, callback.callback(), BoundNetLog());
12985 EXPECT_EQ(ERR_IO_PENDING, rv);
12986
12987 rv = callback.WaitForResult();
12988 EXPECT_EQ(OK, rv);
12989
12990 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
12991 ASSERT_TRUE(response1 != NULL);
12992
12993 EXPECT_TRUE(response1->headers.get() != NULL);
12994 EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine());
12995
12996 std::string response_data1;
12997 rv = ReadTransaction(trans1.get(), &response_data1);
12998 EXPECT_EQ(OK, rv);
12999 EXPECT_EQ("first response", response_data1);
13000 // Delete the transaction to release the socket back into the socket pool.
13001 trans1.reset();
13002
13003 ScopedVector<UploadElementReader> element_readers;
13004 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713005 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413006
13007 HttpRequestInfo request2;
13008 request2.method = "POST";
13009 request2.url = GURL("http://www.foo.com/");
13010 request2.upload_data_stream = &upload_data_stream;
13011 request2.load_flags = 0;
13012
13013 scoped_ptr<HttpTransaction> trans2(
dcheng48459ac22014-08-26 00:46:4113014 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413015 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
13016 EXPECT_EQ(ERR_IO_PENDING, rv);
13017
13018 rv = callback.WaitForResult();
13019 EXPECT_EQ(OK, rv);
13020
13021 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
13022 ASSERT_TRUE(response2 != NULL);
13023
13024 EXPECT_TRUE(response2->headers.get() != NULL);
13025 EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine());
13026
13027 std::string response_data2;
13028 rv = ReadTransaction(trans2.get(), &response_data2);
13029 EXPECT_EQ(OK, rv);
13030 EXPECT_EQ("second response", response_data2);
13031}
13032
13033TEST_P(HttpNetworkTransactionTest,
13034 PostReadsErrorResponseAfterResetPartialBodySent) {
13035 ScopedVector<UploadElementReader> element_readers;
13036 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713037 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413038
13039 HttpRequestInfo request;
13040 request.method = "POST";
13041 request.url = GURL("http://www.foo.com/");
13042 request.upload_data_stream = &upload_data_stream;
13043 request.load_flags = 0;
13044
13045 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13046 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113047 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413048 // Send headers successfully, but get an error while sending the body.
13049 MockWrite data_writes[] = {
13050 MockWrite("POST / HTTP/1.1\r\n"
13051 "Host: www.foo.com\r\n"
13052 "Connection: keep-alive\r\n"
13053 "Content-Length: 3\r\n\r\n"
13054 "fo"),
13055 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13056 };
13057
13058 MockRead data_reads[] = {
13059 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
13060 MockRead("hello world"),
13061 MockRead(SYNCHRONOUS, OK),
13062 };
13063 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13064 arraysize(data_writes));
13065 session_deps_.socket_factory->AddSocketDataProvider(&data);
13066
13067 TestCompletionCallback callback;
13068
13069 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13070 EXPECT_EQ(ERR_IO_PENDING, rv);
13071
13072 rv = callback.WaitForResult();
13073 EXPECT_EQ(OK, rv);
13074
13075 const HttpResponseInfo* response = trans->GetResponseInfo();
13076 ASSERT_TRUE(response != NULL);
13077
13078 EXPECT_TRUE(response->headers.get() != NULL);
13079 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
13080
13081 std::string response_data;
13082 rv = ReadTransaction(trans.get(), &response_data);
13083 EXPECT_EQ(OK, rv);
13084 EXPECT_EQ("hello world", response_data);
13085}
13086
13087// This tests the more common case than the previous test, where headers and
13088// body are not merged into a single request.
13089TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) {
13090 ScopedVector<UploadElementReader> element_readers;
13091 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713092 ChunkedUploadDataStream upload_data_stream(0);
[email protected]02d74a02014-04-23 18:10:5413093
13094 HttpRequestInfo request;
13095 request.method = "POST";
13096 request.url = GURL("http://www.foo.com/");
13097 request.upload_data_stream = &upload_data_stream;
13098 request.load_flags = 0;
13099
13100 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13101 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113102 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413103 // Send headers successfully, but get an error while sending the body.
13104 MockWrite data_writes[] = {
13105 MockWrite("POST / HTTP/1.1\r\n"
13106 "Host: www.foo.com\r\n"
13107 "Connection: keep-alive\r\n"
13108 "Transfer-Encoding: chunked\r\n\r\n"),
13109 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13110 };
13111
13112 MockRead data_reads[] = {
13113 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
13114 MockRead("hello world"),
13115 MockRead(SYNCHRONOUS, OK),
13116 };
13117 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13118 arraysize(data_writes));
13119 session_deps_.socket_factory->AddSocketDataProvider(&data);
13120
13121 TestCompletionCallback callback;
13122
13123 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13124 EXPECT_EQ(ERR_IO_PENDING, rv);
13125 // Make sure the headers are sent before adding a chunk. This ensures that
13126 // they can't be merged with the body in a single send. Not currently
13127 // necessary since a chunked body is never merged with headers, but this makes
13128 // the test more future proof.
13129 base::RunLoop().RunUntilIdle();
13130
mmenkecbc2b712014-10-09 20:29:0713131 upload_data_stream.AppendData("last chunk", 10, true);
[email protected]02d74a02014-04-23 18:10:5413132
13133 rv = callback.WaitForResult();
13134 EXPECT_EQ(OK, rv);
13135
13136 const HttpResponseInfo* response = trans->GetResponseInfo();
13137 ASSERT_TRUE(response != NULL);
13138
13139 EXPECT_TRUE(response->headers.get() != NULL);
13140 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
13141
13142 std::string response_data;
13143 rv = ReadTransaction(trans.get(), &response_data);
13144 EXPECT_EQ(OK, rv);
13145 EXPECT_EQ("hello world", response_data);
13146}
13147
13148TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) {
13149 ScopedVector<UploadElementReader> element_readers;
13150 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713151 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413152
13153 HttpRequestInfo request;
13154 request.method = "POST";
13155 request.url = GURL("http://www.foo.com/");
13156 request.upload_data_stream = &upload_data_stream;
13157 request.load_flags = 0;
13158
13159 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13160 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113161 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413162
13163 MockWrite data_writes[] = {
13164 MockWrite("POST / HTTP/1.1\r\n"
13165 "Host: www.foo.com\r\n"
13166 "Connection: keep-alive\r\n"
13167 "Content-Length: 3\r\n\r\n"),
13168 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13169 };
13170
13171 MockRead data_reads[] = {
13172 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
13173 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
13174 MockRead("hello world"),
13175 MockRead(SYNCHRONOUS, OK),
13176 };
13177 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13178 arraysize(data_writes));
13179 session_deps_.socket_factory->AddSocketDataProvider(&data);
13180
13181 TestCompletionCallback callback;
13182
13183 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13184 EXPECT_EQ(ERR_IO_PENDING, rv);
13185
13186 rv = callback.WaitForResult();
13187 EXPECT_EQ(OK, rv);
13188
13189 const HttpResponseInfo* response = trans->GetResponseInfo();
13190 ASSERT_TRUE(response != NULL);
13191
13192 EXPECT_TRUE(response->headers.get() != NULL);
13193 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
13194
13195 std::string response_data;
13196 rv = ReadTransaction(trans.get(), &response_data);
13197 EXPECT_EQ(OK, rv);
13198 EXPECT_EQ("hello world", response_data);
13199}
13200
13201TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) {
13202 ScopedVector<UploadElementReader> element_readers;
13203 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713204 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413205
13206 HttpRequestInfo request;
13207 request.method = "POST";
13208 request.url = GURL("http://www.foo.com/");
13209 request.upload_data_stream = &upload_data_stream;
13210 request.load_flags = 0;
13211
13212 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13213 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113214 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413215 // Send headers successfully, but get an error while sending the body.
13216 MockWrite data_writes[] = {
13217 MockWrite("POST / HTTP/1.1\r\n"
13218 "Host: www.foo.com\r\n"
13219 "Connection: keep-alive\r\n"
13220 "Content-Length: 3\r\n\r\n"),
13221 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13222 };
13223
13224 MockRead data_reads[] = {
13225 MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"),
13226 MockRead("hello world"),
13227 MockRead(SYNCHRONOUS, OK),
13228 };
13229 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13230 arraysize(data_writes));
13231 session_deps_.socket_factory->AddSocketDataProvider(&data);
13232
13233 TestCompletionCallback callback;
13234
13235 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13236 EXPECT_EQ(ERR_IO_PENDING, rv);
13237
13238 rv = callback.WaitForResult();
13239 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13240
13241 const HttpResponseInfo* response = trans->GetResponseInfo();
13242 EXPECT_TRUE(response == NULL);
13243}
13244
13245TEST_P(HttpNetworkTransactionTest,
13246 PostIgnoresNonErrorResponseAfterResetAnd100) {
13247 ScopedVector<UploadElementReader> element_readers;
13248 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713249 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413250
13251 HttpRequestInfo request;
13252 request.method = "POST";
13253 request.url = GURL("http://www.foo.com/");
13254 request.upload_data_stream = &upload_data_stream;
13255 request.load_flags = 0;
13256
13257 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13258 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113259 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413260 // Send headers successfully, but get an error while sending the body.
13261 MockWrite data_writes[] = {
13262 MockWrite("POST / HTTP/1.1\r\n"
13263 "Host: www.foo.com\r\n"
13264 "Connection: keep-alive\r\n"
13265 "Content-Length: 3\r\n\r\n"),
13266 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13267 };
13268
13269 MockRead data_reads[] = {
13270 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
13271 MockRead("HTTP/1.0 302 Redirect\r\n"),
13272 MockRead("Location: http://somewhere-else.com/\r\n"),
13273 MockRead("Content-Length: 0\r\n\r\n"),
13274 MockRead(SYNCHRONOUS, OK),
13275 };
13276 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13277 arraysize(data_writes));
13278 session_deps_.socket_factory->AddSocketDataProvider(&data);
13279
13280 TestCompletionCallback callback;
13281
13282 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13283 EXPECT_EQ(ERR_IO_PENDING, rv);
13284
13285 rv = callback.WaitForResult();
13286 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13287
13288 const HttpResponseInfo* response = trans->GetResponseInfo();
13289 EXPECT_TRUE(response == NULL);
13290}
13291
13292TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) {
13293 ScopedVector<UploadElementReader> element_readers;
13294 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713295 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413296
13297 HttpRequestInfo request;
13298 request.method = "POST";
13299 request.url = GURL("http://www.foo.com/");
13300 request.upload_data_stream = &upload_data_stream;
13301 request.load_flags = 0;
13302
13303 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13304 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113305 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413306 // Send headers successfully, but get an error while sending the body.
13307 MockWrite data_writes[] = {
13308 MockWrite("POST / HTTP/1.1\r\n"
13309 "Host: www.foo.com\r\n"
13310 "Connection: keep-alive\r\n"
13311 "Content-Length: 3\r\n\r\n"),
13312 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13313 };
13314
13315 MockRead data_reads[] = {
13316 MockRead("HTTP 0.9 rocks!"),
13317 MockRead(SYNCHRONOUS, OK),
13318 };
13319 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13320 arraysize(data_writes));
13321 session_deps_.socket_factory->AddSocketDataProvider(&data);
13322
13323 TestCompletionCallback callback;
13324
13325 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13326 EXPECT_EQ(ERR_IO_PENDING, rv);
13327
13328 rv = callback.WaitForResult();
13329 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13330
13331 const HttpResponseInfo* response = trans->GetResponseInfo();
13332 EXPECT_TRUE(response == NULL);
13333}
13334
13335TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) {
13336 ScopedVector<UploadElementReader> element_readers;
13337 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713338 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413339
13340 HttpRequestInfo request;
13341 request.method = "POST";
13342 request.url = GURL("http://www.foo.com/");
13343 request.upload_data_stream = &upload_data_stream;
13344 request.load_flags = 0;
13345
13346 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13347 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113348 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413349 // Send headers successfully, but get an error while sending the body.
13350 MockWrite data_writes[] = {
13351 MockWrite("POST / HTTP/1.1\r\n"
13352 "Host: www.foo.com\r\n"
13353 "Connection: keep-alive\r\n"
13354 "Content-Length: 3\r\n\r\n"),
13355 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13356 };
13357
13358 MockRead data_reads[] = {
13359 MockRead("HTTP/1.0 400 Not a Full Response\r\n"),
13360 MockRead(SYNCHRONOUS, OK),
13361 };
13362 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13363 arraysize(data_writes));
13364 session_deps_.socket_factory->AddSocketDataProvider(&data);
13365
13366 TestCompletionCallback callback;
13367
13368 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13369 EXPECT_EQ(ERR_IO_PENDING, rv);
13370
13371 rv = callback.WaitForResult();
13372 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13373
13374 const HttpResponseInfo* response = trans->GetResponseInfo();
13375 EXPECT_TRUE(response == NULL);
13376}
13377
Adam Rice425cf122015-01-19 06:18:2413378// Verify that proxy headers are not sent to the destination server when
13379// establishing a tunnel for a secure WebSocket connection.
13380TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) {
13381 HttpRequestInfo request;
13382 request.method = "GET";
13383 request.url = GURL("wss://www.google.com/");
13384 AddWebSocketHeaders(&request.extra_headers);
13385
13386 // Configure against proxy server "myproxy:70".
13387 session_deps_.proxy_service.reset(
13388 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
13389
13390 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13391
13392 // Since a proxy is configured, try to establish a tunnel.
13393 MockWrite data_writes[] = {
13394 MockWrite(
13395 "CONNECT www.google.com:443 HTTP/1.1\r\n"
13396 "Host: www.google.com\r\n"
13397 "Proxy-Connection: keep-alive\r\n\r\n"),
13398
13399 // After calling trans->RestartWithAuth(), this is the request we should
13400 // be issuing -- the final header line contains the credentials.
13401 MockWrite(
13402 "CONNECT www.google.com:443 HTTP/1.1\r\n"
13403 "Host: www.google.com\r\n"
13404 "Proxy-Connection: keep-alive\r\n"
13405 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
13406
13407 MockWrite(
13408 "GET / HTTP/1.1\r\n"
13409 "Host: www.google.com\r\n"
13410 "Connection: Upgrade\r\n"
13411 "Upgrade: websocket\r\n"
13412 "Origin: http://www.google.com\r\n"
13413 "Sec-WebSocket-Version: 13\r\n"
13414 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"),
13415 };
13416
13417 // The proxy responds to the connect with a 407, using a persistent
13418 // connection.
13419 MockRead data_reads[] = {
13420 // No credentials.
13421 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
13422 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
13423 MockRead("Proxy-Connection: close\r\n\r\n"),
13424
13425 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
13426
13427 MockRead("HTTP/1.1 101 Switching Protocols\r\n"),
13428 MockRead("Upgrade: websocket\r\n"),
13429 MockRead("Connection: Upgrade\r\n"),
13430 MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"),
13431 };
13432
13433 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13434 arraysize(data_writes));
13435 session_deps_.socket_factory->AddSocketDataProvider(&data);
13436 SSLSocketDataProvider ssl(ASYNC, OK);
13437 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
13438
13439 scoped_ptr<HttpTransaction> trans(
13440 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
13441 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
13442 trans->SetWebSocketHandshakeStreamCreateHelper(
13443 &websocket_stream_create_helper);
13444
13445 {
13446 TestCompletionCallback callback;
13447
13448 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13449 EXPECT_EQ(ERR_IO_PENDING, rv);
13450
13451 rv = callback.WaitForResult();
13452 EXPECT_EQ(OK, rv);
13453 }
13454
13455 const HttpResponseInfo* response = trans->GetResponseInfo();
13456 ASSERT_TRUE(response);
13457 ASSERT_TRUE(response->headers.get());
13458 EXPECT_EQ(407, response->headers->response_code());
13459
13460 {
13461 TestCompletionCallback callback;
13462
13463 int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar),
13464 callback.callback());
13465 EXPECT_EQ(ERR_IO_PENDING, rv);
13466
13467 rv = callback.WaitForResult();
13468 EXPECT_EQ(OK, rv);
13469 }
13470
13471 response = trans->GetResponseInfo();
13472 ASSERT_TRUE(response);
13473 ASSERT_TRUE(response->headers.get());
13474
13475 EXPECT_EQ(101, response->headers->response_code());
13476
13477 trans.reset();
13478 session->CloseAllConnections();
13479}
13480
13481// Verify that proxy headers are not sent to the destination server when
13482// establishing a tunnel for an insecure WebSocket connection.
13483// This requires the authentication info to be injected into the auth cache
13484// due to crbug.com/395064
13485// TODO(ricea): Change to use a 407 response once issue 395064 is fixed.
13486TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) {
13487 HttpRequestInfo request;
13488 request.method = "GET";
13489 request.url = GURL("ws://www.google.com/");
13490 AddWebSocketHeaders(&request.extra_headers);
13491
13492 // Configure against proxy server "myproxy:70".
13493 session_deps_.proxy_service.reset(
13494 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
13495
13496 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13497
13498 MockWrite data_writes[] = {
13499 // Try to establish a tunnel for the WebSocket connection, with
13500 // credentials. Because WebSockets have a separate set of socket pools,
13501 // they cannot and will not use the same TCP/IP connection as the
13502 // preflight HTTP request.
13503 MockWrite(
13504 "CONNECT www.google.com:80 HTTP/1.1\r\n"
13505 "Host: www.google.com\r\n"
13506 "Proxy-Connection: keep-alive\r\n"
13507 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
13508
13509 MockWrite(
13510 "GET / HTTP/1.1\r\n"
13511 "Host: www.google.com\r\n"
13512 "Connection: Upgrade\r\n"
13513 "Upgrade: websocket\r\n"
13514 "Origin: http://www.google.com\r\n"
13515 "Sec-WebSocket-Version: 13\r\n"
13516 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"),
13517 };
13518
13519 MockRead data_reads[] = {
13520 // HTTP CONNECT with credentials.
13521 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
13522
13523 // WebSocket connection established inside tunnel.
13524 MockRead("HTTP/1.1 101 Switching Protocols\r\n"),
13525 MockRead("Upgrade: websocket\r\n"),
13526 MockRead("Connection: Upgrade\r\n"),
13527 MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"),
13528 };
13529
13530 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13531 arraysize(data_writes));
13532 session_deps_.socket_factory->AddSocketDataProvider(&data);
13533
13534 session->http_auth_cache()->Add(
13535 GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC,
13536 "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/");
13537
13538 scoped_ptr<HttpTransaction> trans(
13539 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
13540 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
13541 trans->SetWebSocketHandshakeStreamCreateHelper(
13542 &websocket_stream_create_helper);
13543
13544 TestCompletionCallback callback;
13545
13546 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13547 EXPECT_EQ(ERR_IO_PENDING, rv);
13548
13549 rv = callback.WaitForResult();
13550 EXPECT_EQ(OK, rv);
13551
13552 const HttpResponseInfo* response = trans->GetResponseInfo();
13553 ASSERT_TRUE(response);
13554 ASSERT_TRUE(response->headers.get());
13555
13556 EXPECT_EQ(101, response->headers->response_code());
13557
13558 trans.reset();
13559 session->CloseAllConnections();
13560}
13561
[email protected]89ceba9a2009-03-21 03:46:0613562} // namespace net