blob: 1c7039315e4d1b4e5bb3fb408defbbdd4bc307ec [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();
[email protected]564b4912010-03-09 16:30:428511 EXPECT_FALSE(
[email protected]17291a022011-10-10 07:32:538512 http_server_properties.HasAlternateProtocol(http_host_port_pair));
[email protected]564b4912010-03-09 16:30:428513
8514 EXPECT_EQ(OK, callback.WaitForResult());
8515
8516 const HttpResponseInfo* response = trans->GetResponseInfo();
8517 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508518 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]564b4912010-03-09 16:30:428519 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:538520 EXPECT_FALSE(response->was_fetched_via_spdy);
8521 EXPECT_FALSE(response->was_npn_negotiated);
[email protected]564b4912010-03-09 16:30:428522
8523 std::string response_data;
8524 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8525 EXPECT_EQ("hello world", response_data);
8526
[email protected]17291a022011-10-10 07:32:538527 ASSERT_TRUE(http_server_properties.HasAlternateProtocol(http_host_port_pair));
[email protected]287d9412014-07-08 23:01:008528 const AlternateProtocolInfo alternate =
[email protected]17291a022011-10-10 07:32:538529 http_server_properties.GetAlternateProtocol(http_host_port_pair);
[email protected]287d9412014-07-08 23:01:008530 AlternateProtocolInfo expected_alternate(
8531 443, AlternateProtocolFromNextProto(GetParam()), 1);
[email protected]564b4912010-03-09 16:30:428532 EXPECT_TRUE(expected_alternate.Equals(alternate));
8533}
8534
[email protected]23e482282013-06-14 16:08:028535TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238536 MarkBrokenAlternateProtocolAndFallback) {
[email protected]d7599122014-05-24 03:37:238537 session_deps_.use_alternate_protocols = true;
[email protected]564b4912010-03-09 16:30:428538
8539 HttpRequestInfo request;
8540 request.method = "GET";
8541 request.url = GURL("http://www.google.com/");
8542 request.load_flags = 0;
8543
[email protected]d973e99a2012-02-17 21:02:368544 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]564b4912010-03-09 16:30:428545 StaticSocketDataProvider first_data;
8546 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078547 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]564b4912010-03-09 16:30:428548
8549 MockRead data_reads[] = {
8550 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8551 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068552 MockRead(ASYNC, OK),
[email protected]564b4912010-03-09 16:30:428553 };
8554 StaticSocketDataProvider second_data(
8555 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078556 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]564b4912010-03-09 16:30:428557
[email protected]bb88e1d32013-05-03 23:11:078558 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]564b4912010-03-09 16:30:428559
[email protected]30d4c022013-07-18 22:58:168560 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538561 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118562 // Port must be < 1024, or the header will be ignored (since initial port was
8563 // port 80 (another restricted port).
[email protected]17291a022011-10-10 07:32:538564 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118565 HostPortPair::FromURL(request.url),
8566 666 /* port is ignored by MockConnect anyway */,
bnc1102b552015-01-30 20:11:018567 AlternateProtocolFromNextProto(GetParam()), 1.0);
[email protected]564b4912010-03-09 16:30:428568
[email protected]262eec82013-03-19 21:01:368569 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508570 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418571 TestCompletionCallback callback;
[email protected]564b4912010-03-09 16:30:428572
[email protected]49639fa2011-12-20 23:22:418573 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]564b4912010-03-09 16:30:428574 EXPECT_EQ(ERR_IO_PENDING, rv);
8575 EXPECT_EQ(OK, callback.WaitForResult());
8576
8577 const HttpResponseInfo* response = trans->GetResponseInfo();
8578 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508579 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]564b4912010-03-09 16:30:428580 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8581
8582 std::string response_data;
8583 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8584 EXPECT_EQ("hello world", response_data);
8585
[email protected]17291a022011-10-10 07:32:538586 ASSERT_TRUE(http_server_properties->HasAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118587 HostPortPair::FromURL(request.url)));
[email protected]287d9412014-07-08 23:01:008588 const AlternateProtocolInfo alternate =
[email protected]17291a022011-10-10 07:32:538589 http_server_properties->GetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118590 HostPortPair::FromURL(request.url));
bnccbd55d5f2014-11-06 19:50:408591 EXPECT_TRUE(alternate.is_broken);
[email protected]564b4912010-03-09 16:30:428592}
8593
[email protected]23e482282013-06-14 16:08:028594TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238595 AlternateProtocolPortRestrictedBlocked) {
[email protected]3912662a32011-10-04 00:51:118596 // Ensure that we're not allowed to redirect traffic via an alternate
8597 // protocol to an unrestricted (port >= 1024) when the original traffic was
8598 // on a restricted port (port < 1024). Ensure that we can redirect in all
8599 // other cases.
[email protected]d7599122014-05-24 03:37:238600 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118601
8602 HttpRequestInfo restricted_port_request;
8603 restricted_port_request.method = "GET";
8604 restricted_port_request.url = GURL("http://www.google.com:1023/");
8605 restricted_port_request.load_flags = 0;
8606
[email protected]d973e99a2012-02-17 21:02:368607 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118608 StaticSocketDataProvider first_data;
8609 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078610 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118611
8612 MockRead data_reads[] = {
8613 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8614 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068615 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118616 };
8617 StaticSocketDataProvider second_data(
8618 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078619 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118620
[email protected]bb88e1d32013-05-03 23:11:078621 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118622
[email protected]30d4c022013-07-18 22:58:168623 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538624 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118625 const int kUnrestrictedAlternatePort = 1024;
[email protected]17291a022011-10-10 07:32:538626 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118627 HostPortPair::FromURL(restricted_port_request.url),
bnc1102b552015-01-30 20:11:018628 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8629 1.0);
[email protected]3912662a32011-10-04 00:51:118630
[email protected]262eec82013-03-19 21:01:368631 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508632 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418633 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118634
[email protected]49639fa2011-12-20 23:22:418635 int rv = trans->Start(
[email protected]262eec82013-03-19 21:01:368636 &restricted_port_request,
8637 callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118638 EXPECT_EQ(ERR_IO_PENDING, rv);
8639 // Invalid change to unrestricted port should fail.
8640 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult());
[email protected]c54c6962013-02-01 04:53:198641}
[email protected]3912662a32011-10-04 00:51:118642
[email protected]23e482282013-06-14 16:08:028643TEST_P(HttpNetworkTransactionTest,
[email protected]c54c6962013-02-01 04:53:198644 AlternateProtocolPortRestrictedPermitted) {
8645 // Ensure that we're allowed to redirect traffic via an alternate
8646 // protocol to an unrestricted (port >= 1024) when the original traffic was
8647 // on a restricted port (port < 1024) if we set
8648 // enable_user_alternate_protocol_ports.
8649
[email protected]d7599122014-05-24 03:37:238650 session_deps_.use_alternate_protocols = true;
[email protected]bb88e1d32013-05-03 23:11:078651 session_deps_.enable_user_alternate_protocol_ports = true;
[email protected]c54c6962013-02-01 04:53:198652
8653 HttpRequestInfo restricted_port_request;
8654 restricted_port_request.method = "GET";
8655 restricted_port_request.url = GURL("http://www.google.com:1023/");
8656 restricted_port_request.load_flags = 0;
8657
8658 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
8659 StaticSocketDataProvider first_data;
8660 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078661 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]c54c6962013-02-01 04:53:198662
8663 MockRead data_reads[] = {
8664 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8665 MockRead("hello world"),
8666 MockRead(ASYNC, OK),
8667 };
8668 StaticSocketDataProvider second_data(
8669 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078670 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]c54c6962013-02-01 04:53:198671
[email protected]bb88e1d32013-05-03 23:11:078672 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]c54c6962013-02-01 04:53:198673
[email protected]30d4c022013-07-18 22:58:168674 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]c54c6962013-02-01 04:53:198675 session->http_server_properties();
8676 const int kUnrestrictedAlternatePort = 1024;
8677 http_server_properties->SetAlternateProtocol(
8678 HostPortPair::FromURL(restricted_port_request.url),
bnc1102b552015-01-30 20:11:018679 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8680 1.0);
[email protected]c54c6962013-02-01 04:53:198681
[email protected]262eec82013-03-19 21:01:368682 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508683 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]c54c6962013-02-01 04:53:198684 TestCompletionCallback callback;
8685
8686 EXPECT_EQ(ERR_IO_PENDING, trans->Start(
[email protected]262eec82013-03-19 21:01:368687 &restricted_port_request,
8688 callback.callback(), BoundNetLog()));
[email protected]c54c6962013-02-01 04:53:198689 // Change to unrestricted port should succeed.
8690 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118691}
8692
[email protected]23e482282013-06-14 16:08:028693TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238694 AlternateProtocolPortRestrictedAllowed) {
[email protected]3912662a32011-10-04 00:51:118695 // Ensure that we're not allowed to redirect traffic via an alternate
8696 // protocol to an unrestricted (port >= 1024) when the original traffic was
8697 // on a restricted port (port < 1024). Ensure that we can redirect in all
8698 // other cases.
[email protected]d7599122014-05-24 03:37:238699 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118700
8701 HttpRequestInfo restricted_port_request;
8702 restricted_port_request.method = "GET";
8703 restricted_port_request.url = GURL("http://www.google.com:1023/");
8704 restricted_port_request.load_flags = 0;
8705
[email protected]d973e99a2012-02-17 21:02:368706 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118707 StaticSocketDataProvider first_data;
8708 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078709 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118710
8711 MockRead data_reads[] = {
8712 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8713 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068714 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118715 };
8716 StaticSocketDataProvider second_data(
8717 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078718 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118719
[email protected]bb88e1d32013-05-03 23:11:078720 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118721
[email protected]30d4c022013-07-18 22:58:168722 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538723 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118724 const int kRestrictedAlternatePort = 80;
[email protected]17291a022011-10-10 07:32:538725 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118726 HostPortPair::FromURL(restricted_port_request.url),
bnc1102b552015-01-30 20:11:018727 kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8728 1.0);
[email protected]3912662a32011-10-04 00:51:118729
[email protected]262eec82013-03-19 21:01:368730 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508731 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418732 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118733
[email protected]49639fa2011-12-20 23:22:418734 int rv = trans->Start(
[email protected]262eec82013-03-19 21:01:368735 &restricted_port_request,
8736 callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118737 EXPECT_EQ(ERR_IO_PENDING, rv);
8738 // Valid change to restricted port should pass.
8739 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118740}
8741
[email protected]23e482282013-06-14 16:08:028742TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238743 AlternateProtocolPortUnrestrictedAllowed1) {
[email protected]3912662a32011-10-04 00:51:118744 // Ensure that we're not allowed to redirect traffic via an alternate
8745 // protocol to an unrestricted (port >= 1024) when the original traffic was
8746 // on a restricted port (port < 1024). Ensure that we can redirect in all
8747 // other cases.
[email protected]d7599122014-05-24 03:37:238748 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118749
8750 HttpRequestInfo unrestricted_port_request;
8751 unrestricted_port_request.method = "GET";
8752 unrestricted_port_request.url = GURL("http://www.google.com:1024/");
8753 unrestricted_port_request.load_flags = 0;
8754
[email protected]d973e99a2012-02-17 21:02:368755 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118756 StaticSocketDataProvider first_data;
8757 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078758 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118759
8760 MockRead data_reads[] = {
8761 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8762 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068763 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118764 };
8765 StaticSocketDataProvider second_data(
8766 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078767 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118768
[email protected]bb88e1d32013-05-03 23:11:078769 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118770
[email protected]30d4c022013-07-18 22:58:168771 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538772 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118773 const int kRestrictedAlternatePort = 80;
[email protected]17291a022011-10-10 07:32:538774 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118775 HostPortPair::FromURL(unrestricted_port_request.url),
bnc1102b552015-01-30 20:11:018776 kRestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8777 1.0);
[email protected]3912662a32011-10-04 00:51:118778
[email protected]262eec82013-03-19 21:01:368779 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508780 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418781 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118782
[email protected]49639fa2011-12-20 23:22:418783 int rv = trans->Start(
8784 &unrestricted_port_request, callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118785 EXPECT_EQ(ERR_IO_PENDING, rv);
8786 // Valid change to restricted port should pass.
8787 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118788}
8789
[email protected]23e482282013-06-14 16:08:028790TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:238791 AlternateProtocolPortUnrestrictedAllowed2) {
[email protected]3912662a32011-10-04 00:51:118792 // Ensure that we're not allowed to redirect traffic via an alternate
8793 // protocol to an unrestricted (port >= 1024) when the original traffic was
8794 // on a restricted port (port < 1024). Ensure that we can redirect in all
8795 // other cases.
[email protected]d7599122014-05-24 03:37:238796 session_deps_.use_alternate_protocols = true;
[email protected]3912662a32011-10-04 00:51:118797
8798 HttpRequestInfo unrestricted_port_request;
8799 unrestricted_port_request.method = "GET";
8800 unrestricted_port_request.url = GURL("http://www.google.com:1024/");
8801 unrestricted_port_request.load_flags = 0;
8802
[email protected]d973e99a2012-02-17 21:02:368803 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
[email protected]3912662a32011-10-04 00:51:118804 StaticSocketDataProvider first_data;
8805 first_data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:078806 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
[email protected]3912662a32011-10-04 00:51:118807
8808 MockRead data_reads[] = {
8809 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8810 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068811 MockRead(ASYNC, OK),
[email protected]3912662a32011-10-04 00:51:118812 };
8813 StaticSocketDataProvider second_data(
8814 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078815 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
[email protected]3912662a32011-10-04 00:51:118816
[email protected]bb88e1d32013-05-03 23:11:078817 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]3912662a32011-10-04 00:51:118818
[email protected]30d4c022013-07-18 22:58:168819 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]17291a022011-10-10 07:32:538820 session->http_server_properties();
[email protected]3912662a32011-10-04 00:51:118821 const int kUnrestrictedAlternatePort = 1024;
[email protected]17291a022011-10-10 07:32:538822 http_server_properties->SetAlternateProtocol(
[email protected]3912662a32011-10-04 00:51:118823 HostPortPair::FromURL(unrestricted_port_request.url),
bnc1102b552015-01-30 20:11:018824 kUnrestrictedAlternatePort, AlternateProtocolFromNextProto(GetParam()),
8825 1.0);
[email protected]3912662a32011-10-04 00:51:118826
[email protected]262eec82013-03-19 21:01:368827 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508828 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:418829 TestCompletionCallback callback;
[email protected]3912662a32011-10-04 00:51:118830
[email protected]49639fa2011-12-20 23:22:418831 int rv = trans->Start(
8832 &unrestricted_port_request, callback.callback(), BoundNetLog());
[email protected]3912662a32011-10-04 00:51:118833 EXPECT_EQ(ERR_IO_PENDING, rv);
8834 // Valid change to an unrestricted port should pass.
8835 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]3912662a32011-10-04 00:51:118836}
8837
[email protected]d7599122014-05-24 03:37:238838TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) {
[email protected]eb6234e2012-01-19 01:50:028839 // Ensure that we're not allowed to redirect traffic via an alternate
8840 // protocol to an unsafe port, and that we resume the second
8841 // HttpStreamFactoryImpl::Job once the alternate protocol request fails.
[email protected]d7599122014-05-24 03:37:238842 session_deps_.use_alternate_protocols = true;
[email protected]eb6234e2012-01-19 01:50:028843
8844 HttpRequestInfo request;
8845 request.method = "GET";
8846 request.url = GURL("http://www.google.com/");
8847 request.load_flags = 0;
8848
8849 // The alternate protocol request will error out before we attempt to connect,
8850 // so only the standard HTTP request will try to connect.
8851 MockRead data_reads[] = {
8852 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
8853 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:068854 MockRead(ASYNC, OK),
[email protected]eb6234e2012-01-19 01:50:028855 };
8856 StaticSocketDataProvider data(
8857 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078858 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]eb6234e2012-01-19 01:50:028859
[email protected]bb88e1d32013-05-03 23:11:078860 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]eb6234e2012-01-19 01:50:028861
[email protected]30d4c022013-07-18 22:58:168862 base::WeakPtr<HttpServerProperties> http_server_properties =
[email protected]eb6234e2012-01-19 01:50:028863 session->http_server_properties();
8864 const int kUnsafePort = 7;
8865 http_server_properties->SetAlternateProtocol(
bnc1102b552015-01-30 20:11:018866 HostPortPair::FromURL(request.url), kUnsafePort,
8867 AlternateProtocolFromNextProto(GetParam()), 1.0);
[email protected]eb6234e2012-01-19 01:50:028868
[email protected]262eec82013-03-19 21:01:368869 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508870 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]eb6234e2012-01-19 01:50:028871 TestCompletionCallback callback;
8872
8873 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8874 EXPECT_EQ(ERR_IO_PENDING, rv);
8875 // The HTTP request should succeed.
8876 EXPECT_EQ(OK, callback.WaitForResult());
8877
8878 // Disable alternate protocol before the asserts.
[email protected]d7599122014-05-24 03:37:238879 // HttpStreamFactory::set_use_alternate_protocols(false);
[email protected]eb6234e2012-01-19 01:50:028880
8881 const HttpResponseInfo* response = trans->GetResponseInfo();
8882 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508883 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]eb6234e2012-01-19 01:50:028884 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8885
8886 std::string response_data;
8887 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8888 EXPECT_EQ("hello world", response_data);
8889}
8890
[email protected]23e482282013-06-14 16:08:028891TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) {
[email protected]d7599122014-05-24 03:37:238892 session_deps_.use_alternate_protocols = true;
8893 session_deps_.next_protos = SpdyNextProtos();
[email protected]2ff8b312010-04-26 22:20:548894
8895 HttpRequestInfo request;
8896 request.method = "GET";
8897 request.url = GURL("http://www.google.com/");
8898 request.load_flags = 0;
8899
[email protected]8a0fc822013-06-27 20:52:438900 std::string alternate_protocol_http_header =
8901 GetAlternateProtocolHttpHeader();
8902
[email protected]2ff8b312010-04-26 22:20:548903 MockRead data_reads[] = {
8904 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438905 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2ff8b312010-04-26 22:20:548906 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:178907 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
8908 MockRead(ASYNC, OK)
[email protected]2ff8b312010-04-26 22:20:548909 };
8910
8911 StaticSocketDataProvider first_transaction(
8912 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:078913 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2ff8b312010-04-26 22:20:548914
[email protected]8ddf8322012-02-23 18:08:068915 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:028916 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:078917 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2ff8b312010-04-26 22:20:548918
[email protected]cdf8f7e72013-05-23 10:56:468919 scoped_ptr<SpdyFrame> req(
8920 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:138921 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]2ff8b312010-04-26 22:20:548922
[email protected]23e482282013-06-14 16:08:028923 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
8924 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2ff8b312010-04-26 22:20:548925 MockRead spdy_reads[] = {
[email protected]e7f75092010-07-01 22:39:138926 CreateMockRead(*resp),
8927 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:068928 MockRead(ASYNC, 0, 0),
[email protected]2ff8b312010-04-26 22:20:548929 };
8930
[email protected]dd54bd82012-07-19 23:44:578931 DelayedSocketData spdy_data(
8932 1, // wait for one write to finish before reading.
8933 spdy_reads, arraysize(spdy_reads),
8934 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:078935 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2ff8b312010-04-26 22:20:548936
[email protected]d973e99a2012-02-17 21:02:368937 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:558938 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
8939 NULL, 0, NULL, 0);
8940 hanging_non_alternate_protocol_socket.set_connect_data(
8941 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:078942 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:558943 &hanging_non_alternate_protocol_socket);
8944
[email protected]49639fa2011-12-20 23:22:418945 TestCompletionCallback callback;
[email protected]2ff8b312010-04-26 22:20:548946
[email protected]bb88e1d32013-05-03 23:11:078947 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:368948 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:508949 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:548950
[email protected]49639fa2011-12-20 23:22:418951 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:548952 EXPECT_EQ(ERR_IO_PENDING, rv);
8953 EXPECT_EQ(OK, callback.WaitForResult());
8954
8955 const HttpResponseInfo* response = trans->GetResponseInfo();
8956 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508957 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:548958 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8959
8960 std::string response_data;
8961 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8962 EXPECT_EQ("hello world", response_data);
8963
[email protected]90499482013-06-01 00:39:508964 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:548965
[email protected]49639fa2011-12-20 23:22:418966 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:548967 EXPECT_EQ(ERR_IO_PENDING, rv);
8968 EXPECT_EQ(OK, callback.WaitForResult());
8969
8970 response = trans->GetResponseInfo();
8971 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:508972 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:548973 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:538974 EXPECT_TRUE(response->was_fetched_via_spdy);
8975 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]2ff8b312010-04-26 22:20:548976
8977 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8978 EXPECT_EQ("hello!", response_data);
[email protected]2ff8b312010-04-26 22:20:548979}
8980
[email protected]23e482282013-06-14 16:08:028981TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
[email protected]d7599122014-05-24 03:37:238982 session_deps_.use_alternate_protocols = true;
8983 session_deps_.next_protos = SpdyNextProtos();
[email protected]2d6728692011-03-12 01:39:558984
8985 HttpRequestInfo request;
8986 request.method = "GET";
8987 request.url = GURL("http://www.google.com/");
8988 request.load_flags = 0;
8989
[email protected]8a0fc822013-06-27 20:52:438990 std::string alternate_protocol_http_header =
8991 GetAlternateProtocolHttpHeader();
8992
[email protected]2d6728692011-03-12 01:39:558993 MockRead data_reads[] = {
8994 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:438995 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2d6728692011-03-12 01:39:558996 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:178997 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:068998 MockRead(ASYNC, OK),
[email protected]2d6728692011-03-12 01:39:558999 };
9000
9001 StaticSocketDataProvider first_transaction(
9002 data_reads, arraysize(data_reads), NULL, 0);
9003 // Socket 1 is the HTTP transaction with the Alternate-Protocol header.
[email protected]bb88e1d32013-05-03 23:11:079004 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559005
[email protected]d973e99a2012-02-17 21:02:369006 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559007 StaticSocketDataProvider hanging_socket(
9008 NULL, 0, NULL, 0);
9009 hanging_socket.set_connect_data(never_finishing_connect);
9010 // Socket 2 and 3 are the hanging Alternate-Protocol and
9011 // non-Alternate-Protocol jobs from the 2nd transaction.
[email protected]bb88e1d32013-05-03 23:11:079012 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
9013 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
[email protected]2d6728692011-03-12 01:39:559014
[email protected]8ddf8322012-02-23 18:08:069015 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029016 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079017 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2d6728692011-03-12 01:39:559018
[email protected]cdf8f7e72013-05-23 10:56:469019 scoped_ptr<SpdyFrame> req1(
9020 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
9021 scoped_ptr<SpdyFrame> req2(
9022 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true));
[email protected]2d6728692011-03-12 01:39:559023 MockWrite spdy_writes[] = {
9024 CreateMockWrite(*req1),
9025 CreateMockWrite(*req2),
9026 };
[email protected]23e482282013-06-14 16:08:029027 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9028 scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true));
9029 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
9030 scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]2d6728692011-03-12 01:39:559031 MockRead spdy_reads[] = {
9032 CreateMockRead(*resp1),
9033 CreateMockRead(*data1),
9034 CreateMockRead(*resp2),
9035 CreateMockRead(*data2),
[email protected]8ddf8322012-02-23 18:08:069036 MockRead(ASYNC, 0, 0),
[email protected]2d6728692011-03-12 01:39:559037 };
9038
[email protected]dd54bd82012-07-19 23:44:579039 DelayedSocketData spdy_data(
9040 2, // wait for writes to finish before reading.
9041 spdy_reads, arraysize(spdy_reads),
9042 spdy_writes, arraysize(spdy_writes));
[email protected]2d6728692011-03-12 01:39:559043 // Socket 4 is the successful Alternate-Protocol for transaction 3.
[email protected]bb88e1d32013-05-03 23:11:079044 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2d6728692011-03-12 01:39:559045
9046 // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3.
[email protected]bb88e1d32013-05-03 23:11:079047 session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket);
[email protected]2d6728692011-03-12 01:39:559048
[email protected]bb88e1d32013-05-03 23:11:079049 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]49639fa2011-12-20 23:22:419050 TestCompletionCallback callback1;
[email protected]90499482013-06-01 00:39:509051 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]2d6728692011-03-12 01:39:559052
[email protected]49639fa2011-12-20 23:22:419053 int rv = trans1.Start(&request, callback1.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559054 EXPECT_EQ(ERR_IO_PENDING, rv);
9055 EXPECT_EQ(OK, callback1.WaitForResult());
9056
9057 const HttpResponseInfo* response = trans1.GetResponseInfo();
9058 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509059 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559060 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9061
9062 std::string response_data;
9063 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
9064 EXPECT_EQ("hello world", response_data);
9065
[email protected]49639fa2011-12-20 23:22:419066 TestCompletionCallback callback2;
[email protected]90499482013-06-01 00:39:509067 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]49639fa2011-12-20 23:22:419068 rv = trans2.Start(&request, callback2.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559069 EXPECT_EQ(ERR_IO_PENDING, rv);
9070
[email protected]49639fa2011-12-20 23:22:419071 TestCompletionCallback callback3;
[email protected]90499482013-06-01 00:39:509072 HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get());
[email protected]49639fa2011-12-20 23:22:419073 rv = trans3.Start(&request, callback3.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559074 EXPECT_EQ(ERR_IO_PENDING, rv);
9075
9076 EXPECT_EQ(OK, callback2.WaitForResult());
9077 EXPECT_EQ(OK, callback3.WaitForResult());
9078
9079 response = trans2.GetResponseInfo();
9080 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509081 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559082 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9083 EXPECT_TRUE(response->was_fetched_via_spdy);
9084 EXPECT_TRUE(response->was_npn_negotiated);
9085 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
9086 EXPECT_EQ("hello!", response_data);
9087
9088 response = trans3.GetResponseInfo();
9089 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509090 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559091 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9092 EXPECT_TRUE(response->was_fetched_via_spdy);
9093 EXPECT_TRUE(response->was_npn_negotiated);
9094 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data));
9095 EXPECT_EQ("hello!", response_data);
[email protected]2d6728692011-03-12 01:39:559096}
9097
[email protected]23e482282013-06-14 16:08:029098TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) {
[email protected]d7599122014-05-24 03:37:239099 session_deps_.use_alternate_protocols = true;
9100 session_deps_.next_protos = SpdyNextProtos();
[email protected]2d6728692011-03-12 01:39:559101
9102 HttpRequestInfo request;
9103 request.method = "GET";
9104 request.url = GURL("http://www.google.com/");
9105 request.load_flags = 0;
9106
[email protected]8a0fc822013-06-27 20:52:439107 std::string alternate_protocol_http_header =
9108 GetAlternateProtocolHttpHeader();
9109
[email protected]2d6728692011-03-12 01:39:559110 MockRead data_reads[] = {
9111 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439112 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2d6728692011-03-12 01:39:559113 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:179114 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:069115 MockRead(ASYNC, OK),
[email protected]2d6728692011-03-12 01:39:559116 };
9117
9118 StaticSocketDataProvider first_transaction(
9119 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079120 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559121
[email protected]8ddf8322012-02-23 18:08:069122 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029123 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079124 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2d6728692011-03-12 01:39:559125
[email protected]d973e99a2012-02-17 21:02:369126 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559127 StaticSocketDataProvider hanging_alternate_protocol_socket(
9128 NULL, 0, NULL, 0);
9129 hanging_alternate_protocol_socket.set_connect_data(
9130 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:079131 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:559132 &hanging_alternate_protocol_socket);
9133
9134 // 2nd request is just a copy of the first one, over HTTP again.
[email protected]bb88e1d32013-05-03 23:11:079135 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2d6728692011-03-12 01:39:559136
[email protected]49639fa2011-12-20 23:22:419137 TestCompletionCallback callback;
[email protected]2d6728692011-03-12 01:39:559138
[email protected]bb88e1d32013-05-03 23:11:079139 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:369140 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509141 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d6728692011-03-12 01:39:559142
[email protected]49639fa2011-12-20 23:22:419143 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559144 EXPECT_EQ(ERR_IO_PENDING, rv);
9145 EXPECT_EQ(OK, callback.WaitForResult());
9146
9147 const HttpResponseInfo* response = trans->GetResponseInfo();
9148 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509149 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559150 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9151
9152 std::string response_data;
9153 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9154 EXPECT_EQ("hello world", response_data);
9155
[email protected]90499482013-06-01 00:39:509156 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2d6728692011-03-12 01:39:559157
[email protected]49639fa2011-12-20 23:22:419158 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2d6728692011-03-12 01:39:559159 EXPECT_EQ(ERR_IO_PENDING, rv);
9160 EXPECT_EQ(OK, callback.WaitForResult());
9161
9162 response = trans->GetResponseInfo();
9163 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509164 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2d6728692011-03-12 01:39:559165 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9166 EXPECT_FALSE(response->was_fetched_via_spdy);
9167 EXPECT_FALSE(response->was_npn_negotiated);
9168
9169 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9170 EXPECT_EQ("hello world", response_data);
[email protected]2d6728692011-03-12 01:39:559171}
9172
[email protected]631f1322010-04-30 17:59:119173class CapturingProxyResolver : public ProxyResolver {
9174 public:
9175 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {}
dchengb03027d2014-10-21 12:00:209176 ~CapturingProxyResolver() override {}
[email protected]631f1322010-04-30 17:59:119177
dchengb03027d2014-10-21 12:00:209178 int GetProxyForURL(const GURL& url,
9179 ProxyInfo* results,
9180 const CompletionCallback& callback,
9181 RequestHandle* request,
9182 const BoundNetLog& net_log) override {
[email protected]fae7669f2010-08-02 21:49:409183 ProxyServer proxy_server(ProxyServer::SCHEME_HTTP,
9184 HostPortPair("myproxy", 80));
[email protected]d911f1b2010-05-05 22:39:429185 results->UseProxyServer(proxy_server);
[email protected]631f1322010-04-30 17:59:119186 resolved_.push_back(url);
[email protected]d911f1b2010-05-05 22:39:429187 return OK;
[email protected]631f1322010-04-30 17:59:119188 }
9189
dchengb03027d2014-10-21 12:00:209190 void CancelRequest(RequestHandle request) override { NOTREACHED(); }
[email protected]631f1322010-04-30 17:59:119191
dchengb03027d2014-10-21 12:00:209192 LoadState GetLoadState(RequestHandle request) const override {
[email protected]f2c971f2011-11-08 00:33:179193 NOTREACHED();
9194 return LOAD_STATE_IDLE;
9195 }
9196
dchengb03027d2014-10-21 12:00:209197 void CancelSetPacScript() override { NOTREACHED(); }
[email protected]1e605472010-12-16 21:41:409198
dchengb03027d2014-10-21 12:00:209199 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&,
9200 const CompletionCallback& /*callback*/) override {
[email protected]d911f1b2010-05-05 22:39:429201 return OK;
[email protected]631f1322010-04-30 17:59:119202 }
9203
[email protected]24476402010-07-20 20:55:179204 const std::vector<GURL>& resolved() const { return resolved_; }
9205
9206 private:
[email protected]631f1322010-04-30 17:59:119207 std::vector<GURL> resolved_;
9208
9209 DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver);
9210};
9211
[email protected]23e482282013-06-14 16:08:029212TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:239213 UseAlternateProtocolForTunneledNpnSpdy) {
[email protected]d7599122014-05-24 03:37:239214 session_deps_.use_alternate_protocols = true;
9215 session_deps_.next_protos = SpdyNextProtos();
[email protected]631f1322010-04-30 17:59:119216
9217 ProxyConfig proxy_config;
[email protected]d911f1b2010-05-05 22:39:429218 proxy_config.set_auto_detect(true);
9219 proxy_config.set_pac_url(GURL("http://fooproxyurl"));
[email protected]2227c692010-05-04 15:36:119220
[email protected]631f1322010-04-30 17:59:119221 CapturingProxyResolver* capturing_proxy_resolver =
9222 new CapturingProxyResolver();
[email protected]bb88e1d32013-05-03 23:11:079223 session_deps_.proxy_service.reset(new ProxyService(
[email protected]66761b952010-06-25 21:30:389224 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
9225 NULL));
[email protected]029c83b62013-01-24 05:28:209226 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:079227 session_deps_.net_log = &net_log;
[email protected]631f1322010-04-30 17:59:119228
9229 HttpRequestInfo request;
9230 request.method = "GET";
9231 request.url = GURL("http://www.google.com/");
9232 request.load_flags = 0;
9233
[email protected]8a0fc822013-06-27 20:52:439234 std::string alternate_protocol_http_header =
9235 GetAlternateProtocolHttpHeader();
9236
[email protected]631f1322010-04-30 17:59:119237 MockRead data_reads[] = {
9238 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439239 MockRead(alternate_protocol_http_header.c_str()),
[email protected]631f1322010-04-30 17:59:119240 MockRead("hello world"),
[email protected]7a5378b2012-11-04 03:25:179241 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]8ddf8322012-02-23 18:08:069242 MockRead(ASYNC, OK),
[email protected]631f1322010-04-30 17:59:119243 };
9244
9245 StaticSocketDataProvider first_transaction(
9246 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079247 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]631f1322010-04-30 17:59:119248
[email protected]8ddf8322012-02-23 18:08:069249 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029250 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079251 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]631f1322010-04-30 17:59:119252
[email protected]cdf8f7e72013-05-23 10:56:469253 scoped_ptr<SpdyFrame> req(
9254 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]631f1322010-04-30 17:59:119255 MockWrite spdy_writes[] = {
9256 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
9257 "Host: www.google.com\r\n"
[email protected]d911f1b2010-05-05 22:39:429258 "Proxy-Connection: keep-alive\r\n\r\n"), // 0
[email protected]cdf8f7e72013-05-23 10:56:469259 CreateMockWrite(*req), // 3
[email protected]631f1322010-04-30 17:59:119260 };
9261
[email protected]d911f1b2010-05-05 22:39:429262 const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
9263
[email protected]23e482282013-06-14 16:08:029264 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9265 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]631f1322010-04-30 17:59:119266 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:069267 MockRead(ASYNC, kCONNECTResponse, arraysize(kCONNECTResponse) - 1, 1), // 1
[email protected]e7f75092010-07-01 22:39:139268 CreateMockRead(*resp.get(), 4), // 2, 4
9269 CreateMockRead(*data.get(), 4), // 5
[email protected]8ddf8322012-02-23 18:08:069270 MockRead(ASYNC, 0, 0, 4), // 6
[email protected]631f1322010-04-30 17:59:119271 };
9272
[email protected]dd54bd82012-07-19 23:44:579273 OrderedSocketData spdy_data(
9274 spdy_reads, arraysize(spdy_reads),
9275 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:079276 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]631f1322010-04-30 17:59:119277
[email protected]d973e99a2012-02-17 21:02:369278 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:559279 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
9280 NULL, 0, NULL, 0);
9281 hanging_non_alternate_protocol_socket.set_connect_data(
9282 never_finishing_connect);
[email protected]bb88e1d32013-05-03 23:11:079283 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:559284 &hanging_non_alternate_protocol_socket);
9285
[email protected]49639fa2011-12-20 23:22:419286 TestCompletionCallback callback;
[email protected]631f1322010-04-30 17:59:119287
[email protected]bb88e1d32013-05-03 23:11:079288 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:369289 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509290 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]631f1322010-04-30 17:59:119291
[email protected]49639fa2011-12-20 23:22:419292 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]631f1322010-04-30 17:59:119293 EXPECT_EQ(ERR_IO_PENDING, rv);
9294 EXPECT_EQ(OK, callback.WaitForResult());
9295
9296 const HttpResponseInfo* response = trans->GetResponseInfo();
9297 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509298 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]631f1322010-04-30 17:59:119299 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539300 EXPECT_FALSE(response->was_fetched_via_spdy);
9301 EXPECT_FALSE(response->was_npn_negotiated);
[email protected]631f1322010-04-30 17:59:119302
9303 std::string response_data;
9304 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9305 EXPECT_EQ("hello world", response_data);
9306
[email protected]90499482013-06-01 00:39:509307 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]631f1322010-04-30 17:59:119308
[email protected]49639fa2011-12-20 23:22:419309 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]631f1322010-04-30 17:59:119310 EXPECT_EQ(ERR_IO_PENDING, rv);
9311 EXPECT_EQ(OK, callback.WaitForResult());
9312
9313 response = trans->GetResponseInfo();
9314 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509315 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]631f1322010-04-30 17:59:119316 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539317 EXPECT_TRUE(response->was_fetched_via_spdy);
9318 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]631f1322010-04-30 17:59:119319
9320 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9321 EXPECT_EQ("hello!", response_data);
[email protected]2d6728692011-03-12 01:39:559322 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size());
[email protected]d911f1b2010-05-05 22:39:429323 EXPECT_EQ("http://www.google.com/",
[email protected]631f1322010-04-30 17:59:119324 capturing_proxy_resolver->resolved()[0].spec());
[email protected]d911f1b2010-05-05 22:39:429325 EXPECT_EQ("https://www.google.com/",
9326 capturing_proxy_resolver->resolved()[1].spec());
[email protected]631f1322010-04-30 17:59:119327
[email protected]029c83b62013-01-24 05:28:209328 LoadTimingInfo load_timing_info;
9329 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
9330 TestLoadTimingNotReusedWithPac(load_timing_info,
9331 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]631f1322010-04-30 17:59:119332}
[email protected]631f1322010-04-30 17:59:119333
[email protected]23e482282013-06-14 16:08:029334TEST_P(HttpNetworkTransactionTest,
[email protected]2ff8b312010-04-26 22:20:549335 UseAlternateProtocolForNpnSpdyWithExistingSpdySession) {
[email protected]d7599122014-05-24 03:37:239336 session_deps_.use_alternate_protocols = true;
9337 session_deps_.next_protos = SpdyNextProtos();
[email protected]2ff8b312010-04-26 22:20:549338
9339 HttpRequestInfo request;
9340 request.method = "GET";
9341 request.url = GURL("http://www.google.com/");
9342 request.load_flags = 0;
9343
[email protected]8a0fc822013-06-27 20:52:439344 std::string alternate_protocol_http_header =
9345 GetAlternateProtocolHttpHeader();
9346
[email protected]2ff8b312010-04-26 22:20:549347 MockRead data_reads[] = {
9348 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:439349 MockRead(alternate_protocol_http_header.c_str()),
[email protected]2ff8b312010-04-26 22:20:549350 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:069351 MockRead(ASYNC, OK),
[email protected]2ff8b312010-04-26 22:20:549352 };
9353
9354 StaticSocketDataProvider first_transaction(
9355 data_reads, arraysize(data_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:079356 session_deps_.socket_factory->AddSocketDataProvider(&first_transaction);
[email protected]2ff8b312010-04-26 22:20:549357
[email protected]8ddf8322012-02-23 18:08:069358 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:029359 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:079360 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]2ff8b312010-04-26 22:20:549361
[email protected]cdf8f7e72013-05-23 10:56:469362 scoped_ptr<SpdyFrame> req(
9363 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:139364 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]2ff8b312010-04-26 22:20:549365
[email protected]23e482282013-06-14 16:08:029366 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
9367 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2ff8b312010-04-26 22:20:549368 MockRead spdy_reads[] = {
[email protected]e7f75092010-07-01 22:39:139369 CreateMockRead(*resp),
9370 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:069371 MockRead(ASYNC, 0, 0),
[email protected]2ff8b312010-04-26 22:20:549372 };
9373
[email protected]dd54bd82012-07-19 23:44:579374 DelayedSocketData spdy_data(
9375 1, // wait for one write to finish before reading.
9376 spdy_reads, arraysize(spdy_reads),
9377 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:079378 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]2ff8b312010-04-26 22:20:549379
[email protected]83039bb2011-12-09 18:43:559380 TestCompletionCallback callback;
[email protected]2ff8b312010-04-26 22:20:549381
[email protected]bb88e1d32013-05-03 23:11:079382 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]2ff8b312010-04-26 22:20:549383
[email protected]262eec82013-03-19 21:01:369384 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509385 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:549386
[email protected]49639fa2011-12-20 23:22:419387 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:549388 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:419389 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]2ff8b312010-04-26 22:20:549390
9391 const HttpResponseInfo* response = trans->GetResponseInfo();
9392 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509393 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:549394 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
9395
9396 std::string response_data;
9397 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9398 EXPECT_EQ("hello world", response_data);
9399
9400 // Set up an initial SpdySession in the pool to reuse.
[email protected]02b0c342010-09-25 21:09:389401 HostPortPair host_port_pair("www.google.com", 443);
[email protected]e6d017652013-05-17 18:01:409402 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
[email protected]314b03992014-04-01 01:28:539403 PRIVACY_MODE_DISABLED);
[email protected]795cbf82013-07-22 09:37:279404 base::WeakPtr<SpdySession> spdy_session =
[email protected]41d64e82013-07-03 22:44:269405 CreateSecureSpdySession(session, key, BoundNetLog());
[email protected]02b0c342010-09-25 21:09:389406
[email protected]90499482013-06-01 00:39:509407 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]2ff8b312010-04-26 22:20:549408
[email protected]49639fa2011-12-20 23:22:419409 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]2ff8b312010-04-26 22:20:549410 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:419411 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]2ff8b312010-04-26 22:20:549412
9413 response = trans->GetResponseInfo();
9414 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:509415 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]2ff8b312010-04-26 22:20:549416 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
[email protected]65041fa2010-05-21 06:56:539417 EXPECT_TRUE(response->was_fetched_via_spdy);
9418 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]2ff8b312010-04-26 22:20:549419
9420 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9421 EXPECT_EQ("hello!", response_data);
[email protected]564b4912010-03-09 16:30:429422}
9423
[email protected]044de0642010-06-17 10:42:159424// GenerateAuthToken is a mighty big test.
9425// It tests all permutation of GenerateAuthToken behavior:
9426// - Synchronous and Asynchronous completion.
9427// - OK or error on completion.
9428// - Direct connection, non-authenticating proxy, and authenticating proxy.
9429// - HTTP or HTTPS backend (to include proxy tunneling).
9430// - Non-authenticating and authenticating backend.
9431//
[email protected]fe3b7dc2012-02-03 19:52:099432// In all, there are 44 reasonable permuations (for example, if there are
[email protected]044de0642010-06-17 10:42:159433// problems generating an auth token for an authenticating proxy, we don't
9434// need to test all permutations of the backend server).
9435//
9436// The test proceeds by going over each of the configuration cases, and
9437// potentially running up to three rounds in each of the tests. The TestConfig
9438// specifies both the configuration for the test as well as the expectations
9439// for the results.
[email protected]23e482282013-06-14 16:08:029440TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) {
[email protected]0b0bf032010-09-21 18:08:509441 static const char kServer[] = "http://www.example.com";
9442 static const char kSecureServer[] = "https://www.example.com";
9443 static const char kProxy[] = "myproxy:70";
[email protected]044de0642010-06-17 10:42:159444 const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS;
9445
9446 enum AuthTiming {
9447 AUTH_NONE,
9448 AUTH_SYNC,
9449 AUTH_ASYNC,
9450 };
9451
9452 const MockWrite kGet(
9453 "GET / HTTP/1.1\r\n"
9454 "Host: www.example.com\r\n"
9455 "Connection: keep-alive\r\n\r\n");
9456 const MockWrite kGetProxy(
9457 "GET http://www.example.com/ HTTP/1.1\r\n"
9458 "Host: www.example.com\r\n"
9459 "Proxy-Connection: keep-alive\r\n\r\n");
9460 const MockWrite kGetAuth(
9461 "GET / HTTP/1.1\r\n"
9462 "Host: www.example.com\r\n"
9463 "Connection: keep-alive\r\n"
9464 "Authorization: auth_token\r\n\r\n");
9465 const MockWrite kGetProxyAuth(
9466 "GET http://www.example.com/ HTTP/1.1\r\n"
9467 "Host: www.example.com\r\n"
9468 "Proxy-Connection: keep-alive\r\n"
9469 "Proxy-Authorization: auth_token\r\n\r\n");
9470 const MockWrite kGetAuthThroughProxy(
9471 "GET http://www.example.com/ HTTP/1.1\r\n"
9472 "Host: www.example.com\r\n"
9473 "Proxy-Connection: keep-alive\r\n"
9474 "Authorization: auth_token\r\n\r\n");
9475 const MockWrite kGetAuthWithProxyAuth(
9476 "GET http://www.example.com/ HTTP/1.1\r\n"
9477 "Host: www.example.com\r\n"
9478 "Proxy-Connection: keep-alive\r\n"
9479 "Proxy-Authorization: auth_token\r\n"
9480 "Authorization: auth_token\r\n\r\n");
9481 const MockWrite kConnect(
9482 "CONNECT www.example.com:443 HTTP/1.1\r\n"
9483 "Host: www.example.com\r\n"
9484 "Proxy-Connection: keep-alive\r\n\r\n");
9485 const MockWrite kConnectProxyAuth(
9486 "CONNECT www.example.com:443 HTTP/1.1\r\n"
9487 "Host: www.example.com\r\n"
9488 "Proxy-Connection: keep-alive\r\n"
9489 "Proxy-Authorization: auth_token\r\n\r\n");
9490
9491 const MockRead kSuccess(
9492 "HTTP/1.1 200 OK\r\n"
9493 "Content-Type: text/html; charset=iso-8859-1\r\n"
9494 "Content-Length: 3\r\n\r\n"
9495 "Yes");
9496 const MockRead kFailure(
9497 "Should not be called.");
9498 const MockRead kServerChallenge(
9499 "HTTP/1.1 401 Unauthorized\r\n"
9500 "WWW-Authenticate: Mock realm=server\r\n"
9501 "Content-Type: text/html; charset=iso-8859-1\r\n"
9502 "Content-Length: 14\r\n\r\n"
9503 "Unauthorized\r\n");
9504 const MockRead kProxyChallenge(
9505 "HTTP/1.1 407 Unauthorized\r\n"
9506 "Proxy-Authenticate: Mock realm=proxy\r\n"
9507 "Proxy-Connection: close\r\n"
9508 "Content-Type: text/html; charset=iso-8859-1\r\n"
9509 "Content-Length: 14\r\n\r\n"
9510 "Unauthorized\r\n");
9511 const MockRead kProxyConnected(
9512 "HTTP/1.1 200 Connection Established\r\n\r\n");
9513
9514 // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with
9515 // no constructors, but the C++ compiler on Windows warns about
9516 // unspecified data in compound literals. So, moved to using constructors,
9517 // and TestRound's created with the default constructor should not be used.
9518 struct TestRound {
9519 TestRound()
9520 : expected_rv(ERR_UNEXPECTED),
9521 extra_write(NULL),
9522 extra_read(NULL) {
9523 }
9524 TestRound(const MockWrite& write_arg, const MockRead& read_arg,
9525 int expected_rv_arg)
9526 : write(write_arg),
9527 read(read_arg),
9528 expected_rv(expected_rv_arg),
9529 extra_write(NULL),
9530 extra_read(NULL) {
9531 }
9532 TestRound(const MockWrite& write_arg, const MockRead& read_arg,
9533 int expected_rv_arg, const MockWrite* extra_write_arg,
[email protected]f871ee152012-07-27 19:02:019534 const MockRead* extra_read_arg)
[email protected]044de0642010-06-17 10:42:159535 : write(write_arg),
9536 read(read_arg),
9537 expected_rv(expected_rv_arg),
9538 extra_write(extra_write_arg),
9539 extra_read(extra_read_arg) {
9540 }
9541 MockWrite write;
9542 MockRead read;
9543 int expected_rv;
9544 const MockWrite* extra_write;
9545 const MockRead* extra_read;
9546 };
9547
9548 static const int kNoSSL = 500;
9549
9550 struct TestConfig {
thestig9d3bb0c2015-01-24 00:49:519551 const char* const proxy_url;
[email protected]044de0642010-06-17 10:42:159552 AuthTiming proxy_auth_timing;
9553 int proxy_auth_rv;
thestig9d3bb0c2015-01-24 00:49:519554 const char* const server_url;
[email protected]044de0642010-06-17 10:42:159555 AuthTiming server_auth_timing;
9556 int server_auth_rv;
9557 int num_auth_rounds;
9558 int first_ssl_round;
9559 TestRound rounds[3];
9560 } test_configs[] = {
9561 // Non-authenticating HTTP server with a direct connection.
9562 { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL,
9563 { TestRound(kGet, kSuccess, OK)}},
9564 // Authenticating HTTP server with a direct connection.
9565 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL,
9566 { TestRound(kGet, kServerChallenge, OK),
9567 TestRound(kGetAuth, kSuccess, OK)}},
9568 { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL,
9569 { TestRound(kGet, kServerChallenge, OK),
9570 TestRound(kGetAuth, kFailure, kAuthErr)}},
9571 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL,
9572 { TestRound(kGet, kServerChallenge, OK),
9573 TestRound(kGetAuth, kSuccess, OK)}},
9574 { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL,
9575 { TestRound(kGet, kServerChallenge, OK),
9576 TestRound(kGetAuth, kFailure, kAuthErr)}},
9577 // Non-authenticating HTTP server through a non-authenticating proxy.
9578 { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL,
9579 { TestRound(kGetProxy, kSuccess, OK)}},
9580 // Authenticating HTTP server through a non-authenticating proxy.
9581 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL,
9582 { TestRound(kGetProxy, kServerChallenge, OK),
9583 TestRound(kGetAuthThroughProxy, kSuccess, OK)}},
9584 { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL,
9585 { TestRound(kGetProxy, kServerChallenge, OK),
9586 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}},
9587 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL,
9588 { TestRound(kGetProxy, kServerChallenge, OK),
9589 TestRound(kGetAuthThroughProxy, kSuccess, OK)}},
9590 { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL,
9591 { TestRound(kGetProxy, kServerChallenge, OK),
9592 TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}},
9593 // Non-authenticating HTTP server through an authenticating proxy.
9594 { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL,
9595 { TestRound(kGetProxy, kProxyChallenge, OK),
9596 TestRound(kGetProxyAuth, kSuccess, OK)}},
9597 { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL,
9598 { TestRound(kGetProxy, kProxyChallenge, OK),
9599 TestRound(kGetProxyAuth, kFailure, kAuthErr)}},
9600 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL,
9601 { TestRound(kGetProxy, kProxyChallenge, OK),
9602 TestRound(kGetProxyAuth, kSuccess, OK)}},
9603 { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL,
9604 { TestRound(kGetProxy, kProxyChallenge, OK),
9605 TestRound(kGetProxyAuth, kFailure, kAuthErr)}},
9606 // Authenticating HTTP server through an authenticating proxy.
9607 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL,
9608 { TestRound(kGetProxy, kProxyChallenge, OK),
9609 TestRound(kGetProxyAuth, kServerChallenge, OK),
9610 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9611 { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL,
9612 { TestRound(kGetProxy, kProxyChallenge, OK),
9613 TestRound(kGetProxyAuth, kServerChallenge, OK),
9614 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9615 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL,
9616 { TestRound(kGetProxy, kProxyChallenge, OK),
9617 TestRound(kGetProxyAuth, kServerChallenge, OK),
9618 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9619 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL,
9620 { TestRound(kGetProxy, kProxyChallenge, OK),
9621 TestRound(kGetProxyAuth, kServerChallenge, OK),
9622 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9623 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL,
9624 { TestRound(kGetProxy, kProxyChallenge, OK),
9625 TestRound(kGetProxyAuth, kServerChallenge, OK),
9626 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9627 { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL,
9628 { TestRound(kGetProxy, kProxyChallenge, OK),
9629 TestRound(kGetProxyAuth, kServerChallenge, OK),
9630 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9631 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL,
9632 { TestRound(kGetProxy, kProxyChallenge, OK),
9633 TestRound(kGetProxyAuth, kServerChallenge, OK),
9634 TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}},
9635 { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL,
9636 { TestRound(kGetProxy, kProxyChallenge, OK),
9637 TestRound(kGetProxyAuth, kServerChallenge, OK),
9638 TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}},
9639 // Non-authenticating HTTPS server with a direct connection.
9640 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0,
9641 { TestRound(kGet, kSuccess, OK)}},
9642 // Authenticating HTTPS server with a direct connection.
9643 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0,
9644 { TestRound(kGet, kServerChallenge, OK),
9645 TestRound(kGetAuth, kSuccess, OK)}},
9646 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0,
9647 { TestRound(kGet, kServerChallenge, OK),
9648 TestRound(kGetAuth, kFailure, kAuthErr)}},
9649 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0,
9650 { TestRound(kGet, kServerChallenge, OK),
9651 TestRound(kGetAuth, kSuccess, OK)}},
9652 { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0,
9653 { TestRound(kGet, kServerChallenge, OK),
9654 TestRound(kGetAuth, kFailure, kAuthErr)}},
9655 // Non-authenticating HTTPS server with a non-authenticating proxy.
9656 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0,
9657 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}},
9658 // Authenticating HTTPS server through a non-authenticating proxy.
9659 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0,
9660 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9661 TestRound(kGetAuth, kSuccess, OK)}},
9662 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0,
9663 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9664 TestRound(kGetAuth, kFailure, kAuthErr)}},
9665 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0,
9666 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9667 TestRound(kGetAuth, kSuccess, OK)}},
9668 { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0,
9669 { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge),
9670 TestRound(kGetAuth, kFailure, kAuthErr)}},
9671 // Non-Authenticating HTTPS server through an authenticating proxy.
9672 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1,
9673 { TestRound(kConnect, kProxyChallenge, OK),
9674 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}},
9675 { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL,
9676 { TestRound(kConnect, kProxyChallenge, OK),
9677 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}},
9678 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1,
9679 { TestRound(kConnect, kProxyChallenge, OK),
9680 TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}},
9681 { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL,
9682 { TestRound(kConnect, kProxyChallenge, OK),
9683 TestRound(kConnectProxyAuth, kFailure, kAuthErr)}},
9684 // Authenticating HTTPS server through an authenticating proxy.
9685 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1,
9686 { TestRound(kConnect, kProxyChallenge, OK),
9687 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9688 &kGet, &kServerChallenge),
9689 TestRound(kGetAuth, kSuccess, OK)}},
9690 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1,
9691 { TestRound(kConnect, kProxyChallenge, OK),
9692 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9693 &kGet, &kServerChallenge),
9694 TestRound(kGetAuth, kFailure, kAuthErr)}},
9695 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1,
9696 { TestRound(kConnect, kProxyChallenge, OK),
9697 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9698 &kGet, &kServerChallenge),
9699 TestRound(kGetAuth, kSuccess, OK)}},
9700 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1,
9701 { TestRound(kConnect, kProxyChallenge, OK),
9702 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9703 &kGet, &kServerChallenge),
9704 TestRound(kGetAuth, kFailure, kAuthErr)}},
9705 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1,
9706 { TestRound(kConnect, kProxyChallenge, OK),
9707 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9708 &kGet, &kServerChallenge),
9709 TestRound(kGetAuth, kSuccess, OK)}},
9710 { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1,
9711 { TestRound(kConnect, kProxyChallenge, OK),
9712 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9713 &kGet, &kServerChallenge),
9714 TestRound(kGetAuth, kFailure, kAuthErr)}},
9715 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1,
9716 { TestRound(kConnect, kProxyChallenge, OK),
9717 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9718 &kGet, &kServerChallenge),
9719 TestRound(kGetAuth, kSuccess, OK)}},
9720 { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1,
9721 { TestRound(kConnect, kProxyChallenge, OK),
9722 TestRound(kConnectProxyAuth, kProxyConnected, OK,
9723 &kGet, &kServerChallenge),
9724 TestRound(kGetAuth, kFailure, kAuthErr)}},
9725 };
9726
viettrungluue4a8b882014-10-16 06:17:389727 for (size_t i = 0; i < arraysize(test_configs); ++i) {
[email protected]2d01c262011-08-11 23:07:089728 HttpAuthHandlerMock::Factory* auth_factory(
9729 new HttpAuthHandlerMock::Factory());
[email protected]bb88e1d32013-05-03 23:11:079730 session_deps_.http_auth_handler_factory.reset(auth_factory);
[email protected]044de0642010-06-17 10:42:159731 const TestConfig& test_config = test_configs[i];
[email protected]65d34382010-07-01 18:12:269732
9733 // Set up authentication handlers as necessary.
[email protected]044de0642010-06-17 10:42:159734 if (test_config.proxy_auth_timing != AUTH_NONE) {
[email protected]2d01c262011-08-11 23:07:089735 for (int n = 0; n < 2; n++) {
9736 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
9737 std::string auth_challenge = "Mock realm=proxy";
9738 GURL origin(test_config.proxy_url);
[email protected]df41d0d82014-03-13 00:43:249739 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9740 auth_challenge.end());
[email protected]2d01c262011-08-11 23:07:089741 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY,
9742 origin, BoundNetLog());
9743 auth_handler->SetGenerateExpectation(
9744 test_config.proxy_auth_timing == AUTH_ASYNC,
9745 test_config.proxy_auth_rv);
9746 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
9747 }
[email protected]044de0642010-06-17 10:42:159748 }
9749 if (test_config.server_auth_timing != AUTH_NONE) {
[email protected]3fd9dae2010-06-21 11:39:009750 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
[email protected]044de0642010-06-17 10:42:159751 std::string auth_challenge = "Mock realm=server";
9752 GURL origin(test_config.server_url);
[email protected]df41d0d82014-03-13 00:43:249753 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9754 auth_challenge.end());
[email protected]044de0642010-06-17 10:42:159755 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
9756 origin, BoundNetLog());
9757 auth_handler->SetGenerateExpectation(
9758 test_config.server_auth_timing == AUTH_ASYNC,
9759 test_config.server_auth_rv);
[email protected]2d01c262011-08-11 23:07:089760 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
[email protected]044de0642010-06-17 10:42:159761 }
9762 if (test_config.proxy_url) {
[email protected]bb88e1d32013-05-03 23:11:079763 session_deps_.proxy_service.reset(
[email protected]6104ea5d2011-04-27 21:37:129764 ProxyService::CreateFixed(test_config.proxy_url));
[email protected]044de0642010-06-17 10:42:159765 } else {
[email protected]bb88e1d32013-05-03 23:11:079766 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
[email protected]044de0642010-06-17 10:42:159767 }
9768
9769 HttpRequestInfo request;
9770 request.method = "GET";
9771 request.url = GURL(test_config.server_url);
9772 request.load_flags = 0;
9773
[email protected]bb88e1d32013-05-03 23:11:079774 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
dcheng48459ac22014-08-26 00:46:419775 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
[email protected]044de0642010-06-17 10:42:159776
9777 for (int round = 0; round < test_config.num_auth_rounds; ++round) {
9778 const TestRound& read_write_round = test_config.rounds[round];
9779
9780 // Set up expected reads and writes.
9781 MockRead reads[2];
9782 reads[0] = read_write_round.read;
9783 size_t length_reads = 1;
9784 if (read_write_round.extra_read) {
9785 reads[1] = *read_write_round.extra_read;
9786 length_reads = 2;
9787 }
9788
9789 MockWrite writes[2];
9790 writes[0] = read_write_round.write;
9791 size_t length_writes = 1;
9792 if (read_write_round.extra_write) {
9793 writes[1] = *read_write_round.extra_write;
9794 length_writes = 2;
9795 }
9796 StaticSocketDataProvider data_provider(
9797 reads, length_reads, writes, length_writes);
[email protected]bb88e1d32013-05-03 23:11:079798 session_deps_.socket_factory->AddSocketDataProvider(&data_provider);
[email protected]044de0642010-06-17 10:42:159799
9800 // Add an SSL sequence if necessary.
[email protected]8ddf8322012-02-23 18:08:069801 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK);
[email protected]044de0642010-06-17 10:42:159802 if (round >= test_config.first_ssl_round)
[email protected]bb88e1d32013-05-03 23:11:079803 session_deps_.socket_factory->AddSSLSocketDataProvider(
[email protected]044de0642010-06-17 10:42:159804 &ssl_socket_data_provider);
9805
9806 // Start or restart the transaction.
[email protected]49639fa2011-12-20 23:22:419807 TestCompletionCallback callback;
[email protected]044de0642010-06-17 10:42:159808 int rv;
9809 if (round == 0) {
[email protected]49639fa2011-12-20 23:22:419810 rv = trans.Start(&request, callback.callback(), BoundNetLog());
[email protected]044de0642010-06-17 10:42:159811 } else {
[email protected]49639fa2011-12-20 23:22:419812 rv = trans.RestartWithAuth(
9813 AuthCredentials(kFoo, kBar), callback.callback());
[email protected]044de0642010-06-17 10:42:159814 }
9815 if (rv == ERR_IO_PENDING)
9816 rv = callback.WaitForResult();
9817
9818 // Compare results with expected data.
9819 EXPECT_EQ(read_write_round.expected_rv, rv);
[email protected]0b0bf032010-09-21 18:08:509820 const HttpResponseInfo* response = trans.GetResponseInfo();
[email protected]044de0642010-06-17 10:42:159821 if (read_write_round.expected_rv == OK) {
[email protected]fe2255a2011-09-20 19:37:509822 ASSERT_TRUE(response != NULL);
[email protected]044de0642010-06-17 10:42:159823 } else {
9824 EXPECT_TRUE(response == NULL);
9825 EXPECT_EQ(round + 1, test_config.num_auth_rounds);
9826 continue;
9827 }
9828 if (round + 1 < test_config.num_auth_rounds) {
9829 EXPECT_FALSE(response->auth_challenge.get() == NULL);
9830 } else {
9831 EXPECT_TRUE(response->auth_challenge.get() == NULL);
9832 }
9833 }
[email protected]e5ae96a2010-04-14 20:12:459834 }
9835}
9836
[email protected]23e482282013-06-14 16:08:029837TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) {
[email protected]c871bce92010-07-15 21:51:149838 // Do multi-round authentication and make sure it works correctly.
[email protected]c871bce92010-07-15 21:51:149839 HttpAuthHandlerMock::Factory* auth_factory(
9840 new HttpAuthHandlerMock::Factory());
[email protected]bb88e1d32013-05-03 23:11:079841 session_deps_.http_auth_handler_factory.reset(auth_factory);
9842 session_deps_.proxy_service.reset(ProxyService::CreateDirect());
9843 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1");
9844 session_deps_.host_resolver->set_synchronous_mode(true);
[email protected]c871bce92010-07-15 21:51:149845
9846 HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock());
9847 auth_handler->set_connection_based(true);
9848 std::string auth_challenge = "Mock realm=server";
9849 GURL origin("http://www.example.com");
[email protected]df41d0d82014-03-13 00:43:249850 HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(),
9851 auth_challenge.end());
[email protected]c871bce92010-07-15 21:51:149852 auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
9853 origin, BoundNetLog());
[email protected]2d01c262011-08-11 23:07:089854 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER);
[email protected]c871bce92010-07-15 21:51:149855
[email protected]c871bce92010-07-15 21:51:149856 int rv = OK;
9857 const HttpResponseInfo* response = NULL;
9858 HttpRequestInfo request;
9859 request.method = "GET";
9860 request.url = origin;
9861 request.load_flags = 0;
[email protected]cb9bf6ca2011-01-28 13:15:279862
[email protected]bb88e1d32013-05-03 23:11:079863 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]7ef4cbbb2011-02-06 11:19:109864
9865 // Use a TCP Socket Pool with only one connection per group. This is used
9866 // to validate that the TCP socket is not released to the pool between
9867 // each round of multi-round authentication.
9868 HttpNetworkSessionPeer session_peer(session);
[email protected]ab739042011-04-07 15:22:289869 ClientSocketPoolHistograms transport_pool_histograms("SmallTCP");
9870 TransportClientSocketPool* transport_pool = new TransportClientSocketPool(
[email protected]7ef4cbbb2011-02-06 11:19:109871 50, // Max sockets for pool
9872 1, // Max sockets per group
[email protected]ab739042011-04-07 15:22:289873 &transport_pool_histograms,
[email protected]bb88e1d32013-05-03 23:11:079874 session_deps_.host_resolver.get(),
9875 session_deps_.socket_factory.get(),
9876 session_deps_.net_log);
[email protected]831e4a32013-11-14 02:14:449877 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager(
9878 new MockClientSocketPoolManager);
[email protected]a42dbd142011-11-17 16:42:029879 mock_pool_manager->SetTransportSocketPool(transport_pool);
dchenge3d1ddc2014-10-15 19:30:519880 session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass());
[email protected]7ef4cbbb2011-02-06 11:19:109881
[email protected]262eec82013-03-19 21:01:369882 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:509883 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:419884 TestCompletionCallback callback;
[email protected]c871bce92010-07-15 21:51:149885
9886 const MockWrite kGet(
9887 "GET / HTTP/1.1\r\n"
9888 "Host: www.example.com\r\n"
9889 "Connection: keep-alive\r\n\r\n");
9890 const MockWrite kGetAuth(
9891 "GET / HTTP/1.1\r\n"
9892 "Host: www.example.com\r\n"
9893 "Connection: keep-alive\r\n"
9894 "Authorization: auth_token\r\n\r\n");
9895
9896 const MockRead kServerChallenge(
9897 "HTTP/1.1 401 Unauthorized\r\n"
9898 "WWW-Authenticate: Mock realm=server\r\n"
9899 "Content-Type: text/html; charset=iso-8859-1\r\n"
9900 "Content-Length: 14\r\n\r\n"
9901 "Unauthorized\r\n");
9902 const MockRead kSuccess(
9903 "HTTP/1.1 200 OK\r\n"
9904 "Content-Type: text/html; charset=iso-8859-1\r\n"
9905 "Content-Length: 3\r\n\r\n"
9906 "Yes");
9907
9908 MockWrite writes[] = {
9909 // First round
9910 kGet,
9911 // Second round
9912 kGetAuth,
9913 // Third round
9914 kGetAuth,
[email protected]eca50e122010-09-11 14:03:309915 // Fourth round
[email protected]7ef4cbbb2011-02-06 11:19:109916 kGetAuth,
9917 // Competing request
9918 kGet,
[email protected]c871bce92010-07-15 21:51:149919 };
9920 MockRead reads[] = {
9921 // First round
9922 kServerChallenge,
9923 // Second round
9924 kServerChallenge,
9925 // Third round
[email protected]eca50e122010-09-11 14:03:309926 kServerChallenge,
9927 // Fourth round
[email protected]c871bce92010-07-15 21:51:149928 kSuccess,
[email protected]7ef4cbbb2011-02-06 11:19:109929 // Competing response
9930 kSuccess,
[email protected]c871bce92010-07-15 21:51:149931 };
9932 StaticSocketDataProvider data_provider(reads, arraysize(reads),
9933 writes, arraysize(writes));
[email protected]bb88e1d32013-05-03 23:11:079934 session_deps_.socket_factory->AddSocketDataProvider(&data_provider);
[email protected]c871bce92010-07-15 21:51:149935
thestig9d3bb0c2015-01-24 00:49:519936 const char kSocketGroup[] = "www.example.com:80";
[email protected]7ef4cbbb2011-02-06 11:19:109937
9938 // First round of authentication.
[email protected]c871bce92010-07-15 21:51:149939 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419940 rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]c871bce92010-07-15 21:51:149941 if (rv == ERR_IO_PENDING)
9942 rv = callback.WaitForResult();
9943 EXPECT_EQ(OK, rv);
9944 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509945 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149946 EXPECT_FALSE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289947 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:149948
[email protected]7ef4cbbb2011-02-06 11:19:109949 // In between rounds, another request comes in for the same domain.
9950 // It should not be able to grab the TCP socket that trans has already
9951 // claimed.
9952 scoped_ptr<HttpTransaction> trans_compete(
[email protected]90499482013-06-01 00:39:509953 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:419954 TestCompletionCallback callback_compete;
9955 rv = trans_compete->Start(
9956 &request, callback_compete.callback(), BoundNetLog());
[email protected]7ef4cbbb2011-02-06 11:19:109957 EXPECT_EQ(ERR_IO_PENDING, rv);
9958 // callback_compete.WaitForResult at this point would stall forever,
9959 // since the HttpNetworkTransaction does not release the request back to
9960 // the pool until after authentication completes.
9961
9962 // Second round of authentication.
[email protected]c871bce92010-07-15 21:51:149963 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419964 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback());
[email protected]c871bce92010-07-15 21:51:149965 if (rv == ERR_IO_PENDING)
9966 rv = callback.WaitForResult();
9967 EXPECT_EQ(OK, rv);
9968 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509969 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149970 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289971 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:149972
[email protected]7ef4cbbb2011-02-06 11:19:109973 // Third round of authentication.
[email protected]c871bce92010-07-15 21:51:149974 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419975 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
[email protected]c871bce92010-07-15 21:51:149976 if (rv == ERR_IO_PENDING)
9977 rv = callback.WaitForResult();
9978 EXPECT_EQ(OK, rv);
9979 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509980 ASSERT_TRUE(response != NULL);
[email protected]c871bce92010-07-15 21:51:149981 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289982 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]eca50e122010-09-11 14:03:309983
[email protected]7ef4cbbb2011-02-06 11:19:109984 // Fourth round of authentication, which completes successfully.
[email protected]eca50e122010-09-11 14:03:309985 auth_handler->SetGenerateExpectation(false, OK);
[email protected]49639fa2011-12-20 23:22:419986 rv = trans->RestartWithAuth(AuthCredentials(), callback.callback());
[email protected]eca50e122010-09-11 14:03:309987 if (rv == ERR_IO_PENDING)
9988 rv = callback.WaitForResult();
9989 EXPECT_EQ(OK, rv);
9990 response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:509991 ASSERT_TRUE(response != NULL);
[email protected]eca50e122010-09-11 14:03:309992 EXPECT_TRUE(response->auth_challenge.get() == NULL);
[email protected]ab739042011-04-07 15:22:289993 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]7ef4cbbb2011-02-06 11:19:109994
9995 // Read the body since the fourth round was successful. This will also
9996 // release the socket back to the pool.
9997 scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50));
[email protected]90499482013-06-01 00:39:509998 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:109999 if (rv == ERR_IO_PENDING)
10000 rv = callback.WaitForResult();
10001 EXPECT_EQ(3, rv);
[email protected]90499482013-06-01 00:39:5010002 rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:1010003 EXPECT_EQ(0, rv);
10004 // There are still 0 idle sockets, since the trans_compete transaction
10005 // will be handed it immediately after trans releases it to the group.
[email protected]ab739042011-04-07 15:22:2810006 EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]7ef4cbbb2011-02-06 11:19:1010007
10008 // The competing request can now finish. Wait for the headers and then
10009 // read the body.
10010 rv = callback_compete.WaitForResult();
10011 EXPECT_EQ(OK, rv);
[email protected]90499482013-06-01 00:39:5010012 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:1010013 if (rv == ERR_IO_PENDING)
10014 rv = callback.WaitForResult();
10015 EXPECT_EQ(3, rv);
[email protected]90499482013-06-01 00:39:5010016 rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback());
[email protected]7ef4cbbb2011-02-06 11:19:1010017 EXPECT_EQ(0, rv);
10018
10019 // Finally, the socket is released to the group.
[email protected]ab739042011-04-07 15:22:2810020 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup));
[email protected]c871bce92010-07-15 21:51:1410021}
10022
[email protected]65041fa2010-05-21 06:56:5310023// This tests the case that a request is issued via http instead of spdy after
10024// npn is negotiated.
[email protected]23e482282013-06-14 16:08:0210025TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) {
[email protected]d7599122014-05-24 03:37:2310026 session_deps_.use_alternate_protocols = true;
10027 NextProtoVector next_protos;
[email protected]0ce3af82013-07-22 16:17:1610028 next_protos.push_back(kProtoHTTP11);
[email protected]d7599122014-05-24 03:37:2310029 session_deps_.next_protos = next_protos;
10030
[email protected]65041fa2010-05-21 06:56:5310031 HttpRequestInfo request;
10032 request.method = "GET";
10033 request.url = GURL("https://www.google.com/");
10034 request.load_flags = 0;
10035
10036 MockWrite data_writes[] = {
10037 MockWrite("GET / HTTP/1.1\r\n"
10038 "Host: www.google.com\r\n"
10039 "Connection: keep-alive\r\n\r\n"),
10040 };
10041
[email protected]8a0fc822013-06-27 20:52:4310042 std::string alternate_protocol_http_header =
10043 GetAlternateProtocolHttpHeader();
10044
[email protected]65041fa2010-05-21 06:56:5310045 MockRead data_reads[] = {
10046 MockRead("HTTP/1.1 200 OK\r\n"),
[email protected]8a0fc822013-06-27 20:52:4310047 MockRead(alternate_protocol_http_header.c_str()),
[email protected]65041fa2010-05-21 06:56:5310048 MockRead("hello world"),
[email protected]8ddf8322012-02-23 18:08:0610049 MockRead(SYNCHRONOUS, OK),
[email protected]65041fa2010-05-21 06:56:5310050 };
10051
[email protected]8ddf8322012-02-23 18:08:0610052 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]65041fa2010-05-21 06:56:5310053 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
10054 ssl.next_proto = "http/1.1";
[email protected]8e3c78cb2012-03-31 03:58:4610055 ssl.protocol_negotiated = kProtoHTTP11;
[email protected]65041fa2010-05-21 06:56:5310056
[email protected]bb88e1d32013-05-03 23:11:0710057 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]65041fa2010-05-21 06:56:5310058
10059 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
10060 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:0710061 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]65041fa2010-05-21 06:56:5310062
[email protected]49639fa2011-12-20 23:22:4110063 TestCompletionCallback callback;
[email protected]65041fa2010-05-21 06:56:5310064
[email protected]bb88e1d32013-05-03 23:11:0710065 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610066 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010067 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]65041fa2010-05-21 06:56:5310068
[email protected]49639fa2011-12-20 23:22:4110069 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]65041fa2010-05-21 06:56:5310070
10071 EXPECT_EQ(ERR_IO_PENDING, rv);
10072 EXPECT_EQ(OK, callback.WaitForResult());
10073
10074 const HttpResponseInfo* response = trans->GetResponseInfo();
10075 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5010076 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]65041fa2010-05-21 06:56:5310077 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
10078
10079 std::string response_data;
10080 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
10081 EXPECT_EQ("hello world", response_data);
10082
10083 EXPECT_FALSE(response->was_fetched_via_spdy);
10084 EXPECT_TRUE(response->was_npn_negotiated);
[email protected]65041fa2010-05-21 06:56:5310085}
[email protected]26ef6582010-06-24 02:30:4710086
[email protected]23e482282013-06-14 16:08:0210087TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) {
[email protected]26ef6582010-06-24 02:30:4710088 // Simulate the SSL handshake completing with an NPN negotiation
10089 // followed by an immediate server closing of the socket.
10090 // Fix crash: http://crbug.com/46369
[email protected]d7599122014-05-24 03:37:2310091 session_deps_.use_alternate_protocols = true;
10092 session_deps_.next_protos = SpdyNextProtos();
[email protected]26ef6582010-06-24 02:30:4710093
10094 HttpRequestInfo request;
10095 request.method = "GET";
10096 request.url = GURL("https://www.google.com/");
10097 request.load_flags = 0;
10098
[email protected]8ddf8322012-02-23 18:08:0610099 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210100 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0710101 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]26ef6582010-06-24 02:30:4710102
[email protected]cdf8f7e72013-05-23 10:56:4610103 scoped_ptr<SpdyFrame> req(
10104 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]e7f75092010-07-01 22:39:1310105 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
[email protected]26ef6582010-06-24 02:30:4710106
10107 MockRead spdy_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610108 MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately.
[email protected]26ef6582010-06-24 02:30:4710109 };
10110
[email protected]dd54bd82012-07-19 23:44:5710111 DelayedSocketData spdy_data(
10112 0, // don't wait in this case, immediate hangup.
10113 spdy_reads, arraysize(spdy_reads),
10114 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0710115 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]26ef6582010-06-24 02:30:4710116
[email protected]49639fa2011-12-20 23:22:4110117 TestCompletionCallback callback;
[email protected]26ef6582010-06-24 02:30:4710118
[email protected]bb88e1d32013-05-03 23:11:0710119 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610120 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010121 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]26ef6582010-06-24 02:30:4710122
[email protected]49639fa2011-12-20 23:22:4110123 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]26ef6582010-06-24 02:30:4710124 EXPECT_EQ(ERR_IO_PENDING, rv);
10125 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
[email protected]26ef6582010-06-24 02:30:4710126}
[email protected]65d34382010-07-01 18:12:2610127
[email protected]795cbf82013-07-22 09:37:2710128// A subclass of HttpAuthHandlerMock that records the request URL when
10129// it gets it. This is needed since the auth handler may get destroyed
10130// before we get a chance to query it.
10131class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock {
10132 public:
10133 explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {}
10134
dchengb03027d2014-10-21 12:00:2010135 ~UrlRecordingHttpAuthHandlerMock() override {}
[email protected]795cbf82013-07-22 09:37:2710136
10137 protected:
dchengb03027d2014-10-21 12:00:2010138 int GenerateAuthTokenImpl(const AuthCredentials* credentials,
10139 const HttpRequestInfo* request,
10140 const CompletionCallback& callback,
10141 std::string* auth_token) override {
[email protected]795cbf82013-07-22 09:37:2710142 *url_ = request->url;
10143 return HttpAuthHandlerMock::GenerateAuthTokenImpl(
10144 credentials, request, callback, auth_token);
10145 }
10146
10147 private:
10148 GURL* url_;
10149};
10150
[email protected]23e482282013-06-14 16:08:0210151TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) {
[email protected]f45c1ee2010-08-03 00:54:3010152 // This test ensures that the URL passed into the proxy is upgraded
10153 // to https when doing an Alternate Protocol upgrade.
[email protected]d7599122014-05-24 03:37:2310154 session_deps_.use_alternate_protocols = true;
10155 session_deps_.next_protos = SpdyNextProtos();
[email protected]f45c1ee2010-08-03 00:54:3010156
[email protected]bb88e1d32013-05-03 23:11:0710157 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010158 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
10159 CapturingNetLog net_log;
[email protected]bb88e1d32013-05-03 23:11:0710160 session_deps_.net_log = &net_log;
[email protected]795cbf82013-07-22 09:37:2710161 GURL request_url;
10162 {
10163 HttpAuthHandlerMock::Factory* auth_factory =
10164 new HttpAuthHandlerMock::Factory();
10165 UrlRecordingHttpAuthHandlerMock* auth_handler =
10166 new UrlRecordingHttpAuthHandlerMock(&request_url);
10167 auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY);
10168 auth_factory->set_do_init_from_challenge(true);
10169 session_deps_.http_auth_handler_factory.reset(auth_factory);
10170 }
[email protected]f45c1ee2010-08-03 00:54:3010171
10172 HttpRequestInfo request;
10173 request.method = "GET";
10174 request.url = GURL("http://www.google.com");
10175 request.load_flags = 0;
10176
10177 // First round goes unauthenticated through the proxy.
10178 MockWrite data_writes_1[] = {
10179 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
10180 "Host: www.google.com\r\n"
10181 "Proxy-Connection: keep-alive\r\n"
10182 "\r\n"),
10183 };
10184 MockRead data_reads_1[] = {
[email protected]8ddf8322012-02-23 18:08:0610185 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
bnc33b8cef42014-11-19 17:30:3810186 MockRead("HTTP/1.1 200 OK\r\n"),
10187 MockRead("Alternate-Protocol: 443:"),
10188 MockRead(GetAlternateProtocolFromParam()),
10189 MockRead("\r\n"),
10190 MockRead("Proxy-Connection: close\r\n"),
10191 MockRead("\r\n"),
[email protected]f45c1ee2010-08-03 00:54:3010192 };
10193 StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1),
10194 data_writes_1, arraysize(data_writes_1));
10195
10196 // Second round tries to tunnel to www.google.com due to the
10197 // Alternate-Protocol announcement in the first round. It fails due
10198 // to a proxy authentication challenge.
[email protected]394816e92010-08-03 07:38:5910199 // After the failure, a tunnel is established to www.google.com using
10200 // Proxy-Authorization headers. There is then a SPDY request round.
10201 //
[email protected]fe3b7dc2012-02-03 19:52:0910202 // NOTE: Despite the "Proxy-Connection: Close", these are done on the
10203 // same MockTCPClientSocket since the underlying HttpNetworkClientSocket
10204 // does a Disconnect and Connect on the same socket, rather than trying
10205 // to obtain a new one.
10206 //
[email protected]394816e92010-08-03 07:38:5910207 // NOTE: Originally, the proxy response to the second CONNECT request
10208 // simply returned another 407 so the unit test could skip the SSL connection
10209 // establishment and SPDY framing issues. Alas, the
10210 // retry-http-when-alternate-protocol fails logic kicks in, which was more
[email protected]f45c1ee2010-08-03 00:54:3010211 // complicated to set up expectations for than the SPDY session.
[email protected]394816e92010-08-03 07:38:5910212
[email protected]cdf8f7e72013-05-23 10:56:4610213 scoped_ptr<SpdyFrame> req(
10214 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
[email protected]23e482282013-06-14 16:08:0210215 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
10216 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]f45c1ee2010-08-03 00:54:3010217
[email protected]394816e92010-08-03 07:38:5910218 MockWrite data_writes_2[] = {
10219 // First connection attempt without Proxy-Authorization.
10220 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10221 "Host: www.google.com\r\n"
10222 "Proxy-Connection: keep-alive\r\n"
10223 "\r\n"),
10224
10225 // Second connection attempt with Proxy-Authorization.
[email protected]f45c1ee2010-08-03 00:54:3010226 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10227 "Host: www.google.com\r\n"
10228 "Proxy-Connection: keep-alive\r\n"
10229 "Proxy-Authorization: auth_token\r\n"
10230 "\r\n"),
[email protected]f45c1ee2010-08-03 00:54:3010231
[email protected]394816e92010-08-03 07:38:5910232 // SPDY request
10233 CreateMockWrite(*req),
[email protected]f45c1ee2010-08-03 00:54:3010234 };
[email protected]394816e92010-08-03 07:38:5910235 const char kRejectConnectResponse[] = ("HTTP/1.1 407 Unauthorized\r\n"
10236 "Proxy-Authenticate: Mock\r\n"
10237 "Proxy-Connection: close\r\n"
10238 "\r\n");
10239 const char kAcceptConnectResponse[] = "HTTP/1.1 200 Connected\r\n\r\n";
10240 MockRead data_reads_2[] = {
10241 // First connection attempt fails
[email protected]8ddf8322012-02-23 18:08:0610242 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, 1),
10243 MockRead(ASYNC, kRejectConnectResponse,
[email protected]394816e92010-08-03 07:38:5910244 arraysize(kRejectConnectResponse) - 1, 1),
10245
10246 // Second connection attempt passes
[email protected]8ddf8322012-02-23 18:08:0610247 MockRead(ASYNC, kAcceptConnectResponse,
[email protected]fe3b7dc2012-02-03 19:52:0910248 arraysize(kAcceptConnectResponse) -1, 4),
[email protected]394816e92010-08-03 07:38:5910249
10250 // SPDY response
[email protected]fe3b7dc2012-02-03 19:52:0910251 CreateMockRead(*resp.get(), 6),
10252 CreateMockRead(*data.get(), 6),
[email protected]8ddf8322012-02-23 18:08:0610253 MockRead(ASYNC, 0, 0, 6),
[email protected]394816e92010-08-03 07:38:5910254 };
[email protected]dd54bd82012-07-19 23:44:5710255 OrderedSocketData data_2(
10256 data_reads_2, arraysize(data_reads_2),
10257 data_writes_2, arraysize(data_writes_2));
[email protected]f45c1ee2010-08-03 00:54:3010258
[email protected]8ddf8322012-02-23 18:08:0610259 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210260 ssl.SetNextProto(GetParam());
[email protected]f45c1ee2010-08-03 00:54:3010261
[email protected]d973e99a2012-02-17 21:02:3610262 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING);
[email protected]2d6728692011-03-12 01:39:5510263 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
10264 NULL, 0, NULL, 0);
10265 hanging_non_alternate_protocol_socket.set_connect_data(
10266 never_finishing_connect);
10267
[email protected]bb88e1d32013-05-03 23:11:0710268 session_deps_.socket_factory->AddSocketDataProvider(&data_1);
10269 session_deps_.socket_factory->AddSocketDataProvider(&data_2);
10270 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
10271 session_deps_.socket_factory->AddSocketDataProvider(
[email protected]2d6728692011-03-12 01:39:5510272 &hanging_non_alternate_protocol_socket);
[email protected]bb88e1d32013-05-03 23:11:0710273 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]f45c1ee2010-08-03 00:54:3010274
10275 // First round should work and provide the Alternate-Protocol state.
[email protected]49639fa2011-12-20 23:22:4110276 TestCompletionCallback callback_1;
[email protected]262eec82013-03-19 21:01:3610277 scoped_ptr<HttpTransaction> trans_1(
[email protected]90499482013-06-01 00:39:5010278 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:4110279 int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog());
[email protected]f45c1ee2010-08-03 00:54:3010280 EXPECT_EQ(ERR_IO_PENDING, rv);
10281 EXPECT_EQ(OK, callback_1.WaitForResult());
10282
10283 // Second round should attempt a tunnel connect and get an auth challenge.
[email protected]49639fa2011-12-20 23:22:4110284 TestCompletionCallback callback_2;
[email protected]262eec82013-03-19 21:01:3610285 scoped_ptr<HttpTransaction> trans_2(
[email protected]90499482013-06-01 00:39:5010286 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]49639fa2011-12-20 23:22:4110287 rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog());
[email protected]f45c1ee2010-08-03 00:54:3010288 EXPECT_EQ(ERR_IO_PENDING, rv);
10289 EXPECT_EQ(OK, callback_2.WaitForResult());
10290 const HttpResponseInfo* response = trans_2->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010291 ASSERT_TRUE(response != NULL);
[email protected]f45c1ee2010-08-03 00:54:3010292 ASSERT_FALSE(response->auth_challenge.get() == NULL);
10293
10294 // Restart with auth. Tunnel should work and response received.
[email protected]49639fa2011-12-20 23:22:4110295 TestCompletionCallback callback_3;
10296 rv = trans_2->RestartWithAuth(
10297 AuthCredentials(kFoo, kBar), callback_3.callback());
[email protected]f45c1ee2010-08-03 00:54:3010298 EXPECT_EQ(ERR_IO_PENDING, rv);
10299 EXPECT_EQ(OK, callback_3.WaitForResult());
10300
10301 // After all that work, these two lines (or actually, just the scheme) are
10302 // what this test is all about. Make sure it happens correctly.
[email protected]f45c1ee2010-08-03 00:54:3010303 EXPECT_EQ("https", request_url.scheme());
10304 EXPECT_EQ("www.google.com", request_url.host());
10305
[email protected]029c83b62013-01-24 05:28:2010306 LoadTimingInfo load_timing_info;
10307 EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info));
10308 TestLoadTimingNotReusedWithPac(load_timing_info,
10309 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]8e6441ca2010-08-19 05:56:3810310}
10311
10312// Test that if we cancel the transaction as the connection is completing, that
10313// everything tears down correctly.
[email protected]23e482282013-06-14 16:08:0210314TEST_P(HttpNetworkTransactionTest, SimpleCancel) {
[email protected]8e6441ca2010-08-19 05:56:3810315 // Setup everything about the connection to complete synchronously, so that
10316 // after calling HttpNetworkTransaction::Start, the only thing we're waiting
10317 // for is the callback from the HttpStreamRequest.
10318 // Then cancel the transaction.
10319 // Verify that we don't crash.
[email protected]d973e99a2012-02-17 21:02:3610320 MockConnect mock_connect(SYNCHRONOUS, OK);
[email protected]8e6441ca2010-08-19 05:56:3810321 MockRead data_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610322 MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"),
10323 MockRead(SYNCHRONOUS, "hello world"),
10324 MockRead(SYNCHRONOUS, OK),
[email protected]8e6441ca2010-08-19 05:56:3810325 };
10326
[email protected]8e6441ca2010-08-19 05:56:3810327 HttpRequestInfo request;
10328 request.method = "GET";
10329 request.url = GURL("http://www.google.com/");
10330 request.load_flags = 0;
10331
[email protected]bb88e1d32013-05-03 23:11:0710332 session_deps_.host_resolver->set_synchronous_mode(true);
[email protected]3fe8d2f82013-10-17 08:56:0710333 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]cb9bf6ca2011-01-28 13:15:2710334 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4110335 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]cb9bf6ca2011-01-28 13:15:2710336
[email protected]8e6441ca2010-08-19 05:56:3810337 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10338 data.set_connect_data(mock_connect);
[email protected]bb88e1d32013-05-03 23:11:0710339 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]8e6441ca2010-08-19 05:56:3810340
[email protected]49639fa2011-12-20 23:22:4110341 TestCompletionCallback callback;
[email protected]8e6441ca2010-08-19 05:56:3810342
[email protected]333bdf62012-06-08 22:57:2910343 CapturingBoundNetLog log;
[email protected]49639fa2011-12-20 23:22:4110344 int rv = trans->Start(&request, callback.callback(), log.bound());
[email protected]8e6441ca2010-08-19 05:56:3810345 EXPECT_EQ(ERR_IO_PENDING, rv);
10346 trans.reset(); // Cancel the transaction here.
10347
[email protected]2da659e2013-05-23 20:51:3410348 base::MessageLoop::current()->RunUntilIdle();
[email protected]f45c1ee2010-08-03 00:54:3010349}
10350
[email protected]ecab6e052014-05-16 14:58:1210351// Test that if a transaction is cancelled after receiving the headers, the
10352// stream is drained properly and added back to the socket pool. The main
10353// purpose of this test is to make sure that an HttpStreamParser can be read
10354// from after the HttpNetworkTransaction and the objects it owns have been
10355// deleted.
10356// See http://crbug.com/368418
10357TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) {
10358 MockRead data_reads[] = {
10359 MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"),
10360 MockRead(ASYNC, "Content-Length: 2\r\n"),
10361 MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"),
10362 MockRead(ASYNC, "1"),
10363 // 2 async reads are necessary to trigger a ReadResponseBody call after the
10364 // HttpNetworkTransaction has been deleted.
10365 MockRead(ASYNC, "2"),
10366 MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this.
10367 };
10368 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
10369 session_deps_.socket_factory->AddSocketDataProvider(&data);
10370
10371 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
10372
10373 {
10374 HttpRequestInfo request;
10375 request.method = "GET";
10376 request.url = GURL("http://www.google.com/");
10377 request.load_flags = 0;
10378
dcheng48459ac22014-08-26 00:46:4110379 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
[email protected]ecab6e052014-05-16 14:58:1210380 TestCompletionCallback callback;
10381
10382 int rv = trans.Start(&request, callback.callback(), BoundNetLog());
10383 EXPECT_EQ(ERR_IO_PENDING, rv);
10384 callback.WaitForResult();
10385
10386 const HttpResponseInfo* response = trans.GetResponseInfo();
10387 ASSERT_TRUE(response != NULL);
10388 EXPECT_TRUE(response->headers.get() != NULL);
10389 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
10390
10391 // The transaction and HttpRequestInfo are deleted.
10392 }
10393
10394 // Let the HttpResponseBodyDrainer drain the socket.
10395 base::MessageLoop::current()->RunUntilIdle();
10396
10397 // Socket should now be idle, waiting to be reused.
dcheng48459ac22014-08-26 00:46:4110398 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]ecab6e052014-05-16 14:58:1210399}
10400
[email protected]76a505b2010-08-25 06:23:0010401// Test a basic GET request through a proxy.
[email protected]23e482282013-06-14 16:08:0210402TEST_P(HttpNetworkTransactionTest, ProxyGet) {
[email protected]bb88e1d32013-05-03 23:11:0710403 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010404 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910405 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710406 session_deps_.net_log = log.bound().net_log();
10407 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010408
[email protected]76a505b2010-08-25 06:23:0010409 HttpRequestInfo request;
10410 request.method = "GET";
10411 request.url = GURL("http://www.google.com/");
10412
10413 MockWrite data_writes1[] = {
10414 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
10415 "Host: www.google.com\r\n"
10416 "Proxy-Connection: keep-alive\r\n\r\n"),
10417 };
10418
10419 MockRead data_reads1[] = {
10420 MockRead("HTTP/1.1 200 OK\r\n"),
10421 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
10422 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610423 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:0010424 };
10425
10426 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10427 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710428 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]76a505b2010-08-25 06:23:0010429
[email protected]49639fa2011-12-20 23:22:4110430 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010431
[email protected]262eec82013-03-19 21:01:3610432 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010433 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]597a1ab2014-06-26 08:12:2710434 BeforeProxyHeadersSentHandler proxy_headers_handler;
10435 trans->SetBeforeProxyHeadersSentCallback(
10436 base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent,
10437 base::Unretained(&proxy_headers_handler)));
[email protected]0b0bf032010-09-21 18:08:5010438
[email protected]49639fa2011-12-20 23:22:4110439 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010440 EXPECT_EQ(ERR_IO_PENDING, rv);
10441
10442 rv = callback1.WaitForResult();
10443 EXPECT_EQ(OK, rv);
10444
10445 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010446 ASSERT_TRUE(response != NULL);
[email protected]76a505b2010-08-25 06:23:0010447
10448 EXPECT_TRUE(response->headers->IsKeepAlive());
10449 EXPECT_EQ(200, response->headers->response_code());
10450 EXPECT_EQ(100, response->headers->GetContentLength());
10451 EXPECT_TRUE(response->was_fetched_via_proxy);
[email protected]d8fc4722014-06-13 13:17:1510452 EXPECT_TRUE(
10453 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70")));
[email protected]597a1ab2014-06-26 08:12:2710454 EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent());
10455 EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri());
[email protected]76a505b2010-08-25 06:23:0010456 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
[email protected]029c83b62013-01-24 05:28:2010457
10458 LoadTimingInfo load_timing_info;
10459 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
10460 TestLoadTimingNotReusedWithPac(load_timing_info,
10461 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
[email protected]76a505b2010-08-25 06:23:0010462}
10463
10464// Test a basic HTTPS GET request through a proxy.
[email protected]23e482282013-06-14 16:08:0210465TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) {
[email protected]bb88e1d32013-05-03 23:11:0710466 session_deps_.proxy_service.reset(
[email protected]029c83b62013-01-24 05:28:2010467 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910468 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710469 session_deps_.net_log = log.bound().net_log();
10470 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010471
[email protected]76a505b2010-08-25 06:23:0010472 HttpRequestInfo request;
10473 request.method = "GET";
10474 request.url = GURL("https://www.google.com/");
10475
10476 // Since we have proxy, should try to establish tunnel.
10477 MockWrite data_writes1[] = {
10478 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10479 "Host: www.google.com\r\n"
10480 "Proxy-Connection: keep-alive\r\n\r\n"),
10481
10482 MockWrite("GET / HTTP/1.1\r\n"
10483 "Host: www.google.com\r\n"
10484 "Connection: keep-alive\r\n\r\n"),
10485 };
10486
10487 MockRead data_reads1[] = {
10488 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
10489
10490 MockRead("HTTP/1.1 200 OK\r\n"),
10491 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
10492 MockRead("Content-Length: 100\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610493 MockRead(SYNCHRONOUS, OK),
[email protected]76a505b2010-08-25 06:23:0010494 };
10495
10496 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10497 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710498 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:0610499 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:0710500 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:0010501
[email protected]49639fa2011-12-20 23:22:4110502 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010503
[email protected]262eec82013-03-19 21:01:3610504 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010505 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:5010506
[email protected]49639fa2011-12-20 23:22:4110507 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010508 EXPECT_EQ(ERR_IO_PENDING, rv);
10509
10510 rv = callback1.WaitForResult();
10511 EXPECT_EQ(OK, rv);
[email protected]f3da152d2012-06-02 01:00:5710512 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:4010513 log.GetEntries(&entries);
[email protected]76a505b2010-08-25 06:23:0010514 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010515 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]76a505b2010-08-25 06:23:0010516 NetLog::PHASE_NONE);
10517 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010518 entries, pos,
[email protected]76a505b2010-08-25 06:23:0010519 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
10520 NetLog::PHASE_NONE);
10521
10522 const HttpResponseInfo* response = trans->GetResponseInfo();
[email protected]fe2255a2011-09-20 19:37:5010523 ASSERT_TRUE(response != NULL);
[email protected]76a505b2010-08-25 06:23:0010524
10525 EXPECT_TRUE(response->headers->IsKeepAlive());
10526 EXPECT_EQ(200, response->headers->response_code());
10527 EXPECT_EQ(100, response->headers->GetContentLength());
10528 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
10529 EXPECT_TRUE(response->was_fetched_via_proxy);
[email protected]d8fc4722014-06-13 13:17:1510530 EXPECT_TRUE(
10531 response->proxy_server.Equals(HostPortPair::FromString("myproxy:70")));
[email protected]029c83b62013-01-24 05:28:2010532
10533 LoadTimingInfo load_timing_info;
10534 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info));
10535 TestLoadTimingNotReusedWithPac(load_timing_info,
10536 CONNECT_TIMING_HAS_SSL_TIMES);
[email protected]76a505b2010-08-25 06:23:0010537}
10538
10539// Test a basic HTTPS GET request through a proxy, but the server hangs up
10540// while establishing the tunnel.
[email protected]23e482282013-06-14 16:08:0210541TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) {
[email protected]bb88e1d32013-05-03 23:11:0710542 session_deps_.proxy_service.reset(ProxyService::CreateFixed("myproxy:70"));
[email protected]333bdf62012-06-08 22:57:2910543 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710544 session_deps_.net_log = log.bound().net_log();
10545 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]76a505b2010-08-25 06:23:0010546
[email protected]76a505b2010-08-25 06:23:0010547 HttpRequestInfo request;
10548 request.method = "GET";
10549 request.url = GURL("https://www.google.com/");
10550
10551 // Since we have proxy, should try to establish tunnel.
10552 MockWrite data_writes1[] = {
10553 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
10554 "Host: www.google.com\r\n"
10555 "Proxy-Connection: keep-alive\r\n\r\n"),
10556
10557 MockWrite("GET / HTTP/1.1\r\n"
10558 "Host: www.google.com\r\n"
10559 "Connection: keep-alive\r\n\r\n"),
10560 };
10561
10562 MockRead data_reads1[] = {
[email protected]8ddf8322012-02-23 18:08:0610563 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
[email protected]76a505b2010-08-25 06:23:0010564 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
[email protected]8ddf8322012-02-23 18:08:0610565 MockRead(ASYNC, 0, 0), // EOF
[email protected]76a505b2010-08-25 06:23:0010566 };
10567
10568 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
10569 data_writes1, arraysize(data_writes1));
[email protected]bb88e1d32013-05-03 23:11:0710570 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8ddf8322012-02-23 18:08:0610571 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]bb88e1d32013-05-03 23:11:0710572 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]76a505b2010-08-25 06:23:0010573
[email protected]49639fa2011-12-20 23:22:4110574 TestCompletionCallback callback1;
[email protected]76a505b2010-08-25 06:23:0010575
[email protected]262eec82013-03-19 21:01:3610576 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010577 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]0b0bf032010-09-21 18:08:5010578
[email protected]49639fa2011-12-20 23:22:4110579 int rv = trans->Start(&request, callback1.callback(), log.bound());
[email protected]76a505b2010-08-25 06:23:0010580 EXPECT_EQ(ERR_IO_PENDING, rv);
10581
10582 rv = callback1.WaitForResult();
10583 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
[email protected]f3da152d2012-06-02 01:00:5710584 net::CapturingNetLog::CapturedEntryList entries;
[email protected]b2fcd0e2010-12-01 15:19:4010585 log.GetEntries(&entries);
[email protected]76a505b2010-08-25 06:23:0010586 size_t pos = ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010587 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
[email protected]76a505b2010-08-25 06:23:0010588 NetLog::PHASE_NONE);
10589 ExpectLogContainsSomewhere(
[email protected]b2fcd0e2010-12-01 15:19:4010590 entries, pos,
[email protected]76a505b2010-08-25 06:23:0010591 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
10592 NetLog::PHASE_NONE);
10593}
10594
[email protected]749eefa82010-09-13 22:14:0310595// Test for crbug.com/55424.
[email protected]23e482282013-06-14 16:08:0210596TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) {
[email protected]cdf8f7e72013-05-23 10:56:4610597 scoped_ptr<SpdyFrame> req(
10598 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
[email protected]749eefa82010-09-13 22:14:0310599 MockWrite spdy_writes[] = { CreateMockWrite(*req) };
10600
[email protected]23e482282013-06-14 16:08:0210601 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
10602 scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]749eefa82010-09-13 22:14:0310603 MockRead spdy_reads[] = {
10604 CreateMockRead(*resp),
10605 CreateMockRead(*data),
[email protected]8ddf8322012-02-23 18:08:0610606 MockRead(ASYNC, 0, 0),
[email protected]749eefa82010-09-13 22:14:0310607 };
10608
[email protected]dd54bd82012-07-19 23:44:5710609 DelayedSocketData spdy_data(
10610 1, // wait for one write to finish before reading.
10611 spdy_reads, arraysize(spdy_reads),
10612 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0710613 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]749eefa82010-09-13 22:14:0310614
[email protected]8ddf8322012-02-23 18:08:0610615 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0210616 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0710617 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]749eefa82010-09-13 22:14:0310618
[email protected]bb88e1d32013-05-03 23:11:0710619 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]749eefa82010-09-13 22:14:0310620
10621 // Set up an initial SpdySession in the pool to reuse.
[email protected]02b0c342010-09-25 21:09:3810622 HostPortPair host_port_pair("www.google.com", 443);
[email protected]e6d017652013-05-17 18:01:4010623 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
[email protected]314b03992014-04-01 01:28:5310624 PRIVACY_MODE_DISABLED);
[email protected]795cbf82013-07-22 09:37:2710625 base::WeakPtr<SpdySession> spdy_session =
[email protected]41d64e82013-07-03 22:44:2610626 CreateInsecureSpdySession(session, key, BoundNetLog());
[email protected]749eefa82010-09-13 22:14:0310627
10628 HttpRequestInfo request;
10629 request.method = "GET";
10630 request.url = GURL("https://www.google.com/");
10631 request.load_flags = 0;
10632
10633 // This is the important line that marks this as a preconnect.
10634 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED;
10635
[email protected]262eec82013-03-19 21:01:3610636 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010637 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]749eefa82010-09-13 22:14:0310638
[email protected]41d64e82013-07-03 22:44:2610639 TestCompletionCallback callback;
[email protected]49639fa2011-12-20 23:22:4110640 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
[email protected]749eefa82010-09-13 22:14:0310641 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4110642 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]749eefa82010-09-13 22:14:0310643}
10644
[email protected]73b8dd222010-11-11 19:55:2410645// Given a net error, cause that error to be returned from the first Write()
10646// call and verify that the HttpTransaction fails with that error.
[email protected]23e482282013-06-14 16:08:0210647void HttpNetworkTransactionTest::CheckErrorIsPassedBack(
[email protected]bb88e1d32013-05-03 23:11:0710648 int error, IoMode mode) {
[email protected]cb9bf6ca2011-01-28 13:15:2710649 net::HttpRequestInfo request_info;
10650 request_info.url = GURL("https://www.example.com/");
10651 request_info.method = "GET";
10652 request_info.load_flags = net::LOAD_NORMAL;
10653
[email protected]8ddf8322012-02-23 18:08:0610654 SSLSocketDataProvider ssl_data(mode, OK);
[email protected]73b8dd222010-11-11 19:55:2410655 net::MockWrite data_writes[] = {
[email protected]8ddf8322012-02-23 18:08:0610656 net::MockWrite(mode, error),
[email protected]73b8dd222010-11-11 19:55:2410657 };
10658 net::StaticSocketDataProvider data(NULL, 0,
10659 data_writes, arraysize(data_writes));
[email protected]bb88e1d32013-05-03 23:11:0710660 session_deps_.socket_factory->AddSocketDataProvider(&data);
10661 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data);
[email protected]73b8dd222010-11-11 19:55:2410662
[email protected]bb88e1d32013-05-03 23:11:0710663 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610664 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010665 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]73b8dd222010-11-11 19:55:2410666
[email protected]49639fa2011-12-20 23:22:4110667 TestCompletionCallback callback;
10668 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]73b8dd222010-11-11 19:55:2410669 if (rv == net::ERR_IO_PENDING)
10670 rv = callback.WaitForResult();
10671 ASSERT_EQ(error, rv);
10672}
10673
[email protected]23e482282013-06-14 16:08:0210674TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) {
[email protected]73b8dd222010-11-11 19:55:2410675 // Just check a grab bag of cert errors.
10676 static const int kErrors[] = {
10677 ERR_CERT_COMMON_NAME_INVALID,
10678 ERR_CERT_AUTHORITY_INVALID,
10679 ERR_CERT_DATE_INVALID,
10680 };
10681 for (size_t i = 0; i < arraysize(kErrors); i++) {
[email protected]8ddf8322012-02-23 18:08:0610682 CheckErrorIsPassedBack(kErrors[i], ASYNC);
10683 CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS);
[email protected]73b8dd222010-11-11 19:55:2410684 }
10685}
10686
[email protected]bd0b6772011-01-11 19:59:3010687// Ensure that a client certificate is removed from the SSL client auth
10688// cache when:
10689// 1) No proxy is involved.
10690// 2) TLS False Start is disabled.
10691// 3) The initial TLS handshake requests a client certificate.
10692// 4) The client supplies an invalid/unacceptable certificate.
[email protected]23e482282013-06-14 16:08:0210693TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:2310694 ClientAuthCertCache_Direct_NoFalseStart) {
[email protected]cb9bf6ca2011-01-28 13:15:2710695 net::HttpRequestInfo request_info;
10696 request_info.url = GURL("https://www.example.com/");
10697 request_info.method = "GET";
10698 request_info.load_flags = net::LOAD_NORMAL;
10699
[email protected]bd0b6772011-01-11 19:59:3010700 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110701 cert_request->host_and_port = HostPortPair("www.example.com", 443);
[email protected]bd0b6772011-01-11 19:59:3010702
10703 // [ssl_]data1 contains the data for the first SSL handshake. When a
10704 // CertificateRequest is received for the first time, the handshake will
10705 // be aborted to allow the caller to provide a certificate.
[email protected]8ddf8322012-02-23 18:08:0610706 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]bd0b6772011-01-11 19:59:3010707 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710708 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]bd0b6772011-01-11 19:59:3010709 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710710 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]bd0b6772011-01-11 19:59:3010711
10712 // [ssl_]data2 contains the data for the second SSL handshake. When TLS
10713 // False Start is not being used, the result of the SSL handshake will be
10714 // returned as part of the SSLClientSocket::Connect() call. This test
10715 // matches the result of a server sending a handshake_failure alert,
10716 // rather than a Finished message, because it requires a client
10717 // certificate and none was supplied.
[email protected]8ddf8322012-02-23 18:08:0610718 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]bd0b6772011-01-11 19:59:3010719 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710720 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]bd0b6772011-01-11 19:59:3010721 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710722 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]bd0b6772011-01-11 19:59:3010723
10724 // [ssl_]data3 contains the data for the third SSL handshake. When a
10725 // connection to a server fails during an SSL handshake,
[email protected]80c75f682012-05-26 16:22:1710726 // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous
10727 // connection was attempted with TLSv1.1. This is transparent to the caller
[email protected]bd0b6772011-01-11 19:59:3010728 // of the HttpNetworkTransaction. Because this test failure is due to
10729 // requiring a client certificate, this fallback handshake should also
10730 // fail.
[email protected]8ddf8322012-02-23 18:08:0610731 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]bd0b6772011-01-11 19:59:3010732 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710733 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]bd0b6772011-01-11 19:59:3010734 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710735 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]bd0b6772011-01-11 19:59:3010736
[email protected]80c75f682012-05-26 16:22:1710737 // [ssl_]data4 contains the data for the fourth SSL handshake. When a
10738 // connection to a server fails during an SSL handshake,
10739 // HttpNetworkTransaction will attempt to fallback to SSLv3 if the previous
10740 // connection was attempted with TLSv1. This is transparent to the caller
10741 // of the HttpNetworkTransaction. Because this test failure is due to
10742 // requiring a client certificate, this fallback handshake should also
10743 // fail.
10744 SSLSocketDataProvider ssl_data4(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
10745 ssl_data4.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710746 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4);
[email protected]80c75f682012-05-26 16:22:1710747 net::StaticSocketDataProvider data4(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710748 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]80c75f682012-05-26 16:22:1710749
[email protected]7799de12013-05-30 05:52:5110750 // Need one more if TLSv1.2 is enabled.
10751 SSLSocketDataProvider ssl_data5(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
10752 ssl_data5.cert_request_info = cert_request.get();
10753 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5);
10754 net::StaticSocketDataProvider data5(NULL, 0, NULL, 0);
10755 session_deps_.socket_factory->AddSocketDataProvider(&data5);
10756
[email protected]bb88e1d32013-05-03 23:11:0710757 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610758 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010759 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bd0b6772011-01-11 19:59:3010760
[email protected]bd0b6772011-01-11 19:59:3010761 // Begin the SSL handshake with the peer. This consumes ssl_data1.
[email protected]49639fa2011-12-20 23:22:4110762 TestCompletionCallback callback;
10763 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]bd0b6772011-01-11 19:59:3010764 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10765
10766 // Complete the SSL handshake, which should abort due to requiring a
10767 // client certificate.
10768 rv = callback.WaitForResult();
10769 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10770
10771 // Indicate that no certificate should be supplied. From the perspective
10772 // of SSLClientCertCache, NULL is just as meaningful as a real
10773 // certificate, so this is the same as supply a
10774 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110775 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]bd0b6772011-01-11 19:59:3010776 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10777
10778 // Ensure the certificate was added to the client auth cache before
10779 // allowing the connection to continue restarting.
10780 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110781 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10782 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010783 ASSERT_EQ(NULL, client_cert.get());
10784
10785 // Restart the handshake. This will consume ssl_data2, which fails, and
[email protected]80c75f682012-05-26 16:22:1710786 // then consume ssl_data3 and ssl_data4, both of which should also fail.
10787 // The result code is checked against what ssl_data4 should return.
[email protected]bd0b6772011-01-11 19:59:3010788 rv = callback.WaitForResult();
10789 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv);
10790
10791 // Ensure that the client certificate is removed from the cache on a
10792 // handshake failure.
[email protected]791879c2013-12-17 07:22:4110793 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10794 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010795}
10796
10797// Ensure that a client certificate is removed from the SSL client auth
10798// cache when:
10799// 1) No proxy is involved.
10800// 2) TLS False Start is enabled.
10801// 3) The initial TLS handshake requests a client certificate.
10802// 4) The client supplies an invalid/unacceptable certificate.
[email protected]23e482282013-06-14 16:08:0210803TEST_P(HttpNetworkTransactionTest,
[email protected]448d4ca52012-03-04 04:12:2310804 ClientAuthCertCache_Direct_FalseStart) {
[email protected]cb9bf6ca2011-01-28 13:15:2710805 net::HttpRequestInfo request_info;
10806 request_info.url = GURL("https://www.example.com/");
10807 request_info.method = "GET";
10808 request_info.load_flags = net::LOAD_NORMAL;
10809
[email protected]bd0b6772011-01-11 19:59:3010810 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110811 cert_request->host_and_port = HostPortPair("www.example.com", 443);
[email protected]bd0b6772011-01-11 19:59:3010812
10813 // When TLS False Start is used, SSLClientSocket::Connect() calls will
10814 // return successfully after reading up to the peer's Certificate message.
10815 // This is to allow the caller to call SSLClientSocket::Write(), which can
10816 // enqueue application data to be sent in the same packet as the
10817 // ChangeCipherSpec and Finished messages.
10818 // The actual handshake will be finished when SSLClientSocket::Read() is
10819 // called, which expects to process the peer's ChangeCipherSpec and
10820 // Finished messages. If there was an error negotiating with the peer,
10821 // such as due to the peer requiring a client certificate when none was
10822 // supplied, the alert sent by the peer won't be processed until Read() is
10823 // called.
10824
10825 // Like the non-False Start case, when a client certificate is requested by
10826 // the peer, the handshake is aborted during the Connect() call.
10827 // [ssl_]data1 represents the initial SSL handshake with the peer.
[email protected]8ddf8322012-02-23 18:08:0610828 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]bd0b6772011-01-11 19:59:3010829 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710830 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]bd0b6772011-01-11 19:59:3010831 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710832 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]bd0b6772011-01-11 19:59:3010833
10834 // When a client certificate is supplied, Connect() will not be aborted
10835 // when the peer requests the certificate. Instead, the handshake will
10836 // artificially succeed, allowing the caller to write the HTTP request to
10837 // the socket. The handshake messages are not processed until Read() is
10838 // called, which then detects that the handshake was aborted, due to the
10839 // peer sending a handshake_failure because it requires a client
10840 // certificate.
[email protected]8ddf8322012-02-23 18:08:0610841 SSLSocketDataProvider ssl_data2(ASYNC, net::OK);
[email protected]bd0b6772011-01-11 19:59:3010842 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710843 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]bd0b6772011-01-11 19:59:3010844 net::MockRead data2_reads[] = {
[email protected]8ddf8322012-02-23 18:08:0610845 net::MockRead(ASYNC /* async */, net::ERR_SSL_PROTOCOL_ERROR),
[email protected]bd0b6772011-01-11 19:59:3010846 };
10847 net::StaticSocketDataProvider data2(
10848 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710849 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]bd0b6772011-01-11 19:59:3010850
10851 // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is
[email protected]80c75f682012-05-26 16:22:1710852 // the data for the SSL handshake once the TLSv1.1 connection falls back to
10853 // TLSv1. It has the same behaviour as [ssl_]data2.
[email protected]8ddf8322012-02-23 18:08:0610854 SSLSocketDataProvider ssl_data3(ASYNC, net::OK);
[email protected]bd0b6772011-01-11 19:59:3010855 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710856 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]bd0b6772011-01-11 19:59:3010857 net::StaticSocketDataProvider data3(
10858 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710859 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]bd0b6772011-01-11 19:59:3010860
[email protected]80c75f682012-05-26 16:22:1710861 // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection
10862 // falls back to SSLv3. It has the same behaviour as [ssl_]data2.
10863 SSLSocketDataProvider ssl_data4(ASYNC, net::OK);
10864 ssl_data4.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710865 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4);
[email protected]80c75f682012-05-26 16:22:1710866 net::StaticSocketDataProvider data4(
10867 data2_reads, arraysize(data2_reads), NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710868 session_deps_.socket_factory->AddSocketDataProvider(&data4);
[email protected]80c75f682012-05-26 16:22:1710869
[email protected]7799de12013-05-30 05:52:5110870 // Need one more if TLSv1.2 is enabled.
10871 SSLSocketDataProvider ssl_data5(ASYNC, net::OK);
10872 ssl_data5.cert_request_info = cert_request.get();
10873 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5);
10874 net::StaticSocketDataProvider data5(
10875 data2_reads, arraysize(data2_reads), NULL, 0);
10876 session_deps_.socket_factory->AddSocketDataProvider(&data5);
10877
[email protected]bb88e1d32013-05-03 23:11:0710878 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]262eec82013-03-19 21:01:3610879 scoped_ptr<HttpTransaction> trans(
[email protected]90499482013-06-01 00:39:5010880 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]bd0b6772011-01-11 19:59:3010881
[email protected]bd0b6772011-01-11 19:59:3010882 // Begin the initial SSL handshake.
[email protected]49639fa2011-12-20 23:22:4110883 TestCompletionCallback callback;
10884 int rv = trans->Start(&request_info, callback.callback(), net::BoundNetLog());
[email protected]bd0b6772011-01-11 19:59:3010885 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10886
10887 // Complete the SSL handshake, which should abort due to requiring a
10888 // client certificate.
10889 rv = callback.WaitForResult();
10890 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10891
10892 // Indicate that no certificate should be supplied. From the perspective
10893 // of SSLClientCertCache, NULL is just as meaningful as a real
10894 // certificate, so this is the same as supply a
10895 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110896 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]bd0b6772011-01-11 19:59:3010897 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10898
10899 // Ensure the certificate was added to the client auth cache before
10900 // allowing the connection to continue restarting.
10901 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110902 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10903 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010904 ASSERT_EQ(NULL, client_cert.get());
10905
[email protected]bd0b6772011-01-11 19:59:3010906 // Restart the handshake. This will consume ssl_data2, which fails, and
[email protected]80c75f682012-05-26 16:22:1710907 // then consume ssl_data3 and ssl_data4, both of which should also fail.
10908 // The result code is checked against what ssl_data4 should return.
[email protected]bd0b6772011-01-11 19:59:3010909 rv = callback.WaitForResult();
10910 ASSERT_EQ(net::ERR_SSL_PROTOCOL_ERROR, rv);
10911
10912 // Ensure that the client certificate is removed from the cache on a
10913 // handshake failure.
[email protected]791879c2013-12-17 07:22:4110914 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
10915 HostPortPair("www.example.com", 443), &client_cert));
[email protected]bd0b6772011-01-11 19:59:3010916}
10917
[email protected]8c405132011-01-11 22:03:1810918// Ensure that a client certificate is removed from the SSL client auth
10919// cache when:
10920// 1) An HTTPS proxy is involved.
10921// 3) The HTTPS proxy requests a client certificate.
10922// 4) The client supplies an invalid/unacceptable certificate for the
10923// proxy.
10924// The test is repeated twice, first for connecting to an HTTPS endpoint,
10925// then for connecting to an HTTP endpoint.
[email protected]23e482282013-06-14 16:08:0210926TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) {
[email protected]bb88e1d32013-05-03 23:11:0710927 session_deps_.proxy_service.reset(
[email protected]8c405132011-01-11 22:03:1810928 ProxyService::CreateFixed("https://proxy:70"));
[email protected]333bdf62012-06-08 22:57:2910929 CapturingBoundNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0710930 session_deps_.net_log = log.bound().net_log();
[email protected]8c405132011-01-11 22:03:1810931
10932 scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo());
[email protected]791879c2013-12-17 07:22:4110933 cert_request->host_and_port = HostPortPair("proxy", 70);
[email protected]8c405132011-01-11 22:03:1810934
10935 // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of
10936 // [ssl_]data[1-3]. Rather than represending the endpoint
10937 // (www.example.com:443), they represent failures with the HTTPS proxy
10938 // (proxy:70).
[email protected]8ddf8322012-02-23 18:08:0610939 SSLSocketDataProvider ssl_data1(ASYNC, net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
[email protected]8c405132011-01-11 22:03:1810940 ssl_data1.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710941 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1);
[email protected]8c405132011-01-11 22:03:1810942 net::StaticSocketDataProvider data1(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710943 session_deps_.socket_factory->AddSocketDataProvider(&data1);
[email protected]8c405132011-01-11 22:03:1810944
[email protected]8ddf8322012-02-23 18:08:0610945 SSLSocketDataProvider ssl_data2(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]8c405132011-01-11 22:03:1810946 ssl_data2.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710947 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2);
[email protected]8c405132011-01-11 22:03:1810948 net::StaticSocketDataProvider data2(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710949 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]8c405132011-01-11 22:03:1810950
[email protected]80c75f682012-05-26 16:22:1710951 // TODO(wtc): find out why this unit test doesn't need [ssl_]data3.
10952#if 0
[email protected]8ddf8322012-02-23 18:08:0610953 SSLSocketDataProvider ssl_data3(ASYNC, net::ERR_SSL_PROTOCOL_ERROR);
[email protected]8c405132011-01-11 22:03:1810954 ssl_data3.cert_request_info = cert_request.get();
[email protected]bb88e1d32013-05-03 23:11:0710955 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3);
[email protected]8c405132011-01-11 22:03:1810956 net::StaticSocketDataProvider data3(NULL, 0, NULL, 0);
[email protected]bb88e1d32013-05-03 23:11:0710957 session_deps_.socket_factory->AddSocketDataProvider(&data3);
[email protected]80c75f682012-05-26 16:22:1710958#endif
[email protected]8c405132011-01-11 22:03:1810959
10960 net::HttpRequestInfo requests[2];
10961 requests[0].url = GURL("https://www.example.com/");
10962 requests[0].method = "GET";
10963 requests[0].load_flags = net::LOAD_NORMAL;
10964
10965 requests[1].url = GURL("http://www.example.com/");
10966 requests[1].method = "GET";
10967 requests[1].load_flags = net::LOAD_NORMAL;
10968
10969 for (size_t i = 0; i < arraysize(requests); ++i) {
[email protected]bb88e1d32013-05-03 23:11:0710970 session_deps_.socket_factory->ResetNextMockIndexes();
10971 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8c405132011-01-11 22:03:1810972 scoped_ptr<HttpNetworkTransaction> trans(
[email protected]90499482013-06-01 00:39:5010973 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]8c405132011-01-11 22:03:1810974
10975 // Begin the SSL handshake with the proxy.
[email protected]49639fa2011-12-20 23:22:4110976 TestCompletionCallback callback;
10977 int rv = trans->Start(
10978 &requests[i], callback.callback(), net::BoundNetLog());
[email protected]8c405132011-01-11 22:03:1810979 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10980
10981 // Complete the SSL handshake, which should abort due to requiring a
10982 // client certificate.
10983 rv = callback.WaitForResult();
10984 ASSERT_EQ(net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv);
10985
10986 // Indicate that no certificate should be supplied. From the perspective
10987 // of SSLClientCertCache, NULL is just as meaningful as a real
10988 // certificate, so this is the same as supply a
10989 // legitimate-but-unacceptable certificate.
[email protected]49639fa2011-12-20 23:22:4110990 rv = trans->RestartWithCertificate(NULL, callback.callback());
[email protected]8c405132011-01-11 22:03:1810991 ASSERT_EQ(net::ERR_IO_PENDING, rv);
10992
10993 // Ensure the certificate was added to the client auth cache before
10994 // allowing the connection to continue restarting.
10995 scoped_refptr<X509Certificate> client_cert;
[email protected]791879c2013-12-17 07:22:4110996 ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup(
10997 HostPortPair("proxy", 70), &client_cert));
[email protected]8c405132011-01-11 22:03:1810998 ASSERT_EQ(NULL, client_cert.get());
10999 // Ensure the certificate was NOT cached for the endpoint. This only
11000 // applies to HTTPS requests, but is fine to check for HTTP requests.
[email protected]791879c2013-12-17 07:22:4111001 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
11002 HostPortPair("www.example.com", 443), &client_cert));
[email protected]8c405132011-01-11 22:03:1811003
11004 // Restart the handshake. This will consume ssl_data2, which fails, and
11005 // then consume ssl_data3, which should also fail. The result code is
11006 // checked against what ssl_data3 should return.
11007 rv = callback.WaitForResult();
11008 ASSERT_EQ(net::ERR_PROXY_CONNECTION_FAILED, rv);
11009
11010 // Now that the new handshake has failed, ensure that the client
11011 // certificate was removed from the client auth cache.
[email protected]791879c2013-12-17 07:22:4111012 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
11013 HostPortPair("proxy", 70), &client_cert));
11014 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup(
11015 HostPortPair("www.example.com", 443), &client_cert));
[email protected]8c405132011-01-11 22:03:1811016 }
11017}
11018
[email protected]23e482282013-06-14 16:08:0211019// Unlike TEST/TEST_F, which are macros that expand to further macros,
11020// TEST_P is a macro that expands directly to code that stringizes the
11021// arguments. As a result, macros passed as parameters (such as prefix
11022// or test_case_name) will not be expanded by the preprocessor. To
11023// work around this, indirect the macro for TEST_P, so that the
11024// pre-processor will expand macros such as MAYBE_test_name before
11025// instantiating the test.
11026#define WRAPPED_TEST_P(test_case_name, test_name) \
11027 TEST_P(test_case_name, test_name)
11028
[email protected]45b170822012-05-04 21:18:1411029// Times out on Win7 dbg(2) bot. http://crbug.com/124776
11030#if defined(OS_WIN)
11031#define MAYBE_UseIPConnectionPooling DISABLED_UseIPConnectionPooling
11032#else
11033#define MAYBE_UseIPConnectionPooling UseIPConnectionPooling
11034#endif
[email protected]23e482282013-06-14 16:08:0211035WRAPPED_TEST_P(HttpNetworkTransactionTest, MAYBE_UseIPConnectionPooling) {
[email protected]d7599122014-05-24 03:37:2311036 session_deps_.use_alternate_protocols = true;
11037 session_deps_.next_protos = SpdyNextProtos();
[email protected]e3ceb682011-06-28 23:55:4611038
11039 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
[email protected]bb88e1d32013-05-03 23:11:0711040 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11041 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]b9ec6882011-07-01 07:40:2611042 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11043 pool_peer.DisableDomainAuthenticationVerification();
[email protected]e3ceb682011-06-28 23:55:4611044
[email protected]8ddf8322012-02-23 18:08:0611045 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211046 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711047 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e3ceb682011-06-28 23:55:4611048
[email protected]cdf8f7e72013-05-23 10:56:4611049 scoped_ptr<SpdyFrame> host1_req(
11050 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11051 scoped_ptr<SpdyFrame> host2_req(
11052 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]e3ceb682011-06-28 23:55:4611053 MockWrite spdy_writes[] = {
11054 CreateMockWrite(*host1_req, 1),
11055 CreateMockWrite(*host2_req, 4),
11056 };
[email protected]23e482282013-06-14 16:08:0211057 scoped_ptr<SpdyFrame> host1_resp(
11058 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11059 scoped_ptr<SpdyFrame> host1_resp_body(
11060 spdy_util_.ConstructSpdyBodyFrame(1, true));
11061 scoped_ptr<SpdyFrame> host2_resp(
11062 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11063 scoped_ptr<SpdyFrame> host2_resp_body(
11064 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]e3ceb682011-06-28 23:55:4611065 MockRead spdy_reads[] = {
11066 CreateMockRead(*host1_resp, 2),
11067 CreateMockRead(*host1_resp_body, 3),
11068 CreateMockRead(*host2_resp, 5),
11069 CreateMockRead(*host2_resp_body, 6),
[email protected]8ddf8322012-02-23 18:08:0611070 MockRead(ASYNC, 0, 7),
[email protected]e3ceb682011-06-28 23:55:4611071 };
11072
[email protected]d2b5f092012-06-08 23:55:0211073 IPAddressNumber ip;
11074 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11075 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11076 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711077 OrderedSocketData spdy_data(
11078 connect,
11079 spdy_reads, arraysize(spdy_reads),
11080 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711081 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]e3ceb682011-06-28 23:55:4611082
[email protected]aa22b242011-11-16 18:58:2911083 TestCompletionCallback callback;
[email protected]e3ceb682011-06-28 23:55:4611084 HttpRequestInfo request1;
11085 request1.method = "GET";
11086 request1.url = GURL("https://www.google.com/");
11087 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011088 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611089
[email protected]49639fa2011-12-20 23:22:4111090 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611091 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111092 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611093
11094 const HttpResponseInfo* response = trans1.GetResponseInfo();
11095 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011096 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611097 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11098
11099 std::string response_data;
11100 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11101 EXPECT_EQ("hello!", response_data);
11102
11103 // Preload www.gmail.com into HostCache.
11104 HostPortPair host_port("www.gmail.com", 443);
[email protected]5109c1952013-08-20 18:44:1011105 HostResolver::RequestInfo resolve_info(host_port);
[email protected]e3ceb682011-06-28 23:55:4611106 AddressList ignored;
[email protected]5109c1952013-08-20 18:44:1011107 rv = session_deps_.host_resolver->Resolve(resolve_info,
11108 DEFAULT_PRIORITY,
11109 &ignored,
11110 callback.callback(),
11111 NULL,
11112 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:4711113 EXPECT_EQ(ERR_IO_PENDING, rv);
11114 rv = callback.WaitForResult();
11115 EXPECT_EQ(OK, rv);
[email protected]e3ceb682011-06-28 23:55:4611116
11117 HttpRequestInfo request2;
11118 request2.method = "GET";
11119 request2.url = GURL("https://www.gmail.com/");
11120 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011121 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611122
[email protected]49639fa2011-12-20 23:22:4111123 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611124 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111125 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611126
11127 response = trans2.GetResponseInfo();
11128 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011129 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611130 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11131 EXPECT_TRUE(response->was_fetched_via_spdy);
11132 EXPECT_TRUE(response->was_npn_negotiated);
11133 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11134 EXPECT_EQ("hello!", response_data);
[email protected]e3ceb682011-06-28 23:55:4611135}
[email protected]45b170822012-05-04 21:18:1411136#undef MAYBE_UseIPConnectionPooling
[email protected]e3ceb682011-06-28 23:55:4611137
[email protected]23e482282013-06-14 16:08:0211138TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) {
[email protected]d7599122014-05-24 03:37:2311139 session_deps_.use_alternate_protocols = true;
11140 session_deps_.next_protos = SpdyNextProtos();
[email protected]d2b5f092012-06-08 23:55:0211141
11142 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
[email protected]bb88e1d32013-05-03 23:11:0711143 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11144 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]d2b5f092012-06-08 23:55:0211145 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11146 pool_peer.DisableDomainAuthenticationVerification();
11147
11148 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211149 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711150 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]d2b5f092012-06-08 23:55:0211151
[email protected]cdf8f7e72013-05-23 10:56:4611152 scoped_ptr<SpdyFrame> host1_req(
11153 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11154 scoped_ptr<SpdyFrame> host2_req(
11155 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]d2b5f092012-06-08 23:55:0211156 MockWrite spdy_writes[] = {
11157 CreateMockWrite(*host1_req, 1),
11158 CreateMockWrite(*host2_req, 4),
11159 };
[email protected]23e482282013-06-14 16:08:0211160 scoped_ptr<SpdyFrame> host1_resp(
11161 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11162 scoped_ptr<SpdyFrame> host1_resp_body(
11163 spdy_util_.ConstructSpdyBodyFrame(1, true));
11164 scoped_ptr<SpdyFrame> host2_resp(
11165 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11166 scoped_ptr<SpdyFrame> host2_resp_body(
11167 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]d2b5f092012-06-08 23:55:0211168 MockRead spdy_reads[] = {
11169 CreateMockRead(*host1_resp, 2),
11170 CreateMockRead(*host1_resp_body, 3),
11171 CreateMockRead(*host2_resp, 5),
11172 CreateMockRead(*host2_resp_body, 6),
11173 MockRead(ASYNC, 0, 7),
11174 };
11175
11176 IPAddressNumber ip;
11177 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11178 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11179 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711180 OrderedSocketData spdy_data(
11181 connect,
11182 spdy_reads, arraysize(spdy_reads),
11183 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711184 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]d2b5f092012-06-08 23:55:0211185
11186 TestCompletionCallback callback;
11187 HttpRequestInfo request1;
11188 request1.method = "GET";
11189 request1.url = GURL("https://www.google.com/");
11190 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011191 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]d2b5f092012-06-08 23:55:0211192
11193 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
11194 EXPECT_EQ(ERR_IO_PENDING, rv);
11195 EXPECT_EQ(OK, callback.WaitForResult());
11196
11197 const HttpResponseInfo* response = trans1.GetResponseInfo();
11198 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011199 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d2b5f092012-06-08 23:55:0211200 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11201
11202 std::string response_data;
11203 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11204 EXPECT_EQ("hello!", response_data);
11205
11206 HttpRequestInfo request2;
11207 request2.method = "GET";
11208 request2.url = GURL("https://www.gmail.com/");
11209 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011210 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]d2b5f092012-06-08 23:55:0211211
11212 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
11213 EXPECT_EQ(ERR_IO_PENDING, rv);
11214 EXPECT_EQ(OK, callback.WaitForResult());
11215
11216 response = trans2.GetResponseInfo();
11217 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011218 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]d2b5f092012-06-08 23:55:0211219 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11220 EXPECT_TRUE(response->was_fetched_via_spdy);
11221 EXPECT_TRUE(response->was_npn_negotiated);
11222 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11223 EXPECT_EQ("hello!", response_data);
[email protected]d2b5f092012-06-08 23:55:0211224}
11225
[email protected]e3ceb682011-06-28 23:55:4611226class OneTimeCachingHostResolver : public net::HostResolver {
11227 public:
11228 explicit OneTimeCachingHostResolver(const HostPortPair& host_port)
11229 : host_port_(host_port) {}
dchengb03027d2014-10-21 12:00:2011230 ~OneTimeCachingHostResolver() override {}
[email protected]e3ceb682011-06-28 23:55:4611231
11232 RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); }
11233
11234 // HostResolver methods:
dchengb03027d2014-10-21 12:00:2011235 int Resolve(const RequestInfo& info,
11236 RequestPriority priority,
11237 AddressList* addresses,
11238 const CompletionCallback& callback,
11239 RequestHandle* out_req,
11240 const BoundNetLog& net_log) override {
[email protected]95a214c2011-08-04 21:50:4011241 return host_resolver_.Resolve(
[email protected]5109c1952013-08-20 18:44:1011242 info, priority, addresses, callback, out_req, net_log);
[email protected]95a214c2011-08-04 21:50:4011243 }
11244
dchengb03027d2014-10-21 12:00:2011245 int ResolveFromCache(const RequestInfo& info,
11246 AddressList* addresses,
11247 const BoundNetLog& net_log) override {
[email protected]95a214c2011-08-04 21:50:4011248 int rv = host_resolver_.ResolveFromCache(info, addresses, net_log);
11249 if (rv == OK && info.host_port_pair().Equals(host_port_))
[email protected]98e1cd012011-11-08 15:33:0911250 host_resolver_.GetHostCache()->clear();
[email protected]e3ceb682011-06-28 23:55:4611251 return rv;
11252 }
11253
dchengb03027d2014-10-21 12:00:2011254 void CancelRequest(RequestHandle req) override {
[email protected]e3ceb682011-06-28 23:55:4611255 host_resolver_.CancelRequest(req);
11256 }
11257
[email protected]46da33be2011-07-19 21:58:0411258 MockCachingHostResolver* GetMockHostResolver() {
11259 return &host_resolver_;
11260 }
11261
[email protected]e3ceb682011-06-28 23:55:4611262 private:
11263 MockCachingHostResolver host_resolver_;
11264 const HostPortPair host_port_;
11265};
11266
[email protected]45b170822012-05-04 21:18:1411267// Times out on Win7 dbg(2) bot. http://crbug.com/124776
11268#if defined(OS_WIN)
[email protected]bb88e1d32013-05-03 23:11:0711269#define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \
11270 DISABLED_UseIPConnectionPoolingWithHostCacheExpiration
[email protected]45b170822012-05-04 21:18:1411271#else
[email protected]bb88e1d32013-05-03 23:11:0711272#define MAYBE_UseIPConnectionPoolingWithHostCacheExpiration \
11273 UseIPConnectionPoolingWithHostCacheExpiration
[email protected]45b170822012-05-04 21:18:1411274#endif
[email protected]23e482282013-06-14 16:08:0211275WRAPPED_TEST_P(HttpNetworkTransactionTest,
11276 MAYBE_UseIPConnectionPoolingWithHostCacheExpiration) {
[email protected]23e482282013-06-14 16:08:0211277// Times out on Win7 dbg(2) bot. http://crbug.com/124776 . (MAYBE_
11278// prefix doesn't work with parametrized tests).
11279#if defined(OS_WIN)
11280 return;
[email protected]88c7b4be2014-03-19 23:04:0111281#else
[email protected]d7599122014-05-24 03:37:2311282 session_deps_.use_alternate_protocols = true;
11283 session_deps_.next_protos = SpdyNextProtos();
[email protected]e3ceb682011-06-28 23:55:4611284
11285 // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver.
[email protected]e3ceb682011-06-28 23:55:4611286 OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443));
[email protected]c6bf8152012-12-02 07:43:3411287 HttpNetworkSession::Params params =
[email protected]bb88e1d32013-05-03 23:11:0711288 SpdySessionDependencies::CreateSessionParams(&session_deps_);
[email protected]e3ceb682011-06-28 23:55:4611289 params.host_resolver = &host_resolver;
[email protected]bb88e1d32013-05-03 23:11:0711290 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]b9ec6882011-07-01 07:40:2611291 SpdySessionPoolPeer pool_peer(session->spdy_session_pool());
11292 pool_peer.DisableDomainAuthenticationVerification();
[email protected]e3ceb682011-06-28 23:55:4611293
[email protected]8ddf8322012-02-23 18:08:0611294 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211295 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711296 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
[email protected]e3ceb682011-06-28 23:55:4611297
[email protected]cdf8f7e72013-05-23 10:56:4611298 scoped_ptr<SpdyFrame> host1_req(
11299 spdy_util_.ConstructSpdyGet("https://www.google.com", false, 1, LOWEST));
11300 scoped_ptr<SpdyFrame> host2_req(
11301 spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST));
[email protected]e3ceb682011-06-28 23:55:4611302 MockWrite spdy_writes[] = {
11303 CreateMockWrite(*host1_req, 1),
11304 CreateMockWrite(*host2_req, 4),
11305 };
[email protected]23e482282013-06-14 16:08:0211306 scoped_ptr<SpdyFrame> host1_resp(
11307 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11308 scoped_ptr<SpdyFrame> host1_resp_body(
11309 spdy_util_.ConstructSpdyBodyFrame(1, true));
11310 scoped_ptr<SpdyFrame> host2_resp(
11311 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11312 scoped_ptr<SpdyFrame> host2_resp_body(
11313 spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]e3ceb682011-06-28 23:55:4611314 MockRead spdy_reads[] = {
11315 CreateMockRead(*host1_resp, 2),
11316 CreateMockRead(*host1_resp_body, 3),
11317 CreateMockRead(*host2_resp, 5),
11318 CreateMockRead(*host2_resp_body, 6),
[email protected]8ddf8322012-02-23 18:08:0611319 MockRead(ASYNC, 0, 7),
[email protected]e3ceb682011-06-28 23:55:4611320 };
11321
[email protected]d2b5f092012-06-08 23:55:0211322 IPAddressNumber ip;
11323 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip));
11324 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11325 MockConnect connect(ASYNC, OK, peer_addr);
[email protected]dd54bd82012-07-19 23:44:5711326 OrderedSocketData spdy_data(
11327 connect,
11328 spdy_reads, arraysize(spdy_reads),
11329 spdy_writes, arraysize(spdy_writes));
[email protected]bb88e1d32013-05-03 23:11:0711330 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
[email protected]e3ceb682011-06-28 23:55:4611331
[email protected]aa22b242011-11-16 18:58:2911332 TestCompletionCallback callback;
[email protected]e3ceb682011-06-28 23:55:4611333 HttpRequestInfo request1;
11334 request1.method = "GET";
11335 request1.url = GURL("https://www.google.com/");
11336 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011337 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611338
[email protected]49639fa2011-12-20 23:22:4111339 int rv = trans1.Start(&request1, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611340 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111341 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611342
11343 const HttpResponseInfo* response = trans1.GetResponseInfo();
11344 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011345 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611346 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11347
11348 std::string response_data;
11349 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
11350 EXPECT_EQ("hello!", response_data);
11351
11352 // Preload cache entries into HostCache.
[email protected]5109c1952013-08-20 18:44:1011353 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443));
[email protected]e3ceb682011-06-28 23:55:4611354 AddressList ignored;
[email protected]5109c1952013-08-20 18:44:1011355 rv = host_resolver.Resolve(resolve_info,
11356 DEFAULT_PRIORITY,
11357 &ignored,
11358 callback.callback(),
11359 NULL,
11360 BoundNetLog());
[email protected]6e78dfb2011-07-28 21:34:4711361 EXPECT_EQ(ERR_IO_PENDING, rv);
11362 rv = callback.WaitForResult();
11363 EXPECT_EQ(OK, rv);
[email protected]e3ceb682011-06-28 23:55:4611364
11365 HttpRequestInfo request2;
11366 request2.method = "GET";
11367 request2.url = GURL("https://www.gmail.com/");
11368 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011369 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
[email protected]e3ceb682011-06-28 23:55:4611370
[email protected]49639fa2011-12-20 23:22:4111371 rv = trans2.Start(&request2, callback.callback(), BoundNetLog());
[email protected]e3ceb682011-06-28 23:55:4611372 EXPECT_EQ(ERR_IO_PENDING, rv);
[email protected]49639fa2011-12-20 23:22:4111373 EXPECT_EQ(OK, callback.WaitForResult());
[email protected]e3ceb682011-06-28 23:55:4611374
11375 response = trans2.GetResponseInfo();
11376 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011377 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]e3ceb682011-06-28 23:55:4611378 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11379 EXPECT_TRUE(response->was_fetched_via_spdy);
11380 EXPECT_TRUE(response->was_npn_negotiated);
11381 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
11382 EXPECT_EQ("hello!", response_data);
[email protected]88c7b4be2014-03-19 23:04:0111383#endif
[email protected]e3ceb682011-06-28 23:55:4611384}
[email protected]45b170822012-05-04 21:18:1411385#undef MAYBE_UseIPConnectionPoolingWithHostCacheExpiration
[email protected]e3ceb682011-06-28 23:55:4611386
[email protected]23e482282013-06-14 16:08:0211387TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) {
lgarrona91df87f2014-12-05 00:51:3411388 const std::string https_url = "https://www.google.com:8080/";
11389 const std::string http_url = "http://www.google.com:8080/";
[email protected]8450d722012-07-02 19:14:0411390
11391 // SPDY GET for HTTPS URL
[email protected]cdf8f7e72013-05-23 10:56:4611392 scoped_ptr<SpdyFrame> req1(
11393 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]8450d722012-07-02 19:14:0411394
11395 MockWrite writes1[] = {
11396 CreateMockWrite(*req1, 0),
11397 };
11398
[email protected]23e482282013-06-14 16:08:0211399 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11400 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]8450d722012-07-02 19:14:0411401 MockRead reads1[] = {
11402 CreateMockRead(*resp1, 1),
11403 CreateMockRead(*body1, 2),
11404 MockRead(ASYNC, ERR_IO_PENDING, 3)
11405 };
11406
[email protected]dd54bd82012-07-19 23:44:5711407 DelayedSocketData data1(
11408 1, reads1, arraysize(reads1),
11409 writes1, arraysize(writes1));
[email protected]8450d722012-07-02 19:14:0411410 MockConnect connect_data1(ASYNC, OK);
[email protected]dd54bd82012-07-19 23:44:5711411 data1.set_connect_data(connect_data1);
[email protected]8450d722012-07-02 19:14:0411412
11413 // HTTP GET for the HTTP URL
11414 MockWrite writes2[] = {
lgarrona91df87f2014-12-05 00:51:3411415 MockWrite(ASYNC, 4,
11416 "GET / HTTP/1.1\r\n"
11417 "Host: www.google.com:8080\r\n"
11418 "Connection: keep-alive\r\n\r\n"),
[email protected]8450d722012-07-02 19:14:0411419 };
11420
11421 MockRead reads2[] = {
11422 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
11423 MockRead(ASYNC, 6, "hello"),
11424 MockRead(ASYNC, 7, OK),
11425 };
11426
[email protected]dd54bd82012-07-19 23:44:5711427 DelayedSocketData data2(
11428 1, reads2, arraysize(reads2),
11429 writes2, arraysize(writes2));
[email protected]8450d722012-07-02 19:14:0411430
[email protected]8450d722012-07-02 19:14:0411431 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211432 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711433 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
11434 session_deps_.socket_factory->AddSocketDataProvider(&data1);
11435 session_deps_.socket_factory->AddSocketDataProvider(&data2);
[email protected]8450d722012-07-02 19:14:0411436
[email protected]bb88e1d32013-05-03 23:11:0711437 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411438
11439 // Start the first transaction to set up the SpdySession
11440 HttpRequestInfo request1;
11441 request1.method = "GET";
11442 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411443 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011444 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411445 TestCompletionCallback callback1;
11446 EXPECT_EQ(ERR_IO_PENDING,
11447 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411448 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411449
11450 EXPECT_EQ(OK, callback1.WaitForResult());
11451 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11452
11453 // Now, start the HTTP request
11454 HttpRequestInfo request2;
11455 request2.method = "GET";
11456 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411457 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011458 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411459 TestCompletionCallback callback2;
11460 EXPECT_EQ(ERR_IO_PENDING,
11461 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411462 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411463
11464 EXPECT_EQ(OK, callback2.WaitForResult());
11465 EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11466}
11467
[email protected]23e482282013-06-14 16:08:0211468TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) {
lgarrona91df87f2014-12-05 00:51:3411469 const std::string https_url = "https://www.google.com:8080/";
11470 const std::string http_url = "http://www.google.com:8080/";
[email protected]8450d722012-07-02 19:14:0411471
11472 // SPDY GET for HTTPS URL (through CONNECT tunnel)
lgarrona91df87f2014-12-05 00:51:3411473 const HostPortPair host_port_pair("www.google.com", 8080);
11474 scoped_ptr<SpdyFrame> connect(
11475 spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair));
[email protected]cdf8f7e72013-05-23 10:56:4611476 scoped_ptr<SpdyFrame> req1(
11477 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]23e482282013-06-14 16:08:0211478 scoped_ptr<SpdyFrame> wrapped_req1(
11479 spdy_util_.ConstructWrappedSpdyFrame(req1, 1));
[email protected]601e03f12014-04-06 16:26:3911480
11481 // SPDY GET for HTTP URL (through the proxy, but not the tunnel).
[email protected]745aa9c2014-06-27 02:21:2911482 SpdyHeaderBlock req2_block;
11483 req2_block[spdy_util_.GetMethodKey()] = "GET";
bnc33b8cef42014-11-19 17:30:3811484 req2_block[spdy_util_.GetPathKey()] = "/";
lgarrona91df87f2014-12-05 00:51:3411485 req2_block[spdy_util_.GetHostKey()] = "www.google.com:8080";
[email protected]745aa9c2014-06-27 02:21:2911486 req2_block[spdy_util_.GetSchemeKey()] = "http";
11487 spdy_util_.MaybeAddVersionHeader(&req2_block);
[email protected]601e03f12014-04-06 16:26:3911488 scoped_ptr<SpdyFrame> req2(
[email protected]745aa9c2014-06-27 02:21:2911489 spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true));
[email protected]8450d722012-07-02 19:14:0411490
11491 MockWrite writes1[] = {
11492 CreateMockWrite(*connect, 0),
11493 CreateMockWrite(*wrapped_req1, 2),
11494 CreateMockWrite(*req2, 5),
11495 };
11496
[email protected]23e482282013-06-14 16:08:0211497 scoped_ptr<SpdyFrame> conn_resp(
11498 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11499 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11500 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
11501 scoped_ptr<SpdyFrame> wrapped_resp1(
11502 spdy_util_.ConstructWrappedSpdyFrame(resp1, 1));
11503 scoped_ptr<SpdyFrame> wrapped_body1(
11504 spdy_util_.ConstructWrappedSpdyFrame(body1, 1));
11505 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11506 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]8450d722012-07-02 19:14:0411507 MockRead reads1[] = {
11508 CreateMockRead(*conn_resp, 1),
11509 CreateMockRead(*wrapped_resp1, 3),
11510 CreateMockRead(*wrapped_body1, 4),
11511 CreateMockRead(*resp2, 6),
11512 CreateMockRead(*body2, 7),
11513 MockRead(ASYNC, ERR_IO_PENDING, 8)
11514 };
11515
[email protected]dd54bd82012-07-19 23:44:5711516 DeterministicSocketData data1(reads1, arraysize(reads1),
11517 writes1, arraysize(writes1));
[email protected]8450d722012-07-02 19:14:0411518 MockConnect connect_data1(ASYNC, OK);
[email protected]dd54bd82012-07-19 23:44:5711519 data1.set_connect_data(connect_data1);
[email protected]8450d722012-07-02 19:14:0411520
[email protected]bb88e1d32013-05-03 23:11:0711521 session_deps_.proxy_service.reset(
[email protected]f6c63db52013-02-02 00:35:2211522 ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"));
11523 CapturingNetLog log;
[email protected]bb88e1d32013-05-03 23:11:0711524 session_deps_.net_log = &log;
[email protected]8450d722012-07-02 19:14:0411525 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
[email protected]23e482282013-06-14 16:08:0211526 ssl1.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711527 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
[email protected]8450d722012-07-02 19:14:0411528 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
[email protected]23e482282013-06-14 16:08:0211529 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711530 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11531 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1);
[email protected]8450d722012-07-02 19:14:0411532
11533 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711534 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411535
11536 // Start the first transaction to set up the SpdySession
11537 HttpRequestInfo request1;
11538 request1.method = "GET";
11539 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411540 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011541 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411542 TestCompletionCallback callback1;
11543 EXPECT_EQ(ERR_IO_PENDING,
11544 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411545 base::MessageLoop::current()->RunUntilIdle();
[email protected]dd54bd82012-07-19 23:44:5711546 data1.RunFor(4);
[email protected]8450d722012-07-02 19:14:0411547
11548 EXPECT_EQ(OK, callback1.WaitForResult());
11549 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11550
[email protected]f6c63db52013-02-02 00:35:2211551 LoadTimingInfo load_timing_info1;
11552 EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1));
11553 TestLoadTimingNotReusedWithPac(load_timing_info1,
11554 CONNECT_TIMING_HAS_SSL_TIMES);
11555
[email protected]8450d722012-07-02 19:14:0411556 // Now, start the HTTP request
11557 HttpRequestInfo request2;
11558 request2.method = "GET";
11559 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411560 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011561 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411562 TestCompletionCallback callback2;
11563 EXPECT_EQ(ERR_IO_PENDING,
11564 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411565 base::MessageLoop::current()->RunUntilIdle();
[email protected]dd54bd82012-07-19 23:44:5711566 data1.RunFor(3);
[email protected]8450d722012-07-02 19:14:0411567
11568 EXPECT_EQ(OK, callback2.WaitForResult());
11569 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
[email protected]f6c63db52013-02-02 00:35:2211570
11571 LoadTimingInfo load_timing_info2;
11572 EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2));
11573 // The established SPDY sessions is considered reused by the HTTP request.
11574 TestLoadTimingReusedWithPac(load_timing_info2);
11575 // HTTP requests over a SPDY session should have a different connection
11576 // socket_log_id than requests over a tunnel.
11577 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id);
[email protected]8450d722012-07-02 19:14:0411578}
11579
[email protected]23e482282013-06-14 16:08:0211580TEST_P(HttpNetworkTransactionTest, UseSpdySessionForHttpWhenForced) {
[email protected]d7599122014-05-24 03:37:2311581 session_deps_.force_spdy_always = true;
lgarrona91df87f2014-12-05 00:51:3411582 const std::string https_url = "https://www.google.com:8080/";
11583 const std::string http_url = "http://www.google.com:8080/";
[email protected]8450d722012-07-02 19:14:0411584
11585 // SPDY GET for HTTPS URL
[email protected]cdf8f7e72013-05-23 10:56:4611586 scoped_ptr<SpdyFrame> req1(
11587 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST));
[email protected]8450d722012-07-02 19:14:0411588 // SPDY GET for the HTTP URL
[email protected]cdf8f7e72013-05-23 10:56:4611589 scoped_ptr<SpdyFrame> req2(
11590 spdy_util_.ConstructSpdyGet(http_url.c_str(), false, 3, MEDIUM));
[email protected]8450d722012-07-02 19:14:0411591
11592 MockWrite writes[] = {
11593 CreateMockWrite(*req1, 1),
11594 CreateMockWrite(*req2, 4),
11595 };
11596
[email protected]23e482282013-06-14 16:08:0211597 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11598 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
11599 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
11600 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true));
[email protected]8450d722012-07-02 19:14:0411601 MockRead reads[] = {
11602 CreateMockRead(*resp1, 2),
11603 CreateMockRead(*body1, 3),
11604 CreateMockRead(*resp2, 5),
11605 CreateMockRead(*body2, 6),
11606 MockRead(ASYNC, ERR_IO_PENDING, 7)
11607 };
11608
[email protected]dd54bd82012-07-19 23:44:5711609 OrderedSocketData data(reads, arraysize(reads),
11610 writes, arraysize(writes));
[email protected]8450d722012-07-02 19:14:0411611
[email protected]8450d722012-07-02 19:14:0411612 SSLSocketDataProvider ssl(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211613 ssl.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711614 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
11615 session_deps_.socket_factory->AddSocketDataProvider(&data);
[email protected]8450d722012-07-02 19:14:0411616
[email protected]bb88e1d32013-05-03 23:11:0711617 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]8450d722012-07-02 19:14:0411618
11619 // Start the first transaction to set up the SpdySession
11620 HttpRequestInfo request1;
11621 request1.method = "GET";
11622 request1.url = GURL(https_url);
[email protected]8450d722012-07-02 19:14:0411623 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011624 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]8450d722012-07-02 19:14:0411625 TestCompletionCallback callback1;
11626 EXPECT_EQ(ERR_IO_PENDING,
11627 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411628 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411629
11630 EXPECT_EQ(OK, callback1.WaitForResult());
11631 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11632
11633 // Now, start the HTTP request
11634 HttpRequestInfo request2;
11635 request2.method = "GET";
11636 request2.url = GURL(http_url);
[email protected]8450d722012-07-02 19:14:0411637 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011638 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]8450d722012-07-02 19:14:0411639 TestCompletionCallback callback2;
11640 EXPECT_EQ(ERR_IO_PENDING,
11641 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411642 base::MessageLoop::current()->RunUntilIdle();
[email protected]8450d722012-07-02 19:14:0411643
11644 EXPECT_EQ(OK, callback2.WaitForResult());
11645 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11646}
11647
[email protected]2d88e7d2012-07-19 17:55:1711648// Test that in the case where we have a SPDY session to a SPDY proxy
11649// that we do not pool other origins that resolve to the same IP when
11650// the certificate does not match the new origin.
11651// http://crbug.com/134690
[email protected]23e482282013-06-14 16:08:0211652TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) {
[email protected]2d88e7d2012-07-19 17:55:1711653 const std::string url1 = "http://www.google.com/";
11654 const std::string url2 = "https://mail.google.com/";
11655 const std::string ip_addr = "1.2.3.4";
11656
11657 // SPDY GET for HTTP URL (through SPDY proxy)
[email protected]23e482282013-06-14 16:08:0211658 scoped_ptr<SpdyHeaderBlock> headers(
11659 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/"));
[email protected]745aa9c2014-06-27 02:21:2911660 scoped_ptr<SpdyFrame> req1(
11661 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true));
[email protected]2d88e7d2012-07-19 17:55:1711662
11663 MockWrite writes1[] = {
11664 CreateMockWrite(*req1, 0),
11665 };
11666
[email protected]23e482282013-06-14 16:08:0211667 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11668 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2d88e7d2012-07-19 17:55:1711669 MockRead reads1[] = {
11670 CreateMockRead(*resp1, 1),
11671 CreateMockRead(*body1, 2),
11672 MockRead(ASYNC, OK, 3) // EOF
11673 };
11674
11675 scoped_ptr<DeterministicSocketData> data1(
11676 new DeterministicSocketData(reads1, arraysize(reads1),
11677 writes1, arraysize(writes1)));
11678 IPAddressNumber ip;
11679 ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip));
11680 IPEndPoint peer_addr = IPEndPoint(ip, 443);
11681 MockConnect connect_data1(ASYNC, OK, peer_addr);
11682 data1->set_connect_data(connect_data1);
11683
11684 // SPDY GET for HTTPS URL (direct)
[email protected]cdf8f7e72013-05-23 10:56:4611685 scoped_ptr<SpdyFrame> req2(
11686 spdy_util_.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM));
[email protected]2d88e7d2012-07-19 17:55:1711687
11688 MockWrite writes2[] = {
11689 CreateMockWrite(*req2, 0),
11690 };
11691
[email protected]23e482282013-06-14 16:08:0211692 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11693 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]2d88e7d2012-07-19 17:55:1711694 MockRead reads2[] = {
11695 CreateMockRead(*resp2, 1),
11696 CreateMockRead(*body2, 2),
11697 MockRead(ASYNC, OK, 3) // EOF
11698 };
11699
11700 scoped_ptr<DeterministicSocketData> data2(
11701 new DeterministicSocketData(reads2, arraysize(reads2),
11702 writes2, arraysize(writes2)));
11703 MockConnect connect_data2(ASYNC, OK);
11704 data2->set_connect_data(connect_data2);
11705
11706 // Set up a proxy config that sends HTTP requests to a proxy, and
11707 // all others direct.
11708 ProxyConfig proxy_config;
11709 proxy_config.proxy_rules().ParseFromString("http=https://proxy:443");
11710 CapturingProxyResolver* capturing_proxy_resolver =
11711 new CapturingProxyResolver();
[email protected]bb88e1d32013-05-03 23:11:0711712 session_deps_.proxy_service.reset(new ProxyService(
[email protected]2d88e7d2012-07-19 17:55:1711713 new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver,
11714 NULL));
11715
11716 // Load a valid cert. Note, that this does not need to
11717 // be valid for proxy because the MockSSLClientSocket does
11718 // not actually verify it. But SpdySession will use this
11719 // to see if it is valid for the new origin
[email protected]6cdfd7f2013-02-08 20:40:1511720 base::FilePath certs_dir = GetTestCertsDirectory();
[email protected]2d88e7d2012-07-19 17:55:1711721 scoped_refptr<X509Certificate> server_cert(
11722 ImportCertFromFile(certs_dir, "ok_cert.pem"));
dcheng48459ac22014-08-26 00:46:4111723 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get());
[email protected]2d88e7d2012-07-19 17:55:1711724
11725 SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy
[email protected]23e482282013-06-14 16:08:0211726 ssl1.SetNextProto(GetParam());
[email protected]2d88e7d2012-07-19 17:55:1711727 ssl1.cert = server_cert;
[email protected]bb88e1d32013-05-03 23:11:0711728 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
11729 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11730 data1.get());
[email protected]2d88e7d2012-07-19 17:55:1711731
11732 SSLSocketDataProvider ssl2(ASYNC, OK); // to the server
[email protected]23e482282013-06-14 16:08:0211733 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711734 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11735 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11736 data2.get());
[email protected]2d88e7d2012-07-19 17:55:1711737
[email protected]bb88e1d32013-05-03 23:11:0711738 session_deps_.host_resolver.reset(new MockCachingHostResolver());
11739 session_deps_.host_resolver->rules()->AddRule("mail.google.com", ip_addr);
11740 session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr);
[email protected]2d88e7d2012-07-19 17:55:1711741
11742 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711743 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]2d88e7d2012-07-19 17:55:1711744
11745 // Start the first transaction to set up the SpdySession
11746 HttpRequestInfo request1;
11747 request1.method = "GET";
11748 request1.url = GURL(url1);
[email protected]2d88e7d2012-07-19 17:55:1711749 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011750 HttpNetworkTransaction trans1(LOWEST, session.get());
[email protected]2d88e7d2012-07-19 17:55:1711751 TestCompletionCallback callback1;
11752 ASSERT_EQ(ERR_IO_PENDING,
11753 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
11754 data1->RunFor(3);
11755
11756 ASSERT_TRUE(callback1.have_result());
11757 EXPECT_EQ(OK, callback1.WaitForResult());
11758 EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy);
11759
11760 // Now, start the HTTP request
11761 HttpRequestInfo request2;
11762 request2.method = "GET";
11763 request2.url = GURL(url2);
[email protected]2d88e7d2012-07-19 17:55:1711764 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011765 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]2d88e7d2012-07-19 17:55:1711766 TestCompletionCallback callback2;
11767 EXPECT_EQ(ERR_IO_PENDING,
11768 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411769 base::MessageLoop::current()->RunUntilIdle();
[email protected]2d88e7d2012-07-19 17:55:1711770 data2->RunFor(3);
11771
11772 ASSERT_TRUE(callback2.have_result());
11773 EXPECT_EQ(OK, callback2.WaitForResult());
11774 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11775}
11776
[email protected]85f97342013-04-17 06:12:2411777// Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED
11778// error) in SPDY session, removes the socket from pool and closes the SPDY
11779// session. Verify that new url's from the same HttpNetworkSession (and a new
11780// SpdySession) do work. http://crbug.com/224701
[email protected]23e482282013-06-14 16:08:0211781TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) {
[email protected]85f97342013-04-17 06:12:2411782 const std::string https_url = "https://www.google.com/";
11783
11784 MockRead reads1[] = {
11785 MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0)
11786 };
11787
11788 scoped_ptr<DeterministicSocketData> data1(
11789 new DeterministicSocketData(reads1, arraysize(reads1), NULL, 0));
11790 data1->SetStop(1);
11791
[email protected]cdf8f7e72013-05-23 10:56:4611792 scoped_ptr<SpdyFrame> req2(
11793 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM));
[email protected]85f97342013-04-17 06:12:2411794 MockWrite writes2[] = {
11795 CreateMockWrite(*req2, 0),
11796 };
11797
[email protected]23e482282013-06-14 16:08:0211798 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11799 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]85f97342013-04-17 06:12:2411800 MockRead reads2[] = {
11801 CreateMockRead(*resp2, 1),
11802 CreateMockRead(*body2, 2),
11803 MockRead(ASYNC, OK, 3) // EOF
11804 };
11805
11806 scoped_ptr<DeterministicSocketData> data2(
11807 new DeterministicSocketData(reads2, arraysize(reads2),
11808 writes2, arraysize(writes2)));
11809
[email protected]85f97342013-04-17 06:12:2411810 SSLSocketDataProvider ssl1(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211811 ssl1.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711812 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1);
11813 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11814 data1.get());
[email protected]85f97342013-04-17 06:12:2411815
11816 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211817 ssl2.SetNextProto(GetParam());
[email protected]bb88e1d32013-05-03 23:11:0711818 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2);
11819 session_deps_.deterministic_socket_factory->AddSocketDataProvider(
11820 data2.get());
[email protected]85f97342013-04-17 06:12:2411821
11822 scoped_refptr<HttpNetworkSession> session(
[email protected]bb88e1d32013-05-03 23:11:0711823 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_));
[email protected]85f97342013-04-17 06:12:2411824
11825 // Start the first transaction to set up the SpdySession and verify that
11826 // connection was closed.
11827 HttpRequestInfo request1;
11828 request1.method = "GET";
11829 request1.url = GURL(https_url);
11830 request1.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011831 HttpNetworkTransaction trans1(MEDIUM, session.get());
[email protected]85f97342013-04-17 06:12:2411832 TestCompletionCallback callback1;
11833 EXPECT_EQ(ERR_IO_PENDING,
11834 trans1.Start(&request1, callback1.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411835 base::MessageLoop::current()->RunUntilIdle();
[email protected]85f97342013-04-17 06:12:2411836 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult());
11837
11838 // Now, start the second request and make sure it succeeds.
11839 HttpRequestInfo request2;
11840 request2.method = "GET";
11841 request2.url = GURL(https_url);
11842 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011843 HttpNetworkTransaction trans2(MEDIUM, session.get());
[email protected]85f97342013-04-17 06:12:2411844 TestCompletionCallback callback2;
11845 EXPECT_EQ(ERR_IO_PENDING,
11846 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
[email protected]2da659e2013-05-23 20:51:3411847 base::MessageLoop::current()->RunUntilIdle();
[email protected]85f97342013-04-17 06:12:2411848 data2->RunFor(3);
11849
11850 ASSERT_TRUE(callback2.have_result());
11851 EXPECT_EQ(OK, callback2.WaitForResult());
11852 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy);
11853}
11854
[email protected]23e482282013-06-14 16:08:0211855TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) {
[email protected]d7599122014-05-24 03:37:2311856 session_deps_.next_protos = SpdyNextProtos();
[email protected]483fa202013-05-14 01:07:0311857 ClientSocketPoolManager::set_max_sockets_per_group(
11858 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
11859 ClientSocketPoolManager::set_max_sockets_per_pool(
11860 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
11861
11862 // Use two different hosts with different IPs so they don't get pooled.
11863 session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1");
11864 session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2");
11865 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
11866
11867 SSLSocketDataProvider ssl1(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211868 ssl1.SetNextProto(GetParam());
[email protected]483fa202013-05-14 01:07:0311869 SSLSocketDataProvider ssl2(ASYNC, OK);
[email protected]23e482282013-06-14 16:08:0211870 ssl2.SetNextProto(GetParam());
[email protected]483fa202013-05-14 01:07:0311871 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1);
11872 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2);
11873
[email protected]cdf8f7e72013-05-23 10:56:4611874 scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet(
[email protected]483fa202013-05-14 01:07:0311875 "https://www.a.com", false, 1, DEFAULT_PRIORITY));
11876 MockWrite spdy1_writes[] = {
11877 CreateMockWrite(*host1_req, 1),
11878 };
[email protected]23e482282013-06-14 16:08:0211879 scoped_ptr<SpdyFrame> host1_resp(
11880 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11881 scoped_ptr<SpdyFrame> host1_resp_body(
11882 spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]483fa202013-05-14 01:07:0311883 MockRead spdy1_reads[] = {
11884 CreateMockRead(*host1_resp, 2),
11885 CreateMockRead(*host1_resp_body, 3),
11886 MockRead(ASYNC, ERR_IO_PENDING, 4),
11887 };
11888
11889 scoped_ptr<OrderedSocketData> spdy1_data(
11890 new OrderedSocketData(
11891 spdy1_reads, arraysize(spdy1_reads),
11892 spdy1_writes, arraysize(spdy1_writes)));
11893 session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get());
11894
[email protected]cdf8f7e72013-05-23 10:56:4611895 scoped_ptr<SpdyFrame> host2_req(spdy_util_.ConstructSpdyGet(
[email protected]483fa202013-05-14 01:07:0311896 "https://www.b.com", false, 1, DEFAULT_PRIORITY));
11897 MockWrite spdy2_writes[] = {
11898 CreateMockWrite(*host2_req, 1),
11899 };
[email protected]23e482282013-06-14 16:08:0211900 scoped_ptr<SpdyFrame> host2_resp(
11901 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
11902 scoped_ptr<SpdyFrame> host2_resp_body(
11903 spdy_util_.ConstructSpdyBodyFrame(1, true));
[email protected]483fa202013-05-14 01:07:0311904 MockRead spdy2_reads[] = {
11905 CreateMockRead(*host2_resp, 2),
11906 CreateMockRead(*host2_resp_body, 3),
11907 MockRead(ASYNC, ERR_IO_PENDING, 4),
11908 };
11909
11910 scoped_ptr<OrderedSocketData> spdy2_data(
11911 new OrderedSocketData(
11912 spdy2_reads, arraysize(spdy2_reads),
11913 spdy2_writes, arraysize(spdy2_writes)));
11914 session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get());
11915
11916 MockWrite http_write[] = {
11917 MockWrite("GET / HTTP/1.1\r\n"
11918 "Host: www.a.com\r\n"
11919 "Connection: keep-alive\r\n\r\n"),
11920 };
11921
11922 MockRead http_read[] = {
11923 MockRead("HTTP/1.1 200 OK\r\n"),
11924 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
11925 MockRead("Content-Length: 6\r\n\r\n"),
11926 MockRead("hello!"),
11927 };
11928 StaticSocketDataProvider http_data(http_read, arraysize(http_read),
11929 http_write, arraysize(http_write));
11930 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
11931
11932 HostPortPair host_port_pair_a("www.a.com", 443);
[email protected]e6d017652013-05-17 18:01:4011933 SpdySessionKey spdy_session_key_a(
[email protected]314b03992014-04-01 01:28:5311934 host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311935 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611936 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311937
11938 TestCompletionCallback callback;
11939 HttpRequestInfo request1;
11940 request1.method = "GET";
11941 request1.url = GURL("https://www.a.com/");
11942 request1.load_flags = 0;
11943 scoped_ptr<HttpNetworkTransaction> trans(
[email protected]90499482013-06-01 00:39:5011944 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0311945
11946 int rv = trans->Start(&request1, callback.callback(), BoundNetLog());
11947 EXPECT_EQ(ERR_IO_PENDING, rv);
11948 EXPECT_EQ(OK, callback.WaitForResult());
11949
11950 const HttpResponseInfo* response = trans->GetResponseInfo();
11951 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011952 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0311953 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11954 EXPECT_TRUE(response->was_fetched_via_spdy);
11955 EXPECT_TRUE(response->was_npn_negotiated);
11956
11957 std::string response_data;
11958 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
11959 EXPECT_EQ("hello!", response_data);
11960 trans.reset();
11961 EXPECT_TRUE(
[email protected]41d64e82013-07-03 22:44:2611962 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311963
11964 HostPortPair host_port_pair_b("www.b.com", 443);
[email protected]e6d017652013-05-17 18:01:4011965 SpdySessionKey spdy_session_key_b(
[email protected]314b03992014-04-01 01:28:5311966 host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311967 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611968 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0311969 HttpRequestInfo request2;
11970 request2.method = "GET";
11971 request2.url = GURL("https://www.b.com/");
11972 request2.load_flags = 0;
[email protected]90499482013-06-01 00:39:5011973 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0311974
11975 rv = trans->Start(&request2, callback.callback(), BoundNetLog());
11976 EXPECT_EQ(ERR_IO_PENDING, rv);
11977 EXPECT_EQ(OK, callback.WaitForResult());
11978
11979 response = trans->GetResponseInfo();
11980 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5011981 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0311982 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
11983 EXPECT_TRUE(response->was_fetched_via_spdy);
11984 EXPECT_TRUE(response->was_npn_negotiated);
11985 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
11986 EXPECT_EQ("hello!", response_data);
11987 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611988 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0311989 EXPECT_TRUE(
[email protected]41d64e82013-07-03 22:44:2611990 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0311991
11992 HostPortPair host_port_pair_a1("www.a.com", 80);
[email protected]e6d017652013-05-17 18:01:4011993 SpdySessionKey spdy_session_key_a1(
[email protected]314b03992014-04-01 01:28:5311994 host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
[email protected]483fa202013-05-14 01:07:0311995 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2611996 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1));
[email protected]483fa202013-05-14 01:07:0311997 HttpRequestInfo request3;
11998 request3.method = "GET";
11999 request3.url = GURL("http://www.a.com/");
12000 request3.load_flags = 0;
[email protected]90499482013-06-01 00:39:5012001 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]483fa202013-05-14 01:07:0312002
12003 rv = trans->Start(&request3, callback.callback(), BoundNetLog());
12004 EXPECT_EQ(ERR_IO_PENDING, rv);
12005 EXPECT_EQ(OK, callback.WaitForResult());
12006
12007 response = trans->GetResponseInfo();
12008 ASSERT_TRUE(response != NULL);
[email protected]90499482013-06-01 00:39:5012009 ASSERT_TRUE(response->headers.get() != NULL);
[email protected]483fa202013-05-14 01:07:0312010 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
12011 EXPECT_FALSE(response->was_fetched_via_spdy);
12012 EXPECT_FALSE(response->was_npn_negotiated);
12013 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
12014 EXPECT_EQ("hello!", response_data);
12015 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2612016 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a));
[email protected]483fa202013-05-14 01:07:0312017 EXPECT_FALSE(
[email protected]41d64e82013-07-03 22:44:2612018 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b));
[email protected]483fa202013-05-14 01:07:0312019}
12020
[email protected]79e1fd62013-06-20 06:50:0412021TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) {
12022 HttpRequestInfo request;
12023 request.method = "GET";
12024 request.url = GURL("http://www.google.com/");
12025 request.load_flags = 0;
12026
[email protected]3fe8d2f82013-10-17 08:56:0712027 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412028 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112029 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412030
12031 MockConnect mock_connect(SYNCHRONOUS, ERR_CONNECTION_REFUSED);
12032 StaticSocketDataProvider data;
12033 data.set_connect_data(mock_connect);
12034 session_deps_.socket_factory->AddSocketDataProvider(&data);
12035
12036 TestCompletionCallback callback;
12037
12038 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12039 EXPECT_EQ(ERR_IO_PENDING, rv);
12040
12041 rv = callback.WaitForResult();
12042 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
12043
12044 EXPECT_EQ(NULL, trans->GetResponseInfo());
12045
12046 // We don't care whether this succeeds or fails, but it shouldn't crash.
12047 HttpRequestHeaders request_headers;
12048 trans->GetFullRequestHeaders(&request_headers);
12049}
12050
12051TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) {
12052 HttpRequestInfo request;
12053 request.method = "GET";
12054 request.url = GURL("http://www.google.com/");
12055 request.load_flags = 0;
12056
[email protected]3fe8d2f82013-10-17 08:56:0712057 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412058 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112059 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412060
12061 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
12062 StaticSocketDataProvider data;
12063 data.set_connect_data(mock_connect);
12064 session_deps_.socket_factory->AddSocketDataProvider(&data);
12065
12066 TestCompletionCallback callback;
12067
12068 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12069 EXPECT_EQ(ERR_IO_PENDING, rv);
12070
12071 rv = callback.WaitForResult();
12072 EXPECT_EQ(ERR_CONNECTION_REFUSED, rv);
12073
12074 EXPECT_EQ(NULL, trans->GetResponseInfo());
12075
12076 // We don't care whether this succeeds or fails, but it shouldn't crash.
12077 HttpRequestHeaders request_headers;
12078 trans->GetFullRequestHeaders(&request_headers);
12079}
12080
12081TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) {
12082 HttpRequestInfo request;
12083 request.method = "GET";
12084 request.url = GURL("http://www.google.com/");
12085 request.load_flags = 0;
12086
[email protected]3fe8d2f82013-10-17 08:56:0712087 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412088 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112089 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412090
12091 MockWrite data_writes[] = {
12092 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12093 };
12094 MockRead data_reads[] = {
12095 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
12096 };
12097
12098 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12099 data_writes, arraysize(data_writes));
12100 session_deps_.socket_factory->AddSocketDataProvider(&data);
12101
12102 TestCompletionCallback callback;
12103
12104 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12105 EXPECT_EQ(ERR_IO_PENDING, rv);
12106
12107 rv = callback.WaitForResult();
12108 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12109
12110 EXPECT_EQ(NULL, trans->GetResponseInfo());
12111
12112 HttpRequestHeaders request_headers;
12113 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12114 EXPECT_TRUE(request_headers.HasHeader("Host"));
12115}
12116
12117TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) {
12118 HttpRequestInfo request;
12119 request.method = "GET";
12120 request.url = GURL("http://www.google.com/");
12121 request.load_flags = 0;
12122
[email protected]3fe8d2f82013-10-17 08:56:0712123 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412124 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112125 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412126
12127 MockWrite data_writes[] = {
12128 MockWrite(ASYNC, ERR_CONNECTION_RESET),
12129 };
12130 MockRead data_reads[] = {
12131 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached.
12132 };
12133
12134 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12135 data_writes, arraysize(data_writes));
12136 session_deps_.socket_factory->AddSocketDataProvider(&data);
12137
12138 TestCompletionCallback callback;
12139
12140 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12141 EXPECT_EQ(ERR_IO_PENDING, rv);
12142
12143 rv = callback.WaitForResult();
12144 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12145
12146 EXPECT_EQ(NULL, trans->GetResponseInfo());
12147
12148 HttpRequestHeaders request_headers;
12149 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12150 EXPECT_TRUE(request_headers.HasHeader("Host"));
12151}
12152
12153TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) {
12154 HttpRequestInfo request;
12155 request.method = "GET";
12156 request.url = GURL("http://www.google.com/");
12157 request.load_flags = 0;
12158
[email protected]3fe8d2f82013-10-17 08:56:0712159 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412160 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112161 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412162
12163 MockWrite data_writes[] = {
12164 MockWrite("GET / HTTP/1.1\r\n"
12165 "Host: www.google.com\r\n"
12166 "Connection: keep-alive\r\n\r\n"),
12167 };
12168 MockRead data_reads[] = {
12169 MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET),
12170 };
12171
12172 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12173 data_writes, arraysize(data_writes));
12174 session_deps_.socket_factory->AddSocketDataProvider(&data);
12175
12176 TestCompletionCallback callback;
12177
12178 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12179 EXPECT_EQ(ERR_IO_PENDING, rv);
12180
12181 rv = callback.WaitForResult();
12182 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12183
12184 EXPECT_EQ(NULL, trans->GetResponseInfo());
12185
12186 HttpRequestHeaders request_headers;
12187 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12188 EXPECT_TRUE(request_headers.HasHeader("Host"));
12189}
12190
12191TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) {
12192 HttpRequestInfo request;
12193 request.method = "GET";
12194 request.url = GURL("http://www.google.com/");
12195 request.load_flags = 0;
12196
[email protected]3fe8d2f82013-10-17 08:56:0712197 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412198 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112199 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412200
12201 MockWrite data_writes[] = {
12202 MockWrite("GET / HTTP/1.1\r\n"
12203 "Host: www.google.com\r\n"
12204 "Connection: keep-alive\r\n\r\n"),
12205 };
12206 MockRead data_reads[] = {
12207 MockRead(ASYNC, ERR_CONNECTION_RESET),
12208 };
12209
12210 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12211 data_writes, arraysize(data_writes));
12212 session_deps_.socket_factory->AddSocketDataProvider(&data);
12213
12214 TestCompletionCallback callback;
12215
12216 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12217 EXPECT_EQ(ERR_IO_PENDING, rv);
12218
12219 rv = callback.WaitForResult();
12220 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
12221
12222 EXPECT_EQ(NULL, trans->GetResponseInfo());
12223
12224 HttpRequestHeaders request_headers;
12225 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12226 EXPECT_TRUE(request_headers.HasHeader("Host"));
12227}
12228
12229TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) {
12230 HttpRequestInfo request;
12231 request.method = "GET";
12232 request.url = GURL("http://www.google.com/");
12233 request.load_flags = 0;
12234 request.extra_headers.SetHeader("X-Foo", "bar");
12235
[email protected]3fe8d2f82013-10-17 08:56:0712236 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
[email protected]79e1fd62013-06-20 06:50:0412237 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112238 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]79e1fd62013-06-20 06:50:0412239
12240 MockWrite data_writes[] = {
12241 MockWrite("GET / HTTP/1.1\r\n"
12242 "Host: www.google.com\r\n"
12243 "Connection: keep-alive\r\n"
12244 "X-Foo: bar\r\n\r\n"),
12245 };
12246 MockRead data_reads[] = {
12247 MockRead("HTTP/1.1 200 OK\r\n"
12248 "Content-Length: 5\r\n\r\n"
12249 "hello"),
12250 MockRead(ASYNC, ERR_UNEXPECTED),
12251 };
12252
12253 StaticSocketDataProvider data(data_reads, arraysize(data_reads),
12254 data_writes, arraysize(data_writes));
12255 session_deps_.socket_factory->AddSocketDataProvider(&data);
12256
12257 TestCompletionCallback callback;
12258
12259 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12260 EXPECT_EQ(ERR_IO_PENDING, rv);
12261
12262 rv = callback.WaitForResult();
12263 EXPECT_EQ(OK, rv);
12264
12265 HttpRequestHeaders request_headers;
12266 EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers));
12267 std::string foo;
12268 EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo));
12269 EXPECT_EQ("bar", foo);
12270}
12271
[email protected]bf828982013-08-14 18:01:4712272namespace {
12273
yhiranoa7e05bb2014-11-06 05:40:3912274// Fake HttpStream that simply records calls to SetPriority().
12275class FakeStream : public HttpStream,
[email protected]e86839fd2013-08-14 18:29:0312276 public base::SupportsWeakPtr<FakeStream> {
12277 public:
12278 explicit FakeStream(RequestPriority priority) : priority_(priority) {}
dchengb03027d2014-10-21 12:00:2012279 ~FakeStream() override {}
[email protected]e86839fd2013-08-14 18:29:0312280
12281 RequestPriority priority() const { return priority_; }
12282
dchengb03027d2014-10-21 12:00:2012283 int InitializeStream(const HttpRequestInfo* request_info,
12284 RequestPriority priority,
12285 const BoundNetLog& net_log,
12286 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312287 return ERR_IO_PENDING;
12288 }
12289
dchengb03027d2014-10-21 12:00:2012290 int SendRequest(const HttpRequestHeaders& request_headers,
12291 HttpResponseInfo* response,
12292 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312293 ADD_FAILURE();
12294 return ERR_UNEXPECTED;
12295 }
12296
dchengb03027d2014-10-21 12:00:2012297 int ReadResponseHeaders(const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312298 ADD_FAILURE();
12299 return ERR_UNEXPECTED;
12300 }
12301
dchengb03027d2014-10-21 12:00:2012302 int ReadResponseBody(IOBuffer* buf,
12303 int buf_len,
12304 const CompletionCallback& callback) override {
[email protected]e86839fd2013-08-14 18:29:0312305 ADD_FAILURE();
12306 return ERR_UNEXPECTED;
12307 }
12308
dchengb03027d2014-10-21 12:00:2012309 void Close(bool not_reusable) override {}
[email protected]e86839fd2013-08-14 18:29:0312310
dchengb03027d2014-10-21 12:00:2012311 bool IsResponseBodyComplete() const override {
[email protected]e86839fd2013-08-14 18:29:0312312 ADD_FAILURE();
12313 return false;
12314 }
12315
dchengb03027d2014-10-21 12:00:2012316 bool CanFindEndOfResponse() const override { return false; }
[email protected]e86839fd2013-08-14 18:29:0312317
dchengb03027d2014-10-21 12:00:2012318 bool IsConnectionReused() const override {
[email protected]e86839fd2013-08-14 18:29:0312319 ADD_FAILURE();
12320 return false;
12321 }
12322
dchengb03027d2014-10-21 12:00:2012323 void SetConnectionReused() override { ADD_FAILURE(); }
[email protected]e86839fd2013-08-14 18:29:0312324
dchengb03027d2014-10-21 12:00:2012325 bool IsConnectionReusable() const override {
[email protected]e86839fd2013-08-14 18:29:0312326 ADD_FAILURE();
12327 return false;
12328 }
12329
dchengb03027d2014-10-21 12:00:2012330 int64 GetTotalReceivedBytes() const override {
[email protected]bc92bc972013-12-13 08:32:5912331 ADD_FAILURE();
12332 return 0;
12333 }
12334
dchengb03027d2014-10-21 12:00:2012335 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override {
[email protected]e86839fd2013-08-14 18:29:0312336 ADD_FAILURE();
12337 return false;
12338 }
12339
dchengb03027d2014-10-21 12:00:2012340 void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); }
12341
12342 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {
[email protected]e86839fd2013-08-14 18:29:0312343 ADD_FAILURE();
12344 }
12345
dchengb03027d2014-10-21 12:00:2012346 bool IsSpdyHttpStream() const override {
[email protected]e86839fd2013-08-14 18:29:0312347 ADD_FAILURE();
12348 return false;
12349 }
12350
dchengb03027d2014-10-21 12:00:2012351 void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); }
[email protected]e86839fd2013-08-14 18:29:0312352
dchengb03027d2014-10-21 12:00:2012353 void SetPriority(RequestPriority priority) override { priority_ = priority; }
[email protected]e86839fd2013-08-14 18:29:0312354
yhiranoa7e05bb2014-11-06 05:40:3912355 UploadProgress GetUploadProgress() const override { return UploadProgress(); }
12356
12357 HttpStream* RenewStreamForAuth() override { return NULL; }
12358
[email protected]e86839fd2013-08-14 18:29:0312359 private:
12360 RequestPriority priority_;
12361
12362 DISALLOW_COPY_AND_ASSIGN(FakeStream);
12363};
12364
12365// Fake HttpStreamRequest that simply records calls to SetPriority()
12366// and vends FakeStreams with its current priority.
[email protected]bf828982013-08-14 18:01:4712367class FakeStreamRequest : public HttpStreamRequest,
12368 public base::SupportsWeakPtr<FakeStreamRequest> {
12369 public:
[email protected]e86839fd2013-08-14 18:29:0312370 FakeStreamRequest(RequestPriority priority,
12371 HttpStreamRequest::Delegate* delegate)
12372 : priority_(priority),
[email protected]831e4a32013-11-14 02:14:4412373 delegate_(delegate),
12374 websocket_stream_create_helper_(NULL) {}
12375
12376 FakeStreamRequest(RequestPriority priority,
12377 HttpStreamRequest::Delegate* delegate,
12378 WebSocketHandshakeStreamBase::CreateHelper* create_helper)
12379 : priority_(priority),
12380 delegate_(delegate),
12381 websocket_stream_create_helper_(create_helper) {}
[email protected]e86839fd2013-08-14 18:29:0312382
dchengb03027d2014-10-21 12:00:2012383 ~FakeStreamRequest() override {}
[email protected]bf828982013-08-14 18:01:4712384
12385 RequestPriority priority() const { return priority_; }
12386
[email protected]831e4a32013-11-14 02:14:4412387 const WebSocketHandshakeStreamBase::CreateHelper*
12388 websocket_stream_create_helper() const {
12389 return websocket_stream_create_helper_;
12390 }
12391
[email protected]e86839fd2013-08-14 18:29:0312392 // Create a new FakeStream and pass it to the request's
12393 // delegate. Returns a weak pointer to the FakeStream.
12394 base::WeakPtr<FakeStream> FinishStreamRequest() {
12395 FakeStream* fake_stream = new FakeStream(priority_);
12396 // Do this before calling OnStreamReady() as OnStreamReady() may
12397 // immediately delete |fake_stream|.
12398 base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr();
12399 delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream);
12400 return weak_stream;
12401 }
12402
dchengb03027d2014-10-21 12:00:2012403 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override {
[email protected]bf828982013-08-14 18:01:4712404 ADD_FAILURE();
12405 return ERR_UNEXPECTED;
12406 }
12407
dchengb03027d2014-10-21 12:00:2012408 LoadState GetLoadState() const override {
[email protected]bf828982013-08-14 18:01:4712409 ADD_FAILURE();
12410 return LoadState();
12411 }
12412
dchengb03027d2014-10-21 12:00:2012413 void SetPriority(RequestPriority priority) override { priority_ = priority; }
[email protected]bf828982013-08-14 18:01:4712414
dchengb03027d2014-10-21 12:00:2012415 bool was_npn_negotiated() const override { return false; }
[email protected]bf828982013-08-14 18:01:4712416
dchengb03027d2014-10-21 12:00:2012417 NextProto protocol_negotiated() const override { return kProtoUnknown; }
[email protected]bf828982013-08-14 18:01:4712418
dchengb03027d2014-10-21 12:00:2012419 bool using_spdy() const override { return false; }
[email protected]bf828982013-08-14 18:01:4712420
12421 private:
12422 RequestPriority priority_;
[email protected]e86839fd2013-08-14 18:29:0312423 HttpStreamRequest::Delegate* const delegate_;
[email protected]831e4a32013-11-14 02:14:4412424 WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_;
[email protected]bf828982013-08-14 18:01:4712425
12426 DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest);
12427};
12428
12429// Fake HttpStreamFactory that vends FakeStreamRequests.
12430class FakeStreamFactory : public HttpStreamFactory {
12431 public:
12432 FakeStreamFactory() {}
dchengb03027d2014-10-21 12:00:2012433 ~FakeStreamFactory() override {}
[email protected]bf828982013-08-14 18:01:4712434
12435 // Returns a WeakPtr<> to the last HttpStreamRequest returned by
12436 // RequestStream() (which may be NULL if it was destroyed already).
12437 base::WeakPtr<FakeStreamRequest> last_stream_request() {
12438 return last_stream_request_;
12439 }
12440
dchengb03027d2014-10-21 12:00:2012441 HttpStreamRequest* RequestStream(const HttpRequestInfo& info,
12442 RequestPriority priority,
12443 const SSLConfig& server_ssl_config,
12444 const SSLConfig& proxy_ssl_config,
12445 HttpStreamRequest::Delegate* delegate,
12446 const BoundNetLog& net_log) override {
[email protected]e86839fd2013-08-14 18:29:0312447 FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate);
[email protected]bf828982013-08-14 18:01:4712448 last_stream_request_ = fake_request->AsWeakPtr();
12449 return fake_request;
12450 }
12451
dchengb03027d2014-10-21 12:00:2012452 HttpStreamRequest* RequestWebSocketHandshakeStream(
[email protected]bf828982013-08-14 18:01:4712453 const HttpRequestInfo& info,
12454 RequestPriority priority,
12455 const SSLConfig& server_ssl_config,
12456 const SSLConfig& proxy_ssl_config,
12457 HttpStreamRequest::Delegate* delegate,
[email protected]467086b2013-11-12 08:19:4612458 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
mostynbba063d6032014-10-09 11:01:1312459 const BoundNetLog& net_log) override {
[email protected]831e4a32013-11-14 02:14:4412460 FakeStreamRequest* fake_request =
12461 new FakeStreamRequest(priority, delegate, create_helper);
12462 last_stream_request_ = fake_request->AsWeakPtr();
12463 return fake_request;
[email protected]bf828982013-08-14 18:01:4712464 }
12465
dchengb03027d2014-10-21 12:00:2012466 void PreconnectStreams(int num_streams,
12467 const HttpRequestInfo& info,
12468 RequestPriority priority,
12469 const SSLConfig& server_ssl_config,
12470 const SSLConfig& proxy_ssl_config) override {
[email protected]bf828982013-08-14 18:01:4712471 ADD_FAILURE();
12472 }
12473
dchengb03027d2014-10-21 12:00:2012474 const HostMappingRules* GetHostMappingRules() const override {
[email protected]bf828982013-08-14 18:01:4712475 ADD_FAILURE();
12476 return NULL;
12477 }
12478
12479 private:
12480 base::WeakPtr<FakeStreamRequest> last_stream_request_;
12481
12482 DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory);
12483};
12484
Adam Rice425cf122015-01-19 06:18:2412485// TODO(ricea): Maybe unify this with the one in
12486// url_request_http_job_unittest.cc ?
12487class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase {
12488 public:
12489 FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection,
12490 bool using_proxy)
12491 : state_(connection.release(), using_proxy) {}
12492
12493 // Fake implementation of HttpStreamBase methods.
12494 // This ends up being quite "real" because this object has to really send data
12495 // on the mock socket. It might be easier to use the real implementation, but
12496 // the fact that the WebSocket code is not compiled on iOS makes that
12497 // difficult.
12498 int InitializeStream(const HttpRequestInfo* request_info,
12499 RequestPriority priority,
12500 const BoundNetLog& net_log,
12501 const CompletionCallback& callback) override {
12502 state_.Initialize(request_info, priority, net_log, callback);
12503 return OK;
12504 }
12505
12506 int SendRequest(const HttpRequestHeaders& request_headers,
12507 HttpResponseInfo* response,
12508 const CompletionCallback& callback) override {
12509 return parser()->SendRequest(state_.GenerateRequestLine(), request_headers,
12510 response, callback);
12511 }
12512
12513 int ReadResponseHeaders(const CompletionCallback& callback) override {
12514 return parser()->ReadResponseHeaders(callback);
12515 }
12516
12517 int ReadResponseBody(IOBuffer* buf,
12518 int buf_len,
12519 const CompletionCallback& callback) override {
12520 NOTREACHED();
12521 return ERR_IO_PENDING;
12522 }
12523
12524 void Close(bool not_reusable) override {
12525 if (parser())
12526 parser()->Close(true);
12527 }
12528
12529 bool IsResponseBodyComplete() const override {
12530 NOTREACHED();
12531 return false;
12532 }
12533
12534 bool CanFindEndOfResponse() const override {
12535 return parser()->CanFindEndOfResponse();
12536 }
12537
12538 bool IsConnectionReused() const override {
12539 NOTREACHED();
12540 return false;
12541 }
12542 void SetConnectionReused() override { NOTREACHED(); }
12543
12544 bool IsConnectionReusable() const override {
12545 NOTREACHED();
12546 return false;
12547 }
12548
12549 int64 GetTotalReceivedBytes() const override {
12550 NOTREACHED();
12551 return 0;
12552 }
12553
12554 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override {
12555 NOTREACHED();
12556 return false;
12557 }
12558
12559 void GetSSLInfo(SSLInfo* ssl_info) override { NOTREACHED(); }
12560
12561 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {
12562 NOTREACHED();
12563 }
12564
12565 bool IsSpdyHttpStream() const override {
12566 NOTREACHED();
12567 return false;
12568 }
12569
12570 void Drain(HttpNetworkSession* session) override { NOTREACHED(); }
12571
12572 void SetPriority(RequestPriority priority) override { NOTREACHED(); }
12573
12574 UploadProgress GetUploadProgress() const override {
12575 NOTREACHED();
12576 return UploadProgress();
12577 }
12578
12579 HttpStream* RenewStreamForAuth() override {
12580 NOTREACHED();
12581 return nullptr;
12582 }
12583
12584 // Fake implementation of WebSocketHandshakeStreamBase method(s)
12585 scoped_ptr<WebSocketStream> Upgrade() override {
12586 NOTREACHED();
12587 return scoped_ptr<WebSocketStream>();
12588 }
12589
12590 private:
12591 HttpStreamParser* parser() const { return state_.parser(); }
12592 HttpBasicState state_;
12593
12594 DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream);
12595};
12596
[email protected]831e4a32013-11-14 02:14:4412597// TODO(yhirano): Split this class out into a net/websockets file, if it is
12598// worth doing.
12599class FakeWebSocketStreamCreateHelper :
12600 public WebSocketHandshakeStreamBase::CreateHelper {
12601 public:
dchengb03027d2014-10-21 12:00:2012602 WebSocketHandshakeStreamBase* CreateBasicStream(
[email protected]7e841a52013-11-22 09:04:2112603 scoped_ptr<ClientSocketHandle> connection,
mostynbba063d6032014-10-09 11:01:1312604 bool using_proxy) override {
Adam Rice425cf122015-01-19 06:18:2412605 return new FakeWebSocketBasicHandshakeStream(connection.Pass(),
12606 using_proxy);
[email protected]831e4a32013-11-14 02:14:4412607 }
12608
dchengb03027d2014-10-21 12:00:2012609 WebSocketHandshakeStreamBase* CreateSpdyStream(
[email protected]831e4a32013-11-14 02:14:4412610 const base::WeakPtr<SpdySession>& session,
mostynbba063d6032014-10-09 11:01:1312611 bool use_relative_url) override {
[email protected]831e4a32013-11-14 02:14:4412612 NOTREACHED();
12613 return NULL;
12614 };
12615
dchengb03027d2014-10-21 12:00:2012616 ~FakeWebSocketStreamCreateHelper() override {}
[email protected]831e4a32013-11-14 02:14:4412617
12618 virtual scoped_ptr<WebSocketStream> Upgrade() {
12619 NOTREACHED();
12620 return scoped_ptr<WebSocketStream>();
12621 }
12622};
12623
[email protected]bf828982013-08-14 18:01:4712624} // namespace
12625
12626// Make sure that HttpNetworkTransaction passes on its priority to its
12627// stream request on start.
12628TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) {
12629 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12630 HttpNetworkSessionPeer peer(session);
12631 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412632 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]bf828982013-08-14 18:01:4712633
dcheng48459ac22014-08-26 00:46:4112634 HttpNetworkTransaction trans(LOW, session.get());
[email protected]bf828982013-08-14 18:01:4712635
12636 ASSERT_TRUE(fake_factory->last_stream_request() == NULL);
12637
12638 HttpRequestInfo request;
12639 TestCompletionCallback callback;
12640 EXPECT_EQ(ERR_IO_PENDING,
12641 trans.Start(&request, callback.callback(), BoundNetLog()));
12642
12643 base::WeakPtr<FakeStreamRequest> fake_request =
12644 fake_factory->last_stream_request();
12645 ASSERT_TRUE(fake_request != NULL);
12646 EXPECT_EQ(LOW, fake_request->priority());
12647}
12648
12649// Make sure that HttpNetworkTransaction passes on its priority
12650// updates to its stream request.
12651TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) {
12652 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12653 HttpNetworkSessionPeer peer(session);
12654 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412655 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]bf828982013-08-14 18:01:4712656
dcheng48459ac22014-08-26 00:46:4112657 HttpNetworkTransaction trans(LOW, session.get());
[email protected]bf828982013-08-14 18:01:4712658
12659 HttpRequestInfo request;
12660 TestCompletionCallback callback;
12661 EXPECT_EQ(ERR_IO_PENDING,
12662 trans.Start(&request, callback.callback(), BoundNetLog()));
12663
12664 base::WeakPtr<FakeStreamRequest> fake_request =
12665 fake_factory->last_stream_request();
12666 ASSERT_TRUE(fake_request != NULL);
12667 EXPECT_EQ(LOW, fake_request->priority());
12668
12669 trans.SetPriority(LOWEST);
12670 ASSERT_TRUE(fake_request != NULL);
12671 EXPECT_EQ(LOWEST, fake_request->priority());
12672}
12673
[email protected]e86839fd2013-08-14 18:29:0312674// Make sure that HttpNetworkTransaction passes on its priority
12675// updates to its stream.
12676TEST_P(HttpNetworkTransactionTest, SetStreamPriority) {
12677 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12678 HttpNetworkSessionPeer peer(session);
12679 FakeStreamFactory* fake_factory = new FakeStreamFactory();
[email protected]831e4a32013-11-14 02:14:4412680 peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory));
[email protected]e86839fd2013-08-14 18:29:0312681
dcheng48459ac22014-08-26 00:46:4112682 HttpNetworkTransaction trans(LOW, session.get());
[email protected]e86839fd2013-08-14 18:29:0312683
12684 HttpRequestInfo request;
12685 TestCompletionCallback callback;
12686 EXPECT_EQ(ERR_IO_PENDING,
12687 trans.Start(&request, callback.callback(), BoundNetLog()));
12688
12689 base::WeakPtr<FakeStreamRequest> fake_request =
12690 fake_factory->last_stream_request();
12691 ASSERT_TRUE(fake_request != NULL);
12692 base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest();
12693 ASSERT_TRUE(fake_stream != NULL);
12694 EXPECT_EQ(LOW, fake_stream->priority());
12695
12696 trans.SetPriority(LOWEST);
12697 EXPECT_EQ(LOWEST, fake_stream->priority());
12698}
12699
[email protected]831e4a32013-11-14 02:14:4412700TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) {
12701 // The same logic needs to be tested for both ws: and wss: schemes, but this
12702 // test is already parameterised on NextProto, so it uses a loop to verify
12703 // that the different schemes work.
12704 std::string test_cases[] = {"ws://www.google.com/", "wss://www.google.com/"};
12705 for (size_t i = 0; i < arraysize(test_cases); ++i) {
12706 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12707 HttpNetworkSessionPeer peer(session);
12708 FakeStreamFactory* fake_factory = new FakeStreamFactory();
12709 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
[email protected]0191b51c2013-11-18 10:55:2312710 peer.SetHttpStreamFactoryForWebSocket(
[email protected]831e4a32013-11-14 02:14:4412711 scoped_ptr<HttpStreamFactory>(fake_factory));
12712
dcheng48459ac22014-08-26 00:46:4112713 HttpNetworkTransaction trans(LOW, session.get());
[email protected]831e4a32013-11-14 02:14:4412714 trans.SetWebSocketHandshakeStreamCreateHelper(
12715 &websocket_stream_create_helper);
12716
12717 HttpRequestInfo request;
12718 TestCompletionCallback callback;
12719 request.method = "GET";
12720 request.url = GURL(test_cases[i]);
12721
12722 EXPECT_EQ(ERR_IO_PENDING,
12723 trans.Start(&request, callback.callback(), BoundNetLog()));
12724
12725 base::WeakPtr<FakeStreamRequest> fake_request =
12726 fake_factory->last_stream_request();
12727 ASSERT_TRUE(fake_request != NULL);
12728 EXPECT_EQ(&websocket_stream_create_helper,
12729 fake_request->websocket_stream_create_helper());
12730 }
12731}
12732
[email protected]043b68c82013-08-22 23:41:5212733// Tests that when a used socket is returned to the SSL socket pool, it's closed
12734// if the transport socket pool is stalled on the global socket limit.
12735TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) {
12736 ClientSocketPoolManager::set_max_sockets_per_group(
12737 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12738 ClientSocketPoolManager::set_max_sockets_per_pool(
12739 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12740
12741 // Set up SSL request.
12742
12743 HttpRequestInfo ssl_request;
12744 ssl_request.method = "GET";
12745 ssl_request.url = GURL("https://www.google.com/");
12746
12747 MockWrite ssl_writes[] = {
12748 MockWrite("GET / HTTP/1.1\r\n"
12749 "Host: www.google.com\r\n"
12750 "Connection: keep-alive\r\n\r\n"),
12751 };
12752 MockRead ssl_reads[] = {
12753 MockRead("HTTP/1.1 200 OK\r\n"),
12754 MockRead("Content-Length: 11\r\n\r\n"),
12755 MockRead("hello world"),
12756 MockRead(SYNCHRONOUS, OK),
12757 };
12758 StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads),
12759 ssl_writes, arraysize(ssl_writes));
12760 session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
12761
12762 SSLSocketDataProvider ssl(ASYNC, OK);
12763 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
12764
12765 // Set up HTTP request.
12766
12767 HttpRequestInfo http_request;
12768 http_request.method = "GET";
12769 http_request.url = GURL("http://www.google.com/");
12770
12771 MockWrite http_writes[] = {
12772 MockWrite("GET / HTTP/1.1\r\n"
12773 "Host: www.google.com\r\n"
12774 "Connection: keep-alive\r\n\r\n"),
12775 };
12776 MockRead http_reads[] = {
12777 MockRead("HTTP/1.1 200 OK\r\n"),
12778 MockRead("Content-Length: 7\r\n\r\n"),
12779 MockRead("falafel"),
12780 MockRead(SYNCHRONOUS, OK),
12781 };
12782 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
12783 http_writes, arraysize(http_writes));
12784 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
12785
12786 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12787
12788 // Start the SSL request.
12789 TestCompletionCallback ssl_callback;
12790 scoped_ptr<HttpTransaction> ssl_trans(
12791 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12792 ASSERT_EQ(ERR_IO_PENDING,
12793 ssl_trans->Start(&ssl_request, ssl_callback.callback(),
12794 BoundNetLog()));
12795
12796 // Start the HTTP request. Pool should stall.
12797 TestCompletionCallback http_callback;
12798 scoped_ptr<HttpTransaction> http_trans(
12799 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12800 ASSERT_EQ(ERR_IO_PENDING,
12801 http_trans->Start(&http_request, http_callback.callback(),
12802 BoundNetLog()));
dcheng48459ac22014-08-26 00:46:4112803 EXPECT_TRUE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212804
12805 // Wait for response from SSL request.
12806 ASSERT_EQ(OK, ssl_callback.WaitForResult());
12807 std::string response_data;
12808 ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data));
12809 EXPECT_EQ("hello world", response_data);
12810
12811 // The SSL socket should automatically be closed, so the HTTP request can
12812 // start.
dcheng48459ac22014-08-26 00:46:4112813 EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get()));
12814 ASSERT_FALSE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212815
12816 // The HTTP request can now complete.
12817 ASSERT_EQ(OK, http_callback.WaitForResult());
12818 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
12819 EXPECT_EQ("falafel", response_data);
12820
dcheng48459ac22014-08-26 00:46:4112821 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212822}
12823
12824// Tests that when a SSL connection is established but there's no corresponding
12825// request that needs it, the new socket is closed if the transport socket pool
12826// is stalled on the global socket limit.
12827TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) {
12828 ClientSocketPoolManager::set_max_sockets_per_group(
12829 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12830 ClientSocketPoolManager::set_max_sockets_per_pool(
12831 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
12832
12833 // Set up an ssl request.
12834
12835 HttpRequestInfo ssl_request;
12836 ssl_request.method = "GET";
12837 ssl_request.url = GURL("https://www.foopy.com/");
12838
12839 // No data will be sent on the SSL socket.
12840 StaticSocketDataProvider ssl_data;
12841 session_deps_.socket_factory->AddSocketDataProvider(&ssl_data);
12842
12843 SSLSocketDataProvider ssl(ASYNC, OK);
12844 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
12845
12846 // Set up HTTP request.
12847
12848 HttpRequestInfo http_request;
12849 http_request.method = "GET";
12850 http_request.url = GURL("http://www.google.com/");
12851
12852 MockWrite http_writes[] = {
12853 MockWrite("GET / HTTP/1.1\r\n"
12854 "Host: www.google.com\r\n"
12855 "Connection: keep-alive\r\n\r\n"),
12856 };
12857 MockRead http_reads[] = {
12858 MockRead("HTTP/1.1 200 OK\r\n"),
12859 MockRead("Content-Length: 7\r\n\r\n"),
12860 MockRead("falafel"),
12861 MockRead(SYNCHRONOUS, OK),
12862 };
12863 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
12864 http_writes, arraysize(http_writes));
12865 session_deps_.socket_factory->AddSocketDataProvider(&http_data);
12866
12867 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12868
12869 // Preconnect an SSL socket. A preconnect is needed because connect jobs are
12870 // cancelled when a normal transaction is cancelled.
12871 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
12872 net::SSLConfig ssl_config;
12873 session->ssl_config_service()->GetSSLConfig(&ssl_config);
12874 http_stream_factory->PreconnectStreams(1, ssl_request, DEFAULT_PRIORITY,
12875 ssl_config, ssl_config);
dcheng48459ac22014-08-26 00:46:4112876 EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212877
12878 // Start the HTTP request. Pool should stall.
12879 TestCompletionCallback http_callback;
12880 scoped_ptr<HttpTransaction> http_trans(
12881 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
12882 ASSERT_EQ(ERR_IO_PENDING,
12883 http_trans->Start(&http_request, http_callback.callback(),
12884 BoundNetLog()));
dcheng48459ac22014-08-26 00:46:4112885 EXPECT_TRUE(IsTransportSocketPoolStalled(session.get()));
[email protected]043b68c82013-08-22 23:41:5212886
12887 // The SSL connection will automatically be closed once the connection is
12888 // established, to let the HTTP request start.
12889 ASSERT_EQ(OK, http_callback.WaitForResult());
12890 std::string response_data;
12891 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data));
12892 EXPECT_EQ("falafel", response_data);
12893
dcheng48459ac22014-08-26 00:46:4112894 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get()));
[email protected]043b68c82013-08-22 23:41:5212895}
12896
[email protected]02d74a02014-04-23 18:10:5412897TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) {
12898 ScopedVector<UploadElementReader> element_readers;
12899 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0712900 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5412901
12902 HttpRequestInfo request;
12903 request.method = "POST";
12904 request.url = GURL("http://www.foo.com/");
12905 request.upload_data_stream = &upload_data_stream;
12906 request.load_flags = 0;
12907
12908 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12909 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4112910 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412911 // Send headers successfully, but get an error while sending the body.
12912 MockWrite data_writes[] = {
12913 MockWrite("POST / HTTP/1.1\r\n"
12914 "Host: www.foo.com\r\n"
12915 "Connection: keep-alive\r\n"
12916 "Content-Length: 3\r\n\r\n"),
12917 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12918 };
12919
12920 MockRead data_reads[] = {
12921 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
12922 MockRead("hello world"),
12923 MockRead(SYNCHRONOUS, OK),
12924 };
12925 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12926 arraysize(data_writes));
12927 session_deps_.socket_factory->AddSocketDataProvider(&data);
12928
12929 TestCompletionCallback callback;
12930
12931 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
12932 EXPECT_EQ(ERR_IO_PENDING, rv);
12933
12934 rv = callback.WaitForResult();
12935 EXPECT_EQ(OK, rv);
12936
12937 const HttpResponseInfo* response = trans->GetResponseInfo();
12938 ASSERT_TRUE(response != NULL);
12939
12940 EXPECT_TRUE(response->headers.get() != NULL);
12941 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
12942
12943 std::string response_data;
12944 rv = ReadTransaction(trans.get(), &response_data);
12945 EXPECT_EQ(OK, rv);
12946 EXPECT_EQ("hello world", response_data);
12947}
12948
12949// This test makes sure the retry logic doesn't trigger when reading an error
12950// response from a server that rejected a POST with a CONNECTION_RESET.
12951TEST_P(HttpNetworkTransactionTest,
12952 PostReadsErrorResponseAfterResetOnReusedSocket) {
12953 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
12954 MockWrite data_writes[] = {
12955 MockWrite("GET / HTTP/1.1\r\n"
12956 "Host: www.foo.com\r\n"
12957 "Connection: keep-alive\r\n\r\n"),
12958 MockWrite("POST / HTTP/1.1\r\n"
12959 "Host: www.foo.com\r\n"
12960 "Connection: keep-alive\r\n"
12961 "Content-Length: 3\r\n\r\n"),
12962 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
12963 };
12964
12965 MockRead data_reads[] = {
12966 MockRead("HTTP/1.1 200 Peachy\r\n"
12967 "Content-Length: 14\r\n\r\n"),
12968 MockRead("first response"),
12969 MockRead("HTTP/1.1 400 Not OK\r\n"
12970 "Content-Length: 15\r\n\r\n"),
12971 MockRead("second response"),
12972 MockRead(SYNCHRONOUS, OK),
12973 };
12974 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
12975 arraysize(data_writes));
12976 session_deps_.socket_factory->AddSocketDataProvider(&data);
12977
12978 TestCompletionCallback callback;
12979 HttpRequestInfo request1;
12980 request1.method = "GET";
12981 request1.url = GURL("http://www.foo.com/");
12982 request1.load_flags = 0;
12983
12984 scoped_ptr<HttpTransaction> trans1(
dcheng48459ac22014-08-26 00:46:4112985 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5412986 int rv = trans1->Start(&request1, callback.callback(), BoundNetLog());
12987 EXPECT_EQ(ERR_IO_PENDING, rv);
12988
12989 rv = callback.WaitForResult();
12990 EXPECT_EQ(OK, rv);
12991
12992 const HttpResponseInfo* response1 = trans1->GetResponseInfo();
12993 ASSERT_TRUE(response1 != NULL);
12994
12995 EXPECT_TRUE(response1->headers.get() != NULL);
12996 EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine());
12997
12998 std::string response_data1;
12999 rv = ReadTransaction(trans1.get(), &response_data1);
13000 EXPECT_EQ(OK, rv);
13001 EXPECT_EQ("first response", response_data1);
13002 // Delete the transaction to release the socket back into the socket pool.
13003 trans1.reset();
13004
13005 ScopedVector<UploadElementReader> element_readers;
13006 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713007 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413008
13009 HttpRequestInfo request2;
13010 request2.method = "POST";
13011 request2.url = GURL("http://www.foo.com/");
13012 request2.upload_data_stream = &upload_data_stream;
13013 request2.load_flags = 0;
13014
13015 scoped_ptr<HttpTransaction> trans2(
dcheng48459ac22014-08-26 00:46:4113016 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413017 rv = trans2->Start(&request2, callback.callback(), BoundNetLog());
13018 EXPECT_EQ(ERR_IO_PENDING, rv);
13019
13020 rv = callback.WaitForResult();
13021 EXPECT_EQ(OK, rv);
13022
13023 const HttpResponseInfo* response2 = trans2->GetResponseInfo();
13024 ASSERT_TRUE(response2 != NULL);
13025
13026 EXPECT_TRUE(response2->headers.get() != NULL);
13027 EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine());
13028
13029 std::string response_data2;
13030 rv = ReadTransaction(trans2.get(), &response_data2);
13031 EXPECT_EQ(OK, rv);
13032 EXPECT_EQ("second response", response_data2);
13033}
13034
13035TEST_P(HttpNetworkTransactionTest,
13036 PostReadsErrorResponseAfterResetPartialBodySent) {
13037 ScopedVector<UploadElementReader> element_readers;
13038 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713039 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413040
13041 HttpRequestInfo request;
13042 request.method = "POST";
13043 request.url = GURL("http://www.foo.com/");
13044 request.upload_data_stream = &upload_data_stream;
13045 request.load_flags = 0;
13046
13047 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13048 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113049 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413050 // Send headers successfully, but get an error while sending the body.
13051 MockWrite data_writes[] = {
13052 MockWrite("POST / HTTP/1.1\r\n"
13053 "Host: www.foo.com\r\n"
13054 "Connection: keep-alive\r\n"
13055 "Content-Length: 3\r\n\r\n"
13056 "fo"),
13057 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13058 };
13059
13060 MockRead data_reads[] = {
13061 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
13062 MockRead("hello world"),
13063 MockRead(SYNCHRONOUS, OK),
13064 };
13065 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13066 arraysize(data_writes));
13067 session_deps_.socket_factory->AddSocketDataProvider(&data);
13068
13069 TestCompletionCallback callback;
13070
13071 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13072 EXPECT_EQ(ERR_IO_PENDING, rv);
13073
13074 rv = callback.WaitForResult();
13075 EXPECT_EQ(OK, rv);
13076
13077 const HttpResponseInfo* response = trans->GetResponseInfo();
13078 ASSERT_TRUE(response != NULL);
13079
13080 EXPECT_TRUE(response->headers.get() != NULL);
13081 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
13082
13083 std::string response_data;
13084 rv = ReadTransaction(trans.get(), &response_data);
13085 EXPECT_EQ(OK, rv);
13086 EXPECT_EQ("hello world", response_data);
13087}
13088
13089// This tests the more common case than the previous test, where headers and
13090// body are not merged into a single request.
13091TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) {
13092 ScopedVector<UploadElementReader> element_readers;
13093 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713094 ChunkedUploadDataStream upload_data_stream(0);
[email protected]02d74a02014-04-23 18:10:5413095
13096 HttpRequestInfo request;
13097 request.method = "POST";
13098 request.url = GURL("http://www.foo.com/");
13099 request.upload_data_stream = &upload_data_stream;
13100 request.load_flags = 0;
13101
13102 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13103 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113104 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413105 // Send headers successfully, but get an error while sending the body.
13106 MockWrite data_writes[] = {
13107 MockWrite("POST / HTTP/1.1\r\n"
13108 "Host: www.foo.com\r\n"
13109 "Connection: keep-alive\r\n"
13110 "Transfer-Encoding: chunked\r\n\r\n"),
13111 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13112 };
13113
13114 MockRead data_reads[] = {
13115 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
13116 MockRead("hello world"),
13117 MockRead(SYNCHRONOUS, OK),
13118 };
13119 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13120 arraysize(data_writes));
13121 session_deps_.socket_factory->AddSocketDataProvider(&data);
13122
13123 TestCompletionCallback callback;
13124
13125 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13126 EXPECT_EQ(ERR_IO_PENDING, rv);
13127 // Make sure the headers are sent before adding a chunk. This ensures that
13128 // they can't be merged with the body in a single send. Not currently
13129 // necessary since a chunked body is never merged with headers, but this makes
13130 // the test more future proof.
13131 base::RunLoop().RunUntilIdle();
13132
mmenkecbc2b712014-10-09 20:29:0713133 upload_data_stream.AppendData("last chunk", 10, true);
[email protected]02d74a02014-04-23 18:10:5413134
13135 rv = callback.WaitForResult();
13136 EXPECT_EQ(OK, rv);
13137
13138 const HttpResponseInfo* response = trans->GetResponseInfo();
13139 ASSERT_TRUE(response != NULL);
13140
13141 EXPECT_TRUE(response->headers.get() != NULL);
13142 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
13143
13144 std::string response_data;
13145 rv = ReadTransaction(trans.get(), &response_data);
13146 EXPECT_EQ(OK, rv);
13147 EXPECT_EQ("hello world", response_data);
13148}
13149
13150TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) {
13151 ScopedVector<UploadElementReader> element_readers;
13152 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713153 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413154
13155 HttpRequestInfo request;
13156 request.method = "POST";
13157 request.url = GURL("http://www.foo.com/");
13158 request.upload_data_stream = &upload_data_stream;
13159 request.load_flags = 0;
13160
13161 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13162 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113163 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413164
13165 MockWrite data_writes[] = {
13166 MockWrite("POST / HTTP/1.1\r\n"
13167 "Host: www.foo.com\r\n"
13168 "Connection: keep-alive\r\n"
13169 "Content-Length: 3\r\n\r\n"),
13170 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13171 };
13172
13173 MockRead data_reads[] = {
13174 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
13175 MockRead("HTTP/1.0 400 Not OK\r\n\r\n"),
13176 MockRead("hello world"),
13177 MockRead(SYNCHRONOUS, OK),
13178 };
13179 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13180 arraysize(data_writes));
13181 session_deps_.socket_factory->AddSocketDataProvider(&data);
13182
13183 TestCompletionCallback callback;
13184
13185 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13186 EXPECT_EQ(ERR_IO_PENDING, rv);
13187
13188 rv = callback.WaitForResult();
13189 EXPECT_EQ(OK, rv);
13190
13191 const HttpResponseInfo* response = trans->GetResponseInfo();
13192 ASSERT_TRUE(response != NULL);
13193
13194 EXPECT_TRUE(response->headers.get() != NULL);
13195 EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine());
13196
13197 std::string response_data;
13198 rv = ReadTransaction(trans.get(), &response_data);
13199 EXPECT_EQ(OK, rv);
13200 EXPECT_EQ("hello world", response_data);
13201}
13202
13203TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) {
13204 ScopedVector<UploadElementReader> element_readers;
13205 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713206 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413207
13208 HttpRequestInfo request;
13209 request.method = "POST";
13210 request.url = GURL("http://www.foo.com/");
13211 request.upload_data_stream = &upload_data_stream;
13212 request.load_flags = 0;
13213
13214 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13215 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113216 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413217 // Send headers successfully, but get an error while sending the body.
13218 MockWrite data_writes[] = {
13219 MockWrite("POST / HTTP/1.1\r\n"
13220 "Host: www.foo.com\r\n"
13221 "Connection: keep-alive\r\n"
13222 "Content-Length: 3\r\n\r\n"),
13223 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13224 };
13225
13226 MockRead data_reads[] = {
13227 MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"),
13228 MockRead("hello world"),
13229 MockRead(SYNCHRONOUS, OK),
13230 };
13231 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13232 arraysize(data_writes));
13233 session_deps_.socket_factory->AddSocketDataProvider(&data);
13234
13235 TestCompletionCallback callback;
13236
13237 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13238 EXPECT_EQ(ERR_IO_PENDING, rv);
13239
13240 rv = callback.WaitForResult();
13241 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13242
13243 const HttpResponseInfo* response = trans->GetResponseInfo();
13244 EXPECT_TRUE(response == NULL);
13245}
13246
13247TEST_P(HttpNetworkTransactionTest,
13248 PostIgnoresNonErrorResponseAfterResetAnd100) {
13249 ScopedVector<UploadElementReader> element_readers;
13250 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713251 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413252
13253 HttpRequestInfo request;
13254 request.method = "POST";
13255 request.url = GURL("http://www.foo.com/");
13256 request.upload_data_stream = &upload_data_stream;
13257 request.load_flags = 0;
13258
13259 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13260 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113261 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413262 // Send headers successfully, but get an error while sending the body.
13263 MockWrite data_writes[] = {
13264 MockWrite("POST / HTTP/1.1\r\n"
13265 "Host: www.foo.com\r\n"
13266 "Connection: keep-alive\r\n"
13267 "Content-Length: 3\r\n\r\n"),
13268 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13269 };
13270
13271 MockRead data_reads[] = {
13272 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
13273 MockRead("HTTP/1.0 302 Redirect\r\n"),
13274 MockRead("Location: http://somewhere-else.com/\r\n"),
13275 MockRead("Content-Length: 0\r\n\r\n"),
13276 MockRead(SYNCHRONOUS, OK),
13277 };
13278 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13279 arraysize(data_writes));
13280 session_deps_.socket_factory->AddSocketDataProvider(&data);
13281
13282 TestCompletionCallback callback;
13283
13284 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13285 EXPECT_EQ(ERR_IO_PENDING, rv);
13286
13287 rv = callback.WaitForResult();
13288 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13289
13290 const HttpResponseInfo* response = trans->GetResponseInfo();
13291 EXPECT_TRUE(response == NULL);
13292}
13293
13294TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) {
13295 ScopedVector<UploadElementReader> element_readers;
13296 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713297 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413298
13299 HttpRequestInfo request;
13300 request.method = "POST";
13301 request.url = GURL("http://www.foo.com/");
13302 request.upload_data_stream = &upload_data_stream;
13303 request.load_flags = 0;
13304
13305 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13306 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113307 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413308 // Send headers successfully, but get an error while sending the body.
13309 MockWrite data_writes[] = {
13310 MockWrite("POST / HTTP/1.1\r\n"
13311 "Host: www.foo.com\r\n"
13312 "Connection: keep-alive\r\n"
13313 "Content-Length: 3\r\n\r\n"),
13314 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13315 };
13316
13317 MockRead data_reads[] = {
13318 MockRead("HTTP 0.9 rocks!"),
13319 MockRead(SYNCHRONOUS, OK),
13320 };
13321 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13322 arraysize(data_writes));
13323 session_deps_.socket_factory->AddSocketDataProvider(&data);
13324
13325 TestCompletionCallback callback;
13326
13327 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13328 EXPECT_EQ(ERR_IO_PENDING, rv);
13329
13330 rv = callback.WaitForResult();
13331 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13332
13333 const HttpResponseInfo* response = trans->GetResponseInfo();
13334 EXPECT_TRUE(response == NULL);
13335}
13336
13337TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) {
13338 ScopedVector<UploadElementReader> element_readers;
13339 element_readers.push_back(new UploadBytesElementReader("foo", 3));
mmenkecbc2b712014-10-09 20:29:0713340 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]02d74a02014-04-23 18:10:5413341
13342 HttpRequestInfo request;
13343 request.method = "POST";
13344 request.url = GURL("http://www.foo.com/");
13345 request.upload_data_stream = &upload_data_stream;
13346 request.load_flags = 0;
13347
13348 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13349 scoped_ptr<HttpTransaction> trans(
dcheng48459ac22014-08-26 00:46:4113350 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
[email protected]02d74a02014-04-23 18:10:5413351 // Send headers successfully, but get an error while sending the body.
13352 MockWrite data_writes[] = {
13353 MockWrite("POST / HTTP/1.1\r\n"
13354 "Host: www.foo.com\r\n"
13355 "Connection: keep-alive\r\n"
13356 "Content-Length: 3\r\n\r\n"),
13357 MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET),
13358 };
13359
13360 MockRead data_reads[] = {
13361 MockRead("HTTP/1.0 400 Not a Full Response\r\n"),
13362 MockRead(SYNCHRONOUS, OK),
13363 };
13364 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13365 arraysize(data_writes));
13366 session_deps_.socket_factory->AddSocketDataProvider(&data);
13367
13368 TestCompletionCallback callback;
13369
13370 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13371 EXPECT_EQ(ERR_IO_PENDING, rv);
13372
13373 rv = callback.WaitForResult();
13374 EXPECT_EQ(ERR_CONNECTION_RESET, rv);
13375
13376 const HttpResponseInfo* response = trans->GetResponseInfo();
13377 EXPECT_TRUE(response == NULL);
13378}
13379
Adam Rice425cf122015-01-19 06:18:2413380// Verify that proxy headers are not sent to the destination server when
13381// establishing a tunnel for a secure WebSocket connection.
13382TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) {
13383 HttpRequestInfo request;
13384 request.method = "GET";
13385 request.url = GURL("wss://www.google.com/");
13386 AddWebSocketHeaders(&request.extra_headers);
13387
13388 // Configure against proxy server "myproxy:70".
13389 session_deps_.proxy_service.reset(
13390 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
13391
13392 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13393
13394 // Since a proxy is configured, try to establish a tunnel.
13395 MockWrite data_writes[] = {
13396 MockWrite(
13397 "CONNECT www.google.com:443 HTTP/1.1\r\n"
13398 "Host: www.google.com\r\n"
13399 "Proxy-Connection: keep-alive\r\n\r\n"),
13400
13401 // After calling trans->RestartWithAuth(), this is the request we should
13402 // be issuing -- the final header line contains the credentials.
13403 MockWrite(
13404 "CONNECT www.google.com:443 HTTP/1.1\r\n"
13405 "Host: www.google.com\r\n"
13406 "Proxy-Connection: keep-alive\r\n"
13407 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
13408
13409 MockWrite(
13410 "GET / HTTP/1.1\r\n"
13411 "Host: www.google.com\r\n"
13412 "Connection: Upgrade\r\n"
13413 "Upgrade: websocket\r\n"
13414 "Origin: http://www.google.com\r\n"
13415 "Sec-WebSocket-Version: 13\r\n"
13416 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"),
13417 };
13418
13419 // The proxy responds to the connect with a 407, using a persistent
13420 // connection.
13421 MockRead data_reads[] = {
13422 // No credentials.
13423 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
13424 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
13425 MockRead("Proxy-Connection: close\r\n\r\n"),
13426
13427 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
13428
13429 MockRead("HTTP/1.1 101 Switching Protocols\r\n"),
13430 MockRead("Upgrade: websocket\r\n"),
13431 MockRead("Connection: Upgrade\r\n"),
13432 MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"),
13433 };
13434
13435 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13436 arraysize(data_writes));
13437 session_deps_.socket_factory->AddSocketDataProvider(&data);
13438 SSLSocketDataProvider ssl(ASYNC, OK);
13439 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
13440
13441 scoped_ptr<HttpTransaction> trans(
13442 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
13443 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
13444 trans->SetWebSocketHandshakeStreamCreateHelper(
13445 &websocket_stream_create_helper);
13446
13447 {
13448 TestCompletionCallback callback;
13449
13450 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13451 EXPECT_EQ(ERR_IO_PENDING, rv);
13452
13453 rv = callback.WaitForResult();
13454 EXPECT_EQ(OK, rv);
13455 }
13456
13457 const HttpResponseInfo* response = trans->GetResponseInfo();
13458 ASSERT_TRUE(response);
13459 ASSERT_TRUE(response->headers.get());
13460 EXPECT_EQ(407, response->headers->response_code());
13461
13462 {
13463 TestCompletionCallback callback;
13464
13465 int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar),
13466 callback.callback());
13467 EXPECT_EQ(ERR_IO_PENDING, rv);
13468
13469 rv = callback.WaitForResult();
13470 EXPECT_EQ(OK, rv);
13471 }
13472
13473 response = trans->GetResponseInfo();
13474 ASSERT_TRUE(response);
13475 ASSERT_TRUE(response->headers.get());
13476
13477 EXPECT_EQ(101, response->headers->response_code());
13478
13479 trans.reset();
13480 session->CloseAllConnections();
13481}
13482
13483// Verify that proxy headers are not sent to the destination server when
13484// establishing a tunnel for an insecure WebSocket connection.
13485// This requires the authentication info to be injected into the auth cache
13486// due to crbug.com/395064
13487// TODO(ricea): Change to use a 407 response once issue 395064 is fixed.
13488TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) {
13489 HttpRequestInfo request;
13490 request.method = "GET";
13491 request.url = GURL("ws://www.google.com/");
13492 AddWebSocketHeaders(&request.extra_headers);
13493
13494 // Configure against proxy server "myproxy:70".
13495 session_deps_.proxy_service.reset(
13496 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
13497
13498 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13499
13500 MockWrite data_writes[] = {
13501 // Try to establish a tunnel for the WebSocket connection, with
13502 // credentials. Because WebSockets have a separate set of socket pools,
13503 // they cannot and will not use the same TCP/IP connection as the
13504 // preflight HTTP request.
13505 MockWrite(
13506 "CONNECT www.google.com:80 HTTP/1.1\r\n"
13507 "Host: www.google.com\r\n"
13508 "Proxy-Connection: keep-alive\r\n"
13509 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
13510
13511 MockWrite(
13512 "GET / HTTP/1.1\r\n"
13513 "Host: www.google.com\r\n"
13514 "Connection: Upgrade\r\n"
13515 "Upgrade: websocket\r\n"
13516 "Origin: http://www.google.com\r\n"
13517 "Sec-WebSocket-Version: 13\r\n"
13518 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"),
13519 };
13520
13521 MockRead data_reads[] = {
13522 // HTTP CONNECT with credentials.
13523 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
13524
13525 // WebSocket connection established inside tunnel.
13526 MockRead("HTTP/1.1 101 Switching Protocols\r\n"),
13527 MockRead("Upgrade: websocket\r\n"),
13528 MockRead("Connection: Upgrade\r\n"),
13529 MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"),
13530 };
13531
13532 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
13533 arraysize(data_writes));
13534 session_deps_.socket_factory->AddSocketDataProvider(&data);
13535
13536 session->http_auth_cache()->Add(
13537 GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC,
13538 "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/");
13539
13540 scoped_ptr<HttpTransaction> trans(
13541 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
13542 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
13543 trans->SetWebSocketHandshakeStreamCreateHelper(
13544 &websocket_stream_create_helper);
13545
13546 TestCompletionCallback callback;
13547
13548 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13549 EXPECT_EQ(ERR_IO_PENDING, rv);
13550
13551 rv = callback.WaitForResult();
13552 EXPECT_EQ(OK, rv);
13553
13554 const HttpResponseInfo* response = trans->GetResponseInfo();
13555 ASSERT_TRUE(response);
13556 ASSERT_TRUE(response->headers.get());
13557
13558 EXPECT_EQ(101, response->headers->response_code());
13559
13560 trans.reset();
13561 session->CloseAllConnections();
13562}
13563
[email protected]89ceba9a2009-03-21 03:46:0613564} // namespace net